Last active
December 21, 2015 19:19
-
-
Save ElmahdiMahmoud/6353516 to your computer and use it in GitHub Desktop.
jquery: plugin pattern
This file contains hidden or 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
/*! | |
* 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