diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js index efb28423..dd4700e0 100644 --- a/Resources/Scripts/code.js +++ b/Resources/Scripts/code.js @@ -1,4 +1,16 @@ -(function($TD, $TDX, $, TD){ +(function($, TD){ + if ($ === null){ + console.error("Missing jQuery"); + } + + if (!("$TD" in window)){ + console.error("Missing $TD"); + } + + if (!("$TDX" in window)){ + console.error("Missing $TDX"); + } + // // Variable: Array of functions called after the website app is loaded. // @@ -54,6 +66,18 @@ }; }; + // + // Function: Triggers an internal debug crash when something is missing. + // + const crashDebug = function(message){ + if ("$TD" in window){ + $TD.crashDebug(message); + } + else{ + console.error(message); + } + } + // // Function: Returns true if an object has a specified property, otherwise returns false with a debug-only error message. // @@ -61,7 +85,7 @@ for(let index = 0; index < chain.length; index++){ if (!obj.hasOwnProperty(chain[index])){ debugger; - $TD.crashDebug("Missing property "+chain[index]+" in chain [obj]."+chain.join(".")); + crashDebug("Missing property " + chain[index] + " in chain [obj]." + chain.join(".")); return false; } @@ -79,7 +103,7 @@ if (!result.length){ debugger; - $TD.crashDebug("No elements were found for selector "+selector); + crashDebug("No elements were found for selector "+selector); } return result; @@ -95,7 +119,7 @@ console.error(err); debugger; - $TD.crashDebug("Caught error in function "+func.name) + crashDebug("Caught error in function "+func.name) fail && fail(); } @@ -1234,14 +1258,14 @@ let prev = TD.mustaches && TD.mustaches[name]; if (!prev){ - $TD.crashDebug("Mustache injection is referencing an invalid mustache: "+name); + crashDebug("Mustache injection is referencing an invalid mustache: "+name); return false; } TD.mustaches[name] = prev.replace(search, replacement); if (prev === TD.mustaches[name]){ - $TD.crashDebug("Mustache injection had no effect: "+name); + crashDebug("Mustache injection had no effect: "+name); return false; } @@ -1823,4 +1847,4 @@ location.href = "https://twitter.com/login?hide_message=true&redirect_after_login=https%3A%2F%2Ftweetdeck.twitter.com%2F%3Fvia_twitter_login%3Dtrue"; }; } -})($TD, $TDX, window.$, window.TD || {}); +})(window.$ || null, window.TD || {}); diff --git a/Resources/Scripts/imports/scripts/plugins.base.js b/Resources/Scripts/imports/scripts/plugins.base.js index 20d85e55..46d842e4 100644 --- a/Resources/Scripts/imports/scripts/plugins.base.js +++ b/Resources/Scripts/imports/scripts/plugins.base.js @@ -1,4 +1,8 @@ -(function($TDP){ +(function(){ + if (!("$TDP" in window)){ + console.error("Missing $TDP"); + } + // // Block: Setup a simple JavaScript object configuration loader. // @@ -49,4 +53,4 @@ element: element }; }; -})($TDP); +})(); diff --git a/Resources/Scripts/introduction.js b/Resources/Scripts/introduction.js index 249a62ee..d7a410fc 100644 --- a/Resources/Scripts/introduction.js +++ b/Resources/Scripts/introduction.js @@ -1,4 +1,4 @@ -(function($, $TD){ +(function(){ $(document).one("TD.ready", function(){ let css = $(`<style>#import "styles/introduction.css"</style>`).appendTo(document.head); let ele = $(`#import "markup/introduction.html"`).appendTo(".js-app"); @@ -38,4 +38,4 @@ }); }); }); -})($, $TD); +})(); diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js index dffdfcb6..98495306 100644 --- a/Resources/Scripts/notification.js +++ b/Resources/Scripts/notification.js @@ -1,4 +1,4 @@ -(function($TD, $TDX){ +(function(){ // // Variable: Collection of all <a> tags. // @@ -181,4 +181,4 @@ // Block: Force a reset of scroll position on every load. // history.scrollRestoration = "manual"; -})($TD, $TDX); +})(); diff --git a/Resources/Scripts/update.js b/Resources/Scripts/update.js index 8d353f7b..f09aea26 100644 --- a/Resources/Scripts/update.js +++ b/Resources/Scripts/update.js @@ -1,4 +1,9 @@ -(function($TDU){ +(function(){ + if (!("$TDU" in window)){ + console.error("Missing $TDU"); + return; + } + // // Function: Creates the update notification element. Removes the old one if already exists. // @@ -140,6 +145,7 @@ $(document).one("TD.ready", triggerCheck); }catch(err){ + console.warn("Missing jQuery or TD.ready event"); setTimeout(triggerCheck, 500); } @@ -147,4 +153,4 @@ // Block: Setup global functions. // window.TDUF_displayNotification = displayNotification; -})($TDU); +})();