Skip to content

Instantly share code, notes, and snippets.

@gerad
Created March 8, 2012 18:58
Show Gist options
  • Select an option

  • Save gerad/2002710 to your computer and use it in GitHub Desktop.

Select an option

Save gerad/2002710 to your computer and use it in GitHub Desktop.
snapengage async jquery plugin
;// http://www.snapengage.com/docs/asyncload.jsp
// usage: $.snapengage()
// loads snapengage asynchronously. A click on any link with class 'snapengage'
// will cause the chat to open.
!function($, window, undefined) {
var widgetid = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX';
$.snapengage = function() {
var protocol = window.location.protocol
, base = /^https/.test(protocol) ? "https://snapabug.appspot.com" : "http://www.snapengage.com";
$(document.body).append('<div id="SnapABug_W"></div><div id="SnapABug_WP"></div><div id="SnapABug_Applet"></div>');
$.getScript(base + "/snapabug.js", function() {
SnapABug.initAsync(widgetid);
$('a.snapengage').live('click', function(e) {
e.preventDefault();
SnapABug.startLink();
});
});
};
}(jQuery, window);
@justabuzz
Copy link

Just a quick note, seems like it isn't that known, but instead of asking for the protocol to determine HTTPS or not you can simply set base to be '//snapabug.appspot.com'. Yup, all I did is dropeed the 'http:' from the URL. This tells the browser to use the current protocol. Too easy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment