Skip to content

Instantly share code, notes, and snippets.

@ElmahdiMahmoud
Last active December 21, 2015 19:19
Show Gist options
  • Save ElmahdiMahmoud/6353516 to your computer and use it in GitHub Desktop.
Save ElmahdiMahmoud/6353516 to your computer and use it in GitHub Desktop.
jquery: plugin pattern
/*!
* jQuery pattern - 24.01.14
* Author: @ElmahdiMahmoud
* Licensed under the MIT license
*/
;(function ( $, window, document, undefined ) {
$.fn.plugiName = function (options) {
// set up default options
var defaults = {
callback: function () {}, // callback func option
propertyName : 'string', // "String"
propertyName : true, // Boolean
propertyName : 100 // Number
};
/*
* Overwrite default options with user provided ones
* and merge them into "options".
*/
var options = $.extend({}, defaults, options);
return this.each(function () {
var $this = $(this);
// plugin logic
$this.css({
color: options.color // settings variable.
});
});
}
})( jQuery, window, document );
$('selector').plugiName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment