日期:2014-05-16 浏览次数:20343 次
selector.model = { template: { 'Id': (/^#(\w+)/), // 1: id 'Class': (/^\.(\w+)/), // 1: class 'Tag': (/^([a-z]+[1-7]*)/i), // 1: tag 'Attr': (/^\[(\w+?)(([~\^\$\*]*=)(['"])(.*?)\4)*\]/), // 1: attr; 3: flag; 5: value; 'Child': (/^>/), 'Sibling': (/^\+/), 'Next': (/^\s+/) }, byId: function(id) { return d.getElementById(id)? [d.getElementById(id)] : []; }, byTag: function(parent, tag) { var result = []; var stag = tag? tag : '*' var temp; ui.each(parent, function(v, i) { temp = v.getElementsByTagName(stag); if(temp) { result = result.concat(ui.toArray(temp)); } }); var ss = result; return result; }, byChild: function(parent, tag) { var result = []; ui.each(parent, function(v, i) { childs = ui.toArray(v.childNodes); ui.each(childs, function(vi, ii) { if(vi.nodeType == 1) { if(!tag || (tag && vi.nodeName.toLowerCase() == tag)) { result.push(vi); } } }); }); return result; }, bySibling: function(nodes, tag) { var result = []; var temp; ui.each(nodes, function(v, i) { temp = v; while(temp.nextSibling) { temp = temp.nextSibling; if(temp.nodeType == 1) { if(!tag || tag && temp.nodeName.toLowerCase() == tag) { result.push(temp); break; } } } }); return result; }, byAttr: function(nodes, k, v, f) { var result = []; var fi = f? f : '='; var vi = v? v : '\[\.\\s\\S]\+'; var reg = fi == '~='? '(^|\\s)' + vi + '(\\s|$)' : fi == '^='? '^' + vi : fi == '$='? vi + '$' : fi == '*='? vi : '^' + vi + '$'; reg = new RegExp(reg); var ki = ui.browser.ie && k == 'class'? 'className' : k; var att; ui.each(nodes, function(vii, i) { att = vii.getAttribute(ki); if(att && reg.test(att)) { result.push(vii); } }); return result; }, byClass: function(nodes, cl) { var result = []