friendica_2021.01_tupambae_.../js/ajaxupload.min.js

1 line
8.1 KiB
JavaScript
Raw Normal View History

2013-02-01 03:05:27 +01:00
(function(){function log(){if(typeof console!="undefined"&&typeof console.log=="function"){Array.prototype.unshift.call(arguments,"[Ajax Upload]");console.log(Array.prototype.join.call(arguments," "))}}function addEvent(el,type,fn){if(el.addEventListener){el.addEventListener(type,fn,false)}else if(el.attachEvent){el.attachEvent("on"+type,function(){fn.call(el)})}else{throw new Error("not supported or DOM not loaded")}}function addResizeEvent(fn){var timeout;addEvent(window,"resize",function(){if(timeout){clearTimeout(timeout)}timeout=setTimeout(fn,100)})}if(document.documentElement.getBoundingClientRect){var getOffset=function(el){var box=el.getBoundingClientRect();var doc=el.ownerDocument;var body=doc.body;var docElem=doc.documentElement;var clientTop=docElem.clientTop||body.clientTop||0;var clientLeft=docElem.clientLeft||body.clientLeft||0;var zoom=1;if(body.getBoundingClientRect){var bound=body.getBoundingClientRect();zoom=(bound.right-bound.left)/body.clientWidth}if(zoom>1){clientTop=0;clientLeft=0}var top=box.top/zoom+(window.pageYOffset||docElem&&docElem.scrollTop/zoom||body.scrollTop/zoom)-clientTop,left=box.left/zoom+(window.pageXOffset||docElem&&docElem.scrollLeft/zoom||body.scrollLeft/zoom)-clientLeft;return{top:top,left:left}}}else{var getOffset=function(el){var top=0,left=0;do{top+=el.offsetTop||0;left+=el.offsetLeft||0;el=el.offsetParent}while(el);return{left:left,top:top}}}function getBox(el){var left,right,top,bottom;var offset=getOffset(el);left=offset.left;top=offset.top;right=left+el.offsetWidth;bottom=top+el.offsetHeight;return{left:left,right:right,top:top,bottom:bottom}}function addStyles(el,styles){for(var name in styles){if(styles.hasOwnProperty(name)){el.style[name]=styles[name]}}}function copyLayout(from,to){var box=getBox(from);addStyles(to,{position:"absolute",left:box.left+"px",top:box.top+"px",width:from.offsetWidth+"px",height:from.offsetHeight+"px"});to.title=from.title}var toElement=function(){var div=document.createElement("div");return function(html){div.innerHTML=html;var el=div.firstChild;return div.removeChild(el)}}();var getUID=function(){var id=0;return function(){return"ValumsAjaxUpload"+id++}}();function fileFromPath(file){return file.replace(/.*(\/|\\)/,"")}function getExt(file){return-1!==file.indexOf(".")?file.replace(/.*[.]/,""):""}function hasClass(el,name){var re=new RegExp("\\b"+name+"\\b");return re.test(el.className)}function addClass(el,name){if(!hasClass(el,name)){el.className+=" "+name}}function removeClass(el,name){var re=new RegExp("\\b"+name+"\\b");el.className=el.className.replace(re,"")}function removeNode(el){el.parentNode.removeChild(el)}window.AjaxUpload=function(button,options){this._settings={action:"upload.php",name:"userfile",data:{},autoSubmit:true,responseType:false,hoverClass:"hover",focusClass:"focus",disabledClass:"disabled",onChange:function(file,extension){},onSubmit:function(file,extension){},onComplete:function(file,response){}};for(var i in options){if(options.hasOwnProperty(i)){this._settings[i]=options[i]}}if(button.jquery){button=button[0]}else if(typeof button=="string"){if(/^#.*/.test(button)){button=button.slice(1)}button=document.getElementById(button)}if(!button||button.nodeType!==1){throw new Error("Please make sure that you're passing a valid element")}if(button.nodeName.toUpperCase()=="A"){addEvent(button,"click",function(e){if(e&&e.preventDefault){e.preventDefault()}else if(window.event){window.event.returnValue=false}})}this._button=button;this._input=null;this._disabled=false;this.enable();this._rerouteClicks()};AjaxUpload.prototype={setData:function(data){this._settings.data=data},disable:function(){addClass(this._button,this._settings.disabledClass);this._disabled=true;var nodeName=this._button.nodeName.toUpperCase();if(nodeName=="INPUT"||nodeName=="BUTTON"){this._button.setAttribute("disabled","disabled")}if(this._input){this._input.parentNode.style.visibility="hidden"}},enable:function(){removeClass(this._button,this._settings.disabledClass);this._button.removeAttribute("disabled");this._disabled=false},_createInput:function(){v