Skip to content

Instantly share code, notes, and snippets.

@chollier
Created March 11, 2013 21:51
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 chollier/5138111 to your computer and use it in GitHub Desktop.
Save chollier/5138111 to your computer and use it in GitHub Desktop.
jQuery Borders plugins
/*!
* jQuery lightweight plugin boilerplate
* Original author: @ajpiano
* Further changes, comments: @addyosmani
* Licensed under the MIT license
*/
;(function ( $, window, document, undefined ) {
var pluginName = 'borders',
defaults = {
// propertyName: "value"
};
function Plugin( element, options ) {
this.element = element;
this.$el = $(element);
//console.log('options typeof: '+typeof(options));
//console.log('!options : '+ !options);
if(typeof(options)=='string') {
console.log("options string alert")
this.options = options;
} else if(!options) {
// console.log("options null alert")
// this.options == null;
this.options == null;
} else {
this.options = $.extend( {}, defaults, options) ;
}
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype.init = function () {
//console.log(this.options);
//console.log(this.$el.width());
if(this.options == null) {
var taba = ['color', 'style', 'width'];
for(a in taba) {
var tab = ['top', 'bottom', 'left', 'right'];
for(i in tab) {
console.log('border-'+tab[i]+'-'+taba[a]+' '+this.$el.css('border-'+tab[i]+'-'+taba[a]));
}
}
console.log('border-top-left-radius '+this.$el.css('border-top-left-radius'));
console.log('border-top-right-radius '+this.$el.css('border-top-right-radius'));
console.log('border-bottom-left-radius '+this.$el.css('border-bottom-left-radius'));
console.log('border-bottom-right-radius '+this.$el.css('border-bottom-right-radius'));
} else if(typeof(this.options)=="string") {
this.$el.css('border', this.options);
} else {
if(this.options.color) {
//console.log("color : " +this.options.color);
this.$el.css('border-color', this.options.color)
}
if(this.options.style) {
//console.log("style : " +this.options.style);
this.$el.css('border-style', this.options.style)
}
if(this.options.width) {
//console.log("width : " +this.options.width);
this.$el.css('border-width', this.options.width)
}
if(this.options.radius) {
//console.log("radius : " +this.options.radius);
this.$el.css('border-radius', this.options.radius)
}
}
};
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function ( options ) {
return this.each(function () {
// if (!$.data(this, 'plugin_' + pluginName)) {
// $.data(this, 'plugin_' + pluginName,
new Plugin( this, options );
// }
});
}
})( jQuery, window, document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment