/*! * vEwe * https://github.com/mattrohland/vEwe * * Copyright (c) 2013 Matt Rohland * Released under the MIT license */ /* global define:true,$:false */ /* jshint strict:false,globalstrict:false */ /** * The vEwe module * @exports vEweFactory * @namespace vewe */ (function(){ // AMDless define method if(typeof define !== 'function') define = function(a,b){ window.vEweFactory = b($); }; // AMD define wrapper define( [ '3rdparty/jquery' ], function($){ 'use strict'; var VEweFactory, Element, ShepHeard; /** * A factory that assists in defining and instantiating views. * * @memberof vewe * @class */ VEweFactory = function(){ this.shepHeard = new ShepHeard(); return this; }; /** * @memberof vewe * @lends VEweFactory.prototype */ VEweFactory.prototype = { /** * * A scoped instance of jQuery. * @static */ '$': $, /** * A method used to creates an instance of a VEwe. * * @function * @param {string} [arguments[0]=inherit] - The method to use when merging prototypes. * @param {...object} arguments - One or more prototypes to use when constructing a VEwe instance. * @returns {Function} VEwe instance */ 'create': function(){ var me = this, VEwe; return (VEwe = me.define.apply(me, arguments))? new VEwe() : false ; }, /** * A method used to construct an uninstantiated definition of a view. * * @function * @param {string} [arguments[0]=inherit] - The method to use when merging prototypes. Supported values include: inherit, inheritAndMergeEvents * @param {...object} arguments - One or more prototypes to use when constructing a VEwe class. * @returns {Function} VEwe class */ 'define': function(){ var me = this, proto = {}, inheritanceMethod = 'inherit', inheritanceArguments, /** * @class */ VEwe = function(){ this.shepHeard = me.shepHeard; return this; }; // Process Arguments if(arguments.length === 0){ return false; }else if(typeof arguments[0] === 'object'){ inheritanceArguments = (Array.prototype.slice.call(arguments)); }else{ inheritanceMethod = arguments[0]; inheritanceArguments = (Array.prototype.slice.call(arguments)).slice(1); } // All items inherit from vEweDefaultPrototype inheritanceArguments.unshift({}); inheritanceArguments.unshift(this.vEweDefaultPrototype); // Begin inheritance if we need to proto = (typeof inheritanceMethod == 'string')? this[inheritanceMethod].apply(this,inheritanceArguments) : inheritanceMethod.apply(this,inheritanceArguments); // All prototypes start from the vEweDefaultPrototype VEwe.prototype = proto; VEwe.prototype.factory = me; // Return "Class" definition return VEwe; }, 'inherit': function(){ var extendArgs = (Array.prototype.slice.call(arguments)); // Insure that we start with a new object (we don't want accidental inheritance) extendArgs.unshift({}); // Runs an extend on all arguments return this.$.extend.apply(this,extendArgs); }, 'inheritAndMergeEvents': function(){ // Runs an extend on all arguments // Also merges all the events down the inheritance chain var i, protos = Array.prototype.slice.call(arguments), proto, events = []; for(i=0;i