summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/js/dom.js
diff options
context:
space:
mode:
authorwei <>2006-01-09 04:39:05 +0000
committerwei <>2006-01-09 04:39:05 +0000
commit9f2ecd591d5be41bb9dc7b8a0fa144ac35a173bb (patch)
tree122d77d166d5df687d524173b883d87fd6674c0d /framework/Web/Javascripts/js/dom.js
parent9c9a2d731fea9679f65904a3a6b72dd78b4253a4 (diff)
TRequiredFieldValidator works now. See FunctionalTests/index.php in your browser.
Diffstat (limited to 'framework/Web/Javascripts/js/dom.js')
-rw-r--r--framework/Web/Javascripts/js/dom.js520
1 files changed, 317 insertions, 203 deletions
diff --git a/framework/Web/Javascripts/js/dom.js b/framework/Web/Javascripts/js/dom.js
index f22d5c80..b93a6c63 100644
--- a/framework/Web/Javascripts/js/dom.js
+++ b/framework/Web/Javascripts/js/dom.js
@@ -1,7 +1,7 @@
document.getElementsByClassName=function(_1,_2){
var _3=($(_2)||document.body).getElementsByTagName("*");
return $A(_3).inject([],function(_4,_5){
-if(Element.hasClassName(_5,_1)){
+if(_5.className.match(new RegExp("(^|\\s)"+_1+"(\\s|$)"))){
_4.push(_5);
}
return _4;
@@ -30,121 +30,128 @@ _10.style.display="";
},remove:function(_11){
_11=$(_11);
_11.parentNode.removeChild(_11);
-},getHeight:function(_12){
-_12=$(_12);
-return _12.offsetHeight;
-},classNames:function(_13){
-return new Element.ClassNames(_13);
-},hasClassName:function(_14,_15){
-if(!(_14=$(_14))){
-return;
-}
-return Element.classNames(_14).include(_15);
-},addClassName:function(_16,_17){
+},update:function(_12,_13){
+$(_12).innerHTML=_13.stripScripts();
+setTimeout(function(){
+_13.evalScripts();
+},10);
+},getHeight:function(_14){
+_14=$(_14);
+return _14.offsetHeight;
+},classNames:function(_15){
+return new Element.ClassNames(_15);
+},hasClassName:function(_16,_17){
if(!(_16=$(_16))){
return;
}
-return Element.classNames(_16).add(_17);
-},removeClassName:function(_18,_19){
+return Element.classNames(_16).include(_17);
+},addClassName:function(_18,_19){
if(!(_18=$(_18))){
return;
}
-return Element.classNames(_18).remove(_19);
-},cleanWhitespace:function(_20){
-if(undef(_20)||isNull(_20)){
+return Element.classNames(_18).add(_19);
+},removeClassName:function(_20,_21){
+if(!(_20=$(_20))){
return;
}
-_20=$(_20);
-for(var i=0;i<_20.childNodes.length;i++){
-var _21=_20.childNodes[i];
-if(_21.nodeType==3&&!/\S/.test(_21.nodeValue)){
-_21.parentNode.removeChild(_21);
+return Element.classNames(_20).remove(_21);
+},cleanWhitespace:function(_22){
+_22=$(_22);
+for(var i=0;i<_22.childNodes.length;i++){
+var _23=_22.childNodes[i];
+if(_23.nodeType==3&&!/\S/.test(_23.nodeValue)){
+Element.remove(_23);
}
}
-},empty:function(_22){
-return $(_22).innerHTML.match(/^\s*$/);
-},scrollTo:function(_23){
-_23=$(_23);
-var x=_23.x?_23.x:_23.offsetLeft,y=_23.y?_23.y:_23.offsetTop;
-window.scrollTo(x,y);
-},getStyle:function(_25,_26){
+},empty:function(_24){
+return $(_24).innerHTML.match(/^\s*$/);
+},scrollTo:function(_25){
_25=$(_25);
-var _27=_25.style[_26.camelize()];
-if(!_27){
+var x=_25.x?_25.x:_25.offsetLeft,y=_25.y?_25.y:_25.offsetTop;
+window.scrollTo(x,y);
+},getStyle:function(_27,_28){
+_27=$(_27);
+var _29=_27.style[_28.camelize()];
+if(!_29){
if(document.defaultView&&document.defaultView.getComputedStyle){
-var css=document.defaultView.getComputedStyle(_25,null);
-_27=css?css.getPropertyValue(_26):null;
+var css=document.defaultView.getComputedStyle(_27,null);
+_29=css?css.getPropertyValue(_28):null;
}else{
-if(_25.currentStyle){
-_27=_25.currentStyle[_26.camelize()];
+if(_27.currentStyle){
+_29=_27.currentStyle[_28.camelize()];
}
}
}
-if(window.opera&&["left","top","right","bottom"].include(_26)){
-if(Element.getStyle(_25,"position")=="static"){
-_27="auto";
+if(window.opera&&["left","top","right","bottom"].include(_28)){
+if(Element.getStyle(_27,"position")=="static"){
+_29="auto";
}
}
-return _27=="auto"?null:_27;
-},getDimensions:function(_29){
-_29=$(_29);
-if(Element.getStyle(_29,"display")!="none"){
-return {width:_29.offsetWidth,height:_29.offsetHeight};
+return _29=="auto"?null:_29;
+},setStyle:function(_31,_32){
+_31=$(_31);
+for(name in _32){
+_31.style[name.camelize()]=_32[name];
+}
+},getDimensions:function(_33){
+_33=$(_33);
+if(Element.getStyle(_33,"display")!="none"){
+return {width:_33.offsetWidth,height:_33.offsetHeight};
}
-var els=_29.style;
-var _31=els.visibility;
-var _32=els.position;
+var els=_33.style;
+var _35=els.visibility;
+var _36=els.position;
els.visibility="hidden";
els.position="absolute";
els.display="";
-var _33=_29.clientWidth;
-var _34=_29.clientHeight;
+var _37=_33.clientWidth;
+var _38=_33.clientHeight;
els.display="none";
-els.position=_32;
-els.visibility=_31;
-return {width:_33,height:_34};
-},makePositioned:function(_35){
-_35=$(_35);
-var pos=Element.getStyle(_35,"position");
+els.position=_36;
+els.visibility=_35;
+return {width:_37,height:_38};
+},makePositioned:function(_39){
+_39=$(_39);
+var pos=Element.getStyle(_39,"position");
if(pos=="static"||!pos){
-_35._madePositioned=true;
-_35.style.position="relative";
+_39._madePositioned=true;
+_39.style.position="relative";
if(window.opera){
-_35.style.top=0;
-_35.style.left=0;
+_39.style.top=0;
+_39.style.left=0;
}
}
-},undoPositioned:function(_37){
-_37=$(_37);
-if(_37._madePositioned){
-_37._madePositioned=undefined;
-_37.style.position=_37.style.top=_37.style.left=_37.style.bottom=_37.style.right="";
+},undoPositioned:function(_41){
+_41=$(_41);
+if(_41._madePositioned){
+_41._madePositioned=undefined;
+_41.style.position=_41.style.top=_41.style.left=_41.style.bottom=_41.style.right="";
}
-},makeClipping:function(_38){
-_38=$(_38);
-if(_38._overflow){
+},makeClipping:function(_42){
+_42=$(_42);
+if(_42._overflow){
return;
}
-_38._overflow=_38.style.overflow;
-if((Element.getStyle(_38,"overflow")||"visible")!="hidden"){
-_38.style.overflow="hidden";
+_42._overflow=_42.style.overflow;
+if((Element.getStyle(_42,"overflow")||"visible")!="hidden"){
+_42.style.overflow="hidden";
}
-},undoClipping:function(_39){
-_39=$(_39);
-if(_39._overflow){
+},undoClipping:function(_43){
+_43=$(_43);
+if(_43._overflow){
return;
}
-_39.style.overflow=_39._overflow;
-_39._overflow=undefined;
+_43.style.overflow=_43._overflow;
+_43._overflow=undefined;
}});
var Toggle=new Object();
Toggle.display=Element.toggle;
-Abstract.Insertion=function(_40){
-this.adjacency=_40;
+Abstract.Insertion=function(_44){
+this.adjacency=_44;
};
-Abstract.Insertion.prototype={initialize:function(_41,_42){
-this.element=$(_41);
-this.content=_42;
+Abstract.Insertion.prototype={initialize:function(_45,_46){
+this.element=$(_45);
+this.content=_46.stripScripts();
if(this.adjacency&&this.element.insertAdjacentHTML){
try{
this.element.insertAdjacentHTML(this.adjacency,this.content);
@@ -163,6 +170,9 @@ this.initializeRange();
}
this.insertContent([this.range.createContextualFragment(this.content)]);
}
+setTimeout(function(){
+_46.evalScripts();
+},10);
},contentFromAnonymousTable:function(){
var div=document.createElement("div");
div.innerHTML="<table><tbody>"+this.content+"</tbody></table>";
@@ -172,58 +182,58 @@ var Insertion=new Object();
Insertion.Before=Class.create();
Insertion.Before.prototype=Object.extend(new Abstract.Insertion("beforeBegin"),{initializeRange:function(){
this.range.setStartBefore(this.element);
-},insertContent:function(_44){
-_44.each((function(_45){
-this.element.parentNode.insertBefore(_45,this.element);
+},insertContent:function(_48){
+_48.each((function(_49){
+this.element.parentNode.insertBefore(_49,this.element);
}).bind(this));
}});
Insertion.Top=Class.create();
Insertion.Top.prototype=Object.extend(new Abstract.Insertion("afterBegin"),{initializeRange:function(){
this.range.selectNodeContents(this.element);
this.range.collapse(true);
-},insertContent:function(_46){
-_46.reverse().each((function(_47){
-this.element.insertBefore(_47,this.element.firstChild);
+},insertContent:function(_50){
+_50.reverse(false).each((function(_51){
+this.element.insertBefore(_51,this.element.firstChild);
}).bind(this));
}});
Insertion.Bottom=Class.create();
Insertion.Bottom.prototype=Object.extend(new Abstract.Insertion("beforeEnd"),{initializeRange:function(){
this.range.selectNodeContents(this.element);
this.range.collapse(this.element);
-},insertContent:function(_48){
-_48.each((function(_49){
-this.element.appendChild(_49);
+},insertContent:function(_52){
+_52.each((function(_53){
+this.element.appendChild(_53);
}).bind(this));
}});
Insertion.After=Class.create();
Insertion.After.prototype=Object.extend(new Abstract.Insertion("afterEnd"),{initializeRange:function(){
this.range.setStartAfter(this.element);
-},insertContent:function(_50){
-_50.each((function(_51){
-this.element.parentNode.insertBefore(_51,this.element.nextSibling);
+},insertContent:function(_54){
+_54.each((function(_55){
+this.element.parentNode.insertBefore(_55,this.element.nextSibling);
}).bind(this));
}});
Element.ClassNames=Class.create();
-Element.ClassNames.prototype={initialize:function(_52){
-this.element=$(_52);
-},_each:function(_53){
-this.element.className.split(/\s+/).select(function(_54){
-return _54.length>0;
-})._each(_53);
-},set:function(_55){
-this.element.className=_55;
-},add:function(_56){
-if(this.include(_56)){
+Element.ClassNames.prototype={initialize:function(_56){
+this.element=$(_56);
+},_each:function(_57){
+this.element.className.split(/\s+/).select(function(_58){
+return _58.length>0;
+})._each(_57);
+},set:function(_59){
+this.element.className=_59;
+},add:function(_60){
+if(this.include(_60)){
return;
}
-this.set(this.toArray().concat(_56).join(" "));
-},remove:function(_57){
-if(!this.include(_57)){
+this.set(this.toArray().concat(_60).join(" "));
+},remove:function(_61){
+if(!this.include(_61)){
return;
}
-this.set(this.select(function(_58){
-return _58!=_57;
-}));
+this.set(this.select(function(_62){
+return _62!=_61;
+}).join(" "));
},toString:function(){
return this.toArray().join(" ");
}};
@@ -232,6 +242,124 @@ Object.extend(Element.ClassNames.prototype,Enumerable);
Object.extend(Element,{condClassName:function(_1,_2,_3){
(_3?Element.addClassName:Element.removeClassName)(_1,_2);
}});
+Prado.Element={setValue:function(_4,_5){
+var el=$(_4);
+if(el&&typeof (el.value)!="undefined"){
+el.value=_5;
+}
+},select:function(_7,_8,_9){
+var el=$(_7);
+var _10=_7.indexOf("[]")>-1;
+if(!el&&!_10){
+return;
+}
+_8=_10?"check"+_8:el.tagName.toLowerCase()+_8;
+var _11=Prado.Element.Selection;
+if(isFunction(_11[_8])){
+_11[_8](_10?_7:el,_9);
+}
+},click:function(_12){
+var el=$(_12);
+if(!el){
+return;
+}
+if(document.createEvent){
+var evt=document.createEvent("HTMLEvents");
+evt.initEvent("click",true,true);
+el.dispatchEvent(evt);
+}else{
+if(el.fireEvent){
+el.fireEvent("onclick");
+if(isFunction(el.onclick)){
+el.onclick();
+}
+}
+}
+},setAttribute:function(_14,_15,_16){
+var el=$(_14);
+if(_15=="disabled"&&_16==false){
+el.removeAttribute(_15);
+}else{
+el.setAttribute(_15,_16);
+}
+},setOptions:function(_17,_18){
+var el=$(_17);
+if(el&&el.tagName.toLowerCase()=="select"){
+while(el.length>0){
+el.remove(0);
+}
+for(var i=0;i<_18.length;i++){
+el.options[el.options.length]=new Option(_18[i][0],_18[i][1]);
+}
+}
+}};
+Prado.Element.Selection={inputValue:function(el,_20){
+switch(el.type.toLowerCase()){
+case "checkbox":
+case "radio":
+return el.checked=_20;
+}
+},selectValue:function(el,_21){
+$A(el.options).each(function(_22){
+_22.selected=_22.value==_21;
+});
+},selectIndex:function(el,_23){
+if(el.type=="select-one"){
+el.selectedIndex=_23;
+}else{
+for(var i=0;i<el.length;i++){
+if(i==_23){
+el.options[i].selected=true;
+}
+}
+}
+},selectClear:function(el){
+el.selectedIndex=-1;
+},selectAll:function(el){
+$A(el.options).each(function(_24){
+_24.selected=true;
+Logger.warn(_24.value);
+});
+},selectInvert:function(el){
+$A(el.options).each(function(_25){
+_25.selected=!_25.selected;
+});
+},checkValue:function(_26,_27){
+$A(document.getElementsByName(_26)).each(function(el){
+el.checked=el.value==_27;
+});
+},checkIndex:function(_28,_29){
+var _30=$A(document.getElementsByName(_28));
+for(var i=0;i<_30.length;i++){
+if(i==_29){
+_30[i].checked=true;
+}
+}
+},checkClear:function(_31){
+$A(document.getElementsByName(_31)).each(function(el){
+el.checked=false;
+});
+},checkAll:function(_32){
+$A(document.getElementsByName(_32)).each(function(el){
+el.checked=true;
+});
+},checkInvert:function(_33){
+$A(document.getElementsByName(_33)).each(function(el){
+el.checked=!el.checked;
+});
+}};
+Object.extend(Prado.Element,{Insert:{After:function(_34,_35){
+new Insertion.After(_34,_35);
+},Before:function(_36,_37){
+new Insertion.Before(_36.innerHTML);
+},Below:function(_38,_39){
+new Insertion.Bottom(_38,_39);
+},Above:function(_40,_41){
+new Insertion.Top(_40,_41);
+}},CssClass:{set:function(_42,_43){
+_42=new Element.ClassNames(_42);
+_42.set(_43);
+}}});
var Field={clear:function(){
for(var i=0;i<arguments.length;i++){
@@ -249,8 +377,11 @@ return true;
},select:function(_3){
$(_3).select();
},activate:function(_4){
-$(_4).focus();
-$(_4).select();
+_4=$(_4);
+_4.focus();
+if(_4.select){
+_4.select();
+}
}};
var Form={serialize:function(_5){
var _6=Form.getElements($(_5));
@@ -263,7 +394,7 @@ _7.push(_8);
}
return _7.join("&");
},getElements:function(_9){
-var _9=$(_9);
+_9=$(_9);
var _10=new Array();
for(tagName in Form.Element.Serializers){
var _11=_9.getElementsByTagName(tagName);
@@ -273,7 +404,7 @@ _10.push(_11[j]);
}
return _10;
},getInputs:function(_13,_14,_15){
-var _13=$(_13);
+_13=$(_13);
var _16=_13.getElementsByTagName("input");
if(!_14&&!_15){
return _16;
@@ -300,94 +431,99 @@ for(var i=0;i<_23.length;i++){
var _24=_23[i];
_24.disabled="";
}
-},focusFirstElement:function(_25){
-var _25=$(_25);
-var _26=Form.getElements(_25);
-for(var i=0;i<_26.length;i++){
-var _27=_26[i];
-if(_27.type!="hidden"&&!_27.disabled){
-Field.activate(_27);
-break;
-}
-}
+},findFirstElement:function(_25){
+return Form.getElements(_25).find(function(_26){
+return _26.type!="hidden"&&!_26.disabled&&["input","select","textarea"].include(_26.tagName.toLowerCase());
+});
+},focusFirstElement:function(_27){
+Field.activate(Form.findFirstElement(_27));
},reset:function(_28){
$(_28).reset();
}};
Form.Element={serialize:function(_29){
-var _29=$(_29);
+_29=$(_29);
var _30=_29.tagName.toLowerCase();
var _31=Form.Element.Serializers[_30](_29);
if(_31){
-return encodeURIComponent(_31[0])+"="+encodeURIComponent(_31[1]);
+var key=encodeURIComponent(_31[0]);
+if(key.length==0){
+return;
+}
+if(_31[1].constructor!=Array){
+_31[1]=[_31[1]];
}
-},getValue:function(_32){
-var _32=$(_32);
-var _33=_32.tagName.toLowerCase();
-var _34=Form.Element.Serializers[_33](_32);
-if(_34){
-return _34[1];
+return _31[1].map(function(_33){
+return key+"="+encodeURIComponent(_33);
+}).join("&");
+}
+},getValue:function(_34){
+_34=$(_34);
+var _35=_34.tagName.toLowerCase();
+var _36=Form.Element.Serializers[_35](_34);
+if(_36){
+return _36[1];
}
}};
-Form.Element.Serializers={input:function(_35){
-switch(_35.type.toLowerCase()){
+Form.Element.Serializers={input:function(_37){
+switch(_37.type.toLowerCase()){
case "submit":
case "hidden":
case "password":
case "text":
-return Form.Element.Serializers.textarea(_35);
+return Form.Element.Serializers.textarea(_37);
case "checkbox":
case "radio":
-return Form.Element.Serializers.inputSelector(_35);
+return Form.Element.Serializers.inputSelector(_37);
}
return false;
-},inputSelector:function(_36){
-if(_36.checked){
-return [_36.name,_36.value];
-}
-},textarea:function(_37){
-return [_37.name,_37.value];
-},select:function(_38){
-return Form.Element.Serializers[_38.type=="select-one"?"selectOne":"selectMany"](_38);
-},selectOne:function(_39){
-var _40="",opt,index=_39.selectedIndex;
+},inputSelector:function(_38){
+if(_38.checked){
+return [_38.name,_38.value];
+}
+},textarea:function(_39){
+return [_39.name,_39.value];
+},select:function(_40){
+return Form.Element.Serializers[_40.type=="select-one"?"selectOne":"selectMany"](_40);
+},selectOne:function(_41){
+var _42="",opt,index=_41.selectedIndex;
if(index>=0){
-opt=_39.options[index];
-_40=opt.value;
-if(!_40&&!("value" in opt)){
-_40=opt.text;
+opt=_41.options[index];
+_42=opt.value;
+if(!_42&&!("value" in opt)){
+_42=opt.text;
}
}
-return [_39.name,_40];
-},selectMany:function(_41){
-var _42=new Array();
-for(var i=0;i<_41.length;i++){
-var opt=_41.options[i];
+return [_41.name,_42];
+},selectMany:function(_43){
+var _44=new Array();
+for(var i=0;i<_43.length;i++){
+var opt=_43.options[i];
if(opt.selected){
-var _44=opt.value;
-if(!_44&&!("value" in opt)){
-_44=opt.text;
+var _46=opt.value;
+if(!_46&&!("value" in opt)){
+_46=opt.text;
}
-_42.push(_44);
+_44.push(_46);
}
}
-return [_41.name,_42];
+return [_43.name,_44];
}};
var $F=Form.Element.getValue;
Abstract.TimedObserver=function(){
};
-Abstract.TimedObserver.prototype={initialize:function(_45,_46,_47){
-this.frequency=_46;
-this.element=$(_45);
-this.callback=_47;
+Abstract.TimedObserver.prototype={initialize:function(_47,_48,_49){
+this.frequency=_48;
+this.element=$(_47);
+this.callback=_49;
this.lastValue=this.getValue();
this.registerCallback();
},registerCallback:function(){
setInterval(this.onTimerEvent.bind(this),this.frequency*1000);
},onTimerEvent:function(){
-var _48=this.getValue();
-if(this.lastValue!=_48){
-this.callback(this.element,_48);
-this.lastValue=_48;
+var _50=this.getValue();
+if(this.lastValue!=_50){
+this.callback(this.element,_50);
+this.lastValue=_50;
}
}};
Form.Element.Observer=Class.create();
@@ -400,9 +536,9 @@ return Form.serialize(this.element);
}});
Abstract.EventObserver=function(){
};
-Abstract.EventObserver.prototype={initialize:function(_49,_50){
-this.element=$(_49);
-this.callback=_50;
+Abstract.EventObserver.prototype={initialize:function(_51,_52){
+this.element=$(_51);
+this.callback=_52;
this.lastValue=this.getValue();
if(this.element.tagName.toLowerCase()=="form"){
this.registerFormCallbacks();
@@ -410,39 +546,29 @@ this.registerFormCallbacks();
this.registerCallback(this.element);
}
},onElementEvent:function(){
-var _51=this.getValue();
-if(this.lastValue!=_51){
-this.callback(this.element,_51);
-this.lastValue=_51;
+var _53=this.getValue();
+if(this.lastValue!=_53){
+this.callback(this.element,_53);
+this.lastValue=_53;
}
},registerFormCallbacks:function(){
-var _52=Form.getElements(this.element);
-for(var i=0;i<_52.length;i++){
-this.registerCallback(_52[i]);
+var _54=Form.getElements(this.element);
+for(var i=0;i<_54.length;i++){
+this.registerCallback(_54[i]);
}
-},registerCallback:function(_53){
-if(_53.type){
-switch(_53.type.toLowerCase()){
+},registerCallback:function(_55){
+if(_55.type){
+switch(_55.type.toLowerCase()){
case "checkbox":
case "radio":
-_53.target=this;
-_53.prev_onclick=_53.onclick||Prototype.emptyFunction;
-_53.onclick=function(){
-this.prev_onclick();
-this.target.onElementEvent();
-};
+Event.observe(_55,"click",this.onElementEvent.bind(this));
break;
case "password":
case "text":
case "textarea":
case "select-one":
case "select-multiple":
-_53.target=this;
-_53.prev_onchange=_53.onchange||Prototype.emptyFunction;
-_53.onchange=function(){
-this.prev_onchange();
-this.target.onElementEvent();
-};
+Event.observe(_55,"change",this.onElementEvent.bind(this));
break;
}
}
@@ -857,9 +983,7 @@ return _4;
var Behaviour={list:new Array,register:function(_1){
Behaviour.list.push(_1);
},start:function(){
-Behaviour.addLoadEvent(function(){
-Behaviour.apply();
-});
+Event.OnLoad(Behaviour.apply);
},apply:function(){
for(h=0;sheet=Behaviour.list[h];h++){
for(selector in sheet){
@@ -872,16 +996,6 @@ sheet[selector](element);
}
}
}
-},addLoadEvent:function(_2){
-var _3=window.onload;
-if(typeof window.onload!="function"){
-window.onload=_2;
-}else{
-window.onload=function(){
-_3();
-_2();
-};
-}
}};
Behaviour.start();