JBoss Rich Faces SVN: r12358 - trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts.
by richfaces-svn-commits@lists.jboss.org
Author: artdaw
Date: 2009-01-20 19:39:10 -0500 (Tue, 20 Jan 2009)
New Revision: 12358
Modified:
trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js
Log:
colorPicker: bug in JS fixed
Modified: trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js 2009-01-20 20:57:32 UTC (rev 12357)
+++ trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js 2009-01-21 00:39:10 UTC (rev 12358)
@@ -425,7 +425,7 @@
var t3 = (t1-t2)*(h%60)/60;
if(h==360) h = 0;
if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3;}
- else if(h<120) {rgb.g=t1; `rgb.b=t2; rgb.r=t1-t3;}
+ else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3;}
else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3;}
else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3;}
else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3;}
16 years, 11 months
JBoss Rich Faces SVN: r12357 - in trunk/sandbox/ui/colorPicker/src/main: resources/org/richfaces/ui/renderkit/html/scripts and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: artdaw
Date: 2009-01-20 15:57:32 -0500 (Tue, 20 Jan 2009)
New Revision: 12357
Modified:
trunk/sandbox/ui/colorPicker/src/main/java/org/richfaces/ui/renderkit/ColorPickerRendererBase.java
trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js
trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx
Log:
colorPicker: ui bug were fixed
Modified: trunk/sandbox/ui/colorPicker/src/main/java/org/richfaces/ui/renderkit/ColorPickerRendererBase.java
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/java/org/richfaces/ui/renderkit/ColorPickerRendererBase.java 2009-01-20 20:30:59 UTC (rev 12356)
+++ trunk/sandbox/ui/colorPicker/src/main/java/org/richfaces/ui/renderkit/ColorPickerRendererBase.java 2009-01-20 20:57:32 UTC (rev 12357)
@@ -3,9 +3,11 @@
import java.io.IOException;
import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.util.InputUtils;
import org.richfaces.ui.component.UIColorPicker;
public abstract class ColorPickerRendererBase extends HeaderResourcesRendererBase{
@@ -21,4 +23,20 @@
colorPicker.setSubmittedValue(submittedValue);
}
}
+
+ public String getInputValue(FacesContext context, UIInput input) {
+ String inputValue = "";
+
+ String submittedValue = (String) input.getSubmittedValue();
+ if (submittedValue != null) {
+ inputValue = submittedValue;
+ } else {
+ Object value = input.getValue();
+ if (value != null) {
+ inputValue = InputUtils.getConvertedStringValue(context, input, value);
+ }
+ }
+
+ return inputValue;
+ }
}
\ No newline at end of file
Modified: trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js 2009-01-20 20:30:59 UTC (rev 12356)
+++ trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js 2009-01-20 20:57:32 UTC (rev 12357)
@@ -425,7 +425,7 @@
var t3 = (t1-t2)*(h%60)/60;
if(h==360) h = 0;
if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3;}
- else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3;}
+ else if(h<120) {rgb.g=t1; `rgb.b=t2; rgb.r=t1-t3;}
else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3;}
else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3;}
else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3;}
Modified: trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx 2009-01-20 20:30:59 UTC (rev 12356)
+++ trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx 2009-01-20 20:57:32 UTC (rev 12357)
@@ -68,7 +68,7 @@
</script>
</div>
<span id="#{clientId}colorPicker" class="rich-colorPicker-span" x:passThruWithExclusions="value,name,type,id,styleClass,class,style">
- <input readonly="readonly" disabled="#{disabled}" type="text" />
+ <input readonly="readonly" disabled="#{disabled}" type="text" name="#{clientId}" value="#{this:getInputValue(context, component)}"/>
<jsp:scriptlet>
<![CDATA[if(component.getFacet("icon")!=null && component.getFacet("icon").isRendered()) {]]>
</jsp:scriptlet>
16 years, 11 months
JBoss Rich Faces SVN: r12356 - in trunk/sandbox/samples/colorPicker/src/main: webapp/pages and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: artdaw
Date: 2009-01-20 15:30:59 -0500 (Tue, 20 Jan 2009)
New Revision: 12356
Added:
trunk/sandbox/samples/colorPicker/src/main/webapp/pages/colorPicker_ico.png
Modified:
trunk/sandbox/samples/colorPicker/src/main/java/org/richfaces/sandbox/samples/Bean.java
trunk/sandbox/samples/colorPicker/src/main/webapp/pages/index.jsp
Log:
colorPicker: sample was updated
Modified: trunk/sandbox/samples/colorPicker/src/main/java/org/richfaces/sandbox/samples/Bean.java
===================================================================
--- trunk/sandbox/samples/colorPicker/src/main/java/org/richfaces/sandbox/samples/Bean.java 2009-01-20 20:27:13 UTC (rev 12355)
+++ trunk/sandbox/samples/colorPicker/src/main/java/org/richfaces/sandbox/samples/Bean.java 2009-01-20 20:30:59 UTC (rev 12356)
@@ -28,8 +28,9 @@
public class Bean {
- private String color = "#cccccc";
-
+ private String color = "rgb(255, 250, 240)";
+ private String color2 = "#ffffff";
+
public Bean() {
}
@@ -41,4 +42,12 @@
public void setColor(String color) {
this.color = color;
}
+
+ public String getColor2() {
+ return color2;
+ }
+
+ public void setColor2(String color2) {
+ this.color2 = color2;
+ }
}
Added: trunk/sandbox/samples/colorPicker/src/main/webapp/pages/colorPicker_ico.png
===================================================================
(Binary files differ)
Property changes on: trunk/sandbox/samples/colorPicker/src/main/webapp/pages/colorPicker_ico.png
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/sandbox/samples/colorPicker/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/sandbox/samples/colorPicker/src/main/webapp/pages/index.jsp 2009-01-20 20:27:13 UTC (rev 12355)
+++ trunk/sandbox/samples/colorPicker/src/main/webapp/pages/index.jsp 2009-01-20 20:30:59 UTC (rev 12356)
@@ -8,8 +8,22 @@
<body>
<f:view>
<h:form>
- <colorPicker:colorPicker value="#{bean.color}" flat="true" showEvent="onclick" colorMode="rgb"/>
+ <colorPicker:colorPicker value="#{bean.color}" flat="false" colorMode="hex" disabled="false"/>
<h:commandButton value="Submit" />
+ <br /><br /><br /><br /><br /><br /><br /><br /><br />
+ <br /><br /><br /><br /><br />
+ <colorPicker:colorPicker value="#{bean.color2}" flat="true" colorMode="rgb">
+ <f:facet name="icon">
+ <f:verbatim>
+ <h:graphicImage value="/pages/colorPicker_ico.png" width="18px" height="18px"/>
+ </f:verbatim>
+ </f:facet>
+ <f:facet name="arrows">
+ <f:verbatim>
+ <div style="width: 30px; height: 5px; border: 1px solid gray; background:none;"></div>
+ </f:verbatim>
+ </f:facet>
+ </colorPicker:colorPicker>
</h:form>
</f:view>
</body>
16 years, 11 months
JBoss Rich Faces SVN: r12355 - in trunk/sandbox/ui/colorPicker: src/main/config/component and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: artdaw
Date: 2009-01-20 15:27:13 -0500 (Tue, 20 Jan 2009)
New Revision: 12355
Modified:
trunk/sandbox/ui/colorPicker/design/colorPicker.html
trunk/sandbox/ui/colorPicker/design/ui.colorpicker.js
trunk/sandbox/ui/colorPicker/src/main/config/component/colorPicker.xml
trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/css/colorPicker.xcss
trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js
trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx
Log:
colorPicker: bugs were fixed
Modified: trunk/sandbox/ui/colorPicker/design/colorPicker.html
===================================================================
--- trunk/sandbox/ui/colorPicker/design/colorPicker.html 2009-01-20 18:19:06 UTC (rev 12354)
+++ trunk/sandbox/ui/colorPicker/design/colorPicker.html 2009-01-20 20:27:13 UTC (rev 12355)
@@ -180,17 +180,17 @@
if(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 7.0") == -1){
$('div.rich-colorPicker-color').pngFix();
}
- $("#rich-colorPicker").colorPicker({
+ $("#rich-colorPicker input, img").colorPicker({
eventName: 'click',
- flat: false,
- color: "#807540",
+ flat: true,
+ color: "rgb(255, 250, 240)",
/*color: {r:128,g:117,b:64},*/
/*color: {h:50,s:50,b:50}*/
clientId: "#rich-colorPicker",
submit: function(e, ui) {
// Possibility to choose color modes for the input
-// $("#rich-colorPicker input").val(ui.hex);
- $("#rich-colorPicker input").val(ui.rgb);
+ $("#rich-colorPicker input").val(ui.hex);
+// $("#rich-colorPicker input").val(ui.rgb);
}
});
});
Modified: trunk/sandbox/ui/colorPicker/design/ui.colorpicker.js
===================================================================
--- trunk/sandbox/ui/colorPicker/design/ui.colorpicker.js 2009-01-20 18:19:06 UTC (rev 12354)
+++ trunk/sandbox/ui/colorPicker/design/ui.colorpicker.js 2009-01-20 20:27:13 UTC (rev 12355)
@@ -55,13 +55,40 @@
(function ($) {
$.widget("ui.colorPicker", {
-
+
+
+ _fixColors: function(cff, mode) {
+ cff.toLowerCase();
+ var pattern = /[0-9]+/g;
+ cff = cff.match(pattern);
+
+ if(mode == 'hsb'){
+ result = {h:cff[0], s: cff[1], b: cff[2]};
+ return result;
+ } else if(mode == 'rgb'){
+ result = {r:cff[0], g: cff[1], b: cff[2]};
+ return result;
+ }
+ },
+
_init: function() {
this.charMin = 65;
var o = this.options, self = this,
- tpl = $(o.clientId.toString()+"-ui");
+ tpl = $(o.clientId.toString()+"-ui");
+
+ if(o.color.indexOf('hsb') > -1){
+ this.color = this._fixHSB(this._fixColors(o.color, 'hsb'));
+ } else if(o.color.indexOf('rgb') > -1){
+ this.color = this._RGBToHSB(this._fixColors(o.color, 'rgb'));
+ } else if(o.color.indexOf('#') > -1){
+ this.color = this._HexToHSB(o.color);
+ } else{
+ return this;
+ }
+
+ /*
if (typeof o.color == 'string') {
this.color = this._HexToHSB(o.color);
} else if (o.color.r != undefined && o.color.g != undefined && o.color.b != undefined) {
@@ -71,6 +98,7 @@
} else {
return this;
}
+*/
this.origColor = this.color;
this.picker = $(tpl);
@@ -115,17 +143,22 @@
this._setIconColor(this.color);
this._setNewColor(this.color);
- if (o.flat) {
+ if (o.flat) {
+
this.picker.css({
- position: 'relative',
+ position: 'absolute',
display: 'block'
- });
+ });
+ $(this.element).bind(o.eventName+".colorPicker", function(e) { return self._show.call(self, e); });
} else {
$(this.element).bind(o.eventName+".colorPicker", function(e) { return self._show.call(self, e); });
- }
+ }
+
},
-
+
+
+
destroy: function() {
this.picker.remove();
Modified: trunk/sandbox/ui/colorPicker/src/main/config/component/colorPicker.xml
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/config/component/colorPicker.xml 2009-01-20 18:19:06 UTC (rev 12354)
+++ trunk/sandbox/ui/colorPicker/src/main/config/component/colorPicker.xml 2009-01-20 20:27:13 UTC (rev 12355)
@@ -52,6 +52,13 @@
<description>
The value of the component. You can define value as hex, RGB or HSB.
</description>
+ </property>
+ <property>
+ <name>disabled</name>
+ <classname>java.lang.Boolean</classname>
+ <description>
+ Defines whether the component is disabled.
+ </description>
</property>
&ui_component_attributes;
&html_events;
Modified: trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/css/colorPicker.xcss
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/css/colorPicker.xcss 2009-01-20 18:19:06 UTC (rev 12354)
+++ trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/css/colorPicker.xcss 2009-01-20 20:27:13 UTC (rev 12355)
@@ -6,7 +6,6 @@
<![CDATA[
.rich-colorPicker-wrapper{
display:none;
- font-family:Arial,Helvetica,sans-serif;
height:176px;
!height:166px;
overflow:hidden;
@@ -15,9 +14,8 @@
margin-top: 2px;
}
.rich-colorPicker-ext{
+ border: 1px solid;
position: relative;
- background-color: #ECF4FE;
- border: 1px solid #BED6F8;
height: 170px;
padding: 0px;
margin: 0px;
@@ -35,11 +33,10 @@
overflow:hidden;
height:150px;
width:150px;
- border: 1px solid #BED6F8;
+ border: 1px solid;
}
.rich-colorPicker-color div {
-/* background:transparent url(images/colorpicker_overlay.png) repeat scroll 0 0;*/
left:0;
position:absolute;
top:0;
@@ -48,7 +45,6 @@
}
.rich-colorPicker-color div div {
-/* background:transparent url(images/colorpicker_select.gif) repeat scroll 0 0;*/
left:0;
top:0;
position:absolute;
@@ -68,7 +64,6 @@
text-align: center;
}
.rich-colorPicker-rainbow div{
-/* background:transparent url(images/rangearrows.gif) no-repeat scroll left top; */
height:9px;
left:1px;
margin:-4px 0 0;
@@ -82,7 +77,7 @@
top:7px;
width: 60px;
height: 30px;
- border: 1px solid #BED6F8;
+ border: 1px solid;
}
.rich-colorPicker-current-color{
@@ -135,13 +130,9 @@
font-size: 16px;
}
-.rich-colorPicker-rgb-wrapper input, .rich-colorPicker-hex-wrapper input, .rich-colorPicker-hsb-wrapper input{
+.rich-colorPicker-colors-input{
width: 35px;
- background-color: #fff;
- border: 1px solid #BED6F8;
- color: #000;
- font-family: Arial,Verdana,sans-serif;
- font-size: 16px;
+ border: 1px solid;
}
.rich-colorPicker-hex-wrapper input{
@@ -151,16 +142,15 @@
.rich-colorPicker-submit, .rich-colorPicker-cancel{
position:absolute;
-right:75px;
-top:144px;
- border: 1px solid #BED6F8;
+ right:75px;
+ top:144px;
+ border: 1px solid;
}
.rich-colorPicker-cancel{
-right:7px;
+ right:7px;
}
.rich-colorPicker-span input{
- border: 1px solid #BED6F8;
- font-size: 12px;
+ border: 1px solid;
width:130px;
vertical-align:middle;
}
@@ -170,34 +160,62 @@
height:16px;
width:16px;
vertical-align:middle;
- border: 1px solid #BED6F8;
+ border: 1px solid;
}
+.rich-colorPicker-icon-disabled{
+ background-color: #cccccc;
+ height:16px;
+ width:16px;
+}
]]>
</f:verbatim>
- <u:selector name=".rich-colorPicker-color div">
+ <u:selector name=".rich-colorPicker-ext">
+ <u:style name="border-color" skin="panelBorderColor"/>
+ <u:style name="background-color" skin="additionalBackgroundColor"/>
+ <u:style name="font-family" skin="generalFamilyFont"/>
+ </u:selector>
+ <u:selector name=".rich-colorPicker-span input">
<u:style name="background-image">
+ <f:resource f:key="org.richfaces.renderkit.html.images.InputBackgroundImage" />
+ </u:style>
+ <u:style name="border-color" skin="panelBorderColor"/>
+ <u:style name="font-size" skin="generalSizeFont"/>
+ <u:style name="font-family" skin="generalFamilyFont"/>
+ </u:selector>
+ <u:selector name=".rich-colorPicker-icon">
+ <u:style name="border-color" skin="panelBorderColor"/>
+ </u:selector>
+ <u:selector name=".rich-colorPicker-color">
+ <u:style name="border-color" skin="panelBorderColor"/>
+ </u:selector>
+ <u:selector name=".rich-colorPicker-new-color">
+ <u:style name="border-color" skin="panelBorderColor"/>
+ </u:selector>
+ <u:selector name=".rich-colorPicker-current-color">
+ <u:style name="border-color" skin="panelBorderColor"/>
+ </u:selector>
+ <u:selector name=".rich-colorPicker-color div">
+ <u:style name="background-image">
<f:resource f:key="org/richfaces/ui/renderkit/html/images/colorpicker_overlay.png" />
</u:style>
</u:selector>
+ <u:selector name=".rich-colorPicker-colors-input">
+ <u:style name="font-size" skin="generalSizeFont"/>
+ <u:style name="font-family" skin="generalFamilyFont"/>
+ <u:style name="color" skin="generalTextColor"/>
+ <u:style name="border-color" skin="panelBorderColor"/>
+ <u:style name="background-color" skin="controlBackgroundColor"/>
+ </u:selector>
<u:selector name=".rich-colorPicker-color div div">
<u:style name="background-image">
<f:resource f:key="org/richfaces/ui/renderkit/html/images/colorpicker_select.gif" />
</u:style>
</u:selector>
-
<u:selector name=".rich-colorPicker-rainbow div">
<u:style name="background-image">
<f:resource f:key="org/richfaces/ui/renderkit/html/images/rangearrows.gif" />
</u:style>
</u:selector>
-
- <!--u:selector name=".my-inputDate-icon">
- <u:style name="border-color" skin="panelBorderColor"/>
- <u:style name="background-image">
- <f:resource f:key="org/richfaces/ui/renderkit/html/images/colorpicker_overlay.png" />
- </u:style>
- </u:selector-->
-
</f:template>
\ No newline at end of file
Modified: trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js 2009-01-20 18:19:06 UTC (rev 12354)
+++ trunk/sandbox/ui/colorPicker/src/main/resources/org/richfaces/ui/renderkit/html/scripts/ui.colorpicker.js 2009-01-20 20:27:13 UTC (rev 12355)
@@ -1,26 +1,43 @@
if (!window.Richfaces) window.Richfaces = {};
(function ($) {
$.widget("ui.colorPicker", {
+
+ _fixColors: function(cff, mode) {
+ cff.toLowerCase();
+ var pattern = /[0-9]+/g;
+ cff = cff.match(pattern);
+ if(mode == 'hsb'){
+ result = {h:cff[0], s: cff[1], b: cff[2]};
+ return result;
+ } else if(mode == 'rgb'){
+ result = {r:cff[0], g: cff[1], b: cff[2]};
+ return result;
+ }
+ },
+
_init: function() {
this.charMin = 65;
var o = this.options, self = this,
- tpl = $(o.clientId.toString()+"-popup");
- if (typeof o.color == 'string') {
+ tpl = $(o.clientId.toString()+"-popup");
+
+ if(o.color.indexOf('hsb') > -1){
+ this.color = this._fixHSB(this._fixColors(o.color, 'hsb'));
+
+ } else if(o.color.indexOf('rgb') > -1){
+ this.color = this._RGBToHSB(this._fixColors(o.color, 'rgb'));
+
+ } else if(o.color.indexOf('#') > -1){
this.color = this._HexToHSB(o.color);
- } else if (o.color.r != undefined && o.color.g != undefined && o.color.b != undefined) {
- this.color = this._RGBToHSB(o.color);
- } else if (o.color.h != undefined && o.color.s != undefined && o.color.b != undefined) {
- this.color = this._fixHSB(o.color);
- } else {
+
+ } else{
return this;
+
}
this.showEvent = o.showEvent;
this.origColor = this.color;
this.picker = $(tpl);
- if (o.flat) {
- this.picker.show();
- }
+
this.fields = this.picker.find('input')
.bind('keydown', function(e) { return self._keyDown.call(self, e); })
@@ -28,8 +45,8 @@
.bind('blur', function(e) { return self._blur.call(self, e); })
.bind('focus', function(e) { return self._focus.call(self, e); });
-/* this.picker.find('span').bind('mousedown', function(e) { return self._downIncrement.call(self, e); }); */
+
this.selector = this.picker.find('div.rich-colorPicker-color').bind('mousedown', function(e) { return self._downSelector.call(self, e); });
this.selectorIndic = this.selector.find('div div');
this.hue = this.picker.find('div.rich-colorPicker-rainbow div');
@@ -37,7 +54,7 @@
this.newColor = this.picker.find('div.rich-colorPicker-new-color');
this.currentColor = this.picker.find('div.rich-colorPicker-current-color');
- this.iconColor = $('img.rich-colorPicker-icon');
+ this.iconColor = $(o.clientId.toString()+' .rich-colorPicker-icon');
this.picker.find('.rich-colorPicker-submit')
.bind('mouseenter', function(e) { return self._enterSubmit.call(self, e); })
@@ -60,10 +77,12 @@
if (o.flat) {
this.picker.css({
- position: 'relative',
- display: 'block'
+ position: 'absolute'
});
+ this.picker.show();
+ $(this.element).bind(this.showEvent+".colorPicker", function(e) { return self._show.call(self, e); });
} else {
+ this.picker.hide();
$(this.element).bind(this.showEvent+".colorPicker", function(e) { return self._show.call(self, e); });
}
@@ -159,16 +178,6 @@
this._trigger('change', e, { options: this.options, hsb: col, hex: this._HSBToHex(col), rgb: this._HSBToRGB(col) });
},
_blur: function(e) {
-/*
- var col = this.color;
- this._fillRGBFields(col);
- this._fillHSBFields(col);
- this._fillHexFields(col);
- this._setHue(col);
- this._setSelector(col);
- this._setNewColor(col);
- this._setIconColor(col);
-*/
this.fields.parent().removeClass('rich-colorPicker-focus');
},
@@ -179,35 +188,6 @@
$(e.target.parentNode).addClass('rich-colorPicker-focus');
},
-/*
- _downIncrement: function(e) {
-
- var field = $(e.target).parent().find('input').focus(), self = this;
- this.currentIncrement = {
- el: $(e.target).parent().addClass('ui-colorPicker-slider'),
- max: e.target.parentNode.className.indexOf('-hsb-h') > 0 ? 360 : (e.target.parentNode.className.indexOf('-hsb') > 0 ? 100 : 255),
- y: e.pageY,
- field: field,
- val: parseInt(field.val(), 10)
- };
- $(document).bind('mouseup.cpSlider', function(e) { return self._upIncrement.call(self, e); });
- $(document).bind('mousemove.cpSlider', function(e) { return self._moveIncrement.call(self, e); });
- return false;
-
- },
- _moveIncrement: function(e) {
- this.currentIncrement.field.val(Math.max(0, Math.min(this.currentIncrement.max, parseInt(this.currentIncrement.val + e.pageY - this.currentIncrement.y, 10))));
- this._change.apply(this, [e, this.currentIncrement.field.get(0)]);
- return false;
- },
- _upIncrement: function(e) {
- this.currentIncrement.el.removeClass('ui-colorPicker-slider').find('input').focus();
- this._change.apply(this, [e, this.currentIncrement.field.get(0)]);
- $(document).unbind('mouseup.cpSlider');
- $(document).unbind('mousemove.cpSlider');
- return false;
- },
-*/
_downHue: function(e) {
this.currentHue = {
@@ -301,16 +281,14 @@
this._setCurrentColor(col);
this._setIconColor(col);
var RGBCol = this._HSBToRGB(col);
-
this._trigger("submit", e, { options: this.options, hex: '#'+this._HSBToHex(col), rgb: 'rgb('+RGBCol.r+', '+RGBCol.g+', '+RGBCol.b+')' });
-// this._trigger("submit", e, { options: this.options, hsb: col, hex: this._HSBToHex(col), rgb: this._HSBToRGB(col) });
this.picker.hide();
- $(window).unbind('mousedown.colorPicker');
+ $(document).unbind('mousedown.colorPicker');
return false;
},
_clickCancel: function(e) {
this.picker.hide();
- $(window).unbind('mousedown.colorPicker');
+ $(document).unbind('mousedown.colorPicker');
return false;
},
_show: function(e) {
@@ -339,7 +317,7 @@
}
var self = this;
- $(window).bind('mousedown.colorPicker', function(e) { return self._hide.call(self, e); });
+ $(document).bind('mousedown.colorPicker', function(e) { return self._hide.call(self, e); });
return false;
},
@@ -396,25 +374,7 @@
}
return false;
},
-/*
- _getScroll: function() {
- var t,l,w,h,iw,ih;
- if (document.documentElement) {
- t = document.documentElement.scrollTop;
- l = document.documentElement.scrollLeft;
- w = document.documentElement.scrollWidth;
- h = document.documentElement.scrollHeight;
- } else {
- t = document.body.scrollTop;
- l = document.body.scrollLeft;
- w = document.body.scrollWidth;
- h = document.body.scrollHeight;
- }
- iw = self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0;
- ih = self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0;
- return { t: t, l: l, w: w, h: h, iw: iw, ih: ih };
- },
-*/
+
_fixHSB: function(hsb) {
return {
h: Math.min(360, Math.max(0, hsb.h)),
@@ -491,14 +451,18 @@
return this._RGBToHex(this._HSBToRGB(hsb));
},
setColor: function(col) {
- if (typeof col == 'string') {
- col = this._HexToHSB(col);
- } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
- col = this._RGBToHSB(col);
- } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
- col = this._fixHSB(col);
- } else {
+ if(o.color.indexOf('hsb') > -1){
+ this.color = this._fixHSB(this._fixColors(o.color, 'hsb'));
+
+ } else if(o.color.indexOf('rgb') > -1){
+ this.color = this._RGBToHSB(this._fixColors(o.color, 'rgb'));
+
+ } else if(o.color.indexOf('#') > -1){
+ this.color = this._HexToHSB(o.color);
+
+ } else{
return this;
+
}
this.color = col;
Modified: trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx
===================================================================
--- trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx 2009-01-20 18:19:06 UTC (rev 12354)
+++ trunk/sandbox/ui/colorPicker/src/main/templates/org/richfaces/ui/htmlColorPicker.jspx 2009-01-20 20:27:13 UTC (rev 12355)
@@ -41,7 +41,9 @@
colorMode = colorMode.toLowerCase();
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("\\s+");
colorMode = pattern.matcher(colorMode).replaceAll("");
-
+
+ boolean disabled = getUtils().isBooleanAttribute(component, "disabled");
+ variables.setVariable("disabled",new Boolean(disabled));
]]></jsp:scriptlet>
$('\##{clientIdJquery}colorPicker').colorPicker({
@@ -66,7 +68,7 @@
</script>
</div>
<span id="#{clientId}colorPicker" class="rich-colorPicker-span" x:passThruWithExclusions="value,name,type,id,styleClass,class,style">
- <input readonly="readonly" type="text" />
+ <input readonly="readonly" disabled="#{disabled}" type="text" />
<jsp:scriptlet>
<![CDATA[if(component.getFacet("icon")!=null && component.getFacet("icon").isRendered()) {]]>
</jsp:scriptlet>
@@ -92,38 +94,54 @@
</div>
</div>
<div class="rich-colorPicker-rainbow">
- <img src="#{rainbow}" alt="rainbow" />
+ <img src="#{rainbow}" alt="rainbow" />
+ <jsp:scriptlet>
+ <![CDATA[if(component.getFacet("arrows")!=null && component.getFacet("arrows").isRendered()) {]]>
+ </jsp:scriptlet>
+ <u:insertFacet name="arrows" />
+ <jsp:scriptlet>
+ <![CDATA[
+ }else{
+ ]]>
+ </jsp:scriptlet>
<div></div>
+ <jsp:scriptlet>
+ <![CDATA[
+ }
+ ]]>
+ </jsp:scriptlet>
+
+
</div>
<div class="rich-colorPicker-new-color"></div>
<div class="rich-colorPicker-current-color"></div>
<div class="rich-colorPicker-hex-wrapper">
<label for="rich-colorPicker-hex-wrapper" title="hex">#:</label>
- <input id="#{clientId}-colorPicker-hex" type="text" maxlength="6" size="6" />
+ <input id="#{clientId}-colorPicker-hex" class="rich-colorPicker-colors-input" type="text" maxlength="6" size="6" />
</div>
<div class="rich-colorPicker-rgb-wrapper rich-colorPicker-rgb-r">
<label for="rgb">R:</label>
- <input id="#{clientId}-colorPicker-rgb-r" type="text" maxlength="3" size="2" />
+ <input id="#{clientId}-colorPicker-rgb-r" class="rich-colorPicker-colors-input" type="text" maxlength="3" size="2" />
</div>
<div class="rich-colorPicker-rgb-wrapper rich-colorPicker-rgb-g">
<label for="rgb-g">G:</label>
- <input id="#{clientId}-colorPicker-rgb-g" type="text" maxlength="3" size="2" />
+ <input id="#{clientId}-colorPicker-rgb-g" class="rich-colorPicker-colors-input" type="text" maxlength="3" size="2" />
</div>
<div class="rich-colorPicker-rgb-wrapper rich-colorPicker-rgb-b">
<label for="rgb-b">B:</label>
- <input id="#{clientId}-colorPicker-rgb-b" type="text" maxlength="3" size="2" />
+ <input id="#{clientId}-colorPicker-rgb-b" class="rich-colorPicker-colors-input" type="text" maxlength="3" size="2" />
</div>
<div class="rich-colorPicker-hsb-h rich-colorPicker-hsb-wrapper">
<label for="hsb-h">H:</label>
- <input id="#{clientId}-colorPicker-hsb-h" type="text" maxlength="3" size="2" />
+ <input id="#{clientId}-colorPicker-hsb-h" class="rich-colorPicker-colors-input" type="text" maxlength="3" size="2" />
</div>
<div class="rich-colorPicker-hsb-s rich-colorPicker-hsb-wrapper">
<label for="hsb-s">S:</label>
- <input id="#{clientId}-colorPicker-hsb-s" type="text" maxlength="3" size="2" />
+ <input id="#{clientId}-colorPicker-hsb-s" class="rich-colorPicker-colors-input" type="text" maxlength="3" size="2" />
</div>
<div class="rich-colorPicker-hsb-b rich-colorPicker-hsb-wrapper">
<label for="hsb-b">B:</label>
- <input id="#{clientId}-colorPicker-hsb-b" type="text" maxlength="3" size="2" />
+ <input id="#{clientId}-colorPicker-hsb-b" class="rich-colorPicker-colors-input" type="text" maxlength="3" size="2" />
</div>
<button type="button" class="rich-colorPicker-submit" name="submit">Apply</button>
<button type="button" class="rich-colorPicker-cancel" name="cancel">Cancel</button>
16 years, 11 months
JBoss Rich Faces SVN: r12354 - in trunk/test-applications/seleniumTest/richfaces/src: main/webapp/pages/tree and 4 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2009-01-20 13:19:06 -0500 (Tue, 20 Jan 2009)
New Revision: 12354
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/rich/
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/rich/dragAndDropTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/rich/treeAutoTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/rich/treeTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/dragAndDropTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/treeAutoTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/treeTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeRichModelTest.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeSwingModelTest.java
Removed:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/dragAndDropTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/treeAutoTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/treeTest.xhtml
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java
Log:
https://jira.jboss.org/jira/browse/RF-4826
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java 2009-01-20 18:12:56 UTC (rev 12353)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeTestBean.java 2009-01-20 18:19:06 UTC (rev 12354)
@@ -21,15 +21,9 @@
package org.ajax4jsf.bean.tree;
import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.Properties;
-import javax.faces.FacesException;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
import org.ajax4jsf.bean.tree.rich.AudioLibrary;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;
@@ -37,15 +31,10 @@
import org.richfaces.component.UITreeNode;
import org.richfaces.component.state.TreeStateAdvisor;
import org.richfaces.event.DropEvent;
-import org.richfaces.event.NodeSelectedEvent;
import org.richfaces.model.TreeNode;
-import org.richfaces.model.TreeNodeImpl;
import org.richfaces.model.TreeRowKey;
import org.xml.sax.SAXException;
-/**
- * Copied from demo
- */
public class TreeTestBean {
private TreeNode<String> rootNode = null;
@@ -54,62 +43,6 @@
private static final String DATA_PATH = "/simple-tree-data.properties";
- public void processSelection(NodeSelectedEvent event) {
- UITree tree = (UITree) event.getComponent();
- }
-
- private void addNodes(String path, TreeNode<String> node, Properties properties) {
- boolean end = false;
- int counter = 1;
-
- while (!end) {
- String key = path != null ? path + '.' + counter : String.valueOf(counter);
-
- String value = properties.getProperty(key);
- if (value != null) {
- TreeNode<String> nodeImpl = new TreeNodeImpl<String>();
- nodeImpl.setData(value);
- node.addChild(new Integer(counter), nodeImpl);
- addNodes(key, nodeImpl, properties);
- counter++;
- } else {
- end = true;
- }
- }
- }
-
- private void loadTree() {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- ExternalContext externalContext = facesContext.getExternalContext();
- InputStream dataStream = this.getClass().getClassLoader().getResourceAsStream(DATA_PATH);
- try {
- Properties properties = new Properties();
- properties.load(dataStream);
-
- rootNode = new TreeNodeImpl<String>();
- addNodes(null, rootNode, properties);
-
- } catch (IOException e) {
- throw new FacesException(e.getMessage(), e);
- } finally {
- if (dataStream != null) {
- try {
- dataStream.close();
- } catch (IOException e) {
- externalContext.log(e.getMessage(), e);
- }
- }
- }
- }
-
- public TreeNode<String> getTreeNode() {
- if (rootNode == null) {
- loadTree();
- }
-
- return rootNode;
- }
-
private TreeNode<Object> richRootNode = null;
public synchronized TreeNode<Object> getRichTreeNode() {
@@ -154,32 +87,6 @@
return swingNodes;
}
- private boolean isRichModel = true;
-
- /**
- * Gets value of isRichModel field.
- * @return value of isRichModel field
- */
- public boolean isRichModel() {
- return isRichModel;
- }
-
- /**
- * Set a new value for isRichModel field.
- * @param isRichModel a new value for isRichModel field
- */
- public void setRichModel(boolean isRichModel) {
- this.isRichModel = isRichModel;
- }
-
- public Object getRootNode() {
- if(isRichModel) {
- return getRichTreeNode();
- } else {
- return getSwingTreeNodes();
- }
- }
-
public String getNodeTitle() {
return nodeTitle;
}
@@ -269,62 +176,48 @@
setToggleOnClick(true);
setSwitchType("server");
setAjaxSubmitSelection(false);
- setRichModel(true);
}
public void initToggleOnClickTestAjaxMode() {
setToggleOnClick(true);
setSwitchType("ajax");
setAjaxSubmitSelection(false);
- setRichModel(true);
}
public void initToggleOnClickTestClientMode() {
setToggleOnClick(true);
setSwitchType("client");
setAjaxSubmitSelection(false);
- setRichModel(true);
}
+
public void initAjaxSubmitSelectionTest() {
setSwitchType("client");
setAjaxSubmitSelection(true);
setToggleOnClick(false);
- setRichModel(true);
}
public void initAjaxCoreTest() {
setSwitchType("ajax");
setToggleOnClick(false);
setAjaxSubmitSelection(true);
- setRichModel(true);
}
- public void initAjaxCoreTestWithSwingModel() {
- setSwitchType("ajax");
- setToggleOnClick(false);
- setAjaxSubmitSelection(true);
- setRichModel(false);
- }
-
public void initServerMode() {
setSwitchType("server");
setToggleOnClick(false);
setAjaxSubmitSelection(false);
- setRichModel(true);
}
public void initAjaxMode() {
setSwitchType("ajax");
setToggleOnClick(false);
setAjaxSubmitSelection(false);
- setRichModel(true);
}
public void initClientMode() {
setSwitchType("client");
setToggleOnClick(false);
setAjaxSubmitSelection(false);
- setRichModel(true);
}
public void initDragAndDropTest() {
@@ -337,7 +230,6 @@
setSwitchType("ajax");
setToggleOnClick(false);
setAjaxSubmitSelection(false);
- setRichModel(true);
}
private TreeStateAdvisor advisor;
Deleted: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/dragAndDropTest.xhtml
===================================================================
(Binary files differ)
Copied: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/rich/dragAndDropTest.xhtml (from rev 12350, trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/dragAndDropTest.xhtml)
===================================================================
(Binary files differ)
Copied: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/rich/treeAutoTest.xhtml (from rev 12350, trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/treeAutoTest.xhtml)
===================================================================
(Binary files differ)
Copied: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/rich/treeTest.xhtml (from rev 12350, trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/treeTest.xhtml)
===================================================================
(Binary files differ)
Added: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/dragAndDropTest.xhtml
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/dragAndDropTest.xhtml
___________________________________________________________________
Name: svn:mime-type
+ application/xhtml+xml
Added: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/treeAutoTest.xhtml
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/treeAutoTest.xhtml
___________________________________________________________________
Name: svn:mime-type
+ application/xhtml+xml
Added: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/treeTest.xhtml
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/swing/treeTest.xhtml
___________________________________________________________________
Name: svn:mime-type
+ application/xhtml+xml
Deleted: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/treeAutoTest.xhtml
===================================================================
(Binary files differ)
Deleted: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/tree/treeTest.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2009-01-20 18:12:56 UTC (rev 12353)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2009-01-20 18:19:06 UTC (rev 12354)
@@ -298,8 +298,8 @@
runScript("loadTemplate('" + template + "', '" + resetMethodName + "');", false);
waitForPageToLoad();
-
- selenium.open(protocol + "://" + host + ":" + port + "/" + APPLICATION_NAME + filterPrefix + postfix);
+ String base = getTestBase();
+ selenium.open(protocol + "://" + host + ":" + port + "/" + APPLICATION_NAME + filterPrefix + (null != base ? base : "") + postfix);
selenium.waitForPageToLoad(String.valueOf(pageRenderTime));
// setParentId(template.getPrefix());
@@ -325,9 +325,10 @@
protected void renderAutoTestPage(Template template, String resetMethodName) {
renderAutoTestPage(null, template, resetMethodName);
}
-
+
protected void renderAutoTestPage(String url, Template template, String resetMethodName) {
- selenium.open(protocol + "://" + host + ":" + port + "/" + APPLICATION_NAME + filterPrefix + (url != null ? url : getAutoTestUrl()));
+ String base = getTestBase();
+ selenium.open(protocol + "://" + host + ":" + port + "/" + APPLICATION_NAME + filterPrefix + (null != base ? base : "") + (url != null ? url : getAutoTestUrl()));
selenium.waitForPageToLoad(String.valueOf(pageRenderTime));
setParentId(template.getPrefix());
@@ -1196,7 +1197,11 @@
public String getAutoTestUrl() {
return null;
}
-
+
+ public String getTestBase() {
+ return null;
+ }
+
/**
* Control action that should force ajax request from the component.
* This method should wait for ajax completion
Added: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeRichModelTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeRichModelTest.java (rev 0)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeRichModelTest.java 2009-01-20 18:19:06 UTC (rev 12354)
@@ -0,0 +1,13 @@
+package org.richfaces.testng;
+
+/**
+ * Put richfaces model specific tests here.
+ */
+public class TreeRichModelTest extends TreeTest {
+
+ @Override
+ public String getTestBase() {
+ return "pages/tree/rich/";
+ }
+
+}
Property changes on: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeRichModelTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeSwingModelTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeSwingModelTest.java (rev 0)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeSwingModelTest.java 2009-01-20 18:19:06 UTC (rev 12354)
@@ -0,0 +1,13 @@
+package org.richfaces.testng;
+
+/**
+ * Put swing model specific tests here.
+ */
+public class TreeSwingModelTest extends TreeTest {
+
+ @Override
+ public String getTestBase() {
+ return "pages/tree/swing/";
+ }
+
+}
Property changes on: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeSwingModelTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java 2009-01-20 18:12:56 UTC (rev 12353)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TreeTest.java 2009-01-20 18:19:06 UTC (rev 12354)
@@ -32,14 +32,13 @@
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TreeTest extends SeleniumTestBase {
+public abstract class TreeTest extends SeleniumTestBase {
private static Map<String, String> params = new HashMap<String, String>();
private final static String INIT_TOGGLE_ON_CLICK_SERVER_MODE = "#{treeBean.initToggleOnClickTestServerMode}";
private final static String INIT_TOGGLE_ON_CLICK_AJAX_MODE = "#{treeBean.initToggleOnClickTestAjaxMode}";
private final static String INIT_TOGGLE_ON_CLICK_CLIENT_MODE = "#{treeBean.initToggleOnClickTestClientMode}";
private final static String INIT_AJAX_CORE_TEST = "#{treeBean.initAjaxCoreTest}";
- private final static String INIT_AJAX_CORE_TEST_WITH_SWING_MODEL = "#{treeBean.initAjaxCoreTestWithSwingModel}";
private final static String INIT_AJAX_SUBMIT_SELECTION = "#{treeBean.initAjaxSubmitSelectionTest}";
private final static String INIT_SERVER_MODE = "#{treeBean.initServerMode}";
private final static String INIT_AJAX_MODE = "#{treeBean.initAjaxMode}";
@@ -48,7 +47,7 @@
private final static String INIT_KEYBOARD_NAVIGATION_TEST = "#{treeBean.initKeyboardNavigationTest}";
private final static String TEAR_DOWN_METHOD = "#{treeBean.tearDown}";
private final static String INIT_DRAG_AND_DROP_TEST = "#{treeBean.initDragAndDropTest}";
- private final static String DRAG_AND_DROP_TEST_URL = "pages/tree/dragAndDropTest.xhtml";
+ private final static String DRAG_AND_DROP_TEST_URL = "dragAndDropTest.xhtml";
static final Map<String, String> styles = new HashMap<String, String>();
@@ -167,101 +166,7 @@
tester.checkNodeSelectedListener(true);
}
-//
-// Swing model
-//
-
@Test
- public void testAjaxSingleWithSwingModel(Template template) {
- AutoTester tester = getAutoTester(this);
- tester.renderPage(template, INIT_AJAX_CORE_TEST_WITH_SWING_MODEL);
- tester.reset();
- tester.setupControl(TestSetupEntry.ajaxSingle, Boolean.TRUE);
- tester.clickLoad();
- writeStatus("Navigate to the first child");
- String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
- writeStatus("Check node expanded events are delivered");
- tester.checkNodeExpandedListener(true);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
- type("//*[@id='"+ compId + ":childs']/div/div/table[1]/tbody/tr/td[3]/input", "New");
- tester.setExtrenalValidationFailed();
- tester.startTracing();
- writeStatus("Test ajaxSingle attribute");
- clickTreeNodeAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td[3]");
- tester.checkUpdateModel(false);
- tester.checkNodeSelectedListener(true);
- }
-
- @Test
- public void testAjaxSingleWithInternalValidationFailedWithSwingModel(Template template) {
- AutoTester tester = getAutoTester(this);
- tester.renderPage(template, INIT_AJAX_CORE_TEST_WITH_SWING_MODEL);
- tester.reset();
- tester.setupControl(TestSetupEntry.ajaxSingle, Boolean.TRUE);
- tester.clickLoad();
- writeStatus("Navigate to the first child");
- String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
- writeStatus("Check node expanded events are delivered");
- tester.checkNodeExpandedListener(true);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
- writeStatus("Set a new invalid value for the child");
- type("//*[@id='"+ compId + ":childs']/div/div/table[1]/tbody/tr/td[3]/input", "");
- tester.startTracing();
- writeStatus("Test ajaxSingle attribute in case of invalid component state");
- clickTreeNodeAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td[3]");
- tester.checkUpdateModel(false);
- tester.checkNodeSelectedListener(false);
- }
-
- @Test
- public void testImmediateWithSwingModel(Template template) {
- AutoTester tester = getAutoTester(this);
- tester.renderPage(template, INIT_AJAX_CORE_TEST_WITH_SWING_MODEL);
- tester.reset();
- tester.setupControl(TestSetupEntry.immediate, Boolean.TRUE);
- tester.clickLoad();
- writeStatus("Navigate to the first child");
- String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
- writeStatus("Check node expanded events are delivered");
- tester.checkNodeExpandedListener(true);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
- writeStatus("Set a new value for the child");
- type("//*[@id='"+ compId + ":childs']/div/div/table[1]/tbody/tr/td[3]/input", "New");
- tester.startTracing();
- writeStatus("Test immediate attribute");
- clickTreeNodeAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td[3]");
- tester.checkUpdateModel(true);
- tester.checkNodeSelectedListener(true);
- }
-
- @Test
- public void testImmediateWithExternalValidationFailedWithSwingModel(Template template) {
- AutoTester tester = getAutoTester(this);
- tester.renderPage(template, INIT_AJAX_CORE_TEST_WITH_SWING_MODEL);
- tester.reset();
- tester.setupControl(TestSetupEntry.immediate, Boolean.TRUE);
- tester.clickLoad();
- writeStatus("Navigate to the first child");
- String compId = getAutoTester(this).getClientId(AutoTester.COMPONENT_ID);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/table[1]/tbody/tr/td/div/a");
- writeStatus("Check node expanded events are delivered");
- tester.checkNodeExpandedListener(true);
- clickAjaxCommandAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td/div/a");
- writeStatus("set a new value for the child");
- type("//*[@id='"+ compId + ":childs']/div/div/table[1]/tbody/tr/td[3]/input", "New");
- writeStatus("Set external validation to fail");
- tester.setExtrenalValidationFailed();
- tester.startTracing();
- writeStatus("Test immediate attribute with external validation failed");
- clickTreeNodeAndWait("//*[@id='"+ compId + ":childs']/div/table[1]/tbody/tr/td[3]");
- tester.checkUpdateModel(false);
- tester.checkNodeSelectedListener(true);
- }
-
- @Test
public void testToggleOnClickTrueWithServerMode(Template template) {
AutoTester tester = getAutoTester(this);
tester.renderPage(template, INIT_TOGGLE_ON_CLICK_SERVER_MODE);
@@ -667,12 +572,12 @@
@Override
public String getTestUrl() {
- return "pages/tree/treeTest.xhtml";
+ return "treeTest.xhtml";
}
@Override
public String getAutoTestUrl() {
- return "pages/tree/treeAutoTest.xhtml";
+ return "treeAutoTest.xhtml";
}
private void clickTreeNode(String locator){
16 years, 11 months
JBoss Rich Faces SVN: r12353 - trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2009-01-20 13:12:56 -0500 (Tue, 20 Jan 2009)
New Revision: 12353
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/TemplateBean.java
Log:
moved to paths based on doc root
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/TemplateBean.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/TemplateBean.java 2009-01-20 16:49:29 UTC (rev 12352)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/TemplateBean.java 2009-01-20 18:12:56 UTC (rev 12353)
@@ -35,36 +35,36 @@
import org.apache.commons.logging.LogFactory;
public class TemplateBean {
-
- private static final Log log = LogFactory.getLog(TemplateBean.class);
-
- static final List<String> dataTableModel = new ArrayList<String>();
- static {
- dataTableModel.add("1");
- dataTableModel.add("2");
- }
-
+
+ private static final Log log = LogFactory.getLog(TemplateBean.class);
+
+ static final List<String> dataTableModel = new ArrayList<String>();
+ static {
+ dataTableModel.add("1");
+ dataTableModel.add("2");
+ }
+
public static final String PARAM_NAME = "t";
-
+
private Template template = Template.SIMPLE;
-
+
private Template templatePath = Template.SIMPLE;
-
+
private String methodName;
-
+
private Integer dataTableRowIndex = 0;
-
- public String getTemplateId() {
+
+ public String getTemplateId() {
return template.toString();
}
-
+
public void setTemplateId(String template) {
- this.template = Template.valueOf(template);
- if (this.template.equals(Template.DATA_TABLE)) {
- dataTableRowIndex = 0;
- }else if (this.template.equals(Template.DATA_TABLE2)) {
- dataTableRowIndex = 1;
- }
+ this.template = Template.valueOf(template);
+ if (this.template.equals(Template.DATA_TABLE)) {
+ dataTableRowIndex = 0;
+ } else if (this.template.equals(Template.DATA_TABLE2)) {
+ dataTableRowIndex = 1;
+ }
}
@@ -76,16 +76,16 @@
* @return the template
*/
public String getTemplate() {
- return "../../template/" + template.getName() + ".xhtml";
+ return "/template/" + template.getName() + ".xhtml";
}
-
+
/**
* @return the template
*/
public String getAutoTestTemplate() {
- return "../../template/autotest/" + template.getName() + ".xhtml";
+ return "/template/autotest/" + template.getName() + ".xhtml";
}
-
+
/**
* @return the template
*/
@@ -100,7 +100,7 @@
public void setTemplate(Template template) {
this.template = template;
}
-
+
public void setTemplatePath(Template templatePath) {
this.templatePath = templatePath;
}
@@ -113,62 +113,58 @@
return retVal;
}
-
+
/**
* Invokes reset method of appropriate backing bean
+ *
* @param actionEvent
*/
public void reset(ActionEvent actionEvent) {
- FacesContext context = FacesContext.getCurrentInstance();
- if (context != null) {
- if (methodName != null && methodName.trim().length() > 0 && !"null".equals(methodName)) {
- try {
- ExpressionFactory factory = context.getApplication()
- .getExpressionFactory();
- if (factory != null) {
- MethodExpression methodExpression = factory
- .createMethodExpression(context.getELContext(),
- methodName, Void.class, new Class[] {});
- methodExpression.invoke(context.getELContext(),
- new Object[] {});
- }
- } catch (Exception e) {
- log.error(
- "Reset method has not been found by this expression: "
- + methodName, e);
- }
- }
- }
+ FacesContext context = FacesContext.getCurrentInstance();
+ if (context != null) {
+ if (methodName != null && methodName.trim().length() > 0 && !"null".equals(methodName)) {
+ try {
+ ExpressionFactory factory = context.getApplication().getExpressionFactory();
+ if (factory != null) {
+ MethodExpression methodExpression = factory.createMethodExpression(context.getELContext(),
+ methodName, Void.class, new Class[] {});
+ methodExpression.invoke(context.getELContext(), new Object[] {});
+ }
+ } catch (Exception e) {
+ log.error("Reset method has not been found by this expression: " + methodName, e);
+ }
+ }
+ }
- }
+ }
- /**
- * @return the methodName
- */
- public String getMethodName() {
- return methodName;
- }
+ /**
+ * @return the methodName
+ */
+ public String getMethodName() {
+ return methodName;
+ }
- /**
- * @param methodName the methodName to set
- */
- public void setMethodName(String methodName) {
- this.methodName = methodName;
- }
+ /**
+ * @param methodName
+ * the methodName to set
+ */
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
- /**
- * @return the dataTableRowIndex
- */
- public Integer getDataTableRowIndex() {
- return dataTableRowIndex;
- }
+ /**
+ * @return the dataTableRowIndex
+ */
+ public Integer getDataTableRowIndex() {
+ return dataTableRowIndex;
+ }
- /**
- * @return the dataTableModel
- */
- public List<String> getDataTableModel() {
- return dataTableModel;
- }
+ /**
+ * @return the dataTableModel
+ */
+ public List<String> getDataTableModel() {
+ return dataTableModel;
+ }
-
}
\ No newline at end of file
16 years, 11 months
JBoss Rich Faces SVN: r12352 - in trunk/sandbox/samples/maven-rd-plugin-sample/src/main/webapp: scripts and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-01-20 11:49:29 -0500 (Tue, 20 Jan 2009)
New Revision: 12352
Added:
trunk/sandbox/samples/maven-rd-plugin-sample/src/main/webapp/scripts/
trunk/sandbox/samples/maven-rd-plugin-sample/src/main/webapp/scripts/custom-dependencies.js
Log:
Added: trunk/sandbox/samples/maven-rd-plugin-sample/src/main/webapp/scripts/custom-dependencies.js
===================================================================
--- trunk/sandbox/samples/maven-rd-plugin-sample/src/main/webapp/scripts/custom-dependencies.js (rev 0)
+++ trunk/sandbox/samples/maven-rd-plugin-sample/src/main/webapp/scripts/custom-dependencies.js 2009-01-20 16:49:29 UTC (rev 12352)
@@ -0,0 +1,10121 @@
+//=========================== before =====================
+/* Prototype JavaScript framework, version 1.6.0.3
+ * (c) 2005-2008 Sam Stephenson
+ *
+ * Prototype is freely distributable under the terms of an MIT-style license.
+ * For details, see the Prototype web site: http://www.prototypejs.org/
+ *
+ *--------------------------------------------------------------------------*/
+
+var Prototype = {
+ Version: '1.6.0.3',
+
+ Browser: {
+ IE: !!(window.attachEvent &&
+ navigator.userAgent.indexOf('Opera') === -1),
+ Opera: navigator.userAgent.indexOf('Opera') > -1,
+ WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
+ Gecko: navigator.userAgent.indexOf('Gecko') > -1 &&
+ navigator.userAgent.indexOf('KHTML') === -1,
+ MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
+ },
+
+ BrowserFeatures: {
+ XPath: !!document.evaluate,
+ SelectorsAPI: !!document.querySelector,
+ ElementExtensions: !!window.HTMLElement,
+ SpecificElementExtensions:
+ document.createElement('div')['__proto__'] &&
+ document.createElement('div')['__proto__'] !==
+ document.createElement('form')['__proto__']
+ },
+
+ ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
+ JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
+
+ emptyFunction: function() { },
+ K: function(x) { return x }
+};
+
+if (Prototype.Browser.MobileSafari)
+ Prototype.BrowserFeatures.SpecificElementExtensions = false;
+
+
+/* Based on Alex Arnell's inheritance implementation. */
+var Class = {
+ create: function() {
+ var parent = null, properties = $A(arguments);
+ if (Object.isFunction(properties[0]))
+ parent = properties.shift();
+
+ function klass() {
+ this.initialize.apply(this, arguments);
+ }
+
+ Object.extend(klass, Class.Methods);
+ klass.superclass = parent;
+ klass.subclasses = [];
+
+ if (parent) {
+ var subclass = function() { };
+ subclass.prototype = parent.prototype;
+ klass.prototype = new subclass;
+ parent.subclasses.push(klass);
+ }
+
+ for (var i = 0; i < properties.length; i++)
+ klass.addMethods(properties[i]);
+
+ if (!klass.prototype.initialize)
+ klass.prototype.initialize = Prototype.emptyFunction;
+
+ klass.prototype.constructor = klass;
+
+ return klass;
+ }
+};
+
+Class.Methods = {
+ addMethods: function(source) {
+ var ancestor = this.superclass && this.superclass.prototype;
+ var properties = Object.keys(source);
+
+ if (!Object.keys({ toString: true }).length)
+ properties.push("toString", "valueOf");
+
+ for (var i = 0, length = properties.length; i < length; i++) {
+ var property = properties[i], value = source[property];
+ if (ancestor && Object.isFunction(value) &&
+ value.argumentNames().first() == "$super") {
+ var method = value;
+ value = (function(m) {
+ return function() { return ancestor[m].apply(this, arguments) };
+ })(property).wrap(method);
+
+ value.valueOf = method.valueOf.bind(method);
+ value.toString = method.toString.bind(method);
+ }
+ this.prototype[property] = value;
+ }
+
+ return this;
+ }
+};
+
+var Abstract = { };
+
+Object.extend = function(destination, source) {
+ for (var property in source)
+ destination[property] = source[property];
+ return destination;
+};
+
+Object.extend(Object, {
+ inspect: function(object) {
+ try {
+ if (Object.isUndefined(object)) return 'undefined';
+ if (object === null) return 'null';
+ return object.inspect ? object.inspect() : String(object);
+ } catch (e) {
+ if (e instanceof RangeError) return '...';
+ throw e;
+ }
+ },
+
+ toJSON: function(object) {
+ var type = typeof object;
+ switch (type) {
+ case 'undefined':
+ case 'function':
+ case 'unknown': return;
+ case 'boolean': return object.toString();
+ }
+
+ if (object === null) return 'null';
+ if (object.toJSON) return object.toJSON();
+ if (Object.isElement(object)) return;
+
+ var results = [];
+ for (var property in object) {
+ var value = Object.toJSON(object[property]);
+ if (!Object.isUndefined(value))
+ results.push(property.toJSON() + ': ' + value);
+ }
+
+ return '{' + results.join(', ') + '}';
+ },
+
+ toQueryString: function(object) {
+ return $H(object).toQueryString();
+ },
+
+ toHTML: function(object) {
+ return object && object.toHTML ? object.toHTML() : String.interpret(object);
+ },
+
+ keys: function(object) {
+ var keys = [];
+ for (var property in object)
+ keys.push(property);
+ return keys;
+ },
+
+ values: function(object) {
+ var values = [];
+ for (var property in object)
+ values.push(object[property]);
+ return values;
+ },
+
+ clone: function(object) {
+ return Object.extend({ }, object);
+ },
+
+ isElement: function(object) {
+ return !!(object && object.nodeType == 1);
+ },
+
+ isArray: function(object) {
+ return object != null && typeof object == "object" &&
+ 'splice' in object && 'join' in object;
+ },
+
+ isHash: function(object) {
+ return object instanceof Hash;
+ },
+
+ isFunction: function(object) {
+ return typeof object == "function";
+ },
+
+ isString: function(object) {
+ return typeof object == "string";
+ },
+
+ isNumber: function(object) {
+ return typeof object == "number";
+ },
+
+ isUndefined: function(object) {
+ return typeof object == "undefined";
+ }
+});
+
+Object.extend(Function.prototype, {
+ argumentNames: function() {
+ var names = this.toString().match(/^[\s\(]*function[^(]*\(([^\)]*)\)/)[1]
+ .replace(/\s+/g, '').split(',');
+ return names.length == 1 && !names[0] ? [] : names;
+ },
+
+ bind: function() {
+ if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
+ var __method = this, args = $A(arguments), object = args.shift();
+ return function() {
+ return __method.apply(object, args.concat($A(arguments)));
+ }
+ },
+
+ bindAsEventListener: function() {
+ var __method = this, args = $A(arguments), object = args.shift();
+ return function(event) {
+ return __method.apply(object, [event || window.event].concat(args));
+ }
+ },
+
+ curry: function() {
+ if (!arguments.length) return this;
+ var __method = this, args = $A(arguments);
+ return function() {
+ return __method.apply(this, args.concat($A(arguments)));
+ }
+ },
+
+ delay: function() {
+ var __method = this, args = $A(arguments), timeout = args.shift() * 1000;
+ return window.setTimeout(function() {
+ return __method.apply(__method, args);
+ }, timeout);
+ },
+
+ defer: function() {
+ var args = [0.01].concat($A(arguments));
+ return this.delay.apply(this, args);
+ },
+
+ wrap: function(wrapper) {
+ var __method = this;
+ return function() {
+ return wrapper.apply(this, [__method.bind(this)].concat($A(arguments)));
+ }
+ },
+
+ methodize: function() {
+ if (this._methodized) return this._methodized;
+ var __method = this;
+ return this._methodized = function() {
+ return __method.apply(null, [this].concat($A(arguments)));
+ };
+ }
+});
+
+Date.prototype.toJSON = function() {
+ return '"' + this.getUTCFullYear() + '-' +
+ (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
+ this.getUTCDate().toPaddedString(2) + 'T' +
+ this.getUTCHours().toPaddedString(2) + ':' +
+ this.getUTCMinutes().toPaddedString(2) + ':' +
+ this.getUTCSeconds().toPaddedString(2) + 'Z"';
+};
+
+var Try = {
+ these: function() {
+ var returnValue;
+
+ for (var i = 0, length = arguments.length; i < length; i++) {
+ var lambda = arguments[i];
+ try {
+ returnValue = lambda();
+ break;
+ } catch (e) { }
+ }
+
+ return returnValue;
+ }
+};
+
+RegExp.prototype.match = RegExp.prototype.test;
+
+RegExp.escape = function(str) {
+ return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
+};
+
+/*--------------------------------------------------------------------------*/
+
+var PeriodicalExecuter = Class.create({
+ initialize: function(callback, frequency) {
+ this.callback = callback;
+ this.frequency = frequency;
+ this.currentlyExecuting = false;
+
+ this.registerCallback();
+ },
+
+ registerCallback: function() {
+ this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
+ },
+
+ execute: function() {
+ this.callback(this);
+ },
+
+ stop: function() {
+ if (!this.timer) return;
+ clearInterval(this.timer);
+ this.timer = null;
+ },
+
+ onTimerEvent: function() {
+ if (!this.currentlyExecuting) {
+ try {
+ this.currentlyExecuting = true;
+ this.execute();
+ } finally {
+ this.currentlyExecuting = false;
+ }
+ }
+ }
+});
+Object.extend(String, {
+ interpret: function(value) {
+ return value == null ? '' : String(value);
+ },
+ specialChar: {
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '\\': '\\\\'
+ }
+});
+
+Object.extend(String.prototype, {
+ gsub: function(pattern, replacement) {
+ var result = '', source = this, match;
+ replacement = arguments.callee.prepareReplacement(replacement);
+
+ while (source.length > 0) {
+ if (match = source.match(pattern)) {
+ result += source.slice(0, match.index);
+ result += String.interpret(replacement(match));
+ source = source.slice(match.index + match[0].length);
+ } else {
+ result += source, source = '';
+ }
+ }
+ return result;
+ },
+
+ sub: function(pattern, replacement, count) {
+ replacement = this.gsub.prepareReplacement(replacement);
+ count = Object.isUndefined(count) ? 1 : count;
+
+ return this.gsub(pattern, function(match) {
+ if (--count < 0) return match[0];
+ return replacement(match);
+ });
+ },
+
+ scan: function(pattern, iterator) {
+ this.gsub(pattern, iterator);
+ return String(this);
+ },
+
+ truncate: function(length, truncation) {
+ length = length || 30;
+ truncation = Object.isUndefined(truncation) ? '...' : truncation;
+ return this.length > length ?
+ this.slice(0, length - truncation.length) + truncation : String(this);
+ },
+
+ strip: function() {
+ return this.replace(/^\s+/, '').replace(/\s+$/, '');
+ },
+
+ stripTags: function() {
+ return this.replace(/<\/?[^>]+>/gi, '');
+ },
+
+ stripScripts: function() {
+ return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
+ },
+
+ extractScripts: function() {
+ var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
+ var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
+ return (this.match(matchAll) || []).map(function(scriptTag) {
+ var result = (scriptTag.match(matchOne) || ['', ''])[1];
+ result = result.replace(/</,"<").replace(/\s*<!--[^\r\n]*/, "");
+ return result;
+ });
+ },
+
+ evalScripts: function() {
+ return this.extractScripts().map(function(script) { return eval(script) });
+ },
+
+ escapeHTML: function() {
+ var self = arguments.callee;
+ self.text.data = this;
+ return self.div.innerHTML;
+ },
+
+ unescapeHTML: function() {
+ var div = new Element('div');
+ div.innerHTML = this.stripTags();
+ return div.childNodes[0] ? (div.childNodes.length > 1 ?
+ $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
+ div.childNodes[0].nodeValue) : '';
+ },
+
+ toQueryParams: function(separator) {
+ var match = this.strip().match(/([^?#]*)(#.*)?$/);
+ if (!match) return { };
+
+ return match[1].split(separator || '&').inject({ }, function(hash, pair) {
+ if ((pair = pair.split('='))[0]) {
+ var key = decodeURIComponent(pair.shift());
+ var value = pair.length > 1 ? pair.join('=') : pair[0];
+ if (value != undefined) value = decodeURIComponent(value);
+
+ if (key in hash) {
+ if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
+ hash[key].push(value);
+ }
+ else hash[key] = value;
+ }
+ return hash;
+ });
+ },
+
+ toArray: function() {
+ return this.split('');
+ },
+
+ succ: function() {
+ return this.slice(0, this.length - 1) +
+ String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
+ },
+
+ times: function(count) {
+ return count < 1 ? '' : new Array(count + 1).join(this);
+ },
+
+ camelize: function() {
+ var parts = this.split('-'), len = parts.length;
+ if (len == 1) return parts[0];
+
+ var camelized = this.charAt(0) == '-'
+ ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
+ : parts[0];
+
+ for (var i = 1; i < len; i++)
+ camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
+
+ return camelized;
+ },
+
+ capitalize: function() {
+ return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
+ },
+
+ underscore: function() {
+ return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
+ },
+
+ dasherize: function() {
+ return this.gsub(/_/,'-');
+ },
+
+ inspect: function(useDoubleQuotes) {
+ var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
+ var character = String.specialChar[match[0]];
+ return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
+ });
+ if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
+ return "'" + escapedString.replace(/'/g, '\\\'') + "'";
+ },
+
+ toJSON: function() {
+ return this.inspect(true);
+ },
+
+ unfilterJSON: function(filter) {
+ return this.sub(filter || Prototype.JSONFilter, '#{1}');
+ },
+
+ isJSON: function() {
+ var str = this;
+ if (str.blank()) return false;
+ str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
+ return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
+ },
+
+ evalJSON: function(sanitize) {
+ var json = this.unfilterJSON();
+ try {
+ if (!sanitize || json.isJSON()) return eval('(' + json + ')');
+ } catch (e) { }
+ throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
+ },
+
+ include: function(pattern) {
+ return this.indexOf(pattern) > -1;
+ },
+
+ startsWith: function(pattern) {
+ return this.indexOf(pattern) === 0;
+ },
+
+ endsWith: function(pattern) {
+ var d = this.length - pattern.length;
+ return d >= 0 && this.lastIndexOf(pattern) === d;
+ },
+
+ empty: function() {
+ return this == '';
+ },
+
+ blank: function() {
+ return /^\s*$/.test(this);
+ },
+
+ interpolate: function(object, pattern) {
+ return new Template(this, pattern).evaluate(object);
+ }
+});
+
+if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
+ escapeHTML: function() {
+ return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
+ },
+ unescapeHTML: function() {
+ return this.stripTags().replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
+ }
+});
+
+String.prototype.gsub.prepareReplacement = function(replacement) {
+ if (Object.isFunction(replacement)) return replacement;
+ var template = new Template(replacement);
+ return function(match) { return template.evaluate(match) };
+};
+
+String.prototype.parseQuery = String.prototype.toQueryParams;
+
+Object.extend(String.prototype.escapeHTML, {
+ div: document.createElement('div'),
+ text: document.createTextNode('')
+});
+
+String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text);
+
+var Template = Class.create({
+ initialize: function(template, pattern) {
+ this.template = template.toString();
+ this.pattern = pattern || Template.Pattern;
+ },
+
+ evaluate: function(object) {
+ if (Object.isFunction(object.toTemplateReplacements))
+ object = object.toTemplateReplacements();
+
+ return this.template.gsub(this.pattern, function(match) {
+ if (object == null) return '';
+
+ var before = match[1] || '';
+ if (before == '\\') return match[2];
+
+ var ctx = object, expr = match[3];
+ var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
+ match = pattern.exec(expr);
+ if (match == null) return before;
+
+ while (match != null) {
+ var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1];
+ ctx = ctx[comp];
+ if (null == ctx || '' == match[3]) break;
+ expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
+ match = pattern.exec(expr);
+ }
+
+ return before + String.interpret(ctx);
+ });
+ }
+});
+Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
+
+var $break = { };
+
+var Enumerable = {
+ each: function(iterator, context) {
+ var index = 0;
+ try {
+ this._each(function(value) {
+ iterator.call(context, value, index++);
+ });
+ } catch (e) {
+ if (e != $break) throw e;
+ }
+ return this;
+ },
+
+ eachSlice: function(number, iterator, context) {
+ var index = -number, slices = [], array = this.toArray();
+ if (number < 1) return array;
+ while ((index += number) < array.length)
+ slices.push(array.slice(index, index+number));
+ return slices.collect(iterator, context);
+ },
+
+ all: function(iterator, context) {
+ iterator = iterator || Prototype.K;
+ var result = true;
+ this.each(function(value, index) {
+ result = result && !!iterator.call(context, value, index);
+ if (!result) throw $break;
+ });
+ return result;
+ },
+
+ any: function(iterator, context) {
+ iterator = iterator || Prototype.K;
+ var result = false;
+ this.each(function(value, index) {
+ if (result = !!iterator.call(context, value, index))
+ throw $break;
+ });
+ return result;
+ },
+
+ collect: function(iterator, context) {
+ iterator = iterator || Prototype.K;
+ var results = [];
+ this.each(function(value, index) {
+ results.push(iterator.call(context, value, index));
+ });
+ return results;
+ },
+
+ detect: function(iterator, context) {
+ var result;
+ this.each(function(value, index) {
+ if (iterator.call(context, value, index)) {
+ result = value;
+ throw $break;
+ }
+ });
+ return result;
+ },
+
+ findAll: function(iterator, context) {
+ var results = [];
+ this.each(function(value, index) {
+ if (iterator.call(context, value, index))
+ results.push(value);
+ });
+ return results;
+ },
+
+ grep: function(filter, iterator, context) {
+ iterator = iterator || Prototype.K;
+ var results = [];
+
+ if (Object.isString(filter))
+ filter = new RegExp(filter);
+
+ this.each(function(value, index) {
+ if (filter.match(value))
+ results.push(iterator.call(context, value, index));
+ });
+ return results;
+ },
+
+ include: function(object) {
+ if (Object.isFunction(this.indexOf))
+ if (this.indexOf(object) != -1) return true;
+
+ var found = false;
+ this.each(function(value) {
+ if (value == object) {
+ found = true;
+ throw $break;
+ }
+ });
+ return found;
+ },
+
+ inGroupsOf: function(number, fillWith) {
+ fillWith = Object.isUndefined(fillWith) ? null : fillWith;
+ return this.eachSlice(number, function(slice) {
+ while(slice.length < number) slice.push(fillWith);
+ return slice;
+ });
+ },
+
+ inject: function(memo, iterator, context) {
+ this.each(function(value, index) {
+ memo = iterator.call(context, memo, value, index);
+ });
+ return memo;
+ },
+
+ invoke: function(method) {
+ var args = $A(arguments).slice(1);
+ return this.map(function(value) {
+ return value[method].apply(value, args);
+ });
+ },
+
+ max: function(iterator, context) {
+ iterator = iterator || Prototype.K;
+ var result;
+ this.each(function(value, index) {
+ value = iterator.call(context, value, index);
+ if (result == null || value >= result)
+ result = value;
+ });
+ return result;
+ },
+
+ min: function(iterator, context) {
+ iterator = iterator || Prototype.K;
+ var result;
+ this.each(function(value, index) {
+ value = iterator.call(context, value, index);
+ if (result == null || value < result)
+ result = value;
+ });
+ return result;
+ },
+
+ partition: function(iterator, context) {
+ iterator = iterator || Prototype.K;
+ var trues = [], falses = [];
+ this.each(function(value, index) {
+ (iterator.call(context, value, index) ?
+ trues : falses).push(value);
+ });
+ return [trues, falses];
+ },
+
+ pluck: function(property) {
+ var results = [];
+ this.each(function(value) {
+ results.push(value[property]);
+ });
+ return results;
+ },
+
+ reject: function(iterator, context) {
+ var results = [];
+ this.each(function(value, index) {
+ if (!iterator.call(context, value, index))
+ results.push(value);
+ });
+ return results;
+ },
+
+ sortBy: function(iterator, context) {
+ return this.map(function(value, index) {
+ return {
+ value: value,
+ criteria: iterator.call(context, value, index)
+ };
+ }).sort(function(left, right) {
+ var a = left.criteria, b = right.criteria;
+ return a < b ? -1 : a > b ? 1 : 0;
+ }).pluck('value');
+ },
+
+ toArray: function() {
+ return this.map();
+ },
+
+ zip: function() {
+ var iterator = Prototype.K, args = $A(arguments);
+ if (Object.isFunction(args.last()))
+ iterator = args.pop();
+
+ var collections = [this].concat(args).map($A);
+ return this.map(function(value, index) {
+ return iterator(collections.pluck(index));
+ });
+ },
+
+ size: function() {
+ return this.toArray().length;
+ },
+
+ inspect: function() {
+ return '#<Enumerable:' + this.toArray().inspect() + '>';
+ }
+};
+
+Object.extend(Enumerable, {
+ map: Enumerable.collect,
+ find: Enumerable.detect,
+ select: Enumerable.findAll,
+ filter: Enumerable.findAll,
+ member: Enumerable.include,
+ entries: Enumerable.toArray,
+ every: Enumerable.all,
+ some: Enumerable.any
+});
+function $A(iterable) {
+ if (!iterable) return [];
+ if (iterable.toArray) return iterable.toArray();
+ var length = iterable.length || 0, results = new Array(length);
+ while (length--) results[length] = iterable[length];
+ return results;
+}
+
+if (Prototype.Browser.WebKit) {
+ $A = function(iterable) {
+ if (!iterable) return [];
+ // In Safari, only use the `toArray` method if it's not a NodeList.
+ // A NodeList is a function, has an function `item` property, and a numeric
+ // `length` property. Adapted from Google Doctype.
+ if (!(typeof iterable === 'function' && typeof iterable.length ===
+ 'number' && typeof iterable.item === 'function') && iterable.toArray)
+ return iterable.toArray();
+ var length = iterable.length || 0, results = new Array(length);
+ while (length--) results[length] = iterable[length];
+ return results;
+ };
+}
+
+Array.from = $A;
+
+Object.extend(Array.prototype, Enumerable);
+
+if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse;
+
+Object.extend(Array.prototype, {
+ _each: function(iterator) {
+ for (var i = 0, length = this.length; i < length; i++)
+ iterator(this[i]);
+ },
+
+ clear: function() {
+ this.length = 0;
+ return this;
+ },
+
+ first: function() {
+ return this[0];
+ },
+
+ last: function() {
+ return this[this.length - 1];
+ },
+
+ compact: function() {
+ return this.select(function(value) {
+ return value != null;
+ });
+ },
+
+ flatten: function() {
+ return this.inject([], function(array, value) {
+ return array.concat(Object.isArray(value) ?
+ value.flatten() : [value]);
+ });
+ },
+
+ without: function() {
+ var values = $A(arguments);
+ return this.select(function(value) {
+ return !values.include(value);
+ });
+ },
+
+ reverse: function(inline) {
+ return (inline !== false ? this : this.toArray())._reverse();
+ },
+
+ reduce: function() {
+ return this.length > 1 ? this : this[0];
+ },
+
+ uniq: function(sorted) {
+ return this.inject([], function(array, value, index) {
+ if (0 == index || (sorted ? array.last() != value : !array.include(value)))
+ array.push(value);
+ return array;
+ });
+ },
+
+ intersect: function(array) {
+ return this.uniq().findAll(function(item) {
+ return array.detect(function(value) { return item === value });
+ });
+ },
+
+ clone: function() {
+ return [].concat(this);
+ },
+
+ size: function() {
+ return this.length;
+ },
+
+ inspect: function() {
+ return '[' + this.map(Object.inspect).join(', ') + ']';
+ },
+
+ toJSON: function() {
+ var results = [];
+ this.each(function(object) {
+ var value = Object.toJSON(object);
+ if (!Object.isUndefined(value)) results.push(value);
+ });
+ return '[' + results.join(', ') + ']';
+ }
+});
+
+// use native browser JS 1.6 implementation if available
+if (Object.isFunction(Array.prototype.forEach))
+ Array.prototype._each = Array.prototype.forEach;
+
+if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) {
+ i || (i = 0);
+ var length = this.length;
+ if (i < 0) i = length + i;
+ for (; i < length; i++)
+ if (this[i] === item) return i;
+ return -1;
+};
+
+if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) {
+ i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
+ var n = this.slice(0, i).reverse().indexOf(item);
+ return (n < 0) ? n : i - n - 1;
+};
+
+Array.prototype.toArray = Array.prototype.clone;
+
+function $w(string) {
+ if (!Object.isString(string)) return [];
+ string = string.strip();
+ return string ? string.split(/\s+/) : [];
+}
+
+if (Prototype.Browser.Opera){
+ Array.prototype.concat = function() {
+ var array = [];
+ for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);
+ for (var i = 0, length = arguments.length; i < length; i++) {
+ if (Object.isArray(arguments[i])) {
+ for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
+ array.push(arguments[i][j]);
+ } else {
+ array.push(arguments[i]);
+ }
+ }
+ return array;
+ };
+}
+Object.extend(Number.prototype, {
+ toColorPart: function() {
+ return this.toPaddedString(2, 16);
+ },
+
+ succ: function() {
+ return this + 1;
+ },
+
+ times: function(iterator, context) {
+ $R(0, this, true).each(iterator, context);
+ return this;
+ },
+
+ toPaddedString: function(length, radix) {
+ var string = this.toString(radix || 10);
+ return '0'.times(length - string.length) + string;
+ },
+
+ toJSON: function() {
+ return isFinite(this) ? this.toString() : 'null';
+ }
+});
+
+$w('abs round ceil floor').each(function(method){
+ Number.prototype[method] = Math[method].methodize();
+});
+function $H(object) {
+ return new Hash(object);
+};
+
+var Hash = Class.create(Enumerable, (function() {
+
+ function toQueryPair(key, value) {
+ if (Object.isUndefined(value)) return key;
+ return key + '=' + encodeURIComponent(String.interpret(value));
+ }
+
+ return {
+ initialize: function(object) {
+ this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
+ },
+
+ _each: function(iterator) {
+ for (var key in this._object) {
+ var value = this._object[key], pair = [key, value];
+ pair.key = key;
+ pair.value = value;
+ iterator(pair);
+ }
+ },
+
+ set: function(key, value) {
+ return this._object[key] = value;
+ },
+
+ get: function(key) {
+ // simulating poorly supported hasOwnProperty
+ if (this._object[key] !== Object.prototype[key])
+ return this._object[key];
+ },
+
+ unset: function(key) {
+ var value = this._object[key];
+ delete this._object[key];
+ return value;
+ },
+
+ toObject: function() {
+ return Object.clone(this._object);
+ },
+
+ keys: function() {
+ return this.pluck('key');
+ },
+
+ values: function() {
+ return this.pluck('value');
+ },
+
+ index: function(value) {
+ var match = this.detect(function(pair) {
+ return pair.value === value;
+ });
+ return match && match.key;
+ },
+
+ merge: function(object) {
+ return this.clone().update(object);
+ },
+
+ update: function(object) {
+ return new Hash(object).inject(this, function(result, pair) {
+ result.set(pair.key, pair.value);
+ return result;
+ });
+ },
+
+ toQueryString: function() {
+ return this.inject([], function(results, pair) {
+ var key = encodeURIComponent(pair.key), values = pair.value;
+
+ if (values && typeof values == 'object') {
+ if (Object.isArray(values))
+ return results.concat(values.map(toQueryPair.curry(key)));
+ } else results.push(toQueryPair(key, values));
+ return results;
+ }).join('&');
+ },
+
+ inspect: function() {
+ return '#<Hash:{' + this.map(function(pair) {
+ return pair.map(Object.inspect).join(': ');
+ }).join(', ') + '}>';
+ },
+
+ toJSON: function() {
+ return Object.toJSON(this.toObject());
+ },
+
+ clone: function() {
+ return new Hash(this);
+ }
+ }
+})());
+
+Hash.prototype.toTemplateReplacements = Hash.prototype.toObject;
+Hash.from = $H;
+var ObjectRange = Class.create(Enumerable, {
+ initialize: function(start, end, exclusive) {
+ this.start = start;
+ this.end = end;
+ this.exclusive = exclusive;
+ },
+
+ _each: function(iterator) {
+ var value = this.start;
+ while (this.include(value)) {
+ iterator(value);
+ value = value.succ();
+ }
+ },
+
+ include: function(value) {
+ if (value < this.start)
+ return false;
+ if (this.exclusive)
+ return value < this.end;
+ return value <= this.end;
+ }
+});
+
+var $R = function(start, end, exclusive) {
+ return new ObjectRange(start, end, exclusive);
+};
+
+var Ajax = {
+ getTransport: function() {
+ return Try.these(
+ function() {return new XMLHttpRequest()},
+ function() {return new ActiveXObject('Msxml2.XMLHTTP')},
+ function() {return new ActiveXObject('Microsoft.XMLHTTP')}
+ ) || false;
+ },
+
+ activeRequestCount: 0
+};
+
+Ajax.Responders = {
+ responders: [],
+
+ _each: function(iterator) {
+ this.responders._each(iterator);
+ },
+
+ register: function(responder) {
+ if (!this.include(responder))
+ this.responders.push(responder);
+ },
+
+ unregister: function(responder) {
+ this.responders = this.responders.without(responder);
+ },
+
+ dispatch: function(callback, request, transport, json) {
+ this.each(function(responder) {
+ if (Object.isFunction(responder[callback])) {
+ try {
+ responder[callback].apply(responder, [request, transport, json]);
+ } catch (e) { }
+ }
+ });
+ }
+};
+
+Object.extend(Ajax.Responders, Enumerable);
+
+Ajax.Responders.register({
+ onCreate: function() { Ajax.activeRequestCount++ },
+ onComplete: function() { Ajax.activeRequestCount-- }
+});
+
+Ajax.Base = Class.create({
+ initialize: function(options) {
+ this.options = {
+ method: 'post',
+ asynchronous: true,
+ contentType: 'application/x-www-form-urlencoded',
+ encoding: 'UTF-8',
+ parameters: '',
+ evalJSON: true,
+ evalJS: true
+ };
+ Object.extend(this.options, options || { });
+
+ this.options.method = this.options.method.toLowerCase();
+
+ if (Object.isString(this.options.parameters))
+ this.options.parameters = this.options.parameters.toQueryParams();
+ else if (Object.isHash(this.options.parameters))
+ this.options.parameters = this.options.parameters.toObject();
+ }
+});
+
+Ajax.Request = Class.create(Ajax.Base, {
+ _complete: false,
+
+ initialize: function($super, url, options) {
+ $super(options);
+ this.transport = Ajax.getTransport();
+ this.request(url);
+ },
+
+ request: function(url) {
+ this.url = url;
+ this.method = this.options.method;
+ var params = Object.clone(this.options.parameters);
+
+ if (!['get', 'post'].include(this.method)) {
+ // simulate other verbs over post
+ params['_method'] = this.method;
+ this.method = 'post';
+ }
+
+ this.parameters = params;
+
+ if (params = Object.toQueryString(params)) {
+ // when GET, append parameters to URL
+ if (this.method == 'get')
+ this.url += (this.url.include('?') ? '&' : '?') + params;
+ else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
+ params += '&_=';
+ }
+
+ try {
+ var response = new Ajax.Response(this);
+ if (this.options.onCreate) this.options.onCreate(response);
+ Ajax.Responders.dispatch('onCreate', this, response);
+
+ this.transport.open(this.method.toUpperCase(), this.url,
+ this.options.asynchronous);
+
+ if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
+
+ this.transport.onreadystatechange = this.onStateChange.bind(this);
+ this.setRequestHeaders();
+
+ this.body = this.method == 'post' ? (this.options.postBody || params) : null;
+ this.transport.send(this.body);
+
+ /* Force Firefox to handle ready state 4 for synchronous requests */
+ if (!this.options.asynchronous && this.transport.overrideMimeType)
+ this.onStateChange();
+
+ }
+ catch (e) {
+ this.dispatchException(e);
+ }
+ },
+
+ onStateChange: function() {
+ var readyState = this.transport.readyState;
+ if (readyState > 1 && !((readyState == 4) && this._complete))
+ this.respondToReadyState(this.transport.readyState);
+ },
+
+ setRequestHeaders: function() {
+ var headers = {
+ 'X-Requested-With': 'XMLHttpRequest',
+ 'X-Prototype-Version': Prototype.Version,
+ 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
+ };
+
+ if (this.method == 'post') {
+ headers['Content-type'] = this.options.contentType +
+ (this.options.encoding ? '; charset=' + this.options.encoding : '');
+
+ /* Force "Connection: close" for older Mozilla browsers to work
+ * around a bug where XMLHttpRequest sends an incorrect
+ * Content-length header. See Mozilla Bugzilla #246651.
+ */
+ if (this.transport.overrideMimeType &&
+ (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
+ headers['Connection'] = 'close';
+ }
+
+ // user-defined headers
+ if (typeof this.options.requestHeaders == 'object') {
+ var extras = this.options.requestHeaders;
+
+ if (Object.isFunction(extras.push))
+ for (var i = 0, length = extras.length; i < length; i += 2)
+ headers[extras[i]] = extras[i+1];
+ else
+ $H(extras).each(function(pair) { headers[pair.key] = pair.value });
+ }
+
+ for (var name in headers)
+ this.transport.setRequestHeader(name, headers[name]);
+ },
+
+ success: function() {
+ var status = this.getStatus();
+ return !status || (status >= 200 && status < 300);
+ },
+
+ getStatus: function() {
+ try {
+ return this.transport.status || 0;
+ } catch (e) { return 0 }
+ },
+
+ respondToReadyState: function(readyState) {
+ var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
+
+ if (state == 'Complete') {
+ try {
+ this._complete = true;
+ (this.options['on' + response.status]
+ || this.options['on' + (this.success() ? 'Success' : 'Failure')]
+ || Prototype.emptyFunction)(response, response.headerJSON);
+ } catch (e) {
+ this.dispatchException(e);
+ }
+
+ var contentType = response.getHeader('Content-type');
+ if (this.options.evalJS == 'force'
+ || (this.options.evalJS && this.isSameOrigin() && contentType
+ && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
+ this.evalResponse();
+ }
+
+ try {
+ (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
+ Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
+ } catch (e) {
+ this.dispatchException(e);
+ }
+
+ if (state == 'Complete') {
+ // avoid memory leak in MSIE: clean up
+ this.transport.onreadystatechange = Prototype.emptyFunction;
+ }
+ },
+
+ isSameOrigin: function() {
+ var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
+ return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
+ protocol: location.protocol,
+ domain: document.domain,
+ port: location.port ? ':' + location.port : ''
+ }));
+ },
+
+ getHeader: function(name) {
+ try {
+ return this.transport.getResponseHeader(name) || null;
+ } catch (e) { return null }
+ },
+
+ evalResponse: function() {
+ try {
+ return eval((this.transport.responseText || '').unfilterJSON());
+ } catch (e) {
+ this.dispatchException(e);
+ }
+ },
+
+ dispatchException: function(exception) {
+ (this.options.onException || Prototype.emptyFunction)(this, exception);
+ Ajax.Responders.dispatch('onException', this, exception);
+ }
+});
+
+Ajax.Request.Events =
+ ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
+
+Ajax.Response = Class.create({
+ initialize: function(request){
+ this.request = request;
+ var transport = this.transport = request.transport,
+ readyState = this.readyState = transport.readyState;
+
+ if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
+ this.status = this.getStatus();
+ this.statusText = this.getStatusText();
+ this.responseText = String.interpret(transport.responseText);
+ this.headerJSON = this._getHeaderJSON();
+ }
+
+ if(readyState == 4) {
+ var xml = transport.responseXML;
+ this.responseXML = Object.isUndefined(xml) ? null : xml;
+ this.responseJSON = this._getResponseJSON();
+ }
+ },
+
+ status: 0,
+ statusText: '',
+
+ getStatus: Ajax.Request.prototype.getStatus,
+
+ getStatusText: function() {
+ try {
+ return this.transport.statusText || '';
+ } catch (e) { return '' }
+ },
+
+ getHeader: Ajax.Request.prototype.getHeader,
+
+ getAllHeaders: function() {
+ try {
+ return this.getAllResponseHeaders();
+ } catch (e) { return null }
+ },
+
+ getResponseHeader: function(name) {
+ return this.transport.getResponseHeader(name);
+ },
+
+ getAllResponseHeaders: function() {
+ return this.transport.getAllResponseHeaders();
+ },
+
+ _getHeaderJSON: function() {
+ var json = this.getHeader('X-JSON');
+ if (!json) return null;
+ json = decodeURIComponent(escape(json));
+ try {
+ return json.evalJSON(this.request.options.sanitizeJSON ||
+ !this.request.isSameOrigin());
+ } catch (e) {
+ this.request.dispatchException(e);
+ }
+ },
+
+ _getResponseJSON: function() {
+ var options = this.request.options;
+ if (!options.evalJSON || (options.evalJSON != 'force' &&
+ !(this.getHeader('Content-type') || '').include('application/json')) ||
+ this.responseText.blank())
+ return null;
+ try {
+ return this.responseText.evalJSON(options.sanitizeJSON ||
+ !this.request.isSameOrigin());
+ } catch (e) {
+ this.request.dispatchException(e);
+ }
+ }
+});
+
+Ajax.Updater = Class.create(Ajax.Request, {
+ initialize: function($super, container, url, options) {
+ this.container = {
+ success: (container.success || container),
+ failure: (container.failure || (container.success ? null : container))
+ };
+
+ options = Object.clone(options);
+ var onComplete = options.onComplete;
+ options.onComplete = (function(response, json) {
+ this.updateContent(response.responseText);
+ if (Object.isFunction(onComplete)) onComplete(response, json);
+ }).bind(this);
+
+ $super(url, options);
+ },
+
+ updateContent: function(responseText) {
+ var receiver = this.container[this.success() ? 'success' : 'failure'],
+ options = this.options;
+
+ if (!options.evalScripts) responseText = responseText.stripScripts();
+
+ if (receiver = $(receiver)) {
+ if (options.insertion) {
+ if (Object.isString(options.insertion)) {
+ var insertion = { }; insertion[options.insertion] = responseText;
+ receiver.insert(insertion);
+ }
+ else options.insertion(receiver, responseText);
+ }
+ else receiver.update(responseText);
+ }
+ }
+});
+
+Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
+ initialize: function($super, container, url, options) {
+ $super(options);
+ this.onComplete = this.options.onComplete;
+
+ this.frequency = (this.options.frequency || 2);
+ this.decay = (this.options.decay || 1);
+
+ this.updater = { };
+ this.container = container;
+ this.url = url;
+
+ this.start();
+ },
+
+ start: function() {
+ this.options.onComplete = this.updateComplete.bind(this);
+ this.onTimerEvent();
+ },
+
+ stop: function() {
+ this.updater.options.onComplete = undefined;
+ clearTimeout(this.timer);
+ (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
+ },
+
+ updateComplete: function(response) {
+ if (this.options.decay) {
+ this.decay = (response.responseText == this.lastText ?
+ this.decay * this.options.decay : 1);
+
+ this.lastText = response.responseText;
+ }
+ this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
+ },
+
+ onTimerEvent: function() {
+ this.updater = new Ajax.Updater(this.container, this.url, this.options);
+ }
+});
+function $(element) {
+ if (arguments.length > 1) {
+ for (var i = 0, elements = [], length = arguments.length; i < length; i++)
+ elements.push($(arguments[i]));
+ return elements;
+ }
+ if (Object.isString(element))
+ element = document.getElementById(element);
+ return Element.extend(element);
+}
+
+if (Prototype.BrowserFeatures.XPath) {
+ document._getElementsByXPath = function(expression, parentElement) {
+ var results = [];
+ var query = document.evaluate(expression, $(parentElement) || document,
+ null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ for (var i = 0, length = query.snapshotLength; i < length; i++)
+ results.push(Element.extend(query.snapshotItem(i)));
+ return results;
+ };
+}
+
+/*--------------------------------------------------------------------------*/
+
+if (!window.Node) var Node = { };
+
+if (!Node.ELEMENT_NODE) {
+ // DOM level 2 ECMAScript Language Binding
+ Object.extend(Node, {
+ ELEMENT_NODE: 1,
+ ATTRIBUTE_NODE: 2,
+ TEXT_NODE: 3,
+ CDATA_SECTION_NODE: 4,
+ ENTITY_REFERENCE_NODE: 5,
+ ENTITY_NODE: 6,
+ PROCESSING_INSTRUCTION_NODE: 7,
+ COMMENT_NODE: 8,
+ DOCUMENT_NODE: 9,
+ DOCUMENT_TYPE_NODE: 10,
+ DOCUMENT_FRAGMENT_NODE: 11,
+ NOTATION_NODE: 12
+ });
+}
+
+(function() {
+ var element = this.Element;
+ this.Element = function(tagName, attributes) {
+ attributes = attributes || { };
+ tagName = tagName.toLowerCase();
+ var cache = Element.cache;
+ if (Prototype.Browser.IE && attributes.name) {
+ tagName = '<' + tagName + ' name="' + attributes.name + '">';
+ delete attributes.name;
+ return Element.writeAttribute(document.createElement(tagName), attributes);
+ }
+ if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
+ return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
+ };
+ Object.extend(this.Element, element || { });
+ if (element) this.Element.prototype = element.prototype;
+}).call(window);
+
+Element.cache = { };
+
+Element.Methods = {
+ visible: function(element) {
+ return $(element).style.display != 'none';
+ },
+
+ toggle: function(element) {
+ element = $(element);
+ Element[Element.visible(element) ? 'hide' : 'show'](element);
+ return element;
+ },
+
+ hide: function(element) {
+ element = $(element);
+ element.style.display = 'none';
+ return element;
+ },
+
+ show: function(element) {
+ element = $(element);
+ element.style.display = '';
+ return element;
+ },
+
+ remove: function(element) {
+ element = $(element);
+ element.parentNode.removeChild(element);
+ return element;
+ },
+
+ update: function(element, content) {
+ element = $(element);
+ if (content && content.toElement) content = content.toElement();
+ if (Object.isElement(content)) return element.update().insert(content);
+ content = Object.toHTML(content);
+ element.innerHTML = content.stripScripts();
+ content.evalScripts.bind(content).defer();
+ return element;
+ },
+
+ replace: function(element, content) {
+ element = $(element);
+ if (content && content.toElement) content = content.toElement();
+ else if (!Object.isElement(content)) {
+ content = Object.toHTML(content);
+ var range = element.ownerDocument.createRange();
+ range.selectNode(element);
+ content.evalScripts.bind(content).defer();
+ content = range.createContextualFragment(content.stripScripts());
+ }
+ element.parentNode.replaceChild(content, element);
+ return element;
+ },
+
+ insert: function(element, insertions) {
+ element = $(element);
+
+ if (Object.isString(insertions) || Object.isNumber(insertions) ||
+ Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
+ insertions = {bottom:insertions};
+
+ var content, insert, tagName, childNodes;
+
+ for (var position in insertions) {
+ content = insertions[position];
+ position = position.toLowerCase();
+ insert = Element._insertionTranslations[position];
+
+ if (content && content.toElement) content = content.toElement();
+ if (Object.isElement(content)) {
+ insert(element, content);
+ continue;
+ }
+
+ content = Object.toHTML(content);
+
+ tagName = ((position == 'before' || position == 'after')
+ ? element.parentNode : element).tagName.toUpperCase();
+
+ childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
+
+ if (position == 'top' || position == 'after') childNodes.reverse();
+ childNodes.each(insert.curry(element));
+
+ content.evalScripts.bind(content).defer();
+ }
+
+ return element;
+ },
+
+ wrap: function(element, wrapper, attributes) {
+ element = $(element);
+ if (Object.isElement(wrapper))
+ $(wrapper).writeAttribute(attributes || { });
+ else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
+ else wrapper = new Element('div', wrapper);
+ if (element.parentNode)
+ element.parentNode.replaceChild(wrapper, element);
+ wrapper.appendChild(element);
+ return wrapper;
+ },
+
+ inspect: function(element) {
+ element = $(element);
+ var result = '<' + element.tagName.toLowerCase();
+ $H({'id': 'id', 'className': 'class'}).each(function(pair) {
+ var property = pair.first(), attribute = pair.last();
+ var value = (element[property] || '').toString();
+ if (value) result += ' ' + attribute + '=' + value.inspect(true);
+ });
+ return result + '>';
+ },
+
+ recursivelyCollect: function(element, property) {
+ element = $(element);
+ var elements = [];
+ while (element = element[property])
+ if (element.nodeType == 1)
+ elements.push(Element.extend(element));
+ return elements;
+ },
+
+ ancestors: function(element) {
+ return $(element).recursivelyCollect('parentNode');
+ },
+
+ descendants: function(element) {
+ return $(element).select("*");
+ },
+
+ firstDescendant: function(element) {
+ element = $(element).firstChild;
+ while (element && element.nodeType != 1) element = element.nextSibling;
+ return $(element);
+ },
+
+ immediateDescendants: function(element) {
+ if (!(element = $(element).firstChild)) return [];
+ while (element && element.nodeType != 1) element = element.nextSibling;
+ if (element) return [element].concat($(element).nextSiblings());
+ return [];
+ },
+
+ previousSiblings: function(element) {
+ return $(element).recursivelyCollect('previousSibling');
+ },
+
+ nextSiblings: function(element) {
+ return $(element).recursivelyCollect('nextSibling');
+ },
+
+ siblings: function(element) {
+ element = $(element);
+ return element.previousSiblings().reverse().concat(element.nextSiblings());
+ },
+
+ match: function(element, selector) {
+ if (Object.isString(selector))
+ selector = new Selector(selector);
+ return selector.match($(element));
+ },
+
+ up: function(element, expression, index) {
+ element = $(element);
+ if (arguments.length == 1) return $(element.parentNode);
+ var ancestors = element.ancestors();
+ return Object.isNumber(expression) ? ancestors[expression] :
+ Selector.findElement(ancestors, expression, index);
+ },
+
+ down: function(element, expression, index) {
+ element = $(element);
+ if (arguments.length == 1) return element.firstDescendant();
+ return Object.isNumber(expression) ? element.descendants()[expression] :
+ Element.select(element, expression)[index || 0];
+ },
+
+ previous: function(element, expression, index) {
+ element = $(element);
+ if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
+ var previousSiblings = element.previousSiblings();
+ return Object.isNumber(expression) ? previousSiblings[expression] :
+ Selector.findElement(previousSiblings, expression, index);
+ },
+
+ next: function(element, expression, index) {
+ element = $(element);
+ if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
+ var nextSiblings = element.nextSiblings();
+ return Object.isNumber(expression) ? nextSiblings[expression] :
+ Selector.findElement(nextSiblings, expression, index);
+ },
+
+ select: function() {
+ var args = $A(arguments), element = $(args.shift());
+ return Selector.findChildElements(element, args);
+ },
+
+ adjacent: function() {
+ var args = $A(arguments), element = $(args.shift());
+ return Selector.findChildElements(element.parentNode, args).without(element);
+ },
+
+ identify: function(element) {
+ element = $(element);
+ var id = element.readAttribute('id'), self = arguments.callee;
+ if (id) return id;
+ do { id = 'anonymous_element_' + self.counter++ } while ($(id));
+ element.writeAttribute('id', id);
+ return id;
+ },
+
+ readAttribute: function(element, name) {
+ element = $(element);
+ if (Prototype.Browser.IE) {
+ var t = Element._attributeTranslations.read;
+ if (t.values[name]) return t.values[name](element, name);
+ if (t.names[name]) name = t.names[name];
+ if (name.include(':')) {
+ return (!element.attributes || !element.attributes[name]) ? null :
+ element.attributes[name].value;
+ }
+ }
+ return element.getAttribute(name);
+ },
+
+ writeAttribute: function(element, name, value) {
+ element = $(element);
+ var attributes = { }, t = Element._attributeTranslations.write;
+
+ if (typeof name == 'object') attributes = name;
+ else attributes[name] = Object.isUndefined(value) ? true : value;
+
+ for (var attr in attributes) {
+ name = t.names[attr] || attr;
+ value = attributes[attr];
+ if (t.values[attr]) name = t.values[attr](element, value);
+ if (value === false || value === null)
+ element.removeAttribute(name);
+ else if (value === true)
+ element.setAttribute(name, name);
+ else element.setAttribute(name, value);
+ }
+ return element;
+ },
+
+ getHeight: function(element) {
+ return $(element).getDimensions().height;
+ },
+
+ getWidth: function(element) {
+ return $(element).getDimensions().width;
+ },
+
+ classNames: function(element) {
+ return new Element.ClassNames(element);
+ },
+
+ hasClassName: function(element, className) {
+ if (!(element = $(element))) return;
+ var elementClassName = element.className;
+ return (elementClassName.length > 0 && (elementClassName == className ||
+ new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
+ },
+
+ addClassName: function(element, className) {
+ if (!(element = $(element))) return;
+ if (!element.hasClassName(className))
+ element.className += (element.className ? ' ' : '') + className;
+ return element;
+ },
+
+ removeClassName: function(element, className) {
+ if (!(element = $(element))) return;
+ element.className = element.className.replace(
+ new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
+ return element;
+ },
+
+ toggleClassName: function(element, className) {
+ if (!(element = $(element))) return;
+ return element[element.hasClassName(className) ?
+ 'removeClassName' : 'addClassName'](className);
+ },
+
+ // removes whitespace-only text node children
+ cleanWhitespace: function(element) {
+ element = $(element);
+ var node = element.firstChild;
+ while (node) {
+ var nextNode = node.nextSibling;
+ if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
+ element.removeChild(node);
+ node = nextNode;
+ }
+ return element;
+ },
+
+ empty: function(element) {
+ return $(element).innerHTML.blank();
+ },
+
+ descendantOf: function(element, ancestor) {
+ element = $(element), ancestor = $(ancestor);
+
+ if (element.compareDocumentPosition)
+ return (element.compareDocumentPosition(ancestor) & 8) === 8;
+
+ if (ancestor.contains)
+ return ancestor.contains(element) && ancestor !== element;
+
+ while (element = element.parentNode)
+ if (element == ancestor) return true;
+
+ return false;
+ },
+
+ scrollTo: function(element) {
+ element = $(element);
+ var pos = element.cumulativeOffset();
+ window.scrollTo(pos[0], pos[1]);
+ return element;
+ },
+
+ getStyle: function(element, style) {
+ element = $(element);
+ style = style == 'float' ? 'cssFloat' : style.camelize();
+ var value = element.style[style];
+ if (!value || value == 'auto') {
+ var css = document.defaultView.getComputedStyle(element, null);
+ value = css ? css[style] : null;
+ }
+ if (style == 'opacity') return value ? parseFloat(value) : 1.0;
+ return value == 'auto' ? null : value;
+ },
+
+ getOpacity: function(element) {
+ return $(element).getStyle('opacity');
+ },
+
+ setStyle: function(element, styles) {
+ element = $(element);
+ var elementStyle = element.style, match;
+ if (Object.isString(styles)) {
+ element.style.cssText += ';' + styles;
+ return styles.include('opacity') ?
+ element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
+ }
+ for (var property in styles)
+ if (property == 'opacity') element.setOpacity(styles[property]);
+ else
+ elementStyle[(property == 'float' || property == 'cssFloat') ?
+ (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
+ property] = styles[property];
+
+ return element;
+ },
+
+ setOpacity: function(element, value) {
+ element = $(element);
+ element.style.opacity = (value == 1 || value === '') ? '' :
+ (value < 0.00001) ? 0 : value;
+ return element;
+ },
+
+ getDimensions: function(element) {
+ element = $(element);
+ var display = element.getStyle('display');
+ if (display != 'none' && display != null) // Safari bug
+ return {width: element.offsetWidth, height: element.offsetHeight};
+
+ // All *Width and *Height properties give 0 on elements with display none,
+ // so enable the element temporarily
+ var els = element.style;
+ var originalVisibility = els.visibility;
+ var originalPosition = els.position;
+ var originalDisplay = els.display;
+ els.visibility = 'hidden';
+ els.position = 'absolute';
+ els.display = 'block';
+ var originalWidth = element.clientWidth;
+ var originalHeight = element.clientHeight;
+ els.display = originalDisplay;
+ els.position = originalPosition;
+ els.visibility = originalVisibility;
+ return {width: originalWidth, height: originalHeight};
+ },
+
+ makePositioned: function(element) {
+ element = $(element);
+ var pos = Element.getStyle(element, 'position');
+ if (pos == 'static' || !pos) {
+ element._madePositioned = true;
+ element.style.position = 'relative';
+ // Opera returns the offset relative to the positioning context, when an
+ // element is position relative but top and left have not been defined
+ if (Prototype.Browser.Opera) {
+ element.style.top = 0;
+ element.style.left = 0;
+ }
+ }
+ return element;
+ },
+
+ undoPositioned: function(element) {
+ element = $(element);
+ if (element._madePositioned) {
+ element._madePositioned = undefined;
+ element.style.position =
+ element.style.top =
+ element.style.left =
+ element.style.bottom =
+ element.style.right = '';
+ }
+ return element;
+ },
+
+ makeClipping: function(element) {
+ element = $(element);
+ if (element._overflow) return element;
+ element._overflow = Element.getStyle(element, 'overflow') || 'auto';
+ if (element._overflow !== 'hidden')
+ element.style.overflow = 'hidden';
+ return element;
+ },
+
+ undoClipping: function(element) {
+ element = $(element);
+ if (!element._overflow) return element;
+ element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
+ element._overflow = null;
+ return element;
+ },
+
+ cumulativeOffset: function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+ element = element.offsetParent;
+ } while (element);
+ return Element._returnOffset(valueL, valueT);
+ },
+
+ positionedOffset: function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+ element = element.offsetParent;
+ if (element) {
+ if (element.tagName.toUpperCase() == 'BODY') break;
+ var p = Element.getStyle(element, 'position');
+ if (p !== 'static') break;
+ }
+ } while (element);
+ return Element._returnOffset(valueL, valueT);
+ },
+
+ absolutize: function(element) {
+ element = $(element);
+ if (element.getStyle('position') == 'absolute') return element;
+ // Position.prepare(); // To be done manually by Scripty when it needs it.
+
+ var offsets = element.positionedOffset();
+ var top = offsets[1];
+ var left = offsets[0];
+ var width = element.clientWidth;
+ var height = element.clientHeight;
+
+ element._originalLeft = left - parseFloat(element.style.left || 0);
+ element._originalTop = top - parseFloat(element.style.top || 0);
+ element._originalWidth = element.style.width;
+ element._originalHeight = element.style.height;
+
+ element.style.position = 'absolute';
+ element.style.top = top + 'px';
+ element.style.left = left + 'px';
+ element.style.width = width + 'px';
+ element.style.height = height + 'px';
+ return element;
+ },
+
+ relativize: function(element) {
+ element = $(element);
+ if (element.getStyle('position') == 'relative') return element;
+ // Position.prepare(); // To be done manually by Scripty when it needs it.
+
+ element.style.position = 'relative';
+ var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
+ var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
+
+ element.style.top = top + 'px';
+ element.style.left = left + 'px';
+ element.style.height = element._originalHeight;
+ element.style.width = element._originalWidth;
+ return element;
+ },
+
+ cumulativeScrollOffset: function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.scrollTop || 0;
+ valueL += element.scrollLeft || 0;
+ element = element.parentNode;
+ } while (element);
+ return Element._returnOffset(valueL, valueT);
+ },
+
+ getOffsetParent: function(element) {
+ if (element.offsetParent) return $(element.offsetParent);
+ if (element == document.body) return $(element);
+
+ while ((element = element.parentNode) && element != document.body
+ && Object.isElement(element)/* changed by Nick - http://dev.rubyonrails.org/ticket/11007 */)
+ if (Element.getStyle(element, 'position') != 'static')
+ return $(element);
+
+ return $(document.body);
+ },
+
+ viewportOffset: function(forElement) {
+ var valueT = 0, valueL = 0;
+
+ var element = forElement;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+
+ // Safari fix
+ if (element.offsetParent == document.body &&
+ Element.getStyle(element, 'position') == 'absolute') break;
+
+ } while (element = element.offsetParent);
+
+ element = forElement;
+ do {
+ if (!Prototype.Browser.Opera || (element.tagName && (element.tagName.toUpperCase() == 'BODY'))) {
+ valueT -= element.scrollTop || 0;
+ valueL -= element.scrollLeft || 0;
+ }
+ } while (element = element.parentNode);
+
+ return Element._returnOffset(valueL, valueT);
+ },
+
+ clonePosition: function(element, source) {
+ var options = Object.extend({
+ setLeft: true,
+ setTop: true,
+ setWidth: true,
+ setHeight: true,
+ offsetTop: 0,
+ offsetLeft: 0
+ }, arguments[2] || { });
+
+ // find page position of source
+ source = $(source);
+ var p = source.viewportOffset();
+
+ // find coordinate system to use
+ element = $(element);
+ var delta = [0, 0];
+ var parent = null;
+ // delta [0,0] will do fine with position: fixed elements,
+ // position:absolute needs offsetParent deltas
+ if (Element.getStyle(element, 'position') == 'absolute') {
+ parent = element.getOffsetParent();
+ delta = parent.viewportOffset();
+ }
+
+ // correct by body offsets (fixes Safari)
+ if (parent == document.body) {
+ delta[0] -= document.body.offsetLeft;
+ delta[1] -= document.body.offsetTop;
+ }
+
+ // set position
+ if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
+ if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
+ if (options.setWidth) element.style.width = source.offsetWidth + 'px';
+ if (options.setHeight) element.style.height = source.offsetHeight + 'px';
+ return element;
+ }
+};
+
+Element.Methods.identify.counter = 1;
+
+Object.extend(Element.Methods, {
+ getElementsBySelector: Element.Methods.select,
+ childElements: Element.Methods.immediateDescendants
+});
+
+Element._attributeTranslations = {
+ write: {
+ names: {
+ className: 'class',
+ htmlFor: 'for'
+ },
+ values: { }
+ }
+};
+
+if (Prototype.Browser.Opera) {
+ Element.Methods.getStyle = Element.Methods.getStyle.wrap(
+ function(proceed, element, style) {
+ switch (style) {
+ case 'left': case 'top': case 'right': case 'bottom':
+ if (proceed(element, 'position') === 'static') return null;
+ case 'height': case 'width':
+ // returns '0px' for hidden elements; we want it to return null
+ if (!Element.visible(element)) return null;
+
+ // returns the border-box dimensions rather than the content-box
+ // dimensions, so we subtract padding and borders from the value
+ var dim = parseInt(proceed(element, style), 10);
+
+ if (dim !== element['offset' + style.capitalize()])
+ return dim + 'px';
+
+ var properties;
+ if (style === 'height') {
+ properties = ['border-top-width', 'padding-top',
+ 'padding-bottom', 'border-bottom-width'];
+ }
+ else {
+ properties = ['border-left-width', 'padding-left',
+ 'padding-right', 'border-right-width'];
+ }
+ return properties.inject(dim, function(memo, property) {
+ var val = proceed(element, property);
+ return val === null ? memo : memo - parseInt(val, 10);
+ }) + 'px';
+ default: return proceed(element, style);
+ }
+ }
+ );
+
+ Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
+ function(proceed, element, attribute) {
+ if (attribute === 'title') return element.title;
+ return proceed(element, attribute);
+ }
+ );
+}
+
+else if (Prototype.Browser.IE) {
+ // IE doesn't report offsets correctly for static elements, so we change them
+ // to "relative" to get the values, then change them back.
+ Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
+ function(proceed, element) {
+ element = $(element);
+ // IE throws an error if element is not in document
+ try { element.offsetParent }
+ catch(e) { return $(document.body) }
+ var position = element.getStyle('position');
+ if (position !== 'static') return proceed(element);
+ element.setStyle({ position: 'relative' });
+ var value = proceed(element);
+ element.setStyle({ position: position });
+ return value;
+ }
+ );
+
+ $w('positionedOffset viewportOffset').each(function(method) {
+ Element.Methods[method] = Element.Methods[method].wrap(
+ function(proceed, element) {
+ element = $(element);
+ try { element.offsetParent }
+ catch(e) { return Element._returnOffset(0,0) }
+ var position = element.getStyle('position');
+ if (position !== 'static') return proceed(element);
+ // Trigger hasLayout on the offset parent so that IE6 reports
+ // accurate offsetTop and offsetLeft values for position: fixed.
+ var offsetParent = element.getOffsetParent();
+ if (offsetParent && offsetParent.getStyle('position') === 'fixed')
+ offsetParent.setStyle({ zoom: 1 });
+ element.setStyle({ position: 'relative' });
+ var value = proceed(element);
+ element.setStyle({ position: position });
+ return value;
+ }
+ );
+ });
+
+ Element.Methods.cumulativeOffset = Element.Methods.cumulativeOffset.wrap(
+ function(proceed, element) {
+ try { element.offsetParent }
+ catch(e) { return Element._returnOffset(0,0) }
+ return proceed(element);
+ }
+ );
+
+ Element.Methods.getStyle = function(element, style) {
+ element = $(element);
+ style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
+ var value = element.style[style];
+ if (!value && element.currentStyle) value = element.currentStyle[style];
+
+ if (style == 'opacity') {
+ if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
+ if (value[1]) return parseFloat(value[1]) / 100;
+ return 1.0;
+ }
+
+ if (value == 'auto') {
+ if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
+ return element['offset' + style.capitalize()] + 'px';
+ return null;
+ }
+ return value;
+ };
+
+ Element.Methods.setOpacity = function(element, value) {
+ function stripAlpha(filter){
+ return filter.replace(/alpha\([^\)]*\)/gi,'');
+ }
+ element = $(element);
+ var currentStyle = element.currentStyle;
+ if ((currentStyle && !currentStyle.hasLayout) ||
+ (!currentStyle && element.style.zoom == 'normal'))
+ element.style.zoom = 1;
+
+ var filter = element.getStyle('filter'), style = element.style;
+ if (value == 1 || value === '') {
+ (filter = stripAlpha(filter)) ?
+ style.filter = filter : style.removeAttribute('filter');
+ return element;
+ } else if (value < 0.00001) value = 0;
+ style.filter = stripAlpha(filter) +
+ 'alpha(opacity=' + (value * 100) + ')';
+ return element;
+ };
+
+ Element._attributeTranslations = {
+ read: {
+ names: {
+ 'class': 'className',
+ 'for': 'htmlFor'
+ },
+ values: {
+ _getAttr: function(element, attribute) {
+ return element.getAttribute(attribute, 2);
+ },
+ _getAttrNode: function(element, attribute) {
+ var node = element.getAttributeNode(attribute);
+ return node ? node.value : "";
+ },
+ _getEv: function(element, attribute) {
+ attribute = element.getAttribute(attribute);
+ return attribute ? attribute.toString().slice(23, -2) : null;
+ },
+ _flag: function(element, attribute) {
+ return $(element).hasAttribute(attribute) ? attribute : null;
+ },
+ style: function(element) {
+ return element.style.cssText.toLowerCase();
+ },
+ title: function(element) {
+ return element.title;
+ }
+ }
+ }
+ };
+
+ Element._attributeTranslations.write = {
+ names: Object.extend({
+ cellpadding: 'cellPadding',
+ cellspacing: 'cellSpacing'
+ }, Element._attributeTranslations.read.names),
+ values: {
+ checked: function(element, value) {
+ element.checked = !!value;
+ },
+
+ style: function(element, value) {
+ element.style.cssText = value ? value : '';
+ }
+ }
+ };
+
+ Element._attributeTranslations.has = {};
+
+ $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
+ 'encType maxLength readOnly longDesc frameBorder').each(function(attr) {
+ Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
+ Element._attributeTranslations.has[attr.toLowerCase()] = attr;
+ });
+
+ (function(v) {
+ Object.extend(v, {
+ href: v._getAttr,
+ src: v._getAttr,
+ type: v._getAttr,
+ action: v._getAttrNode,
+ disabled: v._flag,
+ checked: v._flag,
+ readonly: v._flag,
+ multiple: v._flag,
+ onload: v._getEv,
+ onunload: v._getEv,
+ onclick: v._getEv,
+ ondblclick: v._getEv,
+ onmousedown: v._getEv,
+ onmouseup: v._getEv,
+ onmouseover: v._getEv,
+ onmousemove: v._getEv,
+ onmouseout: v._getEv,
+ onfocus: v._getEv,
+ onblur: v._getEv,
+ onkeypress: v._getEv,
+ onkeydown: v._getEv,
+ onkeyup: v._getEv,
+ onsubmit: v._getEv,
+ onreset: v._getEv,
+ onselect: v._getEv,
+ onchange: v._getEv
+ });
+ })(Element._attributeTranslations.read.values);
+}
+
+else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
+ Element.Methods.setOpacity = function(element, value) {
+ element = $(element);
+ element.style.opacity = (value == 1) ? 0.999999 :
+ (value === '') ? '' : (value < 0.00001) ? 0 : value;
+ return element;
+ };
+}
+
+else if (Prototype.Browser.WebKit) {
+ Element.Methods.setOpacity = function(element, value) {
+ element = $(element);
+ element.style.opacity = (value == 1 || value === '') ? '' :
+ (value < 0.00001) ? 0 : value;
+
+ if (value == 1)
+ if(element.tagName.toUpperCase() == 'IMG' && element.width) {
+ element.width++; element.width--;
+ } else try {
+ var n = document.createTextNode(' ');
+ element.appendChild(n);
+ element.removeChild(n);
+ } catch (e) { }
+
+ return element;
+ };
+
+ // Safari returns margins on body which is incorrect if the child is absolutely
+ // positioned. For performance reasons, redefine Element#cumulativeOffset for
+ // KHTML/WebKit only.
+ Element.Methods.cumulativeOffset = function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+ if (element.offsetParent == document.body)
+ if (Element.getStyle(element, 'position') == 'absolute') break;
+
+ element = element.offsetParent;
+ } while (element);
+
+ return Element._returnOffset(valueL, valueT);
+ };
+}
+
+if (Prototype.Browser.IE || Prototype.Browser.Opera) {
+ // IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements
+ Element.Methods.update = function(element, content) {
+ element = $(element);
+
+ if (content && content.toElement) content = content.toElement();
+ if (Object.isElement(content)) return element.update().insert(content);
+
+ content = Object.toHTML(content);
+ var tagName = element.tagName.toUpperCase();
+
+ if (tagName in Element._insertionTranslations.tags) {
+ $A(element.childNodes).each(function(node) { element.removeChild(node) });
+ Element._getContentFromAnonymousElement(tagName, content.stripScripts())
+ .each(function(node) { element.appendChild(node) });
+ }
+ else element.innerHTML = content.stripScripts();
+
+ content.evalScripts.bind(content).defer();
+ return element;
+ };
+}
+
+if ('outerHTML' in document.createElement('div')) {
+ Element.Methods.replace = function(element, content) {
+ element = $(element);
+
+ if (content && content.toElement) content = content.toElement();
+ if (Object.isElement(content)) {
+ element.parentNode.replaceChild(content, element);
+ return element;
+ }
+
+ content = Object.toHTML(content);
+ var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
+
+ if (Element._insertionTranslations.tags[tagName]) {
+ var nextSibling = element.next();
+ var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
+ parent.removeChild(element);
+ if (nextSibling)
+ fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
+ else
+ fragments.each(function(node) { parent.appendChild(node) });
+ }
+ else element.outerHTML = content.stripScripts();
+
+ content.evalScripts.bind(content).defer();
+ return element;
+ };
+}
+
+Element._returnOffset = function(l, t) {
+ var result = [l, t];
+ result.left = l;
+ result.top = t;
+ return result;
+};
+
+Element._getContentFromAnonymousElement = function(tagName, html) {
+ var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
+ if (t) {
+ div.innerHTML = t[0] + html + t[1];
+ t[2].times(function() { div = div.firstChild });
+ } else div.innerHTML = html;
+ return $A(div.childNodes);
+};
+
+Element._insertionTranslations = {
+ before: function(element, node) {
+ element.parentNode.insertBefore(node, element);
+ },
+ top: function(element, node) {
+ element.insertBefore(node, element.firstChild);
+ },
+ bottom: function(element, node) {
+ element.appendChild(node);
+ },
+ after: function(element, node) {
+ element.parentNode.insertBefore(node, element.nextSibling);
+ },
+ tags: {
+ TABLE: ['<table>', '</table>', 1],
+ TBODY: ['<table><tbody>', '</tbody></table>', 2],
+ TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
+ TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
+ SELECT: ['<select>', '</select>', 1]
+ }
+};
+
+(function() {
+ Object.extend(this.tags, {
+ THEAD: this.tags.TBODY,
+ TFOOT: this.tags.TBODY,
+ TH: this.tags.TD
+ });
+}).call(Element._insertionTranslations);
+
+Element.Methods.Simulated = {
+ hasAttribute: function(element, attribute) {
+ attribute = Element._attributeTranslations.has[attribute] || attribute;
+ var node = $(element).getAttributeNode(attribute);
+ return !!(node && node.specified);
+ }
+};
+
+Element.Methods.ByTag = { };
+
+Object.extend(Element, Element.Methods);
+
+if (!Prototype.BrowserFeatures.ElementExtensions &&
+ document.createElement('div')['__proto__']) {
+ window.HTMLElement = { };
+ window.HTMLElement.prototype = document.createElement('div')['__proto__'];
+ Prototype.BrowserFeatures.ElementExtensions = true;
+}
+
+Element.extend = (function() {
+ if (Prototype.BrowserFeatures.SpecificElementExtensions)
+ return Prototype.K;
+
+ var Methods = { }, ByTag = Element.Methods.ByTag;
+
+ var extend = Object.extend(function(element) {
+ if (!element || element._extendedByPrototype ||
+ element.nodeType != 1 || element == window) return element;
+
+ var methods = Object.clone(Methods),
+ tagName = element.tagName.toUpperCase(), property, value;
+
+ // extend methods for specific tags
+ if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
+
+ for (property in methods) {
+ value = methods[property];
+ if (Object.isFunction(value) && !(property in element))
+ element[property] = value.methodize();
+ }
+
+ element._extendedByPrototype = Prototype.emptyFunction;
+ return element;
+
+ }, {
+ refresh: function() {
+ // extend methods for all tags (Safari doesn't need this)
+ if (!Prototype.BrowserFeatures.ElementExtensions) {
+ Object.extend(Methods, Element.Methods);
+ Object.extend(Methods, Element.Methods.Simulated);
+ }
+ }
+ });
+
+ extend.refresh();
+ return extend;
+})();
+
+Element.hasAttribute = function(element, attribute) {
+ if (element.hasAttribute) return element.hasAttribute(attribute);
+ return Element.Methods.Simulated.hasAttribute(element, attribute);
+};
+
+Element.addMethods = function(methods) {
+ var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
+
+ if (!methods) {
+ Object.extend(Form, Form.Methods);
+ Object.extend(Form.Element, Form.Element.Methods);
+ Object.extend(Element.Methods.ByTag, {
+ "FORM": Object.clone(Form.Methods),
+ "INPUT": Object.clone(Form.Element.Methods),
+ "SELECT": Object.clone(Form.Element.Methods),
+ "TEXTAREA": Object.clone(Form.Element.Methods)
+ });
+ }
+
+ if (arguments.length == 2) {
+ var tagName = methods;
+ methods = arguments[1];
+ }
+
+ if (!tagName) Object.extend(Element.Methods, methods || { });
+ else {
+ if (Object.isArray(tagName)) tagName.each(extend);
+ else extend(tagName);
+ }
+
+ function extend(tagName) {
+ tagName = tagName.toUpperCase();
+ if (!Element.Methods.ByTag[tagName])
+ Element.Methods.ByTag[tagName] = { };
+ Object.extend(Element.Methods.ByTag[tagName], methods);
+ }
+
+ function copy(methods, destination, onlyIfAbsent) {
+ onlyIfAbsent = onlyIfAbsent || false;
+ for (var property in methods) {
+ var value = methods[property];
+ if (!Object.isFunction(value)) continue;
+ if (!onlyIfAbsent || !(property in destination))
+ destination[property] = value.methodize();
+ }
+ }
+
+ function findDOMClass(tagName) {
+ var klass;
+ var trans = {
+ "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
+ "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
+ "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
+ "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
+ "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
+ "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
+ "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
+ "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
+ "FrameSet", "IFRAME": "IFrame"
+ };
+ if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
+ if (window[klass]) return window[klass];
+ klass = 'HTML' + tagName + 'Element';
+ if (window[klass]) return window[klass];
+ klass = 'HTML' + tagName.capitalize() + 'Element';
+ if (window[klass]) return window[klass];
+
+ window[klass] = { };
+ window[klass].prototype = document.createElement(tagName)['__proto__'];
+ return window[klass];
+ }
+
+ if (F.ElementExtensions) {
+ copy(Element.Methods, HTMLElement.prototype);
+ copy(Element.Methods.Simulated, HTMLElement.prototype, true);
+ }
+
+ if (F.SpecificElementExtensions) {
+ for (var tag in Element.Methods.ByTag) {
+ var klass = findDOMClass(tag);
+ if (Object.isUndefined(klass)) continue;
+ copy(T[tag], klass.prototype);
+ }
+ }
+
+ Object.extend(Element, Element.Methods);
+ delete Element.ByTag;
+
+ if (Element.extend.refresh) Element.extend.refresh();
+ Element.cache = { };
+};
+
+document.viewport = {
+ getDimensions: function() {
+ var dimensions = { }, B = Prototype.Browser;
+ $w('width height').each(function(d) {
+ var D = d.capitalize();
+ if (B.WebKit && !document.evaluate) {
+ // Safari <3.0 needs self.innerWidth/Height
+ dimensions[d] = self['inner' + D];
+ } else if (B.Opera && parseFloat(window.opera.version()) < 9.5) {
+ // Opera <9.5 needs document.body.clientWidth/Height
+ dimensions[d] = document.body['client' + D]
+ } else {
+ dimensions[d] = document.documentElement['client' + D];
+ }
+ });
+ return dimensions;
+ },
+
+ getWidth: function() {
+ return this.getDimensions().width;
+ },
+
+ getHeight: function() {
+ return this.getDimensions().height;
+ },
+
+ getScrollOffsets: function() {
+ return Element._returnOffset(
+ window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
+ window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
+ }
+};
+/* Portions of the Selector class are derived from Jack Slocum's DomQuery,
+ * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
+ * license. Please see http://www.yui-ext.com/ for more information. */
+
+var Selector = Class.create({
+ initialize: function(expression) {
+ this.expression = expression.strip();
+
+ if (this.shouldUseSelectorsAPI()) {
+ this.mode = 'selectorsAPI';
+ } else if (this.shouldUseXPath()) {
+ this.mode = 'xpath';
+ this.compileXPathMatcher();
+ } else {
+ this.mode = "normal";
+ this.compileMatcher();
+ }
+
+ },
+
+ shouldUseXPath: function() {
+ if (!Prototype.BrowserFeatures.XPath) return false;
+
+ var e = this.expression;
+
+ // Safari 3 chokes on :*-of-type and :empty
+ if (Prototype.Browser.WebKit &&
+ (e.include("-of-type") || e.include(":empty")))
+ return false;
+
+ // XPath can't do namespaced attributes, nor can it read
+ // the "checked" property from DOM nodes
+ if ((/(\[[\w-]*?:|:checked)/).test(e))
+ return false;
+
+ return true;
+ },
+
+ shouldUseSelectorsAPI: function() {
+ if (!Prototype.BrowserFeatures.SelectorsAPI) return false;
+
+ if (!Selector._div) Selector._div = new Element('div');
+
+ // Make sure the browser treats the selector as valid. Test on an
+ // isolated element to minimize cost of this check.
+ try {
+ Selector._div.querySelector(this.expression);
+ } catch(e) {
+ return false;
+ }
+
+ return true;
+ },
+
+ compileMatcher: function() {
+ var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
+ c = Selector.criteria, le, p, m;
+
+ if (Selector._cache[e]) {
+ this.matcher = Selector._cache[e];
+ return;
+ }
+
+ this.matcher = ["this.matcher = function(root) {",
+ "var r = root, h = Selector.handlers, c = false, n;"];
+
+ while (e && le != e && (/\S/).test(e)) {
+ le = e;
+ for (var i in ps) {
+ p = ps[i];
+ if (m = e.match(p)) {
+ this.matcher.push(Object.isFunction(c[i]) ? c[i](m) :
+ new Template(c[i]).evaluate(m));
+ e = e.replace(m[0], '');
+ break;
+ }
+ }
+ }
+
+ this.matcher.push("return h.unique(n);\n}");
+ eval(this.matcher.join('\n'));
+ Selector._cache[this.expression] = this.matcher;
+ },
+
+ compileXPathMatcher: function() {
+ var e = this.expression, ps = Selector.patterns,
+ x = Selector.xpath, le, m;
+
+ if (Selector._cache[e]) {
+ this.xpath = Selector._cache[e]; return;
+ }
+
+ this.matcher = ['.//*'];
+ while (e && le != e && (/\S/).test(e)) {
+ le = e;
+ for (var i in ps) {
+ if (m = e.match(ps[i])) {
+ this.matcher.push(Object.isFunction(x[i]) ? x[i](m) :
+ new Template(x[i]).evaluate(m));
+ e = e.replace(m[0], '');
+ break;
+ }
+ }
+ }
+
+ this.xpath = this.matcher.join('');
+ Selector._cache[this.expression] = this.xpath;
+ },
+
+ findElements: function(root) {
+ root = root || document;
+ var e = this.expression, results;
+
+ switch (this.mode) {
+ case 'selectorsAPI':
+ // querySelectorAll queries document-wide, then filters to descendants
+ // of the context element. That's not what we want.
+ // Add an explicit context to the selector if necessary.
+ if (root !== document) {
+ var oldId = root.id, id = $(root).identify();
+
+ // https://jira.jboss.org/jira/browse/RF-5416
+ e = "#" + id.replace(/:/g, '\\:') + " " + e
+ //e = "#" + id + " " + e;
+ }
+
+ results = $A(root.querySelectorAll(e)).map(Element.extend);
+ root.id = oldId;
+
+ return results;
+ case 'xpath':
+ return document._getElementsByXPath(this.xpath, root);
+ default:
+ return this.matcher(root);
+ }
+ },
+
+ match: function(element) {
+ this.tokens = [];
+
+ var e = this.expression, ps = Selector.patterns, as = Selector.assertions;
+ var le, p, m;
+
+ while (e && le !== e && (/\S/).test(e)) {
+ le = e;
+ for (var i in ps) {
+ p = ps[i];
+ if (m = e.match(p)) {
+ // use the Selector.assertions methods unless the selector
+ // is too complex.
+ if (as[i]) {
+ this.tokens.push([i, Object.clone(m)]);
+ e = e.replace(m[0], '');
+ } else {
+ // reluctantly do a document-wide search
+ // and look for a match in the array
+ return this.findElements(document).include(element);
+ }
+ }
+ }
+ }
+
+ var match = true, name, matches;
+ for (var i = 0, token; token = this.tokens[i]; i++) {
+ name = token[0], matches = token[1];
+ if (!Selector.assertions[name](element, matches)) {
+ match = false; break;
+ }
+ }
+
+ return match;
+ },
+
+ toString: function() {
+ return this.expression;
+ },
+
+ inspect: function() {
+ return "#<Selector:" + this.expression.inspect() + ">";
+ }
+});
+
+Object.extend(Selector, {
+ _cache: { },
+
+ xpath: {
+ descendant: "//*",
+ child: "/*",
+ adjacent: "/following-sibling::*[1]",
+ laterSibling: '/following-sibling::*',
+ tagName: function(m) {
+ if (m[1] == '*') return '';
+ return "[local-name()='" + m[1].toLowerCase() +
+ "' or local-name()='" + m[1].toUpperCase() + "']";
+ },
+ className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",
+ id: "[@id='#{1}']",
+ attrPresence: function(m) {
+ m[1] = m[1].toLowerCase();
+ return new Template("[@#{1}]").evaluate(m);
+ },
+ attr: function(m) {
+ m[1] = m[1].toLowerCase();
+ m[3] = m[5] || m[6];
+ return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
+ },
+ pseudo: function(m) {
+ var h = Selector.xpath.pseudos[m[1]];
+ if (!h) return '';
+ if (Object.isFunction(h)) return h(m);
+ return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);
+ },
+ operators: {
+ '=': "[@#{1}='#{3}']",
+ '!=': "[@#{1}!='#{3}']",
+ '^=': "[starts-with(@#{1}, '#{3}')]",
+ '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']",
+ '*=': "[contains(@#{1}, '#{3}')]",
+ '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]",
+ '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]"
+ },
+ pseudos: {
+ 'first-child': '[not(preceding-sibling::*)]',
+ 'last-child': '[not(following-sibling::*)]',
+ 'only-child': '[not(preceding-sibling::* or following-sibling::*)]',
+ 'empty': "[count(*) = 0 and (count(text()) = 0)]",
+ 'checked': "[@checked]",
+ 'disabled': "[(@disabled) and (@type!='hidden')]",
+ 'enabled': "[not(@disabled) and (@type!='hidden')]",
+ 'not': function(m) {
+ var e = m[6], p = Selector.patterns,
+ x = Selector.xpath, le, v;
+
+ var exclusion = [];
+ while (e && le != e && (/\S/).test(e)) {
+ le = e;
+ for (var i in p) {
+ if (m = e.match(p[i])) {
+ v = Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m);
+ exclusion.push("(" + v.substring(1, v.length - 1) + ")");
+ e = e.replace(m[0], '');
+ break;
+ }
+ }
+ }
+ return "[not(" + exclusion.join(" and ") + ")]";
+ },
+ 'nth-child': function(m) {
+ return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m);
+ },
+ 'nth-last-child': function(m) {
+ return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m);
+ },
+ 'nth-of-type': function(m) {
+ return Selector.xpath.pseudos.nth("position() ", m);
+ },
+ 'nth-last-of-type': function(m) {
+ return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m);
+ },
+ 'first-of-type': function(m) {
+ m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m);
+ },
+ 'last-of-type': function(m) {
+ m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m);
+ },
+ 'only-of-type': function(m) {
+ var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m);
+ },
+ nth: function(fragment, m) {
+ var mm, formula = m[6], predicate;
+ if (formula == 'even') formula = '2n+0';
+ if (formula == 'odd') formula = '2n+1';
+ if (mm = formula.match(/^(\d+)$/)) // digit only
+ return '[' + fragment + "= " + mm[1] + ']';
+ if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
+ if (mm[1] == "-") mm[1] = -1;
+ var a = mm[1] ? Number(mm[1]) : 1;
+ var b = mm[2] ? Number(mm[2]) : 0;
+ predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " +
+ "((#{fragment} - #{b}) div #{a} >= 0)]";
+ return new Template(predicate).evaluate({
+ fragment: fragment, a: a, b: b });
+ }
+ }
+ }
+ },
+
+ criteria: {
+ tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
+ className: 'n = h.className(n, r, "#{1}", c); c = false;',
+ id: 'n = h.id(n, r, "#{1}", c); c = false;',
+ attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;',
+ attr: function(m) {
+ m[3] = (m[5] || m[6]);
+ return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m);
+ },
+ pseudo: function(m) {
+ if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
+ return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m);
+ },
+ descendant: 'c = "descendant";',
+ child: 'c = "child";',
+ adjacent: 'c = "adjacent";',
+ laterSibling: 'c = "laterSibling";'
+ },
+
+ patterns: {
+ // combinators must be listed first
+ // (and descendant needs to be last combinator)
+ laterSibling: /^\s*~\s*/,
+ child: /^\s*>\s*/,
+ adjacent: /^\s*\+\s*/,
+ descendant: /^\s/,
+
+ // selectors follow
+ tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,
+ id: /^#([\w\-\*]+)(\b|$)/,
+ className: /^\.([\w\-\*]+)(\b|$)/,
+ pseudo:
+/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,
+ attrPresence: /^\[((?:[\w]+:)?[\w]+)\]/,
+ attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/
+ },
+
+ // for Selector.match and Element#match
+ assertions: {
+ tagName: function(element, matches) {
+ return matches[1].toUpperCase() == element.tagName.toUpperCase();
+ },
+
+ className: function(element, matches) {
+ return Element.hasClassName(element, matches[1]);
+ },
+
+ id: function(element, matches) {
+ return element.id === matches[1];
+ },
+
+ attrPresence: function(element, matches) {
+ return Element.hasAttribute(element, matches[1]);
+ },
+
+ attr: function(element, matches) {
+ var nodeValue = Element.readAttribute(element, matches[1]);
+ return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]);
+ }
+ },
+
+ handlers: {
+ // UTILITY FUNCTIONS
+ // joins two collections
+ concat: function(a, b) {
+ for (var i = 0, node; node = b[i]; i++)
+ a.push(node);
+ return a;
+ },
+
+ // marks an array of nodes for counting
+ mark: function(nodes) {
+ var _true = Prototype.emptyFunction;
+ for (var i = 0, node; node = nodes[i]; i++)
+ node._countedByPrototype = _true;
+ return nodes;
+ },
+
+ unmark: function(nodes) {
+ for (var i = 0, node; node = nodes[i]; i++)
+ node._countedByPrototype = undefined;
+ return nodes;
+ },
+
+ // mark each child node with its position (for nth calls)
+ // "ofType" flag indicates whether we're indexing for nth-of-type
+ // rather than nth-child
+ index: function(parentNode, reverse, ofType) {
+ parentNode._countedByPrototype = Prototype.emptyFunction;
+ if (reverse) {
+ for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
+ var node = nodes[i];
+ if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
+ }
+ } else {
+ for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
+ if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
+ }
+ },
+
+ // filters out duplicates and extends all nodes
+ unique: function(nodes) {
+ if (nodes.length == 0) return nodes;
+ var results = [], n;
+ for (var i = 0, l = nodes.length; i < l; i++)
+ if (!(n = nodes[i])._countedByPrototype) {
+ n._countedByPrototype = Prototype.emptyFunction;
+ results.push(Element.extend(n));
+ }
+ return Selector.handlers.unmark(results);
+ },
+
+ // COMBINATOR FUNCTIONS
+ descendant: function(nodes) {
+ var h = Selector.handlers;
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
+ h.concat(results, node.getElementsByTagName('*'));
+ return results;
+ },
+
+ child: function(nodes) {
+ var h = Selector.handlers;
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
+ for (var j = 0, child; child = node.childNodes[j]; j++)
+ if (child.nodeType == 1 && child.tagName != '!') results.push(child);
+ }
+ return results;
+ },
+
+ adjacent: function(nodes) {
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
+ var next = this.nextElementSibling(node);
+ if (next) results.push(next);
+ }
+ return results;
+ },
+
+ laterSibling: function(nodes) {
+ var h = Selector.handlers;
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
+ h.concat(results, Element.nextSiblings(node));
+ return results;
+ },
+
+ nextElementSibling: function(node) {
+ while (node = node.nextSibling)
+ if (node.nodeType == 1) return node;
+ return null;
+ },
+
+ previousElementSibling: function(node) {
+ while (node = node.previousSibling)
+ if (node.nodeType == 1) return node;
+ return null;
+ },
+
+ // TOKEN FUNCTIONS
+ tagName: function(nodes, root, tagName, combinator) {
+ var uTagName = tagName.toUpperCase();
+ var results = [], h = Selector.handlers;
+ if (nodes) {
+ if (combinator) {
+ // fastlane for ordinary descendant combinators
+ if (combinator == "descendant") {
+ for (var i = 0, node; node = nodes[i]; i++)
+ h.concat(results, node.getElementsByTagName(tagName));
+ return results;
+ } else nodes = this[combinator](nodes);
+ if (tagName == "*") return nodes;
+ }
+ for (var i = 0, node; node = nodes[i]; i++)
+ if (node.tagName.toUpperCase() === uTagName) results.push(node);
+ return results;
+ } else return root.getElementsByTagName(tagName);
+ },
+
+ id: function(nodes, root, id, combinator) {
+ var targetNode = $(id), h = Selector.handlers;
+ if (!targetNode) return [];
+ if (!nodes && root == document) return [targetNode];
+ if (nodes) {
+ if (combinator) {
+ if (combinator == 'child') {
+ for (var i = 0, node; node = nodes[i]; i++)
+ if (targetNode.parentNode == node) return [targetNode];
+ } else if (combinator == 'descendant') {
+ for (var i = 0, node; node = nodes[i]; i++)
+ if (Element.descendantOf(targetNode, node)) return [targetNode];
+ } else if (combinator == 'adjacent') {
+ for (var i = 0, node; node = nodes[i]; i++)
+ if (Selector.handlers.previousElementSibling(targetNode) == node)
+ return [targetNode];
+ } else nodes = h[combinator](nodes);
+ }
+ for (var i = 0, node; node = nodes[i]; i++)
+ if (node == targetNode) return [targetNode];
+ return [];
+ }
+ return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : [];
+ },
+
+ className: function(nodes, root, className, combinator) {
+ if (nodes && combinator) nodes = this[combinator](nodes);
+ return Selector.handlers.byClassName(nodes, root, className);
+ },
+
+ byClassName: function(nodes, root, className) {
+ if (!nodes) nodes = Selector.handlers.descendant([root]);
+ var needle = ' ' + className + ' ';
+ for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) {
+ nodeClassName = node.className;
+ if (nodeClassName.length == 0) continue;
+ if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle))
+ results.push(node);
+ }
+ return results;
+ },
+
+ attrPresence: function(nodes, root, attr, combinator) {
+ if (!nodes) nodes = root.getElementsByTagName("*");
+ if (nodes && combinator) nodes = this[combinator](nodes);
+ var results = [];
+ for (var i = 0, node; node = nodes[i]; i++)
+ if (Element.hasAttribute(node, attr)) results.push(node);
+ return results;
+ },
+
+ attr: function(nodes, root, attr, value, operator, combinator) {
+ if (!nodes) nodes = root.getElementsByTagName("*");
+ if (nodes && combinator) nodes = this[combinator](nodes);
+ var handler = Selector.operators[operator], results = [];
+ for (var i = 0, node; node = nodes[i]; i++) {
+ var nodeValue = Element.readAttribute(node, attr);
+ if (nodeValue === null) continue;
+ if (handler(nodeValue, value)) results.push(node);
+ }
+ return results;
+ },
+
+ pseudo: function(nodes, name, value, root, combinator) {
+ if (nodes && combinator) nodes = this[combinator](nodes);
+ if (!nodes) nodes = root.getElementsByTagName("*");
+ return Selector.pseudos[name](nodes, value, root);
+ }
+ },
+
+ pseudos: {
+ 'first-child': function(nodes, value, root) {
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
+ if (Selector.handlers.previousElementSibling(node)) continue;
+ results.push(node);
+ }
+ return results;
+ },
+ 'last-child': function(nodes, value, root) {
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
+ if (Selector.handlers.nextElementSibling(node)) continue;
+ results.push(node);
+ }
+ return results;
+ },
+ 'only-child': function(nodes, value, root) {
+ var h = Selector.handlers;
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
+ if (!h.previousElementSibling(node) && !h.nextElementSibling(node))
+ results.push(node);
+ return results;
+ },
+ 'nth-child': function(nodes, formula, root) {
+ return Selector.pseudos.nth(nodes, formula, root);
+ },
+ 'nth-last-child': function(nodes, formula, root) {
+ return Selector.pseudos.nth(nodes, formula, root, true);
+ },
+ 'nth-of-type': function(nodes, formula, root) {
+ return Selector.pseudos.nth(nodes, formula, root, false, true);
+ },
+ 'nth-last-of-type': function(nodes, formula, root) {
+ return Selector.pseudos.nth(nodes, formula, root, true, true);
+ },
+ 'first-of-type': function(nodes, formula, root) {
+ return Selector.pseudos.nth(nodes, "1", root, false, true);
+ },
+ 'last-of-type': function(nodes, formula, root) {
+ return Selector.pseudos.nth(nodes, "1", root, true, true);
+ },
+ 'only-of-type': function(nodes, formula, root) {
+ var p = Selector.pseudos;
+ return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root);
+ },
+
+ // handles the an+b logic
+ getIndices: function(a, b, total) {
+ if (a == 0) return b > 0 ? [b] : [];
+ return $R(1, total).inject([], function(memo, i) {
+ if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i);
+ return memo;
+ });
+ },
+
+ // handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type
+ nth: function(nodes, formula, root, reverse, ofType) {
+ if (nodes.length == 0) return [];
+ if (formula == 'even') formula = '2n+0';
+ if (formula == 'odd') formula = '2n+1';
+ var h = Selector.handlers, results = [], indexed = [], m;
+ h.mark(nodes);
+ for (var i = 0, node; node = nodes[i]; i++) {
+ if (!node.parentNode._countedByPrototype) {
+ h.index(node.parentNode, reverse, ofType);
+ indexed.push(node.parentNode);
+ }
+ }
+ if (formula.match(/^\d+$/)) { // just a number
+ formula = Number(formula);
+ for (var i = 0, node; node = nodes[i]; i++)
+ if (node.nodeIndex == formula) results.push(node);
+ } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
+ if (m[1] == "-") m[1] = -1;
+ var a = m[1] ? Number(m[1]) : 1;
+ var b = m[2] ? Number(m[2]) : 0;
+ var indices = Selector.pseudos.getIndices(a, b, nodes.length);
+ for (var i = 0, node, l = indices.length; node = nodes[i]; i++) {
+ for (var j = 0; j < l; j++)
+ if (node.nodeIndex == indices[j]) results.push(node);
+ }
+ }
+ h.unmark(nodes);
+ h.unmark(indexed);
+ return results;
+ },
+
+ 'empty': function(nodes, value, root) {
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
+ // IE treats comments as element nodes
+ if (node.tagName == '!' || node.firstChild) continue;
+ results.push(node);
+ }
+ return results;
+ },
+
+ 'not': function(nodes, selector, root) {
+ var h = Selector.handlers, selectorType, m;
+ var exclusions = new Selector(selector).findElements(root);
+ h.mark(exclusions);
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
+ if (!node._countedByPrototype) results.push(node);
+ h.unmark(exclusions);
+ return results;
+ },
+
+ 'enabled': function(nodes, value, root) {
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
+ if (!node.disabled && (!node.type || node.type !== 'hidden'))
+ results.push(node);
+ return results;
+ },
+
+ 'disabled': function(nodes, value, root) {
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
+ if (node.disabled) results.push(node);
+ return results;
+ },
+
+ 'checked': function(nodes, value, root) {
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
+ if (node.checked) results.push(node);
+ return results;
+ }
+ },
+
+ operators: {
+ '=': function(nv, v) { return nv == v; },
+ '!=': function(nv, v) { return nv != v; },
+ '^=': function(nv, v) { return nv == v || nv && nv.startsWith(v); },
+ '$=': function(nv, v) { return nv == v || nv && nv.endsWith(v); },
+ '*=': function(nv, v) { return nv == v || nv && nv.include(v); },
+ '$=': function(nv, v) { return nv.endsWith(v); },
+ '*=': function(nv, v) { return nv.include(v); },
+ '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); },
+ '|=': function(nv, v) { return ('-' + (nv || "").toUpperCase() +
+ '-').include('-' + (v || "").toUpperCase() + '-'); }
+ },
+
+ split: function(expression) {
+ var expressions = [];
+ expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
+ expressions.push(m[1].strip());
+ });
+ return expressions;
+ },
+
+ matchElements: function(elements, expression) {
+ var matches = $$(expression), h = Selector.handlers;
+ h.mark(matches);
+ for (var i = 0, results = [], element; element = elements[i]; i++)
+ if (element._countedByPrototype) results.push(element);
+ h.unmark(matches);
+ return results;
+ },
+
+ findElement: function(elements, expression, index) {
+ if (Object.isNumber(expression)) {
+ index = expression; expression = false;
+ }
+ return Selector.matchElements(elements, expression || '*')[index || 0];
+ },
+
+ findChildElements: function(element, expressions) {
+ expressions = Selector.split(expressions.join(','));
+ var results = [], h = Selector.handlers;
+ for (var i = 0, l = expressions.length, selector; i < l; i++) {
+ selector = new Selector(expressions[i].strip());
+ h.concat(results, selector.findElements(element));
+ }
+ return (l > 1) ? h.unique(results) : results;
+ }
+});
+
+if (Prototype.Browser.IE) {
+ Object.extend(Selector.handlers, {
+ // IE returns comment nodes on getElementsByTagName("*").
+ // Filter them out.
+ concat: function(a, b) {
+ for (var i = 0, node; node = b[i]; i++)
+ if (node.tagName !== "!") a.push(node);
+ return a;
+ },
+
+ // IE improperly serializes _countedByPrototype in (inner|outer)HTML.
+ unmark: function(nodes) {
+ for (var i = 0, node; node = nodes[i]; i++)
+ node.removeAttribute('_countedByPrototype');
+ return nodes;
+ }
+ });
+}
+
+function $$() {
+ return Selector.findChildElements(document, $A(arguments));
+}
+var Form = {
+ reset: function(form) {
+ $(form).reset();
+ return form;
+ },
+
+ serializeElements: function(elements, options) {
+ if (typeof options != 'object') options = { hash: !!options };
+ else if (Object.isUndefined(options.hash)) options.hash = true;
+ var key, value, submitted = false, submit = options.submit;
+
+ var data = elements.inject({ }, function(result, element) {
+ if (!element.disabled && element.name) {
+ key = element.name; value = $(element).getValue();
+ if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
+ submit !== false && (!submit || key == submit) && (submitted = true)))) {
+ if (key in result) {
+ // a key is already present; construct an array of values
+ if (!Object.isArray(result[key])) result[key] = [result[key]];
+ result[key].push(value);
+ }
+ else result[key] = value;
+ }
+ }
+ return result;
+ });
+
+ return options.hash ? data : Object.toQueryString(data);
+ }
+};
+
+Form.Methods = {
+ serialize: function(form, options) {
+ return Form.serializeElements(Form.getElements(form), options);
+ },
+
+ getElements: function(form) {
+ return $A($(form).getElementsByTagName('*')).inject([],
+ function(elements, child) {
+ if (Form.Element.Serializers[child.tagName.toLowerCase()])
+ elements.push(Element.extend(child));
+ return elements;
+ }
+ );
+ },
+
+ getInputs: function(form, typeName, name) {
+ form = $(form);
+ var inputs = form.getElementsByTagName('input');
+
+ if (!typeName && !name) return $A(inputs).map(Element.extend);
+
+ for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
+ var input = inputs[i];
+ if ((typeName && input.type != typeName) || (name && input.name != name))
+ continue;
+ matchingInputs.push(Element.extend(input));
+ }
+
+ return matchingInputs;
+ },
+
+ disable: function(form) {
+ form = $(form);
+ Form.getElements(form).invoke('disable');
+ return form;
+ },
+
+ enable: function(form) {
+ form = $(form);
+ Form.getElements(form).invoke('enable');
+ return form;
+ },
+
+ findFirstElement: function(form) {
+ var elements = $(form).getElements().findAll(function(element) {
+ return 'hidden' != element.type && !element.disabled;
+ });
+ var firstByIndex = elements.findAll(function(element) {
+ return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
+ }).sortBy(function(element) { return element.tabIndex }).first();
+
+ return firstByIndex ? firstByIndex : elements.find(function(element) {
+ return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
+ });
+ },
+
+ focusFirstElement: function(form) {
+ form = $(form);
+ form.findFirstElement().activate();
+ return form;
+ },
+
+ request: function(form, options) {
+ form = $(form), options = Object.clone(options || { });
+
+ var params = options.parameters, action = form.readAttribute('action') || '';
+ if (action.blank()) action = window.location.href;
+ options.parameters = form.serialize(true);
+
+ if (params) {
+ if (Object.isString(params)) params = params.toQueryParams();
+ Object.extend(options.parameters, params);
+ }
+
+ if (form.hasAttribute('method') && !options.method)
+ options.method = form.method;
+
+ return new Ajax.Request(action, options);
+ }
+};
+
+/*--------------------------------------------------------------------------*/
+
+Form.Element = {
+ focus: function(element) {
+ $(element).focus();
+ return element;
+ },
+
+ select: function(element) {
+ $(element).select();
+ return element;
+ }
+};
+
+Form.Element.Methods = {
+ serialize: function(element) {
+ element = $(element);
+ if (!element.disabled && element.name) {
+ var value = element.getValue();
+ if (value != undefined) {
+ var pair = { };
+ pair[element.name] = value;
+ return Object.toQueryString(pair);
+ }
+ }
+ return '';
+ },
+
+ getValue: function(element) {
+ element = $(element);
+ var method = element.tagName.toLowerCase();
+ return Form.Element.Serializers[method](element);
+ },
+
+ setValue: function(element, value) {
+ element = $(element);
+ var method = element.tagName.toLowerCase();
+ Form.Element.Serializers[method](element, value);
+ return element;
+ },
+
+ clear: function(element) {
+ $(element).value = '';
+ return element;
+ },
+
+ present: function(element) {
+ return $(element).value != '';
+ },
+
+ activate: function(element) {
+ element = $(element);
+ try {
+ element.focus();
+ if (element.select && (element.tagName.toLowerCase() != 'input' ||
+ !['button', 'reset', 'submit'].include(element.type)))
+ element.select();
+ } catch (e) { }
+ return element;
+ },
+
+ disable: function(element) {
+ element = $(element);
+ element.disabled = true;
+ return element;
+ },
+
+ enable: function(element) {
+ element = $(element);
+ element.disabled = false;
+ return element;
+ }
+};
+
+/*--------------------------------------------------------------------------*/
+
+var Field = Form.Element;
+var $F = Form.Element.Methods.getValue;
+
+/*--------------------------------------------------------------------------*/
+
+Form.Element.Serializers = {
+ input: function(element, value) {
+ switch (element.type.toLowerCase()) {
+ case 'checkbox':
+ case 'radio':
+ return Form.Element.Serializers.inputSelector(element, value);
+ default:
+ return Form.Element.Serializers.textarea(element, value);
+ }
+ },
+
+ inputSelector: function(element, value) {
+ if (Object.isUndefined(value)) return element.checked ? element.value : null;
+ else element.checked = !!value;
+ },
+
+ textarea: function(element, value) {
+ if (Object.isUndefined(value)) return element.value;
+ else element.value = value;
+ },
+
+ select: function(element, value) {
+ if (Object.isUndefined(value))
+ return this[element.type == 'select-one' ?
+ 'selectOne' : 'selectMany'](element);
+ else {
+ var opt, currentValue, single = !Object.isArray(value);
+ for (var i = 0, length = element.length; i < length; i++) {
+ opt = element.options[i];
+ currentValue = this.optionValue(opt);
+ if (single) {
+ if (currentValue == value) {
+ opt.selected = true;
+ return;
+ }
+ }
+ else opt.selected = value.include(currentValue);
+ }
+ }
+ },
+
+ selectOne: function(element) {
+ var index = element.selectedIndex;
+ return index >= 0 ? this.optionValue(element.options[index]) : null;
+ },
+
+ selectMany: function(element) {
+ var values, length = element.length;
+ if (!length) return null;
+
+ for (var i = 0, values = []; i < length; i++) {
+ var opt = element.options[i];
+ if (opt.selected) values.push(this.optionValue(opt));
+ }
+ return values;
+ },
+
+ optionValue: function(opt) {
+ // extend element because hasAttribute may not be native
+ return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
+ }
+};
+
+/*--------------------------------------------------------------------------*/
+
+Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
+ initialize: function($super, element, frequency, callback) {
+ $super(callback, frequency);
+ this.element = $(element);
+ this.lastValue = this.getValue();
+ },
+
+ execute: function() {
+ var value = this.getValue();
+ if (Object.isString(this.lastValue) && Object.isString(value) ?
+ this.lastValue != value : String(this.lastValue) != String(value)) {
+ this.callback(this.element, value);
+ this.lastValue = value;
+ }
+ }
+});
+
+Form.Element.Observer = Class.create(Abstract.TimedObserver, {
+ getValue: function() {
+ return Form.Element.getValue(this.element);
+ }
+});
+
+Form.Observer = Class.create(Abstract.TimedObserver, {
+ getValue: function() {
+ return Form.serialize(this.element);
+ }
+});
+
+/*--------------------------------------------------------------------------*/
+
+Abstract.EventObserver = Class.create({
+ initialize: function(element, callback) {
+ this.element = $(element);
+ this.callback = callback;
+
+ this.lastValue = this.getValue();
+ if (this.element.tagName.toLowerCase() == 'form')
+ this.registerFormCallbacks();
+ else
+ this.registerCallback(this.element);
+ },
+
+ onElementEvent: function() {
+ var value = this.getValue();
+ if (this.lastValue != value) {
+ this.callback(this.element, value);
+ this.lastValue = value;
+ }
+ },
+
+ registerFormCallbacks: function() {
+ Form.getElements(this.element).each(this.registerCallback, this);
+ },
+
+ registerCallback: function(element) {
+ if (element.type) {
+ switch (element.type.toLowerCase()) {
+ case 'checkbox':
+ case 'radio':
+ Event.observe(element, 'click', this.onElementEvent.bind(this));
+ break;
+ default:
+ Event.observe(element, 'change', this.onElementEvent.bind(this));
+ break;
+ }
+ }
+ }
+});
+
+Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
+ getValue: function() {
+ return Form.Element.getValue(this.element);
+ }
+});
+
+Form.EventObserver = Class.create(Abstract.EventObserver, {
+ getValue: function() {
+ return Form.serialize(this.element);
+ }
+});
+if (!window.Event) var Event = { };
+
+Object.extend(Event, {
+ KEY_BACKSPACE: 8,
+ KEY_TAB: 9,
+ KEY_RETURN: 13,
+ KEY_ESC: 27,
+ KEY_LEFT: 37,
+ KEY_UP: 38,
+ KEY_RIGHT: 39,
+ KEY_DOWN: 40,
+ KEY_DELETE: 46,
+ KEY_HOME: 36,
+ KEY_END: 35,
+ KEY_PAGEUP: 33,
+ KEY_PAGEDOWN: 34,
+ KEY_INSERT: 45,
+
+ cache: { },
+
+ relatedTarget: function(event) {
+ var element;
+ switch(event.type) {
+ case 'mouseover': element = event.fromElement; break;
+ case 'mouseout': element = event.toElement; break;
+ default: return null;
+ }
+ return Element.extend(element);
+ }
+});
+
+Event.Methods = (function() {
+ var isButton;
+
+ if (Prototype.Browser.IE) {
+ var buttonMap = { 0: 1, 1: 4, 2: 2 };
+ isButton = function(event, code) {
+ return event.button == buttonMap[code];
+ };
+
+ } else if (Prototype.Browser.WebKit) {
+ isButton = function(event, code) {
+ switch (code) {
+ case 0: return event.which == 1 && !event.metaKey;
+ case 1: return event.which == 1 && event.metaKey;
+ default: return false;
+ }
+ };
+
+ } else {
+ isButton = function(event, code) {
+ return event.which ? (event.which === code + 1) : (event.button === code);
+ };
+ }
+
+ return {
+ isLeftClick: function(event) { return isButton(event, 0) },
+ isMiddleClick: function(event) { return isButton(event, 1) },
+ isRightClick: function(event) { return isButton(event, 2) },
+
+ element: function(event) {
+ event = Event.extend(event);
+
+ var node = event.target,
+ type = event.type,
+ currentTarget = event.currentTarget;
+
+ if (currentTarget && currentTarget.tagName) {
+ // Firefox screws up the "click" event when moving between radio buttons
+ // via arrow keys. It also screws up the "load" and "error" events on images,
+ // reporting the document as the target instead of the original image.
+ if (type === 'load' || type === 'error' ||
+ (type === 'click' && currentTarget.tagName.toLowerCase() === 'input'
+ && currentTarget.type === 'radio'))
+ node = currentTarget;
+ }
+ if (node.nodeType == Node.TEXT_NODE) node = node.parentNode;
+ return Element.extend(node);
+ },
+
+ findElement: function(event, expression) {
+ var element = Event.element(event);
+ if (!expression) return element;
+ var elements = [element].concat(element.ancestors());
+ return Selector.findElement(elements, expression, 0);
+ },
+
+ pointer: function(event) {
+ var docElement = document.documentElement,
+ body = document.body || { scrollLeft: 0, scrollTop: 0 };
+ return {
+ x: event.pageX || (event.clientX +
+ (docElement.scrollLeft || body.scrollLeft) -
+ (docElement.clientLeft || 0)),
+ y: event.pageY || (event.clientY +
+ (docElement.scrollTop || body.scrollTop) -
+ (docElement.clientTop || 0))
+ };
+ },
+
+ pointerX: function(event) { return Event.pointer(event).x },
+ pointerY: function(event) { return Event.pointer(event).y },
+
+ stop: function(event) {
+ Event.extend(event);
+ event.preventDefault();
+ event.stopPropagation();
+ event.stopped = true;
+ }
+ };
+})();
+
+Event.extend = (function() {
+ var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
+ m[name] = Event.Methods[name].methodize();
+ return m;
+ });
+
+ if (Prototype.Browser.IE) {
+ Object.extend(methods, {
+ stopPropagation: function() { this.cancelBubble = true },
+ preventDefault: function() { this.returnValue = false },
+ inspect: function() { return "[object Event]" }
+ });
+
+ return function(event) {
+ if (!event) return false;
+ if (event._extendedByPrototype) return event;
+
+ event._extendedByPrototype = Prototype.emptyFunction;
+ var pointer = Event.pointer(event);
+ Object.extend(event, {
+ target: event.srcElement,
+ relatedTarget: Event.relatedTarget(event),
+ pageX: pointer.x,
+ pageY: pointer.y
+ });
+ return Object.extend(event, methods);
+ };
+
+ } else {
+ Event.prototype = Event.prototype || document.createEvent("HTMLEvents")['__proto__'];
+ Object.extend(Event.prototype, methods);
+ return Prototype.K;
+ }
+})();
+
+Object.extend(Event, (function() {
+ var cache = Event.cache;
+
+ function getEventID(element) {
+ if (element._prototypeEventID) return element._prototypeEventID[0];
+ arguments.callee.id = arguments.callee.id || 1;
+ return element._prototypeEventID = [++arguments.callee.id];
+ }
+
+ function getDOMEventName(eventName) {
+ if (eventName && eventName.include(':')) return "dataavailable";
+ return eventName;
+ }
+
+ function getCacheForID(id) {
+ return cache[id] = cache[id] || { };
+ }
+
+ function getWrappersForEventName(id, eventName) {
+ var c = getCacheForID(id);
+ return c[eventName] = c[eventName] || [];
+ }
+
+ function createWrapper(element, eventName, handler) {
+ var id = getEventID(element);
+ var c = getWrappersForEventName(id, eventName);
+ if (c.pluck("handler").include(handler)) return false;
+
+ var wrapper = function(event) {
+ if (!Event || !Event.extend ||
+ (event.eventName && event.eventName != eventName))
+ return false;
+
+ Event.extend(event);
+ handler.call(element, event);
+ };
+
+ wrapper.handler = handler;
+ c.push(wrapper);
+ return wrapper;
+ }
+
+ function findWrapper(id, eventName, handler) {
+ var c = getWrappersForEventName(id, eventName);
+ return c.find(function(wrapper) { return wrapper.handler == handler });
+ }
+
+ function destroyWrapper(id, eventName, handler) {
+ var c = getCacheForID(id);
+ if (!c[eventName]) return false;
+ c[eventName] = c[eventName].without(findWrapper(id, eventName, handler));
+ }
+
+ //commented by Nick for RichFaces
+ /*
+ function destroyCache() {
+ for (var id in cache)
+ for (var eventName in cache[id])
+ cache[id][eventName] = null;
+ }
+
+
+ // Internet Explorer needs to remove event handlers on page unload
+ // in order to avoid memory leaks.
+ if (window.attachEvent) {
+ window.attachEvent("onunload", destroyCache);
+ }
+ */
+ //commented
+
+ // Safari has a dummy event handler on page unload so that it won't
+ // use its bfcache. Safari <= 3.1 has an issue with restoring the "document"
+ // object when page is returned to via the back button using its bfcache.
+ if (Prototype.Browser.WebKit) {
+ window.addEventListener('unload', Prototype.emptyFunction, false);
+ }
+
+ return {
+ //added by Nick for RichFaces
+ getDOMEventName: getDOMEventName,
+ //added
+
+ observe: function(element, eventName, handler) {
+ element = $(element);
+ var name = getDOMEventName(eventName);
+
+ var wrapper = createWrapper(element, eventName, handler);
+ if (!wrapper) return element;
+
+ if (element.addEventListener) {
+ element.addEventListener(name, wrapper, false);
+ } else {
+ element.attachEvent("on" + name, wrapper);
+ }
+
+ return element;
+ },
+
+ stopObserving: function(element, eventName, handler) {
+ element = $(element);
+ var id = getEventID(element), name = getDOMEventName(eventName);
+
+ if (!handler && eventName) {
+ getWrappersForEventName(id, eventName).each(function(wrapper) {
+ element.stopObserving(eventName, wrapper.handler);
+ });
+ return element;
+
+ } else if (!eventName) {
+ Object.keys(getCacheForID(id)).each(function(eventName) {
+ element.stopObserving(eventName);
+ });
+ return element;
+ }
+
+ var wrapper = findWrapper(id, eventName, handler);
+ if (!wrapper) return element;
+
+ if (element.removeEventListener) {
+ element.removeEventListener(name, wrapper, false);
+ } else {
+ element.detachEvent("on" + name, wrapper);
+ }
+
+ destroyWrapper(id, eventName, handler);
+
+ return element;
+ },
+
+ fire: function(element, eventName, memo) {
+ element = $(element);
+ if (element == document && document.createEvent && !element.dispatchEvent)
+ element = document.documentElement;
+
+ var event;
+ if (document.createEvent) {
+ event = document.createEvent("HTMLEvents");
+ event.initEvent("dataavailable", true, true);
+ } else {
+ event = document.createEventObject();
+ event.eventType = "ondataavailable";
+ }
+
+ event.eventName = eventName;
+ event.memo = memo || { };
+
+ if (document.createEvent) {
+ element.dispatchEvent(event);
+ } else {
+ element.fireEvent(event.eventType, event);
+ }
+
+ return Event.extend(event);
+ }
+ };
+})());
+
+Object.extend(Event, Event.Methods);
+
+Element.addMethods({
+ fire: Event.fire,
+ observe: Event.observe,
+ stopObserving: Event.stopObserving
+});
+
+Object.extend(document, {
+ fire: Element.Methods.fire.methodize(),
+ observe: Element.Methods.observe.methodize(),
+ stopObserving: Element.Methods.stopObserving.methodize(),
+ loaded: false
+});
+
+(function() {
+ /* Support for the DOMContentLoaded event is based on work by Dan Webb,
+ Matthias Miller, Dean Edwards and John Resig. */
+
+ var timer;
+
+ function fireContentLoadedEvent() {
+ if (document.loaded) return;
+ if (timer) window.clearInterval(timer);
+ document.fire("dom:loaded");
+ document.loaded = true;
+ }
+
+ if (document.addEventListener) {
+ if (Prototype.Browser.WebKit) {
+ timer = window.setInterval(function() {
+ if (/loaded|complete/.test(document.readyState))
+ fireContentLoadedEvent();
+ }, 0);
+
+ Event.observe(window, "load", fireContentLoadedEvent);
+
+ } else {
+ document.addEventListener("DOMContentLoaded",
+ fireContentLoadedEvent, false);
+ }
+
+ } else {
+ // added by Pavel Yaschenko // http://jira.jboss.com/jira/browse/RF-3879
+
+ // for 1.6.0.3
+ if (document.loaded) return;
+
+ if (document.readyState != "complete") { // added by Pavel Yaschenko
+ document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
+ $("__onDOMContentLoaded").onreadystatechange = function() {
+ if (this.readyState == "complete") {
+ this.onreadystatechange = null;
+ fireContentLoadedEvent();
+ }
+ };
+ } // added by Pavel Yaschenko
+ }
+})();
+/*------------------------------- DEPRECATED -------------------------------*/
+
+Hash.toQueryString = Object.toQueryString;
+
+var Toggle = { display: Element.toggle };
+
+Element.Methods.childOf = Element.Methods.descendantOf;
+
+var Insertion = {
+ Before: function(element, content) {
+ return Element.insert(element, {before:content});
+ },
+
+ Top: function(element, content) {
+ return Element.insert(element, {top:content});
+ },
+
+ Bottom: function(element, content) {
+ return Element.insert(element, {bottom:content});
+ },
+
+ After: function(element, content) {
+ return Element.insert(element, {after:content});
+ }
+};
+
+var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
+
+// This should be moved to script.aculo.us; notice the deprecated methods
+// further below, that map to the newer Element methods.
+var Position = {
+ // set to true if needed, warning: firefox performance problems
+ // NOT neeeded for page scrolling, only if draggable contained in
+ // scrollable elements
+ includeScrollOffsets: false,
+
+ // must be called before calling withinIncludingScrolloffset, every time the
+ // page is scrolled
+ prepare: function() {
+ this.deltaX = window.pageXOffset
+ || document.documentElement.scrollLeft
+ || document.body.scrollLeft
+ || 0;
+ this.deltaY = window.pageYOffset
+ || document.documentElement.scrollTop
+ || document.body.scrollTop
+ || 0;
+ },
+
+ // caches x/y coordinate pair to use with overlap
+ within: function(element, x, y) {
+ if (this.includeScrollOffsets)
+ return this.withinIncludingScrolloffsets(element, x, y);
+ this.xcomp = x;
+ this.ycomp = y;
+ this.offset = Element.cumulativeOffset(element);
+
+ return (y >= this.offset[1] &&
+ y < this.offset[1] + element.offsetHeight &&
+ x >= this.offset[0] &&
+ x < this.offset[0] + element.offsetWidth);
+ },
+
+ withinIncludingScrolloffsets: function(element, x, y) {
+ var offsetcache = Element.cumulativeScrollOffset(element);
+
+ this.xcomp = x + offsetcache[0] - this.deltaX;
+ this.ycomp = y + offsetcache[1] - this.deltaY;
+ this.offset = Element.cumulativeOffset(element);
+
+ return (this.ycomp >= this.offset[1] &&
+ this.ycomp < this.offset[1] + element.offsetHeight &&
+ this.xcomp >= this.offset[0] &&
+ this.xcomp < this.offset[0] + element.offsetWidth);
+ },
+
+ // within must be called directly before
+ overlap: function(mode, element) {
+ if (!mode) return 0;
+ if (mode == 'vertical')
+ return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
+ element.offsetHeight;
+ if (mode == 'horizontal')
+ return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
+ element.offsetWidth;
+ },
+
+ // Deprecation layer -- use newer Element methods now (1.5.2).
+
+ cumulativeOffset: Element.Methods.cumulativeOffset,
+
+ positionedOffset: Element.Methods.positionedOffset,
+
+ absolutize: function(element) {
+ Position.prepare();
+ return Element.absolutize(element);
+ },
+
+ relativize: function(element) {
+ Position.prepare();
+ return Element.relativize(element);
+ },
+
+ realOffset: Element.Methods.cumulativeScrollOffset,
+
+ offsetParent: Element.Methods.getOffsetParent,
+
+ page: Element.Methods.viewportOffset,
+
+ clone: function(source, target, options) {
+ options = options || { };
+ return Element.clonePosition(target, source, options);
+ }
+};
+
+/*--------------------------------------------------------------------------*/
+
+if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
+ function iter(name) {
+ return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
+ }
+
+ instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
+ function(element, className) {
+ className = className.toString().strip();
+ var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
+ return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
+ } : function(element, className) {
+ className = className.toString().strip();
+ var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
+ if (!classNames && !className) return elements;
+
+ var nodes = $(element).getElementsByTagName('*');
+ className = ' ' + className + ' ';
+
+ for (var i = 0, child, cn; child = nodes[i]; i++) {
+ if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
+ (classNames && classNames.all(function(name) {
+ return !name.toString().blank() && cn.include(' ' + name + ' ');
+ }))))
+ elements.push(Element.extend(child));
+ }
+ return elements;
+ };
+
+ return function(className, parentElement) {
+ return $(parentElement || document.body).getElementsByClassName(className);
+ };
+}(Element.Methods);
+
+/*--------------------------------------------------------------------------*/
+
+Element.ClassNames = Class.create();
+Element.ClassNames.prototype = {
+ initialize: function(element) {
+ this.element = $(element);
+ },
+
+ _each: function(iterator) {
+ this.element.className.split(/\s+/).select(function(name) {
+ return name.length > 0;
+ })._each(iterator);
+ },
+
+ set: function(className) {
+ this.element.className = className;
+ },
+
+ add: function(classNameToAdd) {
+ if (this.include(classNameToAdd)) return;
+ this.set($A(this).concat(classNameToAdd).join(' '));
+ },
+
+ remove: function(classNameToRemove) {
+ if (!this.include(classNameToRemove)) return;
+ this.set($A(this).without(classNameToRemove).join(' '));
+ },
+
+ toString: function() {
+ return $A(this).join(' ');
+ }
+};
+
+Object.extend(Element.ClassNames.prototype, Enumerable);
+
+/*--------------------------------------------------------------------------*/
+
+Element.addMethods();
+//memory-leaks sanitizing code
+if (!window.RichFaces) {
+ window.RichFaces = {};
+}
+
+if (!window.RichFaces.Memory) {
+ window.RichFaces.Memory = {
+
+ nodeCleaners: {},
+ componentCleaners: {},
+
+ addCleaner: function (name, cleaner) {
+ this.nodeCleaners[name] = cleaner;
+ },
+
+ addComponentCleaner: function (name, cleaner, checker) {
+ this.componentCleaners[name] = {cleaner: cleaner, checker: checker};
+ },
+
+ applyCleaners: function (node, isAjax, componentNodes) {
+ for (var name in this.nodeCleaners) {
+ this.nodeCleaners[name](node, isAjax);
+ }
+ for (var name in this.componentCleaners) {
+ if (this.componentCleaners[name].checker(node, isAjax))
+ componentNodes.push(node);
+ }
+ },
+
+ _clean: function (oldNode, isAjax, componentNodes) {
+ if (oldNode) {
+ this.applyCleaners(oldNode, isAjax, componentNodes);
+
+ //node.all is quicker than recursive traversing
+ //window doesn't have "all" attribute
+ var all = oldNode.all;
+
+ if (all) {
+ var counter = 0;
+ var length = all.length;
+
+ for (var counter = 0; counter < length; counter++ ) {
+ this.applyCleaners(all[counter], isAjax, componentNodes);
+ }
+ } else {
+ var node = oldNode.firstChild;
+ while (node) {
+ this._clean(node, isAjax, componentNodes);
+ node = node.nextSibling;
+ }
+ }
+ }
+ },
+
+ _cleanComponentNodes: function (oldNodes, isAjax) {
+ for (var i=0; i<oldNodes.length; i++) {
+ var node = oldNodes[i];
+ for (var name in this.componentCleaners) {
+ this.componentCleaners[name].cleaner(node, isAjax);
+ }
+ }
+ },
+
+ clean: function (oldNode, isAjax) {
+ var componentNodes = [];
+ this._clean(oldNode, isAjax, componentNodes);
+ this._cleanComponentNodes(componentNodes, isAjax);
+ componentNodes = null;
+ }
+ };
+
+ window.RichFaces.Memory.addComponentCleaner("richfaces", function(node, isAjax) {
+ var component = node.component;
+ if (component) {
+ var destructorName = component["rich:destructor"];
+ //destructor name is required to be back-compatible
+ if (destructorName) {
+ var destructor = component[destructorName];
+ if (destructor) {
+ destructor.call(component, isAjax);
+ }
+ }
+ }
+ }, function(node, isAjax) {
+ return (node.component && node.component["rich:destructor"]);
+ });
+
+ if (window.attachEvent) {
+ window.attachEvent("onunload", function() {
+ var memory = window.RichFaces.Memory;
+ memory.clean(document);
+ memory.clean(window);
+ });
+ }
+}
+
+//
+/**
+* MyFaces compatibility issue
+**/
+Function.prototype.indexOf = function(){
+ return -1;
+}
+
+/**
+* Clear children
+**/
+
+Element.clearChildren = function(element) {
+ element = $(element);
+ while(element.firstChild) {
+ element.removeChild(element.firstChild);
+ }
+ return element;
+};
+/**
+ * Detect if element is child of another one
+ * @param {DomNode} node
+ * @param {DomNode} supposedParent
+ */
+Element.isChildOf = function(node, supposedParent){
+ while(node && supposedParent !=node) {
+ node = node.parentNode;
+ }
+
+ return supposedParent == node;
+};
+
+if (typeof Node == "undefined") {
+ Node = {
+ ELEMENT_NODE: 1,
+ ATTRIBUTE_NODE: 2,
+ TEXT_NODE: 3,
+ CDATA_SECTION_NODE: 4,
+ ENTITY_REFERENCE_NODE: 5,
+ ENTITY_NODE: 6,
+ PROCESSING_INSTRUCTION_NODE: 7,
+ COMMENT_NODE: 8,
+ DOCUMENT_NODE: 9,
+ DOCUMENT_TYPE_NODE: 10,
+ DOCUMENT_FRAGMENT_NODE: 11,
+ NOTATION_NODE: 12
+ };
+};
+
+Element.isUninitialized = function(element) {
+ if (element) {
+ if (element.nodeType == Node.ELEMENT_NODE) {
+
+ if (!element.parentNode || element.document && element.document.readyState == "uninitialized") {
+ return true;
+ } else
+ {
+ return !Element.descendantOf(element, document.documentElement);
+ }
+
+ return false;
+ }
+ }
+};
+
+if (window.RichFaces && window.RichFaces.Memory) {
+ window.RichFaces.Memory.addCleaner("prototype", function(node, isAjax) {
+ var eventID = node._prototypeEventID ? node._prototypeEventID[0] : undefined;
+ if (eventID) {
+ var cache = Event.cache[eventID];
+
+ for (var eventName in cache) {
+ var wrappers = cache[eventName];
+ var domEventName = Event.getDOMEventName(eventName);
+
+ wrappers.each(function(wrapper) {
+ if (node.removeEventListener) {
+ node.removeEventListener(domEventName, wrapper, false);
+ } else {
+ node.detachEvent("on" + domEventName, wrapper);
+ }
+ });
+
+ cache[eventName] = null;
+ }
+
+ delete Event.cache[eventID];
+ }
+ });
+}
+
+//
+
+/*
+ * Prolog for created Ajax4Jsf library
+ */
+if (!window.A4J) { window.A4J= {};}
+
+//if(window.A4J.AJAX && window.A4J.AJAX.XMLHttpRequest) return;
+/*
+ * ====================================================================
+ * About Sarissa: http://dev.abiss.gr/sarissa
+ * ====================================================================
+ * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.
+ * The library supports Gecko based browsers like Mozilla and Firefox,
+ * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and Opera
+ * @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net
+ * ====================================================================
+ * Licence
+ * ====================================================================
+ * Sarissa is free software distributed under the GNU GPL version 2 (see <a href="gpl.txt">gpl.txt</a>) or higher,
+ * GNU LGPL version 2.1 (see <a href="lgpl.txt">lgpl.txt</a>) or higher and Apache Software License 2.0 or higher
+ * (see <a href="asl.txt">asl.txt</a>). This means you can choose one of the three and use that if you like. If
+ * you make modifications under the ASL, i would appreciate it if you submitted those.
+ * In case your copy of Sarissa does not include the license texts, you may find
+ * them online in various formats at <a href="http://www.gnu.org">http://www.gnu.org</a> and
+ * <a href="http://www.apache.org">http://www.apache.org</a>.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+/**
+ * <p>Sarissa is a utility class. Provides "static" methods for DOMDocument,
+ * DOM Node serialization to XML strings and other utility goodies.</p>
+ * @constructor
+ * @static
+ */
+function Sarissa(){}
+Sarissa.VERSION = "0.9.9.3";
+Sarissa.PARSED_OK = "Document contains no parsing errors";
+Sarissa.PARSED_EMPTY = "Document is empty";
+Sarissa.PARSED_UNKNOWN_ERROR = "Not well-formed or other error";
+Sarissa.IS_ENABLED_TRANSFORM_NODE = false;
+Sarissa.REMOTE_CALL_FLAG = "gr.abiss.sarissa.REMOTE_CALL_FLAG";
+/** @private */
+Sarissa._sarissa_iNsCounter = 0;
+/** @private */
+Sarissa._SARISSA_IEPREFIX4XSLPARAM = "";
+/** @private */
+Sarissa._SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true;
+/** @private */
+Sarissa._SARISSA_HAS_DOM_CREATE_DOCUMENT = Sarissa._SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument;
+/** @private */
+Sarissa._SARISSA_HAS_DOM_FEATURE = Sarissa._SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature;
+/** @private */
+Sarissa._SARISSA_IS_MOZ = Sarissa._SARISSA_HAS_DOM_CREATE_DOCUMENT && Sarissa._SARISSA_HAS_DOM_FEATURE;
+/** @private */
+Sarissa._SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("safari") != -1 || navigator.userAgent.toLowerCase().indexOf("konqueror") != -1;
+/** @private */
+Sarissa._SARISSA_IS_SAFARI_OLD = Sarissa._SARISSA_IS_SAFARI && (parseInt((navigator.userAgent.match(/AppleWebKit\/(\d+)/)||{})[1], 10) < 420);
+/** @private */
+Sarissa._SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
+/** @private */
+Sarissa._SARISSA_IS_OPERA = navigator.userAgent.toLowerCase().indexOf("opera") != -1;
+if(!window.Node || !Node.ELEMENT_NODE){
+ Node = {ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5, ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12};
+}
+
+//This breaks for(x in o) loops in the old Safari
+if(Sarissa._SARISSA_IS_SAFARI_OLD){
+ HTMLHtmlElement = document.createElement("html").constructor;
+ Node = HTMLElement = {};
+ HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__;
+ HTMLDocument = Document = document.constructor;
+ var x = new DOMParser();
+ XMLDocument = x.constructor;
+ Element = x.parseFromString("<Single />", "text/xml").documentElement.constructor;
+ x = null;
+}
+if(typeof XMLDocument == "undefined" && typeof Document !="undefined"){ XMLDocument = Document; }
+
+// IE initialization
+if(Sarissa._SARISSA_IS_IE){
+ // for XSLT parameter names, prefix needed by IE
+ Sarissa._SARISSA_IEPREFIX4XSLPARAM = "xsl:";
+ // used to store the most recent ProgID available out of the above
+ var _SARISSA_DOM_PROGID = "";
+ var _SARISSA_XMLHTTP_PROGID = "";
+ var _SARISSA_DOM_XMLWRITER = "";
+ /**
+ * Called when the sarissa.js file is parsed, to pick most recent
+ * ProgIDs for IE, then gets destroyed.
+ * @memberOf Sarissa
+ * @private
+ * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object
+ * @param enabledList an array of arrays where each array has two items; the index of the PROGID for which a certain feature is enabled
+ */
+ Sarissa.pickRecentProgID = function (idList){
+ // found progID flag
+ var bFound = false, e;
+ var o2Store;
+ for(var i=0; i < idList.length && !bFound; i++){
+ try{
+ var oDoc = new ActiveXObject(idList[i]);
+ o2Store = idList[i];
+ bFound = true;
+ }catch (objException){
+ // trap; try next progID
+ e = objException;
+ }
+ }
+ if (!bFound) {
+ throw "Could not retrieve a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")";
+ }
+ idList = null;
+ return o2Store;
+ };
+ // pick best available MSXML progIDs
+ _SARISSA_DOM_PROGID = null;
+ _SARISSA_THREADEDDOM_PROGID = null;
+ _SARISSA_XSLTEMPLATE_PROGID = null;
+ _SARISSA_XMLHTTP_PROGID = null;
+ // commenting the condition out; we need to redefine XMLHttpRequest
+ // anyway as IE7 hardcodes it to MSXML3.0 causing version problems
+ // between different activex controls
+ //if(!window.XMLHttpRequest){
+ /**
+ * Emulate XMLHttpRequest
+ * @constructor
+ */
+ XMLHttpRequest = function() {
+ if(!_SARISSA_XMLHTTP_PROGID){
+ _SARISSA_XMLHTTP_PROGID = Sarissa.pickRecentProgID(["Msxml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
+ }
+ return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
+ };
+ //}
+ // we dont need this anymore
+ //============================================
+ // Factory methods (IE)
+ //============================================
+ // see non-IE version
+ Sarissa.getDomDocument = function(sUri, sName){
+ if(!_SARISSA_DOM_PROGID){
+ _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID(["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"]);
+ }
+ var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
+ // if a root tag name was provided, we need to load it in the DOM object
+ if (sName){
+ // create an artifical namespace prefix
+ // or reuse existing prefix if applicable
+ var prefix = "";
+ if(sUri){
+ if(sName.indexOf(":") > 1){
+ prefix = sName.substring(0, sName.indexOf(":"));
+ sName = sName.substring(sName.indexOf(":")+1);
+ }else{
+ prefix = "a" + (Sarissa._sarissa_iNsCounter++);
+ }
+ }
+ // use namespaces if a namespace URI exists
+ if(sUri){
+ oDoc.loadXML('<' + prefix+':'+sName + " xmlns:" + prefix + "=\"" + sUri + "\"" + " />");
+ } else {
+ oDoc.loadXML('<' + sName + " />");
+ }
+ }
+ return oDoc;
+ };
+ // see non-IE version
+ Sarissa.getParseErrorText = function (oDoc) {
+ var parseErrorText = Sarissa.PARSED_OK;
+ if(oDoc && oDoc.parseError && oDoc.parseError.errorCode && oDoc.parseError.errorCode != 0){
+ parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason +
+ "\nLocation: " + oDoc.parseError.url +
+ "\nLine Number " + oDoc.parseError.line + ", Column " +
+ oDoc.parseError.linepos +
+ ":\n" + oDoc.parseError.srcText +
+ "\n";
+ for(var i = 0; i < oDoc.parseError.linepos;i++){
+ parseErrorText += "-";
+ }
+ parseErrorText += "^\n";
+ }
+ else if(oDoc.documentElement === null){
+ parseErrorText = Sarissa.PARSED_EMPTY;
+ }
+ return parseErrorText;
+ };
+ // see non-IE version
+ Sarissa.setXpathNamespaces = function(oDoc, sNsSet) {
+ oDoc.setProperty("SelectionLanguage", "XPath");
+ oDoc.setProperty("SelectionNamespaces", sNsSet);
+ };
+ /**
+ * A class that reuses the same XSLT stylesheet for multiple transforms.
+ * @constructor
+ */
+ XSLTProcessor = function(){
+ if(!_SARISSA_XSLTEMPLATE_PROGID){
+ _SARISSA_XSLTEMPLATE_PROGID = Sarissa.pickRecentProgID(["Msxml2.XSLTemplate.6.0", "MSXML2.XSLTemplate.3.0"]);
+ }
+ this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);
+ this.processor = null;
+ };
+ /**
+ * Imports the given XSLT DOM and compiles it to a reusable transform
+ * <b>Note:</b> If the stylesheet was loaded from a URL and contains xsl:import or xsl:include elements,it will be reloaded to resolve those
+ * @argument xslDoc The XSLT DOMDocument to import
+ */
+ XSLTProcessor.prototype.importStylesheet = function(xslDoc){
+ if(!_SARISSA_THREADEDDOM_PROGID){
+ _SARISSA_THREADEDDOM_PROGID = Sarissa.pickRecentProgID(["MSXML2.FreeThreadedDOMDocument.6.0", "MSXML2.FreeThreadedDOMDocument.3.0"]);
+ }
+ xslDoc.setProperty("SelectionLanguage", "XPath");
+ xslDoc.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
+ // convert stylesheet to free threaded
+ var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID);
+ // make included/imported stylesheets work if exist and xsl was originally loaded from url
+ try{
+ converted.resolveExternals = true;
+ converted.setProperty("AllowDocumentFunction", true);
+ }
+ catch(e){
+ // Ignore. "AllowDocumentFunction" is only supported in MSXML 3.0 SP4 and later.
+ }
+ if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() = 'import' or local-name() = 'include']") != null){
+ converted.async = false;
+ converted.load(xslDoc.url);
+ }
+ else {
+ converted.loadXML(xslDoc.xml);
+ }
+ converted.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
+ var output = converted.selectSingleNode("//xsl:output");
+ //this.outputMethod = output ? output.getAttribute("method") : "html";
+ if(output) {
+ this.outputMethod = output.getAttribute("method");
+ }
+ else {
+ delete this.outputMethod;
+ }
+ this.template.stylesheet = converted;
+ this.processor = this.template.createProcessor();
+ // for getParameter and clearParameters
+ this.paramsSet = [];
+ };
+
+ /**
+ * Transform the given XML DOM and return the transformation result as a new DOM document
+ * @argument sourceDoc The XML DOMDocument to transform
+ * @return The transformation result as a DOM Document
+ */
+ XSLTProcessor.prototype.transformToDocument = function(sourceDoc){
+ // fix for bug 1549749
+ var outDoc;
+ if(_SARISSA_THREADEDDOM_PROGID){
+ this.processor.input=sourceDoc;
+ outDoc=new ActiveXObject(_SARISSA_DOM_PROGID);
+ this.processor.output=outDoc;
+ this.processor.transform();
+ return outDoc;
+ }
+ else{
+ if(!_SARISSA_DOM_XMLWRITER){
+ _SARISSA_DOM_XMLWRITER = Sarissa.pickRecentProgID(["Msxml2.MXXMLWriter.6.0", "Msxml2.MXXMLWriter.3.0", "MSXML2.MXXMLWriter", "MSXML.MXXMLWriter", "Microsoft.XMLDOM"]);
+ }
+ this.processor.input = sourceDoc;
+ outDoc = new ActiveXObject(_SARISSA_DOM_XMLWRITER);
+ this.processor.output = outDoc;
+ this.processor.transform();
+ var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
+ oDoc.loadXML(outDoc.output+"");
+ return oDoc;
+ }
+ };
+
+ /**
+ * Transform the given XML DOM and return the transformation result as a new DOM fragment.
+ * <b>Note</b>: The xsl:output method must match the nature of the owner document (XML/HTML).
+ * @argument sourceDoc The XML DOMDocument to transform
+ * @argument ownerDoc The owner of the result fragment
+ * @return The transformation result as a DOM Document
+ */
+ XSLTProcessor.prototype.transformToFragment = function (sourceDoc, ownerDoc) {
+ this.processor.input = sourceDoc;
+ this.processor.transform();
+ var s = this.processor.output;
+ var f = ownerDoc.createDocumentFragment();
+ var container;
+ if (this.outputMethod == 'text') {
+ f.appendChild(ownerDoc.createTextNode(s));
+ } else if (ownerDoc.body && ownerDoc.body.innerHTML) {
+ container = ownerDoc.createElement('div');
+ container.innerHTML = s;
+ while (container.hasChildNodes()) {
+ f.appendChild(container.firstChild);
+ }
+ }
+ else {
+ var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);
+ if (s.substring(0, 5) == '<?xml') {
+ s = s.substring(s.indexOf('?>') + 2);
+ }
+ var xml = ''.concat('<my>', s, '</my>');
+ oDoc.loadXML(xml);
+ container = oDoc.documentElement;
+ while (container.hasChildNodes()) {
+ f.appendChild(container.firstChild);
+ }
+ }
+ return f;
+ };
+
+ /**
+ * Set global XSLT parameter of the imported stylesheet
+ * @argument nsURI The parameter namespace URI
+ * @argument name The parameter base name
+ * @argument value The new parameter value
+ */
+ XSLTProcessor.prototype.setParameter = function(nsURI, name, value){
+ // make value a zero length string if null to allow clearing
+ value = value ? value : "";
+ // nsURI is optional but cannot be null
+ if(nsURI){
+ this.processor.addParameter(name, value, nsURI);
+ }else{
+ this.processor.addParameter(name, value);
+ }
+ // update updated params for getParameter
+ nsURI = "" + (nsURI || "");
+ if(!this.paramsSet[nsURI]){
+ this.paramsSet[nsURI] = [];
+ }
+ this.paramsSet[nsURI][name] = value;
+ };
+ /**
+ * Gets a parameter if previously set by setParameter. Returns null
+ * otherwise
+ * @argument name The parameter base name
+ * @argument value The new parameter value
+ * @return The parameter value if reviously set by setParameter, null otherwise
+ */
+ XSLTProcessor.prototype.getParameter = function(nsURI, name){
+ nsURI = "" + (nsURI || "");
+ if(this.paramsSet[nsURI] && this.paramsSet[nsURI][name]){
+ return this.paramsSet[nsURI][name];
+ }else{
+ return null;
+ }
+ };
+
+ /**
+ * Clear parameters (set them to default values as defined in the stylesheet itself)
+ */
+ XSLTProcessor.prototype.clearParameters = function(){
+ for(var nsURI in this.paramsSet){
+ for(var name in this.paramsSet[nsURI]){
+ if(nsURI!=""){
+ this.processor.addParameter(name, "", nsURI);
+ }else{
+ this.processor.addParameter(name, "");
+ }
+ }
+ }
+ this.paramsSet = [];
+ };
+}else{ /* end IE initialization, try to deal with real browsers now ;-) */
+ if(Sarissa._SARISSA_HAS_DOM_CREATE_DOCUMENT){
+ /**
+ * <p>Ensures the document was loaded correctly, otherwise sets the
+ * parseError to -1 to indicate something went wrong. Internal use</p>
+ * @private
+ */
+ Sarissa.__handleLoad__ = function(oDoc){
+ Sarissa.__setReadyState__(oDoc, 4);
+ };
+ /**
+ * <p>Attached by an event handler to the load event. Internal use.</p>
+ * @private
+ */
+ _sarissa_XMLDocument_onload = function(){
+ Sarissa.__handleLoad__(this);
+ };
+ /**
+ * <p>Sets the readyState property of the given DOM Document object.
+ * Internal use.</p>
+ * @memberOf Sarissa
+ * @private
+ * @argument oDoc the DOM Document object to fire the
+ * readystatechange event
+ * @argument iReadyState the number to change the readystate property to
+ */
+ Sarissa.__setReadyState__ = function(oDoc, iReadyState){
+ oDoc.readyState = iReadyState;
+ oDoc.readystate = iReadyState;
+ if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function") {
+ oDoc.onreadystatechange();
+ }
+ };
+
+ Sarissa.getDomDocument = function(sUri, sName){
+ var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
+ if(!oDoc.onreadystatechange){
+
+ /**
+ * <p>Emulate IE's onreadystatechange attribute</p>
+ */
+ oDoc.onreadystatechange = null;
+ }
+ if(!oDoc.readyState){
+ /**
+ * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p>
+ * <ul><li>1 == LOADING,</li>
+ * <li>2 == LOADED,</li>
+ * <li>3 == INTERACTIVE,</li>
+ * <li>4 == COMPLETED</li></ul>
+ */
+ oDoc.readyState = 0;
+ }
+ oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false);
+ return oDoc;
+ };
+ if(window.XMLDocument){
+ // do nothing
+ }// TODO: check if the new document has content before trying to copynodes, check for error handling in DOM 3 LS
+ else if(Sarissa._SARISSA_HAS_DOM_FEATURE && window.Document && !Document.prototype.load && document.implementation.hasFeature('LS', '3.0')){
+ //Opera 9 may get the XPath branch which gives creates XMLDocument, therefore it doesn't reach here which is good
+ /**
+ * <p>Factory method to obtain a new DOM Document object</p>
+ * @memberOf Sarissa
+ * @argument sUri the namespace of the root node (if any)
+ * @argument sUri the local name of the root node (if any)
+ * @returns a new DOM Document
+ */
+ Sarissa.getDomDocument = function(sUri, sName){
+ var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
+ return oDoc;
+ };
+ }
+ else {
+ Sarissa.getDomDocument = function(sUri, sName){
+ var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);
+ // looks like safari does not create the root element for some unknown reason
+ if(oDoc && (sUri || sName) && !oDoc.documentElement){
+ oDoc.appendChild(oDoc.createElementNS(sUri, sName));
+ }
+ return oDoc;
+ };
+ }
+ }//if(Sarissa._SARISSA_HAS_DOM_CREATE_DOCUMENT)
+}
+//==========================================
+// Common stuff
+//==========================================
+if(!window.DOMParser){
+ if(Sarissa._SARISSA_IS_SAFARI){
+ /*
+ * DOMParser is a utility class, used to construct DOMDocuments from XML strings
+ * @constructor
+ */
+ DOMParser = function() { };
+ /**
+ * Construct a new DOM Document from the given XMLstring
+ * @param sXml the given XML string
+ * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml).
+ * @return a new DOM Document from the given XML string
+ */
+ DOMParser.prototype.parseFromString = function(sXml, contentType){
+ var xmlhttp = new XMLHttpRequest();
+ xmlhttp.open("GET", "data:text/xml;charset=utf-8," + encodeURIComponent(sXml), false);
+ xmlhttp.send(null);
+ return xmlhttp.responseXML;
+ };
+ }else if(Sarissa.getDomDocument && Sarissa.getDomDocument() && Sarissa.getDomDocument(null, "bar").xml){
+ DOMParser = function() { };
+ DOMParser.prototype.parseFromString = function(sXml, contentType){
+ var doc = Sarissa.getDomDocument();
+ doc.loadXML(sXml);
+ return doc;
+ };
+ }
+}
+
+if((typeof(document.importNode) == "undefined") && Sarissa._SARISSA_IS_IE){
+ try{
+ /**
+ * Implementation of importNode for the context window document in IE.
+ * If <code>oNode</code> is a TextNode, <code>bChildren</code> is ignored.
+ * @param oNode the Node to import
+ * @param bChildren whether to include the children of oNode
+ * @returns the imported node for further use
+ */
+ document.importNode = function(oNode, bChildren){
+ var tmp;
+ if (oNode.nodeName=='#text') {
+ return document.createTextNode(oNode.data);
+ }
+ else {
+ var tbody = false;
+ if(oNode.nodeName == "tbody" && oNode.parentNode){
+ oNode = oNode.parentNode;
+ tbody = true;
+ }
+ else if(oNode.nodeName == "tbody" || oNode.nodeName == "tr"){
+ tmp = document.createElement("tr");
+ }
+ else if(oNode.nodeName == "td"){
+ tmp = document.createElement("tr");
+ }
+ else if(oNode.nodeName == "option"){
+ tmp = document.createElement("select");
+ }
+ if(!tmp){
+ tmp = document.createElement("div");
+ }
+ if(bChildren){
+ tmp.innerHTML = oNode.xml ? oNode.xml : oNode.outerHTML;
+ }else{
+ tmp.innerHTML = oNode.xml ? oNode.cloneNode(false).xml : oNode.cloneNode(false).outerHTML;
+ }
+ if (tbody) {
+ return tmp.firstChild.tBodies[0];
+ } else {
+ return tmp.getElementsByTagName("*")[0];
+ }
+ }
+ };
+ }catch(e){ }
+}
+if(!Sarissa.getParseErrorText){
+ /**
+ * <p>Returns a human readable description of the parsing error. Usefull
+ * for debugging. Tip: append the returned error string in a <pre>
+ * element if you want to render it.</p>
+ * <p>Many thanks to Christian Stocker for the initial patch.</p>
+ * @memberOf Sarissa
+ * @argument oDoc The target DOM document
+ * @returns The parsing error description of the target Document in
+ * human readable form (preformated text)
+ */
+ Sarissa.getParseErrorText = function (oDoc){
+ var parseErrorText = Sarissa.PARSED_OK;
+ if(!oDoc.documentElement){
+ parseErrorText = Sarissa.PARSED_EMPTY;
+ } else if(oDoc.documentElement.tagName == "parsererror"){
+ parseErrorText = oDoc.documentElement.firstChild.data;
+ parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data;
+ } else if(oDoc.getElementsByTagName("parsererror").length > 0){
+ var parsererror = oDoc.getElementsByTagName("parsererror")[0];
+ parseErrorText = Sarissa.getText(parsererror, true)+"\n";
+ } else if(oDoc.parseError && oDoc.parseError.errorCode != 0){
+ parseErrorText = Sarissa.PARSED_UNKNOWN_ERROR;
+ }
+ return parseErrorText;
+ };
+}
+/**
+ * Get a string with the concatenated values of all string nodes under the given node
+ * @memberOf Sarissa
+ * @argument oNode the given DOM node
+ * @argument deep whether to recursively scan the children nodes of the given node for text as well. Default is <code>false</code>
+ */
+Sarissa.getText = function(oNode, deep){
+ var s = "";
+ var nodes = oNode.childNodes;
+ for(var i=0; i < nodes.length; i++){
+ var node = nodes[i];
+ var nodeType = node.nodeType;
+ if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){
+ s += node.data;
+ } else if(deep === true && (nodeType == Node.ELEMENT_NODE || nodeType == Node.DOCUMENT_NODE || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
+ s += Sarissa.getText(node, true);
+ }
+ }
+ return s;
+};
+if(!window.XMLSerializer && Sarissa.getDomDocument && Sarissa.getDomDocument("","foo", null).xml){
+ /**
+ * Utility class to serialize DOM Node objects to XML strings
+ * @constructor
+ */
+ XMLSerializer = function(){};
+ /**
+ * Serialize the given DOM Node to an XML string
+ * @param oNode the DOM Node to serialize
+ */
+ XMLSerializer.prototype.serializeToString = function(oNode) {
+ return oNode.xml;
+ };
+}
+
+/**
+ * Strips tags from the given markup string. If the given string is
+ * <code>undefined</code>, <code>null</code> or empty, it is returned as is.
+ * @memberOf Sarissa
+ */
+Sarissa.stripTags = function (s) {
+ return s?s.replace(/<[^>]+>/g,""):s;
+};
+/**
+ * <p>Deletes all child nodes of the given node</p>
+ * @memberOf Sarissa
+ * @argument oNode the Node to empty
+ */
+Sarissa.clearChildNodes = function(oNode) {
+ // need to check for firstChild due to opera 8 bug with hasChildNodes
+ while(oNode.firstChild) {
+ oNode.removeChild(oNode.firstChild);
+ }
+};
+/**
+ * <p> Copies the childNodes of nodeFrom to nodeTo</p>
+ * <p> <b>Note:</b> The second object's original content is deleted before
+ * the copy operation, unless you supply a true third parameter</p>
+ * @memberOf Sarissa
+ * @argument nodeFrom the Node to copy the childNodes from
+ * @argument nodeTo the Node to copy the childNodes to
+ * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
+ */
+Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
+ if(Sarissa._SARISSA_IS_SAFARI && nodeTo.nodeType == Node.DOCUMENT_NODE){ // SAFARI_OLD ??
+ nodeTo = nodeTo.documentElement; //Apparently there's a bug in safari where you can't appendChild to a document node
+ }
+
+ if((!nodeFrom) || (!nodeTo)){
+ throw "Both source and destination nodes must be provided";
+ }
+ if(!bPreserveExisting){
+ Sarissa.clearChildNodes(nodeTo);
+ }
+ var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
+ var nodes = nodeFrom.childNodes;
+ var i;
+ if(typeof(ownerDoc.importNode) != "undefined") {
+ for(i=0;i < nodes.length;i++) {
+ nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
+ }
+ } else {
+ for(i=0;i < nodes.length;i++) {
+ nodeTo.appendChild(nodes[i].cloneNode(true));
+ }
+ }
+};
+
+/**
+ * <p> Moves the childNodes of nodeFrom to nodeTo</p>
+ * <p> <b>Note:</b> The second object's original content is deleted before
+ * the move operation, unless you supply a true third parameter</p>
+ * @memberOf Sarissa
+ * @argument nodeFrom the Node to copy the childNodes from
+ * @argument nodeTo the Node to copy the childNodes to
+ * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is
+ */
+Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
+ if((!nodeFrom) || (!nodeTo)){
+ throw "Both source and destination nodes must be provided";
+ }
+ if(!bPreserveExisting){
+ Sarissa.clearChildNodes(nodeTo);
+ }
+ var nodes = nodeFrom.childNodes;
+ // if within the same doc, just move, else copy and delete
+ if(nodeFrom.ownerDocument == nodeTo.ownerDocument){
+ while(nodeFrom.firstChild){
+ nodeTo.appendChild(nodeFrom.firstChild);
+ }
+ } else {
+ var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
+ var i;
+ if(typeof(ownerDoc.importNode) != "undefined") {
+ for(i=0;i < nodes.length;i++) {
+ nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
+ }
+ }else{
+ for(i=0;i < nodes.length;i++) {
+ nodeTo.appendChild(nodes[i].cloneNode(true));
+ }
+ }
+ Sarissa.clearChildNodes(nodeFrom);
+ }
+};
+
+/**
+ * <p>Serialize any <strong>non</strong> DOM object to an XML string. All properties are serialized using the property name
+ * as the XML element name. Array elements are rendered as <code>array-item</code> elements,
+ * using their index/key as the value of the <code>key</code> attribute.</p>
+ * @memberOf Sarissa
+ * @argument anyObject the object to serialize
+ * @argument objectName a name for that object
+ * @return the XML serialization of the given object as a string
+ */
+Sarissa.xmlize = function(anyObject, objectName, indentSpace){
+ indentSpace = indentSpace?indentSpace:'';
+ var s = indentSpace + '<' + objectName + '>';
+ var isLeaf = false;
+ if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String || anyObject instanceof Boolean || anyObject instanceof Date){
+ s += Sarissa.escape(""+anyObject);
+ isLeaf = true;
+ }else{
+ s += "\n";
+ var isArrayItem = anyObject instanceof Array;
+ for(var name in anyObject){
+ s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + " ");
+ }
+ s += indentSpace;
+ }
+ return (s += (objectName.indexOf(' ')!=-1?"</array-item>\n":"</" + objectName + ">\n"));
+};
+
+/**
+ * Escape the given string chacters that correspond to the five predefined XML entities
+ * @memberOf Sarissa
+ * @param sXml the string to escape
+ */
+Sarissa.escape = function(sXml){
+ return sXml.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
+};
+
+/**
+ * Unescape the given string. This turns the occurences of the predefined XML
+ * entities to become the characters they represent correspond to the five predefined XML entities
+ * @memberOf Sarissa
+ * @param sXml the string to unescape
+ */
+Sarissa.unescape = function(sXml){
+ return sXml.replace(/'/g,"'").replace(/"/g,"\"").replace(/>/g,">").replace(/</g,"<").replace(/&/g,"&");
+};
+
+/** @private */
+Sarissa.updateCursor = function(oTargetElement, sValue) {
+ if(oTargetElement && oTargetElement.style && oTargetElement.style.cursor != undefined ){
+ oTargetElement.style.cursor = sValue;
+ }
+};
+
+/**
+ * Asynchronously update an element with response of a GET request on the given URL. Passing a configured XSLT
+ * processor will result in transforming and updating oNode before using it to update oTargetElement.
+ * You can also pass a callback function to be executed when the update is finished. The function will be called as
+ * <code>functionName(oNode, oTargetElement);</code>
+ * @memberOf Sarissa
+ * @param sFromUrl the URL to make the request to
+ * @param oTargetElement the element to update
+ * @param xsltproc (optional) the transformer to use on the returned
+ * content before updating the target element with it
+ * @param callback (optional) a Function object to execute once the update is finished successfuly, called as <code>callback(sFromUrl, oTargetElement)</code>.
+ * In case an exception is thrown during execution, the callback is called as called as <code>callback(sFromUrl, oTargetElement, oException)</code>
+ * @param skipCache (optional) whether to skip any cache
+ */
+Sarissa.updateContentFromURI = function(sFromUrl, oTargetElement, xsltproc, callback, skipCache) {
+ try{
+ Sarissa.updateCursor(oTargetElement, "wait");
+ var xmlhttp = new XMLHttpRequest();
+ xmlhttp.open("GET", sFromUrl, true);
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4) {
+ try{
+ var oDomDoc = xmlhttp.responseXML;
+ if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) == Sarissa.PARSED_OK){
+ Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement, xsltproc);
+ callback(sFromUrl, oTargetElement);
+ }
+ else{
+ throw Sarissa.getParseErrorText(oDomDoc);
+ }
+ }
+ catch(e){
+ if(callback){
+ callback(sFromUrl, oTargetElement, e);
+ }
+ else{
+ throw e;
+ }
+ }
+ }
+ };
+ if (skipCache) {
+ var oldage = "Sat, 1 Jan 2000 00:00:00 GMT";
+ xmlhttp.setRequestHeader("If-Modified-Since", oldage);
+ }
+ xmlhttp.send("");
+ }
+ catch(e){
+ Sarissa.updateCursor(oTargetElement, "auto");
+ if(callback){
+ callback(sFromUrl, oTargetElement, e);
+ }
+ else{
+ throw e;
+ }
+ }
+};
+
+/**
+ * Update an element's content with the given DOM node. Passing a configured XSLT
+ * processor will result in transforming and updating oNode before using it to update oTargetElement.
+ * You can also pass a callback function to be executed when the update is finished. The function will be called as
+ * <code>functionName(oNode, oTargetElement);</code>
+ * @memberOf Sarissa
+ * @param oNode the URL to make the request to
+ * @param oTargetElement the element to update
+ * @param xsltproc (optional) the transformer to use on the given
+ * DOM node before updating the target element with it
+ */
+Sarissa.updateContentFromNode = function(oNode, oTargetElement, xsltproc) {
+ try {
+ Sarissa.updateCursor(oTargetElement, "wait");
+ Sarissa.clearChildNodes(oTargetElement);
+ // check for parsing errors
+ var ownerDoc = oNode.nodeType == Node.DOCUMENT_NODE?oNode:oNode.ownerDocument;
+ if(ownerDoc.parseError && ownerDoc.parseError.errorCode != 0) {
+ var pre = document.createElement("pre");
+ pre.appendChild(document.createTextNode(Sarissa.getParseErrorText(ownerDoc)));
+ oTargetElement.appendChild(pre);
+ }
+ else {
+ // transform if appropriate
+ if(xsltproc) {
+ oNode = xsltproc.transformToDocument(oNode);
+ }
+ // be smart, maybe the user wants to display the source instead
+ if(oTargetElement.tagName.toLowerCase() == "textarea" || oTargetElement.tagName.toLowerCase() == "input") {
+ oTargetElement.value = new XMLSerializer().serializeToString(oNode);
+ }
+ else {
+ // ok that was not smart; it was paranoid. Keep up the good work by trying to use DOM instead of innerHTML
+ if(oNode.nodeType == Node.DOCUMENT_NODE || oNode.ownerDocument.documentElement == oNode) {
+ oTargetElement.innerHTML = new XMLSerializer().serializeToString(oNode);
+ }
+ else{
+ oTargetElement.appendChild(oTargetElement.ownerDocument.importNode(oNode, true));
+ }
+ }
+ }
+ }
+ catch(e) {
+ throw e;
+ }
+ finally{
+ Sarissa.updateCursor(oTargetElement, "auto");
+ }
+};
+
+
+/**
+ * Creates an HTTP URL query string from the given HTML form data
+ * @memberOf Sarissa
+ */
+Sarissa.formToQueryString = function(oForm){
+ var qs = "";
+ for(var i = 0;i < oForm.elements.length;i++) {
+ var oField = oForm.elements[i];
+ var sFieldName = oField.getAttribute("name") ? oField.getAttribute("name") : oField.getAttribute("id");
+ // ensure we got a proper name/id and that the field is not disabled
+ if(sFieldName &&
+ ((!oField.disabled) || oField.type == "hidden")) {
+ switch(oField.type) {
+ case "hidden":
+ case "text":
+ case "textarea":
+ case "password":
+ qs += sFieldName + "=" + encodeURIComponent(oField.value) + "&";
+ break;
+ case "select-one":
+ qs += sFieldName + "=" + encodeURIComponent(oField.options[oField.selectedIndex].value) + "&";
+ break;
+ case "select-multiple":
+ for (var j = 0; j < oField.length; j++) {
+ var optElem = oField.options[j];
+ if (optElem.selected === true) {
+ qs += sFieldName + "[]" + "=" + encodeURIComponent(optElem.value) + "&";
+ }
+ }
+ break;
+ case "checkbox":
+ case "radio":
+ if(oField.checked) {
+ qs += sFieldName + "=" + encodeURIComponent(oField.value) + "&";
+ }
+ break;
+ }
+ }
+ }
+ // return after removing last '&'
+ return qs.substr(0, qs.length - 1);
+};
+
+
+/**
+ * Asynchronously update an element with response of an XMLHttpRequest-based emulation of a form submission. <p>The form <code>action</code> and
+ * <code>method</code> attributess will be followed. Passing a configured XSLT processor will result in
+ * transforming and updating the server response before using it to update the target element.
+ * You can also pass a callback function to be executed when the update is finished. The function will be called as
+ * <code>functionName(oNode, oTargetElement);</code></p>
+ * <p>Here is an example of using this in a form element:</p>
+ * <pre name="code" class="xml">
+ * <div id="targetId"> this content will be updated</div>
+ * <form action="/my/form/handler" method="post"
+ * onbeforesubmit="return Sarissa.updateContentFromForm(this, document.getElementById('targetId'));"><pre>
+ * <p>If JavaScript is supported, the form will not be submitted. Instead, Sarissa will
+ * scan the form and make an appropriate AJAX request, also adding a parameter
+ * to signal to the server that this is an AJAX call. The parameter is
+ * constructed as <code>Sarissa.REMOTE_CALL_FLAG = "=true"</code> so you can change the name in your webpage
+ * simply by assigning another value to Sarissa.REMOTE_CALL_FLAG. If JavaScript is not supported
+ * the form will be submitted normally.
+ * @memberOf Sarissa
+ * @param oForm the form submition to emulate
+ * @param oTargetElement the element to update
+ * @param xsltproc (optional) the transformer to use on the returned
+ * content before updating the target element with it
+ * @param callback (optional) a Function object to execute once the update is finished successfuly, called as <code>callback(oNode, oTargetElement)</code>.
+ * In case an exception occurs during excecution and a callback function was provided, the exception is cought and the callback is called as
+ * <code>callback(oForm, oTargetElement, exception)</code>
+ */
+Sarissa.updateContentFromForm = function(oForm, oTargetElement, xsltproc, callback) {
+ try{
+ Sarissa.updateCursor(oTargetElement, "wait");
+ // build parameters from form fields
+ var params = Sarissa.formToQueryString(oForm) + "&" + Sarissa.REMOTE_CALL_FLAG + "=true";
+ var xmlhttp = new XMLHttpRequest();
+ var bUseGet = oForm.getAttribute("method") && oForm.getAttribute("method").toLowerCase() == "get";
+ if(bUseGet) {
+ xmlhttp.open("GET", oForm.getAttribute("action")+"?"+params, true);
+ }
+ else{
+ xmlhttp.open('POST', oForm.getAttribute("action"), true);
+ xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ xmlhttp.setRequestHeader("Content-length", params.length);
+ xmlhttp.setRequestHeader("Connection", "close");
+ }
+ xmlhttp.onreadystatechange = function() {
+ try{
+ if (xmlhttp.readyState == 4) {
+ var oDomDoc = xmlhttp.responseXML;
+ if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) == Sarissa.PARSED_OK){
+ Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement, xsltproc);
+ callback(oForm, oTargetElement);
+ }
+ else{
+ throw Sarissa.getParseErrorText(oDomDoc);
+ }
+ }
+ }
+ catch(e){
+ if(callback){
+ callback(oForm, oTargetElement, e);
+ }
+ else{
+ throw e;
+ }
+ }
+ };
+ xmlhttp.send(bUseGet?"":params);
+ }
+ catch(e){
+ Sarissa.updateCursor(oTargetElement, "auto");
+ if(callback){
+ callback(oForm, oTargetElement, e);
+ }
+ else{
+ throw e;
+ }
+ }
+ return false;
+};
+
+// EOF
+// Global Variables
+// var timeout = null;
+
+// TODO - use sarissa for standard XMLHttpRequest Support.
+
+
+// AJAX-JSF AJAX-like library, for communicate with view Tree on server side.
+
+// Modified by Alexander J. Smirnov to use as JSF AJAX-like components.
+
+A4J.AJAX = {};
+
+/**
+ * XMLHttp transport class - incapsulate most of client-specifiv functions for call server requests.
+ */
+A4J.AJAX.XMLHttpRequest = function(query){
+ this._query = query;
+
+ // Store document element, to check page replacement.
+ this._documentElement = window.document.documentElement;
+ };
+
+A4J.AJAX.XMLHttpRequest.prototype = {
+ _query : null,
+ _timeout : 0,
+ _timeoutID : null,
+ onready : null,
+ _parsingStatus : Sarissa.PARSED_EMPTY,
+ _errorMessage : "XML Response object not set",
+ _contentType : null,
+ _onerror : function(req,status,message) {
+ // Status not 200 - error !
+ // window.alert(message);
+ if(status !=599 && req.getResponseText()){
+ A4J.AJAX.replacePage(req);
+ }
+ },
+ onfinish : null,
+ options : {},
+ domEvt : null,
+ form : null,
+ _request : null,
+ _aborted : false,
+ _documentElement : null,
+ setRequestTimeout : function(timeout){
+ this._timeout = timeout;
+ },
+ /**
+ * Send request to server with parameters from query ( POST or GET depend on client type )
+ */
+ send : function(){
+ this._request = new XMLHttpRequest();
+ var _this = this;
+ this._request.onreadystatechange = function(){
+ if(window.document.documentElement != _this._documentElement){
+ LOG.warn("Page for current request have been unloaded - abort processing" );
+ _this.abort();
+ return;
+ };
+ if(_this._aborted){
+ return;
+ };
+ LOG.debug("Reqest state : "+_this._request.readyState );
+ if (_this._request.readyState == 4 ) {
+ LOG.debug("Reqest end with state 4");
+ if(_this._timeoutID){
+ window.clearTimeout(_this._timeoutID);
+ }
+ var requestStatus;
+ var requestStatusText;
+ try{
+ requestStatus = _this._request.status;
+ requestStatusText = _this._request.statusText;
+ } catch(e){
+ LOG.error("request don't have status code - network problem, "+e.message);
+ requestStatus = 599;
+ requestStatusText = "Network error";
+ }
+ if(requestStatus == 200){
+ try {
+ LOG.debug("Response with content-type: "+ _this.getResponseHeader('Content-Type'));
+ LOG.debug("Full response content: ", _this.getResponseText());
+ } catch(e) {
+ // IE Can throw exception for any responses
+ }
+ // Prepare XML, if exist.
+ if(_this._request.responseXML ){
+ _this._parsingStatus = Sarissa.getParseErrorText(_this._request.responseXML);
+ if(_this._parsingStatus == Sarissa.PARSED_OK && Sarissa.setXpathNamespaces ){
+ Sarissa.setXpathNamespaces(_this._request.responseXML,"xmlns='http://www.w3.org/1999/xhtml'");
+ }
+ }
+ if(_this.onready){
+ _this.onready(_this);
+ }
+
+ } else {
+ _this._errorMessage = "Reqest error, status : "+requestStatus +" " + requestStatusText ;
+ LOG.error(_this._errorMessage);
+ if(typeof(_this._onerror) == "function"){
+ _this._onerror(_this,requestStatus,_this._errorMessage);
+ }
+ if (_this.onfinish)
+ {
+ _this.onfinish(_this);
+ }
+ }
+
+ _this = undefined;
+ }
+ }; //this._onReady;
+ try{
+ LOG.debug("Start XmlHttpRequest");
+ this._request.open('POST', this._query.getActionUrl("") , true);
+ // Query use utf-8 encoding for prepare urlencode data, force request content-type and charset.
+ var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
+ this._request.setRequestHeader( "Content-Type", contentType);
+ } catch(e){
+ // Opera 7-8 - force get
+ LOG.debug("XmlHttpRequest not support setRequestHeader - use GET instead of POST");
+ this._request.open('GET', this._query.getActionUrl("")+"?"+this._query.getQueryString() , true);
+ }
+ // send data.
+ this._request.send(this._query.getQueryString());
+ if(this._timeout > 0){
+ this._timeoutID = window.setTimeout(function(){
+ LOG.warn("request stopped due to timeout");
+ if(!_this._aborted){
+ A4J.AJAX.status(_this.containerId,_this.options.status,false);
+ if(typeof(A4J.AJAX.onAbort) == "function"){
+ A4J.AJAX.onAbort(_this);
+ }
+ }
+ _this._aborted=true;
+ _this._request.abort();
+ if(_this._onerror){
+ _this._errorMessage = "Request timeout";
+ _this._onerror(_this,500,_this._errorMessage);
+ }
+ if(_this.onfinish){
+ _this.onfinish(_this);
+ }
+ _this._request=undefined;
+ _this = undefined;
+ },this._timeout);
+ }
+ },
+
+ abort: function(){
+ if(!this._aborted){
+ A4J.AJAX.status(this.containerId,this.options.status,false);
+ if(typeof(A4J.AJAX.onAbort) == "function"){
+ A4J.AJAX.onAbort(this);
+ }
+ }
+ this._aborted=true;
+ if(this._request){
+ try{
+// this._request.abort();
+ if(this._timeoutID){
+ window.clearTimeout(this._timeoutID);
+ }
+ } catch (e){
+ LOG.warn("Exception for abort current request "+e.Message);
+ }
+ }
+ },
+ getResponseText : function(){
+ try {
+ return this._request.responseText;
+ } catch(e){
+ return null;
+ }
+ },
+ getError : function(){
+ return this._errorMessage;
+ },
+ getParserStatus : function(){
+ return this._parsingStatus;
+ },
+ getContentType : function(){
+ if(!this._contentType){
+ var contentType = this.getResponseHeader('Content-Type');
+ if(contentType){
+ var i = contentType.indexOf(';');
+ if( i >= 0 ){
+ this._contentType = contentType.substring(0,i);
+ } else {
+ this._contentType = contentType;
+ }
+ } else {
+ this._contentType="text/html";
+ }
+ }
+ return this._contentType;
+ },
+ getResponseHeader : function(name){
+ var result;
+ // Different behavior - for non-existing headers, Firefox throws exception,
+ // IE return "" ,
+ try{
+ result = this._request.getResponseHeader(name);
+ if(result === ""){
+ result = undefined;
+ }
+ } catch(e) {
+ }
+ if(!result){
+ // Header not exist or Opera <=8.0 error. Try to find <meta > tag with same name.
+ LOG.debug("Header "+name+" not found, search in <meta>");
+ if(this._parsingStatus == Sarissa.PARSED_OK){
+ var metas = this.getElementsByTagName("meta");
+ for(var i = 0; i < metas.length;i++){
+ var meta = metas[i];
+ LOG.debug("Find <meta name='"+meta.getAttribute('name')+"' content='"+meta.getAttribute('content')+"'>");
+ if(meta.getAttribute("name") == name){
+ result = meta.getAttribute("content");
+ break;
+ }
+ }
+ }
+
+ }
+ return result;
+ },
+ /**
+ * get elements with elementname in responseXML or, if present - in element.
+ */
+ getElementsByTagName : function(elementname,element){
+ if(!element){
+ element = this._request.responseXML;
+ }
+ LOG.debug("search for elements by name '"+elementname+"' "+" in element "+element.nodeName);
+ var elements;
+ try
+ {
+ elements = element.selectNodes(".//*[local-name()=\""+
+ elementname +"\"]");
+ }
+ catch (ex) {
+ try {
+ elements = element.getElementsByTagName(elementname);
+ } catch(nf){
+ LOG.debug("getElementsByTagName found no elements, "+nf.Message);
+ }
+ }
+// return document.getElementsByTagName(tagName);
+// elements = element.getElementsByTagNameNS("http://www.w3.org/1999/xhtml",elementname);
+// LOG.debug("getElementsByTagNameNS found "+elements.length);
+ return elements;
+ },
+ /**
+ * Find element in response by ID. Since in IE response not validated, use selectSingleNode instead.
+ */
+ getElementById : function(id){
+ // first attempt - .getElementById.
+ var oDoc = this._request.responseXML;
+ if(oDoc){
+ if(typeof(oDoc.getElementById) != 'undefined') {
+ LOG.debug("call getElementById for id= "+id);
+ return oDoc.getElementById(id);
+ }
+ else if(typeof(oDoc.selectSingleNode) != "undefined") {
+ LOG.debug("call selectSingleNode for id= "+id);
+ return oDoc.selectSingleNode("//*[@id='"+id+"']"); /* XPATH istead of ID */
+ }
+ // nodeFromID not worked since XML validation disabled by
+ // default for MS
+ else if(typeof(oDoc.nodeFromID) != "undefined") {
+ LOG.debug("call nodeFromID for id= "+id);
+ return oDoc.nodeFromID(id);
+ }
+ LOG.error("No functions for getElementById found ");
+ } else {
+ LOG.debug("No parsed XML document in response");
+ }
+ return null;
+
+ },
+
+ getJSON : function(id){
+ var data;
+ var dataElement = this.getElementById(id);
+ if(dataElement){
+ try {
+ data = Sarissa.getText(dataElement,true);
+ data = window.eval('('+data+')');
+ } catch(e){
+ LOG.error("Error on parsing JSON data "+e.message,data);
+ }
+ }
+ return data;
+ },
+
+ _evaluateScript: function(node) {
+ var includeComments = !A4J.AJAX.isXhtmlScriptMode();
+ var newscript = A4J.AJAX.getText(node, includeComments) ; // TODO - Mozilla disable innerHTML in XML page ..."";
+
+ try {
+ LOG.debug("Evaluate script replaced area in document: ", newscript);
+ if (window.execScript) {
+ window.execScript( newscript );
+ } else {
+ window.eval(newscript);
+ }
+ LOG.debug("Script evaluation succeeded");
+ } catch(e){
+ LOG.error("ERROR Evaluate script: Error name: " + e.name + e.message?". Error message: "+e.message:"");
+ }
+ },
+
+ evaluateQueueScript: function() {
+ var queueScript = this.getElementById('org.ajax4jsf.queue_script');
+ if (queueScript) {
+ this._evaluateScript(queueScript);
+ }
+ },
+
+ evalScripts : function(node, isLast){
+ var newscripts = this.getElementsByTagName("script",node);
+ LOG.debug("Scripts in updated part count : " + newscripts.length);
+ if( newscripts.length > 0 ){
+ var _this = this;
+ window.setTimeout(function() {
+ for (var i = 0; i < newscripts.length; i++){
+ _this._evaluateScript(newscripts[i]);
+ }
+ newscripts = null;
+ if (isLast)
+ {
+ _this.doFinish();
+ }
+ _this = undefined;
+ }, 0);
+ } else
+ {
+ if (isLast)
+ {
+ this.doFinish();
+ }
+ }
+ },
+
+ /**
+ * Update DOM element with given ID by element with same ID in parsed responseXML
+ */
+ updatePagePart : function(id, isLast){
+ var newnode = this.getElementById(id);
+ if( ! newnode )
+ {
+ LOG.error("New node for ID "+id+" is not present in response");
+ if (isLast)
+ {
+ this.doFinish();
+ }
+ return;
+ }
+ var oldnode = window.document.getElementById(id);
+ if ( oldnode ) {
+
+ // Remove unload prototype events for a removed elements.
+ if (window.RichFaces && window.RichFaces.Memory) {
+ window.RichFaces.Memory.clean(oldnode, true);
+ }
+
+ var anchor = oldnode.parentNode;
+ if(!window.opera && oldnode.outerHTML && !oldnode.tagName.match( /(tbody|thead|tfoot|tr|th|td)/i ) ){
+ LOG.debug("Replace content of node by outerHTML()");
+ try {
+ oldnode.innerHTML = "";
+ } catch(e){
+ LOG.error("Error to clear node content by innerHTML "+e.message);
+ Sarissa.clearChildNodes(oldnode);
+ }
+ oldnode.outerHTML = new XMLSerializer().serializeToString(newnode);
+ } else {
+ // need to check for firstChild due to opera 8 bug with hasChildNodes
+ Sarissa.clearChildNodes(oldnode);
+ var importednode = window.document.importNode(newnode, true);
+ //importednode.innerHTML = importednode.innerHTML;
+ LOG.debug("Replace content of node by replaceChild()");
+ anchor.replaceChild(importednode,oldnode);
+ }
+
+ // re-execute all script fragments in imported subtree...
+ // TODO - opera 8 run scripts at replace content stage.
+ if(!A4J.AJAX._scriptEvaluated){
+ this.evalScripts(newnode, isLast);
+ }
+ LOG.debug("Update part of page for Id: "+id + " successful");
+ } else {
+ LOG.warn("Node for replace by response with id "+id+" not found in document");
+ if (!A4J.AJAX._scriptEvaluated && isLast)
+ {
+ this.doFinish();
+ }
+ }
+
+ if (A4J.AJAX._scriptEvaluated && isLast)
+ {
+ this.doFinish();
+ }
+
+ },
+
+ doFinish: function() {
+ if(this.onfinish){
+ this.onfinish(this);
+ }
+ },
+
+ appendNewHeadElements : function(callback){
+ // Append scripts and styles to head, if not presented in page before.
+ var includes = this._appendNewElements("script","src",null,null,["type","language","charset"]);
+
+ var _this = this;
+ includes.concat( this._appendNewElements("link","href","class",["component","user"],["type","rev","media"],{"class": "className"},
+ function (element, script) {
+ //IE requires to re-set rel or href after insertion to initialize correctly
+ //see http://jira.jboss.com/jira/browse/RF-1627#action_12394642
+ _this._copyAttribute(element,script,"rel");
+ }
+ ));
+
+ if ( includes.length == 0) {
+ callback();
+ return;
+ }
+
+ A4J.AJAX.headElementsCounter = includes.length;
+
+ var onReadyStateChange = function () {
+ if (this.readyState == 'loaded' || this.readyState == 'complete') {
+ this.onreadystatechange = null;
+ this.onload = null;
+ callback();
+ }
+ };
+ var onLoad = function () {
+ this.onreadystatechange = null;
+ this.onload = null;
+ callback();
+ };
+ for (var i = 0; i<includes.length; i++)
+ {
+ includes[i].onreadystatechange = onReadyStateChange;
+ includes[i].onload = onLoad;
+ }
+ },
+
+ _appendNewElements : function(tag,href,role,roles,attributes,mappings,callback){
+ var head = document.getElementsByTagName("head")[0]||document.documentElement;
+ var newscripts = this.getElementsByTagName(tag);
+ var oldscripts = document.getElementsByTagName(tag);
+ var mappedRole = (mappings && mappings[role]) || role;
+ var elements = [];
+
+ var roleAnchors = {};
+ if (roles) {
+ var i = 0;
+
+ for(var j = 0; j < oldscripts.length; j++){
+ var oldscript = oldscripts[j];
+ var scriptRole = oldscript[mappedRole];
+
+ for ( ; i < roles.length && roles[i] != scriptRole; i++) {
+ roleAnchors[roles[i]] = oldscript;
+ }
+
+ if (i == roles.length) {
+ break;
+ }
+ }
+ }
+
+ for(var i=0 ; i<newscripts.length;i++){
+ var element = newscripts[i];
+ var src = element.getAttribute(href);
+ var elementRole;
+
+ if (roles) {
+ elementRole = element.getAttribute(role);
+ }
+
+ if(src){
+ var exist = false;
+ LOG.debug("<"+tag+"> in response with src="+src);
+ for(var j = 0 ; j < oldscripts.length; j++){
+ if(this._noSessionHref(src) == this._noSessionHref(oldscripts[j].getAttribute(href))){
+ LOG.debug("Such element exist in document");
+
+ if (role) {
+ var oldRole = oldscripts[j][mappedRole];
+ if ((!elementRole ^ !oldRole) || (elementRole && oldRole && elementRole != oldRole)) {
+ LOG.warn("Roles are different");
+ }
+ }
+
+ exist = true;
+ break;
+ }
+ }
+ if(!exist){
+ // var script = window.document.importNode(element,true); //
+ var script = document.createElement(tag);
+ script.setAttribute(href,src);
+ for(var j = 0 ; j < attributes.length; j++){
+ this._copyAttribute(element,script,attributes[j]);
+ }
+
+ if (elementRole) {
+ script[mappedRole] = elementRole;
+ }
+
+ LOG.debug("append element to document");
+
+ for ( var j = 0; j < A4J.AJAX._headTransformers.length; j++) {
+ A4J.AJAX._headTransformers[j](script);
+ }
+
+ var anchor = roleAnchors[elementRole];
+ if (anchor && anchor.parentNode) {
+ anchor.parentNode.insertBefore(script, anchor);
+ } else {
+ head.appendChild(script);
+ }
+
+ if (callback) {
+ callback(element,script);
+ }
+ if (tag!="link" || script.type.toLowerCase()=="text/javascript") elements.push(script);
+ }
+ }
+ }
+ return elements;
+ },
+
+ _noSessionHref : function(href){
+ var cref = href;
+ if(href){
+ var sessionid = href.lastIndexOf(";jsessionid=");
+ if(sessionid>0){
+ cref = href.substring(0,sessionid);
+ var params = href.lastIndexOf("?");
+ if(params>sessionid){
+ cref=cref+href.substring(params);
+ }
+ }
+ }
+ return cref;
+ },
+
+ _copyAttribute : function(src,dst,attr){
+ var value = src.getAttribute(attr);
+ if(value){
+ dst.setAttribute(attr,value);
+ }
+ }
+
+};
+
+//Listeners should be notified
+A4J.AJAX.Listener = function(onafterajax){
+ this.onafterajax = onafterajax;
+};
+
+A4J.AJAX.AjaxListener = function(type, callback){
+ this[type] = callback;
+};
+
+A4J.AJAX._listeners= [];
+A4J.AJAX.AddListener = function(listener){
+ A4J.AJAX._listeners.push(listener);
+};
+A4J.AJAX.removeListeners = function(listener){
+ A4J.AJAX._listeners = [];
+};
+A4J.AJAX.removeListener = function(listener){
+ for (var i=A4J.AJAX._listeners.length-1;i>=0;i--){
+ if (A4J.AJAX._listeners[i] == listener){
+ A4J.AJAX._listeners.splice(i,1);
+ }
+ }
+};
+
+
+//head element transformers
+A4J.AJAX.HeadElementTransformer = function(elt){
+ this.elt = elt;
+};
+
+A4J.AJAX._headTransformers = [];
+A4J.AJAX.AddHeadElementTransformer = function(listener){
+ A4J.AJAX._headTransformers.push(listener);
+};
+
+A4J.AJAX.SetZeroRequestDelay = function(options) {
+ if (typeof options.requestDelay == "undefined") {
+ options.requestDelay = 0;
+ }
+};
+
+// pollers timerId's
+A4J.AJAX._pollers = {};
+/*
+ *
+ *
+ */
+A4J.AJAX.Poll = function( containerId, form, options ) {
+ A4J.AJAX.StopPoll(options.pollId);
+ if(!options.onerror){
+ options.onerror = function(req,status,message){
+ if(typeof(A4J.AJAX.onError)== "function"){
+ A4J.AJAX.onError(req,status,message);
+ }
+ // For error, re-submit request.
+ A4J.AJAX.Poll(containerId,form,options);
+ };
+ }
+
+ if (!options.onqueuerequestdrop) {
+ options.onqueuerequestdrop = function() {
+ A4J.AJAX.Poll(containerId,form,options);
+ };
+ }
+
+ A4J.AJAX.SetZeroRequestDelay(options);
+
+ A4J.AJAX._pollers[options.pollId] = window.setTimeout(function(){
+ A4J.AJAX._pollers[options.pollId]=undefined;
+ if((typeof(options.onsubmit) == 'function') && (options.onsubmit()==false)){
+ // Onsubmit disable current poll, start next interval.
+ A4J.AJAX.Poll(containerId,form,options);
+ } else {
+ A4J.AJAX.Submit(containerId,form,null,options);
+ }
+ },options.pollinterval);
+};
+
+A4J.AJAX.StopPoll = function( Id ) {
+ if(A4J.AJAX._pollers[Id]){
+ window.clearTimeout(A4J.AJAX._pollers[Id]);
+ A4J.AJAX._pollers[Id] = undefined;
+ }
+};
+
+/*
+ *
+ *
+ */
+A4J.AJAX.Push = function( containerId, form, options ) {
+ A4J.AJAX.StopPush(options.pushId);
+ options.onerror = function(){
+ // For error, re-submit request.
+ A4J.AJAX.Push(containerId,form,options);
+ };
+
+ options.onqueuerequestdrop = function() {
+ LOG.debug("Push main request dropped from queue");
+ };
+
+ A4J.AJAX._pollers[options.pushId] = window.setTimeout(function(){
+ var request = new XMLHttpRequest();
+ request.onreadystatechange = function(){
+ if (request.readyState == 4 ) {
+ try {
+ if(request.status == 200){
+ if(request.getResponseHeader("Ajax-Push-Status")=="READY"){
+ A4J.AJAX.SetZeroRequestDelay(options);
+ A4J.AJAX.Submit(containerId,form||options.dummyForm,null,options);
+ }
+ }
+ } catch(e){
+ // Network error.
+ }
+ // Clear variables.
+ request=null;
+ A4J.AJAX._pollers[options.pushId] = null;
+ // Re-send request.
+ A4J.AJAX.Push( containerId, form, options );
+ }
+ }
+ A4J.AJAX.SendPush( request,options );
+ },options.pushinterval);
+};
+
+A4J.AJAX.SendPush = function( request,options ) {
+ var url = options.pushUrl || options.actionUrl;
+ request.open('HEAD', url , true);
+ request.setRequestHeader( "Ajax-Push-Key", options.pushId);
+ if(options.timeout){
+ request.setRequestHeader( "Timeout", options.timeout);
+ }
+ request.send(null);
+}
+
+A4J.AJAX.StopPush = function( Id ) {
+ if(A4J.AJAX._pollers[Id]){
+ window.clearTimeout(A4J.AJAX._pollers[Id]);
+ A4J.AJAX._pollers[Id] = null;
+ }
+};
+
+
+
+A4J.AJAX.CloneObject = function( obj, noFunctions ) {
+ var cloned = {};
+ for( var n in obj ){
+ if(noFunctions && typeof(evt[prop]) == 'function'){
+ continue;
+ }
+ cloned[n]=obj[n];
+ }
+ return cloned;
+}
+
+
+A4J.AJAX.SubmitForm = function( containerId, form, options ) {
+ var opt = A4J.AJAX.CloneObject(options);
+ // Setup active control if form submitted by button.
+ if(A4J._formInput){
+ LOG.debug("Form submitted by button "+A4J._formInput.id);
+ opt.control = A4J._formInput;
+ A4J._formInput = null;
+ opt.submitByForm=true;
+ }
+ A4J.AJAX.Submit(containerId,form,null,opt);
+}
+
+/**
+ * This method should be deprecated and maybe even removed?
+ */
+A4J.AJAX.SubmiteventsQueue = function( eventsQueue ) {
+ eventsQueue.submit();
+};
+
+A4J.AJAX.CloneEvent = function(evt) {
+ var domEvt;
+ evt = evt || window.event || null;
+ if(evt){
+ // Create copy of event object, since most of properties undefined outside of event capture.
+ try {
+ domEvt = A4J.AJAX.CloneObject(evt,false);
+ } catch(e){
+ LOG.warn("Exception on clone event "+e.name +":"+e.message);
+ }
+ LOG.debug("Have Event "+domEvt+" with properties: target: "+domEvt.target+", srcElement: "+domEvt.srcElement+", type: "+domEvt.type);
+ }
+
+ return domEvt;
+};
+
+A4J.AJAX.PrepareQuery = function(containerId, formId, domEvt, options) {
+ // Process listeners.
+ for(var li = 0; li < A4J.AJAX._listeners.length; li++){
+ var listener = A4J.AJAX._listeners[li];
+ if(listener.onbeforeajax){
+ listener.onbeforeajax(formId,domEvt,options);
+ }
+ }
+ // First - run onsubmit event for client-side validation.
+ LOG.debug("Query preparation for form '" + formId + "' requested");
+// var form = A4J.AJAX.locateForm(event);
+ var form = window.document.getElementById(formId);
+ if( (!form || form.nodeName.toUpperCase() != "FORM") && domEvt ) {
+ var srcElement = domEvt.target||domEvt.srcElement||null;
+ if(srcElement){
+ form = A4J.AJAX.locateForm(srcElement);
+ };
+ };
+ // TODO - test for null of form object
+ if(!options.submitByForm && form && form.onsubmit) {
+ LOG.debug("Form have onsubmit function, call it" );
+ if( form.onsubmit() == false ){
+ return false;
+ };
+ };
+ var tosend = new A4J.Query(containerId, form);
+ tosend.appendFormControls(options.single, options.control);
+ //appending options.control moved to appendFormControls
+ //if(options.control){
+ // tosend.appendControl(options.control,true);
+ //};
+ if(options.parameters){
+ tosend.appendParameters(options.parameters);
+ };
+ if(options.actionUrl){
+ tosend.setActionUrl(options.actionUrl);
+ };
+
+ return tosend;
+};
+
+A4J.AJAX.SubmitQuery = function (query, options, domEvt) {
+ // build xxxHttpRequest. by Sarissa / JSHttpRequest class always defined.
+ var req = new A4J.AJAX.XMLHttpRequest(query);
+
+ var form = query._form;
+ var containerId = query._containerId;
+
+ req.options = options;
+ req.containerId = containerId;
+ req.domEvt = domEvt;
+ req.form = form;
+
+ if(options.timeout){
+ req.setRequestTimeout(options.timeout);
+ };
+
+ // Event handler for process response result.
+ req.onready = A4J.AJAX.processResponse;
+
+ if(options.onerror){
+ req._onerror = options.onerror;
+ } else if(typeof(A4J.AJAX.onError)== "function"){
+ req._onerror = A4J.AJAX.onError;
+ }
+
+ var _queueonerror = options.queueonerror;
+ if (_queueonerror) {
+ var _onerror = req._onerror;
+ if (_onerror) {
+ req._onerror = function() {
+ _queueonerror.apply(this, arguments);
+ _onerror.apply(this, arguments);
+ };
+ } else {
+ req._onerror = _queueonerror;
+ }
+ }
+
+ req.onfinish = A4J.AJAX.finishRequest;
+
+ LOG.debug("NEW AJAX REQUEST !!! with form: " + (form.id || form.name || form));
+
+ A4J.AJAX.status(containerId,options.status,true);
+ req.send();
+
+ return req;
+};
+
+//Submit or put in queue request. It not full queues - framework perform waiting only one request to same queue, new events simple replace last.
+//If request for same queue already performed, replace with current parameters.
+A4J.AJAX.Submit = function( containerId, formId, event , options ) {
+ var domEvt = A4J.AJAX.CloneEvent(event);
+ var query = A4J.AJAX.PrepareQuery(containerId, formId, domEvt, options);
+ if (query) {
+ var queue = A4J.AJAX.EventQueue.getOrCreateQueue(options, formId);
+
+ if (queue) {
+ queue.push(query, options, domEvt);
+ } else {
+ A4J.AJAX.SubmitQuery(query, options, domEvt);
+ }
+ }
+
+ return false;
+};
+
+
+ // Main request submitting functions.
+ // parameters :
+ // form - HtmlForm object for submit.
+ // control - form element, called request, or, clientID for JSF view.
+ // affected - Array of ID's for DOM Objects, updated after request. Override
+ // list of updated areas in response.
+ // statusID - DOM id request status tags.
+ // oncomplete - function for call after complete request.
+A4J.AJAX.SubmitRequest = function( containerId, formId, event, options ) {
+ var domEvt = A4J.AJAX.CloneEvent(event);
+ var query = A4J.AJAX.PrepareQuery(containerId, formId, domEvt, options);
+ if (query) {
+ A4J.AJAX.SubmitQuery(query, options, domEvt);
+ }
+
+ return false;
+};
+
+A4J.AJAX.processResponseAfterUpdateHeadElements = function (req, ids)
+{
+ req.evaluateQueueScript();
+
+ for ( var k =0; k < ids.length ; k++ ) {
+ var id = ids[k];
+ LOG.debug("Update page part from call parameter for ID " + id);
+ req.updatePagePart(id, k==ids.length-1);
+ };
+}
+
+A4J.AJAX.headElementsCounter = 0;
+
+A4J.AJAX.processResponse = function(req) {
+ A4J.AJAX.TestScriptEvaluation();
+ var options = req.options;
+ var ajaxResponse = req.getResponseHeader('Ajax-Response');
+ // If view is expired, check user-defined handler.
+ var expiredMsg = req.getResponseHeader('Ajax-Expired');
+ if(expiredMsg && typeof(A4J.AJAX.onExpired) == 'function' ){
+ var loc = A4J.AJAX.onExpired(window.location,expiredMsg);
+ if(loc){
+ window.location = loc;
+ return;
+ }
+ }
+ if( ajaxResponse != "true"){
+ // NO Ajax header - new page.
+ LOG.warn("No ajax response header ");
+ var loc = req.getResponseHeader("Location");
+ try{
+ if(ajaxResponse == 'redirect' && loc){
+ window.location = loc;
+ } else if(ajaxResponse == "reload"){
+ window.location.reload(true);
+ } else {
+ A4J.AJAX.replacePage(req);
+ }
+ } catch(e){
+ LOG.error("Error redirect to new location ");
+ }
+ } else {
+ if(req.getParserStatus() == Sarissa.PARSED_OK){
+
+ // perform beforeupdate if exists
+ if(options.onbeforedomupdate || options.queueonbeforedomupdate){
+ var event = req.domEvt;
+ var data = req.getJSON('_ajax:data');
+
+ LOG.debug( "Call local onbeforedomupdate function before replacing elemements" );
+
+ if (options.onbeforedomupdate) {
+ options.onbeforedomupdate(req, event, data);
+ }
+
+ if (options.queueonbeforedomupdate) {
+ options.queueonbeforedomupdate(req, event, data);
+ }
+ }
+
+ var idsFromResponse = req.getResponseHeader("Ajax-Update-Ids");
+ var ids;
+
+ var callback = function () {
+ if (A4J.AJAX.headElementsCounter!=0) {
+ LOG.debug("Script "+A4J.AJAX.headElementsCounter+" was loaded");
+ --A4J.AJAX.headElementsCounter;
+ }
+ if (A4J.AJAX.headElementsCounter==0) {
+ A4J.AJAX.processResponseAfterUpdateHeadElements(req, ids);
+ }
+ };
+
+ // 3 strategy for replace :
+ // if setted affected parameters - replace its
+ if( options.affected ) {
+ ids = options.affected;
+ req.appendNewHeadElements(callback);
+ // if resopnce contains element with ID "ajax:update" get id's from
+ // child text element . like :
+ // <div id="ajax:update" style="display none" >
+ // <span>_id1:1234</span>
+ // .........
+ // </div>
+ //
+ } else if( idsFromResponse && idsFromResponse != "" ) {
+ LOG.debug("Update page by list of rendered areas from response " + idsFromResponse );
+ // Append scripts and styles to head, if not presented in page before.
+ ids = idsFromResponse.split(",");
+ req.appendNewHeadElements(callback);
+ } else {
+ // if none of above - error ?
+ // A4J.AJAX.replace(form.id,A4J.AJAX.findElement(form.id,xmlDoc));
+ LOG.warn("No information in response about elements to replace");
+ req.doFinish();
+ }
+ // Replace client-side hidden inputs for JSF View state.
+ var idsSpan = req.getElementById("ajax-view-state");
+ LOG.debug("Hidden JSF state fields: "+idsSpan);
+ if(idsSpan != null){
+ // For a portal case, replace content in the current window only.
+ var namespace = options.parameters['org.ajax4jsf.portlet.NAMESPACE'];
+ LOG.debug("Namespace for hidden view-state input fields is "+namespace);
+ var anchor = namespace?window.document.getElementById(namespace):window.document;
+ var inputs = anchor.getElementsByTagName("input");
+ try {
+ var newinputs = req.getElementsByTagName("input",idsSpan);
+ A4J.AJAX.replaceViewState(inputs,newinputs);
+ } catch(e){
+ LOG.warn("No elements 'input' in response");
+ }
+ // For any cases, new state can be in uppercase element
+ try {
+ var newinputs = req.getElementsByTagName("INPUT",idsSpan);
+ A4J.AJAX.replaceViewState(inputs,newinputs);
+ } catch(e){
+ LOG.warn("No elements 'INPUT' in response");
+ }
+ }
+
+ // Process listeners.
+ for(var li = 0; li < A4J.AJAX._listeners.length; li++){
+ var listener = A4J.AJAX._listeners[li];
+ if(listener.onafterajax){
+ // Evaluate data as JSON String.
+ var data = req.getJSON('_ajax:data');
+ listener.onafterajax(req,req.domEvt,data);
+ }
+ }
+ // Set focus, if nessesary.
+ var focusId = req.getJSON("_A4J.AJAX.focus");
+ if(focusId){
+ LOG.debug("focus must be set to control "+focusId);
+ var focusElement=false;
+ if(req.form){
+ // Attempt to get form control for name. By Richfaces naming convensions,
+ // complex component must set clientId as DOM id for a root element ,
+ // and as input element name.
+ focusElement = req.form.elements[focusId];
+ }
+ if(!focusElement){
+ // If not found as control element, search in DOM.
+ LOG.debug("No control element "+focusId+" in submitted form");
+ focusElement = document.getElementById(focusId);
+ }
+ if(focusElement){
+ LOG.debug("Set focus to control ");
+ focusElement.focus();
+ if (focusElement.select) focusElement.select();
+ } else {
+ LOG.warn("Element for set focus not found");
+ }
+ } else {
+ LOG.debug("No focus information in response");
+ }
+ } else {
+ // No response XML
+ LOG.error( "Error parsing XML" );
+ LOG.error("Parse Error: " + req.getParserStatus());
+ }
+ }
+ };
+
+
+A4J.AJAX.replacePage = function(req){
+ if(!req.getResponseText()){
+ LOG.warn("No content in response for replace current page");
+ return;
+ }
+ LOG.debug("replace all page content with response");
+ var isIE = Sarissa._SARISSA_IS_IE;
+ // maksimkaszynski
+ //Prevent "Permission denied in IE7"
+ //Reset calling principal
+ var oldDocOpen = window.document.open;
+ if (isIE) {
+ LOG.debug("setup custom document.open method");
+ window.document.open = function() {
+ oldDocOpen.apply(this, arguments);
+ }
+ }
+ // /maksimkaszynski
+ window.setTimeout(function() {
+ var isDocOpen=false;
+ try {
+ window.document.open(req.getContentType(),true);
+ LOG.debug("window.document has opened for writing");
+ isDocOpen=true;
+ window.document.write(req.getResponseText());
+ LOG.debug("window.document has been writed");
+ window.document.close();
+ LOG.debug("window.document has been closed for writing");
+ if(isIE){
+ // For Ie , scripts on page not activated.
+ window.location.reload(false);
+ }
+ } catch(e) {
+ LOG.debug("exception during write page content "+e.Message);
+ if(isDocOpen){
+ window.document.close();
+ }
+ // Firefox/Mozilla in XHTML case don't support document.write()
+ // Use dom manipulation instead.
+ var oDomDoc = (new DOMParser()).parseFromString(req.getResponseText(), "text/xml");
+ if(Sarissa.getParseErrorText(oDomDoc) == Sarissa.PARSED_OK){
+ LOG.debug("response has parsed as DOM documnet.");
+ Sarissa.clearChildNodes(window.document.documentElement);
+ var docNodes = oDomDoc.documentElement.childNodes;
+ for(var i = 0;i<docNodes.length;i++){
+ if(docNodes[i].nodeType == 1){
+ LOG.debug("append new node in document");
+ var node = window.document.importNode(docNodes[i], true);
+ window.document.documentElement.appendChild(node);
+ }
+ }
+ //TODO - unloading cached observers?
+ //if (window.RichFaces && window.RichFaces.Memory) {
+ // window.RichFaces.Memory.clean(oldnode);
+ //}
+ } else {
+ LOG.error("Error parsing response",Sarissa.getParseErrorText(oDomDoc));
+ }
+ // TODO - scripts reloading ?
+ } finally {
+ window.document.open = oldDocOpen;
+ }
+ LOG.debug("page content has been replaced");
+ },0);
+}
+
+
+A4J.AJAX.replaceViewState = function(inputs,newinputs){
+ LOG.debug("Replace value for inputs: "+inputs.length + " by new values: "+ newinputs.length);
+ if( (newinputs.length > 0) && (inputs.length > 0) ){
+ for(var i = 0 ; i < newinputs.length; i++){
+ var newinput = newinputs[i];
+ LOG.debug("Input in response: "+newinput.getAttribute("name"));
+ for(var j = 0 ; j < inputs.length; j++){
+ var input = inputs[j];
+ if(input.name == newinput.getAttribute("name")){
+ LOG.debug("Found same input on page with type: "+input.type);
+ input.value = newinput.getAttribute("value");
+ }
+ }
+ }
+ }
+
+};
+/**
+ *
+ */
+A4J.AJAX.finishRequest = function(request){
+ var options = request.options;
+
+ // we can set listener for complete request - for example,
+ // it can shedule next request for update page.
+ var oncomp = request.getElementById('org.ajax4jsf.oncomplete');
+ if(oncomp) {
+ LOG.debug( "Call request oncomplete function after processing updates" );
+ window.setTimeout(function(){
+ var event = request.domEvt;
+ var data = request.getJSON('_ajax:data');
+
+ try {
+ var target = null;
+ if (event) {
+ target = event.target ? event.target : event.srcElement;
+ }
+
+ var newscript = Sarissa.getText(oncomp,true);
+ var oncomplete = new Function("request","event","data",newscript);
+ oncomplete.call(target,request,event,data);
+
+ if (options.queueoncomplete) {
+ options.queueoncomplete.call(target, request, event, data);
+ }
+
+ } catch (e) {
+ LOG.error('Error evaluate oncomplete function '+e.Message);
+ }
+
+ // mark status object ( if any ) for complete request ;
+ A4J.AJAX.status(request.containerId,options.status,false);},
+ 0);
+ } else if (options.oncomplete || options.queueoncomplete){
+ LOG.debug( "Call local oncomplete function after processing updates" );
+ window.setTimeout(function(){
+ var event = request.domEvt;
+ var data = request.getJSON('_ajax:data');
+
+ if (options.oncomplete) {
+ options.oncomplete(request, event, data);
+ }
+
+ if (options.queueoncomplete) {
+ options.queueoncomplete(request, event, data);
+ }
+
+ // mark status object ( if any ) for complete request ;
+ A4J.AJAX.status(request.containerId,options.status,false);},
+ 0);
+
+ } else {
+ LOG.debug( "Processing updates finished, no oncomplete function to call" );
+
+ setTimeout(function() {
+ // mark status object ( if any ) for complete request ;
+ A4J.AJAX.status(request.containerId,options.status,false);
+ }, 0)
+ }
+
+ if (request.shouldNotifyQueue && request.queue) {
+ request.queue.pop();
+ }
+ };
+
+A4J.AJAX.getCursorPos = function(inp){
+
+ if(inp.selectionEnd != null)
+ return inp.selectionEnd;
+
+ // IE specific code
+ var range = document.selection.createRange();
+ var isCollapsed = range.compareEndPoints("StartToEnd", range) == 0;
+ if (!isCollapsed)
+ range.collapse(false);
+ var b = range.getBookmark();
+ return b.charCodeAt(2) - 2;
+ }
+
+ // Locate enclosing form for object.
+A4J.AJAX.locateForm = function(obj){
+
+ var parent = obj;
+ while(parent && parent.nodeName.toLowerCase() != 'form'){
+ parent = parent.parentNode;
+ };
+ return parent;
+
+ };
+
+A4J.AJAX.getElementById = function(id,options){
+ var namespace = options['org.ajax4jsf.portlet.NAMESPACE'];
+ var anchor = namespace?window.document.getElementById(namespace):window.document;
+ var element;
+ if(anchor){
+ element = anchor.getElementById(id);
+ } else {
+ LOG.error("No root element for portlet namespace "+namespace+" on page");
+ }
+ return element;
+}
+
+ // hash for requests count for all ID's
+A4J.AJAX._requestsCounts = {};
+ // Change status object on start/stop request.
+ // on start, document object with targetID+".start" make visible,
+ // document object with targetID+".stop" make invisible.
+ // on stop - inverse.
+A4J.AJAX.status = function(regionID,targetID,start){
+ try {
+ var elem;
+ targetID = targetID || regionID +":status";
+ A4J.AJAX._requestsCounts[targetID]=(A4J.AJAX._requestsCounts[targetID]||0)+(start?1:-1);
+ if(A4J.AJAX._requestsCounts[targetID]>0){
+ elem = document.getElementById(targetID+".stop");
+ if(elem){elem.style.display="none";}
+ elem = document.getElementById(targetID+".start");
+ if(elem){
+ elem.style.display="";
+ if(typeof(elem.onstart) == 'function'){
+ elem.onstart();
+ }
+ }
+ }else{
+ elem = document.getElementById(targetID+".start");
+ if(elem){elem.style.display="none";}
+ elem = document.getElementById(targetID+".stop");
+ if(elem){
+ elem.style.display="";
+ if(typeof(elem.onstop) == 'function'){
+ elem.onstop();
+ }
+ }
+ }
+ } catch(e){
+ LOG.error("Exception on status change: ");
+ }
+};
+
+
+
+
+// Class for build query string.
+A4J.Query = function(containerId, form){
+ // For detect AJAX Request.
+ this._query = {AJAXREQUEST : containerId};
+ this._oldSubmit = null ;
+ this._form = form;
+ this._containerId = containerId;
+ this._actionUrl = ( this._form.action)?this._form.action:this._form;
+ };
+
+A4J.Query.prototype = {
+ _form : null,
+ _actionUrl : null,
+ _ext : "",
+ _query : {},
+ _oldSubmit : null,
+ // init at loading time - script can change location at run time ? ...
+ _pageBase : window.location.protocol+"//"+window.location.host,
+ // hash for control elements query string functions
+
+ hidden : function(control){
+ this._value_query(control);
+ // TODO - configurable mask for hidden command scripts.
+ if( (control.name.length > 4) && (control.name.lastIndexOf("_idcl") == (control.name.length-5)) ){
+ control.value="";
+ // MYfaces version ...
+ } else if( (control.name.length > 12) && (control.name.lastIndexOf("_link_hidden_") == (control.name.length-13)) ){
+ control.value="";
+ }
+ },
+
+ text : function(control){
+ this._value_query(control);
+ },
+
+ textarea : function(control){
+ this._value_query(control);
+ },
+
+ 'select-one' : function(control){
+ // If none options selected, don't include parameter.
+ if (control.selectedIndex != -1) {
+ this._value_query(control);
+ }
+// for( var i =0; i< control.childNodes.length; i++ ){
+// var child=control.childNodes[i];
+// if( child.selected ){
+// this._value_query(control);
+// break;
+// }
+// }
+ },
+
+ password : function(control){
+ this._value_query(control);
+ },
+
+ file : function(control){
+ this._value_query(control);
+ },
+
+ radio : function(control){
+ this._radio_query(control);
+ },
+
+ checkbox : function(control){
+ this._check_query(control);
+ },
+
+
+ 'select-multiple' : function(control){
+ var cname = control.name;
+ var options = control.options;
+ for( var i=0 ;i< control.length;i++ ){
+ var option = options[i];
+ this._addOption(cname, option);
+ }
+ },
+
+ _addOption : function(cname,option){
+ if ( option.selected ){
+ if( ! this._query[cname] ){
+ this._query[cname]=[];
+ }
+ this._query[cname][this._query[cname].length]=option.value;
+ }
+
+ },
+// command inputs
+
+ image : function( control, action ){
+ if(action) this._value_query(control);
+ },
+ button : function( control, action ){
+ if(action) this._value_query(control);
+ },
+
+ submit : function( control, action ){
+ if(action) {
+ this._value_query(control);
+ }
+ },
+
+ // Anchor link pseudo-control.
+ link : function(control, action ){
+ if(action) {
+ this._value_query(control);
+ if(control.parameters){
+ this.appendParameters(control.parameters);
+ }
+ }
+ },
+
+ // same as link, but have additional field - control, for input submit.
+ input : function(control, action ){
+ if(action) {
+ this.link(control, action );
+ // append original control.
+ if( control.control ) {
+ this.appendControl(control.control,action);
+ }
+ }
+ },
+
+ // Append one control to query.
+ appendControl : function(control,action){
+ if( this[control.type] ) {
+ this[control.type](control,action);
+ } else {
+ this._appendById(control.id||control);
+ }
+
+ },
+
+ // Append all non-hidden controls from form to query.
+ appendFormControls : function(hiddenOnly, actionControl){
+ try {
+ var elems = this._form.elements;
+ if(elems){
+ var k = 0;
+ for ( k=0;k<elems.length;k++ ) {
+ var element=elems[k];
+
+ //skip actionControl, we're going to add it later
+ if (element == actionControl) {
+ continue;
+ }
+
+ try {
+ if( !hiddenOnly || element.type == "hidden") {
+ this.appendControl(element,false) ;
+ }
+ } catch( ee ) {
+ LOG.error("exception in building query ( append form control ) " + ee );
+ }
+ }
+ }
+ } catch(e) {
+ LOG.warn("Error with append form controls to query "+e)
+ }
+
+ if (actionControl) {
+ this.appendControl(actionControl, true);
+ }
+ },
+
+ // append map of parameters to query.
+ appendParameters : function(parameters){
+ for( k in parameters ){
+ if(typeof Object.prototype[k] == 'undefined'){
+ LOG.debug( "parameter " + k + " with value "+parameters[k]);
+ this.appendParameter(k,parameters[k]);
+ }
+ }
+ },
+
+ setActionUrl : function(actionUrl){
+ this._actionUrl = actionUrl;
+ },
+// Return action URL ( append extention, if present )
+ getActionUrl : function( ext ) {
+ var actionUrl = this._actionUrl ;
+ var ask = actionUrl.indexOf('?');
+ // create absolute reference - for Firefox XMLHttpRequest base url can vary
+ if( actionUrl.substring(0,1) == '/' ) {
+ actionUrl = this._pageBase+actionUrl;
+ }
+ if ( ! ext ) ext = this._ext ;
+ if( ask >=0 )
+ {
+ return actionUrl.substring(0,ask) + ext + actionUrl.substring(ask);
+ }
+ else return actionUrl + ext;
+ },
+
+
+// Build query string for send to server.
+ getQueryString : function() {
+ var qs = "";
+ var iname ;
+ for ( var k in this._query ){
+ if(typeof Object.prototype[k] == 'undefined'){
+ iname = this._query[k];
+ if( iname instanceof Object ){
+ for ( var l=0; l< iname.length; l++ ) {
+ qs += this._encode(k) + "=" + this._encode(iname[l]) + "&";
+ }
+ } else {
+ qs += this._encode(k) + "=" + this._encode(iname) + "&";
+ }
+ }
+ }
+ LOG.debug("QueryString: "+qs);
+ return qs;
+ },
+ // private methods
+
+ _appendById : function( id ) {
+ this.appendParameter(this._form.id + "_link_hidden_", id);
+ // JSF-ri version ...
+ // this._query[this._form.id + "_idcl"]=id;
+ },
+
+
+ _value_query : function(control){
+ if (control.name) {
+ LOG.debug("Append "+control.type+" control "+control.name+" with value ["+control.value+"] and value attribute ["+control.getAttribute('value')+"]");
+ if(null != control.value){
+ this.appendParameter(control.name, control.value);
+ }
+ } else {
+ LOG.debug("Ignored "+control.type+" no-name control with value ["+control.value+"] and value attribute ["+control.getAttribute('value')+"]");
+ }
+ },
+
+ _check_query : function(control){
+ if( control.checked ) {
+ this.appendParameter(control.name, control.value?control.value:"on");
+ }
+ },
+
+ _radio_query : function(control) {
+ if( control.checked ) {
+ this.appendParameter(control.name, control.value?control.value:"");
+ }
+ },
+
+ // Append parameter to query. if name exist, append to array of parameters
+ appendParameter: function(cname,value){
+ if( ! this._query[cname] ){
+ this._query[cname]=value;
+ return;
+ } else if( !(this._query[cname] instanceof Object) ){
+ this._query[cname] = [this._query[cname]];
+ }
+ this._query[cname][this._query[cname].length]=value;
+ },
+
+ // Encode data string for request string
+ _encode : function(string) {
+ try {
+ return encodeURIComponent(string);
+ } catch(e) {
+ var str = escape(string);
+ // escape don't encode +. but form replace ' ' in fields by '+'
+ return str.split('+').join('%2B');
+ }
+ }
+
+
+ }
+
+
+A4J.AJAX.getText = function(oNode, includeComment) {
+ var s = "";
+ var nodes = oNode.childNodes;
+ for(var i=0; i < nodes.length; i++){
+ var node = nodes[i];
+ var nodeType = node.nodeType;
+
+ if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE ||
+ (includeComment && nodeType == Node.COMMENT_NODE)){
+
+ s += node.data;
+ } else if(nodeType == Node.ELEMENT_NODE || nodeType == Node.DOCUMENT_NODE || nodeType == Node.DOCUMENT_FRAGMENT_NODE){
+ s += arguments.callee(node, includeComment);
+ }
+ }
+ return s;
+}
+
+A4J.AJAX.isXhtmlScriptMode = function() {
+ if (!this._xhtmlScriptMode) {
+ var elt = document.createElement("div");
+ elt.innerHTML = "<script type='text/javascript'><!--\r\n/**/\r\n//--></script>";
+
+ var commentFound = false;
+ var s = elt.firstChild;
+
+ while (s) {
+ if (s.nodeType == Node.ELEMENT_NODE) {
+ var c = s.firstChild;
+
+ while (c) {
+ if (c.nodeType == Node.COMMENT_NODE) {
+ commentFound = true;
+ break;
+ }
+
+ c = c.nextSibling;
+ }
+
+ break;
+ }
+
+ s = s.nextSibling;
+ }
+
+ if (commentFound) {
+ this._xhtmlScriptMode = 2;
+ } else {
+ this._xhtmlScriptMode = 1;
+ }
+ }
+
+ return this._xhtmlScriptMode > 1;
+}
+
+//Test for re-evaluate Scripts in updated part. Opera & Safari do it.
+A4J.AJAX._scriptEvaluated=false;
+A4J.AJAX.TestScriptEvaluation = function () {
+if ((!document.all || window.opera) && !A4J.AJAX._scriptTested){
+ try{
+ // Simulate same calls as on XmlHttp
+ var oDomDoc = Sarissa.getDomDocument();
+ var _span = document.createElement("span");
+ document.body.appendChild(_span);
+ // If script evaluated with used replace method, variable will be set to true
+ var xmlString = "<html xmlns='http://www.w3.org/1999/xhtml'><sc"+"ript>A4J.AJAX._scriptEvaluated=true;</scr"+"ipt></html>";
+ oDomDoc = (new DOMParser()).parseFromString(xmlString, "text/xml");
+ var _script=oDomDoc.getElementsByTagName("script")[0];
+ if(!window.opera && _span.outerHTML){
+ _span.outerHTML = new XMLSerializer().serializeToString(_script);
+ } else {
+ var importednode ;
+ importednode = window.document.importNode(_script, true);
+ document.body.replaceChild(importednode,_span);
+ }
+
+ } catch(e){ /* Mozilla in XHTML mode not have innerHTML */ };
+}
+A4J.AJAX._scriptTested = true;
+}
+A4J.AJAX._eventQueues = {};
+
+//queue constructor
+A4J.AJAX.EventQueue = function() {
+ var DROP_NEW = 'dropNew';
+ var DROP_NEXT = 'dropNext';
+ var FIRE_NEW = 'fireNew';
+ var FIRE_NEXT = 'fireNext';
+
+ var extend = function(target, source) {
+ for (var property in source) {
+ target[property] = source[property];
+ }
+ };
+
+ var extendOptions = function(options) {
+ var opts = {};
+
+ for (var name in options) {
+ opts[name] = options[name];
+ }
+
+ for (var name in this.requestOptions) {
+ if (typeof opts[name] == 'undefined') {
+ opts[name] = this.requestOptions[name];
+ }
+ }
+
+ return opts;
+ };
+
+ var QueueEntry = function() {
+ var ctor = function(queue, query, options, event) {
+ this.queue = queue;
+ this.query = query;
+ this.options = options;
+ this.event = event;
+
+ this.similarityGroupingId = this.options.similarityGroupingId;
+ this.eventsCount = 1;
+ };
+
+ extend(ctor.prototype, {
+
+ isIgnoreDupResponses: function() {
+ return this.options.ignoreDupResponses;
+ },
+
+ getSimilarityGroupingId: function() {
+ return this.similarityGroupingId;
+ },
+
+ setSimilarityGroupingId: function(id) {
+ this.similarityGroupingId = id;
+ },
+
+ submit: function() {
+ this.query.appendParameter("AJAX:EVENTS_COUNT", this.eventsCount);
+ this.request = A4J.AJAX.SubmitQuery(this.query, this.options, this.event)
+
+ var queue = this.queue; // TODO: move to next line
+ this.request.queue = queue;
+
+ return this.request;
+ },
+
+ abort: function() {
+ if (this.request) {
+ //tell request not to notify queue after its processing finished
+ //request.queue = undefined
+ //is not ok for this case because user might want to obtain queue in any event handler
+ this.request.shouldNotifyQueue = false;
+ this.request.abort();
+ this.request = undefined;
+ }
+ },
+
+ ondrop: function() {
+ var callback = this.options.onqueuerequestdrop;
+ if (callback) {
+ callback.call(this.queue, this.query, this.options, this.event);
+ }
+ },
+
+ onRequestDelayPassed: function() {
+ this.readyToSubmit = true;
+ this.queue.submitFirst();
+ },
+
+ startTimer: function() {
+ var delay = this.options.requestDelay;
+
+ LOG.debug("Queue will wait " + (delay || 0) + "ms before submit");
+
+ if (delay) {
+ var _this = this;
+ this.timer = setTimeout(function() {
+ try {
+ _this.onRequestDelayPassed();
+ } finally {
+ _this.timer = undefined;
+ _this = undefined;
+ }
+ }, delay);
+ } else {
+ this.onRequestDelayPassed();
+ }
+ },
+
+ stopTimer: function() {
+ if (this.timer) {
+ clearTimeout(this.timer);
+ this.timer = undefined;
+ }
+ },
+
+ clearEntry: function() {
+ this.stopTimer();
+ if (this.request) {
+ this.request.shouldNotifyQueue = false;
+ this.request = undefined;
+ }
+ },
+
+ getEventsCount: function() {
+ return this.eventsCount;
+ },
+
+ setEventsCount: function(newCount) {
+ this.eventsCount = newCount;
+ },
+
+ getEventArguments: function() {
+ return [this.query, this.options, this.event];
+ }
+ });
+
+ return ctor;
+ }();
+
+ var Queue = function(name, queueOptions, requestOptions) {
+ this.items = new Array();
+
+ this.name = name;
+ this.queueOptions = queueOptions || {};
+ this.requestOptions = requestOptions || {};
+ };
+
+ extend(Queue.prototype, {
+
+ submitFirst: function() {
+ var firstItem = this.items[0];
+ if (firstItem) {
+ if (!firstItem.request) {
+ if (firstItem.readyToSubmit) {
+ LOG.debug("Queue '" + this.name + "' will submit request NOW");
+
+ var req = firstItem.submit();
+
+ //see entry.abort() method for more details about this assignment
+ req.shouldNotifyQueue = true;
+
+ if (this.requestOptions.queueonsubmit) {
+ this.requestOptions.queueonsubmit.call(this, req);
+ }
+ } else {
+ LOG.debug("First item is not ready to be submitted yet");
+ }
+ }
+ } else {
+ LOG.debug("Queue is empty now");
+ }
+ },
+
+ getSize: function() {
+ return this.items.length;
+ },
+
+ getMaximumSize: function() {
+ return this.queueOptions.size;
+ },
+
+ getSizeExceededBehavior: function() {
+ var policy = this.queueOptions.sizeExceededBehavior;
+ if (!policy) {
+ policy = DROP_NEXT;
+ }
+
+ return policy;
+ },
+
+ queue: function(entry) {
+ this.items.push(entry);
+
+ if (this.queueOptions.onrequestqueue) {
+ LOG.debug("Call onrequestqueue handler");
+ this.queueOptions.onrequestqueue.apply(this, entry.getEventArguments());
+ }
+ },
+
+ dequeue: function() {
+ var entry = this.items.shift();
+
+ if (this.queueOptions.onrequestdequeue) {
+ LOG.debug("Call onrequestdequeue handler");
+ this.queueOptions.onrequestdequeue.apply(this, entry.getEventArguments());
+ }
+ },
+
+ push: function(query, opts, event) {
+ var options = extendOptions.call(this, opts);
+
+ var entry = new QueueEntry(this, query, options, event);
+ var similarityGroupingId = entry.getSimilarityGroupingId();
+
+ var lastIdx = this.items.length - 1;
+ var last = this.items[lastIdx];
+ var handled = false;
+
+ if (last) {
+ if (last.getSimilarityGroupingId() == similarityGroupingId) {
+ LOG.debug("Similar request currently in queue '" + this.name + "'");
+
+ if (last.request) {
+ LOG.debug("Request has already beeen sent to server");
+ if (entry.isIgnoreDupResponses()) {
+ LOG.debug("Duplicate responses ignore requested, queue will abort current request");
+
+ last.abort();
+
+ LOG.debug("Current request in queue '" + this.name + "' has been aborted");
+
+ //remove last (that is actually first) from queue - will be safer to do that in LinkedList
+ this.dequeue();
+ }
+ } else {
+ LOG.debug("Combine similar requests and reset timer");
+
+ handled = true;
+ last.stopTimer();
+ entry.setEventsCount(last.getEventsCount() + 1);
+
+ this.items[lastIdx] = entry;
+ entry.startTimer();
+ }
+ } else {
+ LOG.debug("Last queue entry is not the last anymore. Stopping requestDelay timer and marking entry as ready for submission")
+
+ last.stopTimer();
+ last.setSimilarityGroupingId(undefined);
+ last.readyToSubmit = true;
+ }
+ }
+
+ if (!handled) {
+ if (this.queueOptions.size == this.items.length) {
+ LOG.debug("Queue '" + this.name + "' is currently full")
+
+ var b = this.getSizeExceededBehavior();
+
+ var nextIdx = 0;
+ while (this.items[nextIdx] && this.items[nextIdx].request) {
+ nextIdx++;
+ }
+
+ if (this.queueOptions.onsizeexceeded) {
+ this.queueOptions.onsizeexceeded.apply(this, entry.getEventArguments());
+ }
+ // TODO: create one function that will be implement this functionality // function (behaviorFlag, entry): should return handled flag
+ if (b == DROP_NEW) {
+ LOG.debug("Queue '" + this.name + "' is going to drop new item");
+
+ entry.ondrop();
+
+ handled = true;
+ } else if (b == DROP_NEXT) {
+ LOG.debug("Queue '" + this.name + "' is going to drop [" + nextIdx + "] item that is the next one");
+
+ var nextEntry = this.items.splice(nextIdx, 1)[0];
+ if (nextEntry) {
+ LOG.debug("Item dropped from queue");
+
+ nextEntry.stopTimer();
+
+ nextEntry.ondrop();
+ } else {
+ LOG.debug("There's no such item, will handle new request instead");
+
+ entry.ondrop();
+
+ handled = true;
+ }
+ } else if (b == FIRE_NEW) {
+ LOG.debug("Queue '" + this.name + "' will submit new request");
+
+ entry.submit();
+ handled = true;
+ } else if (b == FIRE_NEXT) {
+ LOG.debug("Queue '" + this.name + "' is going to drop and fire immediately [" + nextIdx + "] item that is the next one");
+
+ var nextEntry = this.items.splice(nextIdx, 1)[0];
+ if (nextEntry) {
+ LOG.debug("Item dropped from queue");
+ nextEntry.stopTimer();
+ nextEntry.submit();
+ } else {
+ LOG.debug("There's no such item, will handle new request instead");
+ entry.submit();
+ handled = true;
+ }
+ }
+ }
+
+ this.submitFirst();
+ }
+
+ if (!handled) {
+ this.queue(entry);
+
+ LOG.debug("New request added to queue '" + this.name + "'. Queue similarityGroupingId changed to " + similarityGroupingId);
+
+ entry.startTimer();
+ }
+ },
+
+ pop: function() {
+ LOG.debug("After request: queue '" + this.name + "'");
+
+ this.dequeue();
+
+ LOG.debug("There are " + this.items.length + " requests more in this queue");
+
+ this.submitFirst();
+ },
+
+ clear: function() {
+ var length = this.items.length;
+ for ( var i = 0; i < this.items.length; i++) {
+ this.items[i].clearEntry();
+ }
+
+ this.items.splice(0, length);
+ }
+ });
+
+ return Queue;
+}();
+
+A4J.AJAX.EventQueue.DEFAULT_QUEUE_NAME = "org.richfaces.queue.global";
+
+A4J.AJAX.EventQueue.getQueue = function(name) {
+ return A4J.AJAX._eventQueues[name];
+};
+
+A4J.AJAX.EventQueue.getQueues = function() {
+ return A4J.AJAX._eventQueues;
+};
+
+A4J.AJAX.EventQueue.addQueue = function(queue) {
+ var name = queue.name;
+
+ if (A4J.AJAX._eventQueues[name]) {
+ throw "Queue already registered";
+ } else {
+ LOG.debug("Adding queue '" + name + "' to queues registry");
+ A4J.AJAX._eventQueues[name] = queue;
+ }
+};
+
+A4J.AJAX.EventQueue.removeQueue = function(name) {
+ var queue = A4J.AJAX._eventQueues[name];
+
+ if (queue) {
+ queue.clear();
+ }
+
+ delete A4J.AJAX._eventQueues[name];
+};
+
+A4J.AJAX.EventQueue.getOrCreateQueue = function(){
+ var qualifyName = function(name, prefix) {
+ if (prefix) {
+ return prefix + ":" + name;
+ } else {
+ return name;
+ }
+ };
+
+ var qualifyNamespace = function(name, prefix) {
+ if (prefix) {
+ return prefix + name;
+ } else {
+ return name;
+ }
+ };
+
+ return function(options, formId) {
+ var queueName = options.eventsQueue;
+ var namespace = options.namespace;
+
+ var formQueueName;
+ var viewQueueName;
+ var implicitQueueName;
+
+ if (queueName) {
+ LOG.debug("Look up queue with name '" + queueName + "'");
+
+ formQueueName = qualifyName(queueName, formId);
+ viewQueueName = qualifyNamespace(queueName, namespace);
+
+ implicitQueueName = viewQueueName;
+ } else {
+ LOG.debug("Look up queue with default name");
+
+ formQueueName = formId;
+ viewQueueName = qualifyNamespace(A4J.AJAX.EventQueue.DEFAULT_QUEUE_NAME, namespace);
+
+ implicitQueueName = options.implicitEventsQueue;
+ }
+
+ var queue = A4J.AJAX._eventQueues[formQueueName];
+ if (!queue) {
+ queue = A4J.AJAX._eventQueues[viewQueueName];
+ if (!queue) {
+ if (implicitQueueName) {
+ queue = A4J.AJAX._eventQueues[implicitQueueName];
+ if (!queue) {
+ LOG.debug("Creating new transient queue '" + implicitQueueName + "' with default settings");
+ queue = new A4J.AJAX.EventQueue(implicitQueueName);
+ queue._transient = true;
+
+ A4J.AJAX.EventQueue.addQueue(queue);
+ } else {
+ LOG.debug("Found transient queue '" + implicitQueueName + "'");
+ }
+ }
+ } else {
+ LOG.debug("Found view queue '" + viewQueueName + "'");
+ }
+ } else {
+ LOG.debug("Found form queue '" + formQueueName + "'");
+ }
+
+ return queue;
+ }
+}();
+
+(function () {
+ var observer = function() {
+ var queues = A4J.AJAX.EventQueue.getQueues();
+ for (var queueName in queues) {
+ var queue = queues[queueName];
+ queue.clear();
+ }
+ };
+
+ if (window.addEventListener) {
+ window.addEventListener("unload", observer, false);
+ } else {
+ window.attachEvent("onunload", observer);
+ }
+})();
+
+/**
+ * Provide client side logging capabilities to AJAX applications.
+ *
+ * @author <a href="mailto:thespiegs@users.sourceforge.net">Eric Spiegelberg</a>
+ * @see <a href="http://sourceforge.net/projects/log4ajax">Log4Ajax</a>
+ */
+if (!window.LOG) {
+ window.LOG = {};
+}
+
+LOG.Level = function(name, priority, color){
+ this.name = name;
+ this.priority = priority;
+ if(color){
+ this.color = color;
+ }
+}
+
+LOG.OFF = new LOG.Level("off", 1000);
+LOG.FATAL = new LOG.Level("fatal", 900, "red");
+LOG.ERROR = new LOG.Level("error", 800, "red");
+LOG.WARN = new LOG.Level("warn", 500, "yellow");
+LOG.INFO = new LOG.Level("info", 400, "blue");
+LOG.DEBUG = new LOG.Level("debug", 300, "darkblue");
+LOG.ALL = new LOG.Level("all", 100);
+LOG.A4J_DEBUG = new LOG.Level("a4j_debug", 0, "green");
+
+LOG.LEVEL = LOG.OFF;
+
+LOG._window = null;
+LOG.transmitToServer = true;
+LOG.consoleDivId = "logConsole";
+LOG.styles = {
+a4j_debug: "green",
+debug : "darkblue",
+info : "blue",
+warn : "yellow",
+error : "red",
+fatal : "red"
+};
+
+LOG.a4j_debug = function(msg,pre)
+{
+ LOG._log(msg, LOG.A4J_DEBUG ,pre);
+}
+
+LOG.debug = function(msg,pre)
+{
+ LOG._log(msg, LOG.DEBUG ,pre);
+}
+
+LOG.info = function(msg,pre)
+{
+ LOG._log(msg, LOG.INFO ,pre);
+}
+
+LOG.warn = function(msg,pre)
+{
+ LOG._log(msg, LOG.WARN ,pre);
+}
+
+LOG.error = function(msg,pre)
+{
+ LOG._log(msg, LOG.ERROR ,pre);
+}
+
+LOG.fatal = function(msg,pre)
+{
+ LOG._log(msg, LOG.FATAL ,pre);
+}
+
+LOG.registerPopup = function(hotkey,name,width,height,level){
+ if(!LOG._onkeydown){
+ LOG._onkeydown = document.onkeydown;
+ }
+ var key = hotkey.toUpperCase();
+ document.onkeydown = function(e){
+ if (window.event){ e = window.event;};
+ if (String.fromCharCode(e.keyCode) == key & e.shiftKey & e.ctrlKey){
+ LOG.LEVEL = level;
+ LOG.openWindow(name,'width='+width+',height='+height+',toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,left = '+((screen.width - width) / 2)+',top ='+((screen.height - height) / 2));
+ } else {
+ if(LOG._onkeydown) LOG._onkeydown(e);
+ };
+ }
+}
+
+LOG.clear = function() {
+ if(LOG._window && LOG._window.document){
+ consoleDiv = LOG._window.document.body;
+ } else {
+ consoleDiv = window.document.getElementById(LOG.consoleDivId);
+ }
+
+ consoleDiv.innerHTML = '<button onclick="LOG.clear()">Clear</button><br />';
+}
+
+LOG.openWindow = function(name,features){
+ if(LOG._window){
+ LOG._window.focus();
+ } else {
+ LOG._window = window.open("",name,features);
+
+ LOG._window.LOG = LOG;
+ LOG.clear();
+
+ var _LOG = LOG;
+ LOG._window.onunload = function(){
+ _LOG._window.LOG = null;
+ _LOG._window = null;
+ _LOG.LEVEL = _LOG.OFF;
+ _LOG=undefined;
+ }
+ }
+}
+
+LOG._log = function(msg, logLevel,pre)
+{
+ if(logLevel.priority >= LOG.LEVEL.priority){
+ LOG._logToConsole(msg, logLevel,pre);
+
+ if (LOG.transmitToServer)
+ {
+ LOG._logToServer(msg, logLevel);
+ }
+ }
+}
+
+LOG._time = function(){
+ var currentTime = new Date();
+ var hours = currentTime.getHours();
+ var minutes = currentTime.getMinutes();
+ if (minutes < 10){
+ minutes = "0" + minutes;
+ }
+ var seconds = currentTime.getSeconds();
+ if (seconds < 10){
+ seconds = "0" + seconds;
+ }
+ var millisec = currentTime.getTime()%1000;
+ if(millisec<100){
+ millisec = "0"+millisec;
+ }
+ if(millisec<10){
+ millisec = "0"+millisec;
+ }
+ return hours+":"+minutes+":"+seconds+","+millisec;
+}
+
+LOG._logToConsole = function(msg, logLevel,preformat)
+{
+ var consoleDiv ;
+ var doc;
+ if(LOG._window && LOG._window.document){
+ doc = LOG._window.document;
+ consoleDiv = LOG._window.document.body;
+ } else {
+ doc = window.document;
+ consoleDiv = window.document.getElementById(LOG.consoleDivId);
+ }
+ if (consoleDiv)
+ {
+ var span = doc.createElement("span");
+ span.style.color=logLevel.color;
+ span.appendChild(doc.createTextNode(logLevel.name+"["+LOG._time()+"]: "));
+ var div = doc.createElement("div");
+ var textnode = doc.createTextNode(msg);
+ div.appendChild(span);
+ div.appendChild(textnode);
+ // preformatted - for example, html
+ if(preformat){
+ var pre = doc.createElement("span");
+ textnode = doc.createTextNode(preformat);
+ pre.appendChild(textnode);
+ div.appendChild(pre);
+ }
+ consoleDiv.appendChild(div);
+/*
+ consoleDiv.innerHTML = "<span style='" + LOG.styles[logLevel] + "'>" +
+ logLevel + "</span>: " + msg + "<br/>" +
+ consoleDiv.innerHTML;*/
+ }
+ else
+ {
+ // If the consoleDiv is not available, you could create a
+ // new div or open a new window.
+ }
+}
+
+LOG._logToServer = function(msg, logLevel)
+{
+ var data = logLevel.name.substring(0, 1) + msg;
+ // TODO - use sarissa-enabled request.
+ // Use request.js to make an AJAX transmission to the server
+// Http.get({
+// url: "log",
+// method: "POST",
+// body: data,
+// callback: LOG._requestCallBack
+// });
+}
+
+LOG._requestCallBack = function()
+{
+ // Handle callback functionality here; if appropriate
+}
+/*
+* final trail for ajax jsf library
+*/
+// }
+//memory-leaks sanitizing code
+if (!window.RichFaces) {
+ window.RichFaces = {};
+}
+
+if (!window.RichFaces.Memory) {
+ window.RichFaces.Memory = {
+
+ nodeCleaners: {},
+ componentCleaners: {},
+
+ addCleaner: function (name, cleaner) {
+ this.nodeCleaners[name] = cleaner;
+ },
+
+ addComponentCleaner: function (name, cleaner, checker) {
+ this.componentCleaners[name] = {cleaner: cleaner, checker: checker};
+ },
+
+ applyCleaners: function (node, isAjax, componentNodes) {
+ for (var name in this.nodeCleaners) {
+ this.nodeCleaners[name](node, isAjax);
+ }
+ for (var name in this.componentCleaners) {
+ if (this.componentCleaners[name].checker(node, isAjax))
+ componentNodes.push(node);
+ }
+ },
+
+ _clean: function (oldNode, isAjax, componentNodes) {
+ if (oldNode) {
+ this.applyCleaners(oldNode, isAjax, componentNodes);
+
+ //node.all is quicker than recursive traversing
+ //window doesn't have "all" attribute
+ var all = oldNode.all;
+
+ if (all) {
+ var counter = 0;
+ var length = all.length;
+
+ for (var counter = 0; counter < length; counter++ ) {
+ this.applyCleaners(all[counter], isAjax, componentNodes);
+ }
+ } else {
+ var node = oldNode.firstChild;
+ while (node) {
+ this._clean(node, isAjax, componentNodes);
+ node = node.nextSibling;
+ }
+ }
+ }
+ },
+
+ _cleanComponentNodes: function (oldNodes, isAjax) {
+ for (var i=0; i<oldNodes.length; i++) {
+ var node = oldNodes[i];
+ for (var name in this.componentCleaners) {
+ this.componentCleaners[name].cleaner(node, isAjax);
+ }
+ }
+ },
+
+ clean: function (oldNode, isAjax) {
+ var componentNodes = [];
+ this._clean(oldNode, isAjax, componentNodes);
+ this._cleanComponentNodes(componentNodes, isAjax);
+ componentNodes = null;
+ }
+ };
+
+ window.RichFaces.Memory.addComponentCleaner("richfaces", function(node, isAjax) {
+ var component = node.component;
+ if (component) {
+ var destructorName = component["rich:destructor"];
+ //destructor name is required to be back-compatible
+ if (destructorName) {
+ var destructor = component[destructorName];
+ if (destructor) {
+ destructor.call(component, isAjax);
+ }
+ }
+ }
+ }, function(node, isAjax) {
+ return (node.component && node.component["rich:destructor"]);
+ });
+
+ if (window.attachEvent) {
+ window.attachEvent("onunload", function() {
+ var memory = window.RichFaces.Memory;
+ memory.clean(document);
+ memory.clean(window);
+ });
+ }
+}
+
+//
+
+if (!window.RichFaces) window.RichFaces = {};
+
+
+
+RichFaces.SortController = function() {
+ var controlsByTable = {};
+
+ return {
+ registerControl : function(control) {
+ var tableId = control.tableId;
+ var sortExpression = control.sortExpression;
+ var controlId = control.id;
+ var columnId = control.columnId;
+
+ var byTable = controlsByTable[tableId];
+ if (!byTable) {
+ byTable = {columns: {}, expressions : {}};
+ controlsByTable[tableId] = byTable;
+ }
+ var byExpression;
+ if (sortExpression) {
+ byExpression = byTable.expressions[sortExpression];
+ if (!byExpression) {
+ byExpression = {};
+ byTable.expressions[sortExpression] = byExpression;
+ }
+ } else if (columnId) {
+ byExpression = byTable.columns[columnId];
+ if (!byExpression) {
+ byExpression = {};
+ byTable.columns[columnId] = byExpression;
+ }
+ }
+ if(byExpression) {
+ var byId = byExpression[controlId];
+ if (byId) {
+ //TODO: delete controls already registered??
+ } else {
+ byExpression[controlId] = control;
+ }
+ }
+ },
+
+ controlsByTable : function(tableId) {
+ var map = controlsByTable[tableId] || {expressions: {}, columns :{}};
+ var result = [];
+ ['expressions', 'columns'].each(
+ function(part) {
+ var parts = map[part];
+ if (parts) {
+ $H(parts).values().each(
+ function(x) {
+ result = result.concat($H(x).values());
+ }
+ );
+ }
+
+ }
+ );
+ return result.uniq();
+ },
+ controls : function(tableId, sortExpression, columnId) {
+ var map = controlsByTable[tableId] || {expressions: {}, columns :{}};
+ var array;
+ if (typeof sortExpression != 'undefined') {
+ array = $H(map.expressions[sortExpression]).values();
+ }
+ if (typeof columnId != 'undefined') {
+ var a = $H(map.columns[columnId]).values();
+ if (array) {
+ array = array.concat(a).uniq();
+ } else {
+ array = a;
+ }
+ }
+ return array;
+
+ }
+ };
+}();
+
+
+RichFaces.SortControl = Class.create({
+ initialize : function(id, tableId, sortExpression, columnId) {
+ this.id = id;
+ this.tableId = tableId;
+ this.columnId = columnId;
+ this.sortExpression = sortExpression;
+ this.prepareEvents();
+ //TODO:Set cursor via clazz
+ //element.setStyle({cursor: "pointer"});
+
+ RichFaces.SortController.registerControl(this);
+
+ },
+
+ prepareEvents : function() {
+ this.onclick = this.invoke.bindAsEventListener(this);
+ var element = this.getElement();
+ element.observe("click", this.onclick);
+ },
+ getElement : function () {
+ return $($(this.id)/*.parentNode*/);
+ },
+ displaySortedAscending : function() {
+ this.getElement()
+ .removeClassName("rich-sort-desc")
+ .addClassName("rich-sort-asc");
+ },
+ displaySortedDescending : function() {
+ this.getElement()
+ .removeClassName("rich-sort-asc")
+ .addClassName("rich-sort-desc");
+ },
+ displayNotSortedAtAll : function() {
+ this.getElement()
+ .removeClassName("rich-sort-desc")
+ .removeClassName("rich-sort-asc");
+ },
+ invoke : function(event) {
+ var sortExpression;
+
+ if (this.sortExpression) {
+ sortExpression = this.sortExpression;
+ } else {
+ var cell = Event.findElement(event, "th,td");
+ if (cell) {
+ sortExpression = cell.cellIndex;
+ }
+ }
+ if (typeof sortExpression != 'undefined') {
+ $(this.tableId).component.changeSorting(new RichFaces.SortOrder([new RichFaces.SortField(sortExpression)]), this.columnId);
+ }
+ }
+});
+
+RichFaces.SortOrder = Class.create({
+ initialize : function(fields) {
+ this.fieldz = fields || [];
+ },
+ fields : function() {
+ return this.fieldz;
+ }
+});
+
+
+
+
+RichFaces.SortField = function(sortExpression, asc) {
+ this.sortExpression = sortExpression;
+ this.asc = asc;
+};
+
+RichFaces.SortMode = Class.create({
+ merge : function(oldSortOrder, newSortOrder) {
+ return oldSortOrder;
+ }
+});
+
+/**
+ * Basically toggle any existing
+ */
+RichFaces.SortMode.Single = Class.create(RichFaces.SortMode, {
+ merge : function(oldSortOrder, newSortOrder) {
+ var newFields = newSortOrder.fields();
+ var oldFields = oldSortOrder.fields();
+ var expr;
+ var asc;
+ if (oldFields.length > 0) {
+ expr = oldFields[0].sortExpression;
+ asc = oldFields[0].asc;
+ }
+ if (newFields.length > 0) {
+ var xpr = newFields[0].sortExpression;
+ if (xpr == expr) {
+ asc = !asc;
+ } else {
+ expr = xpr;
+ asc = true;
+ }
+ }
+ oldSortOrder = new RichFaces.SortOrder([new RichFaces.SortField(expr, asc)]);
+ return oldSortOrder;
+ }
+});
+
+
+RichFaces.DataTable = Class.create({
+ initialize : function(id, options) {
+ var table = $(id);
+ table.component = this;
+
+ this.sortMode = options.sortMode || new RichFaces.SortMode();
+ this.id = id;
+ this.sortOrder = options.sortOrder || new RichFaces.SortOrder();
+ this._compare = this.compare.bind(this);
+ },
+ /**
+ * Call this method to sort the table
+ * @param sortOrder - new sortOrder
+ * @param force if true, new sortOrder will completely replace previous one, otherwise sortOrders are merged using sortMode
+ */
+ changeSorting : function(sortOrder, columnId, force){
+ if (force) {
+ this.sortOrder = sortOrder;
+ } else {
+ this.sortOrder = this.sortMode.merge(this.sortOrder, sortOrder);
+ }
+ this.sort();
+ var tableId = this.id;
+
+ var cbt = $A(RichFaces.SortController.controlsByTable(tableId));
+ cbt.each(
+ function(control) {
+ control.displayNotSortedAtAll();
+ }
+ );
+ $A(this.sortOrder.fields()).each(
+ function(field) {
+ var ctrls =
+ RichFaces.SortController.controls(tableId, field.sortExpression, columnId);
+ $A(ctrls).each(function(control) {
+ if (field.asc) {
+ control.displaySortedAscending();
+ } else {
+ control.displaySortedDescending();
+ }
+ });
+ }
+ );
+ },
+
+ sort : function() {
+ var table = $(this.id);
+ var tbody = table.tBodies[0];
+ if (tbody) {
+ var newTbody = tbody.cloneNode(false);
+ var newCollection = $A(tbody.rows).clone();
+ newCollection.sort(this._compare);
+ for(var i = 0; i < newCollection.length; i++) {
+ newTbody.appendChild(newCollection[i]);
+ }
+ tbody.parentNode.replaceChild(newTbody, tbody);
+ }
+
+ },
+ compare : function(row1, row2) {
+ var fields = this.sortOrder.fields();
+ var result = 0;
+ for(var i = 0; i < fields.length && result == 0; i++) {
+ var field = fields[i];
+ var expression = field.sortExpression;
+ if (typeof (expression) == 'function') {
+ result = expression(row1, row2);
+ } else if (typeof (expression) == 'number') {
+ var c1 = row1.cells[expression];
+ var c2 = row2.cells[expression];
+ if (c1) {
+ c1 = c1.innerHTML.stripTags();
+
+ }
+ if (c2) {
+ c2 = c2.innerHTML.stripTags();
+ }
+
+ result = ((c1 == c2) ? 0 : ((c1 < c2) ? -1 : 1));
+ }
+
+ if (field.asc == false) {
+ result = -result;
+ }
+
+ }
+ return result;
+
+
+ }
+});
+RichFaces.SortControl.Server = Class.create(RichFaces.SortControl, {
+ invoke : function(event) {
+ $(this.id + 's').click();
+ }
+});
+RichFaces.SortControl.Ajax = Class.create(RichFaces.SortControl, {
+ initialize: function(id, f) {
+ this.id = id;
+ this.f = f;
+ this.prepareEvents();
+ },
+ invoke : function(event) {
+ this.f(event);
+ }
+});
+
+RichFaces.blurFilterInput = function(event) {
+ if (event.keyCode == Event.KEY_RETURN && Event.element(event)) {
+ Event.element(event).blur();
+ return false;
+ }
+};
+
+if (!window.Richfaces) {
+ window.Richfaces = {};
+}
+
+Richfaces.mergeStyles = function(userStyles,commonStyles) {
+ var i;
+ for(i in userStyles) {
+ if (typeof userStyles[i] == "object") {
+ this.mergeStyles(userStyles[i],commonStyles[i]);
+ } else {
+ commonStyles[i] += " " + userStyles[i];
+ }
+ }
+ return commonStyles;
+};
+
+Richfaces.getComputedStyle = function(eltId, propertyName) {
+ var elt = $(eltId);
+
+ if (elt.nodeType != Node.ELEMENT_NODE) {
+ return "";
+ }
+
+ if (elt.currentStyle) {
+ return elt.currentStyle[propertyName];
+ }
+
+ if (document.defaultView && document.defaultView.getComputedStyle) {
+
+ var styles = document.defaultView.getComputedStyle(elt, null);
+ if (styles) {
+ return styles.getPropertyValue(propertyName);
+ }
+
+ }
+
+ return "";
+};
+
+Richfaces.getComputedStyleSize = function(eltId, propertyName) {
+ var value = Richfaces.getComputedStyle(eltId, propertyName);
+
+ if (value) {
+ value = value.strip();
+ value = value.replace(/px$/, "");
+
+ return parseFloat(value);
+ }
+
+ return 0;
+};
+
+Richfaces.getWindowSize = function() {
+ var myWidth = 0, myHeight = 0;
+ if( typeof( window.innerWidth ) == 'number' ) {
+ myWidth = window.innerWidth;
+ myHeight = window.innerHeight;
+ } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
+ myWidth = document.documentElement.clientWidth;
+ myHeight = document.documentElement.clientHeight;
+ } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
+ myWidth = document.body.clientWidth;
+ myHeight = document.body.clientHeight;
+ }
+ return {"width":myWidth,"height":myHeight};
+};
+
+Richfaces.removePX = function(str) {
+ var pxIndex = str.indexOf("px")
+ if ( pxIndex == -1 ) return str;
+ return str.substr(0,pxIndex);
+};
+
+Richfaces.visitTree = function(root, callback) {
+ var node = root;
+ if (!node) {
+ node = document;
+ }
+
+ callback.call(this, node);
+
+ var child = node.firstChild;
+ while (child) {
+ Richfaces.visitTree(child, callback);
+ child = child.nextSibling;
+ }
+};
+
+Richfaces.getNSAttribute = function (name, element) {
+ if (element.getAttributeNS) {
+ var attr = element.getAttributeNS('http://richfaces.ajax4jsf.org/rich', name);
+ if (attr) {
+ return attr;
+ }
+ }
+
+ var attributes = element.attributes;
+ var attrName = "rich:" + name;
+ var attr = attributes[attrName];
+ if (attr) {
+ return attr.nodeValue;
+ }
+
+// for (var i = 0; i < attributes.length; i++) {
+// attr = attributes[i];
+// if (attr && attrName == attr.nodeName) {
+// return attr.nodeValue;
+// }
+// }
+
+ return null;
+};
+
+Richfaces.VARIABLE_NAME_PATTERN = /^\s*[_,A-Z,a-z][\w,_\.]*\s*$/;
+
+Richfaces.getObjectValue = function (str, object) {
+ var a=str.split(".");
+ var value=object[a[0]];
+ var c=1;
+ while (value && c<a.length) value = value[a[c++]];
+ return (value ? value : "");
+}
+
+Richfaces.evalMacro = function(template, object)
+{
+ var value="";
+ // variable evaluation
+ if (Richfaces.VARIABLE_NAME_PATTERN.test(template))
+ {
+ if (template.indexOf('.')==-1) {
+ value = object[template];
+ if (!value) value=window[template];
+ }
+ // object's variable evaluation
+ else {
+ value = Richfaces.getObjectValue(template, object);
+ if (!value) value=Richfaces.getObjectValue(template, window);
+ }
+ if (value && typeof value=='function') value = value(object);
+ if (!value) value="";
+ }
+ //js string evaluation
+ else {
+ try {
+ if (Richfaces.browser.isObjectEval) {
+ value = object.eval(template);
+ }
+ else with (object) {
+ value = eval(template) ;
+ }
+
+ if (typeof value == 'function') {
+ value = value(object);
+ }
+ } catch (e) { LOG.warn("Exception: "+e.Message + "\n[" + template + "]"); }
+ }
+ return value;
+}
+Richfaces.evalSimpleMacro = function(template, object)
+{
+ var value = object[template];
+ if (!value) {value=window[template]; if (!value) value="";}
+ return value;
+}
+
+Richfaces.getComponent = function(componentType, element)
+{
+ var attribute="richfacesComponent";
+ var type = "richfaces:"+componentType;
+ while (element.parentNode) {
+ if (element[attribute] && element[attribute]==type)
+ return element.component;
+ else
+ element = element.parentNode;
+ }
+}
+
+Richfaces.browser= {
+ isIE: (!window.opera && /MSIE/.test(navigator.userAgent)),
+ isIE6: (!window.opera && /MSIE\s*[6][\d,\.]+;/.test(navigator.userAgent)),
+ isSafari: /Safari/.test(navigator.userAgent),
+ isOpera: !!window.opera,
+ isObjectEval: (Richfaces.eval!=undefined),
+ isFF3: (!window.opera && /Firefox\s*[\/]3[\.]/.test(navigator.userAgent))
+};
+
+Richfaces.eval = function(template, object) {
+ var value = '';
+
+ try {
+ with (object) {
+ value = eval(template) ;
+ }
+ } catch (e) {
+ LOG.warn('Exception: ' + e.message + '\n[' + template + ']');
+ }
+
+ return value;
+};
+
+Richfaces.interpolate = function (placeholders, context) {
+
+ for(var k in context) {
+ var v = context[k];
+ var regexp = new RegExp("\\{" + k + "\\}", "g");
+ placeholders = placeholders.replace(regexp, v);
+ }
+
+ return placeholders;
+
+};
+
+if (!Richfaces.position) Richfaces.Position={};
+
+Richfaces.Position.setElementPosition = function(element, baseElement, jointPoint, direction, offset)
+{
+ // parameters:
+ // jointPoint: {x:,y:} or ('top-left','top-right','bottom'-left,'bottom-right')
+ // direction: ('top-left','top-right','bottom'-left,'bottom-right', 'auto')
+ // offset: {x:,y:}
+
+ var elementDim = Richfaces.Position.getOffsetDimensions(element);
+ var baseElementDim = Richfaces.Position.getOffsetDimensions(baseElement);
+
+ var windowRect = Richfaces.Position.getWindowViewport();
+
+ var baseOffset = Position.cumulativeOffset(baseElement);
+
+ // jointPoint
+ var ox=baseOffset[0];
+ var oy=baseOffset[1];
+ var re = /^(top|bottom)-(left|right)$/;
+ var match;
+
+ if (typeof jointPoint=='object') {ox = jointPoint.x; oy = jointPoint.y}
+ else if ( jointPoint && (match=jointPoint.toLowerCase().match(re))!=null )
+ {
+ if (match[2]=='right') ox+=baseElementDim.width;
+ if (match[1]=='bottom') oy+=baseElementDim.height;
+ } else
+ {
+ // ??? auto
+ }
+
+ // direction
+ if (direction && (match=direction.toLowerCase().match(re))!=null )
+ {
+ var d = direction.toLowerCase().split('-');
+ if (match[2]=='left') { ox-=elementDim.width + offset.x; } else ox += offset.x;
+ if (match[1]=='top') { oy-=elementDim.height + offset.y; } else oy += offset.y
+ } else
+ {
+ // auto
+ var theBest = {square:0};
+ // jointPoint: bottom-right, direction: bottom-left
+ var rect = {right: baseOffset[0] + baseElementDim.width, top: baseOffset[1] + baseElementDim.height};
+ rect.left = rect.right - elementDim.width;
+ rect.bottom = rect.top + elementDim.height;
+ ox = rect.left; oy = rect.top;
+ var s = Richfaces.Position.checkCollision(rect, windowRect);
+ if (s!=0)
+ {
+ if (ox>=0 && oy>=0 && theBest.square<s) theBest = {x:ox, y:oy, square:s};
+ // jointPoint: top-right, direction: top-left
+ rect = {right: baseOffset[0] + baseElementDim.width, bottom: baseOffset[1]};
+ rect.left = rect.right - elementDim.width;
+ rect.top = rect.bottom - elementDim.height;
+ ox = rect.left; oy = rect.top;
+ s = Richfaces.Position.checkCollision(rect, windowRect);
+ if (s!=0)
+ {
+ if (ox>=0 && oy>=0 && theBest.square<s) theBest = {x:ox, y:oy, square:s};
+ // jointPoint: bottom-left, direction: bottom-right
+ rect = {left: baseOffset[0], top: baseOffset[1] + baseElementDim.height};
+ rect.right = rect.left + elementDim.width;
+ rect.bottom = rect.top + elementDim.height;
+ ox = rect.left; oy = rect.top;
+ s = Richfaces.Position.checkCollision(rect, windowRect);
+ if (s!=0)
+ {
+ if (ox>=0 && oy>=0 && theBest.square<s) theBest = {x:ox, y:oy, square:s};
+ // jointPoint: top-left, direction: top-right
+ rect = {left: baseOffset[0], bottom: baseOffset[1]};
+ rect.right = rect.left + elementDim.width;
+ rect.top = rect.bottom - elementDim.height;
+ ox = rect.left; oy = rect.top;
+ s = Richfaces.Position.checkCollision(rect, windowRect);
+ if (s!=0)
+ {
+ // the best way selection
+ if (ox<0 || oy<0 || theBest.square>s) {ox=theBest.x; oy=theBest.y}
+ }
+ }
+ }
+
+ }
+ }
+
+ element.style.left = ox + 'px';
+ element.style.top = oy + 'px';
+};
+
+Richfaces.Position.getOffsetDimensions = function(element) {
+ // from prototype 1.5.0 // Pavel Yascenko
+ element = $(element);
+ var display = $(element).getStyle('display');
+ if (display != 'none' && display != null) // Safari bug
+ return {width: element.offsetWidth, height: element.offsetHeight};
+
+ // All *Width and *Height properties give 0 on elements with display none,
+ // so enable the element temporarily
+ var els = element.style;
+ var originalVisibility = els.visibility;
+ var originalPosition = els.position;
+ var originalDisplay = els.display;
+ els.visibility = 'hidden';
+ els.position = 'absolute';
+ els.display = 'block';
+ var originalWidth = element.offsetWidth; // was element.clientWidth // Pavel Yascenko
+ var originalHeight = element.offsetHeight; // was element.clientHeight // Pavel Yascenko
+ els.display = originalDisplay;
+ els.position = originalPosition;
+ els.visibility = originalVisibility;
+ return {width: originalWidth, height: originalHeight};
+};
+
+Richfaces.Position.checkCollision = function(elementRect, windowRect, windowOffset)
+{
+ if (elementRect.left >= windowRect.left &&
+ elementRect.top >= windowRect.top &&
+ elementRect.right <= windowRect.right &&
+ elementRect.bottom <= windowRect.bottom)
+ return 0;
+
+ var rect = {left: (elementRect.left>windowRect.left ? elementRect.left : windowRect.left),
+ top: (elementRect.top>windowRect.top ? elementRect.top : windowRect.top),
+ right: (elementRect.right<windowRect.right ? elementRect.right : windowRect.right),
+ bottom: (elementRect.bottom<windowRect.bottom ? elementRect.bottom : windowRect.bottom)};
+ return (rect.right-rect.left)* (rect.bottom-rect.top);
+};
+
+
+Richfaces.Position.getWindowDimensions = function() {
+ var w = self.innerWidth
+ || document.documentElement.clientWidth
+ || document.body.clientWidth
+ || 0;
+ var h = self.innerHeight
+ || document.documentElement.clientHeight
+ || document.body.clientHeight
+ || 0;
+ return {width:w, height: h};
+};
+
+Richfaces.Position.getWindowScrollOffset = function() {
+ var dx = window.pageXOffset
+ || document.documentElement.scrollLeft
+ || document.body.scrollLeft
+ || 0;
+ var dy = window.pageYOffset
+ || document.documentElement.scrollTop
+ || document.body.scrollTop
+ || 0;
+ return {left:dx, top: dy};
+};
+
+Richfaces.Position.getWindowViewport = function() {
+ var windowDim = Richfaces.Position.getWindowDimensions();
+ var windowOffset = Richfaces.Position.getWindowScrollOffset();
+ return {left:windowOffset.left, top:windowOffset.top, right: windowDim.width+windowOffset.left, bottom: windowDim.height+windowOffset.top};
+};
+
+Richfaces.firstDescendant = function(node) {
+ var n = node.firstChild;
+ while (n && n.nodeType != 1) {
+ n = n.nextSibling;
+ }
+
+ return n;
+};
+
+Richfaces.lastDescendant = function(node) {
+ var n = node.lastChild;
+ while (n && n.nodeType != 1) {
+ n = n.previousSibling;
+ }
+
+ return n;
+};
+
+Richfaces.next = function(node) {
+ var n = node;
+ do {
+ n = n.nextSibling;
+ } while (n && n.nodeType != 1);
+
+ return n;
+};
+
+Richfaces.previous = function(node) {
+ var n = node;
+ do {
+ n = n.previousSibling;
+ } while (n && n.nodeType != 1);
+
+ return n;
+};
+
+Richfaces.removeNode = function(node) {
+ if (node) {
+ var parentNode = node.parentNode;
+ if (parentNode) {
+ parentNode.removeChild(node);
+ }
+ }
+};
+
+Richfaces.readAttribute = function(element, name) {
+ var result = null;
+
+ var node = element.getAttributeNode(name);
+ if (node) {
+ result = node.nodeValue;
+ }
+
+ return result;
+};
+
+Richfaces.writeAttribute = function(element, name, value) {
+ var node = element.getAttributeNode(name);
+
+ if (value !== null) {
+ if (node) {
+ node.nodeValue = value;
+ } else {
+ node = document.createAttribute(name);
+ node.nodeValue = value;
+ element.setAttributeNode(node);
+ }
+ } else {
+ if (node) {
+ element.removeAttributeNode(node);
+ }
+ }
+};
+
+Richfaces.mergeObjects = function() {
+ var target = arguments[0];
+ if (target) {
+ for (var i = 1; i < arguments.length; i++) {
+ var source = arguments[i];
+ if (source) {
+ for (var name in source) {
+ if (!target[name]) {
+ target[name] = source[name];
+ }
+ }
+ }
+ }
+ }
+};
+
+Richfaces.invokeEvent = function(eventFunc, element, eventName, memo) {
+ var result;
+ if (eventFunc) {
+ element = $(element);
+ if (element == document && document.createEvent && !element.dispatchEvent)
+ element = document.documentElement;
+
+ var event;
+ if (document.createEvent) {
+ event = document.createEvent("HTMLEvents");
+ event.initEvent("dataavailable", true, true);
+ } else {
+ event = document.createEventObject();
+ event.eventType = "ondataavailable";
+ }
+
+ event.eventName = eventName;
+ event.rich = {component:this};
+ event.memo = memo || { };
+ try {
+ result = eventFunc.call(element,event);
+ }
+ catch (e) { LOG.warn("Exception: "+e.Message + "\n[on"+eventName + "]"); }
+ }
+ if (result!=false) result = true;
+ return result;
+};
+if (!window.RichShuttleUtils) {
+ window.RichShuttleUtils = {};
+}
+
+RichShuttleUtils.execOnLoad = function(func, condition, timeout) {
+
+ if (condition()) {
+ func();
+ } else {
+ window.setTimeout(
+ function() {
+ RichShuttleUtils.execOnLoad(func, condition, timeout);
+ },
+ timeout
+ );
+ }
+};
+RichShuttleUtils.Condition = {
+ ElementPresent : function(el) {
+ return function () {
+ //var el = $(element);
+ return el && el.offsetHeight > 0;
+ };
+ }
+};
+
+Array.prototype.remove = function(object) {
+ var index = this.indexOf(object, 0, this.length);
+ if (index == -1) return;
+ if (index == 0) {
+ this.shift();
+ } else {
+ this.splice(index, 1);
+ }
+};
+if (!window.Richfaces) { window.Richfaces = {}; }
+
+Richfaces.getExternalClass = function(classes, index) {
+ if (classes) {
+ var len = classes.length;
+ while (index >= len) {
+ index -= len;
+ }
+ return (classes[index]) ? classes[index] : "";
+ }
+ return "";
+}
+
+Richfaces.SelectItem = Class.create();
+
+Richfaces.SelectItem.findElement = function(elt, id) {
+ var e = elt;
+
+ if (e) {
+ if (e.id == id) {
+ return e;
+ }
+
+ e = e.firstChild;
+ while (e) {
+ var result = arguments.callee(e, id);
+
+ if (result) {
+ return result;
+ }
+
+ e = e.nextSibling;
+ }
+ }
+
+ return null;
+};
+
+Richfaces.SelectItem.prototype = {
+ initialize : function(label, id, node) {
+ this._label = label;
+ this._node = node;
+
+ this._node.item = this;
+ this._id = id;
+
+ //XXX 2 optimize
+ this.input = Richfaces.SelectItem.findElement(node, node.id + "StateInput");
+
+ this.selected = /^s/.test(this.input.value);
+ this.active = /^s?a/.test(this.input.value);
+ },
+
+ destroy: function() {
+ this._node.item = null;
+ },
+
+ doActive : function(rowStoredClass, cellStoredClasses) {
+ var classes = this.CLASSES;
+ var row = this._node;
+ var rowClass = classes.ROW.ACTIVE;
+ var cellClass = classes.CELL.ACTIVE;
+ if (this.isSelected()) {
+ rowClass = classes.ROW.SELECTED + " " + classes.ROW.ACTIVE;
+ cellClass = classes.CELL.SELECTED + " " + classes.CELL.ACTIVE;
+ }
+ this.changeClass(row, rowClass, cellClass, rowStoredClass, cellStoredClasses);
+
+ this.active = true;
+
+ this.saveState();
+ },
+
+ doSelect : function(rowStoredClass, cellStoredClasses) {
+ var row = this._node;
+ var classes = this.CLASSES;
+
+ this.changeClass(row, classes.ROW.SELECTED, classes.CELL.SELECTED, rowStoredClass, cellStoredClasses);
+
+ this.selected = true;
+
+ this.saveState();
+ },
+
+ doNormal : function(rowStoredClass, cellStoredClasses) {
+ var row = this._node;
+ var classes = this.CLASSES;
+
+ this.changeClass(row, classes.ROW.NORMAL, classes.CELL.NORMAL, rowStoredClass, cellStoredClasses);
+
+ this.active = false;
+ this.selected = false;
+
+ this.saveState();
+ },
+
+ isSelected : function() {
+ return this.selected;
+ },
+
+ isActive : function() {
+ return this.active;
+ },
+
+ changeClass : function(row, rowClassName, cellClassName, rowStoredClass, cellStoredClasses) {
+ row.className = rowStoredClass + " " + rowClassName;
+ var cells = row.cells;
+ for (var i = 0; i < cells.length; i++) {
+ var cell = cells[i];
+ cell.className = Richfaces.getExternalClass(cellStoredClasses, cell.cellIndex) + " " + cellClassName;
+ }
+ },
+
+ /*addClass : function(row, classNameRow, classNameCell) {
+ if (row.addClassName) {
+ row.addClassName(classNameRow);
+ } else {
+ Element.addClassName(row, classNameRow);
+ }
+
+ var cells = row.cells;
+ for (var i = 0; i < cells.length; i++) {
+ var cell = cells[i];
+ if (cell.addClassName) {
+ cell.addClassName(classNameCell);
+ } else {
+ Element.addClassName(cell, classNameCell);
+ }
+ }
+ },
+
+ removeClass : function(row, classNameRow, classNameCell) {
+ if (row.removeClassName) {
+ row.removeClassName(classNameRow);
+ } else {
+ Element.removeClassName(row, classNameRow);
+ }
+ var cells = row.cells;
+ for (var i = 0; i < cells.length; i++) {
+ var cell = cells[i];
+
+ if (cell.removeClassName) {
+ cell.removeClassName(classNameCell);
+ } else {
+ Element.removeClassName(cell, classNameCell);
+ }
+ }
+ },*/
+
+ saveState: function() {
+ var regex = /^s?a?/;
+
+ if (this.selected && this.active) {
+ this.input.value = this.input.value.replace(regex, 'sa');
+ } else if (this.selected) {
+ this.input.value = this.input.value.replace(regex, 's');
+ } else if (this.active) {
+ this.input.value = this.input.value.replace(regex, 'a');
+ } else {
+ this.input.value = this.input.value.replace(regex, '');
+ }
+ }
+}
+
+LayoutManager = function(headerId, contentId) {
+ this.headerTable = $(headerId);
+ this.contentTable = $(contentId);
+ this.headerDiv = (this.headerTable) ? this.headerTable.parentNode : null;
+ this.contentDiv = this.contentTable.parentNode;
+
+ Event.observe(this.contentDiv, "scroll", this.scrollHandler.bindAsEventListener(this));
+
+}
+
+LayoutManager.SCROLL_WIDTH = 17;
+
+LayoutManager.STYLE_CONTENTTD_BORDER = 1;
+LayoutManager.STYLE_CONTENTTD_PADDING = 4;
+
+LayoutManager.prototype.widthSynchronization = function() {
+ if (Prototype.Browser.IE && this.contentDiv && this.contentTable && this.getScrollWidth()) {
+ //IE displays unnecessary horizontal scroll
+ //when vertical scroll's displayed
+ if (this.contentTable.offsetWidth && ((this.contentTable.offsetWidth <= this.contentDiv.clientWidth))) {
+ this.contentTable.style.width = this.contentDiv.clientWidth + "px";
+ if (this.headerTable) {
+ this.headerTable.style.width = this.contentDiv.offsetWidth + "px";
+ }
+ this.contentDiv.style.overflowX = 'hidden';
+ }
+ } else {
+ this.contentTable.style.width = "100%";
+ }
+
+ var rows = this.contentTable.tBodies[0].rows;
+ if (rows && rows[0]) {
+ //table can be empty
+ var contentCells = rows[0].cells;
+ if (!this.headerTable || !this.headerTable.tHead)
+ return ;
+ var headerCells = this.headerTable.tHead.rows[0].cells;
+ var width;
+ for (var i = 0; i < contentCells.length; i++) {
+ var curCell = contentCells[i];
+ var headCell = headerCells[i];
+
+ width = LayoutManager.calculateWidth(curCell, headCell).colWidth;
+ if (i == contentCells.length - 1) {
+ width = width + this.getScrollWidth();
+ }
+ headCell.firstChild.style.width = width + "px";
+ headCell.style.width = width + "px";
+ }
+ } else {
+ if (this.headerTable && this.headerTable.tHead) {
+ this.headerTable.style.width = "100%";
+ }
+ }
+}
+
+LayoutManager.prototype.getScrollWidth = function() {
+ if (this.contentDiv.clientWidth != 0) {
+ return this.contentDiv.offsetWidth - this.contentDiv.clientWidth;
+ }
+ return 0;
+}
+
+LayoutManager.prototype.scrollHandler = function() {
+ if (this.headerDiv) {
+ this.headerDiv.scrollLeft = this.contentDiv.scrollLeft;
+ }
+}
+
+LayoutManager.getHeaderWidth = function(visibleBox, realBox) {
+ return realBox.offsetWidth + (visibleBox.offsetWidth - visibleBox.clientWidth);
+}
+
+LayoutManager.isIE = function() {
+ return (/MSIE/.test(navigator.userAgent) && !window.opera);
+}
+
+LayoutManager.getElemXY = function(elem) {
+ var x = elem.offsetLeft;
+ var y = elem.offsetTop;
+
+ for (var parent = elem.offsetParent; parent; parent = parent.offsetParent) {
+ x += parent.offsetLeft;
+ y += parent.offsetTop;
+ }
+ return {left: x, top: y};
+}
+
+LayoutManager.calculateWidth = function(srcElem, tgtElem) {
+ var srcElemBorderWidth = LayoutManager.getBorderWidth(srcElem, "lr");
+ var srcElemPaddingWidth = LayoutManager.getPaddingWidth(srcElem, "lr");
+ var srcElemMarginWidth = LayoutManager.getMarginWidth(srcElem, "lr");
+
+ var tgtElemBorderWidth = LayoutManager.getBorderWidth(tgtElem, "lr");
+ var tgtElemPaddingWidth = LayoutManager.getPaddingWidth(tgtElem, "lr");
+ var tgtElemMarginWidth = LayoutManager.getMarginWidth(tgtElem, "lr");
+ var srcWidth = srcElem.offsetWidth - srcElemBorderWidth - srcElemPaddingWidth - srcElemMarginWidth;
+ var colWidth = srcWidth + (srcElemBorderWidth - tgtElemBorderWidth)
+ + (srcElemPaddingWidth - tgtElemPaddingWidth)
+ + (srcElemMarginWidth - tgtElemMarginWidth);
+ colWidth = (colWidth > 0) ? colWidth : 0;
+ return {srcWidth : srcWidth, colWidth : colWidth};
+}
+
+LayoutManager.getBorderWidth = function(el, side) {
+ return LayoutManager.getStyles(el, side, LayoutManager.borders);
+}
+
+LayoutManager.getPaddingWidth = function(el, side) {
+ return LayoutManager.getStyles(el, side, LayoutManager.paddings);
+}
+
+LayoutManager.getMarginWidth = function(el, side) {
+ return LayoutManager.getStyles(el, side, LayoutManager.margins);
+}
+
+LayoutManager.getStyles = function(el, sides, styles) {
+ var val = 0;
+ for(var i = 0, len = sides.length; i < len; i++){
+ //if (el.getStyle) {
+ var w = parseInt(Element.getStyle(el, styles[sides.charAt(i)]), 10);
+ if(!isNaN(w)) val += w;
+ //}
+ }
+ return val;
+}
+
+LayoutManager.borders = {l: 'border-left-width', r: 'border-right-width', t: 'border-top-width', b: 'border-bottom-width'},
+LayoutManager.paddings = {l: 'padding-left', r: 'padding-right', t: 'padding-top', b: 'padding-bottom'},
+LayoutManager.margins = {l: 'margin-left', r: 'margin-right', t: 'margin-top', b: 'margin-bottom'}
+
+if(!window.Richfaces) window.Richfaces = {};
+
+Richfaces.Control = Class.create();
+
+Richfaces.Control.eventStub = function() {
+ return false;
+}
+
+Richfaces.Control.onfocus = function(element) {
+ element.hasFocus = true;
+}
+
+Richfaces.Control.onblur = function(element) {
+ element.hasFocus = undefined;
+}
+
+Richfaces.Control.prototype.initialize = function(eNode, dNode, isShown, isEnabled, action) {
+ this.disabledNode = dNode;
+ this.disabledNode.onselectstart = Richfaces.Control.eventStub;
+
+ this.enabledNode = eNode
+ this.enabledNode.onselectstart = Richfaces.Control.eventStub;
+
+ this.isShown = isShown;
+ this.isEnabled = isEnabled;
+ this.action = action;
+ //this.isEnabled ? this.doEnable() : this.doDisable();
+ //this.isShown ? this.doShow() : this.doHide();
+}
+
+/*Control.CLASSES = {
+ first : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"},
+ down : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"},
+ up : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"},
+ last : {hidden : "ol_button_border ol_control_hidden", shown : "ol_button_border ol_control_shown"}
+};*/
+
+Richfaces.Control.prototype.doShow = function() {
+ this.isShown = true;
+ if (this.isEnabled) {
+ this.doHideNode(this.disabledNode);
+ this.doShowNode(this.enabledNode);
+ } else {
+ this.doHideNode(this.enabledNode);
+ this.doShowNode(this.disabledNode);
+ }
+}
+
+Richfaces.Control.prototype.doHide = function() {
+ this.isShown = false;
+ this.doHideNode(this.disabledNode);
+ this.doHideNode(this.enabledNode);
+}
+
+Richfaces.Control.prototype.doEnable = function() {
+ this.isEnabled = true;
+ this.doHideNode(this.disabledNode);
+ this.doShowNode(this.enabledNode);
+}
+
+Richfaces.Control.prototype.doDisable = function() {
+ this.isEnabled = false;
+
+ var nodes = this.enabledNode.select("a[id='" + this.enabledNode.id + "link']");
+
+ var newFocusNode = undefined;
+
+ if (nodes && nodes[0]) {
+ var link = nodes[0];
+ if (link.hasFocus) {
+ var disNodes = this.disabledNode.select("a[id='" + this.disabledNode.id + "link']");
+ if (disNodes && disNodes[0]) {
+ newFocusNode = disNodes[0];
+ }
+ }
+ }
+
+ this.doHideNode(this.enabledNode);
+ this.doShowNode(this.disabledNode);
+ if (newFocusNode && newFocusNode.focus) {
+ //For IE
+ newFocusNode.disabled = false;
+ newFocusNode.focus();
+ //For IE
+ newFocusNode.disabled = true;
+ }
+}
+
+Richfaces.Control.prototype.doHideNode = function(node) {
+ //node.className = Richfaces.Control.CLASSES[this.action].hidden;
+ node.hide();
+}
+
+Richfaces.Control.prototype.doShowNode = function(node) {
+ //node.className = Richfaces.Control.CLASSES[this.action].shown;
+ node.show();
+}
+
+
+
+if(!window.Richfaces) window.Richfaces = {};
+Richfaces.disableSelectionText = function(e) {
+ e = window.event||e;
+ if (e.srcElement) {
+ if (e.srcElement.tagName) {
+ var tagName = e.srcElement.tagName.toUpperCase();
+
+ if (tagName != "INPUT" && tagName != "TEXTAREA" /* any items more? */) {
+ return false;
+ }
+ }
+ }
+};
+
+
+Richfaces.ListBase = Class.create();
+
+Richfaces.ListBase.compare = function(obj1, obj2) {
+ return ((obj1 == obj2) ? 0 : ((obj1 < obj2) ? -1 : 1));
+}
+
+Richfaces.ListBase.ORDERING_LIST_CLASSES = {
+ normal : "rich-ordering-list-items",
+ disabled : "rich-ordering-list-disabled",
+ active : "rich-ordering-list-active"
+}
+
+Richfaces.ListBase.ASC = "acs";
+Richfaces.ListBase.DESC = "desc";
+
+Richfaces.ListBase.CONTROL_SET = ["A", "INPUT", "TEXTAREA", "SELECT", "OPTION", "BUTTON"];
+
+Richfaces.ListBase.prototype = {
+ initialize : function(containerId, contentTableId, headerTableId, focusKeeperId,
+ onclickControlId, controlClass, columnsClasses, rowClasses) {
+ this["rich:destructor"] = "destroy";
+ this.selectedItems = new Array();
+
+ //this.layoutManager = layoutManager;
+ this.container = $(containerId);
+ this.shuttleTable = $(contentTableId);
+ this.shuttleTable.onselectstart = Richfaces.disableSelectionText;
+ this.focusKeeper = $(focusKeeperId);
+ this.focusKeeper.focused = false;
+ //this.setFocus();
+ this.focusKeeper.observe("keydown", (function(e) {this.onkeydownHandler(window.event || e)}).bindAsEventListener(this));
+ this.focusKeeper.observe("blur", function (e) {this.focusListener(e);}.bindAsEventListener(this));
+ this.focusKeeper.observe("focus", function (e) {this.onfocusHandler(e);}.bindAsEventListener(this));
+
+ this.shuttleTbody = this.shuttleTable.tBodies[0];
+
+ this.activeItem = null;
+ this.pseudoActiveItem = null; //it services for items selection by Shift+click
+ this.items = null;
+
+ //FIX
+ this.rowClasses = rowClasses;
+ this.columnsClasses = columnsClasses;
+
+ this.controlClass = controlClass;
+ this.retrieveShuttleItems(containerId, controlClass);
+ this.counter;
+ this.shuttle = null;
+ this.sortOrder = Richfaces.ListBase.ASC;
+ this.clckHandler = function(e) {this.onclickHandler(window.event || e)}.bindAsEventListener(this);
+ this.shuttleTable.observe("click", this.clckHandler);
+
+ this.layoutManager = new LayoutManager(headerTableId, contentTableId);
+//--- http://jira.jboss.com/jira/browse/RF-3830 FF3 & Safari only!
+ this.tableElement = document.getElementById(contentTableId);
+ var rows = this.tableElement.tBodies[0].rows;
+ if (rows && rows[0]) {
+ this.firstTrElement = rows[0];
+ if (this.firstTrElement.addEventListener && (Richfaces.browser.isFF3 || Richfaces.browser.isSafari)) {
+ this.imagesOnLoad = this.imageLoadListener.bind(this);
+ this.firstTrElement.addEventListener('load',this.imagesOnLoad, true);
+ }
+ }
+//---
+ var synch = function() {this.layoutManager.widthSynchronization()}.bindAsEventListener(this);
+ RichShuttleUtils.execOnLoad(
+ synch, RichShuttleUtils.Condition.ElementPresent(this.container), 100
+ );
+ },
+
+ imageLoadListener: function (evt){
+ this.layoutManager.widthSynchronization();
+ if (this.firstTrElement.removeEventListener && (Richfaces.browser.isFF3 || Richfaces.browser.isSafari)) {
+ this.firstTrElement.removeEventListener('load',this.imagesOnLoad, true);
+ }
+ },
+
+ destroy: function() {
+ this.shuttleTable.onselectstart = null;
+ var items = this.shuttleItems;
+ for (var i = 0; i < items.length; i++) {
+ items[i].destroy();
+ }
+
+ },
+
+ setActiveItem : function(newActiveItem) {
+ this.pseudoActiveItem = newActiveItem;
+ this.activeItem = newActiveItem;
+ },
+
+ retrieveShuttleItems : function(containerId, controlClass) {
+ var rows = this.shuttleTbody.rows;
+ this.shuttleItems = new Array();
+ var id;
+
+ for (var i = 0; i < rows.length; i++) {
+ var row = rows[i];
+ id = row.id.split(containerId + ":")[1];
+ var item = new controlClass(null, (id || i), row);
+ if (item.isSelected()) {
+ this.selectedItems.push(row);
+ }
+ if (item.isActive()) {
+ this.setActiveItem(row);
+ }
+ this.shuttleItems[i] = item;
+ }
+ },
+
+ getExtremeItem : function(position) { //FIXME
+ var extremeItem = this.selectedItems[0];
+ var currentItem;
+
+ for (var i = 1; i < this.selectedItems.length; i++) {
+ currentItem = this.selectedItems[i];
+ if (position == "first") {
+ if (currentItem.rowIndex < extremeItem.rowIndex) {
+ extremeItem = currentItem;
+ }
+ } else {
+ if (currentItem.rowIndex > extremeItem.rowIndex) {
+ extremeItem = currentItem;
+ }
+ }
+ }
+ return extremeItem;
+ },
+
+ getEventTargetRow : function(event) {
+ var activeElem;
+ if (event.target) {
+ //activeElem = event.rangeParent.parentNode;
+ activeElem = event.target;
+ } else {
+ activeElem = event.srcElement;
+ }
+
+ if (activeElem == null) {
+ return;
+ }
+
+ if (activeElem.tagName && Richfaces.ListBase.CONTROL_SET.indexOf(activeElem.tagName.toUpperCase()) != -1) {
+ return;
+ }
+
+ while (activeElem.tagName.toLowerCase() != "tr") {
+ activeElem = activeElem.parentNode;
+ if (!activeElem.tagName) {
+ return; //for IE
+ }
+ }
+ return activeElem;
+ },
+
+ onfocusHandler: function (event) {
+ if (!this.activeItem && this.shuttleItems.length != 0) {
+ this.setActiveItem(this.shuttleItems[0]._node);
+ }
+
+ if (this.activeItem) {
+ this.activeItem.item.doActive(this.getExtRowClass(this.activeItem.rowIndex), this.columnsClasses);
+ }
+ },
+
+ onclickHandler : function(event) {
+ if (event.srcElement && (event.srcElement.tagName.toLowerCase() == "tbody")) {
+ return;
+ }
+ var activeElem = this.getEventTargetRow(event);
+ if (activeElem != null) {
+
+ if (event.ctrlKey) {
+ this.addSelectedItem(activeElem);
+ this.setActiveItem(activeElem);
+ } else if (event.shiftKey) {
+ if (!this.pseudoActiveItem) {
+ this.selectionItem(activeElem);
+ this.setActiveItem(activeElem);
+ } else {
+ this.selectItemGroup(activeElem);
+ this.activeItem = activeElem; //given event works with pseudoActiveItem
+ }
+ } else {
+ this.selectionItem(activeElem);
+ this.setActiveItem(activeElem);
+ }
+
+
+ this.setFocus();
+ }
+ },
+
+ onkeydownHandler : function(event) {
+ var action = null;
+ switch (event.keyCode) {
+ case 38 : //up arrow
+ action = 'up';
+ this.moveActiveItem(action, event);
+ Event.stop(event);
+ break;
+ case 40 : //down arrow
+ action = 'down';
+ this.moveActiveItem(action, event);
+ Event.stop(event);
+ break;
+ case 65 : // Ctrl + A
+ if (event.ctrlKey) {
+ this.selectAll();
+ }
+ this.activeItem.item.doActive(this.getExtRowClass(this.activeItem.rowIndex), this.columnsClasses);
+ Event.stop(event);
+ break;
+ }
+ },
+
+ moveActiveItem : function(action, event) {
+ var item = this.activeItem;
+ var rows = this.shuttleTbody.rows;
+ if ((action == 'up') && (item.rowIndex > 0)) {
+ this.changeActiveItems(rows[item.rowIndex - 1], item);
+ } else if ((action == 'down') && (item.rowIndex < this.shuttleItems.length - 1)) {
+ this.changeActiveItems(rows[item.rowIndex + 1], item);
+ }
+
+ this.autoScrolling(action, event);
+
+ },
+
+ changeActiveItems : function(newItem, item) {
+ item.item.doNormal();
+ this.resetMarked();
+
+ newItem.item.doSelect(this.getExtRowClass(newItem.rowIndex), this.columnsClasses);
+ newItem.item.doActive(this.getExtRowClass(newItem.rowIndex), this.columnsClasses);
+ this.setActiveItem(newItem);
+ this.selectedItems.push(newItem);
+ },
+
+ selectAll : function() {
+ this.resetMarked();
+ var startIndex = 0;
+ var endIndex = this.shuttleItems.length - 1;
+ this.selectItemRange(startIndex, endIndex);
+ },
+
+ /**
+ * Click handler
+ */
+ selectionItem : function(activeItem) {
+ var markedShuttleItem = activeItem;
+
+ this.resetMarked();
+ if (activeItem.item.isSelected()) {
+ activeItem.item.doNormal(this.getExtRowClass(activeItem.rowIndex), this.columnsClasses);
+ } else {
+ activeItem.item.doSelect(this.getExtRowClass(activeItem.rowIndex), this.columnsClasses);
+ this.selectedItems[0] = markedShuttleItem; //TODO: delete
+ }
+ },
+
+ /**
+ * CTRL+Click handler
+ */
+ addSelectedItem : function(activeItem) {
+ var markedShuttleItem = activeItem;
+
+ if (activeItem.item.isSelected()) {
+ this.selectedItems.remove(markedShuttleItem); //TODO :delete
+ activeItem.item.doNormal(this.getExtRowClass(activeItem.rowIndex), this.columnsClasses);
+ } else {
+ activeItem.item.doSelect(this.getExtRowClass(activeItem.rowIndex), this.columnsClasses);
+ this.selectedItems.push(markedShuttleItem); //TODO :delete
+ }
+
+ if ((this.activeItem != null) && (this.activeItem.rowIndex != activeItem.rowIndex)) {
+ //reset activity of an element
+ if (this.activeItem.item.isSelected()) {
+ this.activeItem.item.doSelect(this.getExtRowClass(this.activeItem.rowIndex), this.columnsClasses);
+ } else {
+ this.activeItem.item.doNormal(this.getExtRowClass(this.activeItem.rowIndex), this.columnsClasses);
+ }
+ }
+ },
+
+ /**
+ * Shift+Click handler
+ */
+ selectItemGroup : function(currentItem) {
+ //FIXME
+ var activeItemIndex = this.pseudoActiveItem.rowIndex;
+ var startIndex;
+ var endIndex;
+
+ if (currentItem.rowIndex > activeItemIndex) {
+ startIndex = activeItemIndex;
+ endIndex = currentItem.rowIndex;
+ } else {
+ startIndex = currentItem.rowIndex;
+ endIndex = activeItemIndex;
+ }
+
+ this.resetMarked();
+
+ this.selectItemRange(startIndex, endIndex);
+ },
+
+ selectItemRange : function(startIndex, endIndex) {
+ var rows = this.shuttleTbody.rows;
+ for (var i = startIndex; i <= endIndex; i++) {
+ rows[i].item.doSelect(this.getExtRowClass(rows[i].rowIndex), this.columnsClasses);
+ this.selectedItems.push(rows[i]);
+ }
+ },
+
+ resetMarked : function() {
+ var rows = this.selectedItems;
+ var length = rows.length;
+ for (var i = 0; i < length; i++) {
+ var shuttleItem = rows[i];
+ shuttleItem.item.doNormal(this.getExtRowClass(shuttleItem.rowIndex), this.columnsClasses);
+ }
+ this.selectedItems.length = 0;
+
+ //need to reset active item
+ },
+
+ getSelectItemByNode : function(selectItemNode) {
+ for (var i = 0; i < this.shuttleItems.length; i++) {
+ var item = this.shuttleItems[i];
+ if (selectItemNode.rowIndex == item._node.rowIndex) {
+ return item;
+ }
+ }
+ return null;
+ },
+
+ autoScrolling : function(action, event) {
+ this.selectedItems.sort(this.compareByRowIndex);
+ var increment;
+ var scrollTop = this.shuttleTable.parentNode.scrollTop;
+
+ var shuttleTop = LayoutManager.getElemXY(this.shuttleTable.parentNode).top;
+
+ if (action == 'up' || action == 'first') {
+ var targetItemTop = LayoutManager.getElemXY(this.selectedItems[0]).top;
+ increment = (targetItemTop - scrollTop) - shuttleTop;
+ if (increment < 0) {
+ this.shuttleTable.parentNode.scrollTop += increment;
+ }
+ } else if (action == 'down' || action == 'last') {
+ var item = this.selectedItems[this.selectedItems.length - 1];
+ var targetItemBottom = LayoutManager.getElemXY(this.selectedItems[this.selectedItems.length - 1]).top + item.offsetHeight;
+ var increment = (targetItemBottom - scrollTop) - (shuttleTop + this.shuttleTable.parentNode.clientHeight);
+ if (increment > 0) {
+ this.shuttleTable.parentNode.scrollTop += increment;
+ }
+ }
+ if (event) Event.stop(event);
+ },
+
+ setFocus : function() {
+ this.focusKeeper.focus();
+ this.focusKeeper.focused = true;
+ },
+
+ focusListener : function(e) {
+ e = e || window.event;
+ this.focusKeeper.focused = false;
+
+ if (this.activeItem) {
+ if (this.activeItem.item.isSelected()) {
+ this.activeItem.item.doSelect(this.getExtRowClass(this.activeItem.rowIndex), this.columnsClasses);
+ } else {
+ this.activeItem.item.doNormal(this.getExtRowClass(this.activeItem.rowIndex), this.columnsClasses);
+ }
+ }
+ },
+
+ compareByLabel : function(obj1, obj2) {
+ obj1 = obj1._label;
+ obj2 = obj2._label;
+ return Richfaces.ListBase.compare(obj1, obj2);
+ },
+
+ compareByRowIndex : function(obj1, obj2) {
+ obj1 = obj1.rowIndex;
+ obj2 = obj2.rowIndex;
+ return Richfaces.ListBase.compare(obj1, obj2);
+ },
+
+ isListActive : function() {
+ if ((this.activeItem != null || this.selectedItems.length != 0) && this.focusKeeper.focused) {
+ return true;
+ }
+ return false;
+ },
+
+ getExtRowClass : function(index) {
+ return Richfaces.getExternalClass(this.rowClasses, index);
+ },
+
+ getSelection : function() {
+ var result = [];
+ for (var i = 0; i < this.selectedItems.length; i++) {
+ result[i] = this.selectedItems[i].item;
+ }
+ return result;
+ },
+
+ getItems : function() {
+ return this.shuttleTbody.rows;
+ }
+}
+if(!window.Richfaces) window.Richfaces = {};
+
+Richfaces.OrderingListSelectItem = Class.create(Richfaces.SelectItem);
+Richfaces.OrderingListSelectItem.prototype.CLASSES = {
+ ROW : {
+ ACTIVE : "rich-ordering-list-row-active",
+ SELECTED : "rich-ordering-list-row-selected",
+ DISABLED : "rich-ordering-list-row-disabled",
+ NORMAL : "rich-ordering-list-row"
+ },
+ CELL : {
+ ACTIVE : "rich-ordering-list-cell-active",
+ SELECTED : "rich-ordering-list-cell-selected",
+ DISABLED : "rich-ordering-list-cell-disabled",
+ NORMAL : "rich-ordering-list-cell",
+ BEGIN: " rich-ordering-list-cell-first",
+ END: " rich-ordering-list-cell-last"
+ }
+},
+
+
+Richfaces.OrderingList = Class.create(Richfaces.ListBase, {
+ initialize: function($super, containerId, contentTableId, headerTableId, focusKeeperId, ids, onclickControlId, events, controlClass, columnsClasses, rowClasses) {
+ $super(containerId, contentTableId, headerTableId, focusKeeperId, onclickControlId, controlClass, columnsClasses, rowClasses);
+
+ this.container.component = this;
+
+ this.events = events;
+ this.controlList = new Array();
+ this.initControlList(containerId, ids);
+
+ for (var e in this.events) {
+ if (e && this.events[e]) {
+ this.container.observe("rich:" + e.toString(), this.events[e]);
+ }
+ }
+ },
+
+ destroy: function($super) {
+ $super();
+
+ this.container.component = null;
+ },
+
+ initControlList : function(containerId, ids) {
+ for (var i = 0; i < ids.length; i++) {
+ var id = ids[i];
+ var node = $(containerId + id[0]);
+ var disNode = $(containerId + id[1]);
+ if (node && disNode) {
+ node.observe('click', Richfaces.OrderingList.HANDLERS[id[0]].bindAsEventListener(this));
+ this.controlList[i] = new Richfaces.Control(node, disNode, false, false, id[0]);
+ }
+ }
+ },
+
+ controlListManager : function() {
+ this.selectedItems.sort(this.compareByRowIndex);
+ var control;
+ //FIXME
+ this.controlsProcessing(["first", "last", "down", "up"], "enable");
+ if ((this.shuttleItems.length == 0) || (this.selectedItems.length == 0)) {
+ this.controlsProcessing(["first", "last", "down", "up"], "disable");
+ } else {
+ if (this.selectedItems[0].rowIndex == 0)
+ this.controlsProcessing(["first", "up"], "disable");
+ if (this.selectedItems[this.selectedItems.length - 1].rowIndex == (this.shuttleItems.length - 1))
+ this.controlsProcessing(["down", "last"], "disable");
+ }
+ },
+
+ controlsProcessing : function(disabledControls , action) {
+ for (var i = 0; i < this.controlList.length; i++) {
+ control = this.controlList[i];
+ if (control != null) {
+ if (disabledControls != null && disabledControls.indexOf(control.action) != -1) {
+ if (action == "disable") {
+ control.doDisable();
+ } else {
+ control.doEnable();
+ }
+ }
+ }
+ }
+ },
+
+ onclickHandler : function($super, event) {
+ $super(event);
+ this.controlListManager();
+ },
+
+ moveActiveItem : function($super, action, event) {
+ $super(action, event);
+ this.controlListManager();
+ },
+
+ moveSelectedItems : function(action, event) {
+ if (this.selectedItems.length > 0) {
+
+ if (Richfaces.invokeEvent(this.events.onorderchange, this.container, "rich:onorderchange", {items: this.shuttleItems})) {
+ event = window.event||event;
+ var rows = this.shuttleTbody.rows;
+ var item;
+
+ this.selectedItems.sort(this.compareByRowIndex);
+
+ if ((action == 'up') && this.getExtremeItem("first").previousSibling) {
+ for (var i = 0; i < this.selectedItems.length; i++) {
+ item = this.selectedItems[i];
+ item.parentNode.insertBefore(item, item.previousSibling);
+ }
+ } else if ((action == 'down') && this.getExtremeItem("last").nextSibling) {
+ for (var i = this.selectedItems.length - 1; i > -1; i--) {
+ item = this.selectedItems[i];
+ item.parentNode.insertBefore(item.nextSibling, item);
+ }
+ } else if (action == 'first') {
+ var incr = this.selectedItems[0].rowIndex;
+ for (var i = 0; i < this.selectedItems.length; i++) {
+ item = this.selectedItems[i];
+ item.parentNode.insertBefore(item, rows[item.rowIndex - incr]);
+ }
+ } else if (action == 'last') {
+ var length = this.shuttleItems.length;
+ var incr = length - this.selectedItems[this.selectedItems.length - 1].rowIndex;
+ for (var i = this.selectedItems.length - 1; i > -1; i--) {
+ item = this.selectedItems[i];
+ if (item.rowIndex + incr > length - 1) {
+ item.parentNode.insertBefore(item, null);
+ } else {
+ item.parentNode.insertBefore(item, rows[item.rowIndex + incr]);
+ }
+ }
+ }
+
+ this.shuttleItems = new Array();
+ for (var i = 0; i < rows.length; i++) {
+ this.shuttleItems.push(rows[i].item);
+ }
+ if (action != null)
+ this.autoScrolling(action, event);
+
+ this.container.fire("rich:onorderchanged", {items: this.shuttleItems});
+ this.controlListManager();
+ }
+ }
+ },
+
+ onkeydownHandler : function(event) {
+ var action = null;
+ switch (event.keyCode) {
+ case 34 : action = 'last';
+ this.moveSelectedItems(action ,event);
+ Event.stop(event);
+ break; //page down
+ case 33 : action = 'first';
+ this.moveSelectedItems(action, event);
+ Event.stop(event);
+ break; //page up
+ case 38 : //up arrow
+ action = 'up';
+ if (event.ctrlKey) {
+ this.moveSelectedItems(action, event);
+ } else {
+ this.moveActiveItem(action, event);
+ }
+ Event.stop(event);
+ break;
+ case 40 : //down arrow
+ action = 'down';
+ if (event.ctrlKey) {
+ this.moveSelectedItems(action ,event);
+ } else {
+ this.moveActiveItem(action, event);
+ }
+ Event.stop(event);
+ break;
+ case 65 : // Ctrl + A
+ if (event.ctrlKey) {
+ this.selectAll();
+ }
+ this.activeItem.item.doActive(this.getExtRowClass(this.activeItem.rowIndex), this.columnsClasses);
+ this.controlListManager();
+ Event.stop(event);
+ break;
+ }
+ },
+
+ top : function(e) {
+ this.container.fire("rich:ontopclick", {items: this.shuttleItems, selection: this.getSelection()});
+ this.moveSelectedItems("first", e);
+ },
+
+ bottom : function(e) {
+ this.container.fire("rich:onbottomclick", {items: this.shuttleItems, selection: this.getSelection()});
+ this.moveSelectedItems("last", e);
+ },
+
+ up : function(e) {
+ this.container.fire("rich:onupclick", {items: this.shuttleItems, selection: this.getSelection()});
+ this.moveSelectedItems("up", e);
+ },
+
+ down : function(e) {
+ this.container.fire("rich:ondownclick", {items: this.shuttleItems, selection: this.getSelection()});
+ this.moveSelectedItems("down", e);
+ }
+
+});
+
+Richfaces.OrderingList.ACTIVITY_MARKER = "a";
+Richfaces.OrderingList.SELECTION_MARKER = "s";
+Richfaces.OrderingList.ITEM_SEPARATOR = ",";
+
+Richfaces.OrderingList.HANDLERS = {
+ first: function (e) { this.top(e); return false; },
+ last: function (e) { this.bottom(e); return false; },
+ up: function (e) { this.up(e); return false; },
+ down: function (e) { this.down(e); return false; }
+};
+if(!window.Richfaces) window.Richfaces = {};
+
+Richfaces.ListShuttle = Class.create();
+
+Richfaces.ListShuttle.Source = Class.create(Richfaces.ListBase);
+Richfaces.ListShuttle.Target = Class.create(Richfaces.OrderingList);
+
+Richfaces.ListShuttle.Source.SelectItem = Class.create(Richfaces.SelectItem);
+Richfaces.ListShuttle.Source.SelectItem.prototype.CLASSES = {
+ ROW : {
+ ACTIVE : "rich-shuttle-source-row-active",
+ SELECTED : "rich-shuttle-source-row-selected",
+ DISABLED : "rich-shuttle-source-row-disabled",
+ NORMAL : "rich-shuttle-source-row"
+ },
+ CELL : {
+ ACTIVE : "rich-shuttle-source-cell-active",
+ SELECTED : "rich-shuttle-source-cell-selected",
+ DISABLED : "rich-shuttle-source-cell-disabled",
+ NORMAL : "rich-shuttle-source-cell",
+ BEGIN: " rich-shuttle-source-cell-first",
+ END: " rich-shuttle-source-cell-last"
+ }
+}
+
+Richfaces.ListShuttle.Target.SelectItem = Class.create(Richfaces.SelectItem);
+Richfaces.ListShuttle.Target.SelectItem.prototype.CLASSES = {
+ ROW : {
+ ACTIVE : "rich-shuttle-target-row-active",
+ SELECTED : "rich-shuttle-target-row-selected",
+ DISABLED : "rich-shuttle-target-row-disabled",
+ NORMAL : "rich-shuttle-target-row"
+ },
+ CELL : {
+ ACTIVE : "rich-shuttle-target-cell-active",
+ SELECTED : "rich-shuttle-target-cell-selected",
+ DISABLED : "rich-shuttle-target-cell-disabled",
+ NORMAL : "rich-shuttle-target-cell",
+ BEGIN: " rich-shuttle-target-cell-first",
+ END: " rich-shuttle-target-cell-last"
+ }
+}
+
+Richfaces.ListShuttle.prototype = {
+ initialize: function(targetList, sourceList, clientId, controlIds, switchByClick, events) {
+ this.containerId = clientId;
+ this["rich:destructor"] = "destroy";
+
+ this.container = $(this.containerId);
+ this.container.component = this;
+
+ this.targetList = targetList;
+ this.sourceList = sourceList;
+
+ this.events = events;
+
+ this.isFocused = false;
+ this.wasMouseDown = false;
+ this.skipBlurEvent = false;
+
+ this.targetLayoutManager = targetList.layoutManager;
+ this.sourceLayoutManager = sourceList.layoutManager;
+
+ //for focus\blur custom events
+ this.container.observe("focus", function (e) {this.focusOrBlurHandlerLS(e);}.bindAsEventListener(this));
+ this.container.observe("keypress", function (e) {this.focusOrBlurHandlerLS(e);}.bindAsEventListener(this));
+ this.container.observe("keydown", function (e) {this.focusOrBlurHandlerLS(e);}.bindAsEventListener(this));
+ this.container.observe("mousedown", function (e) {this.focusOrBlurHandlerLS(e);}.bindAsEventListener(this));
+ this.container.observe("click", function (e) {this.focusOrBlurHandlerLS(e);}.bindAsEventListener(this));
+ this.container.observe("blur", function (e) {this.focusOrBlurHandlerLS(e);}.bindAsEventListener(this));
+
+ if (switchByClick == "true") {
+ this.targetList.shuttleTable.observe("click", function(e) {this.moveItemByClick(window.event||e, this.targetList, this.sourceList)}.bindAsEventListener(this));
+ this.sourceList.shuttleTable.observe("click", function(e) {this.moveItemByClick(window.event||e, this.sourceList, this.targetList)}.bindAsEventListener(this));
+ Event.stopObserving(this.sourceList.shuttleTable, "click", this.sourceList.clckHandler);
+ Event.stopObserving(this.targetList.shuttleTable, "click", this.targetList.clckHandler);
+ } else {
+ this.targetList.shuttleTable.observe("dblclick", function(e) {this.moveItemByClick(window.event||e, this.targetList, this.sourceList)}.bindAsEventListener(this));
+ this.sourceList.shuttleTable.observe("dblclick", function(e) {this.moveItemByClick(window.event||e, this.sourceList, this.targetList)}.bindAsEventListener(this));
+
+ sourceList._onclickHandler = sourceList.onclickHandler;
+ sourceList.onclickHandler = function(e) { this.onclickHandler(e, sourceList); }.bindAsEventListener(this);
+ targetList._onclickHandler = targetList.onclickHandler;
+ targetList.onclickHandler = function(e) { this.onclickHandler(e, targetList); }.bindAsEventListener(this);
+ }
+
+ sourceList._onkeydownHandler = sourceList.onkeydownHandler;
+ sourceList.onkeydownHandler = function(e) { this.onkeydownHandler(e, sourceList); }.bindAsEventListener(this);
+ targetList._onkeydownHandler = targetList.onkeydownHandler;
+ targetList.onkeydownHandler = function(e) { this.onkeydownHandler(e, targetList); }.bindAsEventListener(this);
+
+ this.controlList = new Array();
+ this.initControlList(clientId, controlIds);
+
+ for (var e in this.events) {
+ if (e && this.events[e]) {
+ this.container.observe("rich:" + e.toString(), this.events[e]);
+ }
+ }
+ },
+
+ destroy: function() {
+ this.container.component = null;
+ this.targetList.destroy();
+ this.sourceList.destroy();
+ },
+
+ initControlList : function(clientId, ids) {
+ for (var i = 0; i < ids.length; i++) {
+ var id = ids[i];
+ var node = $(clientId + id[0]);
+ var disNode = $(clientId + id[1]);
+ if (node && disNode) {
+ node.observe("click", Richfaces.ListShuttle.HANDLERS[id[0]].bindAsEventListener(this));
+ this.controlList[i] = new Richfaces.Control(node, disNode, false, false, id[0]);
+ }
+ }
+ //this.controlListManager();
+ },
+
+ controlListManager : function() {
+ //this.controlsProcessing();
+ this.controlsProcessing(["copy", "copyAll", "removeAll" ,"remove"], "enable");
+ if (this.sourceList.shuttleItems.length < 1)
+ this.controlsProcessing(["copy", "copyAll"], "disable");
+ if (this.sourceList.selectedItems.length < 1)
+ this.controlsProcessing(["copy"] , "disable");
+ if (this.targetList.shuttleItems.length < 1)
+ this.controlsProcessing(["removeAll" ,"remove"], "disable");
+ if (this.targetList.selectedItems.length < 1) {
+ this.controlsProcessing(["remove"], "disable");
+ }
+ },
+
+ onclickHandler : function(event, component) {
+ component._onclickHandler(event);
+ this.controlListManager();
+ //Event.stop(event); //bug: RF-2097
+ },
+
+ onkeydownHandler : function(event, component) {
+ component._onkeydownHandler(event);
+ this.controlListManager();
+ },
+
+ controlsProcessing : function(disabledControls , action) {
+ for (var i = 0; i < this.controlList.length; i++) {
+ control = this.controlList[i];
+ if (control != null) {
+ if (disabledControls != null && disabledControls.indexOf(control.action) != -1) {
+ if (action == "disable") {
+ control.doDisable();
+ } else {
+ control.doEnable();
+ }
+ }
+ }
+ }
+ },
+
+ moveItems : function(sourceComponent, targetComponent, items) {
+ if (Richfaces.invokeEvent(this.events.onlistchange, this.container, "rich:onlistchange", {sourceItems: sourceComponent.shuttleItems, targetItems: targetComponent.shuttleItems})) {
+ if (items.length > 0) {
+ var length = items.length;
+ for (var i = 0; items.length > 0;) {
+ var item = items[i];
+ this.moveItem(sourceComponent, targetComponent, item);
+ }
+ this.controlListManager();
+ if (this.targetList.controlListManager) {
+ this.targetList.controlListManager();
+ }
+
+ this.targetLayoutManager.widthSynchronization();
+ this.sourceLayoutManager.widthSynchronization();
+
+ this.container.fire("rich:onlistchanged", {sourceItems: sourceComponent.shuttleItems, targetItems: targetComponent.shuttleItems});
+ }
+ }
+ },
+
+ moveItem : function(sourceComponent, targetComponent, item) {
+ if (!item) {
+ return;
+ }
+ if (!(item instanceof Richfaces.SelectItem)) {
+ item = sourceComponent.getSelectItemByNode(item);
+ }
+ if (!LayoutManager.isIE() && (targetComponent.shuttleTbody.rows.length == 0)) {
+ var newItem = null;
+ if (item instanceof Richfaces.ListShuttle.Target.SelectItem) {
+ newItem = new this.targetList.controlClass(item._label, item._id, item._node.cloneNode(true));
+ } else {
+ newItem = new this.sourceList.controlClass(item._label, item._id, item._node.cloneNode(true));
+ }
+ this.tableUpdate(targetComponent);
+ this.addItem(targetComponent, newItem);
+
+ this.removeItem(sourceComponent, item);
+ sourceComponent.shuttleTable.deleteRow(item._node.rowIndex);
+ } else {
+ this.addItem(targetComponent, item);
+ this.removeItem(sourceComponent, item);
+ }
+ },
+
+ removeItem : function(component, item) {
+ var items = component.shuttleItems;
+ component.selectedItems.remove(item._node);
+ items.remove(item);
+ if (item == component.activeItem) {
+ component.activeItem == null;
+ }
+ },
+
+ addItem : function(component, item) {
+ item.doNormal(Richfaces.getExternalClass(item.rowIndex), component.columnsClasses);
+
+ component.shuttleTbody.insertBefore(item._node, null);
+ component.shuttleItems.push(item);
+ },
+
+ tableUpdate : function(component) {
+ var table = component.shuttleTable;
+ var tbody = table.tBodies[0];
+ var newTbody = tbody.cloneNode(false);
+ table.removeChild(tbody);
+ table.appendChild(newTbody);
+ component.shuttleTbody = table.tBodies[0];
+ },
+
+ moveItemByClick : function(event, sourceComponent, targetComponent, layoutManager) {
+ if (Richfaces.invokeEvent(this.events.onlistchange, this.container, "rich:onlistchange", {sourceItems: sourceComponent.shuttleItems, targetItems: targetComponent.shuttleItems})) {
+ var item = this.sourceList.getEventTargetRow(event);
+ this.moveItem(sourceComponent, targetComponent, item);
+
+ this.controlListManager();
+ if (this.targetList.controlListManager) {
+ this.targetList.controlListManager();
+ }
+
+ this.targetLayoutManager.widthSynchronization();
+ this.sourceLayoutManager.widthSynchronization();
+
+ this.container.fire("rich:onlistchanged", {sourceItems: sourceComponent.shuttleItems, targetItems: targetComponent.shuttleItems});
+ }
+ },
+
+ copyAll : function() {
+ this.container.fire("rich:oncopyallclick", {sourceItems: this.sourceList.shuttleItems, targetItems: this.targetList.shuttleItems, selection: this.sourceList.getSelection()});
+ this.moveItems(this.sourceList, this.targetList, this.sourceList.shuttleItems);
+ },
+
+ copy : function() {
+ this.container.fire("rich:oncopyclick", {sourceItems: this.sourceList.shuttleItems, targetItems: this.targetList.shuttleItems, selection: this.sourceList.getSelection()});
+ this.moveItems(this.sourceList, this.targetList, this.sourceList.selectedItems);
+ },
+
+ removeAll : function() {
+ this.container.fire("rich:onremoveallclick", {sourceItems: this.sourceList.shuttleItems, targetItems: this.targetList.shuttleItems, selection: this.targetList.getSelection()});
+ this.moveItems(this.targetList, this.sourceList, this.targetList.shuttleItems);
+ },
+
+ remove : function() {
+ this.container.fire("rich:onremoveclick", {sourceItems: this.sourceList.shuttleItems, targetItems: this.targetList.shuttleItems, selection: this.targetList.getSelection()});
+ this.moveItems(this.targetList, this.sourceList, this.targetList.selectedItems);
+ },
+
+ up : function() {
+ this.targetList.up();
+ },
+
+ down : function() {
+ this.targetList.down();
+ },
+
+ top : function() {
+ this.targetList.top();
+ },
+
+ bottom : function() {
+ this.targetList.bottom();
+ },
+
+ focusOrBlurHandlerLS : function(e) {
+ var componentID = e.target.id;
+ if (e.type == "keydown") {
+ var code = e.which;
+ this.skipBlurEvent = false;
+ this.wasKeyDown = true;
+ if (Event.KEY_TAB == code) {
+ if (e.shiftKey) {
+ if ((componentID == this.sourceList.focusKeeper.id) && this.isFocused) {
+ //blur:shift+tab keys were pressed
+ this.fireOnblurEvent();
+ } else {
+ this.skipBlurEvent = true;
+ }
+ } else {
+ if ((componentID == this.targetList.focusKeeper.id) && this.isFocused) {
+ //blur:tab key was pressed
+ this.fireOnblurEvent();
+
+ } else {
+ this.skipBlurEvent = true;
+ }
+ }
+ }
+ } else if (e.type == "mousedown") {
+ this.skipBlurEvent = false;
+ this.wasMouseDown = true;
+ if (!this.isFocused) {
+ this.fireOnfocusEvent();
+ }
+ } else if (e.type == "click") {
+ this.wasMouseDown = false;
+ } else if (e.type == "keypress") {
+ this.wasKeyDown = false;
+ } else if (e.type == "focus") {
+ if (componentID == this.sourceList.focusKeeper.id && !this.wasMouseDown && !this.isFocused) {
+ //focus:tab key was pressed
+ this.fireOnfocusEvent();
+ } else if (componentID == this.targetList.focusKeeper.id && !this.wasMouseDown && !this.isFocused) {
+ //focus:shift+tab keys were pressed
+ this.fireOnfocusEvent();
+ }
+ } else if (e.type == "blur") {
+ //onblur event
+ if (!this.wasMouseDown && !this.wasKeyDown && this.isFocused && !this.skipBlurEvent) {
+ //blur:click component outside
+ this.fireOnblurEvent();
+ }
+ }
+ },
+
+ fireOnfocusEvent : function() {
+ //LOG.warn("fireOnfocusEvent|");
+ this.isFocused = true;
+ this.container.fire("rich:onfocus", {});
+ },
+
+ fireOnblurEvent : function() {
+ //LOG.warn("fireOnblurEvent|");
+ this.isFocused = false;
+ this.container.fire("rich:onblur", {});
+ }
+};
+
+Richfaces.ListShuttle.HANDLERS = {
+ copy: function (e) { this.copy(); return false; },
+ copyAll: function (e) { this.copyAll(); return false; },
+ remove: function (e) { this.remove(); return false; },
+ removeAll: function (e) { this.removeAll(); return false; }
+};
+// ============================= after ==========================
16 years, 11 months
JBoss Rich Faces SVN: r12351 - in trunk/ui/message/src: test/java/org/richfaces/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-01-20 09:55:23 -0500 (Tue, 20 Jan 2009)
New Revision: 12351
Modified:
trunk/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java
trunk/ui/message/src/test/java/org/richfaces/component/UIMessagesTest.java
Log:
https://jira.jboss.org/jira/browse/RF-5830
Modified: trunk/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java
===================================================================
--- trunk/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java 2009-01-20 13:44:58 UTC (rev 12350)
+++ trunk/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java 2009-01-20 14:55:23 UTC (rev 12351)
@@ -28,7 +28,6 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Map.Entry;
import javax.el.ELException;
import javax.el.ValueExpression;
@@ -299,10 +298,30 @@
* </p>
*/
private void writeObject(ObjectOutputStream out) throws IOException {
- out.writeUTF(clientId);
+ if (clientId != null) {
+ out.writeBoolean(true);
+ out.writeUTF(clientId);
+ } else {
+ out.writeBoolean(false);
+ }
+
out.writeInt(message.getSeverity().getOrdinal());
- out.writeUTF(message.getSummary());
- out.writeUTF(message.getDetail());
+
+ String summary = message.getSummary();
+ if (summary != null) {
+ out.writeBoolean(true);
+ out.writeUTF(summary);
+ } else {
+ out.writeBoolean(false);
+ }
+
+ String detail = message.getDetail();
+ if (detail != null) {
+ out.writeBoolean(true);
+ out.writeUTF(detail);
+ } else {
+ out.writeBoolean(false);
+ }
}
/**
@@ -313,14 +332,27 @@
*/
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
- clientId = in.readUTF();
+
+ if (in.readBoolean()) {
+ clientId = in.readUTF();
+ }
+
Severity severity = FacesMessage.SEVERITY_INFO;
int ordinal = in.readInt();
if (ordinal >= 0 && ordinal < FacesMessage.VALUES.size()) {
severity = (Severity) FacesMessage.VALUES.get(ordinal);
}
- String summary = in.readUTF();
- String detail = in.readUTF();
+
+ String summary = null;
+ if (in.readBoolean()) {
+ summary = in.readUTF();
+ }
+
+ String detail = null;
+ if (in.readBoolean()) {
+ detail = in.readUTF();
+ }
+
message = new FacesMessage(severity, summary, detail);
}
Modified: trunk/ui/message/src/test/java/org/richfaces/component/UIMessagesTest.java
===================================================================
--- trunk/ui/message/src/test/java/org/richfaces/component/UIMessagesTest.java 2009-01-20 13:44:58 UTC (rev 12350)
+++ trunk/ui/message/src/test/java/org/richfaces/component/UIMessagesTest.java 2009-01-20 14:55:23 UTC (rev 12351)
@@ -3,7 +3,11 @@
*/
package org.richfaces.component;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -215,6 +219,59 @@
uiMessages.addMessagesForId(facesContext, INPUT_ID, severenities);
assertEquals(1, uiMessages.getRenderedMessages().size());
}
+
+ public void testMessageSerialization() throws Exception {
+ UIRichMessages.FacesMessageWithId message = saveRestore(new UIRichMessages.FacesMessageWithId("clientId",
+ new FacesMessage(FacesMessage.SEVERITY_INFO, "summary", "detail")));
+
+ assertEquals("clientId", message.getClientId());
+ assertNotNull(message.getMessage());
+ assertEquals(FacesMessage.SEVERITY_INFO, message.getMessage().getSeverity());
+ assertEquals("summary", message.getMessage().getSummary());
+ assertEquals("detail", message.getMessage().getDetail());
+
+ message = saveRestore(new UIRichMessages.FacesMessageWithId(null,
+ new FacesMessage()));
+
+ assertNull(message.getClientId());
+ assertNotNull(message.getMessage());
+ assertNull(message.getMessage().getSummary());
+ assertNull(message.getMessage().getDetail());
+
+ message = saveRestore(new UIRichMessages.FacesMessageWithId(null,
+ new FacesMessage("summary")));
+
+ assertNull(message.getClientId());
+ assertNotNull(message.getMessage());
+ assertEquals("summary", message.getMessage().getSummary());
+ assertEquals("summary", message.getMessage().getDetail());
+
+ message = saveRestore(new UIRichMessages.FacesMessageWithId(null,
+ new FacesMessage("summary", "detail")));
+
+ assertNull(message.getClientId());
+ assertNotNull(message.getMessage());
+ assertEquals("summary", message.getMessage().getSummary());
+ assertEquals("detail", message.getMessage().getDetail());
+
+ }
+
+ private <T> T saveRestore(T t) throws IOException, ClassNotFoundException {
+ T newTInstance = null;
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(t);
+ oos.close();
+
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ newTInstance = (T) ois.readObject();
+ ois.close();
+
+ return newTInstance;
+ }
+
/**
* @return
*/
16 years, 11 months