[Pkg-mozext-commits] [itsalltext] 58/459: Added Fade To Yellow on refresh update

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit 5b3081f79ff7736b670eec6b5913848b1b40f4fd
Author: docwhat at gerf.org <docwhat at gerf.org>
Date:   Thu Jan 4 11:09:44 2007 -0500

    Added Fade To Yellow on refresh update
---
 chrome/content/Color.js       | 226 ++++++++++++++++++++++++++++++++++++++++++
 chrome/content/itsalltext.js  |  24 +++++
 chrome/content/itsalltext.xul |   1 +
 3 files changed, 251 insertions(+)

diff --git a/chrome/content/Color.js b/chrome/content/Color.js
new file mode 100644
index 0000000..1905f19
--- /dev/null
+++ b/chrome/content/Color.js
@@ -0,0 +1,226 @@
+/**
+ * Author: Lachlan Hunt
+ * Date: 2005-11-24
+ * Version: 1.0-cgh1
+ * Contributor: Christian G. Höltje
+ *
+ * Licence: Public Domain
+ * Attribution is considered ethical, but not required.
+ *
+ * Usage:
+ *   Color(255, 255, 255);
+ *   Color(255, 255, 255, 1.0);
+ *   Color("#FFF");
+ *   Color("#FFFFFF");
+ *   Color("rgb(255, 255, 255)");
+ *   Color("rgba(255, 255, 255, 1.0)");
+ *   Color("white"); - CSS 2.1 Color keywords only
+ */
+var Color = function() {
+
+    // CSS 2.1 Colour Keywords
+	var keyword = {
+      "maroon"   : "#800000",
+	  "red"      : "#ff0000",
+	  "orange"   : "#ffA500",
+	  "yellow"   : "#ffff00",
+	  "olive"    : "#808000",
+	  "purple"   : "#800080",
+	  "fuchsia"  : "#ff00ff",
+	  "white"    : "#ffffff",
+	  "lime"     : "#00ff00",
+	  "green"    : "#008000",
+	  "navy"     : "#000080",
+	  "blue"     : "#0000ff",
+	  "aqua"     : "#00ffff",
+	  "teal"     : "#008080",
+	  "black"    : "#000000",
+	  "silver"   : "#c0c0c0",
+	  "gray"     : "#808080"
+    };
+
+    // CSS Functional Notations and Hex Patterns
+	var func = {
+      "rgb"   : /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\);?$/,
+      "rgb%"  : /^rgb\(\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\);?$/,
+      "rgba"  : /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*((?:\d+(?:\.\d+)?)|(?:\.\d+))\s*\);?$/,
+      "rgba%" : /^rgba\(\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*((?:\d+(?:\.\d+)?)|(?:\.\d+))\s*\);?$/,
+      "hex3"  : /^#([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f]);?$/,
+      "hex6"  : /^#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2});?$/
+    };
+
+    /**
+	 * Clamp the value between the low value and the high value
+     * @private
+	 */
+	var clamp = function(value, low, high) {
+		if (value < low) {
+			value = low;
+		}
+		else if (value > high) {
+			value = high;
+		}
+		return value;
+	};
+
+    /**
+     * @private
+     */
+    var alphaBlend = function(forground, background, alpha) {
+		return Math.round(background * (1.0 - alpha) + forground * (alpha));
+	};
+
+	/*
+	 * Return the colour in hexadecimal notation: #RRGGBB. e.g. #FF9933
+	 * @param bg - Optional parameter used for calculating the colour if an alpha value less than 1.0 has been specified.
+	 *             If not specified, the alpha value will be ignored.
+	 */
+    this.hex = function(bg) {
+		if (bg) {
+			var r = alphaBlend(this.red, bg.red, this.alpha);
+			var g = alphaBlend(this.green, bg.green, this.alpha);
+			var b = alphaBlend(this.blue, bg.blue, this.alpha);
+		} else {
+			r = this.red;
+			g = this.green;
+			b = this.blue;
+		}
+		
+		var strHexR = r.toString(16).toUpperCase();
+		var strHexG = g.toString(16).toUpperCase();
+		var strHexB = b.toString(16).toUpperCase();
+	
+		if (strHexR.length < 2) { strHexR = "0" + strHexR; }
+		if (strHexG.length < 2) { strHexG = "0" + strHexG; }
+		if (strHexB.length < 2) { strHexB = "0" + strHexB; }
+	
+		return "#" + strHexR + strHexG + strHexB;
+	};
+
+    /**
+	 * Return the colour in CSS rgb() functional notation, using integers 0-255: rgb(255, 255 255);
+	 * @param bg - Optional parameter used for calculating the colour if an alpha value less than 1.0 has been specified.
+	 *             If not specified, the alpha value will be ignored.
+	 */
+	this.rgb = function(bg) {
+		if (bg) {
+			var r = alphaBlend(this.red, bg.red, this.alpha);
+			var g = alphaBlend(this.green, bg.green, this.alpha);
+			var b = alphaBlend(this.blue, bg.blue, this.alpha);
+		} else {
+			r = this.red;
+			g = this.green;
+			b = this.blue;
+		}
+	
+		return "rgb(" + r + ", " + g + ", " + b + ")";
+	};
+
+    /**
+	 * Return the colour in CSS rgba() functional notation, using integers 0-255 for color components: rgb(255, 255 255, 1.0);
+	 * @param bg - Optional parameter used for calculating the colour if an alpha value less than 1.0 has been specified.
+	 *             If not specified, and there is an alpha value, black will be used as the background colour.
+	 */
+	this.rgba = function() {
+		return "rgba(" + this.red + ", " + this.green + ", " + this.blue + ", " + this.alpha + ")";
+	};
+
+    /**
+     * Returns a Color object with the values inverted. Ignores alpha.
+     */
+    this.invert = function() {
+      return new Color("rgb(" + 
+                       (255 - this.red) + ", " + 
+                       (255 - this.green) + ", " + 
+                       (255 - this.blue) + ")");
+    };
+
+    /**
+	 * Blend this colour with the colour specified and return a pallet with all the steps in between.
+	 * @param color - The colour to blend with
+	 * @param steps - The number of steps to take to reach the color.
+	 */
+	this.blend = function(color, steps) {
+      var pallet = [];
+      var r, g, b, i;
+      
+      var step = {
+        "red"   : (alphaBlend(color.red, this.red, color.alpha) - this.red) / steps,
+        "green" : (alphaBlend(color.green, this.green, color.alpha) - this.green) / steps,
+        "blue"  : (alphaBlend(color.blue,  this.blue,  color.alpha) - this.blue) / steps
+      };
+      for (i = 0; i < steps + 1; i++) {
+        r = Math.round(this.red   + (step.red * i));
+        g = Math.round(this.green + (step.green * i));
+        b = Math.round(this.blue  + (step.blue * i));
+        pallet.push(new Color(r, g, b));
+      }
+      return pallet;
+	};
+     
+    /**
+	 * Constructor function
+	 */
+    this.toString = this.hex;
+
+    if (arguments.length >= 3) {
+      /* r, g, b or r, g, b, a */
+      var r = arguments[0];
+      var g = arguments[1];
+      var b = arguments[2];
+      var a = arguments[3];
+      
+      this.red   = (!isNaN(r)) ? clamp(r, 0, 255) : 0;
+      this.green = (!isNaN(g)) ? clamp(g, 0, 255) : 0;
+      this.blue  = (!isNaN(b)) ? clamp(b, 0, 255) : 0;
+      this.alpha = (!isNaN(a)) ? clamp(a, 0.0, 1.0) : 1.0;
+    } else if (arguments.length == 1) {
+      /* CSS Colour keyword or value */
+      var value = keyword[arguments[0]] ? keyword[arguments[0]] : arguments[0];
+      var components, pattern;
+      
+      for (var key in func) {
+        if (func[key].test(value)) {
+          pattern = key;
+        }
+      }
+      
+      components = value.match(func[pattern]);
+      var base = 10;
+      var m = 1; // Multiplier for percentage values
+      
+      switch (pattern) {
+      case "rgb%":
+      case "rgba%":
+        m = 2.55;
+        base = 10;
+        break;
+      case "rgb":
+      case "rgba":
+        base = 10;
+        break;
+      case "hex3":
+        components[1] = components[1] + "" + components[1];
+        components[2] = components[2] + "" + components[2];
+        components[3] = components[3] + "" + components[3];
+        base = 16;
+        break;
+      case "hex6":
+        base = 16;
+        break;
+      default:
+        components = [0, "255", "255", "255", "1.0"];
+      }
+      
+      this.red   = clamp(Math.round(parseInt(components[1],base) * m), 0, 255);
+      this.green = clamp(Math.round(parseInt(components[2],base) * m), 0, 255);
+      this.blue  = clamp(Math.round(parseInt(components[3],base) * m), 0, 255);
+      
+      if (isNaN(components[4])) {
+        this.alpha = 1;
+      } else {
+        this.alpha = clamp(parseFloat("0" + components[4]), 0.0, 1.0);
+      }
+    }
+};
+
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index 6215b65..7ef16b5 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -264,6 +264,7 @@ function ItsAllTextOverlay() {
     self.size = 0;
     self.node = node;
     self.button = null;
+    self.initial_color = 'transparent';
 
     self.uid = hashString([ node.ownerDocument.URL,
                             Math.random(),
@@ -331,6 +332,11 @@ function ItsAllTextOverlay() {
         var text = conv.ConvertFromUnicode(self.node.value);
         foStream.write(text, text.length);
         foStream.close();
+
+        /* Reset Timestamp and filesize, to prevent a spurious refresh */
+        self.timestamp = self.file.lastModifiedTime;
+        self.size      = self.file.fileSize;
+
         return self.file.path;
       } catch(e) {
         that.debug('write',self.file.path,e);
@@ -342,6 +348,7 @@ function ItsAllTextOverlay() {
     self.edit = function() {
       if (self.node.nodeName != "TEXTAREA") { return; }
       var filename = self.write();
+      self.initial_color = self.node.style.backgroundColor;
       try {
         var program = that.getEditor();
 
@@ -414,6 +421,22 @@ function ItsAllTextOverlay() {
       }
     };
 
+    fadeStep = function(pallet, step, delay) {
+      return function() {
+		if (step < pallet.length) {
+          self.node.style.backgroundColor = pallet[step++].hex();
+          setTimeout(fadeStep(pallet, step, delay),delay);
+		}
+      };
+    };
+      
+    fade = function(steps, delay) {
+      var colEnd = new Color(self.initial_color);
+      var colStart = new Color('yellow');//colEnd.invert();
+      var pallet = colStart.blend(colEnd, steps);
+      setTimeout(fadeStep(pallet, 0, delay), delay);
+    };
+
     /**
      * Update the node from the file.
      * @returns {boolean} Returns true ifthe file changed.
@@ -423,6 +446,7 @@ function ItsAllTextOverlay() {
       if (self.hasChanged()) {
         var value = self.read();
         if (value !== null) {
+          fade(15, 100);
           self.node.value = value;
           return true;
         }
diff --git a/chrome/content/itsalltext.xul b/chrome/content/itsalltext.xul
index aa4ae90..80f3dfb 100644
--- a/chrome/content/itsalltext.xul
+++ b/chrome/content/itsalltext.xul
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/x-javascript" src="Color.js"/>
   <script type="application/x-javascript" src="itsalltext.js"/>
   <!-- The merge point is contentAreaContextMenu -->
   <popup id="contentAreaContextMenu">

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list