Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'kenfodder_master'

  • Loading branch information...
commit da81761d176cbe3b35e64619ba7d4a134470bb52 2 parents 0c77eb0 + 32cf358
@courtenay courtenay authored
Showing with 41 additions and 21 deletions.
  1. +41 −21 public/javascripts/lowpro.js
View
62 public/javascripts/lowpro.js
@@ -2,7 +2,7 @@ LowPro = {};
LowPro.Version = '0.5';
LowPro.CompatibleWithPrototype = '1.6';
-if (Prototype.Version.indexOf(LowPro.CompatibleWithPrototype) != 0 && console && console.warn)
+if (Prototype.Version.indexOf(LowPro.CompatibleWithPrototype) != 0 && window.console && window.console.warn)
console.warn("This version of Low Pro is tested with Prototype " + LowPro.CompatibleWithPrototype +
" it may not work as expected with this version (" + Prototype.Version + ")");
@@ -15,19 +15,19 @@ DOM = {};
// DOMBuilder for prototype
DOM.Builder = {
tagFunc : function(tag) {
- return function() {
- var attrs, children;
- if (arguments.length>0) {
- if (arguments[0].nodeName ||
- typeof arguments[0] == "string")
- children = arguments;
- else {
- attrs = arguments[0];
- children = Array.prototype.slice.call(arguments, 1);
- };
- }
- return DOM.Builder.create(tag, attrs, children);
- };
+ return function() {
+ var attrs, children;
+ if (arguments.length>0) {
+ if (arguments[0].constructor == Object) {
+ attrs = arguments[0];
+ children = Array.prototype.slice.call(arguments, 1);
+ } else {
+ children = arguments;
+ };
+ children = $A(children).flatten()
+ }
+ return DOM.Builder.create(tag, attrs, children);
+ };
},
create : function(tag, attrs, children) {
attrs = attrs || {}; children = children || []; tag = tag.toLowerCase();
@@ -109,6 +109,14 @@ Event.addBehavior = function(rules) {
};
+Event.delegate = function(rules) {
+ return function(e) {
+ var element = $(e.element());
+ for (var selector in rules)
+ if (element.match(selector)) return rules[selector].apply(this, $A(arguments));
+ }
+}
+
Object.extend(Event.addBehavior, {
rules : {}, cache : [],
reassignAfterAjax : false,
@@ -122,9 +130,9 @@ Object.extend(Event.addBehavior, {
var parts = sel.split(/:(?=[a-z]+$)/), css = parts[0], event = parts[1];
$$(css).each(function(element) {
if (event) {
- observer = Event.addBehavior._wrapObserver(observer);
- $(element).observe(event, observer);
- Event.addBehavior.cache.push([element, event, observer]);
+ var wrappedObserver = Event.addBehavior._wrapObserver(observer);
+ $(element).observe(event, wrappedObserver);
+ Event.addBehavior.cache.push([element, event, wrappedObserver]);
} else {
if (!element.$$assigned || !element.$$assigned.include(observer)) {
if (observer.attach) observer.attach(element);
@@ -198,7 +206,6 @@ var Behavior = {
parent = properties.shift();
var behavior = function() {
- var behavior = arguments.callee;
if (!this.initialize) {
var args = $A(arguments);
@@ -245,13 +252,17 @@ var Behavior = {
return new this(element, Array.prototype.slice.call(arguments, 1));
},
_bindEvents : function(bound) {
- for (var member in bound)
- if (member.match(/^on(.+)/) && typeof bound[member] == 'function')
- bound.element.observe(RegExp.$1, Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound)));
+ for (var member in bound) {
+ var matches = member.match(/^on(.+)/);
+ if (matches && typeof bound[member] == 'function')
+ bound.element.observe(matches[1], Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound)));
+ }
}
}
};
+
+
Remote = Behavior.create({
initialize: function(options) {
if (this.element.nodeName == 'FORM') new Remote.Form(this.element, options);
@@ -264,11 +275,19 @@ Remote.Base = {
this.options = Object.extend({
evaluateScripts : true
}, options || {});
+
+ this._bindCallbacks();
},
_makeRequest : function(options) {
if (options.update) new Ajax.Updater(options.update, options.url, options);
else new Ajax.Request(options.url, options);
return false;
+ },
+ _bindCallbacks: function() {
+ $w('onCreate onComplete onException onFailure onInteractive onLoading onLoaded onSuccess').each(function(cb) {
+ if (Object.isFunction(this.options[cb]))
+ this.options[cb] = this.options[cb].bind(this);
+ }.bind(this));
}
}
@@ -317,3 +336,4 @@ Observed = Behavior.create({
new Form.Element.EventObserver(this.element, this.callback);
}
});
+
Please sign in to comment.
Something went wrong with that request. Please try again.