/
jquip.q-min.js
68 lines (63 loc) · 2.43 KB
/
jquip.q-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$['plug'](function($){
var doc = document,
$id = function(id, ctx){ return (ctx || doc).getElementById(id); },
$tag = function(tag, ctx){ return (ctx || doc).getElementsByTagName(tag); },
$cls = doc.getElementsByClassName //&& false
? function(cls, ctx){
return (ctx || doc).getElementsByClassName(cls); }
: function(cls, ctx){
var ret = $['walk'](function(el){
return el.className && el.className.indexOf(cls) >= 0;
}, (ctx || doc));
return $['unique'](ret);
};
function childSel(sel, ctx){
var el = $['$$'](ctx)[0], cls = sel.split('.'), tag = cls.shift(), fPos = tag.indexOf('['), fName, fValue, parts,
firstChar = tag.charAt(0);
if (firstChar == "#") return $id(tag.substring(1), el);
if (fPos >= 0){
parts = tag.substring(fPos + 1, tag.length - 1).split('=');
fName = parts[0];
fValue = parts.length == 2 && parts[1];
if (fValue && fValue.charAt(0) == "'")
fValue = fValue.substring(1, fValue.length - 1);
tag = tag.substring(0, fPos);
}
var tagWithId = tag.split('#');
if (tagWithId.length == 2){
el = $id(tagWithId[1], el);
if (!el) return [];
if (!$['eqSI'](el.tagName, tagWithId[0])) return [];
if (cls.length == 1) return [el];
}
var els = tag ? $tag(tag, el) : $cls(cls.shift(), el);
if (!cls.length && !fName) return els;
var ret = [];
for(var i = 0, l = els.length; i < l; i++){
var subEl = els[i], j = cls.length, matches = true;
if (cls.length) while (j--) if (!$['hasClass']([subEl], cls[j])) matches = false;
if (matches && (!fName || (!fValue || subEl[fName] == fValue)))
ret.push(subEl);
}
return ret;
}
$['setQuery'](function(selector, ctx){
if (doc.querySelectorAll)
return (ctx || doc).querySelectorAll(selector);
var els, resSet = [
[(ctx || doc)]
], heir = selector.split(' '), ret = [];
for(var i = 0, l = heir.length; i < l; i++){
var parentSet = resSet[i];
if (parentSet.length == 0) return ret;
var sel = heir[i], res = [];
for(var j = 0, jlen = parentSet.length; j < jlen; j++){
els = childSel(sel, parentSet[j]);
for(var k = 0, klen = els.length; k < klen; k++)
res.push(els[k]);
}
resSet.push(res);
}
return resSet.length > 1 ? resSet.pop() : [];
});
});