-
Notifications
You must be signed in to change notification settings - Fork 0
/
extAdmin.js
120 lines (96 loc) · 2.22 KB
/
extAdmin.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* @class extAdmin
*
* @singleton
*/
var extAdmin = extAdmin || {};
(function(){
Ext.apply( extAdmin, {
applyConfig : function( object, config )
{
if( object && config ) {
for( var property in config ) {
if( config[property] !== undefined ) {
object[property] = config[property];
}
}
}
return object;
},
applyConfigIf : function( object, config )
{
if( object && config ) {
for( var property in config ) {
if( object[property] === undefined && config[property] !== undefined ) {
object[property] = config[property];
}
}
}
return object;
},
applySafe : function( object, config )
{
if( object && config && typeof config === 'object' ) {
for( var property in object ) {
if( object.hasOwnProperty( property ) === false ) {
continue;
}
if( config[property] !== undefined ) {
object[property] = config[property];
}
}
}
return object;
},
abstractFn : function()
{
Ext.Error.raise({
msg: 'Not implemented abstract method called',
'this' : this
});
}
});
var chain = [ [ document.getElementById, document ] ];
var buildGetter = function()
{
var ln = chain.length,
getFn = null;
if( ln === 1 ) {
getFn = chain[0][0];
} else {
var getFnParts = [];
for( var i = 0; i < ln; ++i ) {
getFnParts.push( "chain["+ i +"][0].apply( chain["+ i +"][1], arguments )" );
}
getFn = new Function( 'chain', 'return function( id ) { return '+ getFnParts.join(' || ') +'; }' )( chain );
}
document.getElementById = getFn;
};
Ext.apply( extAdmin, {
/**
* Adds element getter to document.getElementById chain
*
* @param {Function} fn
* @param {Mixed} scope
*/
addElementGetter : function( fn, scope )
{
chain.push( [ fn, scope ] );
buildGetter();
},
/**
* Removes element getter from document.getElementById chain
*
* @param {Function} fn
*/
removeElementGetter : function( fn )
{
Ext.Array.forEach( chain, function( item, i ) {
if( item[0] == fn ) {
Ext.Array.remove( chain, item );
}
});
buildGetter();
}
});
}());