diff --git a/source/jails.js b/source/jails.js index fa6c52d..d1718aa 100755 --- a/source/jails.js +++ b/source/jails.js @@ -129,7 +129,6 @@ define(function(){ } } - modules = null; }, @@ -170,7 +169,7 @@ define(function(){ }; this.x = function(target){ - target = $(dom.querySelectorAll(target)); + target = element.find(target); return function(){ var args = slice.call( arguments ); target.trigger('execute', {args :args}); @@ -232,6 +231,7 @@ define(function(){ }; this.render = function(vo, template){ + var tmpl = template || tpl; this.partial(element, tmpl, vo); }; @@ -332,7 +332,6 @@ define(function(){ _class :function( name, element ){ var _self = this; - this.name = name; Module.common._class.apply(this, [name, element]); diff --git a/source/jails.min.js b/source/jails.min.js index bb94c99..b0aa143 100755 --- a/source/jails.min.js +++ b/source/jails.min.js @@ -1 +1 @@ -define(function(){function t(t){var n=t.html(),a=e("
"),i=e("
");return i.append(n),i.find("[data-if]").each(function(){var t=e(this),n=t.data("if");t.before("{{#"+n+"}}"),t.after("{{/"+n+"}}")}),i.find("[data-not]").each(function(){var t=e(this),n=t.data("not");t.before("{{^"+n+"}}"),t.after("{{/"+n+"}}")}),i.find("[data-each]").each(function(){var t=e(this),n=t.children().eq(0),i=t.data("each");a.empty().append(n),t.html("{{#"+i+"}}"+a.html()+"{{/"+i+"}}")}),i.find("[data-value]").each(function(){var t=e(this),n=t.data("value"),a=n.split(/\:/);t.html(a[1]?"{{#"+a[1]+"}}{{"+a[0]+"}}{{/"+a[1]+"}}":"{{"+n+"}}")}),i.find("[data-out]").each(function(){e(this).before("{{#out}}").after("{{/out}}")}),e.trim(i.html().replace(/(data-attr)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/g,function(t,n,e){return e}))}var n,e,a,i,r,s={};i=Array.prototype.slice,r={partial:0,component:1,controller:2,app:3},n={config:{templates:{type:"x-tmpl-mustache"}},context:null,start:function(t,i){e=t.base,n.context=e(document.documentElement),a=e(""),e.extend(!0,n.config,t),o.start(i),n.context.addClass("ready")},refresh:function(t){o.start(t)},data:function(){return s}};var o={start:function(t){var e,a=[];t=t||n.context,e=n.config.templates.type,o.scan("partial","script[type="+e+"]",t,a),o.scan("component","[data-component]",t,a),o.scan("controller","[data-controller]",t,a),o.scan("app","[data-app]",t,a),c.start(a)},scan:function(t,a,i,r){i=i||n.context;var s,c,l,u;c=i.get(0).querySelectorAll(a),l=c.length;for(var f=0;l>f;f++)s=e(c[f]),u=o[t],u?u(t,s,r):o.module(t,s,r)},module:function(t,e,a){var i,r,o="s";i=e.data(t),r=n[t+o][i],r=r?new r(e,s):new c[t]._class(i,e,t),a.push(r)},partial:function(t,a){var i=n.config.templates.prefix,r=a.prop("id").split(i||"tmpl-").pop();n.templates[r]=e.trim(a.html())},component:function(t,a,i){var r,s,l,u;r=a.data(t),u=o.annotations(r,a),s=r.replace(/\s/g,"").split(/\,/),e.each(s,function(e,r){l=n.components[r],l=l?new l(a,r in u?u[r]:{}):new c[t]._class(r,a),i.push(l)})},annotations:function(t,n){var e,a,i={};return e=n.get(0).previousSibling,e=e?e.previousSibling:null,e&&8==e.nodeType&&(a=e.data.replace(/\@(.*)\((\{.*\})\)/g,function(t,n,e){i[n]=new Function("return "+e)()})),i}},c={start:function(t){for(var n=t.length,e=0;n>e;e++)t[e].init&&t[e].init();t=null},common:{_class:function(t,n){var e=this;this.name=t,n.on("execute",function(n,a){var i=[].concat(a.args),r=i.shift(),s=e[r];s?s.apply(e,i):console.warn("Jails@warning =>",t,"has no method :",r),n.stopPropagation()})}},app:{_class:function(t,n){c.common._class.apply(this,[t,n]);var r=n.get(0);this.watch=function(t,e,a){n.on(e,t,a)},this.x=function(t){return t=e(r.querySelectorAll(t)),function(){var n=i.call(arguments);t.trigger("execute",{args:n})}},this.listen=function(t,e){n.on(t,function(t,n){e.apply(n.element,[t].concat(n.args))})},this.emit=function(e,a){a=i.call(arguments),a.shift(),n.trigger(t+":"+e,{args:a,element:r})},this.publish=function(t,n){n=i.call(arguments),n.shift(),a.trigger(t,{args:n,element:r})},this.subscribe=function(t,n){a.on(t,function(t,e){n.apply(e.element,[t].concat(e.args))})}}},controller:{_class:function(t,n){c.app._class.apply(this,[t,n]),n.is("[data-template]")&&c.view._class.apply(this,[t,n])}},view:{_class:function(a,i){function r(t){return t?u[t]:null}var c,l,u,f,h=this;l=n.config.templates,u=n.templates,c=r(i.data("template"))||t(i),f=i.data("render"),this.template=function(t,n){return l.engine.render(r(n),t,u)},this.render=function(t,n){var e=n||c;this.partial(i,e,t)},this.partial=function(t,a,i){var r,s;i=i||{},a=u[a]||a,i&&i.done?i.done(function(n){h.partial(t,a,n)}):(r=e.extend({},i,n.filters),s=l.engine.render(a||c,r,u),t.html(s),o.start(t))},f?this.render(s):null}},model:{_class:function(t){var n={};this.name=t,this.data=function(t,a){return t?(n=t,a&&(n=this.transform(a,t)),e?e(this).trigger("change",n):null,void 0):n},this.on=function(t,n){e(this).on(t,function(t,e){n.call(this,e)})},this.trigger=function(t,n){e(this).trigger(t,n)},this.find=function(t){return n[t]},this.remove=function(t){delete n[t],this.trigger("change",n)},this.update=function(t,e){n[t]=e,this.trigger("change",n)},this.to_array=function(){return e.map(n,function(t){return[t]})},this.transform=function(t,e){e=e||n,e=e.push?e:[e];var a,i,r={},s=e.length;for(a=0;s>a;a++)i=e[a],r[i[t||a]]=i;return count=a,r}}},component:{_class:function(t,n){this.name=t,c.common._class.apply(this,[t,n]),this.emit=function(e,a){a=i.call(arguments),a.shift(),n.trigger(t+":"+e,{args:a,element:n.get(0)})},this.listen=function(t,e){n.on(t,function(t,n){e.apply(n.element,[t].concat(n.args))})}}}},l={_class:function(){function t(t,e,a){return this instanceof n[t]?void c[t]._class.call(this,arguments[2],arguments[1]):this[t+"s"][e]=function(n,i){c[t]._class.call(this,e,n),a.call(this,n,i)}}this.apps={},this.controllers={},this.models={},this.components={},this.templates={},this.filters={},this.controller=function(n,e){return t.call(this,"controller",n,e)},this.component=function(n,e){t.call(this,"component",n,e)},this.app=function(n,e){t.call(this,"app",n,e)},this.filter=function(t,n){this.filters[t]=function(){return function(t,e){return n(e(t))}}},this.model=function(t,e){if(!(this instanceof n.model)){n.models[t]=e;var a=new c.model._class(t);return e.apply(a),a}c.model._class.call(this,t)},this.filter("out",function(t){var n=e(t),a=e("
"),i=n.data("out");return n.html(new Function("return "+i)()),a.append(n),a.html()})}};return l._class.apply(n),n}); +define(function(){function t(t){var n=t.html(),a=e("
"),i=e("
");return i.append(n),i.find("[data-if]").each(function(){var t=e(this),n=t.data("if");t.before("{{#"+n+"}}"),t.after("{{/"+n+"}}")}),i.find("[data-not]").each(function(){var t=e(this),n=t.data("not");t.before("{{^"+n+"}}"),t.after("{{/"+n+"}}")}),i.find("[data-each]").each(function(){var t=e(this),n=t.children().eq(0),i=t.data("each");a.empty().append(n),t.html("{{#"+i+"}}"+a.html()+"{{/"+i+"}}")}),i.find("[data-value]").each(function(){var t=e(this),n=t.data("value"),a=n.split(/\:/);t.html(a[1]?"{{#"+a[1]+"}}{{"+a[0]+"}}{{/"+a[1]+"}}":"{{"+n+"}}")}),i.find("[data-out]").each(function(){e(this).before("{{#out}}").after("{{/out}}")}),e.trim(i.html().replace(/(data-attr)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/g,function(t,n,e){return e}))}var n,e,a,i,r,s={};i=Array.prototype.slice,r={partial:0,component:1,controller:2,app:3},n={config:{templates:{type:"x-tmpl-mustache"}},context:null,start:function(t,i){e=t.base,n.context=e(document.documentElement),a=e(""),e.extend(!0,n.config,t),o.start(i),n.context.addClass("ready")},refresh:function(t){o.start(t)},data:function(){return s}};var o={start:function(t){var e,a=[];t=t||n.context,e=n.config.templates.type,o.scan("partial","script[type="+e+"]",t,a),o.scan("component","[data-component]",t,a),o.scan("controller","[data-controller]",t,a),o.scan("app","[data-app]",t,a),c.start(a)},scan:function(t,a,i,r){i=i||n.context;var s,c,l,u;c=i.get(0).querySelectorAll(a),l=c.length;for(var f=0;l>f;f++)s=e(c[f]),u=o[t],u?u(t,s,r):o.module(t,s,r)},module:function(t,e,a){var i,r,o="s";i=e.data(t),r=n[t+o][i],r=r?new r(e,s):new c[t]._class(i,e,t),a.push(r)},partial:function(t,a){var i=n.config.templates.prefix,r=a.prop("id").split(i||"tmpl-").pop();n.templates[r]=e.trim(a.html())},component:function(t,a,i){var r,s,l,u;r=a.data(t),u=o.annotations(r,a),s=r.replace(/\s/g,"").split(/\,/),e.each(s,function(e,r){l=n.components[r],l=l?new l(a,r in u?u[r]:{}):new c[t]._class(r,a),i.push(l)})},annotations:function(t,n){var e,a,i={};return e=n.get(0).previousSibling,e=e?e.previousSibling:null,e&&8==e.nodeType&&(a=e.data.replace(/\@(.*)\((\{.*\})\)/g,function(t,n,e){i[n]=new Function("return "+e)()})),i}},c={start:function(t){for(var n=t.length,e=0;n>e;e++)t[e].init&&t[e].init();t=null},common:{_class:function(t,n){var e=this;this.name=t,n.on("execute",function(n,a){var i=[].concat(a.args),r=i.shift(),s=e[r];s?s.apply(e,i):console.warn("Jails@warning =>",t,"has no method :",r),n.stopPropagation()})}},app:{_class:function(t,n){c.common._class.apply(this,[t,n]);var e=n.get(0);this.watch=function(t,e,a){n.on(e,t,a)},this.x=function(t){return t=n.find(t),function(){var n=i.call(arguments);t.trigger("execute",{args:n})}},this.listen=function(t,e){n.on(t,function(t,n){e.apply(n.element,[t].concat(n.args))})},this.emit=function(a,r){r=i.call(arguments),r.shift(),n.trigger(t+":"+a,{args:r,element:e})},this.publish=function(t,n){n=i.call(arguments),n.shift(),a.trigger(t,{args:n,element:e})},this.subscribe=function(t,n){a.on(t,function(t,e){n.apply(e.element,[t].concat(e.args))})}}},controller:{_class:function(t,n){c.app._class.apply(this,[t,n]),n.is("[data-template]")&&c.view._class.apply(this,[t,n])}},view:{_class:function(a,i){function r(t){return t?u[t]:null}var c,l,u,f,h=this;l=n.config.templates,u=n.templates,c=r(i.data("template"))||t(i),f=i.data("render"),this.template=function(t,n){return l.engine.render(r(n),t,u)},this.render=function(t,n){var e=n||c;this.partial(i,e,t)},this.partial=function(t,a,i){var r,s;i=i||{},a=u[a]||a,i&&i.done?i.done(function(n){h.partial(t,a,n)}):(r=e.extend({},i,n.filters),s=l.engine.render(a||c,r,u),t.html(s),o.start(t))},f?this.render(s):null}},model:{_class:function(t){var n={};this.name=t,this.data=function(t,a){return t?(n=t,a&&(n=this.transform(a,t)),e?e(this).trigger("change",n):null,void 0):n},this.on=function(t,n){e(this).on(t,function(t,e){n.call(this,e)})},this.trigger=function(t,n){e(this).trigger(t,n)},this.find=function(t){return n[t]},this.remove=function(t){delete n[t],this.trigger("change",n)},this.update=function(t,e){n[t]=e,this.trigger("change",n)},this.to_array=function(){return e.map(n,function(t){return[t]})},this.transform=function(t,e){e=e||n,e=e.push?e:[e];var a,i,r={},s=e.length;for(a=0;s>a;a++)i=e[a],r[i[t||a]]=i;return count=a,r}}},component:{_class:function(t,n){c.common._class.apply(this,[t,n]),this.emit=function(e,a){a=i.call(arguments),a.shift(),n.trigger(t+":"+e,{args:a,element:n.get(0)})},this.listen=function(t,e){n.on(t,function(t,n){e.apply(n.element,[t].concat(n.args))})}}}},l={_class:function(){function t(t,e,a){return this instanceof n[t]?void c[t]._class.call(this,arguments[2],arguments[1]):this[t+"s"][e]=function(n,i){c[t]._class.call(this,e,n),a.call(this,n,i)}}this.apps={},this.controllers={},this.models={},this.components={},this.templates={},this.filters={},this.controller=function(n,e){return t.call(this,"controller",n,e)},this.component=function(n,e){t.call(this,"component",n,e)},this.app=function(n,e){t.call(this,"app",n,e)},this.filter=function(t,n){this.filters[t]=function(){return function(t,e){return n(e(t))}}},this.model=function(t,e){if(!(this instanceof n.model)){n.models[t]=e;var a=new c.model._class(t);return e.apply(a),a}c.model._class.call(this,t)},this.filter("out",function(t){var n=e(t),a=e("
"),i=n.data("out");return n.html(new Function("return "+i)()),a.append(n),a.html()})}};return l._class.apply(n),n});