aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-26 23:16:55 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-26 23:16:55 +0000
commit4c3d52ad66c2db582ad24e55adf88fa7cfdb39e6 (patch)
treee0e4347d9321b047e936549d24dcb461dddaab89 /actionpack/lib
parent5d6bedb383024df2596a560de6d67337ff6cdb2f (diff)
downloadrails-4c3d52ad66c2db582ad24e55adf88fa7cfdb39e6.tar.gz
rails-4c3d52ad66c2db582ad24e55adf88fa7cfdb39e6.tar.bz2
rails-4c3d52ad66c2db582ad24e55adf88fa7cfdb39e6.zip
Updated to prototype.js 1.1.0
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1012 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb4
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/prototype.js211
2 files changed, 123 insertions, 92 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index 6a0117a163..5b9c35376e 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -159,8 +159,8 @@ module ActionView
js_options['asynchronous'] = options[:type] != :synchronous
js_options['method'] = options[:method] if options[:method]
- js_options['position'] = options[:position] ? "'#{options[:position].to_s}'" : "'replace'"
- js_options['effect'] = ("\'" + options[:effect].to_s + "\'") if options[:effect]
+ js_options['insertion'] = "Insertion.#{options[:position].to_s.camelize}" if options[:position]
+ js_options['effect'] = "Effect.#{options[:effect].to_s.camelize}" if options[:effect]
if options[:form]
js_options['parameters'] = 'Form.serialize(this)'
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js
index 8cddf224e2..18027b3e91 100644
--- a/actionpack/lib/action_view/helpers/javascripts/prototype.js
+++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js
@@ -5,11 +5,11 @@
* For details, see http://prototype.conio.net/
*/
-Prototype = {
- Version: '1.0.1'
+var Prototype = {
+ Version: '1.1.0'
}
-Class = {
+var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
@@ -17,7 +17,7 @@ Class = {
}
}
-Abstract = new Object();
+var Abstract = new Object();
Object.prototype.extend = function(object) {
for (property in object) {
@@ -40,7 +40,13 @@ Function.prototype.bindAsEventListener = function(object) {
}
}
-Try = {
+Number.prototype.toColorPart = function() {
+ var digits = this.toString(16);
+ if (this < 16) return '0' + digits;
+ return digits;
+}
+
+var Try = {
these: function() {
var returnValue;
@@ -56,7 +62,7 @@ Try = {
}
}
-Toggle = {
+var Toggle = {
display: function() {
for (var i = 0; i < arguments.length; i++) {
var element = $(arguments[i]);
@@ -85,21 +91,27 @@ function $() {
return elements;
}
-function getElementsByClassName(className, element) {
- var all = document.all ? document.all : document.getElementsByTagName(element);
+function getElementsByClassName(className) {
+ var children = document.getElementsByTagName('*') || document.all;
var elements = new Array();
-
- for (var e = 0; e < all.length; e++) {
- if (all[e].className == className)
- elements[elements.length] = all[e];
+
+ for (var i = 0; i < children.length; i++) {
+ var child = children[i];
+ var classNames = child.className.split(' ');
+ for (var j = 0; j < classNames.length; j++) {
+ if (classNames[j] == className) {
+ elements.push(child);
+ break;
+ }
+ }
}
-
+
return elements;
}
/*--------------------------------------------------------------------------*/
-Ajax = {
+var Ajax = {
getTransport: function() {
return Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
@@ -117,8 +129,7 @@ Ajax.Base.prototype = {
this.options = {
method: 'post',
asynchronous: true,
- parameters: '',
- position: 'replace'
+ parameters: ''
}.extend(options || {});
}
}
@@ -186,23 +197,28 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({
},
updateContent: function() {
- if (this.options.position.toLowerCase() == 'replace') {
+ this.container.innerHTML = this.request.transport.responseText;
+
+ if (this.options.insertion) {
this.container.innerHTML = this.request.transport.responseText;
} else {
- Insert[this.options.position.toLowerCase()](this.container, this.request.transport.responseText);
+ new this.options.insertion(this.container,
+ this.request.transport.responseText);
}
- switch(this.options.effect) {
- case 'highlight': new YellowFader(this.container); break;
+ if (this.options.effect) {
+ new this.options.effect(this.container);
}
- if (this.onComplete) this.onComplete(this.request);
+ if (this.onComplete) {
+ setTimeout((function() {this.onComplete(this.request)}).bind(this), 10);
+ }
}
});
/*--------------------------------------------------------------------------*/
-Field = {
+var Field = {
clear: function() {
for (var i = 0; i < arguments.length; i++)
$(arguments[i]).value = '';
@@ -221,7 +237,7 @@ Field = {
/*--------------------------------------------------------------------------*/
-Form = {
+var Form = {
serialize: function(form) {
var elements = Form.getElements($(form));
var queryComponents = new Array();
@@ -280,6 +296,7 @@ Form.Element.Serializers = {
case 'radio':
return Form.Element.Serializers.inputSelector(element);
}
+ return false;
},
inputSelector: function(element) {
@@ -339,91 +356,105 @@ Form.Observer.prototype = (new Abstract.TimedObserver()).extend({
}
});
+
/*--------------------------------------------------------------------------*/
-Number.prototype.toColorPart = function() {
- var digits = this.toString(16);
- if (this < 16) return '0' + digits;
- return digits;
+Abstract.Insertion = function(adjacency) {
+ this.adjacency = adjacency;
}
-var YellowFader = Class.create();
-YellowFader.prototype = {
+Abstract.Insertion.prototype = {
+ initialize: function(element, content) {
+ this.element = $(element);
+ this.content = content;
+
+ if (this.adjacency && this.element.insertAdjacentHTML) {
+ this.element.insertAdjacentHTML(this.adjacency, this.content);
+ } else {
+ this.range = this.element.ownerDocument.createRange();
+ if (this.initializeRange) this.initializeRange();
+ this.fragment = this.range.createContextualFragment(this.content);
+ this.insertContent();
+ }
+ }
+}
+
+var Insertion = new Object();
+
+Insertion.Before = Class.create();
+Insertion.Before.prototype = (new Abstract.Insertion('beforeBegin')).extend({
+ initializeRange: function() {
+ this.range.setStartBefore(this.element);
+ },
+
+ insertContent: function() {
+ this.element.parentNode.insertBefore(this.fragment, this.element);
+ }
+});
+
+Insertion.Top = Class.create();
+Insertion.Top.prototype = (new Abstract.Insertion('afterBegin')).extend({
+ initializeRange: function() {
+ this.range.selectNodeContents(this.element);
+ this.range.collapse(true);
+ },
+
+ insertContent: function() {
+ this.element.insertBefore(this.fragment, this.element.firstChild);
+ }
+});
+
+Insertion.Bottom = Class.create();
+Insertion.Bottom.prototype = (new Abstract.Insertion('beforeEnd')).extend({
+ initializeRange: function() {
+ this.range.selectNodeContents(this.element);
+ this.range.collapse(this.element);
+ },
+
+ insertContent: function() {
+ this.element.appendChild(this.fragment);
+ }
+});
+
+Insertion.After = Class.create();
+Insertion.After.prototype = (new Abstract.Insertion('afterEnd')).extend({
+ initializeRange: function() {
+ this.range.setStartAfter(this.element);
+ },
+
+ insertContent: function() {
+ this.element.parentNode.insertBefore(this.fragment,
+ this.element.nextSibling);
+ }
+});
+
+/*--------------------------------------------------------------------------*/
+
+var Effect = new Object();
+
+Effect.Highlight = Class.create();
+Effect.Highlight.prototype = {
initialize: function(element) {
- if (typeof element == 'string') element = $(element);
- if (!element) return;
- this.element = element;
+ this.element = $(element);
this.start = 153;
this.finish = 255;
this.current = this.start;
this.fade();
- },
+ },
+
fade: function() {
if (this.isFinished()) return;
- if (this.timer) clearTimeout(this.timer); // prevent flicker
+ if (this.timer) clearTimeout(this.timer);
this.highlight(this.element, this.current);
this.current += 17;
this.timer = setTimeout(this.fade.bind(this), 250);
- },
+ },
+
isFinished: function() {
return this.current > this.finish;
},
+
highlight: function(element, current) {
element.style.backgroundColor = "#ffff" + current.toColorPart();
}
}
-
-
-/*--------------------------------------------------------------------------*/
-
-Insert = {
- before: function(dom, html) {
- dom = $(dom);
- if (dom.insertAdjacentHTML) {
- dom.insertAdjacentHTML('BeforeBegin', html);
- } else {
- var r = dom.ownerDocument.createRange();
- r.setStartBefore(dom);
- var df = r.createContextualFragment(html);
- dom.parentNode.insertBefore(df, dom);
- }
- },
-
- top: function(dom, html) {
- dom = $(dom);
- if (dom.insertAdjacentHTML) {
- dom.insertAdjacentHTML('AfterBegin', html);
- } else {
- var r = dom.ownerDocument.createRange();
- r.selectNodeContents(dom);
- r.collapse(true);
- var df = r.createContextualFragment( html );
- dom.insertBefore(df, dom.firstChild );
- }
- },
-
- bottom: function(dom, html) {
- dom = $(dom);
- if (dom.insertAdjacentHTML) {
- dom.insertAdjacentHTML('BeforeEnd', html);
- } else {
- var r = dom.ownerDocument.createRange();
- r.selectNodeContents(dom);
- r.collapse(dom);
- var df = r.createContextualFragment(html);
- dom.appendChild(df);
- }
- },
-
- after: function(dom, html) {
- dom = $(dom);
- if (dom.insertAdjacentHTML) {
- dom.insertAdjacentHTML('BeforeBegin', html);
- } else {
- var r = dom.ownerDocument.createRange();
- r.setStartAfter(dom);
- var df = r.createContextualFragment( html );
- dom.parentNode.insertBefore(df, dom.nextSibling);
- }
- }
-}; \ No newline at end of file