You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by je...@apache.org on 2005/10/09 18:10:43 UTC
svn commit: r307449 - in /cocoon/blocks:
ajax/trunk/java/org/apache/cocoon/ajax/resources/js/browserupdater.js
ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl
forms/trunk/samples/forms/sampletree_template.xml
Author: jeremy
Date: Sun Oct 9 09:10:36 2005
New Revision: 307449
URL: http://svn.apache.org/viewcvs?rev=307449&view=rev
Log:
switched to using the Effect.Highlight from scriptaculous
Modified:
cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/browserupdater.js
cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl
cocoon/blocks/forms/trunk/samples/forms/sampletree_template.xml
Modified: cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/browserupdater.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/browserupdater.js?rev=307449&r1=307448&r2=307449&view=diff
==============================================================================
--- cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/browserupdater.js (original)
+++ cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/browserupdater.js Sun Oct 9 09:10:36 2005
@@ -130,12 +130,14 @@
newElement.setAttribute("id", id);
if (Cocoon.Ajax.BrowserUpdater.highlight) {
- Cocoon.Ajax.BrowserUpdater.highlight(newElement);
+ new Cocoon.Ajax.BrowserUpdater.highlight(newElement);
}
}
}
+Cocoon.Ajax.BrowserUpdater.highlight = Effect.Highlight;
+
Cocoon.Ajax.Insertion = new Object();
Cocoon.Ajax.Insertion.Replace = Class.create();
Cocoon.Ajax.Insertion.Replace.prototype = Object.extend(new Abstract.Insertion(''), {
@@ -159,141 +161,3 @@
}
});
-
-
-
-
-
-// NB. This will probably be replaced with scriptaculous Effects
-
-
-
-//-------------------------------------------------------------------------------------------------
-// Fader used to highlight page areas that have been updated
-//-------------------------------------------------------------------------------------------------
-
-/**
- * Create a fader that will progressively change an element's background color from
- * a given color back to its original color.
- *
- * @param elt the element to fade
- * @param color the starting color (default yellow)
- * @param duration the fade duration in msecs (default 1000)
- * @param fps the animation frames per seconds (default 25)
- */
-function Fader(elt, color, duration, fps) {
- // Set default values
- if (!color) color = "#FFFF80"; // yellow
- if (!duration) duration = 1000; // 1 sec
- if (!fps) fps = 25; // 25 frames/sec
-
- this.element = elt;
- this.fromColor = Fader.colorToRgb(color);
- this.toColor = Fader.colorToRgb(Fader.getBgColor(this.element));
-
- this.maxFrames = Math.round(fps * duration / 1000.0);
- this.delay = duration / this.maxFrames;
-}
-
-/**
- * Creates a default fader for a given element. This function can be used to set BrowserUpdate.highlight
- */
-Fader.fade = function(elt) {
- new Fader(elt).start();
-}
-
-Fader.prototype.start = function() {
- this.frame = 0;
- this._changeColor();
-}
-
-Fader.prototype._changeColor = function() {
- if (this.frame < this.maxFrames) {
- // Schedule the next iteration right now to keep a more accurate timing
- var fader = this;
- setTimeout(function() {fader._changeColor();}, this.delay);
- }
- var newColor = new Array(3);
- for (var channel = 0; channel < 3; channel++) {
- newColor[channel] = Math.floor(
- this.fromColor[channel] * ((this.maxFrames - this.frame) / this.maxFrames) +
- this.toColor[channel] * (this.frame/this.maxFrames)
- );
- }
-
- this.frame++;
- var color = Fader.rgbToColor(newColor[0], newColor[1], newColor[2]);
- this.element.style.backgroundColor = color;
-}
-
-/** Converts a "#RRGGBB" color as an array of 3 ints */
-Fader.colorToRgb = function(hex) {
- return [
- parseInt(hex.substr(1,2),16),
- parseInt(hex.substr(3,2),16),
- parseInt(hex.substr(5,2),16) ];
-}
-
-/** Converts rgb values to a "#RRGGBB" color */
-Fader.rgbToColor = function(r, g, b) {
- r = r.toString(16); if (r.length == 1) r = '0' + r;
- g = g.toString(16); if (g.length == 1) g = '0' + g;
- b = b.toString(16); if (b.length == 1) b = '0' + b;
- return "#" + r + g + b;
-}
-
-/** Get the background color of an element */
-Fader.getBgColor = function(elt) {
- while(elt) {
- var c;
- if (window.getComputedStyle) c = window.getComputedStyle(elt,null).getPropertyValue("background-color");
- if (elt.currentStyle) c = elt.currentStyle.backgroundColor;
- if ((c != "" && c != "transparent") || elt.tagName == "BODY") { break; }
- elt = elt.parentNode;
- }
- if (c == undefined || c == "" || c == "transparent" || c == "white") c = "#FFFFFF";
-
- var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
- if (rgb) return this.rgbToColor(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
- return c;
-}
-
-Cocoon.Ajax.BrowserUpdater.highlight = Fader.fade;
-
-//-------------------------------------------------------------------------------------------------
-// Blinker used to highlight page areas that have been updated
-//-------------------------------------------------------------------------------------------------
-
-function Blinker(elt, color, hltDelay, normalDelay, blinks) {
- this.element = elt;
- if (!color) color = "#FFFF80"; // yellow
- if (!hltDelay) hltDelay = 100;
- if (!normalDelay) normalDelay = 100;
- if (!blinks) blinks = 2;
-
- this.hltColor = color;
- this.hltDelay = hltDelay;
- this.normalDelay = normalDelay;
- this.normalColor = Fader.getBgColor(elt);
- this.maxBlinks = blinks * 2;
- this.blink = 0;
-}
-
-Blinker.prototype.start = function() {
- this.blink = 0;
- this._doBlink();
-}
-
-Blinker.blink = function(elt) {
- new Blinker(elt).start();
-}
-
-Blinker.prototype._doBlink = function() {
- var hlt = (this.blink % 2 == 0);
- this.element.style.backgroundColor = hlt ? this.hltColor : this.normalColor;;
- if (this.blink <= this.maxBlinks) {
- var blinker = this;
- setTimeout(function() {blinker._doBlink();}, hlt ? this.hltDelay : this.normalDelay);
- }
- this.blink++;
-}
Modified: cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl?rev=307449&r1=307448&r2=307449&view=diff
==============================================================================
--- cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl (original)
+++ cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl Sun Oct 9 09:10:36 2005
@@ -18,10 +18,10 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bu="http://apache.org/cocoon/browser-update/1.0"
+ xmlns:xl="http://www.w3.org/1999/xlink"
>
-
<!-- first version of tag -->
<xsl:template match="a[@bu:target]">
@@ -44,33 +44,31 @@
<xsl:otherwise>Cocoon.Ajax.Insertion.Replace</xsl:otherwise>
</xsl:choose>
</xsl:variable>
+ <xsl:variable name="effect-target">
+ <xsl:choose>
+ <xsl:when test="$verb = 'insert-before'">.previousSibling</xsl:when>
+ <xsl:when test="$verb = 'insert-after'">.nextSibling</xsl:when>
+ <xsl:when test="$verb = 'insert-top'">.firstChild</xsl:when>
+ <xsl:when test="$verb = 'insert-bottom'">.lastChild</xsl:when>
+ <xsl:otherwise></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
<script type="text/javascript">
function ajax<xsl:value-of select="$loc"/>() {
var up = new Ajax.Updater(
{success: "<xsl:value-of select="$id"/>"},
"<xsl:value-of select="$url"/>",
- {
- method: 'post',
+ {
parameters: "<xsl:value-of select="$params"/>",
onFailure: Cocoon.Ajax.BrowserUpdater.handleError,
- insertion: <xsl:value-of select="$insertion"/>
+ onComplete: function(request) { new Effect.Highlight($("<xsl:value-of select="$id"/>")<xsl:value-of select="$effect-target"/>); },
+ insertion: <xsl:value-of select="$insertion"/>
}
);
}
</script>
<a href="#" onclick="{concat('ajax',$loc,'();')}" title="{@title}"><xsl:apply-templates/></a>
</xsl:template>
-
-
-
-
-
-
-
-
-
-
-
<!-- Catches all unrecognised elements as they are-->
Modified: cocoon/blocks/forms/trunk/samples/forms/sampletree_template.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/forms/sampletree_template.xml?rev=307449&r1=307448&r2=307449&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/forms/sampletree_template.xml (original)
+++ cocoon/blocks/forms/trunk/samples/forms/sampletree_template.xml Sun Oct 9 09:10:36 2005
@@ -67,7 +67,7 @@
}
// Trees are fully-refreshed for now, and highlighting them isn't nice
- BrowserUpdate.highlight = null;
+ Cocoon.Ajax.BrowserUpdater.highlight = null;
</script>
<ft:form-template action="#{$cocoon/continuation/id}.continue" method="get" ajax="true">
Name: <ft:widget id="name"/>