| 1 |
define([ |
| 2 |
"dojo/_base/lang", |
| 3 |
"./_base" |
| 4 |
], function(lang,dd){ |
| 5 |
return dd.Context = lang.extend(function(dict){ |
| 6 |
|
| 7 |
|
| 8 |
this._this = {}; |
| 9 |
dd._Context.call(this, dict); |
| 10 |
}, dd._Context.prototype, |
| 11 |
{ |
| 12 |
getKeys: function(){ |
| 13 |
|
| 14 |
|
| 15 |
var keys = []; |
| 16 |
for(var key in this){ |
| 17 |
if(this.hasOwnProperty(key) && key != "_this"){ |
| 18 |
keys.push(key); |
| 19 |
} |
| 20 |
} |
| 21 |
return keys; |
| 22 |
}, |
| 23 |
extend: function( obj){ |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
return lang.delegate(this, obj); |
| 29 |
}, |
| 30 |
filter: function( filter){ |
| 31 |
|
| 32 |
|
| 33 |
var context = new dd.Context(); |
| 34 |
var keys = []; |
| 35 |
var i, arg; |
| 36 |
if(filter instanceof dd.Context){ |
| 37 |
keys = filter.getKeys(); |
| 38 |
}else if(typeof filter == "object"){ |
| 39 |
for(var key in filter){ |
| 40 |
keys.push(key); |
| 41 |
} |
| 42 |
}else{ |
| 43 |
for(i = 0; arg = arguments[i]; i++){ |
| 44 |
if(typeof arg == "string"){ |
| 45 |
keys.push(arg); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
for(i = 0, key; key = keys[i]; i++){ |
| 51 |
context[key] = this[key]; |
| 52 |
} |
| 53 |
|
| 54 |
return context; |
| 55 |
}, |
| 56 |
setThis: function( scope){ |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
this._this = scope; |
| 62 |
}, |
| 63 |
getThis: function(){ |
| 64 |
|
| 65 |
|
| 66 |
return this._this; |
| 67 |
}, |
| 68 |
hasKey: function(key){ |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if(this._getter){ |
| 74 |
var got = this._getter(key); |
| 75 |
if(typeof got != "undefined"){ |
| 76 |
return true; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
if(typeof this[key] != "undefined"){ |
| 81 |
return true; |
| 82 |
} |
| 83 |
|
| 84 |
return false; |
| 85 |
} |
| 86 |
}); |
| 87 |
}); |