(function(){ var jQ = function(selector, father){ return new jQ.prototype.init(selector); }; jQ.prototype = { length:0, init:function(selector, father){ var _document = father || ja.view, classInt = 0, res = this; if (typeof selector != "string" || !selector ){ if(typeof selector == "object" && selector.hasOwnProperty("length")){ for(var i = 0 ; i < selector.length ; i++){ this[classInt] = selector[i]; classInt++; } }else{ this[classInt] = selector; classInt++; } }else{ var props = selector.trim().split(" "), selector = props.shift(), selectLast = props.join(" "), mark = selector.charAt(0); if(mark == "["){ var selector=selector.replace(/[\[\]]/g,""), arr = selector.split("="); key = arr.length > 1 ? arr[0].trim() : "name", val = arr.length > 1 ? arr[1].trim() : arr[0].trim(); //遍历children // ja.log(key,val); _document.children.map(function(ele){ return (function(father,deep){ // var res = []; if(typeof father[key] !="undefined" && father[key] == val){ this[classInt] = father; classInt++; } var c = father.children; if(c && deep < 5){ deep++; for(var i in c){ arguments.callee.call(this,c[i],deep); } } // return res; }).call(this,ele,0); }.bind(this)) }else if(mark == "."){ var res = this.__class(selector.substring(1)); res.map(function(ele){ this[classInt] = ele; classInt++; }.bind(this)); } } this.length = classInt; return this; }, /*原型方法,不暴露*/ //类选择器位置列表 __class:function(className){ var arr = []; switch (className){ case "mainView": arr.push(ja.view); break; case "setBalance": arr.push(ja.setb); break; case "gameBalance": arr.push( ja.gameb); break; case "playerFrameList": for(var key in ja.view.playerInfoHandler.playerFrameList){ arr.push(ja.view.playerInfoHandler.playerFrameList[key].view); } break; case "playerArea": arr.push( ja.view.posLocal2Player); break; case "playerOut": ja.view.posLocal2Player.map(function(ele){ arr.push( ele.outTile); }); break; default: return null } return arr; }, //通过选择器确定子元素获取方式 _selector: function(selector, father){ if(typeof selector != "string" || !selector){ return this; } father = father ? father.children : Array.prototype.slice.apply(this); var mark = selector.charAt(0); switch(mark){ case "[": var reg = /\[(([\w\W]+)=["']?([\w\W]+)["']?|([\w\W]+))\]/; var reg_res = reg.exec(selector); var res_key = reg_res[2] || "name"; var res_val = reg_res[3] || reg_res[4]; var res = []; father.map(function(ele){ return (function(fa, deep){ if(typeof fa[res_key] != "undefined" && fa[res_key] == res_val){ res.push(fa); } if (fa.children.length > 0 && deep < 5){ deep++; for( var i = 0 ; i < fa.children.length ; i++){ var add = arguments.callee.call(this,fa.children[i],deep); } } return res; }).call(this,ele,0); }.bind(this)); return res; case ":": break; case "*": break; default: } }, //表达式筛选器,未完成 _expression:function(expression){ if(!expression){ } switch (expression){ case "first": return 0; case "last": return } }, /*过滤*/ find:function(selector){ var res = this._selector(selector); return new jQ.prototype.init(res); }, parent:function(){ var arr = []; Array.prototype.slice.apply(this).map(function(ele,ind){ arr.push(ele["parent"]); }.bind(this)); if(arr.length > 0){ var res = arr.length == 1 ? arr.shift() : arr; return new jQ.prototype.init(res); } }, parents:function(){ }, child:function(selector){ }, /*操作*/ attr:function(selector, setValue){ var arr = []; Array.prototype.slice.apply(this).map(function(ele,ind){ if(typeof setValue == "undefined"){ if(typeof ele[selector] != "undefined"){ arr.push(ele[selector]) ; }else if(typeof ele["_"+selector] != "undefined"){ arr.push(ele["_"+selector]) ; } }else{ ele[selector] = setValue; } }.bind(this)); if(arr.length > 0){ return arr.length == 1 ? arr.shift() : arr; } }, hide:function(){ Array.prototype.slice.apply(this).map(function(ele){ ele.setVisible(false); }) }, show:function(){ Array.prototype.slice.apply(this).map(function(ele){ ele.setVisible(true); }) }, }; jQ.prototype.init.prototype = jQ.prototype; return window.$ = jQ; })()