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 @@
+
+
+
+
This is some fresh content.
+This has been added to your page dynamically.
+This content has been added to your page dynamically.
+Replacing existing content.
+This was inserted.
+This sample shows dynamic page updating in action, using Ajax.
+ +
+ Click me to do a replace + Click me to do a different replace + Click me to insert before + Click me to insert at the top + Click me to insert at the bottom + Click me to insert after + |
+
+
+
+ Change Region
+
+ This is the region of the page that gets updated.
+
+ |
+