source: Dev/branches/rest-dojo-ui/client/dojox/dtl/Context.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.0 KB
Line 
1define([
2        "dojo/_base/lang",
3        "./_base"
4], function(lang,dd){
5        /*=====
6                dd = dojox.dtl;
7        =====*/
8       
9        /*=====
10         dd.Context = function(dict){
11                // summary: Represents a runtime context used by DTL templates.
12         }
13         
14        =====*/
15        dd.Context = lang.extend(function(dict){
16                this._this = {};
17                dd._Context.call(this, dict);
18        }, dd._Context.prototype,
19        {
20                getKeys: function(){
21                        // summary: Returns the set of keys exported by this context.
22                        var keys = [];
23                        for(var key in this){
24                                if(this.hasOwnProperty(key) && key != "_this"){
25                                        keys.push(key);
26                                }
27                        }
28                        return keys;
29                },
30                extend: function(/*dojox.dtl.Context|Object*/ obj){
31                        // summary: Returns a clone of this context object, with the items from the
32                        //              passed objecct mixed in.
33                        return  lang.delegate(this, obj);
34                },
35                filter: function(/*dojox.dtl.Context|Object|String...*/ filter){
36                        // summary: Returns a clone of this context, only containing the items
37                        //              defined in the filter.
38                        var context = new dd.Context();
39                        var keys = [];
40                        var i, arg;
41                        if(filter instanceof dd.Context){
42                                keys = filter.getKeys();
43                        }else if(typeof filter == "object"){
44                                for(var key in filter){
45                                        keys.push(key);
46                                }
47                        }else{
48                                for(i = 0; arg = arguments[i]; i++){
49                                        if(typeof arg == "string"){
50                                                keys.push(arg);
51                                        }
52                                }
53                        }
54
55                        for(i = 0, key; key = keys[i]; i++){
56                                context[key] = this[key];
57                        }
58
59                        return context;
60                },
61                setThis: function(/*Object*/ _this){
62                        // summary: Sets the object on which to perform operations.
63                        // _this: the this ref.
64                        this._this = _this;
65                },
66                getThis: function(){
67                        // summary: Gets the object on which to perform operations.
68                        return this._this;
69                },
70                hasKey: function(/*String*/key){
71                        // summary: Indicates whether the specified key is defined on this context.
72                        // key: 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});
87return dojox.dtl.Context;
88});
Note: See TracBrowser for help on using the repository browser.