Skip to content

Commit

Permalink
fireEvent change for IE9
Browse files Browse the repository at this point in the history
Change-Id: I235f2e14590e5dc3556d15d28586d571d79ef4f2
  • Loading branch information
zoltan-dulac committed May 10, 2011
1 parent f80e6eb commit cc2229d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
41 changes: 18 additions & 23 deletions shared/js/EventHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* This javascript library contains helper routines to assist with event
* handling consinstently among browsers
*
* EventHelpers.js v.1.3 available at http://www.useragentman.com/
* EventHelpers.js v.1.4 available at http://www.useragentman.com/
*
* released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
* Chagelog: 1.4: fix fireEvent to work correctly for IE9.
*
*******************************************************************************/
var EventHelpers = new function(){
Expand All @@ -22,12 +24,13 @@ var EventHelpers = new function(){
return;
}

if (document.createEventObject){
// dispatch for IE
globalEvent = document.createEventObject();
} else if (document.createEvent) {
/* This is for fireEvent */
if (document.createEvent) {
globalEvent = document.createEvent("HTMLEvents");
}
} else if (document.createEventObject){
// dispatch for IE8 and lower.
globalEvent = document.createEventObject();
}

me.docIsLoaded = true;
}
Expand Down Expand Up @@ -415,7 +418,8 @@ var EventHelpers = new function(){
/*
* Fires an event manually.
* @author Scott Andrew - http://www.scottandrew.com/weblog/articles/cbs-events
* @author John Resig - http://ejohn.org/projects/flexible-javascript-events/ * @param {Object} obj - a javascript object.
* @author John Resig - http://ejohn.org/projects/flexible-javascript-events/
* @param {Object} obj - a javascript object.
* @param {String} evType - an event attached to the object.
* @param {Function} fn - the function that is called when the event fires.
*
Expand All @@ -426,24 +430,15 @@ var EventHelpers = new function(){
return;
}

if (document.createEventObject){
/*
var stack = DebugHelpers.getStackTrace();
var s = stack.toString();
jslog.debug(s);
if (s.indexOf('fireEvent') >= 0) {
return;
}
*/
return element.fireEvent('on' + event, globalEvent)
jslog.debug('ss');

}
else{
// dispatch for firefox + others
if (element.dispatchEvent) {
// dispatch for firefox + ie9 + others
globalEvent.initEvent(event, true, true); // event type,bubbling,cancelable
return !element.dispatchEvent(globalEvent);
}
} else if (document.createEventObject){
return element.fireEvent('on' + event, globalEvent)
} else {
return false;
}
}

/* EventHelpers.init () */
Expand Down
19 changes: 16 additions & 3 deletions shared/js/html5Widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ var html5Widgets = new function(){
}

}

function setOutputEvents(nodeName) {
var formElements = document.getElementsByTagName(nodeName);

for (var i=0; i<formElements.length; i++) {
var formElement = formElements[i];
// first - set event to resolve output tags
EventHelpers.addEvent(formElement, 'change', me.resolveOutputs);
EventHelpers.addEvent(formElement, 'keyup', me.resolveOutputs);
}
}


function insertElements(){
Expand All @@ -134,9 +145,6 @@ var html5Widgets = new function(){

var formElement = formElements[i];

// first - set event to resolve output tags
EventHelpers.addEvent(formElement, 'change', me.resolveOutputs);
EventHelpers.addEvent(formElement, 'keypress', me.resolveOutputs);

//var elType = getAttributeValue(formElement, 'type');
var elType = DOMHelpers.getAttributeValue(formElement, 'type');
Expand Down Expand Up @@ -176,6 +184,11 @@ var html5Widgets = new function(){

}

var formElementTypes = ["input", "select", "te xtarea"];
for (var i=0; i<formElementTypes.length; i++) {
setOutputEvents(formElementTypes[i]);
}

if (window.fdSliderController) {
fdSliderController.redrawAll();
}
Expand Down

0 comments on commit cc2229d

Please sign in to comment.