summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwei <>2005-12-13 07:08:30 +0000
committerwei <>2005-12-13 07:08:30 +0000
commit35c7ff28cbc311fba5e394b11fb756a4dc1edcb9 (patch)
tree1ee39944b4cdba1ecc6aeb2a952139b5a3165f67
parent2c383b6050b3d8cc6ac7a9442c999cb903af43ab (diff)
Removed inline javascript from components. Adding TJavascriptLogger and logger.js
-rw-r--r--.gitattributes2
-rw-r--r--demos/controls/protected/pages/HomePage.tpl60
-rw-r--r--framework/Web/Javascripts/base/prado.js49
-rw-r--r--framework/Web/Javascripts/extended/event.js4
-rw-r--r--framework/Web/Javascripts/js/base.js32
-rw-r--r--framework/Web/Javascripts/js/dom.js2
-rw-r--r--framework/Web/Javascripts/js/logger.js461
-rw-r--r--framework/Web/UI/TAssetManager.php25
-rw-r--r--framework/Web/UI/TClientScriptManager.php20
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php6
-rw-r--r--framework/Web/UI/WebControls/TButton.php62
-rw-r--r--framework/Web/UI/WebControls/TCheckBox.php45
-rw-r--r--framework/Web/UI/WebControls/TImageButton.php33
-rw-r--r--framework/Web/UI/WebControls/TJavascriptLogger.php65
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php63
-rw-r--r--framework/Web/UI/WebControls/TRadioButton.php15
-rw-r--r--framework/Web/UI/WebControls/TTextBox.php56
17 files changed, 800 insertions, 200 deletions
diff --git a/.gitattributes b/.gitattributes
index f9075e01..ccfa0dcb 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -107,6 +107,7 @@ framework/Web/Javascripts/extra/logger.js -text
framework/Web/Javascripts/extra/tp_template.js -text
framework/Web/Javascripts/js/base.js -text
framework/Web/Javascripts/js/dom.js -text
+framework/Web/Javascripts/js/logger.js -text
framework/Web/Javascripts/js/validator.js -text
framework/Web/Javascripts/prototype/ajax.js -text
framework/Web/Javascripts/prototype/array.js -text
@@ -171,6 +172,7 @@ framework/Web/UI/WebControls/THiddenField.php -text
framework/Web/UI/WebControls/THyperLink.php -text
framework/Web/UI/WebControls/TImage.php -text
framework/Web/UI/WebControls/TImageButton.php -text
+framework/Web/UI/WebControls/TJavascriptLogger.php -text
framework/Web/UI/WebControls/TLabel.php -text
framework/Web/UI/WebControls/TLinkButton.php -text
framework/Web/UI/WebControls/TLiteral.php -text
diff --git a/demos/controls/protected/pages/HomePage.tpl b/demos/controls/protected/pages/HomePage.tpl
index 76c24e39..ea5a182c 100644
--- a/demos/controls/protected/pages/HomePage.tpl
+++ b/demos/controls/protected/pages/HomePage.tpl
@@ -4,17 +4,57 @@
<div>
<com:THiddenField Value="test" />
<h1>Welcome! <%=$this->User->Name %></h1>
+
+<com:TJavascriptLogger />
+
<com:TLiteral Text="<literal>" Encode="true"/>
-<com:TTextBox ID="TextBox" Text="textbox" AutoPostBack="true" CausesValidation="false" />
-<com:TLabel Text="test" AssociatedControlID="checkbox"/><br/>
-<com:System.Web.UI.WebControls.TButton text="Toggle Button" ForeColor="red" Font.size="18" Click="testClick" /> (requires membership)<br/>
-<com:TCheckBox Text="Checkbox" ID="checkbox" AutoPostBack="true" /><br/>
-<com:TRadioButton Text="Radiobutton" ID="radiobutton" AutoPostBack="true" /><br/>
-<com:TImage ImageUrl=<%~/fungii_logo.gif %> />
-<com:TImageButton ImageUrl=<%~/fungii_logo.gif %> Click="clickImage"/><br/>
-<com:THyperLink Text="Visit a 'classless' page" NavigateUrl="?sp=page.plain" /> |
-<com:THyperLink Text="Visit member only page" NavigateUrl="?sp=page.private.member" />
-<com:TLinkButton Text="Click Me" Click="linkClicked" OnClientClick="javascript:alert('you hit me')"/>
+
+<com:TTextBox
+ ID="TextBox"
+ Text="textbox"
+ AutoPostBack="true"
+ CausesValidation="false" />
+
+<com:TLabel
+ Text="test"
+ AssociatedControlID="checkbox" /><br/>
+
+<com:System.Web.UI.WebControls.TButton
+ text="Toggle Button"
+ ForeColor="red"
+ Font.size="18"
+ Click="testClick" /> (requires membership)<br/>
+
+<com:TCheckBox
+ Text="Checkbox"
+ ID="checkbox"
+ AutoPostBack="true" /><br/>
+
+<com:TRadioButton
+ Text="Radiobutton"
+ ID="radiobutton"
+ AutoPostBack="true" /><br/>
+
+<com:TImage
+ ImageUrl=<%~/fungii_logo.gif %> />
+
+<com:TImageButton
+ ImageUrl=<%~/fungii_logo.gif %>
+ Click="clickImage"/><br/>
+
+<com:THyperLink
+ Text="Visit a 'classless' page"
+ NavigateUrl="?sp=page.plain" /> |
+
+<com:THyperLink
+ Text="Visit member only page"
+ NavigateUrl="?sp=page.private.member" />
+
+<com:TLinkButton
+ Text="Click Me"
+ Click="linkClicked"
+ onclick="javascript:alert('you hit me')"/>
+
</div>
</com:TForm>
</com:TContent> \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/prado.js b/framework/Web/Javascripts/base/prado.js
index 2174908f..3eded927 100644
--- a/framework/Web/Javascripts/base/prado.js
+++ b/framework/Web/Javascripts/base/prado.js
@@ -25,26 +25,41 @@ Prado.Button.fireButton = function(event, target)
Prado.TextBox = Class.create();
-Prado.TextBox.handleReturnKey = function(event)
+/**
+ * Returns FALSE when the "Enter" key is pressed AND when onchange
+ * property is defined. The onchange function is called. However,
+ * it does not call event listener functions.
+ * @return boolean false if "Enter" and onchange property is defined, true otherwise.
+ */
+Prado.TextBox.handleReturnKey = function(ev)
{
- if (event.keyCode == 13)
+ var kc = ev.keyCode != null ? ev.keyCode : ev.charCode;
+ if(kc == Event.KEY_RETURN)
{
- var target;
- if(typeof(event.target)!="undefined")
- target=event.target;
- else if(typeof(event.srcElement)!="undefined")
- target=event.srcElement;
- if((typeof(target)!="undefined") && (target!=null))
+ var target = Event.element(ev);
+ if(target && isFunction(target.onchange))
{
- if(typeof(target.onchange)!="undefined")
- {
- target.onchange();
- event.cancelBubble=true;
- if(event.stopPropagation)
- event.stopPropagation();
- return false;
- }
+ target.onchange();
+ Event.stop(ev);
+ return false;
}
}
return true;
-} \ No newline at end of file
+}
+
+/**
+ * Creates a LinkButton and register the post back to the onclick event.
+ */
+/* to finish when doPostback changes
+Prado.LinkButton = Class.create();
+Prado.LinkButton.prototype =
+{
+ initialize : function(element, name)
+ {
+ Event.observe(element, 'click', function(e)
+ {
+ Prado.doPostback(element, name, '');
+ Event.stop(e);
+ });
+ }
+}*/ \ No newline at end of file
diff --git a/framework/Web/Javascripts/extended/event.js b/framework/Web/Javascripts/extended/event.js
index 17a5432c..30123efc 100644
--- a/framework/Web/Javascripts/extended/event.js
+++ b/framework/Web/Javascripts/extended/event.js
@@ -5,7 +5,8 @@ Object.extend(Event, {
Event.__observe(w,'load',fn);
},
observe: function(elements, name, observer, useCapture) {
- if(isElement(elements))
+
+ if(!isList(elements))
return this.__observe(elements, name, observer, useCapture);
for(var i=0; i<elements.length; i++)
this.__observe(elements[i], name, observer, useCapture);
@@ -18,7 +19,6 @@ Object.extend(Event, {
((navigator.appVersion.indexOf('AppleWebKit') > 0)
|| element.attachEvent))
name = 'keydown';
-
this._observeAndCache(element, name, observer, useCapture);
}
}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/js/base.js b/framework/Web/Javascripts/js/base.js
index 276c17bd..b999f722 100644
--- a/framework/Web/Javascripts/js/base.js
+++ b/framework/Web/Javascripts/js/base.js
@@ -859,29 +859,25 @@ return false;
return true;
};
Prado.TextBox=Class.create();
-Prado.TextBox.handleReturnKey=function(_4){
-if(_4.keyCode==13){
-var _5;
-if(typeof (_4.target)!="undefined"){
-_5=_4.target;
-}else{
-if(typeof (_4.srcElement)!="undefined"){
-_5=_4.srcElement;
-}
-}
-if((typeof (_5)!="undefined")&&(_5!=null)){
-if(typeof (_5.onchange)!="undefined"){
-_5.onchange();
-_4.cancelBubble=true;
-if(_4.stopPropagation){
-_4.stopPropagation();
-}
+Prado.TextBox.handleReturnKey=function(ev){
+var kc=ev.keyCode!=null?ev.keyCode:ev.charCode;
+if(kc==Event.KEY_RETURN){
+var _6=Event.element(ev);
+if(_6&&isFunction(_6.onchange)){
+_6.onchange();
+Event.stop(ev);
return false;
}
}
-}
return true;
};
+Prado.LinkButton=Class.create();
+Prado.LinkButton.prototype={initialize:function(_7,_8){
+Event.observe(_7,"click",function(e){
+Prado.doPostback(_7,_8,"");
+Event.stop(e);
+});
+}};
Prado.doPostBack=function(_1,_2,_3,_4,_5,_6,_7,_8){
if(typeof (_4)=="undefined"){
diff --git a/framework/Web/Javascripts/js/dom.js b/framework/Web/Javascripts/js/dom.js
index a0f4a3f3..f22d5c80 100644
--- a/framework/Web/Javascripts/js/dom.js
+++ b/framework/Web/Javascripts/js/dom.js
@@ -530,7 +530,7 @@ Object.extend(Event,{OnLoad:function(fn){
var w=document.addEventListener&&!window.addEventListener?document:window;
Event.__observe(w,"load",fn);
},observe:function(_3,_4,_5,_6){
-if(isElement(_3)){
+if(!isList(_3)){
return this.__observe(_3,_4,_5,_6);
}
for(var i=0;i<_3.length;i++){
diff --git a/framework/Web/Javascripts/js/logger.js b/framework/Web/Javascripts/js/logger.js
new file mode 100644
index 00000000..0c617bd7
--- /dev/null
+++ b/framework/Web/Javascripts/js/logger.js
@@ -0,0 +1,461 @@
+CustomEvent=Class.create();
+CustomEvent.prototype={initialize:function(){
+this.listeners=[];
+},addListener:function(_1){
+this.listeners.push(_1);
+},removeListener:function(_2){
+var _3=this._findListenerIndexes(_2);
+for(var i=0;i<_3.length;i++){
+this.listeners.splice(_3[i],1);
+}
+},dispatch:function(_5){
+for(var i=0;i<this.listeners.length;i++){
+try{
+this.listeners[i](_5);
+}
+catch(e){
+alert("Could not run the listener "+this.listeners[i]+". "+e);
+}
+}
+},_findListenerIndexes:function(_6){
+var _7=[];
+for(var i=0;i<this.listeners.length;i++){
+if(this.listeners[i]==_6){
+_7.push(i);
+}
+}
+return _7;
+}};
+var Cookie={set:function(_8,_9,_10,_11){
+var _12=escape(_8)+"="+escape(_9);
+if(_10){
+var _13=new Date();
+_13.setDate(_13.getDate()+_10);
+_12+="; expires="+_13.toGMTString();
+}
+if(_11){
+_12+=";path="+_11;
+}
+document.cookie=_12;
+if(_9&&(_10==undefined||_10>0)&&!this.get(_8)){
+Logger.error("Cookie ("+_8+") was not set correctly... The value was "+_9.toString().length+" charachters long (This may be over the cookie limit)");
+}
+},get:function(_14){
+var _15="(^|;)\\s*"+escape(_14)+"=([^;]+)";
+var m=document.cookie.match(_15);
+if(m&&m[2]){
+return unescape(m[2]);
+}else{
+return null;
+}
+},getAll:function(){
+var _17=document.cookie.split(";");
+var _18=[];
+for(var i=0;i<_17.length;i++){
+try{
+var _19=unescape(_17[i].match(/^\s*([^=]+)/m)[1]);
+var _20=unescape(_17[i].match(/=(.*$)/m)[1]);
+}
+catch(e){
+continue;
+}
+_18.push({name:_19,value:_20});
+if(_18[_19]!=undefined){
+Logger.waring("Trying to retrieve cookie named("+_19+"). There appears to be another property with this name though.");
+}
+_18[_19]=_20;
+}
+return _18;
+},clear:function(_21){
+this.set(_21,"",-1);
+},clearAll:function(){
+var _22=this.getAll();
+for(var i=0;i<_22.length;i++){
+this.clear(_22[i].name);
+}
+}};
+Logger={logEntries:[],onupdate:new CustomEvent(),onclear:new CustomEvent(),log:function(_23,tag){
+var _25=new LogEntry(_23,tag||"info");
+this.logEntries.push(_25);
+this.onupdate.dispatch(_25);
+},info:function(_26){
+this.log(_26,"info");
+},debug:function(_27){
+this.log(_27,"debug");
+},warn:function(_28){
+this.log(_28,"warning");
+},error:function(_29,_30){
+this.log(_29+": \n"+_30,"error");
+},clear:function(){
+this.logEntries=[];
+this.onclear.dispatch();
+}};
+LogEntry=Class.create();
+LogEntry.prototype={initialize:function(_31,tag){
+this.message=_31;
+this.tag=tag;
+}};
+LogConsole=Class.create();
+LogConsole.prototype={commandHistory:[],commandIndex:0,initialize:function(){
+this.outputCount=0;
+this.tagPattern=Cookie.get("tagPattern")||".*";
+this.logElement=document.createElement("div");
+document.body.appendChild(this.logElement);
+Element.hide(this.logElement);
+this.logElement.style.position="absolute";
+this.logElement.style.left="0px";
+this.logElement.style.width="100%";
+this.logElement.style.textAlign="left";
+this.logElement.style.fontFamily="lucida console";
+this.logElement.style.fontSize="100%";
+this.logElement.style.backgroundColor="darkgray";
+this.logElement.style.opacity=0.9;
+this.logElement.style.zIndex=2000;
+this.toolbarElement=document.createElement("div");
+this.logElement.appendChild(this.toolbarElement);
+this.toolbarElement.style.padding="0 0 0 2px";
+this.buttonsContainerElement=document.createElement("span");
+this.toolbarElement.appendChild(this.buttonsContainerElement);
+this.buttonsContainerElement.innerHTML+="<button onclick=\"logConsole.toggle()\" style=\"float:right;color:black\">close</button>";
+this.buttonsContainerElement.innerHTML+="<button onclick=\"Logger.clear()\" style=\"float:right;color:black\">clear</button>";
+if(!Prado.Inspector.disabled){
+this.buttonsContainerElement.innerHTML+="<button onclick=\"Prado.Inspector.inspect()\" style=\"float:right;color:black; margin-right:15px;\">Object Tree</button>";
+}
+this.tagFilterContainerElement=document.createElement("span");
+this.toolbarElement.appendChild(this.tagFilterContainerElement);
+this.tagFilterContainerElement.style.cssFloat="left";
+this.tagFilterContainerElement.appendChild(document.createTextNode("Log Filter"));
+this.tagFilterElement=document.createElement("input");
+this.tagFilterContainerElement.appendChild(this.tagFilterElement);
+this.tagFilterElement.style.width="200px";
+this.tagFilterElement.value=this.tagPattern;
+this.tagFilterElement.setAttribute("autocomplete","off");
+Event.observe(this.tagFilterElement,"keyup",this.updateTags.bind(this));
+Event.observe(this.tagFilterElement,"click",function(){
+this.tagFilterElement.select();
+}.bind(this));
+this.outputElement=document.createElement("div");
+this.logElement.appendChild(this.outputElement);
+this.outputElement.style.overflow="auto";
+this.outputElement.style.clear="both";
+this.outputElement.style.height="200px";
+this.outputElement.style.backgroundColor="black";
+this.inputContainerElement=document.createElement("div");
+this.inputContainerElement.style.width="100%";
+this.logElement.appendChild(this.inputContainerElement);
+this.inputElement=document.createElement("input");
+this.inputContainerElement.appendChild(this.inputElement);
+this.inputElement.style.width="100%";
+this.inputElement.style.borderWidth="0px";
+this.inputElement.style.margin="0px";
+this.inputElement.style.padding="0px";
+this.inputElement.value="Type command here";
+this.inputElement.setAttribute("autocomplete","off");
+Event.observe(this.inputElement,"keyup",this.handleInput.bind(this));
+Event.observe(this.inputElement,"click",function(){
+this.inputElement.select();
+}.bind(this));
+window.setInterval(this.repositionWindow.bind(this),500);
+this.repositionWindow();
+Logger.onupdate.addListener(this.logUpdate.bind(this));
+Logger.onclear.addListener(this.clear.bind(this));
+for(var i=0;i<Logger.logEntries.length;i++){
+this.logUpdate(Logger.logEntries[i]);
+}
+Event.observe(window,"error",function(msg,url,_34){
+Logger.error("Error in ("+(url||location)+") on line "+_34+"",msg);
+});
+var _35=document.createElement("span");
+_35.innerHTML="<button style=\"position:absolute;top:-100px\" onclick=\"javascript:logConsole.toggle()\" accesskey=\"d\"></button>";
+document.body.appendChild(_35);
+if(Cookie.get("ConsoleVisible")=="true"){
+this.toggle();
+}
+},toggle:function(){
+if(this.logElement.style.display=="none"){
+this.show();
+}else{
+this.hide();
+}
+},show:function(){
+Element.show(this.logElement);
+this.outputElement.scrollTop=this.outputElement.scrollHeight;
+Cookie.set("ConsoleVisible","true");
+this.inputElement.select();
+},hide:function(){
+Element.hide(this.logElement);
+Cookie.set("ConsoleVisible","false");
+},output:function(_36,_37){
+var _38=(this.outputElement.scrollTop+(2*this.outputElement.clientHeight))>=this.outputElement.scrollHeight;
+this.outputCount++;
+_37=(_37?_37+=";":"");
+_37+="padding:1px;margin:0 0 5px 0";
+if(this.outputCount%2==0){
+_37+=";background-color:#101010";
+}
+_36=_36||"undefined";
+_36=_36.toString().escapeHTML();
+this.outputElement.innerHTML+="<pre style='"+_37+"'>"+_36+"</pre>";
+if(_38){
+this.outputElement.scrollTop=this.outputElement.scrollHeight;
+}
+},updateTags:function(){
+var _39=this.tagFilterElement.value;
+if(this.tagPattern==_39){
+return;
+}
+try{
+new RegExp(_39);
+}
+catch(e){
+return;
+}
+this.tagPattern=_39;
+Cookie.set("tagPattern",this.tagPattern);
+this.outputElement.innerHTML="";
+this.outputCount=0;
+for(var i=0;i<Logger.logEntries.length;i++){
+this.logUpdate(Logger.logEntries[i]);
+}
+},repositionWindow:function(){
+var _40=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop;
+var _41=self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
+this.logElement.style.top=(_40+_41-Element.getHeight(this.logElement))+"px";
+},logUpdate:function(_42){
+if(_42.tag.search(new RegExp(this.tagPattern,"igm"))==-1){
+return;
+}
+var _43="";
+if(_42.tag.search(/error/)!=-1){
+_43+="color:red";
+}else{
+if(_42.tag.search(/warning/)!=-1){
+_43+="color:orange";
+}else{
+if(_42.tag.search(/debug/)!=-1){
+_43+="color:green";
+}else{
+if(_42.tag.search(/info/)!=-1){
+_43+="color:white";
+}else{
+_43+="color:yellow";
+}
+}
+}
+}
+this.output(_42.message,_43);
+},clear:function(e){
+this.outputElement.innerHTML="";
+},handleInput:function(e){
+if(e.keyCode==Event.KEY_RETURN){
+var _45=this.inputElement.value;
+switch(_45){
+case "clear":
+Logger.clear();
+break;
+default:
+var _46="";
+try{
+_46=eval(this.inputElement.value);
+}
+catch(e){
+Logger.error("Problem parsing input <"+_45+">",e);
+break;
+}
+Logger.log(_46);
+break;
+}
+if(this.inputElement.value!=""&&this.inputElement.value!=this.commandHistory[0]){
+this.commandHistory.unshift(this.inputElement.value);
+}
+this.commandIndex=0;
+this.inputElement.value="";
+}else{
+if(e.keyCode==Event.KEY_UP&&this.commandHistory.length>0){
+this.inputElement.value=this.commandHistory[this.commandIndex];
+if(this.commandIndex<this.commandHistory.length-1){
+this.commandIndex+=1;
+}
+}else{
+if(e.keyCode==Event.KEY_DOWN&&this.commandHistory.length>0){
+if(this.commandIndex>0){
+this.commandIndex-=1;
+}
+this.inputElement.value=this.commandHistory[this.commandIndex];
+}else{
+this.commandIndex=0;
+}
+}
+}
+}};
+Event.observe(window,"load",function(){
+logConsole=new LogConsole();
+});
+function inspect(_47,_48,_49){
+var _50=[];
+var _51=[];
+for(var _52 in _47){
+if(_52=="______array"){
+continue;
+}
+try{
+if(_47[_52] instanceof Function){
+if(_49){
+_51.push(_52+":\t"+_47[_52]);
+}
+}else{
+if(_47[_52] instanceof Object){
+_51.push(_52+":\t"+inspect(_47[_52],_48,_49));
+}else{
+if(!_48){
+_50.push(_52+":\t"+_47[_52]);
+}
+}
+}
+}
+catch(e){
+Logger.error("Excetion thrown while inspecting object.",e);
+}
+}
+_50.sort();
+_51.sort();
+var _53=_50.concat(_51);
+var _54="";
+for(var i=0;i<_53.length;i++){
+_54+=(_53[i]+"\n");
+}
+return _54;
+}
+Array.prototype.contains=function(_55){
+for(var i=0;i<this.length;i++){
+if(_55==this[i]){
+return true;
+}
+}
+return false;
+};
+var puts=function(){
+return Logger.log(arguments[0],arguments[1]);
+};
+if(typeof Prado=="undefined"){
+var Prado={};
+}
+Prado.Inspector={d:document,types:new Array(),objs:new Array(),hidden:new Array(),opera:window.opera,displaying:"",format:function(str){
+str=str.replace(/</g,"&lt;");
+str=str.replace(/>/g,"&gt;");
+return str;
+},parseJS:function(obj){
+var _58;
+if(typeof obj=="string"){
+_58=obj;
+obj=eval(obj);
+}
+win=typeof obj=="undefined"?window:obj;
+this.displaying=_58?_58:win.toString();
+for(js in win){
+try{
+if(win[js]&&js.toString().indexOf("Inspector")==-1&&win[js].toString().indexOf("[native code]")==-1){
+t=typeof (win[js]);
+if(!this.objs[t.toString()]){
+this.types[this.types.length]=t;
+this.objs[t]=new Array();
+}
+index=this.objs[t].length;
+this.objs[t][index]=new Array();
+this.objs[t][index][0]=js;
+this.objs[t][index][1]=this.format(win[js].toString());
+}
+}
+catch(err){
+}
+}
+},show:function(_59){
+this.d.getElementById(_59).style.display=this.hidden[_59]?"none":"block";
+this.hidden[_59]=this.hidden[_59]?0:1;
+},changeSpan:function(_60){
+if(this.d.getElementById(_60).innerHTML.indexOf("+")>-1){
+this.d.getElementById(_60).innerHTML="[-]";
+}else{
+this.d.getElementById(_60).innerHTML="[+]";
+}
+},buildInspectionLevel:function(){
+var _61=this.displaying;
+var _62=_61.split(".");
+var _63=["<a href=\"javascript:var_dump()\">[object Window]</a>"];
+var _64="";
+if(_61.indexOf("[object ")>=0){
+return _63.join(".");
+}
+for(var i=0;i<_62.length;i++){
+_64+=(_64.length?".":"")+_62[i];
+_63[i+1]="<a href=\"javascript:var_dump('"+_64+"')\">"+_62[i]+"</a>";
+}
+return _63.join(".");
+},buildTree:function(){
+mHTML="<div>Inspecting "+this.buildInspectionLevel()+"</div>";
+mHTML+="<ul class=\"topLevel\">";
+this.types.sort();
+var _65=0;
+for(i=0;i<this.types.length;i++){
+mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('ul"+i+"');Prado.Inspector.changeSpan('sp"+i+"')\"><span id=\"sp"+i+"\">[+]</span><b>"+this.types[i]+"</b> ("+this.objs[this.types[i]].length+")</li><ul style=\"display:none;\" id=\"ul"+i+"\">";
+this.hidden["ul"+i]=0;
+for(e=0;e<this.objs[this.types[i]].length;e++){
+var _66="";
+if(this.objs[this.types[i]][e][1].indexOf("[object ")>=0&&/^[a-zA-Z_]/.test(this.objs[this.types[i]][e][0][0])){
+if(this.displaying.indexOf("[object ")<0){
+_66=" <a href=\"javascript:var_dump('"+this.displaying+"."+this.objs[this.types[i]][e][0]+"')\"><b>more</b></a>";
+}else{
+if(this.displaying.indexOf("[object Window]")>=0){
+_66=" <a href=\"javascript:var_dump('"+this.objs[this.types[i]][e][0]+"')\"><b>more</b></a>";
+}
+}
+}
+mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('mul"+_65+"');Prado.Inspector.changeSpan('sk"+_65+"')\"><span id=\"sk"+_65+"\">[+]</span>"+this.objs[this.types[i]][e][0]+"</li><ul id=\"mul"+_65+"\" style=\"display:none;\"><li style=\"list-style-type:none;\"><pre>"+this.objs[this.types[i]][e][1]+_66+"</pre></li></ul>";
+this.hidden["mul"+_65]=0;
+_65++;
+}
+mHTML+="</ul>";
+}
+mHTML+="</ul>";
+this.d.getElementById("so_mContainer").innerHTML=mHTML;
+},handleKeyEvent:function(e){
+keyCode=document.all?window.event.keyCode:e.keyCode;
+if(keyCode==27){
+this.cleanUp();
+}
+},cleanUp:function(){
+if(this.d.getElementById("so_mContainer")){
+this.d.body.removeChild(this.d.getElementById("so_mContainer"));
+this.d.body.removeChild(this.d.getElementById("so_mStyle"));
+if(typeof Event!="undefined"){
+Event.stopObserving(this.d,"keydown",this.handleKeyEvent.bind(this));
+}
+this.types=new Array();
+this.objs=new Array();
+this.hidden=new Array();
+}
+},disabled:document.all&&!this.opera,inspect:function(obj){
+if(this.disabled){
+return alert("Sorry, this only works in Mozilla and Firefox currently.");
+}
+this.cleanUp();
+mObj=this.d.body.appendChild(this.d.createElement("div"));
+mObj.id="so_mContainer";
+sObj=this.d.body.appendChild(this.d.createElement("style"));
+sObj.id="so_mStyle";
+sObj.type="text/css";
+sObj.innerHTML=this.style;
+if(typeof Event!="undefined"){
+Event.observe(this.d,"keydown",this.handleKeyEvent.bind(this));
+}
+this.parseJS(obj);
+this.buildTree();
+cObj=mObj.appendChild(this.d.createElement("div"));
+cObj.className="credits";
+cObj.innerHTML="<b>[esc] to <a href=\"javascript:Prado.Inspector.cleanUp();\">close</a></b><br />Javascript Object Tree V2.0, <a target=\"_blank\" href=\"http://slayeroffice.com/?c=/content/tools/js_tree.html\">more info</a>.";
+window.scrollTo(0,0);
+},style:"#so_mContainer { position:absolute; top:5px; left:5px; background-color:#E3EBED; text-align:left; font:9pt verdana; width:85%; border:2px solid #000; padding:5px; z-index:1000; color:#000; } "+"#so_mContainer ul { padding-left:20px; } "+"#so_mContainer ul li { display:block; list-style-type:none; list-style-image:url(); line-height:2em; -moz-border-radius:.75em; font:10px verdana; padding:0; margin:2px; color:#000; } "+"#so_mContainer li:hover { background-color:#E3EBED; } "+"#so_mContainer ul li span { position:relative; width:15px; height:15px; margin-right:4px; } "+"#so_mContainer pre { background-color:#F9FAFB; border:1px solid #638DA1; height:auto; padding:5px; font:9px verdana; color:#000; } "+"#so_mContainer .topLevel { margin:0; padding:0; } "+"#so_mContainer .credits { float:left; width:200px; font:6.5pt verdana; color:#000; padding:2px; margin-left:5px; text-align:left; border-top:1px solid #000; margin-top:15px; width:75%; } "+"#so_mContainer .credits a { font:9px verdana; font-weight:bold; color:#004465; text-decoration:none; background-color:transparent; }"};
+function var_dump(obj){
+Prado.Inspector.inspect(obj);
+}
+
diff --git a/framework/Web/UI/TAssetManager.php b/framework/Web/UI/TAssetManager.php
index df189b58..dfc1fa53 100644
--- a/framework/Web/UI/TAssetManager.php
+++ b/framework/Web/UI/TAssetManager.php
@@ -150,7 +150,7 @@ class TAssetManager extends TModule
return '';
else if(is_file($fullpath))
{
- $dir=md5(dirname($fullpath));
+ $dir=$this->hash(dirname($fullpath));
$file=$this->_basePath.'/'.$dir.'/'.basename($fullpath);
if(!is_file($file) || $checkTimestamp || $this->_application->getMode()!=='Performance')
{
@@ -164,7 +164,7 @@ class TAssetManager extends TModule
}
else
{
- $dir=md5($fullpath);
+ $dir=$this->hash($fullpath);
if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->_application->getMode()!=='Performance')
$this->copyDirectory($fullpath,$this->_basePath.'/'.$dir);
$this->_published[$path]=$this->_baseUrl.'/'.$dir;
@@ -173,6 +173,27 @@ class TAssetManager extends TModule
}
/**
+ * Generate a CRC32 hash for the directory path. Collisions are higher
+ * than MD5 but generates a much smaller hash string.
+ * @param string string to be hashed.
+ * @return string hashed string.
+ */
+ private function hash($dir)
+ {
+ $num = sprintf('%u', crc32($dir));
+ $base = 62;
+ $index = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $out = '';
+ for ( $t = floor( log10( $num ) / log10( $base ) ); $t >= 0; $t-- )
+ {
+ $a = floor( $num / pow( $base, $t ) );
+ $out = $out . substr( $index, $a, 1 );
+ $num = $num - ( $a * pow( $base, $t ) );
+ }
+ return $out;
+ }
+
+ /**
* Copies a directory recursively as another.
* If the destination directory does not exist, it will be created.
* File modification time is used to ensure the copied files are latest.
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index ca28751f..6106cfbf 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -165,13 +165,17 @@ class TClientScriptManager extends TComponent
public function registerPradoScript($script)
{
- foreach(TPradoClientScript::getScript($script) as $scriptFile)
+ foreach(TPradoClientScript::getScripts($script) as $scriptFile)
{
if(isset($this->_publishedScriptFiles[$scriptFile]))
$url=$this->_publishedScriptFiles[$scriptFile];
else
{
- $url=$this->_page->getService()->getAssetManager()->publishFilePath(Prado::getFrameworkPath().'/'.self::SCRIPT_DIR.'/'.$scriptFile);
+ $base = Prado::getFrameworkPath();
+ $clientScripts = self::SCRIPT_DIR;
+ $file = "{$base}/{$clientScripts}/{$scriptFile}.js";
+ $assetManager = $this->_page->getService()->getAssetManager();
+ $url= $assetManager->publishFilePath($file);
$this->_publishedScriptFiles[$scriptFile]=$url;
$this->registerScriptFile('prado:'.$scriptFile,$url);
}
@@ -444,6 +448,16 @@ class TClientScriptManager extends TComponent
return count($this->_onSubmitStatements)>0;
}
+ public function registerClientEvent($control, $event, $code)
+ {
+ if(empty($code)) return;
+ $this->registerPradoScript("dom");
+ $script= "Event.observe('{$control->ClientID}', '{$event}', function(e){ {$code} });";
+ $key = "prado:{$control->ClientID}:{$event}";
+ $this->registerEndScript($key, $script);
+ }
+
+
/*
private void EnsureEventValidationFieldLoaded();
@@ -619,7 +633,7 @@ class TPradoClientScript
* @param array list of libraries to load.
* @return array list of libraries including its dependencies.
*/
- protected static function getScripts($scripts)
+ public static function getScripts($scripts)
{
$files = array();
if(!is_array($scripts)) $scripts = array($scripts);
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index ab314087..0d88fc43 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -111,7 +111,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
* Returns an array of javascript validator options.
* @return array javascript validator options.
*/
- protected function getClientScriptAttributes()
+ protected function getClientScriptOptions()
{
$options['ID'] = $this->getClientID();
$options['Display'] = $this->getDisplay();
@@ -153,8 +153,8 @@ abstract class TBaseValidator extends TLabel implements IValidator
$class = get_class($this);
$scriptKey = "prado:".$this->getClientID();
$scripts = $this->getPage()->getClientScript();
- $option = TJavascript::toList($this->getClientScriptAttributes());
- $js = "new Prado.Validation(Prado.Validation.{$class}, {$option});";
+ $options = TJavascript::toList($this->getClientScriptOptions());
+ $js = "new Prado.Validation(Prado.Validation.{$class}, {$options});";
$scripts->registerEndScript($scriptKey, $js);
}
}
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index e7c40a75..c18bcc62 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -44,10 +44,6 @@
* You can change the postback target by setting the {@link setPostBackUrl PostBackUrl}
* property.
*
- * To set the client-side javascript associated with the user's click action,
- * use the {@link setOnClientClick OnClientClick} property. The value will be rendered
- * as the <b>onclick</b> attribute of the button.
- *
* TButton displays the {@link setText Text} property as the button caption.
*
* @author Qiang Xue <qiang.xue@gmail.com>
@@ -78,18 +74,27 @@ class TButton extends TWebControl implements IPostBackEventHandler
if(($uniqueID=$this->getUniqueID())!=='')
$writer->addAttribute('name',$uniqueID);
$writer->addAttribute('value',$this->getText());
+ if(!$this->getEnabled()) // in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ parent::addAttributesToRender($writer);
+ }
+ /**
+ * Registers the postback javascript code.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ protected function onPreRender($param)
+ {
if($this->getEnabled(true))
{
- $onclick=$this->removeAttribute('onclick');
- $onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
- $onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),false);
- if(!empty($onclick))
- $writer->addAttribute('onclick','javascript:'.$onclick);
+ $scripts = $this->getPage()->getClientScript();
+ $options = $this->getPostBackOptions();
+ $postback = $scripts->getPostBackEventReference($this, '', $options, false);
+ $scripts->registerClientEvent($this, "click", $postback);
}
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
- parent::addAttributesToRender($writer);
+ parent::onPreRender($param);
}
/**
@@ -99,16 +104,19 @@ class TButton extends TWebControl implements IPostBackEventHandler
*/
protected function getPostBackOptions()
{
- $options=new TPostBackOptions();
- if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0)
+ $option=new TPostBackOptions();
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ if($this->getCausesValidation() && $hasValidators)
{
- $options->setPerformValidation(true);
- $options->setValidationGroup($this->getValidationGroup());
+ $option->setPerformValidation(true);
+ $option->setValidationGroup($group);
}
if($this->getPostBackUrl()!=='')
- $options->setActionUrl($this->getPostBackUrl());
- $options->setClientSubmit(!$this->getUseSubmitBehavior());
- return $options;
+ $option->setActionUrl($this->getPostBackUrl());
+ $option->setClientSubmit(!$this->getUseSubmitBehavior());
+
+ return $option;
}
/**
@@ -275,22 +283,6 @@ class TButton extends TWebControl implements IPostBackEventHandler
{
$this->setViewState('PostBackUrl',$value,'');
}
-
- /**
- * @return string the javascript to be executed when the button is clicked.
- */
- public function getOnClientClick()
- {
- return $this->getViewState('OnClientClick','');
- }
-
- /**
- * @param string the javascript to be executed when the button is clicked.
- */
- public function setOnClientClick($value)
- {
- $this->setViewState('OnClientClick',$value,'');
- }
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php
index caaafa78..ba3a45f7 100644
--- a/framework/Web/UI/WebControls/TCheckBox.php
+++ b/framework/Web/UI/WebControls/TCheckBox.php
@@ -108,6 +108,9 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl
* Registers the checkbox to receive postback data during postback.
* This is necessary because a checkbox if unchecked, when postback,
* does not have direct mapping between post data and the checkbox name.
+ *
+ * Auto-postback javascript code is also registered here.
+ *
* This method overrides the parent implementation and is invoked before render.
* @param mixed event parameter
*/
@@ -116,6 +119,15 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl
parent::onPreRender($param);
if($this->getEnabled(true))
$this->getPage()->registerRequiresPostData($this);
+
+ if($this->getAutoPostBack()
+ && $this->getPage()->getClientSupportsJavaScript())
+ {
+ $options = $this->getAutoPostBackOptions();
+ $scripts = $this->getPage()->getClientScript();
+ $postback = $scripts->getPostBackEventReference($this,'',$options,false);
+ $scripts->registerClientEvent($this, "click", $postback);
+ }
}
/**
@@ -353,21 +365,6 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl
if(!$this->getEnabled(true))
$writer->addAttribute('disabled','disabled');
$page=$this->getPage();
- if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- {
- $option=new TPostBackOptions();
- if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount())
- {
- $option->setPerformValidation(true);
- $option->setValidationGroup($this->getValidationGroup());
- }
- $option->setAutoPostBack(true);
- if(!empty($onclick))
- $onclick=THttpUtility::trimJavaScriptString($onclick);
- $onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$option,false);
- }
- if(!empty($onclick))
- $writer->addAttribute('onclick',$onclick);
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
if(($tabindex=$this->getTabIndex())>0)
@@ -377,6 +374,24 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl
$writer->renderBeginTag('input');
$writer->renderEndTag();
}
+
+ /**
+ * Sets the post back options for this textbox.
+ * @return TPostBackOptions
+ */
+ protected function getAutoPostBackOptions()
+ {
+ $option=new TPostBackOptions();
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ if($this->getCausesValidation() && $hasValidators)
+ {
+ $option->setPerformValidation(true);
+ $option->setValidationGroup($group);
+ }
+ $option->setAutoPostBack(true);
+ }
+
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php
index 96fbff67..131f7b1c 100644
--- a/framework/Web/UI/WebControls/TImageButton.php
+++ b/framework/Web/UI/WebControls/TImageButton.php
@@ -51,10 +51,6 @@ Prado::using('System.Web.UI.WebControls.TImage');
* You can change the postback target by setting the {@link setPostBackUrl PostBackUrl}
* property.
*
- * To set the client-side javascript associated with the user's click action,
- * use the {@link setOnClientClick OnClientClick} property. The value will be rendered
- * as the <b>onclick</b> attribute of the button.
- *
* TImageButton displays the {@link setText Text} property as the hint text to the displayed image.
*
* @author Qiang Xue <qiang.xue@gmail.com>
@@ -93,19 +89,8 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven
$writer->addAttribute('type','image');
if(($uniqueID=$this->getUniqueID())!=='')
$writer->addAttribute('name',$uniqueID);
-
- if($this->getEnabled(true))
- {
- $onclick=$this->removeAttribute('onclick');
- $onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
- $onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),false);
- if(!empty($onclick))
- $writer->addAttribute('onclick','javascript:'.$onclick);
- }
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
+ if(!$this->getEnabled()) // in this case, parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
- if($onclick!=='')
- $writer->addAttribute('onclick','javascript:'.$onclick);
parent::addAttributesToRender($writer);
}
@@ -280,22 +265,6 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven
}
/**
- * @return string the javascript to be executed when the button is clicked.
- */
- public function getOnClientClick()
- {
- return $this->getViewState('OnClientClick','');
- }
-
- /**
- * @param string the javascript to be executed when the button is clicked.
- */
- public function setOnClientClick($value)
- {
- $this->setViewState('OnClientClick',$value,'');
- }
-
- /**
* @return string caption of the button
*/
public function getText()
diff --git a/framework/Web/UI/WebControls/TJavascriptLogger.php b/framework/Web/UI/WebControls/TJavascriptLogger.php
new file mode 100644
index 00000000..d5761a90
--- /dev/null
+++ b/framework/Web/UI/WebControls/TJavascriptLogger.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * TJavascriptLogger component class file.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD License.
+ *
+ * Copyright(c) 2004 by Wei Zhuo. All rights reserved.
+ *
+ * To contact the author write to {@link mailto:weizhuo[at]gmail[dot]com Wei Zhuo}
+ * The latest version of PRADO can be obtained from:
+ * {@link http://prado.sourceforge.net/}
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.2 $ $Date: 2005/11/06 23:02:33 $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TJavascriptLogger class.
+ *
+ * Provides logging for client-side javascript. Example: template code
+ * <code><com:TJavascriptLogger /></code>
+ *
+ * Client-side javascript code to log info, error, warn, debug
+ * <code>Logger.warn('A warning');
+ * Logger.info('something happend');
+ * </code>
+ *
+ * To see the logger and console, press ALT-D (or CTRL-D on OS X).
+ * More information on the logger can be found at
+ * http://gleepglop.com/javascripts/logger/
+ *
+ * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
+ * @version $Revision: 1.2 $ $Date: 2005/11/06 23:02:33 $
+ * @package System.Web.UI.WebControls
+ * @since 2.0.2
+ */
+class TJavascriptLogger extends TWebControl
+{
+
+ /**
+ * @return string tag name of the panel
+ */
+ protected function getTagName()
+ {
+ return 'div';
+ }
+
+ /**
+ * Register the required javascript libraries and
+ * display some general usage information.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ protected function renderContents($writer)
+ {
+ $this->Page->ClientScript->registerPradoScript('logger');
+ $info = '(<a href="http://gleepglop.com/javascripts/logger/" target="_blank">more info</a>).';
+ $usage = 'Press ALT-D (Or CTRL-D on OS X) to toggle the javascript log console';
+ $writer->write("{$usage} {$info}");
+ parent::renderContents($writer);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index dd2d8cb7..3ddb6f68 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -46,10 +46,6 @@
* You can change the postback target by setting the {@link setPostBackUrl PostBackUrl}
* property.
*
- * To set the client-side javascript associated with the user's click action,
- * use the {@link setOnClientClick OnClientClick} property. The value will be rendered
- * as the <b>onclick</b> attribute of the link button.
- *
* TLinkButton will display the {@link setText Text} property value
* as the hyperlink text. If {@link setText Text} is empty, the body content
* of TLinkButton will be displayed. Therefore, you can use TLinkButton
@@ -79,19 +75,41 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
{
$page=$this->getPage();
$page->ensureRenderInForm($this);
- $onclick=$this->removeAttribute('onclick');
- $onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
- if(!empty($onclick))
- $writer->addAttribute('onclick','javascript:'.$onclick);
+
+ $writer->addAttribute('id',$this->getClientID());
// We call parent implementation here because some attributes
// may be overwritten in the following
parent::addAttributesToRender($writer);
+
+ if($this->getEnabled())
+ {
+ $url = $this->getPostBackUrl();
+ //create unique no-op url references
+ $nop = "javascript:;//{$this->ClientID}";
+ $writer->addAttribute('href', $url ? $url : $nop);
+ }
+ else// in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ }
+ /**
+ * Registers the postback javascript code.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ protected function onPreRender($param)
+ {
if($this->getEnabled(true))
- $writer->addAttribute('href',$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),true));
- else if($this->getEnabled()) // in this case, parent will not render 'disabled'
- $writer->addAttribute('disabled','disabled');
+ {
+ $scripts = $this->getPage()->getClientScript();
+ $options = $this->getPostBackOptions();
+ $postback = $scripts->getPostBackEventReference($this, '', $options, false);
+ $code = "{$postback}; Event.stop(e);";
+ $scripts->registerClientEvent($this, "click", $code);
+ }
+ parent::onPreRender($param);
}
/**
@@ -102,8 +120,11 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
protected function getPostBackOptions()
{
$flag=false;
- $options=new TPostBackOptions();
- if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0)
+
+ $option=new TPostBackOptions();
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ if($this->getCausesValidation() && $hasValidators)
{
$flag=true;
$options->setPerformValidation(true);
@@ -183,22 +204,6 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
}
/**
- * @return string the javascript to be executed when the button is clicked
- */
- public function getOnClientClick()
- {
- return $this->getViewState('OnClientClick','');
- }
-
- /**
- * @param string the javascript to be executed when the button is clicked. Do not prefix it with "javascript:".
- */
- public function setOnClientClick($value)
- {
- $this->setViewState('OnClientClick',$value,'');
- }
-
- /**
* @return string the URL of the page to post to when the button is clicked, default is empty meaning post to the current page itself
*/
public function getPostBackUrl()
diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php
index 302d088c..153da8e6 100644
--- a/framework/Web/UI/WebControls/TRadioButton.php
+++ b/framework/Web/UI/WebControls/TRadioButton.php
@@ -153,21 +153,6 @@ class TRadioButton extends TCheckBox
if(!$this->getEnabled(true))
$writer->addAttribute('disabled','disabled');
$page=$this->getPage();
- if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
- {
- $option=new TPostBackOptions();
- if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount())
- {
- $option->setPerformValidation(true);
- $option->setValidationGroup($this->getValidationGroup());
- }
- $option->setAutoPostBack(true);
- if(!empty($onclick))
- $onclick=THttpUtility::trimJavaScriptString($onclick);
- $onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$option,false);
- }
- if(!empty($onclick))
- $writer->addAttribute('onclick',$onclick);
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
if(($tabindex=$this->getTabIndex())>0)
diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php
index 3e5f0107..1ad736db 100644
--- a/framework/Web/UI/WebControls/TTextBox.php
+++ b/framework/Web/UI/WebControls/TTextBox.php
@@ -117,29 +117,49 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
$writer->addAttribute('readonly','readonly');
if(!$this->getEnabled(true) && $this->getEnabled()) // in this case parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
- if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * Registers the auto-postback javascript code.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ protected function onPreRender($param)
+ {
+ if($this->getAutoPostBack()
+ && $this->getPage()->getClientSupportsJavaScript())
{
- $option=new TPostBackOptions();
- if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount()>0)
- {
- $option->setPerformValidation(true);
- $option->setValidationGroup($this->getValidationGroup());
- }
- $option->setAutoPostBack(true);
- $onchange=$this->removeAttribute('onchange');
- $onchange.=THttpUtility::trimJavaScriptString($onchange).$page->getClientScript()->getPostBackEventReference($this,'',$option,false);
- $writer->addAttribute('onchange','javascript:'.$onchange);
+ $options = $this->getAutoPostBackOptions();
+ $scripts = $this->getPage()->getClientScript();
+ $postback = $scripts->getPostBackEventReference($this,'',$options,false);
+ $scripts->registerClientEvent($this, "change", $postback);
- if($textMode!=='MultiLine')
+ if($this->getTextMode() !== 'MultiLine')
{
- // note, Prado.TextBox.handleReturnKey is defined in base.js,
- // which is included when AutoPostBack is true for textbox.
- $onkeypress='javascript:if(Prado.TextBox.handleReturnKey(event)==false) return false;';
- $onkeypress.=THttpUtility::trimJavaScriptString($this->removeAttribute('onkeypress'));
- $writer->addAttribute('onkeypress',$onkeypress);
+ $code = "if(Prado.TextBox.handleReturnKey(e)==false) Event.stop(e);";
+ $scripts->registerClientEvent($this, "keypress", $code);
}
}
- parent::addAttributesToRender($writer);
+ parent::onPreRender($param);
+ }
+
+ /**
+ * Sets the post back options for this textbox.
+ * @return TPostBackOptions
+ */
+ protected function getAutoPostBackOptions()
+ {
+ $option=new TPostBackOptions();
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ if($this->getCausesValidation() && $hasValidators)
+ {
+ $option->setPerformValidation(true);
+ $option->setValidationGroup($group);
+ }
+ $option->setAutoPostBack(true);
}
/**