diff --git a/dist/gremlin.min.js b/dist/gremlin.min.js index f526ddb..84e5721 100644 --- a/dist/gremlin.min.js +++ b/dist/gremlin.min.js @@ -1 +1 @@ -/*! GremlinJS 0.5.1 (2013-11-06) - http://grml.in - Licensed under MIT license */!function(a,b){b["true"]=a,!function(a){window.onDomReady=a()}(function(){"use strict";function a(b){if(!v){if(!g.body)return d(a);for(v=!0;b=w.shift();)d(b)}}function b(b){(t||b.type===i||g[m]===l)&&(c(),a())}function c(){t?(g[s](q,b,j),f[s](i,b,j)):(g[o](r,b),f[o](k,b))}function d(a,b){setTimeout(a,+b>=0?b:1)}function e(a){v?d(a):w.push(a)}var f=window,g=f.document,h=g.documentElement,i="load",j=!1,k="on"+i,l="complete",m="readyState",n="attachEvent",o="detachEvent",p="addEventListener",q="DOMContentLoaded",r="onreadystatechange",s="removeEventListener",t=p in g,u=j,v=j,w=[];if(g[m]===l)d(a);else if(t)g[p](q,b,j),f[p](i,b,j);else{g[n](r,b),f[n](k,b);try{u=null==f.frameElement&&h}catch(x){}u&&u.doScroll&&function y(){if(!v){try{u.doScroll("left")}catch(b){return d(y,50)}c(),a()}}()}return e.version="1.3",e});var c;c=function(){function a(){this._events={}}return a.prototype.on=function(a,b){return this._events[a]=this._events[a]||[],this._events[a].push(b)},a.prototype.off=function(a,b){return!1!=a in this._events?this._events[a].splice(this._events[a].indexOf(b),1):void 0},a.prototype.emit=function(a){var b,c;if(this._events=this._events||{},!1!=a in this._events){for(b=0,c=[];bg;g++)for(a in b=c[g])f=b[a],d[a]=f;return d},a.mixin=function(a,c){return b(a.prototype,c)},a.clone=function(a){var b,c;if(null==a||"object"!=typeof a)return a;if(a instanceof Date)return new Date(a.getTime());if(a instanceof RegExp)return b="",null!=a.global&&(b+="g"),null!=a.ignoreCase&&(b+="i"),null!=a.multiline&&(b+="m"),null!=a.sticky&&(b+="y"),RegExp(a.source,b);c=new a.constructor;for(b in a)c[b]=f.Helper.clone(a[b]);return c},a.hasClass=function(a,b){return b=b.trim(),null===a.className.match(RegExp("(\\s|^)"+b+"(\\s|$)"))?!1:!0},a.addClass=function(a,b){return b=b.trim(),f.Helper.hasClass(a,b)||(a.className+=" "+b),a.className=a.className.trim()},a.removeClass=function(a,b){var c;return b=b.trim(),f.Helper.hasClass(a,b)?(c=RegExp("(\\s|^)"+b+"(\\s|$)"),a.className=a.className.replace(c," "),a.className=a.className.trim()):void 0},a.addStyleSheet=function(a){var b,c;return b=document.getElementsByTagName("head")[0],c=document.createElement("style"),c.type="text/css",c.styleSheet?c.styleSheet.cssText=a:c.appendChild(document.createTextNode(a)),b.appendChild(c)},a}(),f.Debug=function(){function a(a){this._isDebug=a,this._gremlins=[],this._broken=[],this._logEl=null,this._createLog(),this._createConsole()}var b,c,d,e,g;return b="debug error info log warn dir dirxml trace assert count markTimeline profile profileEnd time timeEnd timeStamp group groupCollapsed groupEnd".split(" "),c="function"==typeof Function.prototype.bind,d="function"==typeof(null!=(g=window.console)?g.log:void 0),e=function(){},a.prototype._createLog=function(){return this._isDebug?(this._logEl=document.createElement("div"),this._logEl.className="gremlinjs-log",document.body.appendChild(this._logEl)):void 0},a.prototype._createConsole=function(){var a,g,h,i;if(this.console={},this._isDebug&&f.Helper.addStyleSheet(".gremlinjs-log {\nposition: fixed;\nbottom: 0;\nleft: 0;\nbackground: #fff;\npadding: 4px 6px;\n-webkit-box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.3);\nbox-shadow: 0px 0px 4px 0px rgba(0,0,0,0.3);\nz-index: 9999;\n}\n\n.gremlinjs-log p {\n font-size: 12px;\n color: #666666;\n margin: 0;\n padding: 0;\n}\n\n.gremlinjs-log p span {\n display: inline-block;\n margin: 0 5px;\n cursor: help;\n}\n\n.gremlinjs-log p .gremlinjs-log-ready{\ncolor: #41bb19;\n}\n\n.gremlinjs-log p .gremlinjs-log-waiting{\ncolor: #8d46b0;\n}\n\n.gremlinjs-log p .gremlinjs-log-pending{\ncolor: #fff;\nbackground: #fe781e;\npadding: 0 4px;\n}\n\n.gremlinjs-log p .gremlinjs-log-error{\ncolor: #fff;\nbackground: #f50f43;\npadding: 0 4px;\n}\n\n*[data-gremlin-found] {\noutline: 2px solid #41bb19;\n}\n\n*[data-gremlin-found]::before {\ncolor: #41bb19;\nfont-family: monospace;\ncontent: '[' attr(data-gremlin-found) '] ready';\nposition: absolute;\nmargin-top: -14px;\nfont-size: 11px;\nfont-weight: bold;\n}\n\n.gremlin-definition-pending {\noutline: 2px solid #fe781e;\n}\n.gremlin-definition-pending::before {\ncontent: '[' attr(data-gremlin-found) '] definition pendig...';\ncolor: #fe781e;\n}\n.gremlin-error {\noutline: 2px solid red;\n}\n\n.gremlin-error[data-gremlin-found]::before {\ncontent: 'faulty gremlin!';\ncolor: red;\n}"),d&&this._isDebug){for(i=[],g=0,h=b.length;h>g;g++)a=b[g],c?i.push(this.console[a]=console[a]?Function.prototype.bind.call(console[a],console):e):void 0!==console[a]?i.push(this.console[a]=function(){return Function.prototype.apply.call(console[a],console,arguments)}):i.push(this.console[a]=e);return i}for(i=[],g=0,h=b.length;h>g;g++)a=b[g],i.push(this.console[a]=e);return i},a.prototype.registerGremlin=function(a){return this._gremlins.push(a)},a.prototype.reportBrokenGremlin=function(a){return this._broken.push(a)},a.prototype.updateGremlinLog=function(){var a=this;return this._isDebug&&this._logEl?window.setTimeout(function(){var b,c,d,e,f,g,h,i,j,k,l;for(f=0,g={},h=0,i={},d=0,e={},b=a._broken.length,l=a._gremlins,j=0,k=l.length;k>j;j++)c=l[j],c.hasGremlin()?(f++,a._addName(g,c.name)):c.isLazy?(h++,a._addName(i,c.name)):(d++,a._addName(e,c.name));return b='

\n"+f+' ready\n"+h+' lazy waiting\n"+d+" pending\n"+b+" error(s)\n

",a._logEl.innerHTML=b},50):void 0},a.prototype._addName=function(a,b){return a[b]?a[b]++:a[b]=1},a.prototype._getTitle=function(a){var b,c,d;c="";for(b in a)d=a[b],c+=""+d+"x "+b+" \n";return""===c?"":"Gremlins: \n"+c},a}();var g;g={};var h={};h.Configuration=function(){function a(a){this._options=f.Helper.extend({},b,a)}var b;return b={debug:!1},a.prototype.get=function(a){var b;return null!=(b=this._options[a])?b:null},a.options={DEBUG:"debug",AUTOLOAD:"autoload"},a}(),f.ready=window.onDomReady;var i={};i.Gizmo=function(){function a(a,b,c,d){this.el=a,this.data=b,this.id=c,d.call(this)}return a.prototype.data=null,a.prototype.el=null,a.prototype.id=null,a.prototype.klass=null,a}();var j={};j.ModuleCollection=function(){function a(){}var b,c,d;return d={},c={},b=function(a,b){var e,f,g;if(!c[a]){switch(e=b.include,typeof e){case"string":f=[e];break;case"object":f=Array.isArray(e)?e:[];break;default:f=[]}c[a]=function(){var a,b,c,e;for(e=[],a=0,b=f.length;b>a;a++)g=f[a],e.push(function(){if(null!=(c=d[g]))return c;throw Error("The module "+g+" does not exists!")}());return e}()}return c[a]},a.registerModule=function(a){return d[a.name]=a},a.extendGizmo=function(a,c){var d,e,f,g,h;for(e=b(a,c),h=[],f=0,g=e.length;g>f;f++)d=e[f],h.push(d.extend(c));return h},a.bindGizmo=function(a,c){var d,e,f,g,h;for(e=b(a,c.klass),h=[],f=0,g=e.length;g>f;f++)d=e[f],h.push(d.bind(c));return h},a}();var d={}.hasOwnProperty,k=function(a,b){function c(){this.constructor=a}for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};i.Pool=function(){function a(){}var b,c;return c=null,b={},a=function(){function a(){}return a.prototype.get=function(a){var c;return null!=(c=b[a])?c:null},a.prototype.set=function(a,c){if("undefined"!=typeof b[a])throw Error("Trying to add new Gremlin definition, but a definition for "+a+" already exists.");return j.ModuleCollection.extendGizmo(a,c),b[a]=c},a.prototype.define=function(a,b,c,e){var g,h;if("string"!=typeof a)throw Error("The first parameter when defining a gremlin has to be a string, the gremlin definition's name!");if("function"!=typeof b)throw Error("The second parameter when defining a gremlin has to be the constructor function!");if(void 0!==c&&"object"!=typeof c)throw Error("The third parameter when defining a gremlin has to be an object providing the instance members of the gremlin!");if(void 0!==e&&"object"!=typeof e)throw Error("The fourth parameter when defining a gremlin has to be an object providing the static members of the gremlin!");g=function(a){function c(){c.__super__.constructor.apply(this,arguments),b.call(this)}return k(c,a),c}(i.Gizmo),g.prototype.klass=g,f.Helper.mixin(g,c);for(h in e)d.call(e,h)&&(c=e[h],g[h]=c);return this.set(a,g),g},a.prototype.addClass=function(a,b){if("string"!=typeof a)throw Error("Please provide the name of the gremlin!");if("function"!=typeof b)throw Error("When adding a gremlin, you have to provide a constructor function!");return b.prototype.klass=b,this.set(a,b),b},a}(),a.getInstance=function(){return null!=c?c:c=new a},a}();var l=function(a,b){return function(){return a.apply(b,arguments)}},m={clocks:{}};m.clocks.LegacyTimeoutClock=function(){function a(){this._onInterval=l(this._onInterval,this)}return a.prototype.observe=function(){return this._initiateInterval()},a.prototype._initiateInterval=function(){return this._interval=window.setTimeout(this._onInterval,500)},a.prototype._onInterval=function(){return this.onMutation(),this._initiateInterval()},a.prototype.onMutation=function(){},a}();var n={};n.NameProvider=function(){function a(){}var b;return b=function(a,b){var c;return"function"==typeof a.hasAttribute?a.hasAttribute(b):(c=a.getAttributeNode(b),!(!c||!c.specified&&!c.nodeValue))},a.DATA_NAME_ATTR="data-gremlin",a.isGremlin=function(a){return b(a,"data-gremlin")},a.getNames=function(a){var b,c;if(b=a.getAttribute("data-gremlin"),""===b)return b=null!=(c=a.outerHTML)?c:"",n.NameProvider.flagBrokenElement(a),s.debug.console.log("Couldn't process gremlin element, no gremlin names available, 'data-gremlin' is empty!\n"+b),[];var d,e;for(d=b.split(","),e=[],c=0,b=d.length;b>c;c++)a=d[c],e.push(a.trim());return e},a.flagBrokenElement=function(a){return f.Helper.addClass(a,"gremlin-error"),n.NameProvider.flagProcessedElement(a),s.debug.reportBrokenGremlin(a)},a.flagProcessedElement=function(a){var b;return b=a.getAttribute("data-gremlin"),a.removeAttribute("data-gremlin"),a.setAttribute("data-gremlin-found",b)},a}(),m.clocks.cssAnimationStyle=function(a){return a="@keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n@-moz-keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n@-webkit-keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n@-o-keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n*[{{GREMLIN_ATTRIBUTE}}] {\n animation-duration: 1ms;\n -o-animation-duration: 1ms;\n -moz-animation-duration: 1ms;\n -webkit-animation-duration: 1ms;\n animation-name: {{ANIMATION_NAME}};\n -o-animation-name: {{ANIMATION_NAME}};\n -moz-animation-name: {{ANIMATION_NAME}};\n -webkit-animation-name: {{ANIMATION_NAME}};\n}".replace(/{{ANIMATION_NAME}}/g,a),a.replace(/{{GREMLIN_ATTRIBUTE}}/g,n.NameProvider.DATA_NAME_ATTR)},l=function(a,b){return function(){return a.apply(b,arguments)}},m.clocks.CssAnimationClock=function(){function a(){this._onAnimation=l(this._onAnimation,this);var a;a=m.clocks.cssAnimationStyle(b),f.Helper.addStyleSheet(a)}var b,c;return b="gremlinInserted",c=["animationstart","webkitAnimationStart","oanimationstart"],a.prototype.observe=function(){var a,b,d,e;for(e=[],b=0,d=c.length;d>b;b++)a=c[b],e.push(document.body.addEventListener(a,this._onAnimation,!1));return e},a.prototype._onAnimation=function(a){return a.animationName===b?this.onMutation():void 0},a.prototype.onMutation=function(){},a}(),l=function(a,b){return function(){return a.apply(b,arguments)}},m.clocks.MutationObserverClock=function(){function a(){if(this._onMutation=l(this._onMutation,this),null===b)throw Error("Mutation Observer not available")}var b;return b=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver||null,a.prototype.observe=function(){return new b(this._onMutation).observe(document.body,{childList:!0,subtree:!0})},a.prototype._onMutation=function(a){var b,c,d,e;for(e=[],c=0,d=a.length;d>c;c++){if(b=a[c],"childList"===b.type){this.onMutation();break}e.push(void 0)}return e},a.prototype.onMutation=function(){},a}(),f.FeatureDetector=function(){function a(){}return a.hasQuerySelectorAll="undefined"!=typeof document.querySelectorAll,a.hasMutationObserver=!(!window.MutationObserver&&!window.WebKitMutationObserver&&!window.MozMutationObserver),a.hasGetClientRect=void 0!==document.documentElement.getBoundingClientRect,a.hasCssAnimations=function(){var a,b,c,d;if(c=document.documentElement,a=!1,b=["Webkit","Moz","O","ms","Khtml"],c.style.animationName&&(a=!0),!1===a)for(d=0;dc;c++)a=b[c],e.push(a);return e},a}(),b=function(){function a(){}return a.get=function(a){var b,c,d,e;for(b=document.getElementsByTagName("*"),e=[],c=0,d=b.length;d>c;c++)a=b[c],n.NameProvider.isGremlin(a)&&e.push(a);return e},a}(),d=f.FeatureDetector.hasQuerySelectorAll?c:b,a.prototype.getList=function(){return d.get(this._attributeName)},a}.call(this),l=function(a,b){return function(){return a.apply(b,arguments)}},m.DomObserver=function(){function a(){this._handleMutation=l(this._handleMutation,this),this._elementList=new m.ElementList}return a.prototype._bindMutations=function(){var a;return a=o.get(),a.on(o.ON_MUTATION,this._handleMutation),a.observe()},a.prototype._handleMutation=function(){var a;return a=this._elementList.getList(),0this._el.getBoundingClientRect().top-a):!0},a.prototype._create=function(){return this._gremlinInstance=n.GremlinFactory.getInstance(this._name,this._el,this._data),this.hasGremlin()?(f.Helper.removeClass(this._el,b),f.Helper.removeClass(this._el,"gremlin-definition-pending"),f.Helper.addClass(this._el,"gremlin-ready"),s.emit(s.ON_GREMLIN_LOADED,this._el)):this._triggeredPending?void 0:(this._triggeredPending=!0,f.Helper.addClass(this._el,"gremlin-definition-pending"),s.debug.console.info("Gremlin <"+this._name+"> found in the dom, but there is no definition for it at the moment."),s.emit(s.ON_DEFINITION_PENDING,this._el))},a.prototype.hasGremlin=function(){return null!==this._gremlinInstance},a}(),l=function(a,b){return function(){return a.apply(b,arguments)}},n.GremlinCollection=function(){function a(){this._scrollHandler=l(this._scrollHandler,this),this._queue=[],this._bindScroll(),this._scrollTimer=this._didScroll=!1}return a.prototype._queue=null,a.prototype._bindScroll=function(){return window.addEventListener?window.addEventListener("scroll",this._scrollHandler,!1):window.attachEvent?window.attachEvent("onscroll",this._scrollHandler):void 0},a.prototype.add=function(a){var b,c,d;for(c=0,d=a.length;d>c;c++)b=a[c],this._addGremlinElements(b);return this._processQueue()},a.prototype._addGremlinElements=function(a){var b,c,d,e,f;for(c=n.NameProvider.getNames(a),n.NameProvider.flagProcessedElement(a),f=[],d=0,e=c.length;e>d;d++)b=c[d],f.push(this._queue.push(new n.GremlinDomElement(a,b)));return f},a.prototype._processQueue=function(){var a,b,c,d,e;for(b=[],e=this._queue,c=0,d=e.length;d>c;c++)a=e[c],a.check(),a.hasGremlin()||b.push(a);return this._queue=b,s.debug.updateGremlinLog()},a.prototype.process=function(){return this._processQueue()},a.prototype._scrollHandler=function(){var a=this;return 0===this._queue.length?!0:(this._didScroll||(this._scrollTimer=setInterval(function(){return a._didScroll?(a._didScroll=!1,clearTimeout(a._scrollTimer),a.process()):void 0},250)),this._didScroll=!0)},a}();var q,l=function(a,b){return function(){return a.apply(b,arguments)}};q=function(){function a(){this._onNew=l(this._onNew,this);var a,c;a=null!=(c=new f.ElementData.ElementData(document.body).get(b))?c:{},this.configuration=new h.Configuration(a),this._observer=new m.DomObserver,this._coll=new n.GremlinCollection,this._observer.onNewElements=this._onNew}var b;return b="gremlinConfig",a.prototype._onNew=function(a){return this._coll.add(a)},a.prototype.start=function(){return this._observer.observe()},a.prototype.refresh=function(){return this._coll.process()},a}(),j.Module=function(){return function(a,b){var c,d;if(!(this instanceof j.Module))return function(a,b,c){return c.prototype=a.prototype,c=new c,a=a.apply(c,b),Object(a)===a?a:c}(j.Module,arguments,function(){});if(d="function"==typeof b.extend,c="function"==typeof b.bind,!d)throw Error("Missing .extend method in your module "+a);if(!c)throw Error("Missing .bind method in your module "+a);this.name=a,this.extend=b.extend,this.bind=b.bind,j.ModuleCollection.registerModule(this)}}();var r={};r.Package=function(){function a(a,c){return this instanceof r.Package?(this._package=b(a,c),void 0):function(a,b,c){return c.prototype=a.prototype,c=new c,a=a.apply(c,b),Object(a)===a?a:c}(r.Package,arguments,function(){})}var b,c;return c=g,b=function(a,b){var d,e,f,g,h,i;for(null==b&&(b=null),e=a.split("."),f=e.pop(),g=c,h=0,i=e.length;i>h;h++)d=e[h],g=g[d]||(g[d]={});return g[f]=b||g[f]||(g[f]={})},a.get=function(a){return b(a)},a}(),f.polyfill={},"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),Array.prototype.filter||(Array.prototype.filter=function(a,b){var c,d,e,f,g;if("undefined"==typeof this||null===this)throw new TypeError;if(f=Object(this),d=f.length>>>0,"function"!=typeof a)throw new TypeError;for(e=[],c=0;d>c;)c in f&&(g=f[c],a.call(b,g,c,f)&&e.push(g)),c++;return e}),Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){if(null==this)throw new TypeError;var b,c=Object(this),d=c.length>>>0;if(0===d)return-1;if(b=0,10||-1)*Math.floor(Math.abs(b)))),b>=d)return-1;for(b=b>=0?b:Math.max(d-Math.abs(b),0);d>b;b++)if(b in c&&c[b]===a)return b;return-1});var s,d={}.hasOwnProperty,k=function(a,b){function c(){this.constructor=a}for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};s=function(){var a,b;return a=null,b=new(function(b){function c(){c.__super__.constructor.apply(this,arguments),this.debug=new f.Debug(!1)}return k(c,b),c.prototype.ON_ELEMENT_FOUND="elementfound",c.prototype.ON_DEFINITION_PENDING="definitionpending",c.prototype.ON_GREMLIN_LOADED="gremlinloaded",c.prototype.add=function(b,c){return c=i.Pool.getInstance().addClass(b,c),null!=a&&a.refresh(),c},c.prototype.define=function(b,c,d,e){return b=i.Pool.getInstance().define(b,c,d,e),null!=a&&a.refresh(),b},c.prototype.Gizmo=i.Gizmo,c.prototype.Helper=f.Helper,c.prototype.Module=j.Module,c.prototype.namespace=g,c.prototype.ns=g,c.prototype.Package=r.Package,c.prototype.require=r.Package.get,c}(c)),f.ready(function(){var c;return a=new q,(c=a.configuration.get(h.Configuration.options.DEBUG))&&(b.debug=new f.Debug(c)),a.start(),b.debug.console.log("gremlin.js up and running...")}),b}(),window.Gremlin=s,void 0===window.G&&(window.G=window.Gremlin),"function"==typeof window.define&&window.define.amd&&define("Gremlin",[],function(){return s})}({},function(){return this}()); \ No newline at end of file +/*! GremlinJS 0.6.0 (2013-11-10) - http://grml.in - Licensed under MIT license */!function(a,b){b["true"]=a,!function(a){window.onDomReady=a()}(function(){"use strict";function a(b){if(!v){if(!g.body)return d(a);for(v=!0;b=w.shift();)d(b)}}function b(b){(t||b.type===i||g[m]===l)&&(c(),a())}function c(){t?(g[s](q,b,j),f[s](i,b,j)):(g[o](r,b),f[o](k,b))}function d(a,b){setTimeout(a,+b>=0?b:1)}function e(a){v?d(a):w.push(a)}var f=window,g=f.document,h=g.documentElement,i="load",j=!1,k="on"+i,l="complete",m="readyState",n="attachEvent",o="detachEvent",p="addEventListener",q="DOMContentLoaded",r="onreadystatechange",s="removeEventListener",t=p in g,u=j,v=j,w=[];if(g[m]===l)d(a);else if(t)g[p](q,b,j),f[p](i,b,j);else{g[n](r,b),f[n](k,b);try{u=null==f.frameElement&&h}catch(x){}u&&u.doScroll&&function y(){if(!v){try{u.doScroll("left")}catch(b){return d(y,50)}c(),a()}}()}return e.version="1.3",e});var c;c=function(){function a(){this._events={}}return a.prototype.on=function(a,b){return this._events[a]=this._events[a]||[],this._events[a].push(b)},a.prototype.off=function(a,b){return!1!=a in this._events?this._events[a].splice(this._events[a].indexOf(b),1):void 0},a.prototype.emit=function(a){var b,c;if(this._events=this._events||{},!1!=a in this._events){for(b=0,c=[];bg;g++)for(a in b=c[g])f=b[a],d[a]=f;return d},a.mixin=function(a,c){return b(a.prototype,c)},a.clone=function(a){var b,c;if(null==a||"object"!=typeof a)return a;if(a instanceof Date)return new Date(a.getTime());if(a instanceof RegExp)return b="",null!=a.global&&(b+="g"),null!=a.ignoreCase&&(b+="i"),null!=a.multiline&&(b+="m"),null!=a.sticky&&(b+="y"),RegExp(a.source,b);c=new a.constructor;for(b in a)c[b]=f.Helper.clone(a[b]);return c},a.hasClass=function(a,b){return b=b.trim(),null===a.className.match(RegExp("(\\s|^)"+b+"(\\s|$)"))?!1:!0},a.addClass=function(a,b){return b=b.trim(),f.Helper.hasClass(a,b)||(a.className+=" "+b),a.className=a.className.trim()},a.removeClass=function(a,b){var c;return b=b.trim(),f.Helper.hasClass(a,b)?(c=RegExp("(\\s|^)"+b+"(\\s|$)"),a.className=a.className.replace(c," "),a.className=a.className.trim()):void 0},a.addStyleSheet=function(a){var b,c;return b=document.getElementsByTagName("head")[0],c=document.createElement("style"),c.type="text/css",c.styleSheet?c.styleSheet.cssText=a:c.appendChild(document.createTextNode(a)),b.appendChild(c)},a}(),f.Debug=function(){function a(a){this._isDebug=a,this._gremlins=[],this._broken=[],this._logEl=null,this._createLog(),this._createConsole()}var b,c,d,e,g;return b="debug error info log warn dir dirxml trace assert count markTimeline profile profileEnd time timeEnd timeStamp group groupCollapsed groupEnd".split(" "),c="function"==typeof Function.prototype.bind,d="function"==typeof(null!=(g=window.console)?g.log:void 0),e=function(){},a.prototype._createLog=function(){return this._isDebug?(this._logEl=document.createElement("div"),this._logEl.className="gremlinjs-log",document.body.appendChild(this._logEl)):void 0},a.prototype._createConsole=function(){var a,g,h,i;if(this.console={},this._isDebug&&f.Helper.addStyleSheet(".gremlinjs-log {\nposition: fixed;\nbottom: 0;\nleft: 0;\nbackground: #fff;\npadding: 4px 6px;\n-webkit-box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.3);\nbox-shadow: 0px 0px 4px 0px rgba(0,0,0,0.3);\nz-index: 9999;\n}\n\n.gremlinjs-log p {\n font-size: 12px;\n color: #666666;\n margin: 0;\n padding: 0;\n}\n\n.gremlinjs-log p span {\n display: inline-block;\n margin: 0 5px;\n cursor: help;\n}\n\n.gremlinjs-log p .gremlinjs-log-ready{\ncolor: #41bb19;\n}\n\n.gremlinjs-log p .gremlinjs-log-waiting{\ncolor: #8d46b0;\n}\n\n.gremlinjs-log p .gremlinjs-log-pending{\ncolor: #fff;\nbackground: #fe781e;\npadding: 0 4px;\n}\n\n.gremlinjs-log p .gremlinjs-log-error{\ncolor: #fff;\nbackground: #f50f43;\npadding: 0 4px;\n}\n\n*[data-gremlin-found] {\noutline: 2px solid #41bb19;\n}\n\n*[data-gremlin-found]::before {\ncolor: #41bb19;\nfont-family: monospace;\ncontent: '[' attr(data-gremlin-found) '] ready';\nposition: absolute;\nmargin-top: -14px;\nfont-size: 11px;\nfont-weight: bold;\n}\n\n.gremlin-definition-pending {\noutline: 2px solid #fe781e;\n}\n.gremlin-definition-pending::before {\ncontent: '[' attr(data-gremlin-found) '] definition pendig...';\ncolor: #fe781e;\n}\n.gremlin-error {\noutline: 2px solid red;\n}\n\n.gremlin-error[data-gremlin-found]::before {\ncontent: 'faulty gremlin!';\ncolor: red;\n}"),d&&this._isDebug){for(i=[],g=0,h=b.length;h>g;g++)a=b[g],c?i.push(this.console[a]=console[a]?Function.prototype.bind.call(console[a],console):e):void 0!==console[a]?i.push(this.console[a]=function(){return Function.prototype.apply.call(console[a],console,arguments)}):i.push(this.console[a]=e);return i}for(i=[],g=0,h=b.length;h>g;g++)a=b[g],i.push(this.console[a]=e);return i},a.prototype.registerGremlin=function(a){return this._gremlins.push(a)},a.prototype.reportBrokenGremlin=function(a){return this._broken.push(a)},a.prototype.updateGremlinLog=function(){var a=this;return this._isDebug&&this._logEl?window.setTimeout(function(){var b,c,d,e,f,g,h,i,j,k,l;for(f=0,g={},h=0,i={},d=0,e={},b=a._broken.length,l=a._gremlins,j=0,k=l.length;k>j;j++)c=l[j],c.hasGremlin()?(f++,a._addName(g,c.name)):c.isLazy?(h++,a._addName(i,c.name)):(d++,a._addName(e,c.name));return b='

\n"+f+' ready\n"+h+' lazy waiting\n"+d+" pending\n"+b+" error(s)\n

",a._logEl.innerHTML=b},50):void 0},a.prototype._addName=function(a,b){return a[b]?a[b]++:a[b]=1},a.prototype._getTitle=function(a){var b,c,d;c="";for(b in a)d=a[b],c+=""+d+"x "+b+" \n";return""===c?"":"Gremlins: \n"+c},a}();var g={};g.Configuration=function(){function a(a){this._options=f.Helper.extend({},b,a)}var b;return b={debug:!1},a.prototype.get=function(a){var b;return null!=(b=this._options[a])?b:null},a.options={DEBUG:"debug",AUTOLOAD:"autoload"},a}(),f.ready=window.onDomReady;var d={}.hasOwnProperty,h=function(a,b){function c(){this.constructor=a}for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},i={};i.Gizmo=function(){function a(a,b,c,d){this.el=a,this.data=b,this.id=c,d.call(this)}var b;return b=function(a,b,c,e){var g;if("function"!=typeof b)throw Error("The second parameter when defining a gremlin has to be the constructor function!");if("undefined"!=typeof c&&"object"!=typeof c)throw Error("The third parameter when defining a gremlin has to be an object providing the instance members of the gremlin!");if("undefined"!=typeof e&&"object"!=typeof e)throw Error("The fourth parameter when defining a gremlin has to be an object providing the static members of the gremlin!");a=function(a){function c(){c.__super__.constructor.apply(this,arguments),b.call(this)}return h(c,a),c}(a),f.Helper.mixin(a,c);for(g in e)d.call(e,g)&&(c=e[g],a[g]=c);return a},a.extend=function(a,c,d){return b(this,a,c,d)},a.prototype.data=null,a.prototype.el=null,a.prototype.id=null,a}();var j={};j.ModuleCollection=function(){function a(){}var b,c,d;return d={},c={},b=function(a,b){var e,f,g;if(!c[a]){switch(e=b.include,typeof e){case"string":f=[e];break;case"object":f=Array.isArray(e)?e:[];break;default:f=[]}c[a]=function(){var a,b,c,e;for(e=[],a=0,b=f.length;b>a;a++)g=f[a],e.push(function(){if(null!=(c=d[g]))return c;throw Error("The module "+g+" does not exists!")}());return e}()}return c[a]},a.registerModule=function(a){return d[a.name]=a},a.extendGizmo=function(a,c){var d,e,f,g,h;for(e=b(a,c),h=[],f=0,g=e.length;g>f;f++)d=e[f],h.push(d.extend(c));return h},a.bindGizmo=function(a,c){var d,e,f,g,h;for(e=b(a,c.constructor),h=[],f=0,g=e.length;g>f;f++)d=e[f],h.push(d.bind(c));return h},a}(),i.Pool=function(){function a(){}var b,c;return c=null,b={},a=function(){function a(){}return a.prototype.get=function(a){var c;return null!=(c=b[a])?c:null},a.prototype.set=function(a,c){if("undefined"!=typeof b[a])throw Error("Trying to add new Gremlin definition, but a definition for "+a+" already exists.");return j.ModuleCollection.extendGizmo(a,c),b[a]=c},a.prototype.addClass=function(a,b){if("string"!=typeof a)throw Error("Please provide the name of the gremlin!");if("function"!=typeof b)throw Error("When adding a gremlin, you have to provide a constructor function!");return this.set(a,b),b},a}(),a.getInstance=function(){return null!=c?c:c=new a},a}();var k=function(a,b){return function(){return a.apply(b,arguments)}},l={clocks:{}};l.clocks.LegacyTimeoutClock=function(){function a(){this._onInterval=k(this._onInterval,this)}return a.prototype.observe=function(){return this._initiateInterval()},a.prototype._initiateInterval=function(){return this._interval=window.setTimeout(this._onInterval,500)},a.prototype._onInterval=function(){return this.onMutation(),this._initiateInterval()},a.prototype.onMutation=function(){},a}();var m={};m.NameProvider=function(){function a(){}var b;return b=function(a,b){var c;return"function"==typeof a.hasAttribute?a.hasAttribute(b):(c=a.getAttributeNode(b),!(!c||!c.specified&&!c.nodeValue))},a.DATA_NAME_ATTR="data-gremlin",a.isGremlin=function(a){return b(a,"data-gremlin")},a.getNames=function(a){var b,c;if(b=a.getAttribute("data-gremlin"),""===b)return b=null!=(c=a.outerHTML)?c:"",m.NameProvider.flagBrokenElement(a),r.debug.console.log("Couldn't process gremlin element, no gremlin names available, 'data-gremlin' is empty!\n"+b),[];var d,e;for(d=b.split(","),e=[],c=0,b=d.length;b>c;c++)a=d[c],e.push(a.trim());return e},a.flagBrokenElement=function(a){return f.Helper.addClass(a,"gremlin-error"),m.NameProvider.flagProcessedElement(a),r.debug.reportBrokenGremlin(a)},a.flagProcessedElement=function(a){var b;return b=a.getAttribute("data-gremlin"),a.removeAttribute("data-gremlin"),a.setAttribute("data-gremlin-found",b)},a}(),l.clocks.cssAnimationStyle=function(a){return a="@keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n@-moz-keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n@-webkit-keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n@-o-keyframes {{ANIMATION_NAME}} {\n 0% { opacity: 0.9; }\n 100% { opacity: 1; }\n}\n\n*[{{GREMLIN_ATTRIBUTE}}] {\n animation-duration: 1ms;\n -o-animation-duration: 1ms;\n -moz-animation-duration: 1ms;\n -webkit-animation-duration: 1ms;\n animation-name: {{ANIMATION_NAME}};\n -o-animation-name: {{ANIMATION_NAME}};\n -moz-animation-name: {{ANIMATION_NAME}};\n -webkit-animation-name: {{ANIMATION_NAME}};\n}".replace(/{{ANIMATION_NAME}}/g,a),a.replace(/{{GREMLIN_ATTRIBUTE}}/g,m.NameProvider.DATA_NAME_ATTR)},k=function(a,b){return function(){return a.apply(b,arguments)}},l.clocks.CssAnimationClock=function(){function a(){this._onAnimation=k(this._onAnimation,this);var a;a=l.clocks.cssAnimationStyle(b),f.Helper.addStyleSheet(a)}var b,c;return b="gremlinInserted",c=["animationstart","webkitAnimationStart","oanimationstart"],a.prototype.observe=function(){var a,b,d,e;for(e=[],b=0,d=c.length;d>b;b++)a=c[b],e.push(document.body.addEventListener(a,this._onAnimation,!1));return e},a.prototype._onAnimation=function(a){return a.animationName===b?this.onMutation():void 0},a.prototype.onMutation=function(){},a}(),k=function(a,b){return function(){return a.apply(b,arguments)}},l.clocks.MutationObserverClock=function(){function a(){if(this._onMutation=k(this._onMutation,this),null===b)throw Error("Mutation Observer not available")}var b;return b=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver||null,a.prototype.observe=function(){return new b(this._onMutation).observe(document.body,{childList:!0,subtree:!0})},a.prototype._onMutation=function(a){var b,c,d,e;for(e=[],c=0,d=a.length;d>c;c++){if(b=a[c],"childList"===b.type){this.onMutation();break}e.push(void 0)}return e},a.prototype.onMutation=function(){},a}(),f.FeatureDetector=function(){function a(){}return a.hasQuerySelectorAll="undefined"!=typeof document.querySelectorAll,a.hasMutationObserver=!(!window.MutationObserver&&!window.WebKitMutationObserver&&!window.MozMutationObserver),a.hasGetClientRect=void 0!==document.documentElement.getBoundingClientRect,a.hasCssAnimations=function(){var a,b,c,d;if(c=document.documentElement,a=!1,b=["Webkit","Moz","O","ms","Khtml"],c.style.animationName&&(a=!0),!1===a)for(d=0;dc;c++)a=b[c],e.push(a);return e},a}(),b=function(){function a(){}return a.get=function(a){var b,c,d,e;for(b=document.getElementsByTagName("*"),e=[],c=0,d=b.length;d>c;c++)a=b[c],m.NameProvider.isGremlin(a)&&e.push(a);return e},a}(),d=f.FeatureDetector.hasQuerySelectorAll?c:b,a.prototype.getList=function(){return d.get(this._attributeName)},a}.call(this),k=function(a,b){return function(){return a.apply(b,arguments)}},l.DomObserver=function(){function a(){this._handleMutation=k(this._handleMutation,this),this._elementList=new l.ElementList}return a.prototype._bindMutations=function(){var a;return a=n.get(),a.on(n.ON_MUTATION,this._handleMutation),a.observe()},a.prototype._handleMutation=function(){var a;return a=this._elementList.getList(),0this._el.getBoundingClientRect().top-a):!0},a.prototype._create=function(){return this._gremlinInstance=m.GremlinFactory.getInstance(this._name,this._el,this._data),this.hasGremlin()?(f.Helper.removeClass(this._el,b),f.Helper.removeClass(this._el,"gremlin-definition-pending"),f.Helper.addClass(this._el,"gremlin-ready"),r.emit(r.ON_GREMLIN_LOADED,this._el)):this._triggeredPending?void 0:(this._triggeredPending=!0,f.Helper.addClass(this._el,"gremlin-definition-pending"),r.debug.console.info("Gremlin <"+this._name+"> found in the dom, but there is no definition for it at the moment."),r.emit(r.ON_DEFINITION_PENDING,this._el))},a.prototype.hasGremlin=function(){return null!==this._gremlinInstance},a}(),k=function(a,b){return function(){return a.apply(b,arguments)}},m.GremlinCollection=function(){function a(){this._scrollHandler=k(this._scrollHandler,this),this._queue=[],this._bindScroll(),this._scrollTimer=this._didScroll=!1}return a.prototype._queue=null,a.prototype._bindScroll=function(){return window.addEventListener?window.addEventListener("scroll",this._scrollHandler,!1):window.attachEvent?window.attachEvent("onscroll",this._scrollHandler):void 0},a.prototype.add=function(a){var b,c,d;for(c=0,d=a.length;d>c;c++)b=a[c],this._addGremlinElements(b);return this._processQueue()},a.prototype._addGremlinElements=function(a){var b,c,d,e,f;for(c=m.NameProvider.getNames(a),m.NameProvider.flagProcessedElement(a),f=[],d=0,e=c.length;e>d;d++)b=c[d],f.push(this._queue.push(new m.GremlinDomElement(a,b)));return f},a.prototype._processQueue=function(){var a,b,c,d,e;for(b=[],e=this._queue,c=0,d=e.length;d>c;c++)a=e[c],a.check(),a.hasGremlin()||b.push(a);return this._queue=b,r.debug.updateGremlinLog()},a.prototype.process=function(){return this._processQueue()},a.prototype._scrollHandler=function(){var a=this;return 0===this._queue.length?!0:(this._didScroll||(this._scrollTimer=setInterval(function(){return a._didScroll?(a._didScroll=!1,clearTimeout(a._scrollTimer),a.process()):void 0},250)),this._didScroll=!0)},a}();var p,k=function(a,b){return function(){return a.apply(b,arguments)}};p=function(){function a(){this._onNew=k(this._onNew,this);var a,c;a=null!=(c=new f.ElementData.ElementData(document.body).get(b))?c:{},this.configuration=new g.Configuration(a),this._observer=new l.DomObserver,this._coll=new m.GremlinCollection,this._observer.onNewElements=this._onNew}var b;return b="gremlinConfig",a.prototype._onNew=function(a){return this._coll.add(a)},a.prototype.start=function(){return this._observer.observe()},a.prototype.refresh=function(){return this._coll.process()},a}(),j.Module=function(){return function(a,b){var c,d;if(!(this instanceof j.Module))return function(a,b,c){return c.prototype=a.prototype,c=new c,a=a.apply(c,b),Object(a)===a?a:c}(j.Module,arguments,function(){});if(d="function"==typeof b.extend,c="function"==typeof b.bind,!d)throw Error("Missing .extend method in your module "+a);if(!c)throw Error("Missing .bind method in your module "+a);this.name=a,this.extend=b.extend,this.bind=b.bind,j.ModuleCollection.registerModule(this)}}();var q={};q.Package=function(){function a(a,c){return this instanceof q.Package?(this._package=b(a,c),void 0):function(a,b,c){return c.prototype=a.prototype,c=new c,a=a.apply(c,b),Object(a)===a?a:c}(q.Package,arguments,function(){})}var b,c;return c={},b=function(a,b){var d,e,f,g,h,i;for(null==b&&(b=null),e=a.split("."),f=e.pop(),g=c,h=0,i=e.length;i>h;h++)d=e[h],g=g[d]||(g[d]={});return g[f]=b||g[f]||(g[f]={})},a.require=function(a){return b(a)},a}(),f.polyfill={},"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),Array.prototype.filter||(Array.prototype.filter=function(a,b){var c,d,e,f,g;if("undefined"==typeof this||null===this)throw new TypeError;if(f=Object(this),d=f.length>>>0,"function"!=typeof a)throw new TypeError;for(e=[],c=0;d>c;)c in f&&(g=f[c],a.call(b,g,c,f)&&e.push(g)),c++;return e}),Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){if(null==this)throw new TypeError;var b,c=Object(this),d=c.length>>>0;if(0===d)return-1;if(b=0,10||-1)*Math.floor(Math.abs(b)))),b>=d)return-1;for(b=b>=0?b:Math.max(d-Math.abs(b),0);d>b;b++)if(b in c&&c[b]===a)return b;return-1});var r,d={}.hasOwnProperty,h=function(a,b){function c(){this.constructor=a}for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};r=function(){var a,b;return a=null,b=new(function(b){function c(){c.__super__.constructor.apply(this,arguments),this.debug=new f.Debug(!1)}return h(c,b),c.prototype.ON_ELEMENT_FOUND="elementfound",c.prototype.ON_DEFINITION_PENDING="definitionpending",c.prototype.ON_GREMLIN_LOADED="gremlinloaded",c.prototype.add=function(b,c){return c=i.Pool.getInstance().addClass(b,c),null!=a&&a.refresh(),c},c.prototype.Gizmo=i.Gizmo,c.prototype.Helper=f.Helper,c.prototype.Module=j.Module,c.prototype.Package=q.Package,c}(c)),f.ready(function(){var c;return a=new p,(c=a.configuration.get(g.Configuration.options.DEBUG))&&(b.debug=new f.Debug(c)),a.start(),b.debug.console.log("gremlin.js up and running...")}),b}(),window.Gremlin=r,void 0===window.G&&(window.G=window.Gremlin),"function"==typeof window.define&&window.define.amd&&define("Gremlin",[],function(){return r})}({},function(){return this}()); \ No newline at end of file diff --git a/package.json b/package.json index 08cceb1..8205167 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "GremlinJS", - "version": "0.5.1", + "version": "0.6.0", "main": "./src/scripts/GremlinJS.coffee", "license": "MIT", "repository": { diff --git a/release-notes.md b/release-notes.md index 7569304..b985419 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,5 +1,19 @@ # Release notes +## v0.6.0 *2013-11-10* + +### New + +- `G.Gizmo.extend` to inherit from gremlin classes +- `G.Package.require` to reference packages + +### Removed + +- `G.define`, use `G.Gizmo.extend` +- `G.require`, use `G.Package.require` +- `G.namespace`, `G.ns`, use `G.Package.require` +- `G.Gizmo#klass`, use `G.Gizmo#constructor` + ## v0.5.1 *2013-11-6* ### New diff --git a/src/scripts/Gremlin.coffee b/src/scripts/Gremlin.coffee index 1ade5e9..63c7023 100644 --- a/src/scripts/Gremlin.coffee +++ b/src/scripts/Gremlin.coffee @@ -6,7 +6,6 @@ goog.require 'EventDispatcher' goog.require 'conf.Configuration' goog.require 'util.Helper' goog.require 'util.Debug' -goog.require 'namespace' goog.require 'packages.Package' goog.require 'modules.Module' goog.require 'Application' @@ -31,20 +30,11 @@ Gremlin = do -> app?.refresh() GremlinClass - define: (name, constructor, instanceMembers, staticMembers) -> - GremlinClass = gremlinDefinitions.Pool.getInstance().define name, constructor, instanceMembers, staticMembers - app?.refresh() - GremlinClass - - #derive: (parentName, name, constructor, instanceMembers, staticMembers) -> - Gizmo: gremlinDefinitions.Gizmo + Helper: util.Helper Module: modules.Module - namespace: namespace - ns: namespace Package: packages.Package - require: packages.Package.get g = new GremlinAdapter diff --git a/src/scripts/gremlinDefinitions/Gizmo.coffee b/src/scripts/gremlinDefinitions/Gizmo.coffee index 374dc1e..e0e8731 100644 --- a/src/scripts/gremlinDefinitions/Gizmo.coffee +++ b/src/scripts/gremlinDefinitions/Gizmo.coffee @@ -1,12 +1,38 @@ goog.provide 'gremlinDefinitions.Gizmo' +goog.require 'util.Helper' + class gremlinDefinitions.Gizmo + + define = (Parent, constructor, instanceMembers, staticMembers) -> + unless typeof constructor is 'function' + throw new Error("The second parameter when defining a gremlin has to be the constructor function!") + + unless typeof instanceMembers is 'undefined' or typeof instanceMembers is 'object' + throw new Error("The third parameter when defining a gremlin has to be an object providing the instance members of the gremlin!") + + unless typeof staticMembers is 'undefined' or typeof staticMembers is 'object' + throw new Error("The fourth parameter when defining a gremlin has to be an object providing the static members of the gremlin!") + + + class Gremlin extends Parent + constructor: -> + super + constructor.call this + + util.Helper.mixin Gremlin, instanceMembers + Gremlin[key] = member for own key, member of staticMembers + + return Gremlin + + @extend: (constructor, instanceMembers, staticMembers) -> + define @, constructor, instanceMembers, staticMembers + # @property [Object] the data object holding the dom element's data attributes data: null el: null id: null - klass: null - + # The constructor function used internally to instantiate gremlins. # # diff --git a/src/scripts/gremlinDefinitions/Pool.coffee b/src/scripts/gremlinDefinitions/Pool.coffee index e1eccef..8dfe972 100644 --- a/src/scripts/gremlinDefinitions/Pool.coffee +++ b/src/scripts/gremlinDefinitions/Pool.coffee @@ -1,4 +1,5 @@ goog.provide 'gremlinDefinitions.Pool' + goog.require 'util.Helper' goog.require 'gremlinDefinitions.Gizmo' goog.require 'modules.ModuleCollection' @@ -22,35 +23,6 @@ class gremlinDefinitions.Pool modules.ModuleCollection.extendGizmo name, Definition definitions[name] = Definition - define: (name, constructor, instanceMembers, staticMembers) -> - unless typeof name is 'string' - throw new Error("The first parameter when defining a gremlin has to be a string, the gremlin definition's name!") - - unless typeof constructor is 'function' - throw new Error("The second parameter when defining a gremlin has to be the constructor function!") - - unless instanceMembers is undefined or typeof instanceMembers is 'object' - throw new Error("The third parameter when defining a gremlin has to be an object providing the instance members of the gremlin!") - - unless staticMembers is undefined or typeof staticMembers is 'object' - throw new Error("The fourth parameter when defining a gremlin has to be an object providing the static members of the gremlin!") - - - #constructor = noop if typeof constructor is 'object' - - class Gremlin extends gremlinDefinitions.Gizmo - constructor: -> - super - constructor.call this - - Gremlin::klass = Gremlin - - util.Helper.mixin Gremlin, instanceMembers - Gremlin[key] = member for own key, member of staticMembers - - @set name, Gremlin - return Gremlin - addClass: (name, Gremlin) -> unless typeof name is 'string' throw new Error("Please provide the name of the gremlin!") @@ -58,8 +30,6 @@ class gremlinDefinitions.Pool unless typeof Gremlin is 'function' throw new Error("When adding a gremlin, you have to provide a constructor function!") - Gremlin::klass = Gremlin - @set name, Gremlin return Gremlin diff --git a/src/scripts/modules/ModuleCollection.coffee b/src/scripts/modules/ModuleCollection.coffee index d0d5fc2..51ffc52 100644 --- a/src/scripts/modules/ModuleCollection.coffee +++ b/src/scripts/modules/ModuleCollection.coffee @@ -31,7 +31,7 @@ class modules.ModuleCollection module.extend Gizmo for module in modules @bindGizmo: (name, gizmo) -> - modules = getModules name, gizmo.klass + modules = getModules name, gizmo.constructor module.bind gizmo for module in modules diff --git a/src/scripts/namespace.coffee b/src/scripts/namespace.coffee deleted file mode 100644 index d21ef13..0000000 --- a/src/scripts/namespace.coffee +++ /dev/null @@ -1,3 +0,0 @@ -goog.provide 'namespace' - -namespace = {} diff --git a/src/scripts/packages/Package.coffee b/src/scripts/packages/Package.coffee index 5dbc2ae..5d11488 100644 --- a/src/scripts/packages/Package.coffee +++ b/src/scripts/packages/Package.coffee @@ -1,10 +1,8 @@ goog.provide 'packages.Package' -goog.require 'namespace' - class packages.Package - root = namespace + root = {} getNamespace = (name, content = null) -> items = name.split '.' @@ -19,4 +17,4 @@ class packages.Package return new packages.Package arguments... if this not instanceof packages.Package @_package = getNamespace ns, content - @get: (ns) -> getNamespace ns \ No newline at end of file + @require: (ns) -> getNamespace ns \ No newline at end of file diff --git a/test/js/gremlins/cs/InheritTest.coffee b/test/js/gremlins/cs/InheritTest.coffee new file mode 100644 index 0000000..3277379 --- /dev/null +++ b/test/js/gremlins/cs/InheritTest.coffee @@ -0,0 +1,12 @@ +class window.InheritTestParent extends G.Gizmo + @FOO: 'FOO' + constructor : -> + super + + foo: -> + + bar: 'bar' + +class window.InheritTestChild extends window.InheritTestParent + constructor: -> + super \ No newline at end of file diff --git a/test/js/gremlins/cs/InheritTest.js b/test/js/gremlins/cs/InheritTest.js new file mode 100644 index 0000000..cfd44c4 --- /dev/null +++ b/test/js/gremlins/cs/InheritTest.js @@ -0,0 +1,38 @@ +// Generated by CoffeeScript 1.6.3 +(function() { + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + window.InheritTestParent = (function(_super) { + __extends(InheritTestParent, _super); + + InheritTestParent.FOO = 'FOO'; + + function InheritTestParent() { + InheritTestParent.__super__.constructor.apply(this, arguments); + } + + InheritTestParent.prototype.foo = function() {}; + + InheritTestParent.prototype.bar = 'bar'; + + return InheritTestParent; + + })(G.Gizmo); + + window.InheritTestChild = (function(_super) { + __extends(InheritTestChild, _super); + + function InheritTestChild() { + InheritTestChild.__super__.constructor.apply(this, arguments); + } + + return InheritTestChild; + + })(window.InheritTestParent); + +}).call(this); + +/* +//@ sourceMappingURL=InheritTest.map +*/ diff --git a/test/js/gremlins/cs/InheritTest.map b/test/js/gremlins/cs/InheritTest.map new file mode 100644 index 0000000..ca0438b --- /dev/null +++ b/test/js/gremlins/cs/InheritTest.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "InheritTest.js", + "sourceRoot": "", + "sources": [ + "InheritTest.coffee" + ], + "names": [], + "mappings": ";AAAA;CAAA,KAAA;oSAAA;;CAAA,CAAM,IAAM;CACV;;CAAA,EAAA,CAAA,CAAA,YAAC;;CACa,EAAA,CAAA,uBAAA;CACZ,KAAA,GAAA,2CAAA;CAFF,IACc;;CADd,EAIA,MAAK;;CAJL,EAMA,EANA;;CAAA;;CADqC;;CAAvC,CASM,IAAM;CACV;;CAAa,EAAA,CAAA,sBAAA;CACX,KAAA,GAAA,0CAAA;CADF,IAAa;;CAAb;;CADoC,KAAM;CAT5C" +} \ No newline at end of file diff --git a/test/spec/Gremlin.js b/test/spec/Gremlin.js index 7619b0a..a51444e 100644 --- a/test/spec/Gremlin.js +++ b/test/spec/Gremlin.js @@ -7,15 +7,17 @@ describe('Gremlin', function () { }); it('should expose the main gremlin.js API', function () { - //expect(G).to.have.property('add', 'debug','define','Gizmo','Helper','on','registerExtension','ON_ELEMENT_FOUND','ON_DEFINITION_PENDING','ON_GREMLIN_LOADED'); expect(G).to.have.property('add') expect(G.add).to.be.a('function'); expect(G).to.have.property('debug'); expect(G.debug).to.be.a(util.Debug); - expect(G).to.have.property('define'); - expect(G.define).to.be.a('function'); + expect(G).to.have.property('Module'); + expect(G.Module).to.be.a('function'); + + expect(G).to.have.property('Package'); + expect(G.Package).to.be.a('function'); expect(G).to.have.property('Gizmo'); expect(G.Gizmo).to.equal(gremlinDefinitions.Gizmo); @@ -57,28 +59,80 @@ describe('Gremlin', function () { }); - it('can define new gremlin classes', function () { + it('can inherit from gremlin classes', function (done) { + + var elChild = document.createElement('div'), + elChildCoffee = document.createElement('div'); + elChild.setAttribute('data-gremlin', 'InheritChild'); + elChildCoffee.setAttribute('data-gremlin', 'InheritChild2'); + + document.body.appendChild(elChild); + document.body.appendChild(elChildCoffee); + + var Parent = G.Gizmo.extend(function () { + }, + { + foo: 'bar' + }, { + FOO: "BAR" + }); + + var Child = Parent.extend(function () { + try { + expect(this.el).to.equal(elChild); + expect(this.constructor).to.equal(Child); + done(); + } catch (e) { + done(e); + } + }, + { + + }, { + + }); + + G.add('InheritParent', Parent); + G.add('InheritChild', Child); + + expect(Child).to.have.property('FOO'); + expect(Child.FOO).to.equal('BAR'); + + expect(Child.prototype).to.have.property('foo'); + expect(Child.prototype.foo).to.equal('bar'); + + expect(InheritTestChild).to.have.property('FOO'); + expect(InheritTestChild.FOO).to.equal('FOO'); + + expect(InheritTestChild.prototype).to.have.property('foo'); + expect(InheritTestChild.prototype).to.have.property('bar'); + expect(InheritTestChild.prototype.foo).to.be.a('function'); + expect(InheritTestChild.prototype.bar).to.equal('bar'); + + }) + + it('can create new gremlin classes without coffeescript', function () { expect(function () { - G.define('DefineTest'); + G.add('DefineTest'); }).to.throwError(Error); expect(function () { - G.define(function () { - }); + G.Gizmo.extend(); }).to.throwError(Error); expect(function () { - G.define('DefineTest', function () { + G.Gizmo.extend(function () { }, 'foo', 'foo'); }).to.throwError(Error); expect(function () { - G.define('DefineTest', function () { + G.Gizmo.extend(function () { }, function () { }); }).to.throwError(Error); - var TestGremlin = G.define('DefineTest', function () { + + var TestGremlin = G.Gizmo.extend(function () { }, { foo: 'bar' }, { @@ -102,10 +156,10 @@ describe('Gremlin', function () { document.body.appendChild(el); document.body.appendChild(elCoffee); - var TestGremlin = G.define('CreateTest', function () { + var TestGremlin = G.Gizmo.extend(function () { try { expect(this.el).to.equal(el); - expect(this.klass).to.equal(TestGremlin); + expect(this.constructor).to.equal(TestGremlin); expect(this.id).to.be.a('number'); expect(this.data).to.be.an('object'); //done(); @@ -114,6 +168,8 @@ describe('Gremlin', function () { } }); + + TestGremlin = G.add('CreateTest', TestGremlin); var CreateTestGremlin = G.add('CreateTestCoffee', CreateTest); window.setTimeout(function () { @@ -121,7 +177,7 @@ describe('Gremlin', function () { var g = elCoffee.__gremlin; expect(elCoffee.className).to.equal('gremlin-ready'); expect(g.el).to.equal(elCoffee); - expect(g.klass).to.equal(CreateTestGremlin); + expect(g.constructor).to.equal(CreateTestGremlin); expect(g.id).to.be.a('number'); expect(g.data).to.be.an('object'); done(); @@ -150,7 +206,7 @@ describe('Gremlin', function () { el.setAttribute('data-with-long-name', 'foo'); document.body.appendChild(el); - var TestGremlin = G.define('DataTest', function () { + var TestGremlin = G.Gizmo.extend(function () { try { expect(this.data).to.have.property('string') expect(this.data.string).to.be('foo'); @@ -175,6 +231,8 @@ describe('Gremlin', function () { done(e); } }); + + G.add('DataTest', TestGremlin); }); it('puts unavailble gremlins into a queue', function (done) { @@ -216,7 +274,7 @@ describe('Gremlin', function () { el.style.marginTop = "3000px"; document.body.appendChild(el); - G.define('LazyTest', function () { + var LazyTest = G.Gizmo.extend(function () { try { expect(this.el).to.equal(el); done(); @@ -226,6 +284,8 @@ describe('Gremlin', function () { done(e); } }); + G.add('LazyTest', LazyTest); + window.setTimeout(function () { try { expect(el.className).to.equal('gremlin-loading'); @@ -292,8 +352,10 @@ describe('Gremlin', function () { G.on(G.ON_GREMLIN_LOADED, onCreated); document.body.appendChild(el); - G.define('EventOnLoadedTest', function () { + var EventOnLoadedTest = G.Gizmo.extend(function () { }); + + G.add('EventOnLoadedTest', EventOnLoadedTest); }); }); \ No newline at end of file diff --git a/test/spec/modules/Module.js b/test/spec/modules/Module.js index e250b3b..c0393bb 100644 --- a/test/spec/modules/Module.js +++ b/test/spec/modules/Module.js @@ -68,9 +68,9 @@ describe('modules.Module', function () { } }); - TestGremlin = G.define('ModuleTest', function () { + TestGremlin = G.Gizmo.extend(function () { try { - expect(this.klass.FOO).to.equal("BAR"); + expect(this.constructor.FOO).to.equal("BAR"); expect(this.onClick()).to.equal("onClick"); //done(); } catch (e) { @@ -82,10 +82,12 @@ describe('modules.Module', function () { include: 'moduleTestModule' } ); - TestGremlin2 = G.define('ModuleTest2', function () { + G.add('ModuleTest', TestGremlin); + + TestGremlin2 = G.Gizmo.extend(function () { try { - expect(this.klass.FOO).to.equal("BAR"); - expect(this.klass.BAZ).to.equal("BOZ"); + expect(this.constructor.FOO).to.equal("BAR"); + expect(this.constructor.BAZ).to.equal("BOZ"); expect(this.onClick()).to.equal("onClick"); expect(this.onWhatever()).to.equal("onWhatever"); done(); @@ -98,16 +100,19 @@ describe('modules.Module', function () { include: ['moduleTestModule', 'moduleTestModule2'] } ); + G.add('ModuleTest2', TestGremlin2); - expect(function () { - TestGremlin3 = G.define('ModuleTest3', function () { - }, - {}, - { - include: ['foo'] - } - ); + TestGremlin3 = G.Gizmo.extend(function () { + }, + {}, + { + include: ['foo'] + } + ); + + expect(function () { + G.add('ModuleTest3', TestGremlin3); }).to.throwError(); }); }); \ No newline at end of file diff --git a/test/spec/packages/Package.js b/test/spec/packages/Package.js index ce275d1..448974c 100644 --- a/test/spec/packages/Package.js +++ b/test/spec/packages/Package.js @@ -1,11 +1,4 @@ describe('packages.Package', function () { - it('has a namespace for all packages', function () { - - expect(namespace).to.equal(G.namespace); - expect(namespace).to.be.an('object'); - - }); - it('can add packages', function () { expect(packages.Package).to.equal(G.Package); @@ -19,10 +12,7 @@ describe('packages.Package', function () { G.Package(ns, data); - var thePackage = G.require('foo.bar'); - expect(G.namespace.foo.bar).to.equal(data); - expect(G.namespace.foo.bar).to.equal(G.Package.get(ns)); - expect(G.Package.get(ns)).to.equal(data); + var thePackage = G.Package.require('foo.bar'); expect(thePackage).to.equal(data); }); diff --git a/test/test.html b/test/test.html index 6aa2e8b..de826e0 100644 --- a/test/test.html +++ b/test/test.html @@ -23,6 +23,7 @@ src="vendor/mantri.web.js"> +