From 403dabc43f638b6dfdcccbb66db2343c02029932 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 18 Jan 2017 22:56:07 +0000 Subject: [PATCH] add jquery wrapper --- oauth3.jquery.js | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 oauth3.jquery.js diff --git a/oauth3.jquery.js b/oauth3.jquery.js new file mode 100644 index 0000000..f1abcfe --- /dev/null +++ b/oauth3.jquery.js @@ -0,0 +1,105 @@ +(function () { + 'use strict'; + + // I did try to shim jQuery's deferred, but it's just too clunky. + // Here I use es6-promise which lacks asynchrity, but it's the smallest Promise implementation. + // Only Opera Mini and MSIE (even on 11) will use this shim, so no biggie; + + var oauth3 = window.OAUTH3; + var count = 0; + + function inject() { + count += 1; + + if (count >= 100) { + throw new Error("you forgot to include rsvp.js, methinks"); + } + + /* + * + [window.Promise, window.ES6Promise, window.RSVP.Promise].forEach(function (PromiseA) { + var x = 1; new PromiseA(function (resolve, reject) { console.log('x', 1 === x); resolve(); }); x = 2; void null; + var y = 1; PromiseA.resolve().then(function () { console.log('y', 2 === x); }); y = 2; void null; + }); + */ + var PromiseA = /*(window.RSVP && window.RSVP.Promise) || window.ES6Promise || */window.Promise; + if ('undefined' !== typeof PromiseA) { + oauth3.providePromise(PromiseA).then(function () { + // ignore + window.jqOauth3 = oauth3; + }, function (err) { + console.error(err); + console.error("Bad Promise Implementation!"); + }); + return; + } + + + // because MSIE can't tell when a script is loaded + setTimeout(inject, 100); + } + + if ('undefined' === typeof Promise) { + // support Opera Mini and MSIE 11+ (which doesn't support