mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 17:05:17 +00:00
2 lines
5.5 KiB
JavaScript
2 lines
5.5 KiB
JavaScript
/*! promise-polyfill 2.1.3 */
|
|
!function(a){function b(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof a)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],i(a,b(e,this),b(f,this))}function d(a){var b=this;return null===this._state?void this._deferreds.push(a):void k(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function e(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"==typeof a||"function"==typeof a)){var c=a.then;if("function"==typeof c)return void i(b(c,a),b(e,this),b(f,this))}this._state=!0,this._value=a,g.call(this)}catch(d){f.call(this,d)}}function f(a){this._state=!1,this._value=a,g.call(this)}function g(){for(var a=0,b=this._deferreds.length;b>a;a++)d.call(this,this._deferreds[a]);this._deferreds=null}function h(a,b,c,d){this.onFulfilled="function"==typeof a?a:null,this.onRejected="function"==typeof b?b:null,this.resolve=c,this.reject=d}function i(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var j=j,k="function"==typeof setImmediate&&setImmediate||function(a){j(a,1)},l=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};c.prototype["catch"]=function(a){return this.then(null,a)},c.prototype.then=function(a,b){var e=this;return new c(function(c,f){d.call(e,new h(a,b,c,f))})},c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&l(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(f,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var h=g.then;if("function"==typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;f<a.length;f++)d(f,a[f])})},c.resolve=function(a){return a&&"object"==typeof a&&a.constructor===c?a:new c(function(b){b(a)})},c.reject=function(a){return new c(function(b,c){c(a)})},c.race=function(a){return new c(function(b,c){for(var d=0,e=a.length;e>d;d++)a[d].then(b,c)})},c._setImmediateFn=function(a){k=a},"undefined"!=typeof module&&module.exports?module.exports=c:a.Promise||(a.Promise=c)}(this);"use strict";!function(n){function t(n){function e(n,t,e,r){if(!Array.isArray(r))throw Error("buttons should be array!");return'<div class="page">\n <div data-name="js-close" class="close-button"></div>\n <header>'+n+'</header>\n <div class="content-area">\n '+t+"\n "+e+'\n </div>\n <div class="action-area">\n <div class="button-strip"> '+r.map(function(n,t){return"<button tabindex="+t+' data-name="js-'+n.toLowerCase()+'">'+n+"</button>"}).join("")+"\n </div>\n </div>\n </div>"}function r(n,t,r,o,u){var c=document.createElement("div"),l=["cancel","close","ok"],d=void 0,v=void 0,p=new Promise(function(n,t){var e=u&&!u.cancel,r=function(){};d=n,v=t,e&&(v=r)}),m=e(n,t,r,o);return c.innerHTML=m,c.className="smalltalk",document.body.appendChild(c),f(c,["ok","input"]).forEach(function(n){return n.focus()}),f(c,["input"]).forEach(function(n){n.setSelectionRange(0,r.length)}),s("click",c,l,function(n){return i(n.target,c,d,v)}),["click","contextmenu"].forEach(function(n){return c.addEventListener(n,function(){return f(c,["ok","input"]).forEach(function(n){return n.focus()})})}),c.addEventListener("keydown",a(c,d,v)),p}function a(n,t,e){return function(r){var a={ENTER:13,ESC:27,TAB:9,LEFT:37,UP:38,RIGHT:39,DOWN:40},s=r.keyCode,l=r.target,d=["ok","cancel","input"],p=f(n,d).map(function(n){return o(n)});switch(s){case a.ENTER:i(l,n,t,e),r.preventDefault();break;case a.ESC:v(),e();break;case a.TAB:r.shiftKey&&c(n,p),c(n,p),r.preventDefault();break;default:var m=["left","right","up","down"].some(function(n){return s===a[n.toUpperCase()]});m&&u(n,p)}r.stopPropagation()}}function o(n){return n.getAttribute("data-name").replace("js-","")}function u(n,t){var e="",r=document.activeElement,a=o(r),u=/ok|cancel/.test(a),c=t.length-1;"input"!==a&&c&&u&&(e="cancel"===a?"ok":"cancel",f(n,[e]).forEach(function(n){return n.focus()}))}function c(n,t){var e=document.activeElement,r=o(e),a=t.length-1,u=t.indexOf(r);u===a?u=0:a>u&&++u;var c=t[u];f(n,[c]).forEach(function(n){return n.focus()})}function i(n,t,e,r){var a=void 0,o=n.getAttribute("data-name").replace("js-","");/close|cancel/.test(o)?r():(a=f(t,["input"]).reduce(function(n,t){return t.value},null),e(a)),v()}function f(n,t){var e=t.map(function(t){return n.querySelector('[data-name="js-'+t+'"]')}).filter(function(n){return n});return e}function s(n,t,e,r){f(t,e).forEach(function(t){return t.addEventListener(n,r)})}function l(n){var t=document.querySelector(n);t.parentElement.removeChild(t)}function d(n){for(var t=arguments.length,e=Array(t>1?t-1:0),r=1;t>r;r++)e[r-1]=arguments[r];return function(){return n.apply(void 0,e)}}if(!(this instanceof t))return new t(n);var v=d(l,".smalltalk"),p=["OK"],m=["OK","Cancel"];this.alert=function(n,t,e){return r(n,t,"",p,e)},this.prompt=function(n,t,e,a){var o=e||"",u='<input type="text" value="'+o+'" data-name="js-input">';return r(n,t,u,m,a)},this.confirm=function(n,t,e){return r(n,t,"",m,e)}}"undefined"!=typeof module&&module.exports?module.exports=t():n.smalltalk=t()}("undefined"!=typeof window&&window);
|