diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-26 23:16:55 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-26 23:16:55 +0000 |
commit | 4c3d52ad66c2db582ad24e55adf88fa7cfdb39e6 (patch) | |
tree | e0e4347d9321b047e936549d24dcb461dddaab89 /railties | |
parent | 5d6bedb383024df2596a560de6d67337ff6cdb2f (diff) | |
download | rails-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 'railties')
-rw-r--r-- | railties/html/javascripts/prototype.js | 226 |
1 files changed, 119 insertions, 107 deletions
diff --git a/railties/html/javascripts/prototype.js b/railties/html/javascripts/prototype.js index 60dbd5d419..18027b3e91 100644 --- a/railties/html/javascripts/prototype.js +++ b/railties/html/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,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); - } - } -};
\ No newline at end of file |