infusion
Version:
Infusion is an application framework for developing flexible stuff with JavaScript
8 lines (7 loc) • 658 kB
JavaScript
/*!
infusion - v3.0.0-dev.20181204T213346Z.2ca90f6e6
Friday, December 7th, 2018, 7:28:56 AM
branch: master
revision: 2ca90f6e6
*/
var fluid_3_0_0=fluid_3_0_0||{},fluid=fluid||fluid_3_0_0;!function($,fluid){"use strict";fluid.version="Infusion 3.0.0",fluid.Error=Error,fluid.environment={fluid:fluid},fluid.global=fluid.global||"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},fluid.invokeLater=function(func){return setTimeout(func,1)},fluid.defeatLogging=!0,fluid.activityTracing=!1,fluid.activityTrace=[];var activityParser=/(%\w+)/g;function transformInternal(source,togo,key,args){for(var transit=source[key],j=0;j<args.length-1;++j)transit=args[j+1](transit,key);togo[key]=transit}fluid.renderOneActivity=function(activity,nowhile){for(var togo=!0===nowhile?[]:[" while "],message=activity.message,index=activityParser.lastIndex=0;;){var match=activityParser.exec(message);if(!match)break;var key=match[1].substring(1);togo.push(message.substring(index,match.index)),togo.push(activity.args[key]),index=activityParser.lastIndex}return index<message.length&&togo.push(message.substring(index)),togo},fluid.renderActivity=function(activityStack,renderer){return renderer=renderer||fluid.renderOneActivity,fluid.transform(activityStack,renderer)},fluid.singleThreadLocal=function(initFunc){var value=initFunc();return function(newValue){return void 0===newValue?value:value=newValue}},fluid.threadLocal=fluid.singleThreadLocal,fluid.globalThreadLocal=fluid.threadLocal(function(){return{}}),fluid.getActivityStack=function(){var root=fluid.globalThreadLocal();return root.activityStack||(root.activityStack=[]),root.activityStack},fluid.describeActivity=fluid.getActivityStack,fluid.logActivity=function(activity){activity=activity||fluid.describeActivity();var rendered=fluid.renderActivity(activity).reverse();0<rendered.length&&(fluid.log("Current activity: "),fluid.each(rendered,function(args){fluid.log.apply(null,args)}))},fluid.pushActivity=function(type,message,args){var record={type:type,message:message,args:args,time:(new Date).getTime()};fluid.activityTracing&&fluid.activityTrace.push(record),fluid.passLogLevel(fluid.logLevel.TRACE)&&fluid.log.apply(null,fluid.renderOneActivity(record,!0)),fluid.getActivityStack().push(record)},fluid.popActivity=function(popframes){popframes=popframes||1,fluid.activityTracing&&fluid.activityTrace.push({pop:popframes});var activityStack=fluid.getActivityStack(),popped=activityStack.length-popframes;activityStack.length=popped<0?0:popped},fluid.FluidError=function(){var togo=Error.apply(this,arguments);this.message=togo.message;try{throw togo}catch(togo){this.stack=togo.stack}return this},fluid.FluidError.prototype=Object.create(Error.prototype),fluid.logFailure=function(args,activity){fluid.log.apply(null,[fluid.logLevel.FAIL,"ASSERTION FAILED: "].concat(args)),fluid.logActivity(activity)},fluid.renderLoggingArg=function(arg){return void 0===arg?"undefined":fluid.isPrimitive(arg)||!fluid.isPlainObject(arg)?arg:JSON.stringify(arg)},fluid.builtinFail=function(args){var message=fluid.transform(args,fluid.renderLoggingArg).join("");throw new fluid.FluidError("Assertion failure - check console for more details: "+message)},fluid.fail=function(){var args=fluid.makeArray(arguments),activity=fluid.makeArray(fluid.describeActivity());fluid.popActivity(activity.length),fluid.failureEvent?fluid.failureEvent.fire(args,activity):(fluid.logFailure(args,activity),fluid.builtinFail(args,activity))},fluid.expect=function(name,target,members){fluid.transform(fluid.makeArray(members),function(key){void 0===target[key]&&fluid.fail(name+" missing required parameter "+key)})},fluid.isLogging=function(){return logLevelStack[0].priority>fluid.logLevel.IMPORTANT.priority},fluid.isLogLevel=function(arg){return fluid.isMarker(arg)&&void 0!==arg.priority},fluid.passLogLevel=function(testLogLevel){return testLogLevel.priority<=logLevelStack[0].priority},fluid.setLogging=function(enabled){var logLevel;"boolean"==typeof enabled?logLevel=fluid.logLevel[enabled?"INFO":"IMPORTANT"]:fluid.isLogLevel(enabled)?logLevel=enabled:fluid.fail("Unrecognised fluid logging level ",enabled),logLevelStack.unshift(logLevel),fluid.defeatLogging=!fluid.isLogging()},fluid.setLogLevel=fluid.setLogging,fluid.popLogging=function(){var togo=1===logLevelStack.length?logLevelStack[0]:logLevelStack.shift();return fluid.defeatLogging=!fluid.isLogging(),togo},fluid.doBrowserLog=function(args){"undefined"!=typeof console&&(console.debug?console.debug.apply(console,args):"function"==typeof console.log&&console.log.apply(console,args))},fluid.log=function(){var directArgs=fluid.makeArray(arguments),userLogLevel=fluid.logLevel.INFO;fluid.isLogLevel(directArgs[0])&&(userLogLevel=directArgs.shift()),fluid.passLogLevel(userLogLevel)&&fluid.loggingEvent.fire(directArgs)},fluid.isValue=function(value){return null!=value},fluid.isPrimitive=function(value){var valueType=typeof value;return!value||"string"===valueType||"boolean"===valueType||"number"===valueType||"function"===valueType},fluid.isJQuery=function(totest){return Boolean(totest&&totest.jquery&&totest.constructor&&totest.constructor.prototype&&totest.constructor.prototype.jquery)},fluid.isArrayable=function(totest){return Boolean(totest)&&("[object Array]"===Object.prototype.toString.call(totest)||fluid.isJQuery(totest))},fluid.isPlainObject=function(totest,strict){var string=Object.prototype.toString.call(totest);return"[object Array]"===string?!strict:"[object Object]"===string&&(!totest.constructor||!totest.constructor.prototype||Object.prototype.hasOwnProperty.call(totest.constructor.prototype,"isPrototypeOf"))},fluid.typeCode=function(totest){return fluid.isPrimitive(totest)||!fluid.isPlainObject(totest)?"primitive":fluid.isArrayable(totest)?"array":"object"},fluid.isIoCReference=function(ref){return"string"==typeof ref&&"{"===ref.charAt(0)&&0<ref.indexOf("}")},fluid.isDOMNode=function(obj){return obj&&"number"==typeof obj.nodeType},fluid.isComponent=function(obj){return obj&&obj.constructor===fluid.componentConstructor},fluid.isUncopyable=function(totest){return fluid.isPrimitive(totest)||!fluid.isPlainObject(totest)},fluid.isApplicable=function(totest){return totest.apply&&"function"==typeof totest.apply},fluid.identity=function(arg){return arg},fluid.notImplemented=function(){fluid.fail("This operation is not implemented")},fluid.firstDefined=function(a,b){return void 0===a?b:a},fluid.freshContainer=function(tocopy){return fluid.isArrayable(tocopy)?[]:{}},fluid.copyRecurse=function(tocopy,segs){return segs.length>fluid.strategyRecursionBailout&&fluid.fail("Runaway recursion encountered in fluid.copy - reached path depth of "+fluid.strategyRecursionBailout+" via path of "+segs.join(".")+"this object is probably circularly connected. Either adjust your object structure to remove the circularity or increase fluid.strategyRecursionBailout"),fluid.isUncopyable(tocopy)?tocopy:fluid.transform(tocopy,function(value,key){segs.push(key);var togo=fluid.copyRecurse(value,segs);return segs.pop(),togo})},fluid.copy=function(tocopy){return fluid.copyRecurse(tocopy,[])},fluid.extend=$.extend,fluid.makeArray=function(arg){var togo=[];if(null!=arg)if(fluid.isPrimitive(arg)||fluid.isPlainObject(arg,!0)||"number"!=typeof arg.length)togo.push(arg);else for(var i=0;i<arg.length;++i)togo[i]=arg[i];return togo},fluid.pushArray=function(holder,member,topush){var array=holder[member]?holder[member]:holder[member]=[];fluid.isArrayable(topush)?array.push.apply(array,topush):array.push(topush)},fluid.transform=function(source){if(fluid.isPrimitive(source))return source;var togo=fluid.freshContainer(source);if(fluid.isArrayable(source))for(var i=0;i<source.length;++i)transformInternal(source,togo,i,arguments);else for(var key in source)transformInternal(source,togo,key,arguments);return togo},fluid.each=function(source,func){if(fluid.isArrayable(source))for(var i=0;i<source.length;++i)func(source[i],i);else for(var key in source)func(source[key],key)},fluid.make_find=function(find_if){var target=!find_if&&void 0;return function(source,func,deffolt){var disp;if(fluid.isArrayable(source)){for(var i=0;i<source.length;++i)if((disp=func(source[i],i))!==target)return find_if?source[i]:disp}else for(var key in source)if((disp=func(source[key],key))!==target)return find_if?source[key]:disp;return deffolt}},fluid.find=fluid.make_find(!1),fluid.find_if=fluid.make_find(!0),fluid.accumulate=function(list,fn,arg){for(var i=0;i<list.length;++i)arg=fn(list[i],arg,i);return arg},fluid.add=function(a,b){return a+b},fluid.remove_if=function(source,fn,target){if(fluid.isArrayable(source))for(var i=source.length-1;0<=i;--i)fn(source[i],i)&&(target&&target.unshift(source[i]),source.splice(i,1));else for(var key in source)fn(source[key],key)&&(target&&(target[key]=source[key]),delete source[key]);return target||source},fluid.generate=function(n,generator,applyFunc){for(var togo=[],i=0;i<n;++i)togo[i]=applyFunc?generator(i):generator;return togo},fluid.iota=function(count,first){first=first||0;for(var togo=[],i=0;i<count;++i)togo[togo.length]=first++;return togo},fluid.getMembers=function(holder,name){return fluid.transform(holder,function(member){return fluid.get(member,name)})},fluid.filterKeys=function(toFilter,keys,exclude){return fluid.remove_if($.extend({},toFilter),function(value,key){return exclude^-1===keys.indexOf(key)})},fluid.censorKeys=function(toCensor,keys){return fluid.filterKeys(toCensor,keys,!0)},fluid.keys=function(obj){var togo=[];for(var key in obj)togo.push(key);return togo},fluid.values=function(obj){var togo=[];for(var key in obj)togo.push(obj[key]);return togo},fluid.contains=function(obj,value){return obj?fluid.isArrayable(obj)?-1!==obj.indexOf(value):fluid.find(obj,function(thisValue){if(value===thisValue)return!0}):void 0},fluid.keyForValue=function(obj,value){return fluid.find(obj,function(thisValue,key){if(value===thisValue)return key})},fluid.arrayToHash=function(array){var togo={};return fluid.each(array,function(el){togo[el]=!0}),togo},fluid.stableSort=function(array,func){for(var i=0;i<array.length;i++){var j,k=array[i];for(j=i;0<j&&func(k,array[j-1])<0;j--)array[j]=array[j-1];array[j]=k}},fluid.hashToArray=function(hash,keyName,func){var togo=[];return fluid.each(hash,function(el,key){var newEl={};newEl[keyName]=key,func?newEl=func(newEl,el,key)||newEl:$.extend(!0,newEl,el),togo.push(newEl)}),togo},fluid.flatten=function(array){var togo=[];return fluid.each(array,function(element){fluid.isArrayable(element)?togo=togo.concat(element):togo.push(element)}),togo},fluid.clear=function(target){if(fluid.isArrayable(target))target.length=0;else for(var i in target)delete target[i]},fluid.compareStringLength=function(ascending){return ascending?function(a,b){return a.length-b.length}:function(a,b){return b.length-a.length}},fluid.parseInteger=function(string){return isFinite(string)&&string%1==0?Number(string):NaN},fluid.roundToDecimal=function(num,scale,method){return scale=scale&&0<=scale?Math.round(scale):0,"ceil"===method||"floor"===method?Number(Math[method](num+"e"+scale)+"e-"+scale):Number((0<=num?1:-1)*(Math.round(Math.abs(num)+"e"+scale)+"e-"+scale))},fluid.debounce=function(func,wait,immediate){var timeout,result;return function(){var context=this,args=arguments,callNow=immediate&&!timeout;return clearTimeout(timeout),timeout=setTimeout(function(){timeout=null,immediate||(result=func.apply(context,args))},wait),callNow&&(result=func.apply(context,args)),result}},fluid.freezeRecursive=function(tofreeze){return fluid.isPlainObject(tofreeze)?(fluid.each(tofreeze,function(value){fluid.freezeRecursive(value)}),Object.freeze(tofreeze)):tofreeze},fluid.marker=function(){},fluid.makeMarker=function(value,extra){var togo=Object.create(fluid.marker.prototype);return togo.value=value,$.extend(togo,extra),Object.freeze(togo)},fluid.VALUE=fluid.makeMarker("VALUE"),fluid.NO_VALUE=fluid.makeMarker("NO_VALUE"),fluid.EXPAND=fluid.makeMarker("EXPAND"),fluid.isMarker=function(totest,type){return totest instanceof fluid.marker&&(!type||totest.value===type.value)},fluid.logLevelsSpec={FATAL:0,FAIL:5,WARN:10,IMPORTANT:12,INFO:15,TRACE:20},fluid.logLevel=fluid.transform(fluid.logLevelsSpec,function(value,key){return fluid.makeMarker(key,{priority:value})});var logLevelStack=[fluid.logLevel.IMPORTANT];fluid.model={},fluid.model.copyModel=function(target,source){fluid.clear(target),$.extend(!0,target,source)},fluid.model.parseEL=function(EL){return""===EL?[]:String(EL).split(".")},fluid.model.composePath=function(prefix,suffix){return""===prefix?suffix:""===suffix?prefix:prefix+"."+suffix},fluid.model.composeSegments=function(){return fluid.makeArray(arguments).join(".")},fluid.lastDotIndex=function(path){return path.lastIndexOf(".")},fluid.model.getToTailPath=function(path){var lastdot=fluid.lastDotIndex(path);return-1===lastdot?"":path.substring(0,lastdot)},fluid.model.getTailPath=function(path){var lastdot=fluid.lastDotIndex(path);return path.substring(lastdot+1)},fluid.path=fluid.model.composeSegments,fluid.composePath=fluid.model.composePath,fluid.requireDataBinding=function(){fluid.fail("Please include DataBinding.js in order to operate complex model accessor configuration")},fluid.model.setWithStrategy=fluid.model.getWithStrategy=fluid.requireDataBinding,fluid.model.resolvePathSegment=function(root,segment,create,origEnv){if(!origEnv&&root.resolvePathSegment){var togo=root.resolvePathSegment(segment);if(void 0!==togo)return togo}return create&&void 0===root[segment]?root[segment]={}:root[segment]},fluid.model.parseToSegments=function(EL,parseEL,copy){return"number"==typeof EL||"string"==typeof EL?parseEL(EL):copy?fluid.makeArray(EL):EL},fluid.model.pathToSegments=function(EL,config){var parser=config&&config.parser?config.parser.parse:fluid.model.parseEL;return fluid.model.parseToSegments(EL,parser)},fluid.model.accessImpl=function(root,EL,newValue,config,initSegs,returnSegs,traverser){var segs=fluid.model.pathToSegments(EL,config),initPos=0;if(initSegs&&(initPos=initSegs.length,segs=initSegs.concat(segs)),root=traverser(root,segs,initPos,config,newValue===fluid.NO_VALUE?0:1),newValue===fluid.NO_VALUE||newValue===fluid.VALUE)return returnSegs?{root:root,segs:segs}:root;root[segs[segs.length-1]]=newValue},fluid.model.accessSimple=function(root,EL,newValue,environment,initSegs,returnSegs){return fluid.model.accessImpl(root,EL,newValue,environment,initSegs,returnSegs,fluid.model.traverseSimple)},fluid.model.traverseSimple=function(root,segs,initPos,environment,uncess){for(var origEnv=environment,limit=segs.length-uncess,i=0;i<limit;++i){if(!root)return;var segment=segs[i];root=environment&&environment[segment]?environment[segment]:fluid.model.resolvePathSegment(root,segment,1===uncess,origEnv),environment=null}return root},fluid.model.setSimple=function(root,EL,newValue,environment,initSegs){fluid.model.accessSimple(root,EL,newValue,environment,initSegs,!1)},fluid.model.getSimple=function(root,EL,environment,initSegs){return null==EL||0===EL.length?root:fluid.model.accessSimple(root,EL,fluid.NO_VALUE,environment,initSegs,!1)},fluid.getImmediate=function(root,segs,i){for(var limit=void 0===i?segs.length:i+1,j=0;j<limit;++j)root=root?root[segs[j]]:void 0;return root},fluid.decodeAccessorArg=function(arg3){return arg3&&arg3!==fluid.model.defaultGetConfig&&arg3!==fluid.model.defaultSetConfig?"environment"===arg3.type?arg3.value:void 0:null},fluid.set=function(root,EL,newValue,config,initSegs){var env=fluid.decodeAccessorArg(config);void 0===env?fluid.model.setWithStrategy(root,EL,newValue,config,initSegs):fluid.model.setSimple(root,EL,newValue,env,initSegs)},fluid.get=function(root,EL,config,initSegs){var env=fluid.decodeAccessorArg(config);return void 0===env?fluid.model.getWithStrategy(root,EL,config,initSegs):fluid.model.accessImpl(root,EL,fluid.NO_VALUE,env,null,!1,fluid.model.traverseSimple)},fluid.getGlobalValue=function(path,env){if(path)return env=env||fluid.environment,fluid.get(fluid.global,path,{type:"environment",value:env})},fluid.bind=function(obj,fnName,args){return obj[fnName].apply(obj,fluid.makeArray(args))},fluid.invokeGlobalFunction=function(functionPath,args,environment){var func=fluid.getGlobalValue(functionPath,environment);if(func)return func.apply(null,fluid.isArrayable(args)?args:fluid.makeArray(args));fluid.fail("Error invoking global function: "+functionPath+" could not be located")},fluid.registerGlobalFunction=function(functionPath,func,env){env=env||fluid.environment,fluid.set(fluid.global,functionPath,func,{type:"environment",value:env})},fluid.setGlobalValue=fluid.registerGlobalFunction,fluid.registerNamespace=function(naimspace,env){env=env||fluid.environment;var existing=fluid.getGlobalValue(naimspace,env);return existing||(existing={},fluid.setGlobalValue(naimspace,existing,env)),existing},fluid.dumpEl=fluid.identity,fluid.renderTimestamp=fluid.identity,fluid.generateUniquePrefix=function(){return Math.floor(1e12*Math.random()).toString(36)+"-"};var fluid_prefix=fluid.generateUniquePrefix();fluid.fluidInstance=fluid_prefix;var fluid_guid=1;fluid.allocateGuid=function(){return fluid_prefix+fluid_guid++},fluid.registerNamespace("fluid.event"),fluid.extremePriority=4e9,fluid.priorityTypes={first:-1,last:1,before:0,after:0},fluid.extremalPriorities={none:0,testing:10,authoring:20},fluid.parsePriorityConstraint=function(constraint,fixedOnly,site){var segs=constraint.split(":"),type=segs[0],lookup=fluid.priorityTypes[type];return void 0===lookup&&fluid.fail("Invalid constraint type in priority field "+constraint+": the only supported values are "+fluid.keys(fluid.priorityTypes).join(", ")+" or numeric"),fixedOnly&&0===lookup&&fluid.fail("Constraint type in priority field "+constraint+" is not supported in a "+site+" record - you must use either a numeric value or first, last"),{type:segs[0],target:segs[1]}},fluid.parsePriority=function(priority,count,fixedOnly,site){var togo={count:count||0,fixed:null,constraint:null,site:site};"number"==typeof(priority=priority||0)?togo.fixed=-priority:togo.constraint=fluid.parsePriorityConstraint(priority,fixedOnly,site);var multiplier=togo.constraint?fluid.priorityTypes[togo.constraint.type]:0;if(0!==multiplier){var target=togo.constraint.target||"none",extremal=fluid.extremalPriorities[target];void 0===extremal&&fluid.fail("Unrecognised extremal priority target "+target+": the currently supported values are "+fluid.keys(fluid.extremalPriorities).join(", ")+": register your value in fluid.extremalPriorities"),togo.fixed=multiplier*(fluid.extremePriority+extremal)}return null!==togo.fixed&&(togo.fixed+=togo.count/1024),togo},fluid.renderPriority=function(parsed){return parsed.constraint?parsed.constraint.target?parsed.constraint.type+":"+parsed.constraint.target:parsed.constraint.type:Math.floor(parsed.fixed)},fluid.compareByPriority=function(recA,recB){return null!==recA.priority.fixed&&null!==recB.priority.fixed?recA.priority.fixed-recB.priority.fixed:(null===recA.priority.fixed)-(null===recB.priority.fixed)},fluid.honourConstraint=function(array,firstConstraint,c){var constraint=array[c].priority.constraint,matchIndex=fluid.find(array,function(element,index){return element.namespace===constraint.target?index:void 0},-1);if(-1===matchIndex)return!0;if(firstConstraint<=matchIndex)return!1;for(var target=matchIndex+("after"===constraint.type?1:0),temp=array[c],shift=c;target<=shift;--shift)array[shift]=array[shift-1];return array[target]=temp,!0},fluid.sortByPriority=function(array){fluid.stableSort(array,fluid.compareByPriority);for(var firstConstraint=fluid.find(array,function(element,index){return element.priority.constraint&&0===fluid.priorityTypes[element.priority.constraint.type]?index:void 0},array.length);;){if(firstConstraint===array.length)return array;for(var oldFirstConstraint=firstConstraint,c=firstConstraint;c<array.length;++c){fluid.honourConstraint(array,firstConstraint,c)&&++firstConstraint}if(firstConstraint===oldFirstConstraint){var holders=array.slice(firstConstraint);fluid.fail("Could not find targets for any constraints in "+holders[0].priority.site+" ",holders,": none of the targets ("+fluid.getMembers(holders,"priority.constraint.target").join(", ")+") matched any namespaces of the elements in (",array.slice(0,firstConstraint),") - this is caused by either an invalid or circular reference")}}},fluid.parsePriorityRecords=function(records,name){var array=fluid.hashToArray(records,"namespace",function(newElement,oldElement,index){$.extend(newElement,oldElement),newElement.priority=fluid.parsePriority(oldElement.priority,index,!1,name)});return fluid.sortByPriority(array),array},fluid.event.identifyListener=function(listener,soft){return"string"==typeof listener||listener.$$fluid_guid||soft||(listener.$$fluid_guid=fluid.allocateGuid()),listener.$$fluid_guid},fluid.event.impersonateListener=function(origListener,newListener){fluid.event.identifyListener(origListener),newListener.$$fluid_guid=origListener.$$fluid_guid},fluid.event.sortListeners=function(listeners){var togo=[];return fluid.each(listeners,function(oneNamespace){for(var headHard,i=0;i<oneNamespace.length;++i){var thisListener=oneNamespace[i];thisListener.softNamespace||headHard||(headHard=thisListener)}headHard?togo.push(headHard):togo=togo.concat(oneNamespace)}),fluid.sortByPriority(togo)},fluid.event.resolveListener=function(listener){var listenerName=listener.globalName||("string"==typeof listener?listener:null);if(listenerName){var listenerFunc=fluid.getGlobalValue(listenerName);listenerFunc?listener=listenerFunc:fluid.fail("Unable to look up name "+listenerName+" as a global function")}return listener},fluid.nameComponent=function(that){return that?"component with typename "+that.typeName+" and id "+that.id:"[unknown component]"},fluid.event.nameEvent=function(that,eventName){return eventName+" of "+fluid.nameComponent(that)},fluid.makeEventFirer=function(options){var that,name=(options=options||{}).name||"<anonymous>";return that={eventId:fluid.allocateGuid(),name:name,ownerId:options.ownerId,typeName:"fluid.event.firer",destroy:function(){that.destroyed=!0},addListener:function(){(function(){that.listeners={},that.byId={},that.sortedListeners=[],that.addListener=function(listener,namespace,priority,softNamespace,listenerId){var record;if(that.destroyed&&fluid.fail("Cannot add listener to destroyed event firer "+that.name),listener){fluid.isPlainObject(listener,!0)&&!fluid.isApplicable(listener)&&(listener=(record=listener).listener,namespace=record.namespace,priority=record.priority,softNamespace=record.softNamespace,listenerId=record.listenerId),"string"==typeof listener&&(listener={globalName:listener});var id=listenerId||fluid.event.identifyListener(listener);namespace=namespace||id,record=$.extend(record||{},{namespace:namespace,listener:listener,softNamespace:softNamespace,listenerId:listenerId,priority:fluid.parsePriority(priority,that.sortedListeners.length,!1,"listeners")}),that.byId[id]=record,(that.listeners[namespace]=fluid.makeArray(that.listeners[namespace]))[softNamespace?"push":"unshift"](record),that.sortedListeners=fluid.event.sortListeners(that.listeners)}},that.addListener.apply(null,arguments)}).apply(null,arguments)},removeListener:function(listener){if(that.listeners){var namespace,id,record;"string"==typeof listener?(namespace=listener,(record=that.listeners[namespace])||(id=namespace,namespace=null)):"function"==typeof listener&&((id=fluid.event.identifyListener(listener,!0))||fluid.fail("Cannot remove unregistered listener function ",listener," from event "+that.name));var rec=that.byId[id],softNamespace=rec&&rec.softNamespace;namespace=namespace||rec&&rec.namespace||id,delete that.byId[id],(record=that.listeners[namespace])&&(softNamespace?fluid.remove_if(record,function(thisLis){return thisLis.listener.$$fluid_guid===id||thisLis.listenerId===id}):record.shift(),0===record.length&&delete that.listeners[namespace]),that.sortedListeners=fluid.event.sortListeners(that.listeners)}},fire:function(){var listeners=that.sortedListeners;if(listeners&&!that.destroyed)for(var i=0;i<listeners.length;++i){var lisrec=listeners[i];"function"!=typeof lisrec.listener&&(lisrec.listener=fluid.event.resolveListener(lisrec.listener));var value,ret=lisrec.listener.apply(null,arguments);if((options.preventable&&!1===ret||that.destroyed)&&(value=!1),void 0!==value)return value}}}},fluid.fireEvent=function(component,eventName,args){var firer=component.events[eventName];firer&&firer.fire.apply(null,fluid.makeArray(args))},fluid.event.addListenerToFirer=function(firer,value,namespace,wrapper){if(wrapper=wrapper||fluid.identity,fluid.isArrayable(value))for(var i=0;i<value.length;++i)fluid.event.addListenerToFirer(firer,value[i],namespace,wrapper);else"function"==typeof value||"string"==typeof value?wrapper(firer).addListener(value,namespace):value&&"object"==typeof value&&wrapper(firer).addListener(value.listener,namespace||value.namespace,value.priority,value.softNamespace,value.listenerId)},fluid.event.resolveListenerRecord=function(records){return{records:records}},fluid.expandImmediate=function(material){fluid.fail("fluid.expandImmediate could not be loaded - please include FluidIoC.js in order to operate IoC-driven event with descriptor "+material)},fluid.mergeListeners=function(that,events,listeners){fluid.each(listeners,function(value,key){var firer,namespace;if(fluid.isIoCReference(key))(firer=fluid.expandImmediate(key,that))||fluid.fail("Error in listener record: key "+key+' could not be looked up to an event firer - did you miss out "events." when referring to an event firer?');else{var keydot=key.indexOf(".");-1!==keydot&&(namespace=key.substring(keydot+1),key=key.substring(0,keydot)),events[key]||fluid.fail("Listener registered for event "+key+" which is not defined for this component"),firer=events[key]}var record=fluid.event.resolveListenerRecord(value,that,key,namespace,!0);fluid.event.addListenerToFirer(firer,record.records,namespace,record.adderWrapper)})},fluid.eventFromRecord=function(eventSpec,eventKey,that){var event;return eventSpec&&("string"!=typeof eventSpec||fluid.isIoCReference(eventSpec))?fluid.event.resolveEvent?event=fluid.event.resolveEvent(that,eventKey,eventSpec):fluid.fail("fluid.event.resolveEvent could not be loaded - please include FluidIoC.js in order to operate IoC-driven event with descriptor ",eventSpec):event=fluid.makeEventFirer({name:fluid.event.nameEvent(that,eventKey),preventable:"preventable"===eventSpec,ownerId:that.id}),event},fluid.instantiateFirers=function(that,options){fluid.each(options.events,function(eventSpec,eventKey){that.events[eventKey]=fluid.eventFromRecord(eventSpec,eventKey,that)})},fluid.mergeListenerPolicy=function(target,source,key){return"string"!=typeof key&&fluid.fail("Error in listeners declaration - the keys in this structure must resolve to event names - got "+key+" from ",source),!fluid.isIoCReference(key)&&-1!==key.indexOf(".")?source||target:fluid.arrayConcatPolicy(target,source)},fluid.makeMergeListenersPolicy=function(merger,modelRelay){return function(target,source){return target=target||{},modelRelay&&(fluid.isArrayable(source)||"string"==typeof source.target)?target[""]=merger(target[""],source,""):fluid.each(source,function(listeners,key){target[key]=merger(target[key],listeners,key)}),target}},fluid.validateListenersImplemented=function(that){var errors=[];return fluid.each(that.events,function(event,name){fluid.each(event.sortedListeners,function(lisrec){lisrec.listener!==fluid.notImplemented&&"fluid.notImplemented"!==lisrec.listener.globalName||errors.push({name:name,namespace:lisrec.namespace,componentSource:fluid.model.getSimple(that.options.listeners,[name+"."+lisrec.namespace,0,"componentSource"])})})}),errors},fluid.unique=function(array){return fluid.remove_if(array,function(element,i){return!element||0<i&&element===array[i-1]})},fluid.arrayConcatPolicy=function(target,source){return fluid.makeArray(target).concat(fluid.makeArray(source))},fluid.loggingEvent=fluid.makeEventFirer({name:"logging event"}),fluid.addTimestampArg=function(args){var arg0=fluid.renderTimestamp(new Date)+": ";args.unshift(arg0)},fluid.loggingEvent.addListener(fluid.doBrowserLog,"log"),fluid.loggingEvent.addListener(fluid.identity,"filterArgs","before:log"),fluid.loggingEvent.addListener(fluid.addTimestampArg,"addTimestampArg","after:filterArgs"),fluid.failureEvent=fluid.makeEventFirer({name:"failure event"}),fluid.failureEvent.addListener(fluid.builtinFail,"fail"),fluid.failureEvent.addListener(fluid.logFailure,"log","before:fail"),fluid.pushSoftFailure=function(condition){"function"==typeof condition?fluid.failureEvent.addListener(condition,"fail"):-1===condition?fluid.failureEvent.removeListener("fail"):"boolean"==typeof condition&&fluid.fail("pushSoftFailure with boolean value is no longer supported")},fluid.componentConstructor=function(){},fluid.typeTag=function(name){var that=Object.create(fluid.componentConstructor.prototype);return that.typeName=name,that.id=fluid.allocateGuid(),that};var gradeTick=1,gradeTickStore={};function regenerateCursor(source,segs,limit,sourceStrategy){for(var i=0;i<limit;++i)source=sourceStrategy(source,segs[i],i,fluid.makeArray(segs));return source}fluid.defaultsStore={},fluid.resolveGradesImpl=function(gs,gradeNames){for(var i=(gradeNames=fluid.makeArray(gradeNames)).length-1;0<=i;--i){var gradeName=gradeNames[i];if(gradeName&&!gs.gradeHash[gradeName]){var options=(fluid.isIoCReference(gradeName)?null:fluid.rawDefaults(gradeName))||{},thisTick=gradeTickStore[gradeName]||gradeTick-1;gs.lastTick=Math.max(gs.lastTick,thisTick),gs.gradeHash[gradeName]=!0,gs.gradeChain.push(gradeName);for(var oGradeNames=fluid.makeArray(options.gradeNames),j=oGradeNames.length-1;0<=j;--j)fluid.resolveGradesImpl(gs,oGradeNames[j])}}return gs},fluid.resolveGradeStructure=function(defaultName,gradeNames){var gradeStruct={lastTick:0,gradeChain:[],gradeHash:{}};return fluid.resolveGradesImpl(gradeStruct,[defaultName].concat(fluid.makeArray(gradeNames))),gradeStruct.gradeChain.reverse(),gradeStruct},fluid.hasGrade=function(options,gradeName){return!(!options||!options.gradeNames)&&fluid.contains(options.gradeNames,gradeName)},fluid.resolveGrade=function(defaults,defaultName,gradeNames){var gradeStruct=fluid.resolveGradeStructure(defaultName,gradeNames),mergeArgs=fluid.transform(gradeStruct.gradeChain,fluid.rawDefaults,fluid.copy);fluid.remove_if(mergeArgs,function(options){return!options});for(var mergePolicy={},i=0;i<mergeArgs.length;++i)mergeArgs[i]&&mergeArgs[i].mergePolicy&&(mergePolicy=$.extend(!0,mergePolicy,mergeArgs[i].mergePolicy));mergeArgs=[mergePolicy,{}].concat(mergeArgs);var mergedDefaults=fluid.merge.apply(null,mergeArgs);return mergedDefaults.gradeNames=gradeStruct.gradeChain,fluid.freezeRecursive(mergedDefaults),{defaults:mergedDefaults,lastTick:gradeStruct.lastTick}},fluid.mergedDefaultsCache={},fluid.gradeNamesToKey=function(defaultName,gradeNames){return defaultName+"|"+gradeNames.join("|")},fluid.getMergedDefaults=function(defaultName,gradeNames){gradeNames=fluid.makeArray(gradeNames);var key=fluid.gradeNamesToKey(defaultName,gradeNames),mergedDefaults=fluid.mergedDefaultsCache[key];if(mergedDefaults){for(var lastTick=0,searchGrades=mergedDefaults.defaults.gradeNames||[],i=0;i<searchGrades.length;++i)lastTick=Math.max(lastTick,gradeTickStore[searchGrades[i]]||0);lastTick>mergedDefaults.lastTick&&(fluid.passLogLevel(fluid.logLevel.TRACE)&&fluid.log(fluid.logLevel.TRACE,"Clearing cache for component "+defaultName+" with gradeNames ",searchGrades),mergedDefaults=null)}if(!mergedDefaults){var defaults=fluid.rawDefaults(defaultName);if(!defaults)return defaults;mergedDefaults=fluid.mergedDefaultsCache[key]=fluid.resolveGrade(defaults,defaultName,gradeNames)}return mergedDefaults.defaults},fluid.upgradePrimitiveFunc=function(rec,key){if(rec&&fluid.isPrimitive(rec)){var togo={};return togo[key||("string"==typeof rec&&"{"!==rec.charAt(0)?"funcName":"func")]=rec,togo.args=fluid.NO_VALUE,togo}return rec},fluid.annotateListeners=function(componentName,options){options.listeners=fluid.transform(options.listeners,function(record){var togo=fluid.makeArray(record);return fluid.transform(togo,function(onerec){return(onerec=fluid.upgradePrimitiveFunc(onerec,"listener")).componentSource=componentName,onerec})}),options.invokers=fluid.transform(options.invokers,function(record){return(record=fluid.upgradePrimitiveFunc(record))&&(record.componentSource=componentName),record})},fluid.rawDefaults=function(componentName){var entry=fluid.defaultsStore[componentName];return entry&&entry.options},fluid.registerRawDefaults=function(componentName,options){fluid.pushActivity("registerRawDefaults","registering defaults for grade %componentName with options %options",{componentName:componentName,options:options});var optionsCopy=fluid.expandCompact?fluid.expandCompact(options):fluid.copy(options);fluid.annotateListeners(componentName,optionsCopy);var callerInfo=fluid.getCallerInfo&&fluid.getCallerInfo(6);fluid.defaultsStore[componentName]={options:optionsCopy,callerInfo:callerInfo},gradeTickStore[componentName]=gradeTick++,fluid.popActivity()},fluid.doIndexDefaults=function(defaultName,defaults,index,indexSpec){for(var requiredGrades=fluid.makeArray(indexSpec.gradeNames),i=0;i<requiredGrades.length;++i)if(!fluid.hasGrade(defaults,requiredGrades[i]))return;for(var keys=("function"==typeof indexSpec.indexFunc?indexSpec.indexFunc:fluid.getGlobalValue(indexSpec.indexFunc))(defaults)||[],j=0;j<keys.length;++j)fluid.pushArray(index,keys[j],defaultName)},fluid.indexDefaults=function(indexName,indexSpec){var index={};for(var defaultName in fluid.defaultsStore){var defaults=fluid.getMergedDefaults(defaultName);fluid.doIndexDefaults(defaultName,defaults,index,indexSpec)}return index},fluid.defaults=function(componentName,options){if(void 0===options)return fluid.getMergedDefaults(componentName);options&&options.options&&fluid.fail("Probable error in options structure for "+componentName+' with option named "options" - perhaps you meant to write these options at top level in fluid.defaults? - ',options),fluid.registerRawDefaults(componentName,options);var gradedDefaults=fluid.getMergedDefaults(componentName);fluid.hasGrade(gradedDefaults,"fluid.function")||fluid.makeComponentCreator(componentName)},fluid.makeComponentCreator=function(componentName){var creator=function(){var defaults=fluid.getMergedDefaults(componentName);if(defaults.gradeNames&&0!==defaults.gradeNames.length){if(defaults.initFunction)return fluid.initComponent(componentName,arguments);for(var blankGrades=[],i=0;i<defaults.gradeNames.length;++i){var gradeName=defaults.gradeNames[i];fluid.rawDefaults(gradeName)||blankGrades.push(gradeName)}0===blankGrades.length?fluid.fail("Cannot make component creator for type "+componentName+" which does not have an initFunction defined"):fluid.fail("The grade hierarchy of component with type "+componentName+" is incomplete - it inherits from the following grade(s): "+blankGrades.join(", ")+" for which the grade definitions are corrupt or missing. Please check the files which might include these grades and ensure they are readable and have been loaded by this instance of Infusion")}else fluid.fail("Cannot make component creator for type "+componentName+" which does not have any gradeNames defined")},existing=fluid.getGlobalValue(componentName);existing&&$.extend(creator,existing),fluid.setGlobalValue(componentName,creator)},fluid.emptyPolicy=fluid.freezeRecursive({}),fluid.derefMergePolicy=function(policy){return(policy?policy["*"]:fluid.emptyPolicy)||fluid.emptyPolicy},fluid.compileMergePolicy=function(mergePolicy){var builtins={},defaultValues={},togo={builtins:builtins,defaultValues:defaultValues};return mergePolicy&&fluid.each(mergePolicy,function(value,key){var parsed={},builtin=!0;if("function"==typeof value)parsed.func=value;else if("object"==typeof value)parsed=value;else if(fluid.isDefaultValueMergePolicy(value))fluid.set(defaultValues,key,"{that}.options."+value),builtin=!(togo.hasDefaults=!0);else for(var split=value.split(/\s*,\s*/),i=0;i<split.length;++i)parsed[split[i]]=!0;builtin&&fluid.set(builtins,fluid.composePath(key,"*"),parsed)}),togo},fluid.isDefaultValueMergePolicy=function(policy){return"string"==typeof policy&&-1===policy.indexOf(",")&&!/replace|nomerge|noexpand/.test(policy)},fluid.mergeOneImpl=function(thisTarget,thisSource,j,sources,newPolicy,i,segs){var togo=thisTarget,primitiveTarget=fluid.isPrimitive(thisTarget);return void 0!==thisSource&&(newPolicy.func||null===thisSource||!fluid.isPlainObject(thisSource)||newPolicy.nomerge?(sources[j]=void 0,togo=newPolicy.func?newPolicy.func.call(null,thisTarget,thisSource,segs[i-1],segs,i):thisSource):primitiveTarget&&(togo=thisTarget=fluid.freshContainer(thisSource))),togo},fluid.fetchMergeChildren=function(target,i,segs,sources,mergePolicy,options){for(var thisPolicy=fluid.derefMergePolicy(mergePolicy),j=sources.length-1;0<=j;--j){var source=sources[j];if(void 0!==source&&(fluid.each(source,function(newSource,name){var childPolicy=fluid.concreteTrundler(mergePolicy,name);name in target&&(!options.evaluateFully||void 0!==childPolicy||fluid.isPrimitive(target[name]))||(segs[i]=name,options.strategy(target,name,i+1,segs,sources,mergePolicy))}),thisPolicy.replace))break}return target},fluid.inEvaluationMarker=Object.freeze({__CURRENTLY_IN_EVALUATION__:!0}),fluid.strategyRecursionBailout=50,fluid.makeMergeStrategy=function(options){var strategy=function(target,name,i,segs,sources,policy){if(i>fluid.strategyRecursionBailout&&fluid.fail("Overflow/circularity in options merging, current path is ",segs," at depth ",i,' - please protect components from merging using the "nomerge" merge policy'),!fluid.isPrimitive(target)){var oldTarget;if(fluid.isTracing&&fluid.tracing.pathCount.push(fluid.path(segs.slice(0,i))),name in target){if(oldTarget=target[name],!options.evaluateFully)return oldTarget}else target!==fluid.inEvaluationMarker&&(target[name]=fluid.inEvaluationMarker);void 0===sources&&(segs=fluid.makeArray(segs),sources=function(sources,segs,limit,sourceStrategies){for(var togo=[],i=0;i<sources.length;++i){var thisSource=regenerateCursor(sources[i],segs,limit,sourceStrategies[i]);void 0!==thisSource&&togo.push(thisSource)}return togo}(options.sources,segs,i-1,options.sourceStrategies),policy=regenerateCursor(options.mergePolicy,segs,i-1,fluid.concreteTrundler));var start,limit,mul,newPolicyHolder=fluid.concreteTrundler(policy,name),newPolicy=fluid.derefMergePolicy(newPolicyHolder);mul=newPolicy.replace?(start=1-sources.length,limit=0,-1):(start=0,limit=sources.length-1,1);for(var thisTarget,newSources=[],j=start;j<=limit;++j){var k=mul*j,thisSource=options.sourceStrategies[k](sources[k],name,i,segs);if(void 0!==thisSource&&(fluid.isPrimitive(thisSource)||(newSources[k]=thisSource),void 0===oldTarget)){if(-1===mul){thisTarget=target[name]=thisSource;break}thisTarget=fluid.mergeOneImpl(thisTarget,thisSource,j,newSources,newPolicy,i,segs,options),target!==fluid.inEvaluationMarker&&(target[name]=thisTarget)}}return void 0!==oldTarget&&(thisTarget=oldTarget),0<newSources.length&&fluid.isPlainObject(thisTarget)&&fluid.fetchMergeChildren(thisTarget,i,segs,newSources,newPolicyHolder,options),void 0===oldTarget&&0===newSources.length&&delete target[name],thisTarget}};return options.strategy=strategy},fluid.driveStrategy=function(root,pathSegs,strategy){pathSegs=fluid.makeArray(pathSegs);for(var i=0;i<pathSegs.length;++i){if(!root)return;root=strategy(root,pathSegs[i],i+1,pathSegs)}return root},fluid.concreteTrundler=function(source,seg){return source?source[seg]:void 0},fluid.merge=function(policy){var sources=Array.prototype.slice.call(arguments,1),compiled=fluid.compileMergePolicy(policy).builtins,options=fluid.makeMergeOptions(compiled,sources,{});return options.initter(),options.target},fluid.simpleGingerBlock=function(source,recordType){return{target:source,simple:!0,strategy:fluid.concreteTrundler,initter:fluid.identity,recordType:recordType,priority:fluid.mergeRecordTypes[recordType]}},fluid.makeMergeOptions=function(policy,sources,userOptions){var options={mergePolicy:policy,sources:sources};return(options=$.extend(options,userOptions)).target=options.target||fluid.freshContainer(options.sources[0]),options.sourceStrategies=options.sourceStrategies||fluid.generate(options.sources.length,fluid.concreteTrundler),options.initter=function(){options.evaluateFully=!0,fluid.fetchMergeChildren(options.target,0,[],options.sources,options.mergePolicy,options)},fluid.makeMergeStrategy(options),options},fluid.transformOptions=function(options,transRec){return fluid.expect("Options transformation record",transRec,["transformer","config"]),fluid.getGlobalValue(transRec.transformer).call(null,options,transRec.config)},fluid.findMergeBlocks=function(mergeBlocks,recordType){return fluid.remove_if(fluid.makeArray(mergeBlocks),function(block){return block.recordType!==recordType})},fluid.transformOptionsBlocks=function(mergeBlocks,transformOptions,recordTypes){fluid.each(recordTypes,function(recordType){var blocks=fluid.findMergeBlocks(mergeBlocks,recordType);fluid.each(blocks,function(block){var source=block.source?"source":"target";block[block.simple||"target"===source?"target":"source"]=fluid.transformOptions(block[source],transformOptions)})})},fluid.dedupeDistributionNamespaces=function(mergeBlocks){var byNamespace={};fluid.remove_if(mergeBlocks,function(mergeBlock){var ns=mergeBlock.namespace;if(ns){if(byNamespace[ns]&&byNamespace[ns]!==mergeBlock.contextThat.id)return!0;byNamespace[ns]=mergeBlock.contextThat.id}})},fluid.deliverOptionsStrategy=fluid.identity,fluid.computeComponentAccessor=fluid.identity,fluid.computeDynamicComponents=fluid.identity,fluid.mergeRecordTypes={defaults:1e3,defaultValueMerge:900,subcomponentRecord:800,user:700,distribution:100},fluid.model.applyChangeRequest=function(model,request){var segs=request.segs;if(0===segs.length)"ADD"===request.type?$.extend(!0,model,request.value):fluid.clear(model);else if("ADD"===request.type)fluid.model.setSimple(model,request.segs,request.value);else{for(var i=0;i<segs.length-1;++i)if(!(model=model[segs[i]]))return;delete model[segs[segs.length-1]]}},fluid.destroyValue=function(target,segs){target&&fluid.model.applyChangeRequest(target,{type:"DELETE",segs:segs})},fluid.mergeComponentOptions=function(that,componentName,userOptions,localOptions){var rawDefaults=fluid.rawDefaults(componentName),defaults=fluid.getMergedDefaults(componentName,rawDefaults&&rawDefaults.gradeNames?null:localOptions.gradeNames),sharedMergePolicy={},mergeBlocks=[];mergeBlocks=fluid.expandComponentOptions?mergeBlocks.concat(fluid.expandComponentOptions(sharedMergePolicy,defaults,userOptions,that)):mergeBlocks.concat([fluid.simpleGingerBlock(defaults,"defaults"),fluid.simpleGingerBlock(userOptions,"user")]);var options={},sourceStrategies=[],sources=[],baseMergeOptions={target:options,sourceStrategies:sourceStrategies},updateBlocks=function(){fluid.each(mergeBlocks,function(block){fluid.isPrimitive(block.priority)&&(block.priority=fluid.parsePriority(block.priority,0,!1,"options distribution"))}),fluid.sortByPriority(mergeBlocks),fluid.dedupeDistributionNamespaces(mergeBlocks),sourceStrategies.length=0,sources.length=0,fluid.each(mergeBlocks,function(block){sourceStrategies.push(block.strategy),sources.push(block.target)})};updateBlocks();var compiledPolicy,mergePolicy,mergeOptions=fluid.makeMergeOptions(sharedMergePolicy,sources,baseMergeOptions);function computeMergePolicy(){mergePolicy=fluid.driveStrategy(options,"mergePolicy",mergeOptions.strategy),mergePolicy=$.extend({},fluid.rootMergePolicy,mergePolicy),compiledPolicy=fluid.compileMergePolicy(mergePolicy),$.extend(!0,sharedMergePolicy,compiledPolicy.builtins)}mergeOptions.mergeBlocks=mergeBlocks,mergeOptions.updateBlocks=updateBlocks,mergeOptions.destroyValue=function(segs){for(var i=0;i<mergeBlocks.length;++i)mergeBlocks[i].immutableTarget||fluid.destroyValue(mergeBlocks[i].target,segs);fluid.destroyValue(baseMergeOptions.target,segs)},computeMergePolicy(),mergeOptions.computeMergePolicy=computeMergePolicy,compiledPolicy.hasDefaults&&(fluid.generateExpandBlock?(mergeBlocks.push(fluid.generateExpandBlock({options:compiledPolicy.defaultValues,recordType:"defaultValueMerge",priority:fluid.mergeRecordTypes.defaultValueMerge},that,{})),updateBlocks()):fluid.fail("Cannot operate mergePolicy ",mergePolicy," for component ",that," without including FluidIoC.js")),that.options=options,fluid.driveStrategy(options,"gradeNames",mergeOptions.strategy),fluid.deliverOptionsStrategy(that,options,mergeOptions),fluid.computeComponentAccessor(that,userOptions&&userOptions.localRecord);var transformOptions=fluid.driveStrategy(options,"transformOptions",mergeOptions.strategy);return transformOptions&&(fluid.transformOptionsBlocks(mergeBlocks,transformOptions,["user","subcomponentRecord"]),updateBlocks()),baseMergeOptions.target.mergePolicy||computeMergePolicy(),mergeOptions},fluid.defaults("fluid.function",{}),fluid.invokeGradedFunction=function(name,spec){var defaults=fluid.defaults(name);defaults&&defaults.argumentMap&&fluid.hasGrade(defaults,"fluid.function")||fluid.fail("Cannot look up name "+name+" to a function with registered argumentMap - got defaults ",defaults);var args=[];return fluid.each(defaults.argumentMap,function(value,key){args[value]=spec[key]}),fluid.invokeGlobalFunction(name,args)},fluid.noNamespaceDistributionPrefix="no-namespace-distribution-",fluid.mergeOneDistribution=function(target,source,key){var namespace=source.namespace||key||fluid.noNamespaceDistributionPrefix+fluid.allocateGuid();target[source.namespace=namespace]=$.extend(!0,{},target[namespace],source)},fluid.distributeOptionsPolicy=function(target,source){if(target=target||{},fluid.isArrayable(source))for(var i=0;i<source.length;++i)fluid.mergeOneDistribution(target,source[i]);else"string"==typeof source.target?fluid.mergeOneDistribution(target,source):fluid.each(source,function(oneSource,key){fluid.mergeOneDistribution(target,oneSource,key)});return target},fluid.mergingArray=function(){},fluid.mergingArray.prototype=[],fluid.membersMergePolicy=function(target,source){return target=target||{},fluid.each(source,function(oneSource,key){target[key]||(target[key]=new fluid.mergingArray),oneSource instanceof fluid.mergingArray?target[key].push.apply(target[key],oneSource):void 0!==oneSource&&target[key].push(oneSource)}),target},fluid.invokerStrategies=fluid.arrayToHash(["func","funcName","listener","this","method","changePath","value"]),fluid.invokersMergePolicy=function(target,source){return target=target||{},fluid.each(source,function(oneInvoker,name){if(oneInvoker){oneInvoker=fluid.upgradePrimitiveFunc(oneInvoker);var oneT=target[name];for(var key in oneT||(oneT=target[name]={}),fluid.invokerStrategies)if(key in oneInvoker)for(var key2 in fluid.invokerStrategies)oneT[key2]=void 0;$.extend(oneT,oneInvoker)}else target[name]=oneInvoker}),target},fluid.rootMergePolicy={gradeNames:fluid.arrayConcatPolicy,distributeOptions:fluid.distributeOptionsPolicy,members:{noexpand:!0,func:fluid.membersMergePolicy},invokers:{noexpand:!0,func:fluid.invokersMergePolicy},transformOptions:"replace",listeners:fluid.makeMergeListenersPolicy(fluid.mergeListenerPolicy)},fluid.defaults("fluid.component",{initFunction:"fluid.initLittleComponent",mergePolicy:fluid.rootMergePolicy,argumentMap:{options:0},events:{onCreate:null,onDestroy:null,afterDestroy:null}}),fluid.defaults("fluid.emptySubcomponent",{gradeNames:["fluid.component"]}),fluid.computeNickName=function(typeName){var segs=fluid.model.parseEL(typeName);return segs[segs.length-1]},fluid.defaults("fluid.typeFount",{gradeNames:["fluid.component"]}),fluid.initLittleComponent=function(name,userOptions,localOptions,receiver){var that=fluid.typeTag(name);that.lifecycleStatus="constructing",localOptions=localOptions||{gradeNames:"fluid.component"},that.destroy=fluid.makeRootDestroy(that);var mergeOptions=fluid.mergeComponentOptions(that,name,userOptions,localOptions);mergeOptions.exceptions={members:{model:!0,modelRelay:!0}};var options=that.options;that.events={},(receiver||fluid.identity)(that,options,mergeOptions.strategy),fluid.computeDynamicComponents(that,mergeOptions);for(var i=0;i<mergeOptions.mergeBlocks.length;++i)mergeOptions.mergeBlocks[i].initter();return mergeOptions.initter(),delete options.mergePolicy,fluid.instantiateFirers(that,options),fluid.mergeListeners(that,that.events,options.listeners),that},fluid.diagnoseFailedView=fluid.identity,fluid.makeRootDestroy=function(that){return function(){fluid.doDestroy(that),fluid.fireEvent(that,"afterDestroy",[that,"",null])}},fluid.isDestroyed=function(that){return"destroyed"===that.lifecycleStatus},fluid.doDestroy=function(that,name,parent){for(var key in fluid.fireEvent(that,"onDestroy",[that,name||"",parent]),that.lifecycleStatus="destroyed",that.events)"afterDestroy"!==key&&"function"==typeof that.events[key].destroy&&that.events[key].destroy();that.applier&&that.applier.destroy()},fluid.initComponent=function(componentName,initArgs){var options=fluid.defaults(componentName);options.gradeNames||fluid.fail("Cannot initialise component "+componentName+" which has no gradeName registered");var that,args=[componentName].concat(fluid.makeArray(initArgs));fluid.pushActivity("initComponent","constructing component of type %componentName with arguments %initArgs",{componentName:componentName,initArgs:initArgs}),that=fluid.invokeGlobalFunction(options.initFunction,args),fluid.diagnoseFailedView(componentName,that,options,args),fluid.initDependents&&fluid.initDependents(that);var errors=fluid.validateListenersImplemented(that);return 0<errors.length&&fluid.fail(fluid.transform(errors,function(error){return["Error constructing component ",that," - the listener for event "+error.name+" with namespace "+error.namespace+(error.componentSource?" wh