1LowPro = {}; 2LowPro.Version = '0.5'; 3LowPro.CompatibleWithPrototype = '1.6'; 4 5if (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 9if (!Element.addMethods) 10 Element.addMethods = function(o) { Object.extend(Element.Methods, o) }; 11 12// Simple utility methods for working with the DOM 13DOM = {}; 14 15// DOMBuilder for prototype 16DOM.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 57DOM.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); 72Object.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. 92Event.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 112Event.delegate = function(rules) { 113 return function(e) { 114 var element = $(e.element()); 115 for (var selector in rules) 116 if (element.match(selector)) return rules[selector].apply(this, $A(arguments)); 117 } 118} 119 120Object.extend(Event.addBehavior, { 121 rules : {}, cache : [], 122 reassignAfterAjax : false, 123 autoTrigger : true, 124 125 load : function(rules) { 126 for (var selector in rules) { 127 var observer = rules[selector]; 128 var sels = selector.split(','); 129 sels.each(function(sel) { 130 var match = sel.match(/^([^:]*)(?::(.*)$)?/), css = match[1], event = match[2]; 131 $$(css).each(function(element) { 132 if (event) { 133 var wrappedObserver = Event.addBehavior._wrapObserver(observer); 134 $(element).observe(event, wrappedObserver); 135 Event.addBehavior.cache.push([element, event, wrappedObserver]); 136 } else { 137 if (!element.$$assigned || !element.$$assigned.include(observer)) { 138 if (observer.attach) observer.attach(element); 139 140 else observer.call($(element)); 141 element.$$assigned = element.$$assigned || []; 142 element.$$assigned.push(observer); 143 } 144 } 145 }); 146 }); 147 } 148 }, 149 150 unload : function() { 151 this.cache.each(function(c) { 152 Event.stopObserving.apply(Event, c); 153 }); 154 this.cache = []; 155 }, 156
157 reload: function() { 158 var ab = Event.addBehavior; 159 ab.unload(); 160 ab.load(ab.rules); 161 }, 162 163 _wrapObserver: function(observer) { 164 return function(event) { 165 if (observer.call(this, event) === false) event.stop(); 166 } 167 } 168 169}); 170 171Event.observe(window, 'unload', Event.addBehavior.unload.bind(Event.addBehavior)); 172 173// A silly Prototype style shortcut for the reckless 174$$$ = Event.addBehavior.bind(Event); 175 176// Behaviors can be bound to elements to provide an object orientated way of controlling elements 177// and their behavior. Use Behavior.create() to make a new behavior class then use attach() to 178// glue it to an element. Each element then gets it's own instance of the behavior and any 179// methods called onxxx are bound to the relevent event. 180// 181// Usage: 182// 183// var MyBehavior = Behavior.create({ 184// onmouseover : function() { this.element.addClassName('bong') } 185// }); 186// 187// Event.addBehavior({ 'a.rollover' : MyBehavior }); 188// 189// If you need to pass additional values to initialize use: 190// 191// Event.addBehavior({ 'a.rollover' : MyBehavior(10, { thing : 15 }) }) 192// 193// You can also use the attach() method. If you specify extra arguments to attach they get passed to initialize. 194// 195// MyBehavior.attach(el, values, to, init); 196// 197// Finally, the rawest method is using the new constructor normally: 198// var draggable = new Draggable(element, init, vals); 199// 200// Each behaviour has a collection of all its instances in Behavior.instances 201// 202var Behavior = { 203 create: function() { 204 var parent = null, properties = $A(arguments); 205 if (Object.isFunction(properties[0])) 206 parent = properties.shift(); 207 208 var behavior = function() { 209 if (!this.initialize) { 210 var args = $A(arguments); 211 212 return function() { 213 var initArgs = [this].concat(args); 214 behavior.attach.apply(behavior, initArgs); 215 }; 216 } else { 217 var args = (arguments.length == 2 && arguments[1] instanceof Array) ? 218 arguments[1] : Array.prototype.slice.call(arguments, 1); 219 220 this.element = $(arguments[0]); 221 this.initialize.apply(this, args); 222 behavior._bindEvents(this); 223 behavior.instances.push(this); 224 } 225 }; 226 227 Object.extend(behavior, Class.Methods); 228 Object.extend(behavior, Behavior.Methods); 229 behavior.superclass = parent; 230 behavior.subclasses = []; 231 behavior.instances = []; 232 233 if (parent) { 234 var subclass = function() { }; 235 subclass.prototype = parent.prototype; 236 behavior.prototype = new subclass; 237 parent.subclasses.push(behavior); 238 } 239 240 for (var i = 0; i < properties.length; i++) 241 behavior.addMethods(properties[i]); 242 243 if (!behavior.prototype.initialize) 244 behavior.prototype.initialize = Prototype.emptyFunction; 245 246 behavior.prototype.constructor = behavior; 247 248 return behavior; 249 }, 250 Methods : { 251 attach : function(element) { 252 return new this(element, Array.prototype.slice.call(arguments, 1)); 253 }, 254 _bindEvents : function(bound) { 255 for (var member in bound) { 256 var matches = member.match(/^on(.+)/); 257 if (matches && typeof bound[member] == 'function') 258 bound.element.observe(matches[1], Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound))); 259 } 260 } 261 } 262}; 263 264 265 266Remote = Behavior.create({ 267 initialize: function(options) { 268 if (this.element.nodeName == 'FORM') new Remote.Form(this.element, options); 269 else new Remote.Link(this.element, options); 270 } 271}); 272 273Remote.Base = { 274 initialize : function(options) { 275 this.options = Object.extend({ 276 evaluateScripts : true 277 }, options || {}); 278 279 this._bindCallbacks(); 280 }, 281 _makeRequest : function(options) { 282 if (options.update) new Ajax.Updater(options.update, options.url, options); 283 else new Ajax.Request(options.url, options); 284 return false; 285 }, 286 _bindCallbacks: function() { 287 $w('onCreate onComplete onException onFailure onInteractive onLoading onLoaded onSuccess').each(function(cb) { 288 if (Object.isFunction(this.options[cb])) 289 this.options[cb] = this.options[cb].bind(this); 290 }.bind(this)); 291 } 292} 293 294Remote.Link = Behavior.create(Remote.Base, { 295 onclick : function() { 296 var options = Object.extend({ url : this.element.href, method : 'get' }, this.options);
297 return this._makeRequest(options); 298 } 299}); 300 301 302Remote.Form = Behavior.create(Remote.Base, { 303 onclick : function(e) { 304 var sourceElement = e.element(); 305 306 if (['input', 'button'].include(sourceElement.nodeName.toLowerCase()) && 307 sourceElement.type == 'submit') 308 this._submitButton = sourceElement; 309 }, 310 onsubmit : function() { 311 var options = Object.extend({ 312 url : this.element.action, 313 method : this.element.method || 'get', 314 parameters : this.element.serialize({ submit: this._submitButton.name }) 315 }, this.options); 316 this._submitButton = null; 317 return this._makeRequest(options); 318 } 319}); 320 321Observed = Behavior.create({ 322 initialize : function(callback, options) { 323 this.callback = callback.bind(this); 324 this.options = options || {}; 325 this.observer = (this.element.nodeName == 'FORM') ? this._observeForm() : this._observeField(); 326 }, 327 stop: function() { 328 this.observer.stop(); 329 }, 330 _observeForm: function() { 331 return (this.options.frequency) ? new Form.Observer(this.element, this.options.frequency, this.callback) : 332 new Form.EventObserver(this.element, this.callback); 333 }, 334 _observeField: function() { 335 return (this.options.frequency) ? new Form.Element.Observer(this.element, this.options.frequency, this.callback) : 336 new Form.Element.EventObserver(this.element, this.callback); 337 } 338}); 339
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.