aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/prototype.js30
-rw-r--r--railties/html/javascripts/prototype.js30
3 files changed, 62 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 070a8b8503..a12e5db90d 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added Effect.Fade which smoothly turns opacity from 100 to 0 and then hides the element #960 [thomas@fesch.at]
+
* Fixed problem with page caching #958 [Rick Olson]
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js
index 5042e3304d..2541866ccb 100644
--- a/actionpack/lib/action_view/helpers/javascripts/prototype.js
+++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js
@@ -452,3 +452,33 @@ Effect.Highlight.prototype = {
element.style.backgroundColor = "#ffff" + current.toColorPart();
}
}
+
+
+Effect.Fade = Class.create();
+Effect.Fade.prototype = {
+ initialize: function(element) {
+ this.element = $(element);
+ this.start = 100;
+ this.finish = 0;
+ this.current = this.start;
+ this.fade();
+ },
+
+ fade: function() {
+ if (this.isFinished()) { this.element.style.display = 'none'; return; }
+ if (this.timer) clearTimeout(this.timer);
+ this.setOpacity(this.element, this.current);
+ this.current -= 10;
+ this.timer = setTimeout(this.fade.bind(this), 100);
+ },
+
+ isFinished: function() {
+ return this.current <= this.finish;
+ },
+
+ setOpacity: function(element, opacity) {
+ opacity = (opacity == 100) ? 99.999 : opacity;
+ element.style.filter = "alpha(opacity:"+opacity+")";
+ element.style.opacity = opacity/100;
+ }
+} \ No newline at end of file
diff --git a/railties/html/javascripts/prototype.js b/railties/html/javascripts/prototype.js
index 5042e3304d..2541866ccb 100644
--- a/railties/html/javascripts/prototype.js
+++ b/railties/html/javascripts/prototype.js
@@ -452,3 +452,33 @@ Effect.Highlight.prototype = {
element.style.backgroundColor = "#ffff" + current.toColorPart();
}
}
+
+
+Effect.Fade = Class.create();
+Effect.Fade.prototype = {
+ initialize: function(element) {
+ this.element = $(element);
+ this.start = 100;
+ this.finish = 0;
+ this.current = this.start;
+ this.fade();
+ },
+
+ fade: function() {
+ if (this.isFinished()) { this.element.style.display = 'none'; return; }
+ if (this.timer) clearTimeout(this.timer);
+ this.setOpacity(this.element, this.current);
+ this.current -= 10;
+ this.timer = setTimeout(this.fade.bind(this), 100);
+ },
+
+ isFinished: function() {
+ return this.current <= this.finish;
+ },
+
+ setOpacity: function(element, opacity) {
+ opacity = (opacity == 100) ? 99.999 : opacity;
+ element.style.filter = "alpha(opacity:"+opacity+")";
+ element.style.opacity = opacity/100;
+ }
+} \ No newline at end of file