!function(){var moduleFactory=function($){var module=this;$.require().script("mvc/class","mvc/lang.string","mvc/event.destroyed").done(function(){var exports=function(){var basicProcessor,bind=function(el,ev,callback){var wrappedCallback,binder=el.bind&&el.unbind?el:$(isFunction(el)?[el]:el);return 0===ev.indexOf(">")&&(ev=ev.substr(1),wrappedCallback=function(event){event.target===el&&callback.apply(this,arguments)}),binder.bind(ev,wrappedCallback||callback),function(){binder.unbind(ev,wrappedCallback||callback),el=ev=callback=wrappedCallback=null
}},makeArray=$.makeArray,isArray=$.isArray,isFunction=$.isFunction,extend=$.extend,Str=$.String,each=$.each,STR_PROTOTYPE="prototype",STR_CONSTRUCTOR="constructor",slice=Array[STR_PROTOTYPE].slice,delegate=function(el,selector,ev,callback){0===selector.indexOf(">")&&(selector=(el.data("directSelector")+" "||"")+selector);var binder=el.delegate&&el.undelegate?el:$(isFunction(el)?[el]:el);return binder.delegate(selector,ev,callback),function(){binder.undelegate(selector,ev,callback),binder=el=ev=callback=selector=null
}},binder=function(el,ev,callback,selector){return selector?delegate(el,selector,ev,callback):bind(el,ev,callback)},shifter=function(context,name){var method="string"==typeof name?context[name]:name;return function(){return context.called=name,method.apply(context,[this.nodeName?$(this):this].concat(slice.call(arguments,0)))}},dotsReg=/\./g,controllersReg=/_?controllers?/gi,underscoreAndRemoveController=function(className){return Str.underscore(className.replace($.globalNamespace+".","").replace(dotsReg,"_").replace(controllersReg,""))
},actionMatcher=/^\S(.*)\s(.*)/,parameterReplacer=/\{([^\}]+)\}/g,breaker=/^(?:(.*?)\s)?([\w\.\:>]+)$/,data=function(el,data){return $.data(el,"controllers",data)};$.Class($.globalNamespace+".Controller",{setup:function(){if(this._super.apply(this,arguments),this.shortName&&this.fullName!=$.globalNamespace+".Controller"){this._fullName=underscoreAndRemoveController(this.fullName),this._shortName=underscoreAndRemoveController(this.shortName);var proto,_prototype=arguments[3];isFunction(_prototype)&&(this.protoFactory=_prototype,proto=this.protoFactory.call(this,null));
var funcName,controller=this;if(this.isPlugin){var pluginname=this.pluginName||this._fullName;$.fn[pluginname]||($.fn[pluginname]=function(options){var args=makeArray(arguments),isMethod="string"==typeof options&&isFunction(controller[STR_PROTOTYPE][options]),meth=args[0];return this.each(function(){var controllers=data(this),plugin=controllers&&controllers[pluginname];plugin?isMethod?plugin[meth].apply(plugin,args.slice(1)):plugin.update.apply(plugin,args):controller.newInstance.apply(controller,[this].concat(args))
})})}this.actions={},proto=proto||this[STR_PROTOTYPE];for(funcName in proto)"constructor"!=funcName&&isFunction(proto[funcName])&&this._isAction(funcName)&&(this.actions[funcName]=this._action(funcName))}},hookup:function(el){return new this(el)},_isAction:function(methodName){return actionMatcher.test(methodName)?!0:$.inArray(methodName,this.listensTo)>-1||$.event.special[methodName]||processors[methodName]},_action:function(methodName,options){if(parameterReplacer.lastIndex=0,!options&&parameterReplacer.test(methodName))return null;
var evt,ready=[];return methodName.match(/^\[.+\]/)?(methodNames=methodName.replace(/^\[|\]/g,"").replace(", ",",").split(" "),evt=methodNames.pop(),methodNames=methodNames[0].split(",")):methodNames=[methodName],$.each(methodNames,function(i,methodName){methodName=methodName.replace("{self} ","");var convertedName=options?Str.sub(methodName,[options,window]):methodName,arr=isArray(convertedName),parts=evt?[convertedName+" "+evt,convertedName,evt]:(arr?convertedName[1]:convertedName).match(breaker),event=evt||parts[2],processor=processors[event]||basicProcessor;
ready.push({processor:processor,parts:parts,delegate:arr?convertedName[0]:void 0})}),ready},processors:{},listensTo:[],defaults:{}},{setup:function(element,options){var cls=this[STR_CONSTRUCTOR];if(cls.protoFactory){var proto=cls.protoFactory.call(cls,this);$.extend(!0,this,proto)}this.bind=this._bind,element=("string"==typeof element?$(element):element.jquery?element:[element])[0];var pluginname=cls.pluginName||cls._fullName;if(this.element=$(element),(data(element)||data(element,{}))[pluginname]=this,this.instanceId=$.uid(cls._fullName+"_"),void 0===this.element.data("directSelector")){var selector=$.uid("DS");
this.element.data("directSelector","."+selector),this.element.addClass(selector)}this.options=extend(!0,{},cls.defaults,cls.defaultOptions,options);for(prop in this.options)if(prop.match(/^\{.+\}$/)){var selector=this.options[prop],propFunc=prop.replace(/^\{|\}$/g,"");this[propFunc]=function(instance,selector,propFunc){if("string"!=typeof selector)return selector;selector=/^(\.|\#)$/.test(selector)?selector+propFunc:selector;var selectorFunc=function(filter){return filter?instance.element.find(selector).filter(filter):instance.element.find(selector)
};return selectorFunc.selector=selector,selectorFunc}(this,selector,propFunc)}var instance=this,views=this.options.view,__view=instance.view;return instance.view=function(){return __view.apply(this,arguments)},$.isPlainObject(views)&&$.each(views,function(view){instance.view[view]=function(){var args=$.makeArray(arguments),useHtml=!1;"boolean"==typeof args[0]&&(useHtml=args[0],args=args.slice(1));var options=[useHtml,view].concat(args);return instance.view.apply(instance,options)}}),$.extend(this,this.options.controller),this.called="init",this.bind(),[this.element,this.options].concat(makeArray(arguments).slice(2))
},_bind:function(el,eventName,func){if(void 0===el){this._bindings=[];var cls=this[STR_CONSTRUCTOR],bindings=this._bindings,actions=cls.actions,element=this.element;for(funcName in actions)if(actions.hasOwnProperty(funcName)){readyList=cls.actions[funcName]||cls._action(funcName,this.options);var self=this;$.each(readyList,function(i,ready){self._bindings.push(ready.processor(ready.delegate||element,ready.parts[2],ready.parts[1],funcName,self))})}var destroyCB=shifter(this,"destroy");return element.bind("destroyed",destroyCB),bindings.push(function(el){$(el).unbind("destroyed",destroyCB)
}),bindings.length}return"string"==typeof el&&(func=eventName,eventName=el,el=this.element),this._binder(el,eventName,func)},_binder:function(el,eventName,func,selector){return"string"==typeof func&&(func=shifter(this,func)),this._bindings.push(binder(el,eventName,func,selector)),this._bindings.length},_unbind:function(){var el=this.element[0];each(this._bindings,function(key,value){value(el)}),this._bindings=[]},trigger:function(){this.element.trigger.apply(this.element,arguments)},delegate:function(element,selector,eventName,func){return"string"==typeof element&&(func=eventName,eventName=selector,selector=element,element=this.element),this._binder(element,eventName,func,selector)
},update:function(options){extend(this.options,options),this._unbind(),this.bind()},destroy:function(){if(this._destroyed)try{console.error(this[STR_CONSTRUCTOR].shortName+" controller already deleted")}catch(e){}else{var fname=this[STR_CONSTRUCTOR].pluginName||this[STR_CONSTRUCTOR]._fullName;this._destroyed=!0,this.element.removeClass(fname),this._unbind(),delete this._actions,delete this.element.data("controllers")[fname],$(this).triggerHandler("destroyed"),this.element=null}},find:function(selector){return this.element.find(selector)
},view:function(){var name,args=$.makeArray(arguments),options=args,useHtml=!1,context=this[STR_CONSTRUCTOR].component||$,html="",view=this.options.view||{};return"boolean"==typeof args[0]&&(useHtml=args[0],options=args.slice(1)),name=options[0]=view[options[0]],void 0==name?useHtml?"":$(""):(html=context.View.apply(context,options),useHtml?html:$(html))},_set_called:!0});var processors=$.Controller.processors,basicProcessor=function(el,event,selector,methodName,controller){return binder(el,event,shifter(controller,methodName),selector)
};each("change click contextmenu dblclick keydown keyup keypress mousedown mousemove mouseout mouseover mouseup reset resize scroll select submit focusin focusout mouseenter mouseleave".split(" "),function(i,v){processors[v]=basicProcessor});var i,isAControllerOf=function(instance,controllers){for(i=0;i<controllers.length;i++)if("string"==typeof controllers[i]?instance[STR_CONSTRUCTOR]._shortName==controllers[i]:instance instanceof controllers[i])return!0;return!1};$.fn.extend({controllers:function(){var controllers,c,cname,controllerNames=makeArray(arguments),instances=[];
return this.each(function(){controllers=$.data(this,"controllers");for(cname in controllers)controllers.hasOwnProperty(cname)&&(c=controllers[cname],(!controllerNames.length||isAControllerOf(c,controllerNames))&&instances.push(c))}),instances},controller:function(){return this.controllers.apply(this,arguments)[0]},implement:function(controller,options,callback){var controllerName,elements=this;return"string"==typeof controller&&(controllerName=controller,controller=$.String.getObject(controllerName)),void 0!==controller&&$.each(elements,function(){var instance=new controller(this,options);
callback&&callback.apply(instance)}),this}})};exports(),module.resolveWith(exports)})};dispatch("mvc/controller").containing(moduleFactory).to("Foundry/2.1 Modules")}();