diff options
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r-- | framework/Web/Javascripts/extended/base.js | 2 | ||||
-rw-r--r-- | framework/Web/Javascripts/extended/event.js | 33 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/prado.js | 59 | ||||
-rw-r--r-- | framework/Web/Javascripts/prado/controls.js | 66 |
4 files changed, 97 insertions, 63 deletions
diff --git a/framework/Web/Javascripts/extended/base.js b/framework/Web/Javascripts/extended/base.js index e3ca729b..48927b75 100644 --- a/framework/Web/Javascripts/extended/base.js +++ b/framework/Web/Javascripts/extended/base.js @@ -29,6 +29,6 @@ function $(n,d) { Function.prototype.bindEvent = function() {
var __method = this, args = $A(arguments), object = args.shift();
return function(event) {
- return __method.call(object, event || window.event, args);
+ return __method.apply(object, [event || window.event].concat(args));
}
}
diff --git a/framework/Web/Javascripts/extended/event.js b/framework/Web/Javascripts/extended/event.js index a7514cda..b6dccf3b 100644 --- a/framework/Web/Javascripts/extended/event.js +++ b/framework/Web/Javascripts/extended/event.js @@ -26,12 +26,39 @@ Object.extend(Event, { return e.keyCode != null ? e.keyCode : e.charCode
},
+ isHTMLEvent : function(type)
+ {
+ var events = ['abort', 'blur', 'change', 'error', 'focus', 'load', 'reset', 'resize', 'scroll', 'select', 'submit', 'unload'];
+ return events.include(type);
+ },
+
+ isMouseEvent : function(type)
+ {
+ var events = ['click', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup'];
+ return events.include(type);
+ },
+
fireEvent : function(element,type)
{
if(document.createEvent)
- {
- var event = document.createEvent('HTMLEvents');
- event.initEvent(type, true, true);
+ {
+ if(Event.isHTMLEvent(type))
+ {
+ var event = document.createEvent('HTMLEvents');
+ event.initEvent(type, true, true);
+ }
+ else if(Event.isMouseEvent(type))
+ {
+ var event = document.createEvent('MouseEvents');
+ event.initMouseEvent(type,true,true,
+ document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
+ }
+ else
+ {
+ if(Logger)
+ Logger.error("undefined event", type);
+ return;
+ }
element.dispatchEvent(event);
}
else if(element.fireEvent)
diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index 590882fa..f411cbcf 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -193,7 +193,7 @@ return x; Function.prototype.bindEvent=function(){ var _6=this,args=$A(arguments),object=args.shift(); return function(_7){ -return _6.call(object,_7||window.event,args); +return _6.apply(object,[_7||window.event].concat(args)); }; }; @@ -1140,17 +1140,35 @@ _9="keydown"; this._observeAndCache(_8,_9,_10,_11); },keyCode:function(e){ return e.keyCode!=null?e.keyCode:e.charCode; -},fireEvent:function(_13,_14){ +},isHTMLEvent:function(_13){ +var _14=["abort","blur","change","error","focus","load","reset","resize","scroll","select","submit","unload"]; +return _14.include(_13); +},isMouseEvent:function(_15){ +var _16=["click","mousedown","mousemove","mouseout","mouseover","mouseup"]; +return _16.include(_15); +},fireEvent:function(_17,_18){ if(document.createEvent){ -var _15=document.createEvent("HTMLEvents"); -_15.initEvent(_14,true,true); -_13.dispatchEvent(_15); +if(Event.isHTMLEvent(_18)){ +var _19=document.createEvent("HTMLEvents"); +_19.initEvent(_18,true,true); }else{ -if(_13.fireEvent){ -_13.fireEvent("on"+_14); -_13[_14](); +if(Event.isMouseEvent(_18)){ +var _19=document.createEvent("MouseEvents"); +_19.initMouseEvent(_18,true,true,document.defaultView,1,0,0,0,0,false,false,false,false,0,null); }else{ -_13[_14](); +if(Logger){ +Logger.error("undefined event",_18); +} +return; +} +} +_17.dispatchEvent(_19); +}else{ +if(_17.fireEvent){ +_17.fireEvent("on"+_18); +_17[_18](); +}else{ +_17[_18](); } } }}); @@ -2372,7 +2390,7 @@ _41.set(_42); Prado.WebUI=Class.create(); Prado.WebUI.PostBackControl=Class.create(); Object.extend(Prado.WebUI.PostBackControl.prototype,{initialize:function(_1){ -this.element=$(_1["ID"]); +this.control=$(_1["ID"]); if(_1["CausesValidation"]&&Prado.Validation){ Prado.Validation.AddTarget(_1["ID"],_1["ValidationGroup"]); } @@ -2390,7 +2408,7 @@ return _3; }; Prado.WebUI.TButton=Prado.WebUI.createPostBackComponent(); Prado.WebUI.ClickableComponent=Prado.WebUI.createPostBackComponent({onInit:function(_4){ -Event.observe(this.element,"click",Prado.PostBack.bindEvent(this,_4)); +Event.observe(this.control,"click",Prado.PostBack.bindEvent(this,_4)); }}); Prado.WebUI.TLinkButton=Prado.WebUI.ClickableComponent; Prado.WebUI.TCheckBox=Prado.WebUI.ClickableComponent; @@ -2407,14 +2425,29 @@ var _7=Event.element(e); if(_7){ Event.fireEvent(_7,"change"); Event.stop(e); -return false; } } -return true; }}); Prado.WebUI.TListControl=Prado.WebUI.createPostBackComponent({onInit:function(_8){ Event.observe(this.element.id,"change",Prado.PostBack.bindEvent(this,_8)); }}); Prado.WebUI.TListBox=Prado.WebUI.TListControl; Prado.WebUI.TDropDownList=Prado.WebUI.TListControl; +Prado.WebUI.DefaultButton=Class.create(); +Object.extend(Prado.WebUI.DefaultButton.prototype,{initialize:function(_9){ +this.options=_9; +this._event=this.triggerEvent.bindEvent(this); +Event.observe(_9["Panel"],"keydown",this._event); +},triggerEvent:function(ev,_11){ +var _12=Event.keyCode(ev)==Event.KEY_RETURN; +var _13=Event.element(ev).tagName.toLowerCase()=="textarea"; +if(_12&&!_13){ +var _14=$(this.options["Target"]); +if(_14){ +this.triggered=true; +Event.fireEvent(_14,this.options["Event"]); +Event.stop(ev); +} +} +}}); diff --git a/framework/Web/Javascripts/prado/controls.js b/framework/Web/Javascripts/prado/controls.js index 34c734f9..d1720dfe 100644 --- a/framework/Web/Javascripts/prado/controls.js +++ b/framework/Web/Javascripts/prado/controls.js @@ -6,7 +6,7 @@ Object.extend(Prado.WebUI.PostBackControl.prototype, {
initialize : function(options)
{
- this.element = $(options['ID']);
+ this.control = $(options['ID']);
if(options['CausesValidation'] && Prado.Validation)
Prado.Validation.AddTarget(options['ID'], options['ValidationGroup']);
@@ -34,7 +34,7 @@ Prado.WebUI.ClickableComponent = Prado.WebUI.createPostBackComponent( {
onInit : function(options)
{
- Event.observe(this.element, "click", Prado.PostBack.bindEvent(this,options));
+ Event.observe(this.control, "click", Prado.PostBack.bindEvent(this,options));
}
});
@@ -61,10 +61,8 @@ Prado.WebUI.TTextBox = Prado.WebUI.createPostBackComponent( {
Event.fireEvent(target, "change");
Event.stop(e);
- return false;
}
}
- return true;
}
});
@@ -79,53 +77,29 @@ Prado.WebUI.TListControl = Prado.WebUI.createPostBackComponent( Prado.WebUI.TListBox = Prado.WebUI.TListControl;
Prado.WebUI.TDropDownList = Prado.WebUI.TListControl;
-
-//Prado.Button = Class.create();
-
-/**
- * Usage: Event.observe("panelID", "keypress", Prado.fireButton.bindEvent($("panelID"), "targetButtonID"));
- */
-/*Object.extend(Prado.Button,
+Prado.WebUI.DefaultButton = Class.create();
+Object.extend(Prado.WebUI.DefaultButton.prototype,
{
- buttonFired : false,
- fireButton : function(e, target)
+ initialize : function(options)
{
- var eventFired = !this.buttonFired && Event.keyCode(e) == Event.KEY_RETURN;
- var isTextArea = Event.element(e).tagName.toLowerCase() == "textarea";
- if (eventFired && !isTextArea)
- {
- var defaultButton = $(target);
- if (defaultButton)
- {
- Prado.Button.buttonFired = true;
- Event.fireEvent(defaultButton,"click");
- Event.stop(e);
- return false;
- }
- }
- return true;
- }
-});
+ this.options = options;
+ this._event = this.triggerEvent.bindEvent(this);
+ Event.observe(options['Panel'], 'keydown', this._event);
+ },
-Prado.TextBox = Class.create();
-*/
-/**
- * Usage: Event.observe("textboxID", "keypress", Prado.fireButton.bindEvent($("textboxID")));
- */
-/*Object.extend(Prado.TextBox,
-{
- handleReturnKey : function(e)
+ triggerEvent : function(ev, target)
{
- if(Event.keyCode(e) == Event.KEY_RETURN)
- {
- var target = Event.element(e);
- if(target)
+ var enterPressed = Event.keyCode(ev) == Event.KEY_RETURN;
+ var isTextArea = Event.element(ev).tagName.toLowerCase() == "textarea";
+ if(enterPressed && !isTextArea)
+ {
+ var defaultButton = $(this.options['Target']);
+ if(defaultButton)
{
- Event.fireEvent(target, "change");
- Event.stop(e);
- return false;
+ this.triggered = true;
+ Event.fireEvent(defaultButton, this.options['Event']);
+ Event.stop(ev);
}
}
- return true;
}
-});*/
+});
\ No newline at end of file |