source: Dev/trunk/src/client/dojox/dtl/Context.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.0 KB
Line 
1define([
2        "dojo/_base/lang",
3        "./_base"
4], function(lang,dd){
5        return dd.Context = lang.extend(function(/*Object*/dict){
6                // summary:
7                //              Represents a runtime context used by DTL templates.
8                this._this = {};
9                dd._Context.call(this, dict);   // TODO: huh?
10        }, dd._Context.prototype,               // TODO: huh?
11        {
12                getKeys: function(){
13                        // summary:
14                        //              Returns the set of keys exported by this context.
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(/*dojox/dtl/Context|Object*/ obj){
24                        // summary:
25                        //              Returns a clone of this context object, with the items from the passed objecct mixed in.
26                        // obj:
27                        //              The object to extend.
28                        return  lang.delegate(this, obj);
29                },
30                filter: function(/*dojox/dtl/Context|Object|String...*/ filter){
31                        // summary:
32                        //              Returns a clone of this context, only containing the items defined in the filter.
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(/*Object*/ scope){
57                        // summary:
58                        //              Sets the object on which to perform operations.
59                        // scope:
60                        //              the this ref.
61                        this._this = scope;
62                },
63                getThis: function(){
64                        // summary:
65                        //              Gets the object on which to perform operations.
66                        return this._this;
67                },
68                hasKey: function(/*String*/key){
69                        // summary:
70                        //              Indicates whether the specified key is defined on this context.
71                        // key:
72                        //              The key to look up.
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});
Note: See TracBrowser for help on using the repository browser.