From c15f6ea77ce3fbc64c0f2b1aa0f729d22473566a Mon Sep 17 00:00:00 2001 From: Eric McDaniel Date: Wed, 5 Mar 2014 11:45:55 -0500 Subject: [PATCH] CustomEvent support for older devices. Samsung Galaxy SII did not pass typeof CustomEvent == 'function' in a PhoneGap application. This broke Push and my app. This fix should be applied for all CustomEvents in Ratchet in order to work on older devices. --- js/push.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/js/push.js b/js/push.js index da45507..a954ea1 100644 --- a/js/push.js +++ b/js/push.js @@ -382,11 +382,19 @@ }; var triggerStateChange = function () { - var e = new CustomEvent('push', { - detail: { state: getCached(PUSH.id) }, - bubbles: true, - cancelable: true - }); + var e; + var options = {}; + + options.detail = { state: getCached(PUSH.id) }; + options.bubbles = true; + options.cancelable = true; + + if (typeof CustomEvent === 'function') { + e = new CustomEvent('push', options); + } else if (document.createEvent) { + e = document.createEvent('CustomEvent'); + e.initCustomEvent('push', options.bubbles, options.cancelable, options.detail); + } window.dispatchEvent(e); };