sproutit-sproutcore 1.0.20090721145251 → 1.0.20090721145280

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/Rakefile +3 -3
  2. data/VERSION.yml +2 -2
  3. data/frameworks/sproutcore/Buildfile +0 -1
  4. data/gen/app/templates/apps/@target_name@/core.js +27 -0
  5. data/gen/app/templates/apps/@target_name@/english.lproj/loading.rhtml +9 -0
  6. data/gen/app/templates/apps/@target_name@/english.lproj/main_page.js +22 -0
  7. data/gen/app/templates/apps/@target_name@/english.lproj/strings.js +15 -0
  8. data/gen/app/templates/apps/@target_name@/main.js +30 -0
  9. data/gen/controller/templates/controllers/@filename@.js +18 -0
  10. data/gen/controller/templates/tests/controllers/@filename@.js +15 -0
  11. data/gen/framework/templates/frameworks/@target_name@/core.js +21 -0
  12. data/gen/framework/templates/frameworks/@target_name@/english.lproj/strings.js +15 -0
  13. data/gen/language/templates/@filename@/strings.js +14 -0
  14. data/gen/model/templates/fixtures/@filename@.js +35 -0
  15. data/gen/model/templates/models/@filename@.js +19 -0
  16. data/gen/model/templates/tests/models/@filename@.js +15 -0
  17. data/gen/project/templates/@filename@/Buildfile +7 -0
  18. data/gen/project/templates/@filename@/README +7 -0
  19. data/gen/test/templates/tests/@filename@.js +15 -0
  20. data/gen/theme/templates/themes/@target_name@/english.lproj/strings.js +15 -0
  21. data/gen/view/templates/tests/views/@filename@.js +15 -0
  22. data/gen/view/templates/views/@filename@.js +18 -0
  23. data/lib/sproutcore/models/generator.rb +2 -2
  24. metadata +21 -33
  25. data/frameworks/sproutcore/frameworks/deprecated/core.js +0 -59
  26. data/frameworks/sproutcore/frameworks/deprecated/lib/button_views.rb +0 -330
  27. data/frameworks/sproutcore/frameworks/deprecated/lib/collection_view.rb +0 -83
  28. data/frameworks/sproutcore/frameworks/deprecated/lib/core_views.rb +0 -326
  29. data/frameworks/sproutcore/frameworks/deprecated/lib/form_views.rb +0 -253
  30. data/frameworks/sproutcore/frameworks/deprecated/lib/index.rhtml +0 -75
  31. data/frameworks/sproutcore/frameworks/deprecated/lib/menu_views.rb +0 -93
  32. data/frameworks/sproutcore/frameworks/deprecated/server/rails_server.js +0 -80
  33. data/frameworks/sproutcore/frameworks/deprecated/server/rest_server.js +0 -178
  34. data/frameworks/sproutcore/frameworks/deprecated/server/server.js +0 -673
  35. data/frameworks/sproutcore/frameworks/deprecated/system/animator.js +0 -679
  36. data/frameworks/sproutcore/frameworks/deprecated/system/binding.js +0 -36
  37. data/frameworks/sproutcore/frameworks/deprecated/system/browser.js +0 -75
  38. data/frameworks/sproutcore/frameworks/deprecated/system/classic_responder.js +0 -312
  39. data/frameworks/sproutcore/frameworks/deprecated/system/event.js +0 -58
  40. data/frameworks/sproutcore/frameworks/deprecated/system/globals.js +0 -20
  41. data/frameworks/sproutcore/frameworks/deprecated/system/misc.js +0 -58
  42. data/frameworks/sproutcore/frameworks/deprecated/system/node_descriptor.js +0 -72
  43. data/frameworks/sproutcore/frameworks/deprecated/system/object.js +0 -122
  44. data/frameworks/sproutcore/frameworks/deprecated/system/path_module.js +0 -432
  45. data/frameworks/sproutcore/frameworks/deprecated/system/string.js +0 -107
  46. data/frameworks/sproutcore/frameworks/deprecated/tests/application/application.rhtml +0 -125
  47. data/frameworks/sproutcore/frameworks/deprecated/tests/views/classic_view/clippingFrame.rhtml +0 -401
  48. data/frameworks/sproutcore/frameworks/deprecated/tests/views/classic_view/frame.rhtml +0 -357
  49. data/frameworks/sproutcore/frameworks/deprecated/tests/views/classic_view/isVisibleInWindow.rhtml +0 -147
  50. data/frameworks/sproutcore/frameworks/deprecated/tests/views/collection/base.rhtml +0 -298
  51. data/frameworks/sproutcore/frameworks/deprecated/tests/views/collection/incremental_rendering.rhtml +0 -260
  52. data/frameworks/sproutcore/frameworks/deprecated/tests/views/collection/source_list_rendering.rhtml +0 -143
  53. data/frameworks/sproutcore/frameworks/deprecated/tests/views/popup_button.rhtml +0 -128
  54. data/frameworks/sproutcore/frameworks/deprecated/tests/views/text_field.rhtml +0 -37
  55. data/frameworks/sproutcore/frameworks/deprecated/views/collection.js +0 -24
