1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Updated to prototype.js 1.1.0

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1012 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-03-26 23:16:55 +00:00
parent 5d6bedb383
commit 4c3d52ad66
3 changed files with 242 additions and 199 deletions

View file

@ -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)'

View file

@ -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);
}
}
};

View file

@ -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,39 +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;
}
// function getElementsByClassName(className, element) {
// var children = (element || document).getElementsByTagName('*');
// var elements = new Array();
//
// 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')},
@ -135,8 +129,7 @@ Ajax.Base.prototype = {
this.options = {
method: 'post',
asynchronous: true,
parameters: '',
position: 'replace'
parameters: ''
}.extend(options || {});
}
}
@ -206,23 +199,26 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({
updateContent: function() {
this.container.innerHTML = this.request.transport.responseText;
if (this.options.position.toLowerCase() == 'replace') {
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 = '';
@ -241,7 +237,7 @@ Field = {
/*--------------------------------------------------------------------------*/
Form = {
var Form = {
serialize: function(form) {
var elements = Form.getElements($(form));
var queryComponents = new Array();
@ -300,6 +296,7 @@ Form.Element.Serializers = {
case 'radio':
return Form.Element.Serializers.inputSelector(element);
}
return false;
},
inputSelector: function(element) {
@ -359,90 +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_begin: 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);
}
},
after_begin: 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 );
}
},
before_end: 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_end: 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);
}
}
};