-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdropins.js
1 lines (1 loc) · 17 KB
/
dropins.js
1
(function(){var D,a,t,y,d,x,e,g,o,k,z,f,l,p,n,q,u,w,c,j,r,s,i,m,C,B,A,h,v=[].slice,b=[].indexOf||function(G){for(var F=0,E=this.length;F<E;F++){if(F in this&&this[F]===G){return F}}return -1};if(window.Dropbox==null){window.Dropbox={}}if(Dropbox.baseUrl==null){Dropbox.baseUrl="https://www.dropbox.com"}if(Dropbox.blockBaseUrl==null){Dropbox.blockBaseUrl="https://dl.dropbox.com"}Dropbox.addListener=function(G,F,E){if(G.addEventListener){G.addEventListener(F,E,false)}else{G.attachEvent("on"+F,function(H){H.preventDefault=function(){return this.returnValue=false};return E(H)})}};Dropbox.removeListener=function(G,F,E){if(G.removeEventListener){G.removeEventListener(F,E,false)}else{G.detachEvent("on"+F,E)}};y=function(F){var G,E;E=encodeURIComponent(Dropbox.VERSION);G=F.indexOf("?")===-1?"?":"&";return""+F+G+"version="+E};x=function(O,J){var M,K,I,E,H,N,G,F,L;N=encodeURIComponent(window.location.protocol+"//"+window.location.host);M=encodeURIComponent(Dropbox.appKey);E=encodeURIComponent(O.linkType||"");G=encodeURIComponent(O._trigger||"js");H=Boolean(O.multiselect);K=encodeURIComponent(((L=O.extensions)!=null?typeof L.join==="function"?L.join(" "):void 0:void 0)||"");I=Boolean(O.folderselect);J=Boolean(J);F=""+Dropbox.baseUrl+"/chooser?origin="+N+"&app_key="+M+"&link_type="+E;F+="&trigger="+G+"&multiselect="+H+"&extensions="+K+"&folderselect="+I+"&iframe="+J;return y(F)};C=function(G){var H,E,F;E=encodeURIComponent(window.location.protocol+"//"+window.location.host);H=encodeURIComponent(Dropbox.appKey);F=""+Dropbox.baseUrl+"/saver?origin="+E+"&app_key="+H;return y(F)};j=1;n=function(F,H){var J,G,I,E;J=encodeURIComponent(Dropbox.appKey);E=""+Dropbox.baseUrl+"/dropins/job_status?job="+H+"&app_key="+J;E=y(E);I=function(L){var K;if(L.status==="COMPLETE"){if(typeof F.progress==="function"){F.progress(1)}if(typeof F.success==="function"){F.success()}}else{if((K=L.status)==="PENDING"||K==="DOWNLOADING"){if(L.progress!=null){if(typeof F.progress==="function"){F.progress(L.progress/100)}}setTimeout(G,1500)}else{if(L.status==="FAILED"){if(typeof F.error==="function"){F.error(L.error)}}}}};if("withCredentials" in new XMLHttpRequest()){G=function(){var K;K=new XMLHttpRequest();K.onload=function(){return I(JSON.parse(K.responseText))};K.onerror=function(){return typeof F.error==="function"?F.error():void 0};K.open("GET",E,true);return K.send()}}else{if(!Dropbox.disableJSONP){G=function(){var M,L,K;M="DropboxJsonpCallback"+j++;L=false;window[M]=function(N){L=true;return I(N)};K=document.createElement("script");K.src=""+E+"&callback="+M;K.onreadystatechange=function(){var N;if(K.readyState==="loaded"){if(!L){if(typeof F.error==="function"){F.error()}}return(N=K.parentNode)!=null?N.removeChild(K):void 0}};return document.getElementsByTagName("head")[0].appendChild(K)}}else{if((typeof XDomainRequest!=="undefined"&&XDomainRequest!==null)&&"https:"===document.location.protocol){G=function(){var K;K=new XDomainRequest();K.onload=function(){return I(JSON.parse(K.responseText))};K.onerror=function(){return typeof F.error==="function"?F.error():void 0};K.open("get",E);return K.send()}}else{throw new Error("Unable to find suitable means of cross domain communication")}}}if(typeof F.progress==="function"){F.progress(0)}return G()};q=function(K,L,M){var I,H,J,G,F,E;H=JSON.parse(K.data);if((typeof u!=="undefined"&&u!==null)&&M._popup){J=u.contentWindow}else{J=K.source}switch(H.method){case"origin_request":K.source.postMessage(JSON.stringify({method:"origin"}),Dropbox.baseUrl);break;case"ready":if(M.files!=null){if(M._fetch_url_on_save){E=(function(){var Q,O,P,N;P=M.files;N=[];for(Q=0,O=P.length;Q<O;Q++){G=P[Q];N.push({filename:G.filename})}return N})();F=JSON.stringify({method:"files_with_callback",params:E})}else{F=JSON.stringify({method:"files",params:M.files})}J.postMessage(F,Dropbox.baseUrl)}if(typeof M.ready==="function"){M.ready()}break;case"files_selected":case"files_saved":if(typeof L==="function"){L()}if(typeof M.success==="function"){M.success(H.params)}break;case"progress":if(typeof M.progress==="function"){M.progress(H.params)}break;case"close_dialog":if(typeof L==="function"){L()}if(typeof M.cancel==="function"){M.cancel()}break;case"web_session_error":if(typeof L==="function"){L()}if(typeof M.webSessionFailure==="function"){M.webSessionFailure()}break;case"web_session_unlinked":if(typeof L==="function"){L()}if(typeof M.webSessionUnlinked==="function"){M.webSessionUnlinked()}break;case"resize":if(typeof M.resize==="function"){M.resize(H.params)}break;case"error":if(typeof L==="function"){L()}if(typeof M.error==="function"){M.error(H.params)}break;case"job_id":if(typeof L==="function"){L()}n(M,H.params);break;case"save_callback":I=function(N){H={method:"continue_saving",params:{download_url:N!=null?N.url:void 0}};J.postMessage(JSON.stringify(H),Dropbox.baseUrl)};f(M,H,I);break;case"_debug_log":if(typeof console!=="undefined"&&console!==null){console.log(H.params.msg)}}};f=function(E,H,G){var F;if(E._fetch_url_on_save){F=E.files[0];if(typeof F.url!=="function"){if(typeof E.error==="function"){E.error("Something went wrong, file url callback not provided.")}}F.url(G)}};u=null;g=function(){if(/\bTrident\b/.test(navigator.userAgent)&&(document.body!=null)&&(u==null)){u=document.createElement("iframe");u.setAttribute("id","dropbox_xcomm");u.setAttribute("src",Dropbox.baseUrl+"/static/api/1/xcomm.html");u.style.display="none";document.body.appendChild(u)}};Dropbox.createChooserWidget=function(E){var F;F=o(x(E,true));F._handler=function(G){if(G.source===F.contentWindow&&G.origin===Dropbox.baseUrl){q(G,null,E)}};Dropbox.addListener(window,"message",F._handler);return F};Dropbox.cleanupWidget=function(E){if(!E._handler){throw new Error("Invalid widget!")}Dropbox.removeListener(window,"message",E._handler);delete E._handler};m=function(E,F){var H,G;H=(window.screenX||window.screenLeft)+((window.outerWidth||document.documentElement.offsetWidth)-E)/2;G=(window.screenY||window.screenTop)+((window.outerHeight||document.documentElement.offsetHeight)-F)/2;return"width="+E+",height="+F+",left="+H+",top="+G};if(Dropbox._dropinsjs_loaded){if(typeof console!=="undefined"&&console!==null){if(typeof console.warn==="function"){console.warn("dropins.js included more than once")}}return}Dropbox._dropinsjs_loaded=true;if(Dropbox.appKey==null){Dropbox.appKey=(h=document.getElementById("dropboxjs"))!=null?h.getAttribute("data-app-key"):void 0}A=function(E){return E};D="https://www.dropbox.com/developers/dropins/chooser/js";t=["text","documents","images","video","audio"];Dropbox.init=function(E){if(E.translation_function!=null){A=E.translation_function}if(E.appKey!=null){Dropbox.appKey=E.appKey}};o=function(E){var F;F=document.createElement("iframe");F.src=E;F.style.display="block";F.style.backgroundColor="white";F.style.border="none";return F};i=function(K){var G,E,M,F,J,L,I,H;if(typeof K[0]==="string"){F=K.shift();if(typeof K[0]==="string"){E=K.shift()}else{E=p(F)}M=K.shift()||{};M.files=[{url:F,filename:E}]}else{M=K.shift();if(M==null){throw new Error("Missing arguments. See documentation.")}if(!(((I=M.files)!=null?I.length:void 0)||typeof M.files==="function")){throw new Error("Missing files. See documentation.")}H=M.files;for(J=0,L=H.length;J<L;J++){G=H[J];if(typeof G.url==="function"){M._fetch_url_on_save=true}if(!G.filename){G.filename=p(G.url)}}if(M._fetch_url_on_save&&M.files.length>1){throw new Error("File url as callback is only supported for single files.")}}return M};Dropbox.save=function(){var H,J,I,G,K,F,E;H=1<=arguments.length?v.call(arguments,0):[];G=i(H);if(!Dropbox.isBrowserSupported()){alert(A("Your browser does not support the Dropbox Saver"));return}G._popup=true;if(!(typeof G.files==="object"&&G.files.length)){throw new Error("The object passed in must have a 'files' property that contains a list of objects. See documentation.")}E=G.files;for(K=0,F=E.length;K<F;K++){I=E[K];if(G._fetch_url_on_save){if(typeof I.url!=="function"){throw new Error("File urls should be either all functions or all urls, not a mix of both. See documentation.")}}else{if(typeof I.url!=="string"){throw new Error("File urls to download incorrectly configured. Each file must have a url. See documentation.")}}}J=m(352,237);return s(C(G),J,G)};s=function(G,H,F){var J,I,K,E,L;J=function(){if(!E.closed){E.close()}Dropbox.removeListener(window,"message",I);clearInterval(L)};I=function(M){if(M.source===E||M.source===(u!=null?u.contentWindow:void 0)){q(M,J,F)}};K=function(){if(E.closed){J();if(typeof F.cancel==="function"){F.cancel()}}};E=window.open(G,"dropbox",""+H+",resizable=yes,location=yes");if(!E){throw new Error("Failed to open a popup window. Dropbox.choose and Dropbox.save should only be called from within a user-triggered event handler such as a tap or click event.")}E.focus();L=setInterval(K,100);Dropbox.addListener(window,"message",I);return E};B=function(H){var I,G,J,F,E;if(H.success==null){if(typeof console!=="undefined"&&console!==null){if(typeof console.warn==="function"){console.warn("You must provide a success callback to the Chooser to see the files that the user selects")}}}G=function(){if(typeof console!=="undefined"&&console!==null){if(typeof console.warn==="function"){console.warn("The provided list of extensions or file types is not valid. See Chooser documentation: "+D)}}if(typeof console!=="undefined"&&console!==null){if(typeof console.warn==="function"){console.warn("Available file types are: "+t.join(", "))}}return delete H.extensions};if((H.extensions!=null)&&(Array.isArray!=null)){if(Array.isArray(H.extensions)){E=H.extensions;for(J=0,F=E.length;J<F;J++){I=E[J];if(!I.match(/^\.[\.\w$#&+@!()\-'`_~]+$/)&&b.call(t,I)<0){G()}}}else{G()}}return H};d=function(F){var J,I,E,G,K,H;if(!Dropbox.isBrowserSupported()){alert(A("Your browser does not support the Dropbox Chooser"));return}H=640;E=552;if(F.iframe){K=o(x(F,true));K.style.width=H+"px";K.style.height=E+"px";K.style.margin="125px auto 0 auto";K.style.border="1px solid #ACACAC";K.style.boxShadow="rgba(0, 0, 0, .2) 0px 4px 16px";G=document.createElement("div");G.style.position="fixed";G.style.left=G.style.right=G.style.top=G.style.bottom="0";G.style.zIndex="1000";G.style.backgroundColor="rgba(160, 160, 160, 0.2)";G.appendChild(K);document.body.appendChild(G);I=function(L){if(L.source===K.contentWindow){q(L,(function(){document.body.removeChild(G);Dropbox.removeListener(window,"message",I)}),F)}};Dropbox.addListener(window,"message",I)}else{J=m(H,E);s(x(F),J,F)}};Dropbox.choose=function(E){if(E==null){E={}}E=B(E);d(E)};Dropbox.isBrowserSupported=function(){var E;E=c();Dropbox.isBrowserSupported=function(){return E};return E};c=function(){var H,G,F,E;E=[/IEMobile\/(7|8|9|10)\./,/BB10;/,/CriOS/];for(G=0,F=E.length;G<F;G++){H=E[G];if(H.test(navigator.userAgent)){return false}}if(!((typeof JSON!=="undefined"&&JSON!==null)&&(window.postMessage!=null)&&(window.addEventListener!=null))){return false}return true};l=function(E){return E.replace(/\/+$/g,"").split("/").pop()};p=function(F){var E;E=document.createElement("a");E.href=F;return l(E.pathname)};e=function(F,G){var E;if(G!=null){G.innerHTML=""}else{G=document.createElement("a");G.href="#"}G.className+=" dropbox-dropin-btn";if(Dropbox.isBrowserSupported()){G.className+=" dropbox-dropin-default"}else{G.className+=" dropbox-dropin-disabled"}E=document.createElement("span");E.className="dropin-btn-status";G.appendChild(E);F=document.createTextNode(F);G.appendChild(F);return G};Dropbox.createChooseButton=function(E){var F;if(E==null){E={}}E=B(E);F=e(A("Choose from Dropbox"));Dropbox.addListener(F,"click",function(G){G.preventDefault();d({success:function(H){F.className="dropbox-dropin-btn dropbox-dropin-success";if(typeof E.success==="function"){E.success(H)}},cancel:E.cancel,linkType:E.linkType,multiselect:E.multiselect,folderselect:E.folderselect,extensions:E.extensions,iframe:E.iframe,_trigger:"button"})});return F};Dropbox.createSaveButton=function(){var F,G,E;F=1<=arguments.length?v.call(arguments,0):[];E=i(F);G=F.shift();G=e(A("Save to Dropbox"),G);Dropbox.addListener(G,"click",function(H){var I;H.preventDefault();if(!(G.className.indexOf("dropbox-dropin-error")>=0||G.className.indexOf("dropbox-dropin-default")>=0||G.className.indexOf("dropbox-dropin-disabled")>=0)){return}I=(typeof E.files==="function"?E.files():void 0)||E.files;if(!(I!=null?I.length:void 0)){G.className="dropbox-dropin-btn dropbox-dropin-error";if(typeof E.error==="function"){E.error("Missing files")}return}Dropbox.save({files:I,success:function(){G.className="dropbox-dropin-btn dropbox-dropin-success";if(typeof E.success==="function"){E.success()}},progress:function(J){G.className="dropbox-dropin-btn dropbox-dropin-progress";if(typeof E.progress==="function"){E.progress(J)}},cancel:function(){if(typeof E.cancel==="function"){E.cancel()}},error:function(J){G.className="dropbox-dropin-btn dropbox-dropin-error";if(typeof E.error==="function"){E.error(J)}}})});return G};r=function(F,E){return"background: "+F+";\nbackground: -moz-linear-gradient(top, "+F+" 0%, "+E+" 100%);\nbackground: -webkit-linear-gradient(top, "+F+" 0%, "+E+" 100%);\nbackground: linear-gradient(to bottom, "+F+" 0%, "+E+" 100%);\nfilter: progid:DXImageTransform.Microsoft.gradient(startColorstr='"+F+"', endColorstr='"+E+"',GradientType=0);"};k=document.createElement("style");k.type="text/css";z='@-webkit-keyframes rotate {\n from { -webkit-transform: rotate(0deg); }\n to { -webkit-transform: rotate(360deg); }\n}\n\n@keyframes rotate {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n\n.dropbox-dropin-btn, .dropbox-dropin-btn:link, .dropbox-dropin-btn:hover {\n display: inline-block;\n height: 14px;\n font-family: "Lucida Grande", "Segoe UI", "Tahoma", "Helvetica Neue", "Helvetica", sans-serif;\n font-size: 11px;\n font-weight: 600;\n color: #636363;\n text-decoration: none;\n padding: 1px 7px 5px 3px;\n border: 1px solid #ebebeb;\n border-radius: 2px;\n border-bottom-color: #d4d4d4;\n '+(r("#fcfcfc","#f5f5f5"))+"\n}\n\n.dropbox-dropin-default:hover, .dropbox-dropin-error:hover {\n border-color: #dedede;\n border-bottom-color: #cacaca;\n "+(r("#fdfdfd","#f5f5f5"))+"\n}\n\n.dropbox-dropin-default:active, .dropbox-dropin-error:active {\n border-color: #d1d1d1;\n box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);\n}\n\n.dropbox-dropin-btn .dropin-btn-status {\n display: inline-block;\n width: 15px;\n height: 14px;\n vertical-align: bottom;\n margin: 0 5px 0 2px;\n background: transparent url('"+Dropbox.baseUrl+"/static/images/widgets/dbx-saver-status.png') no-repeat;\n position: relative;\n top: 2px;\n}\n\n.dropbox-dropin-default .dropin-btn-status {\n background-position: 0px 0px;\n}\n\n.dropbox-dropin-progress .dropin-btn-status {\n width: 18px;\n margin: 0 4px 0 0;\n background: url('"+Dropbox.baseUrl+"/static/images/widgets/dbx-progress.png') no-repeat center center;\n -webkit-animation-name: rotate;\n -webkit-animation-duration: 1.7s;\n -webkit-animation-iteration-count: infinite;\n -webkit-animation-timing-function: linear;\n animation-name: rotate;\n animation-duration: 1.7s;\n animation-iteration-count: infinite;\n animation-timing-function: linear;\n}\n\n.dropbox-dropin-success .dropin-btn-status {\n background-position: -15px 0px;\n}\n\n.dropbox-dropin-disabled {\n background: #e0e0e0;\n border: 1px #dadada solid;\n border-bottom: 1px solid #ccc;\n box-shadow: none;\n}\n\n.dropbox-dropin-disabled .dropin-btn-status {\n background-position: -30px 0px;\n}\n\n.dropbox-dropin-error .dropin-btn-status {\n background-position: -45px 0px;\n}\n\n@media only screen and (-webkit-min-device-pixel-ratio: 1.4) {\n .dropbox-dropin-btn .dropin-btn-status {\n background-image: url('"+Dropbox.baseUrl+"/static/images/widgets/dbx-saver-status-2x.png');\n background-size: 60px 14px;\n -webkit-background-size: 60px 14px;\n }\n\n .dropbox-dropin-progress .dropin-btn-status {\n background: url('"+Dropbox.baseUrl+"/static/images/widgets/dbx-progress-2x.png') no-repeat center center;\n background-size: 20px 20px;\n -webkit-background-size: 20px 20px;\n }\n}\n\n.dropbox-saver:hover, .dropbox-chooser:hover {\n text-decoration: none;\n cursor: pointer;\n}\n\n.dropbox-chooser, .dropbox-dropin-btn {\n line-height: 11px !important;\n text-decoration: none !important;\n box-sizing: content-box !important;\n -webkit-box-sizing: content-box !important;\n -moz-box-sizing: content-box !important;\n}\n";if(k.styleSheet){k.styleSheet.cssText=z}else{k.textContent=z}document.getElementsByTagName("head")[0].appendChild(k);setTimeout(g,0);a=function(){if(document.removeEventListener){document.removeEventListener("DOMContentLoaded",a,false)}else{if(document.detachEvent){document.detachEvent("onreadystatechange",a)}}g();return w()};if(document.readyState==="complete"){setTimeout(a,0)}else{if(document.addEventListener){document.addEventListener("DOMContentLoaded",a,false)}else{document.attachEvent("onreadystatechange",a)}}Dropbox.VERSION="2";w=function(){var G,H,F,E;E=document.getElementsByTagName("a");for(H=0,F=E.length;H<F;H++){G=E[H];if(b.call((G.getAttribute("class")||"").split(" "),"dropbox-saver")>=0){(function(I){Dropbox.createSaveButton({files:function(){return[{url:I.getAttribute("data-url")||I.href,filename:I.getAttribute("data-filename")||l(I.pathname)}]}},I)})(G)}}}}).call(this);