cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jer...@apache.org
Subject svn commit: r306800 - in /cocoon/blocks/ajax/trunk: java/org/apache/cocoon/ajax/resources/js/ java/org/apache/cocoon/ajax/resources/xslt/ samples/
Date Thu, 06 Oct 2005 16:19:41 GMT
Author: jeremy
Date: Thu Oct  6 09:19:27 2005
New Revision: 306800

URL: http://svn.apache.org/viewcvs?rev=306800&view=rev
Log:
adding linked updating via ajax

Added:
    cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/
    cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl
    cocoon/blocks/ajax/trunk/samples/linked-updater-content-1.xml
    cocoon/blocks/ajax/trunk/samples/linked-updater-content-2.xml
    cocoon/blocks/ajax/trunk/samples/linked-updater-content-3.xml
    cocoon/blocks/ajax/trunk/samples/linked-updater.xml
Modified:
    cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/browserupdater.js
    cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/timedbrowserupdater.js
    cocoon/blocks/ajax/trunk/samples/sitemap.xmap
    cocoon/blocks/ajax/trunk/samples/welcome.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=306800&r1=306799&r2=306800&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 Thu
Oct  6 09:19:27 2005
@@ -111,34 +111,59 @@
 
 Cocoon.Ajax.BrowserUpdater.Handlers = {
     replace :  function(element) {
-        var id = element.getAttribute("id");
+        var id = element.getAttribute("id"); // the id from the incoming element
         if (!id) {
            alert("no id found on update element");
            return;
         }    
-        // Get the first child element (the first child may be some text!)
-        var firstChild = DOMUtils.firstChildElement(element);
-    
-        var oldElement = document.getElementById(id);
-        
+        var oldElement = $(id); // the element that is being replaced
         if (!oldElement) {
             alert("no element '" + id + "' in source document");
             return;
         }
-    
-        var newElement = DOMUtils.importNode(firstChild, document);
+        // Get the first child element (the first child may be some text!)
+        var content = DOMUtils.firstChildElement(element); // the element to replace with
+        var insertion = new Cocoon.Ajax.Insertion.Replace(oldElement, content);
         
-        // Warn: it's replace(new, old)!!
-        oldElement.parentNode.replaceChild(newElement, oldElement);
-        // Ensure the new node has the correct id
+        var newElement = $(id);
+				// Ensure the new node has the correct id
         newElement.setAttribute("id", id);
-        
+
         if (Cocoon.Ajax.BrowserUpdater.highlight) {
            Cocoon.Ajax.BrowserUpdater.highlight(newElement);
         }
     }
 
 }
+
+Cocoon.Ajax.Insertion = new Object();
+Cocoon.Ajax.Insertion.Replace = Class.create();
+Cocoon.Ajax.Insertion.Replace.prototype = Object.extend(new Abstract.Insertion(''), {
+
+  initialize: function(element, content) {
+  	this.element = $(element);
+    this.content = content;
+    this.insertContent();
+  },
+  
+  insertContent: function() {
+  	if (typeof this.content == "string") {
+  		var newDiv = document.createElement('div');
+  		newDiv.innerHTML = this.content;
+  		var newElement = newDiv.firstChild;
+  		this.element.parentNode.insertBefore(newElement, this.element);
+  		this.element.parentNode.removeChild(this.element);
+  	} else { // hopefully 'content' is a DOM Fragment
+			var newElement = DOMUtils.importNode(this.content, document);
+			this.element.parentNode.replaceChild(newElement, this.element);
+		}
+  }
+
+});
+
+
+
+
 
 // NB. This will probably be replaced with scriptaculous Effects
 

Modified: cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/timedbrowserupdater.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/timedbrowserupdater.js?rev=306800&r1=306799&r2=306800&view=diff
==============================================================================
--- cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/timedbrowserupdater.js
(original)
+++ cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/timedbrowserupdater.js
Thu Oct  6 09:19:27 2005
@@ -23,7 +23,7 @@
     this.setOptions(options);
     this.onComplete = this.options.onComplete;
 		this.autostart = (this.options.autostart || true); // default autostart: true
-    this.frequency = (this.options.frequency || 30);  // default frequency: 5 minutes
+    this.frequency = (this.options.frequency || 30);   // default frequency: 5 minutes
     this.decay = 1;																		 // default decay: none
 		this.populated = false;
     this.updater = {};
@@ -44,7 +44,6 @@
     this.updater.onComplete = undefined;
     clearTimeout(this.timer);
     this.timerIsRunning = false;
