jscow-application-environment
Version:
jsCow - Application Environment - Javascript Component Framework
1 lines • 25.2 kB
JavaScript
jsCow=function(){var jsCowBase=function(){this.config={version:"2.0.0",url:{base:""},zIndex:1},this.componentsObjectList=[],this.res={core:{mvc:{},events:{}},components:{},model:{},view:{},controller:{}},this.events={},this.cache={},this.debug={events:!1,controller:!1,model:!1,view:!1}};return jsCowBase.prototype={nextZIndex:function(){return this.config.zIndex++,this.config.zIndex},cache:function(index,value){if(index&&value)void 0===this.cache[index]&&(this.cache[index]=!1),this.cache[index]=value;else{if(!index)return this.cache;if(this.cache[index])return this.cache[index]}return this},removeCache:function(index){return delete this.cache[index],this},del:function(cmp){var list=this.componentsObjectList;return $.each(list,function(i,c){"undefined"!==c&&c.getID()===cmp.getID()&&(c.view().removeAll(),list.splice(i,1))}),this},get:function(cmp,preConfig){return this.components.get(cmp,preConfig)},find:function(cmp){return this.components.find(cmp)}},new jsCowBase}();var component=function(){};component.prototype={get:function(cmpClassReference,preConfig){var c=new cmpClassReference;if("object"==typeof c){"undefined"!=typeof preConfig?c.__preConfig__=preConfig:c.__preConfig__={},c.events=!1,c.__model__=!1,c.__view__=!1,c.__controller__=!1,c.__cfg__={},c.__cfg__.parent=!1,c.__cfg__.dom=!1,c.__cfg__.layerindex=0,c.__cfg__.initialized=[],c.__cfg__.__execInit__=!1,c.__cfg__.rendered=!1,c.__cfg__.placeholder=!1,c.__cfg__.id=!1,c.__cfg__.target=!1,c.__children__=[],c.extension=!1,c=$.extend(!0,c,{add:function(childs){var list=[];return childs instanceof Array?list=childs:list.push(childs),$.each(list,function(self){return function(i,child){if("object"==typeof child&&!child.__cfg__.__execInit__){var content=self.view().content();content?content.append(child.placeholder()):content=self.placeholder(),child.parent(self),child.target(content),self.__children__.push(child)}}}(this)),this},createPlaceholder:function(index){var ph=$('<div class="jsc-ph-'+index+'"></div>');return this.placeholder(ph),ph},placeholder:function(placeholder){return placeholder?(this.__cfg__.placeholder=placeholder,this.__cfg__.placeholder.appendTo(this.target()),this):this.__cfg__.placeholder},target:function(t){var target=t;return"undefined"==typeof target?(this.__cfg__.target||(this.__cfg__.target=$("body")),this.__cfg__.target):(this.parent()||"undefined"!=typeof target?(this.__cfg__.target=target,this.placeholder().appendTo(this.__cfg__.target)):(this.__cfg__.target=$("body"),target=this.__cfg__.target),this.children.length&&$.each(this.children,function(i,child){child.target(target)}),this)},defineVariables:function(){this.__preConfig__||(this.__preConfig__={}),this.__children__||(this.__children__=[]),this.extension||(this.extension={}),this.__cfg__||(this.__cfg__={}),this.__cfg__.__execInit__||(this.__cfg__.__execInit__=!1),this.__cfg__.apps||(this.__cfg__.apps=[]),this.__cfg__.parent||(this.__cfg__.parent=!1),this.__cfg__.dom||(this.__cfg__.dom={}),this.__cfg__.rendered||(this.__cfg__.rendered=[]),this.__cfg__.placeholder||(this.__cfg__.placeholder=!1),this.__cfg__.initialized||(this.__cfg__.initialized=[]),this.__cfg__.target||(this.__cfg__.target=!1),this.events||(this.events=!1),this.__model__||(this.__model__={}),this.__view__||(this.__view__=[]),this.__controller__||(this.__controller__=[])},append:function(child){return window.setTimeout(function(self,child){return function(){child.config.__execInit__||"object"!=typeof child||(self.add(child),child.__init())}}(this,child),0),this},appendInner:function(child,target){return window.setTimeout(function(self){return function(){if(self.defineVariables(),target&&!child.config.__execInit__&&"object"==typeof child){var placeholder=self.createPlaceholder();target.append(placeholder),child.parent(self),child.placeholder(placeholder),child.target(target),self.__children__.push(child),child.__init()}}}(this),0),child},appendAfterInner:function(child,target){return child.defineVariables(),target&&!child.config.__execInit__&&"object"==typeof child&&(child.parent(this),child.target(this.target()),child.placeholder(!1),target.view().getDomMain().after(child.view().getDomMain()),this.__children__.push(child),child.__init()),child},del:function(){"undefined"!=typeof this.parent()&&this.parent()&&this.parent().remove(this);var list=this.__children__;return list.length>0&&$(list).each(function(i,c){c.del()}),this},remove:function(cmp){var self=this,list=this.__children__;return"undefined"!=typeof cmp?list.length>0&&$(list).each(function(i,c){"undefined"!=typeof c&&"object"==typeof cmp&&"undefined"!=typeof cmp&&c.id()===cmp.id()&&(self.__children__.splice(i,1),c.del())}):"string"!=typeof cmp&&"*"===cmp&&list.length>0&&$(list).each(function(i,c){"undefined"!=typeof c&&(self.__children__.splice(i,1),c.del())}),this},run:function(){this.__init()},__init:function(){this.readyToShow(this),this.extension.init&&"function"==typeof this.extension.init&&this.extension.init(),this.__children__.length?$.each(this.__children__,function(i,c){c.__init()}):this.__show(!0),this.__cfg__.__execInit__=!0,this.events.trigger("init")},__show:function(showNow){this.showComplete(this),(showNow||this.__cfg__.rendered.length===this.__children__.length)&&(this.view().init(),this.events.trigger("controller.init"),this.parent()&&this.parent().__show())},extend:function(method,root){var methodList;if(root===!0)$.extend(!0,this,method);else{var _this=this;if(this.extension)methodList={},$.each(method,function(i,m){methodList[i]=function(_super,m,i){return m._super="function"==typeof _super[i]?_super[i]:function(){},function(){m.apply(_super,arguments)}}(_this,m,i)}),$.extend(!0,this.extension,methodList);else{var ext=function(){};methodList={},$.each(method,function(i,m){methodList[i]=function(_super,m,i){return m._super="function"==typeof _super[i]?_super[i]:function(){},function(){m.apply(_super,arguments)}}(_this,m,i)}),$.extend(!0,ext.prototype,methodList),this.extension=new ext}}return this},move:function(target){if("undefined"!==target&&"object"==typeof target){var targetViewContent=target.view().content();if(this.view().appendTo(targetViewContent),this.parent()){var parentChildIndex=this.parent().children().indexOf(this);this.parent().children().splice(parentChildIndex,1),this.parent(target)}target.__children__.push(this)}return this},id:function(id){return id?(this.__cfg__.id=id,this.trigger("update.id",{id:id}),this):this.__cfg__.id},children:function(){return this.__children__},model:function(){return"undefined"!==this.__model__&&this.__model__?this.__model__:!1},view:function(){return void 0===this.__view__?!1:this.__view__},controller:function(){return void 0===this.__controller__?!1:this.__controller__},config:function(config,value){if(config&&value)this.model().data[config]=value,this.trigger("update",this.config());else{if(!config)return this.model().data;$.extend(!0,this.model().data,config),this.trigger("update",this.config())}return this},parent:function(parent){return parent?(this.__cfg__.parent=parent,this):this.__cfg__.parent},readyToShow:function(c){return this.__cfg__.initialized&&(this.__cfg__.initialized=[]),this.__cfg__.initialized.push(c),this},showComplete:function(c){return this.__cfg__.rendered||(this.__cfg__.rendered=[]),this.__cfg__.rendered.push(c),this},eventsManager:function(eventsManager){eventsManager.cmp(this),this.events=eventsManager},addModel:function(m){this.__model__=new m,this.__model__.__controller__=this.__controller__,"undefined"==typeof this.__model__.data&&(this.__model__.data={});var eventsManager=new jsCow.res.core.events.eventsManager;return eventsManager.cmp(this),eventsManager.parent(this.__model__),this.__model__.events=eventsManager,$.extend(!0,this.__model__,{reset:function(index){return index?this.data[index]&&("object"==typeof this.data[index]&&(this.data[index]={}),"string"==typeof this.data[index]&&(this.data[index]=""),this.data[index]instanceof Array&&(this.data[index]=[])):("object"==typeof this.data&&(this.data={}),"string"==typeof this.data&&(this.data=""),this.data instanceof Array&&(this.data=[])),this},update:function(e){return this.data=$.extend(!0,this.data,e.data),this.trigger("update",this.data),this},id:function(id){return id?(this.__id__=id,this):this.__id__},on:function(event,handler,local){return this.events.on(event,handler,local),this},trigger:function(event,data,local){return this.events.trigger(event,data,local),this},bubbleIn:function(event,data,local){return this.events.bubbleIn(event,data,local),this},bubbleOut:function(event,data,local){return this.events.bubbleOut(event,data,local),this},bubble:function(event,data,local){return this.events.bubble(event,data,local),this}}),this.__model__.id("m"+((new Date).getTime()+""+Math.floor(1e6*Math.random())).substr(0,18)),this.__model__.on("controller.init",this.__model__.init),this.__model__.on("model.update",this.__model__.update),this},addView:function(v){return this.__view__.add(v),this},deleteView:function(v){return this.__view__.del(v),this},deleteController:function(c){return this.__controller__.del(c),this},replaceController:function(o,n){return this.__controller__.replace(o,n),this},addController:function(c){return this.__controller__.add(c),this},replaceView:function(o,n){return this.__view__.replace(o,n),this},cfg:function(option,value){return option&&value?(void 0===this.__cfg__[option]&&(this.__cfg__[option]=!1),this.__cfg__[option]=value,this):option&&!value?("object"==typeof option&&$.extend(!0,this.__cfg__,option),this):this.__cfg__},on:function(event,handler,local){return"undefined"!=typeof this.events.on&&this.events.on(event,handler,local),this},trigger:function(event,data,local){return"undefined"!=typeof this.events.trigger&&this.events.trigger(event,data,local),this},bubbleIn:function(event,data,local){return"undefined"!=typeof this.events.bubbleIn&&this.events.bubbleIn(event,data,local),this},bubbleOut:function(event,data,local){return"undefined"!=typeof this.events.bubbleOut&&this.events.bubbleOut(event,data,local),this},bubble:function(event,data,local){return"undefined"!=typeof this.events.bubble&&this.events.bubble(event,data,local),this},isEnabled:function(){var c=this.config();return c.enabled===!1||"undefined"==typeof c.enabled?!1:!0},disable:function(bubble){return"undefined"!=typeof bubble&&bubble?this.bubbleIn("disable",{__forcedEnable__:!0}):this.trigger("disable",{__forcedEnable__:!0}),this},enable:function(bubble){return"undefined"!=typeof bubble&&bubble?this.bubbleIn("enable",{__forcedEnable__:!0}):this.trigger("enable",{__forcedEnable__:!0}),this},show:function(){return this.config({visible:!0}),this},hide:function(){return this.config({visible:!1}),this},update:function(){return this.trigger("update"),this},focus:function(){return this.events.trigger("focus"),this}}),c.defineVariables();var cIndex=jsCow.componentsObjectList.length;c.id("c_"+cIndex+"_"+((new Date).getTime()+""+Math.floor(1e6*Math.random())).substr(0,18));var eventsManager=new jsCow.res.core.events.eventsManager;eventsManager.cmp(c),eventsManager.parent(c),c.events=eventsManager,c.on("model.ready",function(e){$.isEmptyObject(e.sender.__preConfig__.model)||e.sender.config(e.sender.__preConfig__.model),$.each(this.__preConfig__,function(self){return function(i,args){"undefined"!=typeof self[i]?"model"!==i&&(args instanceof Array?self[i].apply(self,args):self[i].apply(self,[args])):"model"!==i&&console.warn("Configuration parameter could not be set. The method '"+i+"' doesn't exists for component '"+self.id()+"'!")}}(this))});var controllerHandler=new jsCow.res.core.mvc.controllerHandler;controllerHandler.events=c.events,controllerHandler.__cmp__=c,c.__controller__=controllerHandler;var viewsManager=new jsCow.res.core.mvc.viewsManager;return viewsManager.__cmp__=c,c.__view__=viewsManager,c.createPlaceholder(cIndex),c.init(),jsCow.componentsObjectList[cIndex]=c,c=null,jsCow.componentsObjectList[cIndex]}return console.log("The ressource of a component does not exists!"),{}},find:function(component){var cid,foundCmp;return"object"==typeof component&&(cid=component.id()),foundCmp=!1,$.each(jsCow.componentsObjectList,function(i,c){c.id()===component&&(foundCmp=c)}),foundCmp}},jsCow.components=new component,jsCow.res.core.mvc.viewsManager=function(){this.viewList=[]},jsCow.res.core.mvc.viewsManager.prototype={init:function(config){var self=this,viewList=this.list();$.each(viewList,function(i,view){view.isInit||("undefined"!==view.dom&&"undefined"!==view.dom.main&&(0===i&&self.cmp().placeholder()&&self.cmp().placeholder().replaceWith(view.dom.main),i>0&&viewList[i-1].dom.main.after(view.dom.main)),view.isInit=!0)})},list:function(){return this.viewList},addView:function(v){var self=this,length=this.length();this.viewList[length]=new v,this.viewList[length].__cmp__=this.cmp(),this.viewList[length].__cfg__={};var eventsManager=new jsCow.res.core.events.eventsManager;return eventsManager.cmp(this.cmp()),eventsManager.parent(this.viewList[length]),this.viewList[length].events=eventsManager,$.extend(!0,this.viewList[length],{cmp:function(){return this.__cmp__},main:function(){return this.dom.main},content:function(){return this.dom.content?this.dom.content:!1},appendToTarget:function(){return $(this.dom.main).appendTo(this.cmp().target()),this},appendAfter:function(target){return target.after(this.dom.main),this},cfg:function(param){return void 0===param?this.__cfg__:this.__cfg__[param]?this.__cfg__[param]:!1},id:function(id){return id?(this.__id__=id,this):this.__id__},focus:function(e){$(".jsc-focus").removeClass("jsc-focus"),this.dom.main.addClass("jsc-focus")},on:function(event,handler,local){return this.events.on(event,handler,local),this},trigger:function(event,data,local){return this.events.trigger(event,data,local),this},bubbleIn:function(event,data,local){return this.events.bubbleIn(event,data,local),this},bubbleOut:function(event,data,local){return this.events.bubbleOut(event,data,local),this},bubble:function(event,data,local){return this.events.bubble(event,data,local),this}}),this.viewList[length].id("v"+((new Date).getTime()+""+Math.floor(1e6*Math.random())).substr(0,18)),this.viewList[length].on("view.init",this.viewList[length].init),this.viewList[length].on("view.update",this.viewList[length].update),this.viewList[length].on("view.focus",this.viewList[length].focus),this.viewList[length].dom.main.mousedown(function(self,length){return function(e){e.stopPropagation(),self.viewList[length].trigger("view.focus")}}(self,length)),this.viewList[length]},add:function(v){return this.addView(v),this},del:function(view){var v=new view,viewList=this.list();$.each(viewList,function(i,view){v.id()===view.id()&&("undefined"!==view.dom.main&&view.dom.main.remove(),viewList.splice(i,1))})},update:function(e){var self=this,viewList=this.list();$.each(viewList,function(i,view){self.cmp().trigger("view.update")})},length:function(){return this.viewList.length},content:function(idx){var index;index=void 0===idx?0:idx;var self=this,viewList=this.list(),content=!1;return $.each(viewList,function(i,view){if("undefined"!==view.dom&&"undefined"!==view.dom.content&&"object"==typeof view.dom.content&&view.dom.content instanceof Array)view.dom.content[index]&&(content=view.dom.content[index]);else{if(void 0===view.dom||void 0===view.dom.content)return self.main(index);content=view.dom.content}}),content},main:function(idx){var index;index=void 0===idx?0:idx;var viewList=this.list(),main=!1;return $.each(viewList,function(i,view){"undefined"!==view.dom&&"undefined"!==view.dom.main&&"object"==typeof view.dom.main&&view.dom.main instanceof Array?view.dom.main[index]&&(main=view.dom.main[index]):main="undefined"!==view.dom&&"undefined"!==view.dom.main?view.dom.main:!1}),main},cmp:function(){return this.__cmp__},appendTo:function(target){var self=this,viewList=this.list();return $.each(viewList,function(i,view){view.main().appendTo(target),self.cmp().target(target)}),this},removeAll:function(){var viewList=this.list();return $.each(viewList,function(i,view){"undefined"!==view.dom.main&&view.dom.main.remove()}),this.cmp()},replace:function(o,n){var oV=new o,_this=this,viewList=this.list();$.each(viewList,function(i,view){view.id()===oV.id()&&(_this.addView(n).appendAfter(view.main()),_this.del(o))})},style:function(css){var style=css,viewList=this.list();$.each(viewList,function(i,view){"object"==typeof style?view.main().css(style):"string"==typeof style&&view.main().addClass(style)})}},jsCow.res.core.mvc.controllerHandler=function(){this.controllerList=[],this.__cmp__=!1,this.events=!1},jsCow.res.core.mvc.controllerHandler.prototype={controllers:function(){return this.controllerList},add:function(c){$.extend(!0,c.prototype,{model:function(){return this.__model__},view:function(){return this.__view__},cmp:function(){return this.__cmp__},__update__:function(e){return this.trigger("view.update",this.cmp().config()),this.trigger("updated",this.cmp().config()),this},id:function(id){return id?(this.__id__=id,this):this.__id__},enable:function(e){var c=this.cmp().config();return c.enabled!==!1&&"undefined"!=typeof c.enabled||!(!this.cmp().parent()||this.cmp().parent()&&this.cmp().parent().isEnabled())||(this.cmp().config({enabled:!0}),this.trigger("enabled",this.cmp().config(e.data)),$.each(this.cmp().children(),function(self){return function(i,c){var cfg=c.config();"undefined"!=typeof cfg.__forcedEnable__&&cfg.__forcedEnable__||(e.data.__forcedEnable__=!1,c.trigger("enable",e.data))}}(this))),this},disable:function(e){var c=this.cmp().config();return c.enabled===!0&&"undefined"!=typeof c.enabled&&(this.cmp().config({enabled:!1}),this.trigger("disabled",this.cmp().config(e.data)),$.each(this.cmp().children(),function(self){return function(i,c){e.data.__forcedEnable__=!1,c.trigger("disable",e.data)}}(this))),this},show:function(e){return this.cmp().config({visible:!0}),this.trigger("showed",this.cmp().config()),this},hide:function(e){return this.cmp().config({visible:!1}),this.trigger("hidden",this.cmp().config()),this},on:function(event,handler,local){return this.events.on(event,handler,local),this},trigger:function(event,data,local){return this.events.trigger(event,data,local),this},bubbleIn:function(event,data,local){return this.events.bubbleIn(event,data,local),this},bubbleOut:function(event,data,local){return this.events.bubbleOut(event,data,local),this},bubble:function(event,data,local){return this.events.bubble(event,data,local),this}});var length=this.length();this.controllerList[length]=new c,this.controllerList[length].__view__=this.cmp().view(),this.controllerList[length].__model__=this.cmp().model(),this.controllerList[length].__cmp__=this.cmp(),this.controllerList[length].id("c"+((new Date).getTime()+""+Math.floor(1e6*Math.random())).substr(0,18));var eventsManager=new jsCow.res.core.events.eventsManager;return eventsManager.cmp(this.cmp()),eventsManager.parent(this.controllerList[length]),this.controllerList[length].events=eventsManager,this.controllerList[length].on("controller.init",this.controllerList[length].init,!0),this.controllerList[length].on("controller.update",this.controllerList[length].update,!0),this.controllerList[length].on("show",this.controllerList[length].show),this.controllerList[length].on("hide",this.controllerList[length].hide),this.controllerList[length].on("enable",this.controllerList[length].enable),this.controllerList[length].on("disable",this.controllerList[length].disable),this.controllerList[length].on("update",this.controllerList[length].__update__),this},length:function(){return this.controllerList.length},cmp:function(){return this.__cmp__},del:function(controller){var c,controllerList;return c=new controller,controllerList=this.controllers(),$.each(controllerList,function(i,controller){c.id()===controller.id()&&controllerList.splice(i,1)}),this}},jsCow.res.core.events.eventsManager=function(){this.__cfg__=!1,this.__cmp__=!1,this.parentClass=!1},jsCow.res.core.events.eventsManager.prototype={cmp:function(cmp){return void 0!==cmp?(this.__cmp__=cmp,this):this.__cmp__},isNot:function(local){return local?!1:!0},parent:function(parentClass){return void 0!==parentClass?(this.parentClass=parentClass,this):this.parentClass},on:function(event,h,l){var handler=h,local=l;void 0===handler&&(handler=!1);var sender=this.cmp(),parentClass=this.parentClass;return local="undefined"==typeof local||local===!0?!0:!1,void 0!==event&&sender?"function"==typeof handler?(void 0===jsCow.events[event]&&(jsCow.events[event]=Array()),jsCow.events[event].push({event:event,handler:handler,sender:sender,that:parentClass,local:local})):jsCow.debug.events&&console.warn("There is not defined a handler method for event '"+event+"' in '"+this.cmp().id()+"'. The event trigger will be ignored!"):console.error("There have to be defined an event name for the event listener in '"+this.cmp().id()+"'!"),this},off:function(event,cmp){jsCow.events[event]&&$.each(jsCow.events[event],function(i,evt){jsCow.events[event][i].getID()===cmp.getID()&&jsCow.events[event][i].slice(i,1)})},trigger:function(event,d,l){var data=d,local=l;if("undefined"!=typeof data&&data||(data={}),data){var self=this;local="undefined"!=typeof local&&local?!1:this.cmp(),void 0!==jsCow.events[event]&&$.each(jsCow.events[event],function(self,event,data,local){return function(i,e){"object"==typeof local&&local.id()===e.sender.id()&&e.local?setTimeout(function(){jsCow.debug.events&&console.log("local :: trigger event ","'"+e.event+"'","from","'"+self.cmp().id()+"' for '"+e.that.id()+"'."),e.handler.apply(e.that,[{data:data,sender:self.cmp(),date:new Date}])},0):self.isNot(local)===e.local&&setTimeout(function(){jsCow.debug.events&&console.log("global :: trigger even","'"+e.event+"'","from","'"+self.cmp().id()+"' for '"+e.that.id()+"'."),e.handler.apply(e.that,[{data:data,sender:self.cmp(),date:new Date}])},0)}}(self,event,data,local))}return this},bubbleOut:function(event,data,local){var bubble=this.bubbleTrigger(event,data,local);bubble&&this.cmp().parent()&&this.cmp().parent().bubbleOut(event,data,local)},bubbleIn:function(event,data,local){var bubble=this.bubbleTrigger(event,data,local);if(bubble&&this.cmp().children().length>0){var children=this.cmp().children();$.each(children,function(self){return function(i,c){c.bubbleIn(event,data,local)}}(this))}},bubble:function(event,data,local){var bubble=this.bubbleTrigger(event,data,local);bubble&&(this.bubbleOut(event,data,local),this.bubbleIn(event,data,local))},bubbleTrigger:function(event,data,local){var bubble=!0;return this.trigger(event,data,local),bubble}},jsCow.res.components.button=function(){},jsCow.res.components.button.prototype={init:function(){return this.addController(jsCow.res.controller.button),this.addModel(jsCow.res.model.button),this.addView(jsCow.res.view.button),this},text:function(text){return"undefined"!=typeof text&&"string"==typeof text&&this.trigger("text",{text:text}),this},icon:function(o){var options;return"undefined"==typeof o?options=!1:"object"==typeof o&&(options=$.extend(!0,{direction:"l",name:"user",prefix:"fa fa-"},o)),this.trigger("icon",{icon:options}),this}},jsCow.res.model.button=function(){this.data={enabled:!0,visible:!0,text:""}},jsCow.res.model.button.prototype={init:function(){this.trigger("model.ready",this.data)}},jsCow.res.view.button=function(){this.dom={},this.dom.main=$("<div/>").addClass("jsc-btn")},jsCow.res.view.button.prototype={init:function(e){this.dom.main.hover(function(self,e){return function(){e.data.enabled&&(self.dom.main.addClass("jsc-btn-hover"),self.trigger("mouseover"))}}(this,e),function(self,e){return function(){e.data.enabled&&(self.dom.main.removeClass("jsc-btn-hover"),self.trigger("mouseout"))}}(this,e)).mousedown(function(self,e){return function(){e.data.enabled&&(self.dom.main.addClass("jsc-btn-press"),self.trigger("press"))}}(this,e)).mouseup(function(self,e){return function(){e.data.enabled&&(self.dom.main.removeClass("jsc-btn-press"),self.trigger("pressed"))}}(this,e)).click(function(self,e){return function(){e.data.enabled&&(self.dom.main.removeClass("jsc-btn-press"),self.trigger("click"))}}(this,e)),this.dom.text=$("<span/>").appendTo(this.dom.main),this.dom.icon=$("<i/>"),this.trigger("view.update",e.data)},update:function(e){if(e.data.enabled){if(this.dom.main.removeClass("jsc-btn-disabled").addClass("jsc-btn"),e.data.text&&""!==e.data.text?this.dom.text.html(e.data.text).removeClass("hidden").show():this.dom.text.addClass("hidden"),e.data.visible?this.dom.main.show():this.dom.main.hide(),e.data.icon)switch(this.dom.icon.addClass(e.data.icon.prefix+""+e.data.icon.name),e.data.icon.direction){case"l":this.dom.text.before(this.dom.icon);break;case"r":this.dom.text.after(this.dom.icon);break;default:this.dom.text.before(this.dom.icon)}}else this.dom.main.removeClass("jsc-btn").addClass("jsc-btn-disabled")}},jsCow.res.controller.button=function(){},jsCow.res.controller.button.prototype={init:function(){this.on("model.ready",this.isModelReady),this.on("text",this.text),this.on("icon",this.icon)},isModelReady:function(e){this.trigger("view.init",e.data)},text:function(e){this.cmp().config({text:e.data.text})},icon:function(e){this.cmp().config({icon:e.data.icon})}};