Skip to content

Instantly share code, notes, and snippets.

@kovaldn
Created August 17, 2015 15:20
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 kovaldn/587b028a0517922bfcba to your computer and use it in GitHub Desktop.
Save kovaldn/587b028a0517922bfcba to your computer and use it in GitHub Desktop.
jquery plugin
// jQuery plugin
http://learn.jquery.com/plugins/basic-plugin-creation/
(function ( $ ) {
var shade = "#556b2f";
$.fn.greenify = function() {
this.css( "color", shade );
return this;
};
}( jQuery ));
$( "a" ).greenify().addClass( "greenified" );
// ------------------------------------------------------
// Если хотим сделать что-то с большим количеством элементов
$.fn.myNewPlugin = function() {
return this.each(function() {
// Do something to each element here.
});
};
// ------------------------------------------------------
// Options
(function ( $ ) {
$.fn.greenify = function( options ) {
// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
color: "#556b2f",
backgroundColor: "white"
}, options );
// Greenify the collection based on the settings variable.
return this.css({
color: settings.color,
backgroundColor: settings.backgroundColor
});
};
}( jQuery ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment