You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by bb...@apache.org on 2007/06/25 03:05:26 UTC

svn commit: r550329 [13/13] - in /incubator/xap/site: docs/ docs/xmodify/ docs/xmodify/content/ docs/xmodify/css/ docs/xmodify/doc/ docs/xmodify/doc/complexTypes/ docs/xmodify/doc/complexTypes/html/ docs/xmodify/doc/complexTypes/xml/ docs/xmodify/doc/o...

Added: incubator/xap/site/javascript/xmodify/xmodify-jquery-compressed.js
URL: http://svn.apache.org/viewvc/incubator/xap/site/javascript/xmodify/xmodify-jquery-compressed.js?view=auto&rev=550329
==============================================================================
--- incubator/xap/site/javascript/xmodify/xmodify-jquery-compressed.js (added)
+++ incubator/xap/site/javascript/xmodify/xmodify-jquery-compressed.js Sun Jun 24 20:05:18 2007
@@ -0,0 +1 @@
+$.extend({xmodifyVersion:"0.3.0",xmodify:function(_1){var _2=_1.complete;_1.complete=function(_3,_4){if(_3.responseXML==null){_1.error.call(this,_3,_4);}else{jQuery.xProc(_3.responseXML);if(_2){_2.call(this,_3,_4);}}};return jQuery.ajax(_1);},xProc:function(_5){var _6={};jQuery.each(_5.documentElement.childNodes,function(){if(this.nodeType==1&&jQuery.xNodeName(this.nodeName)=="modifications"){jQuery.each(this.childNodes,function(){if(this.nodeType==1){jQuery.xProcElem(this,_6);}});}});},xProcElem:function(_7,_8){var _9=jQuery.xNodeName(_7.nodeName);var _a=_7.getAttribute("select");if(_9=="append"){jQuery.xProcIn(_7.childNodes,function(_b){$(_a).append(_b);},_8);}else{if(_9=="set-attribute"){jQuery.each(_7.childNodes,function(){if(this.nodeType==1){$(_a).attr(this.getAttribute("name"),this.getAttribute("value"));}});}else{if(_9=="set-style"){jQuery.each(_7.childNodes,function(){if(this.nodeType==1){$(_a).css(this.getAttribute("name"),this.getAttribute("value"));}});}else{if(_
 9=="insert-before"){jQuery.xProcIn(_7.childNodes,function(_c){$(_a).before(_c);},_8);}else{if(_9=="insert-after"){jQuery.xProcIn(_7.childNodes,function(_d){$(_a).after(_d);},_8);}else{if(_9=="replace-children"||_9=="set-innerhtml"){$(_a).empty();jQuery.xProcIn(_7.childNodes,function(_e){$(_a).append(_e);},_8);}else{if(_9=="remove-element"){$(_a).remove();}else{if(_9=="remove-attribute"){jQuery.each(_7.childNodes,function(){if(this.nodeType==1){$(_a).removeAttr(this.getAttribute("name"));}});}else{if(_9=="replace"){$(_a).each(function(){if(this.nextSibling){var _f=this.nextSibling;$(this).remove();jQuery.xProcIn(_7.childNodes,function(_10){$(_f).before(_10);},_8);}else{var _11=this.parentNode;$(this).remove();jQuery.xProcIn(_7.childNodes,function(_12){$(_11).append(_12);},_8);}});}else{if(_9=="insert-at"){var _13=_7.getAttribute("index");$(_a).each(function(){var _14=null;var _15=this;if(this.childNodes.length>_13){_14=this.childNodes[_13];}jQuery.xProcIn(_7.childNodes,functi
 on(_16){if(_14){$(_14).before(_16);}else{$(_15).append(_16);}},_8);});}else{if(_9=="variable"){var _17=_7.getAttribute("name");var _18=_7.getAttribute("deep");_8[_17]=$(_a).clone(_18);}}}}}}}}}}}},xProcIn:function(_19,_1a,_1b){$(_19).each(function(){if((this.nodeType==3||this.nodeType==4)&&jQuery.trim(this.nodeValue)!=""){_1a.call(this,this.nodeValue);}else{if(this.nodeType==1&&jQuery.xNodeName(this.nodeName)=="value-of"){_1a.call(this,_1b[this.getAttribute("name")]);}else{if(this.nodeType==1&&jQuery.xNodeName(this.nodeName)=="clone"){var _1c=this.getAttribute("select");var _1d=this.getAttribute("deep");_1a.call(this,$(_1c).clone(_1d));}else{if(this.nodeType==1){_1a.call(this,jQuery.xConvertToString(this));}}}}});},xConvertToString:function(_1e){var _1f="<"+_1e.nodeName;if(_1e.attributes){for(var i=0;i<_1e.attributes.length;i++){_1f+=" "+_1e.attributes[i].name+"=\""+_1e.attributes[i].value+"\"";}}_1f+=">";for(var i=0;i<_1e.childNodes.length;i++){if(_1e.childNodes[i].nodeType
 ==1){_1f+=jQuery.xConvertToString(_1e.childNodes[i]);}else{_1f+=_1e.childNodes[i].nodeValue;}}_1f+="</"+_1e.nodeName+">";return _1f;},xNodeName:function(_22){var i=_22.indexOf(":");if(i!=-1){_22=_22.substring(i+1);}return _22;}});