@@ -1,20 +0,0 @@
1
- // ========================================================================
2
- // SproutCore -- JavaScript Application Framework
3
- // Copyright ©2006-2008, Sprout Systems, Inc. and contributors.
4
- // Portions copyright ©2008 Apple, Inc. All rights reserved.
5
- // ========================================================================
6
-
7
- // Globally defined variables are no longer supported to allow SproutCore to
8
- // work with other libraries.
9
- // Export the type variables into the global space.
10
- var T_ERROR = SC.T_ERROR ;
11
- var T_OBJECT = SC.T_OBJECT ;
12
- var T_NULL = SC.T_NULL ;
13
- var T_CLASS = SC.T_CLASS ;
14
- var T_HASH = SC.T_HASH ;
15
- var T_FUNCTION = SC.T_FUNCTION ;
16
- var T_UNDEFINED = SC.T_UNDEFINED ;
17
- var T_NUMBER = SC.T_NUMBER ;
18
- var T_BOOL = SC.T_BOOL ;
19
- var T_ARRAY = SC.T_ARRAY ;
20
- var T_STRING = SC.T_STRING ;
@@ -1,58 +0,0 @@
1
- // ========================================================================
2
- // SproutCore -- JavaScript Application Framework
3
- // Copyright ©2006-2008, Sprout Systems, Inc. and contributors.
4
- // Portions copyright ©2008 Apple, Inc. All rights reserved.
5
- // ========================================================================
6
-
7
- // Legacy. Will retire.
8
- SC.mixin(Object,
9
- /** @scope Object */ {
10
-
11
- /** @deprecated
12
- Serialize a general JSON object into a URI. This method of encoding is
13
- no longer supported or recommended.
14
- */
15
- serialize: function(obj) {
16
- var ret = [] ;
17
- for(var key in obj) {
18
- var value = obj[key] ;
19
- if (typeof value == 'number') { value = '' + value ; }
20
- if (!(typeof value == 'string')) { value = value.join(','); }
21
- ret.push(encodeURIComponent(key) + "=" + encodeURIComponent(value)) ;
22
- }
23
- return ret.join('&') ;
24
- }
25
-
26
- }) ;
27
-
28
- /** @deprecated
29
- This will add or remove the class name based on the flag, allowing you to
30
- treat it like a bool setting. Simplifies the common case where you need
31
- to make a class name match a bool.
32
-
33
- Since SproutCore no long requires the Prototype library, this extension to
34
- Prototype is also no longer supported. You can use setClassName() on
35
- SC.ClassicView, or the sproutcore-jquery framework instead.
36
- */
37
- Element.setClassName = function(element,className,flag) {
38
- if(SC.browser.isIE)
39
- {
40
- if (flag) {
41
- Element.addClassName(element,className);
42
- } else {
43
- Element.removeClassName(element,className) ;
44
- }
45
- }
46
- else
47
- {
48
- if (flag) {
49
- element.addClassName(className);
50
- } else {
51
- element.removeClassName(className) ;
52
- }
53
- }
54
- } ;
55
-
56
-
57
- SC.Routes = SC.routes;
58
- SC.Routes.addRoute = SC.routes.add;
@@ -1,72 +0,0 @@
1
- // ========================================================================
2
- // SproutCore -- JavaScript Application Framework
3
- // Copyright ©2006-2008, Sprout Systems, Inc. and contributors.
4
- // Portions copyright ©2008 Apple, Inc. All rights reserved.
5
- // ========================================================================
6
-
7
- require('core') ;
8
-
9
- /**
10
- This object can generate HTML DOM elements from a hash-based description of
11
- the nodes. See the NodeDescriptor wiki page for complete docs.
12
-
13
- See https://wiki.sproutit.com/engineering/show/NodeDescriptor
14
-
15
- @deprecated
16
- */
17
- SC.NodeDescriptor = {
18
- create: function(descriptor, opts) {
19
- if (!opts) opts = {} ;
20
- // collect info from descriptor
21
- var tag = opts.tag || descriptor.tag || 'div' ;
22
- var className = opts.cssClass || descriptor.cssClass ;
23
- var elementId = opts.id || descriptor.id ;
24
- var style = opts.style || descriptor.style ;
25
- var innerHTML = opts.innerHTML || descriptor.innerHTML ;
26
- if (!innerHTML) {
27
- var childNodes = opts.childNodes || descriptor.childNodes ;
28
- }
29
-
30
- // create element
31
- var ret = $(document.createElement(tag)) ;
32
- if (className) ret.className = className ;
33
- if (elementId) ret.id = elementId ;
34
- if (style) {
35
- for (var name in style) element.style[name.camelize()] = style[name];
36
- }
37
-
38
- // apply extra attributes
39
- for(var attr in descriptor) {
40
- if (this.ignoredProperties.indexOf(attr) == -1) {
41
- ret.setAttribute(attr,descriptor[attr]) ;
42
- }
43
- }
44
-
45
- // build child nodes, if they exist.
46
- if (innerHTML) {
47
- ret.innerHTML = innerHTML ;
48
- } else if (childNodes) {
49
- var that = this ;
50
- childNodes.each(function(desc) {
51
- ret.appendChild(that.create(desc)) ;
52
- }) ;
53
- that=null;
54
- childNodes=null;
55
- }
56
-
57
- try{
58
- return ret ;
59
- }finally{
60
- //ie7 memory leaks
61
- tag=null;
62
- className=null;
63
- elementId=null;
64
- style=null;
65
- innerHTML=null;
66
- ret=null;
67
- }
68
- },
69
-
70
- ignoredProperties: ['tag','cssClass','id','style','childNodes','innerHTML']
71
- };
72
-
@@ -1,122 +0,0 @@
1
- // ========================================================================
2
- // SproutCore -- JavaScript Application Framework
3
- // Copyright ©2006-2008, Sprout Systems, Inc. and contributors.
4
- // Portions copyright ©2008 Apple, Inc. All rights reserved.
5
- // ========================================================================
6
-
7
- SC.mixin(SC.Object, {
8
-
9
- /** @deprecated
10
- This method will listen for the observed value to change one time and
11
- then will remove itself. You can also set an optional timeout that
12
- will cause the function to be triggered (and the observer removed) after
13
- a set amount of time even if the value never changes. The function
14
- can expect an extra parameter, 'didTimeout', set to true.
15
-
16
- The returned value is the function actually set as the observer. You
17
- can manually remove this observer by calling the cancel() method on it.
18
- */
19
- observeOnce: function(key, target, method, timeout) {
20
-
21
- // fixup the params
22
- var targetType = SC.typeOf(target) ;
23
- if (targetType === SC.T_FUNCTION) {
24
- if ((SC.typeOf(method) === SC.T_NUMBER) && (timeout === undefined)) {
25
- timeout = method ;
26
- }
27
- method = target ;
28
- target = this ;
29
- }
30
-
31
- // convert the method to a function if needed...
32
- if (SC.typeOf(method) === SC.T_STRING) method = target[method] ;
33
- if (!method) throw "You must pass a valid method to observeOnce()";
34
-
35
- var timeoutObject = null ;
36
-
37
- // define a custom observer that will call the target method and remove
38
- // itself as an observer.
39
- var handler = function(observer, target, property, value, rev, didTimeout) {
40
- // invoke method...
41
- method.call(this, observer, target, property, value, rev, didTimeout);
42
-
43
- // remove observer...
44
- target.removeObserver(key, this, handler) ;
45
-
46
- // if there is a timeout, invalidate it.
47
- if (timeoutObject) { timeoutObject.invalidate();}
48
-
49
- // avoid memory leaks
50
- handler = target = method = timeoutObject = null;
51
- } ;
52
-
53
- // now add observer
54
- target.addObserver(key, target, handler) ;
55
- if (timeout) {
56
- timeoutObject = function() {
57
- handler(null, target, key, target.get(key), target.propertyRevision, true) ;
58
- handler = target = method = timeoutObject = null;
59
- }.invokeLater(this, timeout) ;
60
- }
61
-
62
- handler.cancel = function() {
63
- target.removeObserver(key, target, handler);
64
- handler = target = method = timeoutObject = null;
65
- } ;
66
-
67
- return handler ;
68
- },
69
-
70
- /** @deprecated
71
- Takes an array of hashes and returns newly created instances.
72
-
73
- This convenience method will take an array of properties and simply
74
- instantiates objects from them.
75
-
76
- @params {Array} array Array of hashes with properties to assigned to each object.
77
- @returns {Array} instantiated objects.
78
- */
79
- createEach: function(array) {
80
- return array.map(function(props) { return this.create(props); }, this);
81
- },
82
-
83
- /** @deprecated
84
- Adding this function to the end of a view declaration will define the
85
- class as an outlet that can be constructed using the outlet() method
86
- (instead of get()).
87
-
88
- @returns {Outlet} a specially constructed function that will be used to
89
- build the outlet later.
90
- */
91
- outlet: function() {
92
- var obj = this ;
93
- return function() {
94
- var ret = obj.create() ; ret.owner = this ; return ret ;
95
- }.property().cacheable().outlet() ;
96
- },
97
-
98
- /** @deprecated
99
- Returns all the keys defined on this object, excluding any defined in
100
- parent classes unless you pass all.
101
-
102
- @param {Boolean} all OPTIONAL: if YES return all keys, NO return only keys belonging to object itself. Defaults to NO.
103
- @returns {Array} keys
104
- */
105
- keys: function(all) {
106
- var ret = [];
107
- for(var key in this) {
108
- if (all || ret.hasOwnProperty(key)) ret.push(key);
109
- }
110
- return ret ;
111
- },
112
-
113
- tupleForPropertyPath: SC.tupleForPropertyPath,
114
- objectForPropertyPath: SC.objectForPropertyPath,
115
- createArray: SC.Object.createEach
116
- });
117
-
118
- /** @deprecated
119
- outlet() now works just like get(). Use get() instead.
120
- */
121
- SC.Object.prototype.outlet = SC.Object.prototype.get ;
122
-
@@ -1,432 +0,0 @@
1
- // ========================================================================
2
- // SproutCore -- JavaScript Application Framework
3
- // Copyright ©2006-2008, Sprout Systems, Inc. and contributors.
4
- // Portions copyright ©2008 Apple, Inc. All rights reserved.
5
- // ========================================================================
6
- //
7
- // When creating a web app, you often need to find elements in your page to
8
- // configure them on load. These elements are often marked with a class or
9
- // id. General purpose methods such as $$() or getElementsByClassName are
10
- // not very good for this because they search entire trees of nodes.
11
- //
12
- // These methods are much faster because they make some assumptions about
13
- // how your elements are structured.
14
- //
15
- // ==========================================================================
16
-
17
- require('core') ;
18
-
19
- // Constants
20
- SC.BENCHMARK_SELECTOR = NO ;
21
- NO_LIMIT = 10000 ;
22
-
23
- /**
24
- PathModule is high-performance API for locating DOM nodes in your HTML
25
- document. It's designed to be used by searching elements from a parent
26
- node.
27
-
28
- PathModule is patched into Prototypes Element.Methods, which means that
29
- you can automatically access this API for any DOM element retrieved via
30
- the $() operator. You can also mixin the PathModule api to your own
31
- objects. Be sure to also have a property called rootElement that points to
32
- the root DOM element you want to search.
33
- */
34
- SC.PathModule = {
35
-
36
- // NOTE: The code below simulates having document.rootElement = document.
37
- // we can't actually do this assignment because it will leak memory in IE.
38
-
39
- $$func: function(func, levels, max, nest) {
40
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
41
- return SC._PathModule.$$func(el,func,levels,max,nest);
42
- },
43
-
44
- $$C: function(className, levels, max, nest) {
45
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
46
- return SC._PathModule.$$C(el,className,levels,max,nest);
47
- },
48
-
49
- $$T: function(tagName, levels, max, nest) {
50
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
51
- return SC._PathModule.$$T(el,tagName,levels,max,nest);
52
- },
53
-
54
- $$P: function(property, value, levels, max, nest) {
55
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
56
- return SC._PathModule.$$P(el, property, value, levels, max, nest);
57
- },
58
-
59
- $$S: function(selector, levels, max, nest) {
60
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
61
- return SC._PathModule.$$S(el, selector, levels, max, nest);
62
- },
63
-
64
- // finds the first node for which func returns true.
65
- $func: function(func, levels) {
66
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
67
- return SC._PathModule.$func(el, func, levels);
68
- },
69
-
70
- // finds the first node with class name. returns element, not array.
71
- $C: function(className, levels) {
72
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
73
- return SC._PathModule.$C(el, className, levels);
74
- },
75
-
76
- // finds the first node with tag name. returns element, not array.
77
- $T: function(tagName, levels) {
78
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
79
- return SC._PathModule.$T(el, tagName, levels);
80
- },
81
-
82
- // find first node with an attribute matching then named value.
83
- $P: function(attr, value, levels) {
84
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
85
- return SC._PathModule.$P(el, attr, value, levels);
86
- },
87
-
88
- // find first node matching the specified class selector.
89
- $S: function(selector, levels) {
90
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
91
- return SC._PathModule.$S(el, selector, levels);
92
- },
93
-
94
- // find an element and configure it as the named view if it is not already
95
- // configured.
96
- $$view: function(selector, viewClass, levels, max, nest) {
97
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
98
- return SC._PathModule.$$view(el, selector, viewClass, levels, max, nest) ;
99
- },
100
-
101
- // find the first element matching the selector and create a view if it is
102
- // not already configured.
103
- $view: function(selector, viewClass, levels) {
104
- var el = (this.rootElement) ? this.rootElement : (this === document) ? document : null ;
105
- return SC._PathModule.$view(el, selector, viewClass, levels) ;
106
- }
107
-
108
- };
109
-
110
- // This version of PathModule can be added to Element.Methods among others.
111
- // It is the same API except that it passes the element as the first parameter.
112
- SC._PathModule = {
113
-
114
- // this is the core method that needs to be implemented for each object.
115
- // this method will search the receiver (up to _levels_ deep) for _max_
116
- // elements for which the function func() returns true.
117
- //
118
- // el: (req) the root element. If you pass null, document will be used.
119
- // func: (req) the function to be used to check each element.
120
- // levels: (opt) the max levels deep in nested elements. defaults: NO_LIMIT
121
- // max: (opt) the maximum number of elements to return. defaults:
122
- // NO_LIMIT
123
- // nest: (opt) if true, then the children of matched elements will also be
124
- // searched. if your element matches will never be nested, setting
125
- // this to false can be much faster. defaults: false
126
- $$func: function(el, func, levels, max, nest) {
127
- // defaults
128
- levels = levels || NO_LIMIT ; max = max || NO_LIMIT; nest = nest || false;
129
-
130
- // function to search this node.
131
- var searchNode = function(node, depth, remain, includeThisNode) {
132
- var ret = [] ;
133
-
134
- // does this node match?
135
- // we extend any returned elements so you can chain these methods.
136
- // on browsers that support HTMLElement.prototype, this will do nothing.
137
- var match = (includeThisNode) ? func(node) : false ;
138
- if (match) { ret.push(node); remain--; }
139
-
140
- // can we search children?
141
- depth-- ;
142
- if ((match && !nest) || (remain<=0) || (depth<=0)) return ret;
143
-
144
- // search children.
145
- node = node.firstChild ;
146
- while(node && (remain > 0)) {
147
- var found = searchNode(node,depth,remain,true) ;
148
- remain -= found.length ;
149
- ret = ret.concat(found) ;
150
- node = node.nextSibling ;
151
- }
152
- return ret ;
153
- } ;
154
-
155
- return searchNode(el || document, levels+1, max, false) ;
156
- },
157
-
158
- // finds all nodes with class name.
159
- $$C: function(el, className, levels, max, nest) {
160
- return SC._PathModule.$$func(el, function(node) {
161
- return Element.hasClassName(node, className) ;
162
- }, levels, max, nest) ;
163
- },
164
-
165
- // find all nodes with tag name
166
- $$T: function(el, tagName, levels, max, nest) {
167
- tagName = tagName.toUpperCase() ;
168
- return SC._PathModule.$$func(el, function(node) {
169
- return node.tagName == tagName;
170
- }, levels, max, nest) ;
171
- },
172
-
173
- // find all nodes with an attribute matching then named value.
174
- $$P: function(el, property, value, levels, max, nest) {
175
- return SC._PathModule.$$func(el, function(node) {
176
- var pvalue = (node.getAttribute) ? node.getAttribute(property) : node[property] ;
177
- return pvalue == value;
178
- }, levels, max, nest) ;
179
- },
180
-
181
- // this will parse the selector and then execute the selectors to return
182
- // the result. this understands a very simple form for selectors. the
183
- // parts are split by spaces. and treated like so:
184
- // '.classname' = class name
185
- // 'tag' = tag
186
- // '#id' = an id. (this will bypass the normal selector methods)
187
- // 'attr=value' = find an attr with the value.
188
- //
189
- // understands the following qualifiers:
190
- // .selector:3 => find .selector at most 3 levels deep
191
- // .selector:3:4 => find at most 4 .selectors at most 3 levels deep
192
- // .selector? => find at most 1 .selector, any depth.
193
- // .selector?3 => find at most 3 .selectors, any depth
194
- // .selector:*:4 => find at more 4 .selectors at any depth.
195
- //
196
- // You can also directly access child nodes by doing:
197
- // .selector[0][1][3] -> get child 3 of child 1 of child 0.
198
- // or:
199
- // [0][2][3] -> search base.
200
- //
201
- $$S: function(el,selector, levels, max, nest) {
202
- var parts = selector.split(' ') ;
203
- var ret = [el] ; var nextMax = null ; var bits ;
204
- var blevels; var bmax; var q; var indicies ;
205
-
206
- parts.each(function(part) {
207
- // this is included for compatibility with earlier changes I made to
208
- // prototype. the preferred way to do this in the future is with with
209
- // the colon format.
210
- if (part == '?') { nextMax = 1; return ; }
211
-
212
- // get defaults
213
- blevels = levels; bmax = (nextMax) ? nextMax : max ;
214
- nextMax = null ;
215
-
216
- // if there are indexes, find those and save them.
217
- if (part.slice(part.length-1,part.length) == ']') {
218
- bits = part.split('[') ;
219
- part = bits.shift();
220
- indicies = bits.map(function(b) {return parseInt(b.slice(0,-1),0);});
221
- } else indicies = null ;
222
-
223
- // find found modifiers
224
- bits = part.split('?') ;
225
- part = bits[0] ;
226
- if (bits.length > 1) {
227
- bmax = (bits[1].length == 0) ? 1 : parseInt(bits[1],0) ;
228
- }
229
-
230
- // find level modifiers
231
- bits = part.split(':') ;
232
- part = bits[0] ;
233
- if (bits.length > 1) blevels = (bits[1] == '*') ? '*' : parseInt(bits[1],0) ;
234
- if (bits.length > 2) bmax = (bits[2] == '*') ? '*' : parseInt(bits[2],0) ;
235
-
236
- // convert star to NO_LIMIT
237
- if (blevels == '*') blevels = NO_LIMIT ;
238
- if (bmax == '*') bmax = NO_LIMIT ;
239
-
240
- // prepare the selector info.
241
- // q tells us how to process the first part.
242
- // part is the first part of the selector
243
- // bits are any extra css selectors.
244
- if (part && part.length > 0) {
245
- q = part.slice(0,1) ;
246
- if (['.','#'].indexOf(q) >= 0) {
247
- part = part.slice(1,part.length) ;
248
- }
249
-
250
- bits = part.split('.') ;
251
- part = bits[0] ;
252
- bits = bits.slice(1,bits.length) ;
253
-
254
- // optimization for # types.
255
- var fret = null ;
256
- if (q == '#') {
257
- fret = $(part) ;
258
- fret = (fret) ? [fret] : null ;
259
- if (fret) ret = fret ;
260
- }
261
-
262
- // otherwise pass this off to $$func to actually search.
263
- if (fret == null) {
264
- fret = [] ;
265
- for(var i=0;i<ret.length;i++) {
266
-
267
- var found = SC._PathModule.$$func(ret[i],function(node) {
268
- var match ;
269
- switch(q) {
270
- case '.':
271
- NODE = node ;
272
- var elementClassName = node.className;
273
- if (elementClassName && (elementClassName.length > 0)) {
274
- match = (elementClassName == part ||
275
- elementClassName.match( new RegExp("(^|\\s)" + part +
276
- "(\\s|$)"))) ;
277
- } else match = false ;
278
- break ;
279
- case '#':
280
- match = node.id == part ;
281
- break ;
282
- default:
283
- if (node.tagName) {
284
- match = (node.tagName.toLowerCase() == part.toLowerCase()) ;
285
- } else { match = false; }
286
- }
287
-
288
- // if the first item matched, verify that the others match as well.
289
- var ilen = bits.length ;
290
- for(var i=0; match && i < ilen; i++) {
291
- if (!Element.hasClassName(node,bits[i])) match = false ;
292
- }
293
- return match ;
294
- }, blevels, bmax, nest) ;
295
- fret = fret.concat(found) ;
296
- }
297
- ret = fret ;
298
- }
299
- } else if (SC.typeOf(ret) != SC.T_ARRAY) ret = [ret] ;
300
-
301
- // now follow indicies, if there are any
302
- if (indicies && indicies.length > 0 && ret) {
303
- ret = ret.map(function(el){
304
- var iloclen = indicies.length ;
305
- for(var iloc=0; el && (iloc < iloclen); iloc++) {
306
- el = el.childNodes[indicies[iloc]] ;
307
- }
308
- return el;
309
- }) ;
310
- }
311
- }) ;
312
- return ret ;
313
- },
314
-
315
- // finds the first node for which func returns true.
316
- $func: function(el,func, levels) {
317
- var ret = SC._PathModule.$$func(el,func,levels,1,false) ;
318
- return (ret.length>0) ? ret[0] : null ;
319
- },
320
-
321
- // finds the first node with class name. returns element, not array.
322
- $C: function(el, className, levels) {
323
- var ret = SC._PathModule.$$C(el, className,levels,1,false) ;
324
- return (ret.length>0) ? ret[0] : null ;
325
- },
326
-
327
- // finds the first node with tag name. returns element, not array.
328
- $T: function(el, tagName, levels) {
329
- var ret = SC._PathModule.$$T(el, tagName,levels,1,false) ;
330
- return (ret.length>0) ? ret[0] : null ;
331
- },
332
-
333
- // find first node with an attribute matching then named value.
334
- $P: function(el, attr, value, levels) {
335
- var ret = SC._PathModule.$$P(el, attr, value,levels,1,false) ;
336
- return (ret.length>0) ? ret[0] : null ;
337
- },
338
-
339
- // find first node matching the specified class selector.
340
- $S: function(el, selector, levels) {
341
- var ret = SC._PathModule.$$S(el, selector,levels,1,false) ;
342
- return (ret.length>0) ? ret[0] : null ;
343
- },
344
-
345
- // find an element and configure it as the named view if it is not already
346
- // configured.
347
- $$view: function(el, selector, viewClass, levels, max, nest) {
348
- //if (!viewClass) viewClass = SC.ClassicView;
349
- var ret ;
350
- if (selector && (typeof(selector) != 'string')) {
351
- ret = [selector] ;
352
- } else {
353
- ret = SC._PathModule.$$S(el,selector,levels,max,nest) ;
354
- }
355
- if (ret) ret = ret.map(function(x) { return (viewClass) ? viewClass.viewFor(x) : SC.ClassicView.findViewForElement(x); }) ;
356
- return ret ;
357
- },
358
-
359
- // find the first element matching the selector and create a view if it is
360
- // not already configured.
361
- $view: function(el, selector, viewClass, levels) {
362
- var ret = SC._PathModule.$$view(el, selector, viewClass, levels, 1, false) ;
363
- return (ret.length>0) ? ret[0] : null ;
364
- }
365
-
366
- } ;
367
-
368
- // Install benchmark report for selector if configured.
369
- if (SC.BENCHMARK_SELECTOR) {
370
- ['$$S','$$C','$$T','$S','$C','$T'].each(function(mname) {
371
- SC.Benchmark.install(SC._PathModule,mname) ;
372
- }) ;
373
- SC.Benchmark.install(window,'$$$') ;
374
- }
375
-
376
- // longer form aliases of the functions.
377
- SC.mixin(SC._PathModule, {
378
- $$class: SC._PathModule.$$C,
379
- $$tag: SC._PathModule.$$T,
380
- $$sel: SC._PathModule.$$S,
381
- $$prop: SC._PathModule.$$P,
382
-
383
- $class: SC._PathModule.$C,
384
- $tag: SC._PathModule.$T,
385
- $sel: SC._PathModule.$S,
386
- $prop: SC._PathModule.$P
387
- }) ;
388
-
389
- // longer form aliases of the functions.
390
- SC.mixin(SC.PathModule, {
391
- $$class: SC.PathModule.$$C,
392
- $$tag: SC.PathModule.$$T,
393
- $$sel: SC.PathModule.$$S,
394
- $$prop: SC.PathModule.$$P,
395
-
396
- $class: SC.PathModule.$C,
397
- $tag: SC.PathModule.$T,
398
- $sel: SC.PathModule.$S,
399
- $prop: SC.PathModule.$P
400
- }) ;
401
-
402
- // Add _PathModule to the appropriate elements. Add to Element.Methods which
403
- // will cause it to be copied onto elements automatically in IE when you
404
- // call IE.
405
- SC.mixin(Element.Methods,SC._PathModule) ;
406
- SC.mixin(Element,SC._PathModule) ;
407
-
408
- // applies to Element.
409
- if (typeof HTMLElement != 'undefined') {
410
- SC.mixin(HTMLElement.prototype,SC.PathModule) ;
411
- }
412
-
413
- // applies to document
414
- SC.mixin(document,SC.PathModule) ;
415
-
416
- // applies to window.
417
- SC.mixin(SC.mixin(window,SC.PathModule), {
418
- $$func: function(func, levels, max, nest) {
419
- return document.$$func(func,levels,max,nest) ;
420
- }
421
- });
422
-
423
- // applies to arrays. Note the override of $$func to act on the group.
424
- SC.mixin(SC.mixin(Array.prototype,SC.PathModule), {
425
- $$func: function(func, levels, max, nest) {
426
- var ret = [] ;
427
- for(var loc=0;loc<this.length;loc++) {
428
- ret = ret.concat(this[loc].$$func(func,levels,max,nest)) ;
429
- }
430
- return ret ;
431
- }
432
- }) ;