From 9efdd54701b147f9b150dda87e15457f13c13c80 Mon Sep 17 00:00:00 2001 From: Alexander Ward Date: Wed, 17 Aug 2011 13:57:21 -0500 Subject: [PATCH 1/2] Adds some bulletproofing to the API event dispatching, in the event that for whatever reason you have a broken jQuery/Prototype install basic events will still fire. --- soundcloud.player.api.js | 16 ++++++++++++++-- soundcloud.player.api.min.js | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 soundcloud.player.api.min.js diff --git a/soundcloud.player.api.js b/soundcloud.player.api.js index 2b3d783..d59b86a 100644 --- a/soundcloud.player.api.js +++ b/soundcloud.player.api.js @@ -31,10 +31,22 @@ // re-dispatch SoundCloud events up in the DOM if(window.jQuery){ // if jQuery is available, trigger the custom event - jQuery(playerNode).trigger(customEventType, [data]); + try { + jQuery(playerNode).trigger(customEventType, [data]); + } catch (e) { + if (this.debug && window.console) { + console.error("Unable to dispatch jQuery Event (.trigger failed) " + eventType + " for the widget id " + flashId, data, e); + } + } }else if(window.Prototype){ // if Prototype.js is available, fire the custom event - $(playerNode).fire(customEventType, data); + try { + $(playerNode).fire(customEventType, data); + } catch (e) { + if (this.debug && window.console) { + console.error("Unable to dispatch Prototype Event (.fire failed) " + eventType + " for the widget id " + flashId, data, e); + } + } }else{ // TODO add more JS libraries that support custom DOM events } diff --git a/soundcloud.player.api.min.js b/soundcloud.player.api.min.js new file mode 100644 index 0000000..855d804 --- /dev/null +++ b/soundcloud.player.api.min.js @@ -0,0 +1 @@ +(function(){var b=(/msie/i).test(navigator.userAgent)&&!(/opera/i).test(navigator.userAgent);var a=window.soundcloud={version:"0.1",debug:false,_listeners:[],_redispatch:function(c,n,g){var j,m=this._listeners[c]||[],d="soundcloud:"+c;try{j=this.getPlayer(n)}catch(k){if(this.debug&&window.console){console.error("unable to dispatch widget event "+c+" for the widget id "+n,g,k)}return}if(window.jQuery){try{jQuery(j).trigger(d,[g])}catch(k){if(this.debug&&window.console){console.error("Unable to dispatch jQuery Event (.trigger failed) "+c+" for the widget id "+n,g,k)}}}else{if(window.Prototype){try{$(j).fire(d,g)}catch(k){if(this.debug&&window.console){console.error("Unable to dispatch Prototype Event (.fire failed) "+c+" for the widget id "+n,g,k)}}}else{}}for(var h=0,f=m.length;h Date: Thu, 18 Aug 2011 09:24:18 -0500 Subject: [PATCH 2/2] Matching formatting of source file --- soundcloud.player.api.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/soundcloud.player.api.js b/soundcloud.player.api.js index d59b86a..884825b 100644 --- a/soundcloud.player.api.js +++ b/soundcloud.player.api.js @@ -31,22 +31,22 @@ // re-dispatch SoundCloud events up in the DOM if(window.jQuery){ // if jQuery is available, trigger the custom event - try { - jQuery(playerNode).trigger(customEventType, [data]); - } catch (e) { - if (this.debug && window.console) { - console.error("Unable to dispatch jQuery Event (.trigger failed) " + eventType + " for the widget id " + flashId, data, e); - } - } + try{ + jQuery(playerNode).trigger(customEventType, [data]); + }catch(e){ + if(this.debug && window.console){ + console.error("Unable to dispatch jQuery Event (.trigger failed) " + eventType + " for the widget id " + flashId, data, e); + } + } }else if(window.Prototype){ // if Prototype.js is available, fire the custom event - try { - $(playerNode).fire(customEventType, data); - } catch (e) { - if (this.debug && window.console) { - console.error("Unable to dispatch Prototype Event (.fire failed) " + eventType + " for the widget id " + flashId, data, e); - } - } + try{ + $(playerNode).fire(customEventType, data); + }catch(e){ + if(this.debug && window.console){ + console.error("Unable to dispatch Prototype Event (.fire failed) " + eventType + " for the widget id " + flashId, data, e); + } + } }else{ // TODO add more JS libraries that support custom DOM events }