\ No newline at end of file

Added: incubator/xap/site/javascript/xmodify/xmodify-jquery.js
URL: http://svn.apache.org/viewvc/incubator/xap/site/javascript/xmodify/xmodify-jquery.js?view=auto&rev=550329
==============================================================================
--- incubator/xap/site/javascript/xmodify/xmodify-jquery.js (added)
+++ incubator/xap/site/javascript/xmodify/xmodify-jquery.js Sun Jun 24 20:05:18 2007
@@ -0,0 +1,246 @@
+/**
+ *
+ * xModify is an extension of the jQuery library that processes requests
+ * and update the HTML DOM using the xModify syntax.  Included in xModify is
+ * a series of instructions that can be used to update html.
+ *
+ * insert-after, insert-before, append, set-attribute, set-style
+ * set-innerhtml, replace-children, remove-element, remove-attribute
+ * replace
+ *
+ *
+ */
+$.extend({
+    /*
+     * Library version of xModify.
+     */
+    xmodifyVersion: "0.3.0",
+    
+    /**
+     * Main function to kick off an xModify request.
+     * The results of the request will be automatically
+     * processed.
+     *
+     * Look at the documenation for the jQuery.ajax function
+     * for information on the parameters.
+     *
+     * http://docs.jquery.com/Ajax
+     *
+     */
+    xmodify: function(ajaxProperties){
+        var complete = ajaxProperties.complete;
+        ajaxProperties.complete = function(result, request){
+            if (result.responseXML == null){
+                ajaxProperties.error.call(this, result, request);
+            }else{
+                jQuery.xProc(result.responseXML);
+                if (complete){
+                    complete.call(this, result, request);
+                }
+            }
+        }
+        return jQuery.ajax(ajaxProperties);
+    },
+    
+    /**
+     * Will return the modification element.
+     *
+     * Assumes the modifications elements are under XAL
+     * <xal>
+     *    <modifications>
+     *    </modifications>
+     * </xal>
+     *
+     */
+    xProc: function(modificationDocument){
+        var variables = {};
+        jQuery.each( 
+            modificationDocument.documentElement.childNodes, function(){
+                //look up all the modification elements
+				if ( this.nodeType == 1 && jQuery.xNodeName(this.nodeName) == "modifications"){
+				    //process all the modification elements
+                    jQuery.each(this.childNodes, function(){
+            				if (this.nodeType == 1){
+                                jQuery.xProcElem(this, variables);
+                            }
+                        }
+            		);
+                }
+            }
+		);
+    },
+    
+    /**
+     * Will return the modification element.
+     *
+     * Assumes the modifications elements are under XAL
+     *
+     * MAIN ELEMENT NAMES     
+     * insert-after         //This one is roughed out.
+     * insert-before        //This one is roughed out.
+     * append               //This one is roughed out.
+     * set-attribute        //This one is roughed out.
+     * set-style            //This one is roughed out.
+     * set-innerhtml        //This one is roughed out.
+     * replace-children     //This one is roughed out.
+     * remove-element       //This one is roughed out.
+     * remove-attribute     //This one is roughed out.
+     * replace              //This one is roughed out. 
+     * 
+     * insert-at            //This one is roughed out.  
+     *   
+     * clone                //This one is roughed out.  
+     * create-document      //NOT IMPLEMENTED
+     * 
+     * variable             //This one is roughed out.
+     * attribute            //This one is roughed out.       
+     * value-of             //This one is roughed out.
+     *
+     * TODOs
+     *
+     * Look into events and styles. Events and styles work
+     * as long as the programmer types them in correctly
+     *
+     * Need to add the must exist attribute
+     * Need to add events.
+     */
+    xProcElem: function(modElement, variables){
+        var nodeName = jQuery.xNodeName(modElement.nodeName);
+        var select = modElement.getAttribute("select");
+        
+        if (nodeName == "append"){
+            jQuery.xProcIn(modElement.childNodes, function(nodeValue){                
+                $(select).append(nodeValue);        
+            }, variables);
+        }else if (nodeName == "set-attribute"){
+            jQuery.each(modElement.childNodes, function(){
+            	if (this.nodeType == 1){
+                    $(select).attr(this.getAttribute("name"), this.getAttribute("value"));
+    			}
+            });
+        }else if (nodeName == "set-style"){
+            jQuery.each(modElement.childNodes, function(){
+            	if (this.nodeType == 1){
+                    $(select).css(this.getAttribute("name"), this.getAttribute("value"));
+    			}
+            });
+        }else if (nodeName == "insert-before"){
+            jQuery.xProcIn(modElement.childNodes, function(nodeValue){
+                $(select).before(nodeValue);        
+            }, variables);
+        }else if (nodeName == "insert-after"){
+            jQuery.xProcIn(modElement.childNodes, function(nodeValue){
+                $(select).after(nodeValue);        
+            }, variables);
+        }else if (nodeName == "replace-children" ||
+            nodeName == "set-innerhtml"){
+            $(select).empty();        
+            jQuery.xProcIn(modElement.childNodes, function(nodeValue){
+                $(select).append(nodeValue);        
+            }, variables);
+        }else if (nodeName == "remove-element"){
+            $(select).remove();        
+        }else if (nodeName == "remove-attribute"){
+            jQuery.each(modElement.childNodes, function(){
+            		if (this.nodeType == 1){
+    				    $(select).removeAttr(this.getAttribute("name"));
+    				}
+                });
+        }else if (nodeName == "replace"){
+            $(select).each(function(){
+                    //if the next sibling doesn't exist then place it at the end
+                    //other wise place it before the next sibling.
+                    if (this.nextSibling){
+                        var node = this.nextSibling;
+                        $(this).remove();
+                        jQuery.xProcIn(modElement.childNodes, function(nodeValue){
+                            $(node).before(nodeValue);        
+                        }, variables);
+                    }else{
+                        var node = this.parentNode;
+                        $(this).remove();
+                        jQuery.xProcIn(modElement.childNodes, function(nodeValue){
+                            $(node).append(nodeValue);        
+                        }, variables);
+                    }
+                });       
+        }else if (nodeName == "insert-at"){
+            var index = modElement.getAttribute("index");
+            $(select).each(function(){
+                    var beforeNode = null;
+                    var node = this;
+                    
+                    //if the index is more than the number
+                    //of children nodes append it.
+                    if (this.childNodes.length > index){
+                        beforeNode = this.childNodes[index];
+                    }
+                    
+                    jQuery.xProcIn(modElement.childNodes, function(nodeValue){
+                            if (beforeNode){
+                                $(beforeNode).before(nodeValue); 
+                            }else{
+                                $(node).append(nodeValue); 
+                            }       
+                        }, variables);
+            	});	
+        }else if (nodeName == "variable"){
+            var name = modElement.getAttribute("name");
+            var deep = modElement.getAttribute("deep");
+            variables[name] = $(select).clone(deep);
+        }
+    },     
+    
+    /**
+     * Called to process the an instruction will loop over each of the
+     * instruction's children and fire a callback
+     */
+    xProcIn: function(nodes, callback, variables){
+        $(nodes).each(function(){
+            //make sure there is a nodeValue and this isn't an empty string
+            if ((this.nodeType == 3 || this.nodeType == 4) && jQuery.trim(this.nodeValue) != ""){
+                callback.call(this, this.nodeValue);
+    		}else if (this.nodeType == 1 && jQuery.xNodeName(this.nodeName) == "value-of"){
+                callback.call(this, variables[this.getAttribute("name")]);
+            }else if (this.nodeType == 1 && jQuery.xNodeName(this.nodeName) == "clone"){
+                var select = this.getAttribute("select");
+                var deep = this.getAttribute("deep");
+                callback.call(this, $(select).clone(deep));
+    		}else if (this.nodeType == 1){
+    		    //got an XML node need to convert it into an HTML node
+                callback.call(this, jQuery.xConvertToString(this));
+     		}
+		});
+    }, 
+    
+    /**
+     * Convert an XML structure into a string 
+     */
+    xConvertToString: function(node){
+	    var elements = "<" + node.nodeName;
+	    if (node.attributes){
+    	    for (var i = 0; i < node.attributes.length; i++){
+    	          elements += " " + node.attributes[i].name + "=\"" + node.attributes[i].value + "\"";
+    	    } 
+	    }
+	    elements += ">";	    
+	    for (var i = 0; i < node.childNodes.length; i++){
+	          if (node.childNodes[i].nodeType == 1){
+	            elements += jQuery.xConvertToString(node.childNodes[i]);
+	          }else{
+	            elements += node.childNodes[i].nodeValue;
+	          }
+	    }
+	    elements += "</" + node.nodeName + ">";
+	    return elements;
+   },
+    
+    xNodeName: function(name){
+    	var i = name.indexOf(":");
+		if (i != -1){
+			name = name.substring(i + 1);
+		}
+		return name;
+    }
+
+});