Skip to content

Instantly share code, notes, and snippets.

@phillipharding
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipharding/075f176cb4659c8de342 to your computer and use it in GitHub Desktop.
Save phillipharding/075f176cb4659c8de342 to your computer and use it in GitHub Desktop.
(function($) {
"use strict";
function checkSPWebResource(url, async) {
var
endpoint = url.match(/^http[s]?:\/\//i) || url.match("^"+_spPageContextInfo.webServerRelativeUrl)
? url
: _spPageContextInfo.webServerRelativeUrl.replace(/\/$/g,'')
+ '/' + url.replace(/^\//g,''),
p = $.Deferred();
$.ajax({ type: 'HEAD', url: endpoint, async: (typeof async !== "undefined" ? async : true) })
.done(function(response, textStatus, xhr) {
p.resolve({ status: true, url: endpoint });
})
.fail(function(xhr, textStatus, err) {
p.reject({ status: false, url: endpoint });
});
return p.promise();
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment