Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Replace jQuery getScript
Follow up to #709
  • Loading branch information
joedolson committed Dec 30, 2025
commit fa3ae304f2e7258701ef1cf1ce4a2555cfbb94f3
20 changes: 20 additions & 0 deletions scripts/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@
});
}

AblePlayer.prototype.getScript = function( source, callback ) {
var script = document.createElement('script');
var prior = document.getElementsByTagName('script')[0];
script.async = 1;

script.onload = script.onreadystatechange = function( _, isAbort ) {
if ( isAbort || !script.readyState || /loaded|complete/.test(script.readyState) ) {
script.onload = script.onreadystatechange = null;
script = undefined;

if ( !isAbort && callback ) {
setTimeout(callback, 0);
}
}
};

script.src = source;
prior.parentNode.insertBefore(script, prior);
}

AblePlayer.prototype.hasAttr = function (object, attribute) {
// surprisingly, there is no hasAttr() function in Jquery as of 3.2.1
// return true if object has attribute; otherwise false
Expand Down
6 changes: 3 additions & 3 deletions scripts/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@
});
} else {
// Has another player already started loading the script? If so, abort...
if (!AblePlayer.loadingYouTubeIframeAPI) {
$.getScript('https://www.youtube.com/iframe_api').fail(function () {
deferred.reject();
if ( ! AblePlayer.loadingYouTubeIframeAPI ) {
thisObj.getScript('https://www.youtube.com/iframe_api', function () {
console.log( 'YouTube API loaded' );
});
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
} else {
// Has another player already started loading the script? If so, abort...
if (!AblePlayer.loadingYouTubeIframeAPI) {
$.getScript('https://www.youtube.com/iframe_api').fail(function () {
deferred.reject();
thisObj.getScript('https://www.youtube.com/iframe_api', function () {
console.log( 'YouTube API loaded' );
});
}

Expand Down