Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 381
- Log:
Radiant is now packaged as a Gem - see Changeset #373, Changeset #374,
Changeset #375, Changeset #376, Changeset #377, Changeset #378,
Changeset #379 and Changeset #380. The application part of Radiant is
now mostly empty; it exists to provide a structure which hooks into the
gem and which provides a framework for extensions. Included in this big
changeset are all the deletions, additions and changes needed to go from
the old ROOL customised Radiant to a new ROOL customised Radiant, which
includes several custom extensions adapted from the old Radiant
modifications and requires Radiant 0.9.1 to be installed as a gem.
- Author:
- rool
- Date:
- Mon Mar 21 14:01:18 +0000 2011
- Size:
- 10493 Bytes
1 | LowPro = {}; |
2 | LowPro.Version = '0.5'; |
3 | LowPro.CompatibleWithPrototype = '1.6'; |
4 | |
5 | if (Prototype.Version.indexOf(LowPro.CompatibleWithPrototype) != 0 && window.console && window.console.warn) |
6 | console.warn("This version of Low Pro is tested with Prototype " + LowPro.CompatibleWithPrototype + |
7 | " it may not work as expected with this version (" + Prototype.Version + ")"); |
8 | |
9 | if (!Element.addMethods) |
10 | Element.addMethods = function(o) { Object.extend(Element.Methods, o) }; |
11 | |
12 | // Simple utility methods for working with the DOM |
13 | DOM = {}; |
14 | |
15 | // DOMBuilder for prototype |
16 | DOM.Builder = { |
17 | tagFunc : function(tag) { |
18 | return function() { |
19 | var attrs, children; |
20 | if (arguments.length>0) { |
21 | if (arguments[0].constructor == Object) { |
22 | attrs = arguments[0]; |
23 | children = Array.prototype.slice.call(arguments, 1); |
24 | } else { |
25 | children = arguments; |
26 | }; |
27 | children = $A(children).flatten() |
28 | } |
29 | return DOM.Builder.create(tag, attrs, children); |
30 | }; |
31 | }, |
32 | create : function(tag, attrs, children) { |
33 | attrs = attrs || {}; children = children || []; tag = tag.toLowerCase(); |
34 | var el = new Element(tag, attrs); |
35 | |
36 | for (var i=0; i<children.length; i++) { |
37 | if (typeof children[i] == 'string') |
38 | children[i] = document.createTextNode(children[i]); |
39 | el.appendChild(children[i]); |
40 | } |
41 | return $(el); |
42 | } |
43 | }; |
44 | |
45 | // Automatically create node builders as $tagName. |
46 | (function() { |
47 | var els = ("p|div|span|strong|em|img|table|tr|td|th|thead|tbody|tfoot|pre|code|" + |
48 | "h1|h2|h3|h4|h5|h6|ul|ol|li|form|input|textarea|legend|fieldset|" + |
49 | "select|option|blockquote|cite|br|hr|dd|dl|dt|address|a|button|abbr|acronym|" + |
50 | "script|link|style|bdo|ins|del|object|param|col|colgroup|optgroup|caption|" + |
51 | "label|dfn|kbd|samp|var").split("|"); |
52 | var el, i=0; |
53 | while (el = els[i++]) |
54 | window['$' + el] = DOM.Builder.tagFunc(el); |
55 | })(); |
56 | |
57 | DOM.Builder.fromHTML = function(html) { |
58 | var root; |
59 | if (!(root = arguments.callee._root)) |
60 | root = arguments.callee._root = document.createElement('div'); |
61 | root.innerHTML = html; |
62 | return root.childNodes[0]; |
63 | }; |
64 | |
65 | |
66 | |
67 | // Wraps the 1.6 contentloaded event for backwards compatibility |
68 | // |
69 | // Usage: |
70 | // |
71 | // Event.onReady(callbackFunction); |
72 | Object.extend(Event, { |
73 | onReady : function(f) { |
74 | if (document.body) f(); |
75 | else document.observe('dom:loaded', f); |
76 | } |
77 | }); |
78 | |
79 | // Based on event:Selectors by Justin Palmer |
80 | // http://encytemedia.com/event-selectors/ |
81 | // |
82 | // Usage: |
83 | // |
84 | // Event.addBehavior({ |
85 | // "selector:event" : function(event) { /* event handler. this refers to the element. */ }, |
86 | // "selector" : function() { /* runs function on dom ready. this refers to the element. */ } |
87 | // ... |
88 | // }); |
89 | // |
90 | // Multiple calls will add to exisiting rules. Event.addBehavior.reassignAfterAjax and |
91 | // Event.addBehavior.autoTrigger can be adjusted to needs. |
92 | Event.addBehavior = function(rules) { |
93 | var ab = this.addBehavior; |
94 | Object.extend(ab.rules, rules); |
95 | |
96 | if (!ab.responderApplied) { |
97 | Ajax.Responders.register({ |
98 | onComplete : function() { |
99 | if (Event.addBehavior.reassignAfterAjax) |
100 | setTimeout(function() { ab.reload() }, 10); |
101 | } |
102 | }); |
103 | ab.responderApplied = true; |
104 | } |
105 | |
106 | if (ab.autoTrigger) { |
107 | this.onReady(ab.load.bind(ab, rules)); |
108 | } |
109 | |
110 | }; |
111 | |
112 | Event.delegate = function(rules) { |
113 | return function(e) { |
114 | for ( var selector in rules ){ |
115 | if ( e.findElement(selector) ) { |
116 | return rules[selector].apply(this, $A(arguments)); |
117 | } |
118 | } |
119 | } |
120 | } |
121 | |
122 | Object.extend(Event.addBehavior, { |
123 | rules : {}, cache : [], |
124 | reassignAfterAjax : false, |
125 | autoTrigger : true, |
126 | |
127 | load : function(rules) { |
128 | for (var selector in rules) { |
129 | var observer = rules[selector]; |
130 | var sels = selector.split(','); |
131 | sels.each(function(sel) { |
132 | var parts = sel.split(/:(?=[a-z]+$)/), css = parts[0], event = parts[1]; |
133 | $$(css).each(function(element) { |
134 | if (event) { |
135 | var wrappedObserver = Event.addBehavior._wrapObserver(observer); |
136 | $(element).observe(event, wrappedObserver); |
137 | Event.addBehavior.cache.push([element, event, wrappedObserver]); |
138 | } else { |
139 | if (!element.$$assigned || !element.$$assigned.include(observer)) { |
140 | if (observer.attach) observer.attach(element); |
141 | |
142 | else observer.call($(element)); |
143 | element.$$assigned = element.$$assigned || []; |
144 | element.$$assigned.push(observer); |
145 | } |
146 | } |
147 | }); |
148 | }); |
149 | } |
150 | }, |
151 | |
152 | unload : function() { |
153 | this.cache.each(function(c) { |
154 | Event.stopObserving.apply(Event, c); |
155 | }); |
156 | this.cache = []; |
157 | }, |
158 | |
159 | reload: function() { |
160 | var ab = Event.addBehavior; |
161 | ab.unload(); |
162 | ab.load(ab.rules); |
163 | }, |
164 | |
165 | _wrapObserver: function(observer) { |
166 | return function(event) { |
167 | if (observer.call(this, event) === false) event.stop(); |
168 | } |
169 | } |
170 | |
171 | }); |
172 | |
173 | Event.observe(window, 'unload', Event.addBehavior.unload.bind(Event.addBehavior)); |
174 | |
175 | // A silly Prototype style shortcut for the reckless |
176 | $$$ = Event.addBehavior.bind(Event); |
177 | |
178 | // Behaviors can be bound to elements to provide an object orientated way of controlling elements |
179 | // and their behavior. Use Behavior.create() to make a new behavior class then use attach() to |
180 | // glue it to an element. Each element then gets it's own instance of the behavior and any |
181 | // methods called onxxx are bound to the relevent event. |
182 | // |
183 | // Usage: |
184 | // |
185 | // var MyBehavior = Behavior.create({ |
186 | // onmouseover : function() { this.element.addClassName('bong') } |
187 | // }); |
188 | // |
189 | // Event.addBehavior({ 'a.rollover' : MyBehavior }); |
190 | // |
191 | // If you need to pass additional values to initialize use: |
192 | // |
193 | // Event.addBehavior({ 'a.rollover' : MyBehavior(10, { thing : 15 }) }) |
194 | // |
195 | // You can also use the attach() method. If you specify extra arguments to attach they get passed to initialize. |
196 | // |
197 | // MyBehavior.attach(el, values, to, init); |
198 | // |
199 | // Finally, the rawest method is using the new constructor normally: |
200 | // var draggable = new Draggable(element, init, vals); |
201 | // |
202 | // Each behaviour has a collection of all its instances in Behavior.instances |
203 | // |
204 | var Behavior = { |
205 | create: function() { |
206 | var parent = null, properties = $A(arguments); |
207 | if (Object.isFunction(properties[0])) |
208 | parent = properties.shift(); |
209 | |
210 | var behavior = function() { |
211 | if (!this.initialize) { |
212 | var args = $A(arguments); |
213 | |
214 | return function() { |
215 | var initArgs = [this].concat(args); |
216 | behavior.attach.apply(behavior, initArgs); |
217 | }; |
218 | } else { |
219 | var args = (arguments.length == 2 && arguments[1] instanceof Array) ? |
220 | arguments[1] : Array.prototype.slice.call(arguments, 1); |
221 | |
222 | this.element = $(arguments[0]); |
223 | this.initialize.apply(this, args); |
224 | behavior._bindEvents(this); |
225 | behavior.instances.push(this); |
226 | } |
227 | }; |
228 | |
229 | Object.extend(behavior, Class.Methods); |
230 | Object.extend(behavior, Behavior.Methods); |
231 | behavior.superclass = parent; |
232 | behavior.subclasses = []; |
233 | behavior.instances = []; |
234 | |
235 | if (parent) { |
236 | var subclass = function() { }; |
237 | subclass.prototype = parent.prototype; |
238 | behavior.prototype = new subclass; |
239 | parent.subclasses.push(behavior); |
240 | } |
241 | |
242 | for (var i = 0; i < properties.length; i++) |
243 | behavior.addMethods(properties[i]); |
244 | |
245 | if (!behavior.prototype.initialize) |
246 | behavior.prototype.initialize = Prototype.emptyFunction; |
247 | |
248 | behavior.prototype.constructor = behavior; |
249 | |
250 | return behavior; |
251 | }, |
252 | Methods : { |
253 | attach : function(element) { |
254 | return new this(element, Array.prototype.slice.call(arguments, 1)); |
255 | }, |
256 | _bindEvents : function(bound) { |
257 | for (var member in bound) { |
258 | var matches = member.match(/^on(.+)/); |
259 | if (matches && typeof bound[member] == 'function') |
260 | bound.element.observe(matches[1], Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound))); |
261 | } |
262 | } |
263 | } |
264 | }; |
265 | |
266 | |
267 | |
268 | Remote = Behavior.create({ |
269 | initialize: function(options) { |
270 | if (this.element.nodeName == 'FORM') new Remote.Form(this.element, options); |
271 | else new Remote.Link(this.element, options); |
272 | } |
273 | }); |
274 | |
275 | Remote.Base = { |
276 | initialize : function(options) { |
277 | this.options = Object.extend({ |
278 | evaluateScripts : true |
279 | }, options || {}); |
280 | |
281 | this._bindCallbacks(); |
282 | }, |
283 | _makeRequest : function(options) { |
284 | if (options.update) new Ajax.Updater(options.update, options.url, options); |
285 | else new Ajax.Request(options.url, options); |
286 | return false; |
287 | }, |
288 | _bindCallbacks: function() { |
289 | $w('onCreate onComplete onException onFailure onInteractive onLoading onLoaded onSuccess').each(function(cb) { |
290 | if (Object.isFunction(this.options[cb])) |
291 | this.options[cb] = this.options[cb].bind(this); |
292 | }.bind(this)); |
293 | } |
294 | } |
295 | |
296 | Remote.Link = Behavior.create(Remote.Base, { |
297 | onclick : function() { |
298 | var options = Object.extend({ url : this.element.href, method : 'get' }, this.options); |
299 | return this._makeRequest(options); |
300 | } |
301 | }); |
302 | |
303 | |
304 | Remote.Form = Behavior.create(Remote.Base, { |
305 | onclick : function(e) { |
306 | var sourceElement = e.element(); |
307 | |
308 | if (['input', 'button'].include(sourceElement.nodeName.toLowerCase()) && |
309 | ['submit', 'image'].include(sourceElement.type)) |
310 | this._submitButton = sourceElement; |
311 | }, |
312 | onsubmit : function() { |
313 | var options = Object.extend({ |
314 | url : this.element.action, |
315 | method : this.element.method || 'get', |
316 | parameters : this.element.serialize({ submit: this._submitButton.name }) |
317 | }, this.options); |
318 | this._submitButton = null; |
319 | return this._makeRequest(options); |
320 | } |
321 | }); |
322 | |
323 | Observed = Behavior.create({ |
324 | initialize : function(callback, options) { |
325 | this.callback = callback.bind(this); |
326 | this.options = options || {}; |
327 | this.observer = (this.element.nodeName == 'FORM') ? this._observeForm() : this._observeField(); |
328 | }, |
329 | stop: function() { |
330 | this.observer.stop(); |
331 | }, |
332 | _observeForm: function() { |
333 | return (this.options.frequency) ? new Form.Observer(this.element, this.options.frequency, this.callback) : |
334 | new Form.EventObserver(this.element, this.callback); |
335 | }, |
336 | _observeField: function() { |
337 | return (this.options.frequency) ? new Form.Element.Observer(this.element, this.options.frequency, this.callback) : |
338 | new Form.Element.EventObserver(this.element, this.callback); |
339 | } |
340 | }); |