-
Notifications
You must be signed in to change notification settings - Fork 380
/
core.js
64 lines (64 loc) · 2.64 KB
/
core.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
/*funcunit@3.2.2#browser/core*/
define(function (require, exports, module) {
var jQuery = require('./jquery');
var oldFuncUnit = require('./init');
var FuncUnit = oldFuncUnit.jQuery.sub();
var origFuncUnit = FuncUnit;
FuncUnit = function (selector, frame) {
var frame, forceSync, isSyncOnly = false;
if (frame && frame.forceSync) {
forceSync = frame.forceSync;
}
if (frame && typeof frame.frame !== 'undefined') {
frame = frame.frame;
}
isSyncOnly = typeof forceSync === 'boolean' ? forceSync : isSyncOnly;
if (typeof selector == 'function') {
return FuncUnit.wait(0, selector);
}
this.selector = selector;
if (isSyncOnly === true) {
var collection = performSyncQuery(selector, frame);
return collection;
} else {
performAsyncQuery(selector, frame, this);
var collection = performSyncQuery(selector, frame);
return collection;
}
};
var getContext = function (context) {
if (typeof context === 'number' || typeof context === 'string') {
var sel = typeof context === 'number' ? 'iframe:eq(' + context + ')' : 'iframe[name=\'' + context + '\']', frames = new origFuncUnit.fn.init(sel, FuncUnit.win.document.documentElement, true);
var frame = (frames.length ? frames.get(0).contentWindow : FuncUnit.win).document.documentElement;
} else {
frame = FuncUnit.win.document.documentElement;
}
return frame;
}, performAsyncQuery = function (selector, frame, self) {
FuncUnit.add({
method: function (success, error) {
this.frame = frame;
if (FuncUnit.win) {
frame = getContext(frame);
}
this.selector = selector;
this.bind = new origFuncUnit.fn.init(selector, frame, true);
success();
return this;
},
error: 'selector failed: ' + selector,
type: 'query'
});
}, performSyncQuery = function (selector, frame) {
var origFrame = frame;
if (FuncUnit.win) {
frame = getContext(frame);
}
var obj = new origFuncUnit.fn.init(selector, frame, true);
obj.frame = origFrame;
return obj;
};
oldFuncUnit.jQuery.extend(FuncUnit, oldFuncUnit, origFuncUnit);
FuncUnit.prototype = origFuncUnit.prototype;
module.exports = FuncUnit;
});