JSFiddle - React, Tailwind, and code Playground
by pavel_krupala
HTML
<p>pivo</p>
<p>limo</p>
JavaScript
//$(document).ready(function() {
/**
jQuery Layer Plugin
*/
(function($) {
var PLUGIN_NAME = "Layer";
var defaults = {
width: 320,
height: 200
};
function Plugin(el, options) {
// defaults go here...
this.settings = $.extend({}, defaults, options);
// privates
this.el = el;
var elm = el;
this.$el = $(el);
this.init();
}
Plugin.prototype.init = function() {
// Place your initialization logic here...
// U can access this.el, this.$el, this.settings
};
Plugin.prototype.colorize = function(options) {
console.log('Couling colorize with param:', options, 'ON', this.el, this.$el);
$(this.el).css({border:"2px solid "+options.color}).append(" - "+options.color).append(" ~ OPT:" + JSON.stringify(this.settings));
};
Plugin.prototype.options = function(options) {
console.log("Couling options func...");
return this.settings;
};
$.fn[PLUGIN_NAME] = function(func, options) {
return this.each(function() {
if (! $.data(this, PLUGIN_NAME+"_plugin")) {
if (typeof func === 'object')
$.data(this, PLUGIN_NAME+"_plugin", new Plugin(this, func));
else
$.data(this, PLUGIN_NAME+"_plugin", new Plugin(this, {}));
}
var plug = $.data(this, PLUGIN_NAME+"_plugin");
//plug.
/*if (typeof func === 'object') {
//
}*/
if (typeof func === 'string') {
//console.log('wanna call plugin on', this, 'func:', func);
if (typeof plug[func] === 'function') {
plug[func].call(plug, options);
} else {
//console.log('plugins function', func, 'is not defined!');
}
...