if(typeof ProtoScript=="undefined"){var ProtoScript={};} ProtoScript.Proto=function(){if(arguments.length===1){var config=arguments[0];if(window==this||!this.init){return new ProtoScript.Proto(config);} return this.init(config);}else{var identifierStr=arguments[0];var config=arguments[1];if(window==this||!this.init){return new ProtoScript.Proto(identifierStr,config);} var cfg=[];cfg[identifierStr]=config;return this.init(cfg);}};var $proto=ProtoScript.Proto;ProtoScript.Proto.prototype={init:function(cfg){ProtoScript.Core.startParseInteraction(cfg);ProtoScript.Core.startExecuteInteraction(cfg);}};ProtoScript.Core=function(){return{behaviorNamespace:null,$$:$,registerBehaviorSet:function(selectorMethod,behaviorNamespace){this.$$=selectorMethod;this.behaviorNamespace=behaviorNamespace;},getBehaviorNamespace:function(){return this.behaviorNamespace;},$:function(selector){try{if(typeof(selector)==='undefined'||selector===null||selector.length===0){return[];}else{if(selector.substr(0,1)==="$"){return[];}else{var tmp=this.$$(selector);var elems=this.$$(selector);var cleanArr=[];for(var i=0;i0&&cfgTarget.substr(0,1)==="$"){var pseudoName=cfgTarget.substr(1,cfgTarget.length-1);behaviorScope.elems=[scope.pseudoElems[pseudoName]];}else{}} this.callBehavior(behaviorCfg,behaviorScope);this.callBehaviors(behaviorCfg,behaviorScope);}}},callBehavior:function(behaviorCfg,currScope){var behavior=behaviorCfg._behaviorExt.action(currScope);},startExecuteInteraction:function(cfg){for(var identifierStr in cfg){var identifierCfg=cfg[identifierStr];var elems=ProtoScript.Core.$(identifierStr);this.executeInteraction(identifierCfg,false,1);}},createScope:function(cfg,idx,pseudoElems){var cfgTarget=cfg.target;var scopeElems;if(pseudoElems&&cfgTarget&&cfgTarget.length>0&&cfgTarget.substr(0,1)==="$"){var pseudoName=cfgTarget.substr(1,cfgTarget.length-1);scopeElems=[pseudoElems[pseudoName]];}else if(typeof(idx)!='undefined'&&idx!==null&&idx>=0){scopeElems=[cfg._elems[idx]];}else{scopeElems=cfg._elems;} return{elems:scopeElems,idx:idx,pseudoElems:pseudoElems};},getPseudoElemInScope:function(scope,pseudoName){var pseudoElems=scope.pseudoElems;var elem=null;if(pseudoElems){elem=[pseudoElems[pseudoName]];} return elem;},getElemInScope:function(scope,selector){var elems=null;if(selector!==null&&selector!==''){elems=ProtoScript.Core.$(selector);if(elems&&elems.length){if(typeof(scope.idx)!=='undefined'&&scope.idx!==null&&scope.idx>=0){var idx=scope.idx;elems=[elems[idx]];}}else if(scope.pseudoElems){var pseudoName=selector.substr(1,selector.length-1);elems=[scope.pseudoElems[pseudoName]];}} return elems;},executeInteraction:function(parentCfg,inCallback,level){var indents=" ";var indent=indents.substring(0,level*3);for(var propName in parentCfg){if(this.isBehavior(propName)){var behaviorCfg=parentCfg[propName];if(!inCallback){var behaviorScope=this.createScope(behaviorCfg,-1);this.callBehavior(behaviorCfg,behaviorScope);} this.executeInteraction(behaviorCfg,inCallback,level+1);}else if(this.isCallback(propName)){var callbackCfg=parentCfg[propName];this.executeInteraction(callbackCfg,true,level+1);}else{}}},initCfg:function(parentCfg,cfg,name,scopeElems,type){cfg._parentCfg=parentCfg;cfg._name=name;cfg._elems=scopeElems;cfg._type=type;},instantiateBehaviorExt:function(cfg,behName){console.log("instantiateBehaviorExt:name=",behName);var namespace=ProtoScript.Core.getBehaviorNamespace();if(namespace){try{cfg._behaviorExt=new namespace[behName](behName,cfg);}catch(e){alert("Sorry, the behavior '"+behName+"' could not be found. Check your spelling to make sure that behavior exists.");}}else{}},isBehavior:function(name){return(/^[A-Z]/.test(name))},isCallback:function(name){return(/^on/.test(name))},echoIdentifier:function(cfg){var elems=cfg._elems;var name=cfg._name;var tagName=elems.length>0?elems.tagName:"";var message="";if(elems.length>1){message=message+"For the "+elems.length+" elems: [ ";for(var i=0;i ";} message+="] matching '"+name+"'";}else if(elems.length===1){message+="For the <"+elems[0].tagName+"> matching '"+name+"'";} return message;},startParseInteraction:function(cfg){for(var identifierStr in cfg){var identifierCfg=cfg[identifierStr];var elems=ProtoScript.Core.$(identifierStr);this.initCfg(null,identifierCfg,identifierStr,elems,'element');this.parseInteraction(identifierCfg,false,1);}},applyConfig:function(defaultConfig,userConfig){for(prop in defaultConfig){var userSetProp=(typeof(userConfig[prop])!=='undefined'&&userConfig[prop]!==null&&userConfig[prop]!=='')?true:false;if(!userSetProp&&defaultConfig[prop]){userConfig[prop]=defaultConfig[prop];}} return userConfig;},createAnimConfig:function(userConfig){var animAttrs="borderWidth bottom fontSize left right top height margin opacity lineHeight padding width points color backgroundColor borderTopColor borderRightColor borderBottomColor borderLeftColor";var animConfig=new Object();for(prop in userConfig){if(animAttrs.match(prop)){animConfig[prop]=userConfig[prop];}} return animConfig;},testModifier:function(modifier,evt){return!modifier||evt[modifier];},dump:function(){for(var identifier in ProtoScript.Config){var behaviorSet=ProtoScript.Config[identifier];behaviorSet._name=identifier;var elems=ProtoScript.Core.$(identifier);var tagName=elems.length>0?elems.tagName:"";var message="";if(elems.length>1){message=message+"For the "+elems.length+" elems: [ ";for(var i=0;i ";} message+="] matching '"+identifier+"'";}else if(elems.length===1){} ProtoScript.Core.dumpConfig(behaviorSet,1);}},dumpConfig:function(props,level){var indents=" ";var indent=indents.substring(0,level*3);for(var propName in props){var propObj=props[propName];if(this.isBehavior(propName)){this.dumpConfig(propObj,level+1);}else if(this.isCallback(propName)){this.dumpConfig(propObj,level+1);}}}};}();