-    //(this.onComplete || Ajax.emptyFunction).apply(this, arguments);
     self.status = "Timer Stoping";
   },
 
@@ -213,6 +212,7 @@
 	document.location, 
 	{
 		method: 'post', 
-		onFailure: Cocoon.Ajax.BrowserUpdater.handleError
+		onFailure: Cocoon.Ajax.BrowserUpdater.handleError,
+		insertion: Cocoon.Ajax.Insertion.Replace
 	}
 );

Added: 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=306800&view=auto
==============================================================================
--- cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl (added)
+++ cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl Thu
Oct  6 09:19:27 2005
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<xsl:stylesheet version="1.0"
+		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+		xmlns:bu="http://apache.org/cocoon/browser-update/1.0"
+	>
+	
+	
+	
+	<!-- first version of tag -->
+	
+	<xsl:template match="a[@bu:target]">
+		<xsl:variable name="loc" select="generate-id()"/>
+		<xsl:variable name="verb" select="substring-before(@bu:target,'::')"/>
+		<xsl:variable name="id" select="substring-after(@bu:target,'::')"/>
+		<xsl:variable name="params" select="substring-after(@href,'?')"/>
+		<xsl:variable name="url">
+			<xsl:choose>
+				<xsl:when test="$params != ''"><xsl:value-of select="substring-before(@href,'?')"/></xsl:when>
+				<xsl:otherwise><xsl:value-of select="@href"/></xsl:otherwise>
+			</xsl:choose>
+		</xsl:variable>
+		<xsl:variable name="insertion">
+			<xsl:choose>
+				<xsl:when test="$verb = 'insert-before'">Insertion.Before</xsl:when>
+				<xsl:when test="$verb = 'insert-after'">Insertion.After</xsl:when>
+				<xsl:when test="$verb = 'insert-top'">Insertion.Top</xsl:when>
+				<xsl:when test="$verb = 'insert-bottom'">Insertion.Bottom</xsl:when>
+				<xsl:otherwise>Cocoon.Ajax.Insertion.Replace</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"/>
+					}
+				);
+      }
+    </script>
+		<a href="#" onclick="{concat('ajax',$loc,'();')}" title="{@title}"><xsl:apply-templates/></a>
+	</xsl:template>
+
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	<!-- Catches all unrecognised elements as they are-->
+	<xsl:template match="*|@*|node()|text()" priority="-1">
+		<xsl:copy><xsl:apply-templates select="*|@*|node()|text()"/></xsl:copy>
+	</xsl:template>
+</xsl:stylesheet>

Added: cocoon/blocks/ajax/trunk/samples/linked-updater-content-1.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/samples/linked-updater-content-1.xml?rev=306800&view=auto
==============================================================================
--- cocoon/blocks/ajax/trunk/samples/linked-updater-content-1.xml (added)
+++ cocoon/blocks/ajax/trunk/samples/linked-updater-content-1.xml Thu Oct  6 09:19:27 2005
@@ -0,0 +1,4 @@
+<div id="changeme">
+	<p>This is some fresh content.</p>
+	<p>This has been added to your page dynamically.</p>
+</div>
\ No newline at end of file

Added: cocoon/blocks/ajax/trunk/samples/linked-updater-content-2.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/samples/linked-updater-content-2.xml?rev=306800&view=auto
==============================================================================
--- cocoon/blocks/ajax/trunk/samples/linked-updater-content-2.xml (added)
+++ cocoon/blocks/ajax/trunk/samples/linked-updater-content-2.xml Thu Oct  6 09:19:27 2005
@@ -0,0 +1,4 @@
+<div id="changeme">
+	<p>This content has been added to your page dynamically.</p>
+	<p>Replacing existing content.</p>	
+</div>
\ No newline at end of file

Added: cocoon/blocks/ajax/trunk/samples/linked-updater-content-3.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/samples/linked-updater-content-3.xml?rev=306800&view=auto
==============================================================================
--- cocoon/blocks/ajax/trunk/samples/linked-updater-content-3.xml (added)
+++ cocoon/blocks/ajax/trunk/samples/linked-updater-content-3.xml Thu Oct  6 09:19:27 2005
@@ -0,0 +1,3 @@
+<div class="insert">
+	<p>This was inserted.</p>
+</div>
\ No newline at end of file

