123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /**************************************************************************
- * Licensed Materials - Property of IBM *
- * *
- * IBM Cognos Products: AGS *
- * *
- * (C) Copyright IBM Corp. 2005, 2017 *
- * *
- * US Government Users Restricted Rights - Use, duplication or disclosure *
- * restricted by GSA ADP Schedule Contract with IBM Corp. *
- ***************************************************************************/
- // -----------------------------------------------------------------------------
- //
- // --- event listener utility ---
- //
- // -----------------------------------------------------------------------------
- //object to ease the chaining of event handlers, in order to allow users to add more than one handler to a control
- function EventHandlerChain(name, handler){
- this.eventName = name;
- this.functionRefs = new Array();
- this.addHandler(handler);
- }
- EventHandlerChain.prototype.setEventHandlerChain = function(an_object){
- if (an_object) {
- if (cf.browserCheck.isIE5Up()) {
- an_object.attachEvent("on" + this.eventName,this.handleEvent);
- }
- else if (cf.browserCheck.isNav6Up()) {
- an_object.addEventListener(this.eventName,this.handleEvent,true);
- }
- an_object[eventHandlerChainUtil.getPropertyName(this.eventName)] = this;
- }
- }
- EventHandlerChain.prototype.addHandler = function(handler){
- this.functionRefs.push(handler);
- }
- EventHandlerChain.prototype.handleEvent = function(event){
-
- if(!this.eventName){
- //find the right instance
- if (!event) event=arguments.callee.caller.arguments[0];
- var control=event.srcElement || event.currentTarget || event.target;
-
- var evtName = eventHandlerChainUtil.getPropertyName(event.type);
-
- var ehc = eventHandlerChainUtil.getEventHandlerChain(control, evtName);
-
- if (ehc) {
- ehc.handleEvent(event);
- }
-
- return;
- }
-
- for(var i = 0; i < this.functionRefs.length; i++){
- if(this.functionRefs[i]){
- if (typeof this.functionRefs[i] == "object" && this.functionRefs[i].update) {
- //callback on the object itself (used by eventNotification framework)
- this.functionRefs[i].update(event);
- } else {
- //should be a function
- this.functionRefs[i](event);
- }
- }
- }
- }
- function EventHandlerChainUtil(){
-
- return this.PROPERTY_NAME = "event_handler_chain";
- }
- EventHandlerChainUtil.prototype.getPropertyName = function(event_name){
-
- return this.PROPERTY_NAME + "_" + event_name;
- }
- EventHandlerChainUtil.prototype.getEventHandlerChain = function(an_object, property_name){
- //var property_name = this.getPropertyName(event_name);
-
- var ehc;
-
- //the event source object may not have had the handler applied
- if(an_object && an_object[property_name]){
- ehc = an_object[property_name];
- }else if(an_object){
- ehc = this.getEventHandlerChain(an_object.parentNode, property_name);
- }
- return ehc;
-
-
- }
- //utility to check and then initialise or add to event handler chain for this object event and handler
- EventHandlerChainUtil.prototype.doEventHandlerChain = function(an_object, event_name, handler){
- var property_name = this.getPropertyName(event_name);
- var ehc = this.getEventHandlerChain(an_object,property_name);
-
- if(!ehc){
- ehc = new EventHandlerChain(event_name, handler);
- ehc.setEventHandlerChain(an_object);
- }else{
- ehc.addHandler(handler);
- }
- }
- var eventHandlerChainUtil = new EventHandlerChainUtil();
|