Created
March 18, 2013 00:35
-
-
Save clu3/5184285 to your computer and use it in GitHub Desktop.
Spagetti version of Bootstro.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************Live on-page Help ********************************/ | |
var popups; | |
var pIdx; //index of popup | |
var destroy_current_popup = function() | |
{ | |
if (!_.isUndefined(pIdx)) | |
{ | |
p = popups[pIdx]; | |
selector = p.selector; | |
$(selector).popover('destroy').removeClass('help_highlight'); | |
} | |
}; | |
var stop_live_help = function() | |
{ | |
destroy_current_popup(); | |
$("div.live-help-backdrop").remove(); | |
}; | |
var start_live_help = function(idx) | |
{ | |
if (!_.isUndefined(pIdx) && pIdx >= popups.length) //end of slide show | |
{ | |
stop_live_help(); | |
} | |
else | |
{ | |
//destroy current popup if any | |
destroy_current_popup(); | |
p = popups[idx]; | |
selector = p.selector; | |
$(selector).popover(p).popover('show'); | |
//resize popup if it's explicitly said so by server | |
if (!_.isUndefined(p.width)) | |
$("div.popover").css('width', p.width); | |
/*else | |
$("div.popover").css('width', p.width); | |
*/ | |
$(selector).addClass('help_highlight'); | |
pIdx = idx; | |
} | |
}; | |
var trigger_live_help = function() | |
{ | |
$.ajax({ | |
url : '/site/live-help?page=' + CL.help_page, | |
success : function(data){ | |
if (data.success) | |
{ | |
popups = data.result; | |
$('<div class="live-help-backdrop"></div>').insertBefore('body'); | |
start_live_help(0); | |
} | |
} | |
}); | |
}; | |
$("#next_live_help").live('click', function(e){ | |
if (pIdx + 1 == popups.length) | |
{ | |
$("#ok_live_help").trigger('click'); | |
} | |
else | |
{ | |
start_live_help(pIdx + 1); | |
} | |
e.preventDefault(); | |
return false; | |
}); | |
$("#prev_live_help").live('click', function(e){ | |
start_live_help(pIdx - 1); | |
e.preventDefault(); | |
return false; | |
}); | |
var no_help_please = function() | |
{ | |
setCookie('_cl_help_' + CL.help_page, 1, 150);//15 days | |
stop_live_help(); | |
//send CL.help_page to user | |
if (!is_guest()) | |
{ | |
$.ajax( | |
{ | |
url : "/site/mark-live-help", | |
data : {page : CL.help_page}, | |
success : function(){ | |
//stop_live_help(); | |
} | |
} | |
); | |
} | |
}; | |
//end of show | |
$("#ok_live_help").live('click', function(e){ | |
no_help_please(); | |
}); | |
if (!_.isUndefined(CL.trigger_live_help)) | |
{ | |
if (_.isUndefined(getCookie('_cl_help_' + CL.help_page))) | |
{ | |
//trigger_live_help(); | |
//TODO draw dialog. On "OK" clicked, then trigger_live_help() | |
$("#helpModal div.modal-body").html(CL.modal_help_msg); | |
// $("#helpModalLabel").html("Hey there"); | |
$("#helpModal").modal({backdrop: false}); | |
} | |
}; | |
$("#yes_help_thanks,#remind_help_later, #no_help_thanks").live('click', function(e){ | |
//close modal | |
$("#helpModal div.modal-footer").hide(); | |
$("#helpModal").modal('hide'); | |
if ($(this).attr('id') == 'yes_help_thanks') | |
trigger_live_help(); | |
else if($(this).attr('id') == 'no_help_thanks') | |
{ | |
no_help_please(); | |
} | |
else | |
{ | |
//not now.Set cookie to some short certain period | |
setCookie('_cl_help_' + CL.help_page, 1, 1);//1 day | |
stop_live_help(); | |
} | |
}); | |
//////////////////////////////End live onpage help///////////////////////////////////////////// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment