Basic Class Extending with jQuery
We are taking a Class and OO pattern to build a Plugin architecture system.
by Chad Drummond
JavaScript
(function($) {
var Plugin = function Plugin() {
var private = {};
this.init = function() {
console.log(arguments);
}
this.__private = function(key) {
return (typeof private[key] != 'undefined') ? private[key] : null;
};
return this;
}
/*Function.prototype.__clone = function() {
var f = this;
var c = function() {
return f.apply(this, arguments);
};
c.prototype = $.extend(true, {}, c.prototype, f.prototype, {
__parent: f
});
return c;
};*/
/*Plugin.create = function(name, options) {
var Class = function() {};
if (options.Extends) {
var Extends = options.Extends;
delete options.Extends;
Class = Extends.__clone();
}
Class.prototype = $.extend(true, {}, Class.prototype, options || {});
this[name] = Class;
}*/
Plugin.extend = function(Extendee, Extender) {
Extendee.prototype = $.extend(true, {}, Plugin.prototype, Extender.prototype, Extendee.prototype, Extendee.defaults || {}, {
__parent: Extender,
__base: new Plugin
});
}
Plugin.uniqueID = function() {
return (Date.now() + 1).toString(36);
};
Plugin.version = '0.5';
// the base plugin
$.Plugin = Plugin;
})(jQuery);
$.R = function R(elements, options) {
var timer = true;
var init = function() {
this.__base.init();
};
this.fun = function() {
return this.__parent.uniqueID();
}
this.isTiming = function() {
return timer
};
this.toggleTimer = function(isRunning) {
timer = isRunning || timer;
return timer;
}
this.version = 'legit';
//return init();
};
$.Rotator = function(elements, options) {
this.fun = function() {}
};
$.Rotator.prototype.funner = function() {
return...