Added: cocoon/blocks/ajax/trunk/samples/linked-updater.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/samples/linked-updater.xml?rev=306800&view=auto
==============================================================================
--- cocoon/blocks/ajax/trunk/samples/linked-updater.xml (added)
+++ cocoon/blocks/ajax/trunk/samples/linked-updater.xml Thu Oct  6 09:19:27 2005
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<page
+	xmlns:bu="http://apache.org/cocoon/browser-update/1.0"
+	>
+  <title>Linked Updating</title>
+  <!-- include ajax scripts -->
+  <script type="text/javascript" src="resources/ajax/js/cocoon-ajax.js"/>
+
+	<style>
+		.container {border-color: #aaa;border-width: 1px;border-style: dotted; padding: 6px;margin:3px;}
+		#changeme {background-color: #eee; padding: 6px;margin:3px;border-color: green;border-width:
1px;border-style: dotted;padding:2px}
+		#changeme .insert {border-color: blue;border-width: 1px;border-style: dotted; padding:
6px;margin:3px;}
+		.insert {border-color: red;border-width: 1px;border-style: dotted; padding: 6px;margin:3px;}
+	</style>
+	<content>
+		<p>This sample shows dynamic page updating in action, using Ajax.</p>
+		
+		<table width="100%">
+			<tr valign="top">
+				<td width="30%">
+					<a href="linked-updater-content-1" bu:target="replace::changeme">Click me to do
a replace</a><br/>
+					<a href="linked-updater-content-2" bu:target="replace::changeme">Click me to do
a different replace</a><br/>
+					<a href="linked-updater-content-3" bu:target="insert-before::changeme">Click me
to insert before</a><br/>
+					<a href="linked-updater-content-3" bu:target="insert-top::changeme">Click me to
insert at the top</a><br/>
+					<a href="linked-updater-content-3" bu:target="insert-bottom::changeme">Click me
to insert at the bottom</a><br/>
+					<a href="linked-updater-content-3" bu:target="insert-after::changeme">Click me
to insert after</a><br/>
+				</td>
+				<td>
+					<div class="container">
+						<div>Change Region</div>
+						<div id="changeme">
+							This is the region of the page that gets updated.
+						</div>
+					</div>
+				</td>
+			</tr>
+		</table>
+	
+	
+	</content>
+</page>
\ No newline at end of file

Modified: cocoon/blocks/ajax/trunk/samples/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/samples/sitemap.xmap?rev=306800&r1=306799&r2=306800&view=diff
==============================================================================
--- cocoon/blocks/ajax/trunk/samples/sitemap.xmap (original)
+++ cocoon/blocks/ajax/trunk/samples/sitemap.xmap Thu Oct  6 09:19:27 2005
@@ -100,6 +100,24 @@
        <map:call function="timedUpdateDemo"/>
      </map:match>
 
+
+     <!--  Ajax Linked Update Demo -->
+     <map:match pattern="linked-updater">
+       <map:generate type="jx" src="linked-updater.xml"/>
+       <!--<map:transform src="resource://org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl"/>-->
+       <map:transform src="/Users/Shared/Development/Checkouts/Apache/Cocoon/Cocoon_2_1_X/src/blocks/ajax/java/org/apache/cocoon/ajax/resources/xslt/ajax-styling.xsl"/>
+       <map:call resource="simple-page2html">
+         <map:param name="file" value="linked-updater.xml"/>
+       </map:call>
+       <map:serialize type="html"/>
+     </map:match>
+
+     <map:match pattern="linked-updater-content-*">
+       <map:generate type="jx" src="{0}.xml"/>
+       <map:serialize type="xml"/>
+     </map:match>
+
+
      <map:match pattern="display-freememory">
        <map:generate type="jx" src="display-freememory.xml"/>
        <map:serialize type="xml"/>

Modified: cocoon/blocks/ajax/trunk/samples/welcome.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/samples/welcome.xml?rev=306800&r1=306799&r2=306800&view=diff
==============================================================================
--- cocoon/blocks/ajax/trunk/samples/welcome.xml (original)
+++ cocoon/blocks/ajax/trunk/samples/welcome.xml Thu Oct  6 09:19:27 2005
@@ -26,5 +26,6 @@
  <group name="Basic Samples">
   <sample name="File explorer" href="file-browser">Browse through the files in Cocoon's
sample directory with Ajax auto-completion.</sample>
   <sample name="Timed Browser Updater" href="timed-updater">Update regions of the screen
with live information, asynchronously.</sample>
+  <sample name="Linked Browser Updater" href="linked-updater">Update regions of the
screen via links.</sample>
  </group>
 </samples>



Mime
View raw message