Skip to content

Instantly share code, notes, and snippets.

@alexpts
Last active August 16, 2016 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpts/fa28f3cbb56ff034b105c0688bc03935 to your computer and use it in GitHub Desktop.
Save alexpts/fa28f3cbb56ff034b105c0688bc03935 to your computer and use it in GitHub Desktop.
Example js module 2
(function ($, $popover) {
/**
* @param {{}|undefined}options
* @returns {{on: Function, off: Function}}
* @constructor
*/
var Popover = function (options) {
options = $.extend({
delegateElement: document,
}, options || {});
/**
* @param {Event} event
*/
var _close = function (event) {
$('.popover').popover('hide');
};
// public
return {
on: function () {
$(options.delegateElement)
.on('click', '.popover .close', _close)
.on('show.bs.popover', _close);
},
off: function () {
$(options.delegateElement)
.off('click', '.popover .close', _close)
.off('show.bs.popover', _close);
}
};
};
// pass module to app, one of way
$(document).trigger('js.load', ['popover', Popover]);
})(jQuery, jQuery.fn.popover);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment