Boilerplate jQuery Plugin
Test for writing a jQuery plugin.
by Shaun Ellis
HTML
<body>
<a href="http://sdellis.com">My Site</a>
</body>
JavaScript
$( "a" ).css( "color", "red" );
$.fn.greenify = function() {
this.css( "color", "green" );
};
$( "a" ).greenify();
;(function( $, window, document, undefined ){
// $.fn.manifestView = function(){
var pluginName = "Prospero",
defaults = {
jsonLd : null,
request : null,
manifestUri : "http://lae.princeton.edu/catalog/077ws.jsonld"
};
function Plugin( element, options ){
this.element = element;
this.options = $.extend( {}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype.init = function () {
$( this.element ).attr( "href", this.options.manifestUri );
$( this.element ).css( "color", "orange" );
};
$.fn[pluginName] = function (options) {
return this.each(function (){
if( !$.data(this, "plugin_" + pluginName )) {
$.data( this, "plugin_" + pluginName, new Plugin( this, options ));
}
});
};
// };
})(jQuery, window, document);
$( "a" ).Prospero();