Repository: ProgerXP/FileDrop Branch: master Commit: e47c361bdb29 Files: 18 Total size: 328.2 KB Directory structure: gitextract_egk0w3e8/ ├── LICENSE.txt ├── README.md ├── demo/ │ ├── basic.html │ ├── ie9.js │ ├── index.css │ ├── index.html │ ├── index.js │ ├── jquery.js │ ├── normalize.css │ ├── tests.html │ └── upload.php ├── filedrop-min.js ├── filedrop.css ├── filedrop.js ├── logos/ │ └── CREDIT.md ├── package.json ├── upload.aspx └── upload.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE.txt ================================================ This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to ================================================ FILE: README.md ================================================ # FileDrop Revamped #### Self-contained cross-browser HTML5, legacy, AJAX, drag & drop JavaScript file upload **FileDrop** is a lightweight JavaScript class for easy-to-use file uploading that works out of the box and supports even most legacy browsers. [ [Documentation](http://filedropjs.org) | [Demo page](http://filedropjs.org/demo/) ] ## Features * **Cross-browser** – supports Firefox 3.6, Internet Explorer 6, Google Chrome 7, Apple Safari 5 and Opera 11.61. * **No JS dependencies**, Flash or Java applets * 900 lines of code, 1300 lines of comments * **16 KiB minified**, 6 KiB gzipped * **HTML5, drag & drop** for modern browsers * **IFrame fallback** for legacy agents (IE 6+) * Flexible **event system** with over 15 callbacks * Multiple **independent FileDrops** on one page * Ready for **jQuery**, PHP, ASP.net and others * 500+ lines of **unit tests** ([tests.html](http://filedropjs.org/demo/tests.html)) ## Basic example [Live demo](http://filedropjs.org/demo/basic.html) → ```HTML Basic FileDrop example

FileDrop basic sample

Drop a file inside…

Or click here to Browse..

``` ## jQuery integration FileDrop can be integrated with jQuery by simply calling the following method (once, after loading both FileDrop and jQuery): `fd.jQuery()`. Drop zone events are prefixed with **fd** while individual file events start with **file**. DOM node events are triggered before those assigned to `obj.on.XXX` arrays and if a node handler returns non-null value on’s events are skipped. Note that jQuery will prepend its own event object in front of FileDrop’s normal event arguments since they’re triggered as regular events of a DOM node. See extensive comments in the sources for more details and examples. More information in the [documentation](http://filedropjs.org/#jquery) → ```JS fd.jQuery(); // you can also pass an object like 'jQuery'. // Henceforth it's possible to access FileDrop as $().filedrop(). $('

Drop something here...

') .appendTo(document.body) .filedrop() // jQuery always passes event object as the first argument. .on('fdsend', function (e, files) { $.each(files, function (i, file) { file.SendTo('upload.php'); }); }) .on('filedone', function (e, file) { alert('Done uploading ' + file.name + ' on ' + this.tagName); }); ``` ================================================ FILE: demo/basic.html ================================================ Basic FileDrop example

FileDrop basic sample

Drop a file inside…

Or click here to Browse..

================================================ FILE: demo/ie9.js ================================================ /* IE7/IE8/IE9.js - copyright 2004-2010, Dean Edwards http://code.google.com/p/ie7-js/ http://www.opensource.org/licenses/mit-license.php */ ;(function(N,p){var h=N.IE7={version:"2.1(beta4)",toString:bT("[IE7]")};h.compat=9;var t=h.appVersion=navigator.appVersion.match(/MSIE (\d\.\d)/)[1]-0;if(/ie7_off/.test(top.location.search)||t<5.5||t>=h.compat)return;var E=t<6,bj=bT(),bx=p.documentElement,B,x,cy="!",U=":link{ie7-link:link}:visited{ie7-link:visited}",cz=/^[\w\.]+[^:]*$/;function bk(c,a){if(cz.test(c))c=(a||"")+c;return c};function by(c,a){c=bk(c,a);return c.slice(0,c.lastIndexOf("/")+1)};var bU=p.scripts[p.scripts.length-1],cA=by(bU.src);try{var V=new ActiveXObject("Microsoft.XMLHTTP")}catch(ex){}var bl={};function cB(c,a){try{c=bk(c,a);if(!bl[c]){V.open("GET",c,false);V.send();if(V.status==0||V.status==200){bl[c]=V.responseText}}}catch(ex){}return bl[c]||""};var dA=Array.prototype.slice,dB=/%([1-9])/g,cC=/^\s\s*/,cD=/\s\s*$/,cE=/([\/()[\]{}|*+-.,^$?\\])/g,bV=/\bbase\b/,bW=["constructor","toString"],bm;function F(){};F.extend=function(g,f){bm=true;var d=new this;O(d,g);bm=false;var c=d.constructor;function a(){if(!bm)c.apply(this,arguments)};d.constructor=a;a.extend=arguments.callee;O(a,f);a.prototype=d;return a};F.prototype.extend=function(a){return O(this,a)};var P="#",Q="#",bc=".",bn="/",dC=/\\(\d+)/g,cF=/\[(\\.|[^\]\\])+\]|\\.|\(\?/g,cG=/\(/g,cH=/\$(\d+)/,cI=/^\$\d+$/,cJ=/(\[(\\.|[^\]\\])+\]|\\.|\(\?)|\(/g,cK=/^<#\w+>$/,cL=/<#(\w+)>/g,G=F.extend({constructor:function(a){this[bc]=[];this[Q]={};this.merge(a)},add:function(c,a){delete this[bn];if(c instanceof RegExp){c=c.source}if(!this[P+c])this[bc].push(String(c));return this[Q][P+c]=new G.Item(c,a,this)},compile:function(a){if(a||!this[bn]){this[bn]=new RegExp(this,this.ignoreCase?"gi":"g")}return this[bn]},merge:function(c){for(var a in c)this.add(a,c[a])},exec:function(o){var k=this,l=k[bc],m=k[Q],j,i=this.compile(true).exec(o);if(i){var g=0,f=1;while((j=m[P+l[g++]])){var d=f+j.length+1;if(i[f]){if(j.replacement===0){return k.exec(o)}else{var c=i.slice(f,d),a=c.length;while(--a)c[a]=c[a]||"";c[0]={match:c[0],item:j};return c}}f=d}}return null},parse:function(o){o+="";var k=this,l=k[bc],m=k[Q];return o.replace(this.compile(),function(j){var i=[],g,f=1,d=arguments.length;while(--d)i[d]=arguments[d]||"";while((g=m[P+l[d++]])){var c=f+g.length+1;if(i[f]){var a=g.replacement;switch(typeof a){case"function":return a.apply(k,i.slice(f,c));case"number":return i[f+a];default:return a}}f=c}return j})},toString:function(){var g=[],f=this[bc],d=this[Q],c;for(var a=0;c=d[P+f[a]];a++){g[a]=c.source}return"("+g.join(")|(")+")"}},{IGNORE:null,Item:F.extend({constructor:function(k,l,m){var j=k.indexOf("(")===-1?0:G.count(k),i=m.dictionary;if(i&&k.indexOf("<#")!==-1){if(cK.test(k)){var g=i[Q][P+k.slice(2,-1)];k=g.replacement;j=g._5}else{k=i.parse(k)}}if(typeof l=="number")l=String(l);else if(l==null)l=0;if(typeof l=="string"&&cH.test(l)){if(cI.test(l)){var f=l.slice(1)-0;if(f&&f<=j)l=f}else{var d=l,c;l=function(a){if(!c){c=new RegExp(k,"g"+(this.ignoreCase?"i":""))}return a.replace(c,d)}}}this.length=j;this.source=String(k);this.replacement=l}}),count:function(a){return(String(a).replace(cF,"").match(cG)||"").length}}),cM=G.extend({parse:function(f){var d=this[Q];return f.replace(cL,function(c,a){a=d[P+a];return a?a._6:c})},add:function(g,f){if(f instanceof RegExp){f=f.source}var d=f.replace(cJ,cN);if(f.indexOf("(")!==-1){var c=G.count(f)}if(f.indexOf("<#")!==-1){f=this.parse(f);d=this.parse(d)}var a=this.base(g,f);a._6=d;a._5=c||a.length;return a},toString:function(){return"(<#"+this[PATTERNS].join(">)|(<#")+">)"}});function cN(c,a){return a||"(?:"};function O(i,g){if(i&&g){var f=(typeof g=="function"?Function:Object).prototype;var d=bW.length,c;if(bm)while(c=bW[--d]){var a=g[c];if(a!=f[c]){if(bV.test(a)){bX(i,c,a)}else{i[c]=a}}}for(c in g)if(typeof f[c]=="undefined"){var a=g[c];if(i[c]&&typeof a=="function"&&bV.test(a)){bX(i,c,a)}else{i[c]=a}}}return i};function bX(i,g,f){var d=i[g];i[g]=function(){var c=this.base;this.base=d;var a=f.apply(this,arguments);this.base=c;return a}};function cO(f,d){if(!d)d=f;var c={};for(var a in f)c[a]=d[a];return c};function H(g){var f=arguments,d=new RegExp("%([1-"+arguments.length+"])","g");return String(g).replace(d,function(c,a){return a":"","\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\/":"","@(namespace|import)[^;\\n]+[;\\n]":"","'(\\\\.|[^'\\\\])*'":cd,'"(\\\\.|[^"\\\\])*"':cd,"\\s+":" "});function cQ(a){return cc.parse(a).replace(bz,"$1")};function bd(a){return a.replace(cb,cR)};function cd(c){var a=W.length;W[a]=c.slice(1,-1).replace(bz,"$1").replace(cP,"\\'");return"'"+a+"'"};function cR(d,c){var a=W[c];if(a==null)return d;return"'"+W[c]+"'"};function bp(a){return a.indexOf("'")===0?W[a.slice(1,-1)]:a};var cS=new G({Width:"Height",width:"height",Left:"Top",left:"top",Right:"Bottom",right:"bottom",onX:"onY"});function ce(a){return cS.parse(a)};var cf=[];function bA(a){cT(a);y(N,"onresize",a)};function y(d,c,a){d.attachEvent(c,a);cf.push(arguments)};function cU(d,c,a){try{d.detachEvent(c,a)}catch(ex){}};y(N,"onunload",function(){var a;while(a=cf.pop()){cU(a[0],a[1],a[2])}});function be(d,c,a){if(!d.elements)d.elements={};if(a)d.elements[c.uniqueID]=c;else delete d.elements[c.uniqueID];return a};y(N,"onbeforeprint",function(){if(!h.CSS.print)new cg("print");h.CSS.print.recalc()});var ch=/^\d+(px)?$/i,X=/^\d+%$/,C=function(f,d){if(ch.test(d))return parseInt(d);var c=f.style.left,a=f.runtimeStyle.left;f.runtimeStyle.left=f.currentStyle.left;f.style.left=d||0;d=f.style.pixelLeft;f.style.left=c;f.runtimeStyle.left=a;return d},bB="ie7-",ci=F.extend({constructor:function(){this.fixes=[];this.recalcs=[]},init:bj}),bC=[];function cT(a){bC.push(a)};h.recalc=function(){h.HTML.recalc();h.CSS.recalc();for(var a=0;a'@'",cm="if("+cl+"){",cn="(e.nodeName==='FORM'?IE7._0(e,'id'):e.id)",cV=/a(#[\w-]+)?(\.[\w-]+)?:(hover|active)/i,cW=/(.*)(:first-(line|letter))/,cX=/\s/,cY=/((?:\\.|[^{\\])+)\{((?:\\.|[^}\\])+)\}/g,cZ=/(?:\\.|[^,\\])+/g,I=p.styleSheets,bF=[];h.CSS=new(ci.extend({parser:new ca,screen:"",print:"",styles:[],rules:[],pseudoClasses:t<7?"first\\-child":"",dynamicPseudoClasses:{toString:function(){var c=[];for(var a in this)c.push(a);return c.join("|")}},init:function(){var j="^\x01$",i="\\[class=?[^\\]]*\\]",g=[];if(this.pseudoClasses)g.push(this.pseudoClasses);var f=this.dynamicPseudoClasses.toString();if(f)g.push(f);g=g.join("|");var d=t<7?["[>+~\\[(]|([:.])[\\w-]+\\1"]:[i];if(g)d.push(":("+g+")");this.UNKNOWN=new RegExp(d.join("|")||j,"i");var c=t<7?["\\[[^\\]]+\\]|[^\\s(\\[]+\\s*[+~]"]:[i],a=c.concat();if(g)a.push(":("+g+")");u.COMPLEX=new RegExp(a.join("|")||j,"ig");if(this.pseudoClasses)c.push(":("+this.pseudoClasses+")");bf.COMPLEX=new RegExp(c.join("|")||j,"i");f="not\\(:"+f.split("|").join("\\)|not\\(:")+"\\)|"+f;bf.MATCH=new RegExp(f?"(.*?):("+f+")(.*)":j,"i");this.createStyleSheet();this.refresh()},addEventHandler:function(){y.apply(null,arguments)},addFix:function(c,a){this.parser.add(c,a)},addRecalc:function(i,g,f,d){i=i.source||i;g=new RegExp("([{;\\s])"+i+"\\s*:\\s*"+g+"[^;}]*");var c=this.recalcs.length;if(typeof d=="string")d=i+":"+d;this.addFix(g,function(a){if(typeof d=="function")d=d(a);return(d?d:a)+";ie7-"+a.slice(1)+";ie7_recalc"+c+":1"});this.recalcs.push(arguments);return c},apply:function(){this.getInlineCSS();new cg("screen");this.trash()},createStyleSheet:function(){p.getElementsByTagName("head")[0].appendChild(p.createElement("style"));this.styleSheet=I[I.length-1];this.styleSheet.ie7=true;this.styleSheet.owningElement.ie7=true;this.styleSheet.cssText=U},getInlineCSS:function(){var d=p.getElementsByTagName("style"),c;for(var a=d.length-1;c=d[a];a--){if(!c.disabled&&!c.ie7){c._7=c.innerHTML}}},getText:function(d,c){try{var a=d.cssText}catch(e){a=""}if(V)a=cB(d.href,c)||a;return a},recalc:function(){this.screen.recalc();var q=/ie7_recalc\d+/g,n=U.match(/[{,]/g).length,o=this.styleSheet.rules,k,l,m,j,i,g,f,d,c;for(g=n;k=o[g];g++){var a=k.style.cssText;if(l=a.match(q)){j=J(k.selectorText);if(j.length)for(f=0;f*","position:relative")}l.push(g.join("\n"))}}this.cssText=l.join("\n");this.rules=h.CSS.rules.slice(k)},recalc:function(){var c,a;for(a=0;(c=this.rules[a]);a++)c.recalc()},toString:function(){return this.declarations+"@media "+this.media+"{"+this.cssText+"}"}}),R,u=h.Rule=F.extend({constructor:function(d,c){this.id=h.CSS.rules.length;this.className=u.PREFIX+this.id;var a=d.match(cW);this.selector=(a?a[1]:d)||"*";this.selectorText=this.parse(this.selector)+(a?a[2]:"");this.cssText=c;this.MATCH=new RegExp("\\s"+this.className+"(\\s|$)","g");h.CSS.rules.push(this);this.init()},init:bj,add:function(a){a.className+=" "+this.className},recalc:function(){var c=J(this.selector);for(var a=0;a0&&u.CLASS.test(f)){f=f.replace(u.CLASS,"");c--}while(d>0&&u.TAG.test(f)){f=f.replace(u.TAG,"$1*");d--}f+="."+this.className;c=Math.min(c,2);d=Math.min(d,2);var a=-10*c-d;if(a>0){f=f+","+u.MAP[a]+" "+f}return f},remove:function(a){a.className=a.className.replace(this.MATCH,"$1")},toString:function(){return H("%1 {%2}",this.selectorText,this.cssText)}},{CHILD:/>/g,CLASS:/\.[\w-]+/,CLASSES:/[.:\[]/g,MULTI:/(\.[\w-]+)+/g,PREFIX:"ie7_class",TAG:/^\w+|([\s>+~])\w+/,TAGS:/^\w|[\s>+~]\w/g,MAP:{"1":"html","2":"html body","10":".ie7_html","11":"html.ie7_html","12":"html.ie7_html body","20":".ie7_html .ie7_body","21":"html.ie7_html .ie7_body","22":"html.ie7_html body.ie7_body"}}),bf=u.extend({constructor:function(g,f,d,c,a){this.negated=d.indexOf("not")===0;if(this.negated)d=d.slice(5,-1);this.attach=f||"*";this.dynamicPseudoClass=h.CSS.dynamicPseudoClasses[d];this.target=c;this.base(g,a)},recalc:function(){var f=J(this.attach),d;for(var c=0;d=f[c];c++){var a=this.target?J(this.target,d):[d];if(a.length)this.dynamicPseudoClass.apply(d,a,this)}}}),M=F.extend({constructor:function(c,a){this.name=c;this.apply=a;this.instances={};h.CSS.dynamicPseudoClasses[c]=this},register:function(g,f){var d=g[2];if(!f&&d.negated){this.unregister(g,true)}else{g.id=d.id+g[0].uniqueID;if(!this.instances[g.id]){var c=g[1],a;for(a=0;a":function(g,f,d,c){var a="IE7._0(e,'"+f+"')";c=bp(c);if(d.length>1){if(!c||d==="~="&&cX.test(c)){return"false&&"}a="("+a+"||'')"}return"("+H(co[d],a,c)+")&&"},"<#id>":cn+"==='$1'&&","<#class>":"e.className&&(' '+e.className+' ').indexOf(' $1 ')!==-1&&",":first-child":"!"+ck+"&&",":link":"e.currentStyle['ie7-link']=='link'&&",":visited":"e.currentStyle['ie7-link']=='visited'&&"};h.HTML=new(ci.extend({fixed:{},init:bj,addFix:function(){this.fixes.push(arguments)},apply:function(){for(var f=0;f=n(d,d.currentStyle.maxWidth)){d.runtimeStyle.width=d.currentStyle.maxWidth}else{d.runtimeStyle.width=d.runtimeStyle.fixedWidth}};function m(a){if(be(m,a,/^(fixed|absolute)$/.test(a.currentStyle.position)&&bD(a,"left")!=="auto"&&bD(a,"right")!=="auto"&&L.test(bD(a,"width")))){j(a);v.boxSizing(a)}};v.fixRight=m;function j(d){var c=q(d,d.runtimeStyle._3||d.currentStyle.left),a=s(d)-q(d,d.currentStyle.right)-c-k(d,"margin");if(parseInt(d.runtimeStyle.width)===a)return;d.runtimeStyle.width="";if(bq(d)||r||d.offsetWidth=7)return;h.CSS.addRecalc("position","fixed",o,"absolute");h.CSS.addRecalc("background(-attachment)?","[^};]*fixed",q);var z=E?"body":"documentElement";function w(){if(B.currentStyle.backgroundAttachment!=="fixed"){if(B.currentStyle.backgroundImage==="none"){B.runtimeStyle.backgroundRepeat="no-repeat";B.runtimeStyle.backgroundImage="url("+bG+")"}B.runtimeStyle.backgroundAttachment="fixed"}w=bj};var r=cj("img");function A(a){return a?bq(a)||A(a.parentElement):false};function s(d,c,a){setTimeout("document.all."+d.uniqueID+".runtimeStyle.setExpression('"+c+"','"+a+"')",0)};function q(a){if(be(q,a,a.currentStyle.backgroundAttachment==="fixed"&&!a.contains(B))){w();j.bgLeft(a);j.bgTop(a);n(a)}};function n(c){r.src=c.currentStyle.backgroundImage.slice(5,-2);var a=c.canHaveChildren?c:c.parentElement;a.appendChild(r);j.setOffsetLeft(c);j.setOffsetTop(c);a.removeChild(r)};function o(a){if(be(o,a,bq(a))){Y(a,"position","absolute");Y(a,"left",a.currentStyle.left);Y(a,"top",a.currentStyle.top);w();h.Layout.fixRight(a);k(a)}};function k(d,c){p.body.getBoundingClientRect();j.positionTop(d,c);j.positionLeft(d,c,true);if(!d.runtimeStyle.autoLeft&&d.currentStyle.marginLeft==="auto"&&d.currentStyle.right!=="auto"){var a=x.clientWidth-j.getPixelWidth(d,d.currentStyle.right)-j.getPixelWidth(d,d.runtimeStyle._3)-d.clientWidth;if(d.currentStyle.marginRight==="auto")a=parseInt(a/2);if(A(d.offsetParent))d.runtimeStyle.pixelLeft+=a;else d.runtimeStyle.shiftLeft=a}if(!d.runtimeStyle.fixedWidth)j.clipWidth(d);if(!d.runtimeStyle.fixedHeight)j.clipHeight(d)};function l(){var c=q.elements;for(var a in c)n(c[a]);c=o.elements;for(a in c){k(c[a],true);k(c[a],true)}m=0};var m;bA(function(){if(!m)m=setTimeout(l,100)});var j={},i=function(g){g.bgLeft=function(a){a.style.backgroundPositionX=a.currentStyle.backgroundPositionX;if(!A(a)){s(a,"backgroundPositionX","(parseInt(runtimeStyle.offsetLeft)+document."+z+".scrollLeft)||0")}};g.setOffsetLeft=function(c){var a=A(c)?"backgroundPositionX":"offsetLeft";c.runtimeStyle[a]=g.getOffsetLeft(c,c.style.backgroundPositionX)-c.getBoundingClientRect().left-c.clientLeft+2};g.getOffsetLeft=function(c,a){switch(a){case"left":case"top":return 0;case"right":case"bottom":return x.clientWidth-r.offsetWidth;case"center":return(x.clientWidth-r.offsetWidth)/2;default:if(X.test(a)){return parseInt((x.clientWidth-r.offsetWidth)*parseFloat(a)/100)}r.style.left=a;return r.offsetLeft}};g.clipWidth=function(f){var d=f.runtimeStyle.fixWidth;f.runtimeStyle.borderRightWidth="";f.runtimeStyle.width=d?g.getPixelWidth(f,d)+"px":"";if(f.currentStyle.width!=="auto"){var c=f.getBoundingClientRect();var a=f.offsetWidth-x.clientWidth+c.left-2;if(a>=0){f.runtimeStyle.borderRightWidth="0px";a=Math.max(C(f,f.currentStyle.width)-a,0);Y(f,"width",a);return a}}};g.positionLeft=function(c,a){if(!a&&X.test(c.currentStyle.width)){c.runtimeStyle.fixWidth=c.currentStyle.width}if(c.runtimeStyle.fixWidth){c.runtimeStyle.width=g.getPixelWidth(c,c.runtimeStyle.fixWidth)}c.runtimeStyle.shiftLeft=0;c.runtimeStyle._3=c.currentStyle.left;c.runtimeStyle.autoLeft=c.currentStyle.right!=="auto"&&c.currentStyle.left==="auto";c.runtimeStyle.left="";c.runtimeStyle.screenLeft=g.getScreenLeft(c);c.runtimeStyle.pixelLeft=c.runtimeStyle.screenLeft;if(!a&&!A(c.offsetParent)){s(c,"pixelLeft","runtimeStyle.screenLeft+runtimeStyle.shiftLeft+document."+z+".scrollLeft")}};g.getScreenLeft=function(d){var c=d.offsetLeft,a=1;if(d.runtimeStyle.autoLeft){c=x.clientWidth-d.offsetWidth-g.getPixelWidth(d,d.currentStyle.right)}if(d.currentStyle.marginLeft!=="auto"){c-=g.getPixelWidth(d,d.currentStyle.marginLeft)}while(d=d.offsetParent){if(d.currentStyle.position!=="static")a=-1;c+=d.offsetLeft*a}return c};g.getPixelWidth=function(c,a){return X.test(a)?parseInt(parseFloat(a)/100*x.clientWidth):C(c,a)}};eval("var _9="+ce(i));i(j);_9(j)})();if(t<7){var bJ={backgroundColor:"transparent",backgroundImage:"none",backgroundPositionX:null,backgroundPositionY:null,backgroundRepeat:null,borderTopWidth:0,borderRightWidth:0,borderBottomWidth:0,borderLeftStyle:"none",borderTopStyle:"none",borderRightStyle:"none",borderBottomStyle:"none",borderLeftWidth:0,borderLeftColor:"#000",borderTopColor:"#000",borderRightColor:"#000",borderBottomColor:"#000",height:null,marginTop:0,marginBottom:0,marginRight:0,marginLeft:0,width:"100%"};h.CSS.addRecalc("overflow","visible",function(d){if(d.currentStyle.position==="absolute")return;if(d.parentNode.ie7_wrapped)return;if(h.Layout&&d.currentStyle["max-height"]!=="auto"){h.Layout.maxHeight(d)}if(d.currentStyle.marginLeft==="auto")d.style.marginLeft=0;if(d.currentStyle.marginRight==="auto")d.style.marginRight=0;var c=p.createElement(cy);c.ie7_wrapped=d;for(var a in bJ){c.style[a]=d.currentStyle[a];if(bJ[a]!=null){d.runtimeStyle[a]=bJ[a]}}c.style.display="block";c.style.position="relative";d.runtimeStyle.position="absolute";d.parentNode.insertBefore(c,d);c.appendChild(d)})}function dc(){var s="xx-small,x-small,small,medium,large,x-large,xx-large".split(",");for(var q=0;q%4",MATCH:/(.*):(before|after).*/,count:0});h._getLang=function(c){var a="";while(c&&c.nodeType===1){a=c.lang||c.getAttribute("lang")||"";if(a)break;c=c.parentNode}return a};T=O(T,{":lang\\(([^)]+)\\)":"((ii=IE7._getLang(e))==='$1'||ii.indexOf('$1-')===0)&&"})}var dj=/^(submit|reset|button)$/;h.HTML.addRecalc("button,input",function(c){if(c.nodeName==="BUTTON"){var a=c.outerHTML.match(/ value="([^"]*)"/i);c.runtimeStyle.value=a?a[1]:""}if(c.type==="submit"){y(c,"onclick",function(){c.runtimeStyle.clicked=true;setTimeout("document.all."+c.uniqueID+".runtimeStyle.clicked=false",1)})}});h.HTML.addRecalc("form",function(d){y(d,"onsubmit",function(){for(var c,a=0;c=d[a];a++){if(dj.test(c.type)&&!c.disabled&&!c.runtimeStyle.clicked){c.disabled=true;setTimeout("document.all."+c.uniqueID+".disabled=false",1)}else if(c.nodeName==="BUTTON"&&c.type==="submit"){setTimeout("document.all."+c.uniqueID+".value='"+c.value+"'",1);c.value=c.runtimeStyle.value}}})});h.HTML.addRecalc("img",function(a){if(a.alt&&!a.title)a.title=""});if(t<8){h.CSS.addRecalc("border-spacing",bg,function(a){if(a.currentStyle.borderCollapse!=="collapse"){a.cellSpacing=C(a,a.currentStyle["ie7-border-spacing"].split(" ")[0])}});h.CSS.addRecalc("box-sizing","content-box",h.Layout.boxSizing);h.CSS.addRecalc("box-sizing","border-box",h.Layout.borderBox)}if(t<8){var dk=/^image/i;h.HTML.addRecalc("object",function(a){if(dk.test(a.type)){a.body.style.cssText="margin:0;padding:0;border:none;overflow:hidden";return a}})}var bM="!IE7._a(e,'next')&&",cs=bM.replace("next","previous");if(h.CSS.pseudoClasses)h.CSS.pseudoClasses+="|";h.CSS.pseudoClasses+="(?:first|last|only)\\-(?:child|of\\-type)|empty|root|target|"+("not|nth\\-child|nth\\-last\\-child|nth\\-of\\-type|nth\\-last\\-of\\-type".split("|").join(bK+"|")+bK);var bN=new M("checked",function(c){if(typeof c.checked!=="boolean")return;var a=arguments;h.CSS.addEventHandler(c,"onpropertychange",function(){if(event.propertyName==="checked"){if(c.checked===true)bN.register(a);else bN.unregister(a)}});if(c.checked===true)bN.register(a)}),bO=new M("enabled",function(c){if(typeof c.disabled!=="boolean")return;var a=arguments;h.CSS.addEventHandler(c,"onpropertychange",function(){if(event.propertyName==="disabled"){if(c.disabled===false)bO.register(a);else bO.unregister(a)}});if(c.disabled===false)bO.register(a)}),bP=new M("disabled",function(c){if(typeof c.disabled!=="boolean")return;var a=arguments;h.CSS.addEventHandler(c,"onpropertychange",function(){if(event.propertyName==="disabled"){if(c.disabled===true)bP.register(a);else bP.unregister(a)}});if(c.disabled===true)bP.register(a)}),bQ=new M("indeterminate",function(c){if(typeof c.indeterminate!=="boolean")return;var a=arguments;h.CSS.addEventHandler(c,"onpropertychange",function(){if(event.propertyName==="indeterminate"){if(c.indeterminate===true)bQ.register(a);else bQ.unregister(a)}});h.CSS.addEventHandler(c,"onclick",function(){bQ.unregister(a)})}),bR=new M("target",function(c){var a=arguments;if(!c.tabIndex)c.tabIndex=0;h.CSS.addEventHandler(p,"onpropertychange",function(){if(event.propertyName==="activeElement"){if(c.id&&c.id===location.hash.slice(1))bR.register(a);else bR.unregister(a)}});if(c.id&&c.id===location.hash.slice(1))bR.register(a)}),ct=1,bu={_4:1};h._b=function(l,m,j){var i=l.parentNode;if(!i||i.nodeType!==1)return NaN;var g=j?l.nodeName:"";if(g==="TR"&&l.sectionRowIndex>=0){var c=l.sectionRowIndex;return m?l.parentNode.rows.length-c+1:c}if((g==="TD"||g==="TH")&&l.cellIndex>=0){c=l.cellIndex;return m?l.parentNode.cells.length-c+1:c}if(bu._4!==ct){bu={_4:ct}}var f=(i.uniqueID)+"-"+g,d=bu[f];if(!d){d={};var c=0,a=i.firstChild;while(a){if(j?a.nodeName===g:a.nodeName>"@"){d[a.uniqueID]=++c}a=a.nextSibling}d.length=c;bu[f]=d}c=d[l.uniqueID];return m?d.length-c+1:c};h._c=function(a){a=a.firstChild;while(a){if(a.nodeType===3||a.nodeName>"@")return false;a=a.nextSibling}return true};h._a=function(d,c){var a=d.nodeName;c+="Sibling";do{d=d[c];if(d&&d.nodeName===a)break}while(d);return d};var dl={"+":1,"-":-1},dm=/ /g;T=O(O({":nth(-last)?-(?:child|(of-type))\\((<#nth_arg>)\\)(<#filter>)?":function(m,j,i,g,f){g=g.replace(dm,"");var d="IE7._b(e,"+!!j+","+!!i+")";if(g==="even")g="2n";else if(g==="odd")g="2n+1";else if(!isNaN(g))g="0n"+~~g;g=g.split("n");var c=~~(dl[g[0]]||g[0]||1),b=~~g[1];if(c===0){var a=d+"==="+b}else{a="((ii="+d+")-("+b+"))%"+c+"===0&&ii"+(c<0?"<":">")+"="+b}return this.parse(f)+a+"&&"},"<#negation>":function(c,a){if(/:not/i.test(a))bv();if(/^[#.:\[]/.test(a)){a="*"+a}return"!("+D.parse(a).slice(3,-2)+")&&"}},T),{":checked":"e.checked===true&&",":disabled":"e.disabled===true&&",":enabled":"e.disabled===false&&",":last-child":"!"+bE+"&&",":only-child":"!"+ck+"&&!"+bE+"&&",":first-of-type":cs,":last-of-type":bM,":only-of-type":cs+bM,":empty":"IE7._c(e)&&",":root":"e==R&&",":target":"H&&"+cn+"===H&&"});var dn="article,aside,audio,canvas,details,figcaption,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,summary,time,video".split(",");for(var cu=0,cv;cv=dn[cu];cu++)p.createElement(cv);U+="datalist{display:none}details{padding-left:40px;display:block;margin:1em 0}meter,progress{vertical-align:-0.2em;width:5em;height:1em;display:inline-block}progress{width:10em;}article,aside,figcaption,footer,header,hgroup,summary,section,nav{display:block;margin:1em 0}figure{margin:1em 40px;display:block}mark{background:yellow}";h.CSS.addFix(/\bopacity\s*:\s*([\d.]+)/,function(c,a){return"zoom:1;filter:Alpha(opacity="+((a*100)||1)+")"});var D,J=(function(){var o0=/^[>+~]/,bw=false;function dp(f,d,c){f=bZ(f);if(!d)d=p;var a=d;bw=o0.test(f);if(bw){d=d.parentNode;f="*"+f}try{return n.create(f,bw)(d,c?null:[],a)}catch(ex){return c?null:[]}};var dq=/^(\\.|[' >+~#.\[\]:*(),\w-\^|$=]|[^\x00-\xa0])+$/,dE=/^(href|src)$/,cw={"class":"className","for":"htmlFor"},dF=/\sie7_\w+/g,dr=/^(action|cite|codebase|data|dynsrc|href|longdesc|lowsrc|src|usemap|url)$/i;h._0=function(f,d){if(f.getAttributeNode){var c=f.getAttributeNode(d)}d=cw[d.toLowerCase()]||d;if(!c)c=f.attributes[d];var a=c&&c.specified;if(f[d]&&typeof f[d]=="boolean")return d.toLowerCase();if((a&&dr.test(d))||(!c&&E)||d==="value"||d==="type"){return f.getAttribute(d,2)}if(d==="style")return f.style.cssText.toLowerCase()||null;return a?String(c.nodeValue):null};var cx="colSpan,rowSpan,vAlign,dateTime,accessKey,tabIndex,encType,maxLength,readOnly,longDesc";O(cw,cO(cx.toLowerCase().split(","),cx.split(",")));h._1=function(c,a){a+="Sibling";do{c=c[a];if(c&&c.nodeName>"@")break}while(c);return c};var ds=/(^|[, >+~])([#.:\[])/g,dG=/\)\{/g,dt=/,/,dH=/^['"]/,du=/\\([\da-f]{2,2})/gi,dI=/last/i;h._d=function(f,d){var c=f.all[d]||null;if(!c||(c.nodeType&&h._0(c,"id")===d))return c;for(var a=0;a+~]/,operator:/[\^~|$*]?=/,nth_arg:/[+-]?\d+|[+-]?\d*n(?:\s*[+-]\s*\d+)?|even|odd/,tag:/\*|<#ident>/,id:/#(<#ident>)/,'class':/\.(<#ident>)/,pseudo:/\:([\w-]+)(?:\(([^)]+)\))?/,attr:/\[(<#ident>)(?:(<#operator>)((?:\\.|[^\[\]#.:])+))?\]/,negation:/:not\((<#tag>|<#id>|<#class>|<#attr>|<#pseudo>)\)/,sequence:/(\\.|[~*]=|\+\d|\+?\d*n\s*\+\s*\d|[^\s>+~,\*])+/,filter:/[#.:\[]<#sequence>/,selector:/[^>+~](\\.|[^,])*?/,grammar:/^(<#selector>)((,<#selector>)*)$/}),ignoreCase:true}),dv=new bb({"\\\\.|[~*]\\s+=|\\+\\s+\\d":G.IGNORE,"\\[\\s+":"[","\\(\\s+":"(","\\s+\\)":")","\\s+\\]":"]","\\s*([,>+~]|<#operator>)\\s*":"$1","\\s+$":"","\\s+":" "});function dw(a){a=dv.parse(a.replace(du,"\\x$1")).replace(bz,"$1").replace(ds,"$1*$2");if(!dq.test(a))bv();return a};function dJ(a){return a.replace(cb,dx)};function dx(c,a){return W[a]};var dy=/\{/g,dz=/\\{/g;function bS(a){return Array((a.replace(dz,"").match(dy)||"").length+1).join("}")};T=new bb(T);var v=/:target/i,Z=/:root/i;function S(c){var a="";if(Z.test(c))a+=",R=d.documentElement";if(v.test(c))a+=",H=d.location;H=H&&H.hash.replace('#','')";if(a||c.indexOf("#")!==-1){a=",t=c.nodeType,d=t===9?c:c.ownerDocument||(c.document||c).parentWindow.document"+a}return"var ii"+a+";"};var ba={" ":";while(e!=s&&(e=e.parentNode)&&e.nodeType===1){",">":".parentElement;if(e){","+":";while((e=e.previousSibling)&&!("+cl+"))continue;if(e){","~":";while((e=e.previousSibling)){"+cm},K=/\be\b/g;D=new bb({"(?:(<#selector>)(<#combinator>))?(<#tag>)(<#filter>)?$":function(j,i,g,f,d){var c="";if(f!=="*"){var a=f.toUpperCase();c+="if(e.nodeName==='"+a+(a===f?"":"'||e.nodeName==='"+f)+"'){"}if(d){c+="if("+T.parse(d).slice(0,-2)+"){"}c=c.replace(K,"e"+this.index);if(g){c+="var e=e"+(this.index++)+ba[g];c=c.replace(K,"e"+this.index)}if(i){c+=this.parse(i)}return c}});var L="e0=IE7._d(d,'%1');if(e0){",z="var n=c.getElementsByTagName('%1');",w="if(r==null)return e0;r[k++]=e0;",r=1,A=new bb({"^((?:<#selector>)?(?:<#combinator>))(<#tag>)(<#filter>)?$":true}),s={},q=new bb({"^(<#tag>)#(<#ident>)(<#filter>)?( [^,]*)?$":function(j,i,g,f,d){var c=H(L,g),a="}";if(f){c+=D.parse(i+f);a=bS(c)}if(d){c+="s=c=e0;"+n.parse("*"+d)}else{c+=w}return c+a},"^([^#,]+)#(<#ident>)(<#filter>)?$":function(g,f,d,c){var a=H(L,d);if(f==="*"){a+=w}else{a+=D.parse(f+c)+w+"break"}return a+bS(a)},"^.*$":""}),n=new bb({"<#grammar>":function(k,l,m){if(!this.groups)this.groups=[];var j=A.exec(" "+l);if(!j)bv();this.groups.push(j.slice(1));if(m){return this.parse(m.replace(dt,""))}var i=this.groups,g=i[0][r];for(var c=1;j=i[c];c++){if(g!==j[r]){g="*";break}}var f="",d=w+"continue filtering;";for(var c=0;j=i[c];c++){D.index=0;if(g!=="*")j[r]="*";j=j.join("");if(j===" *"){f=d;break}else{j=D.parse(j);if(bw)j+="if(e"+D.index+"==s){";f+=j+d+bS(j)}}var a=g==="*";return(a?"var n=c.all;":H(z,g))+"filtering:while((e0=n[i++]))"+(a?cm.replace(K,"e0"):"{")+f+"}"},"^.*$":bv}),o=/\&\&(e\d+)\.nodeType===1(\)\{\s*if\(\1\.nodeName=)/g;n.create=function(d){if(!s[d]){d=dw(d);this.groups=null;D.index=0;var c=this.parse(d);this.groups=null;D.index=0;if(d.indexOf("#")!==-1){var a=q.parse(d);if(a){c="if(t===1||t===11|!c.getElementById){"+c+"}else{"+a+"}"}}c=c.replace(o,"$2");c=S(d)+bd(c);s[d]=new Function("return function(c,r,s){var i=0,k=0,e0;"+c+"return r}")()}return s[d]};return dp})();function bv(){throw new SyntaxError("Invalid selector.");};h.loaded=true;(function(){try{if(!p.body)throw"continue";bx.doScroll("left")}catch(ex){setTimeout(arguments.callee,1);return}try{eval(bU.innerHTML)}catch(ex){}if(typeof IE7_PNG_SUFFIX=="object"){bh=IE7_PNG_SUFFIX}else{bh=new RegExp(bY(N.IE7_PNG_SUFFIX||"-trans.png")+"(\\?.*)?$","i")}B=p.body;x=E?B:bx;B.className+=" ie7_body";bx.className+=" ie7_html";if(E)dc();h.CSS.init();h.HTML.init();h.HTML.apply();h.CSS.apply();h.recalc()})()})(this,document); ================================================ FILE: demo/index.css ================================================ @import url(normalize.css); /*** Essential FileDrop styles for ================================================ FILE: demo/upload.php ================================================ and
// using regular multipart/form-data enctype (which is handled by PHP $_FILES). if (!empty($_FILES['fd-file']) and is_uploaded_file($_FILES['fd-file']['tmp_name'])) { // Regular multipart/form-data upload. $name = $_FILES['fd-file']['name']; $data = file_get_contents($_FILES['fd-file']['tmp_name']); } else { // Raw POST data. $name = urldecode(@$_SERVER['HTTP_X_FILE_NAME']); $data = file_get_contents("php://input"); } // Output message for this demo upload. In your real app this would be something // meaningful for the calling script (that uses FileDrop.js). $output = sprintf('%s; received %s bytes, CRC32 = %08X, MD5 = %s', $name, number_format(strlen($data)), crc32($data), strtoupper(md5($data))); // In FileDrop sample this demonstrates the passing of custom ?query variables along // with an AJAX/iframe upload. $opt = &$_REQUEST['upload_option']; isset($opt) and $output .= "\nReceived upload_option with value $opt"; if ($callback) { // Callback function given - the caller loads response into a hidden
',n.firstChild.setAttribute("id",t),n.firstChild.style.display="none",n.lastChild.setAttribute("target",t);for(var r=e.firstChild;r&&(!f.isTag(r)||f.isTag(r,"legend"));)r=r.nextSibling;return r?e.insertBefore(n,r):e.appendChild(n),n.lastChild.lastChild},o.abortIFrame=function(){var e;!o.opt.input.form||(e=f.byID(o.opt.input.form.getAttribute("target")))&&e.setAttribute("src","javascript:false")},o.sendViaIFrame=function(t){t=t||o.opt.iframe.url;var e=(o.opt.input||{}).form;if(t&&e){do{var n=f.randomID()}while(n in window);window[n]=function(e){"object"!=typeof e&&(e={response:e,responseXML:"",responseText:(e||"").toString(),readyState:4,status:200,statusText:"OK",getAllResponseHeaders:function(){return""},getResponseHeader:function(){return""},setRequestHeader:function(){return this},statusCode:function(){return this},abort:function(){return this}}),f.extend(e,{iframe:!0,url:t}),f.callAllOfObject(o,"iframeDone",e)};for(var r=e.firstChild;r&&(!f.isTag(r,"input")||r.name!=o.opt.iframe.callbackParam);)r=r.nextSibling;return r?r.value=n:t=t.replace(/[?&]+$/,"")+(-1==t.indexOf("?")?"?":"&")+o.opt.iframe.callbackParam+"="+n,e.setAttribute("action",t),f.callAllOfObject(o,"iframeSetup",e),e.submit(),setTimeout(o.resetForm,300),!0}},o.resetForm=function(){var e,t=o.opt.input&&o.opt.input.file;t&&(t.value="",o.opt.recreateInput&&(e=o.opt.input.file=t.cloneNode(!0),t.parentNode.replaceChild(e,t),f.callAllOfObject(o,"inputSetup",[o.opt.input,t])))},o.multiple=function(e){return o.opt.input&&void 0!==e&&(e?o.opt.input.file.setAttribute("multiple","multiple"):o.opt.input.file.removeAttribute("multiple")),o.opt.input&&!!o.opt.input.file.getAttribute("multiple")},o.event=function(e,t){return f.appendEventsToObject.apply(o,arguments)},o.preview=function(e,t){return f.previewToObject.apply(o,arguments)},o.onInputSetup=function(e,t){t?(e.file.clearAttributes&&e.file.clearAttributes(),e.file.mergeAttributes&&e.file.mergeAttributes(t)):o.multiple(o.opt.multiple),f.setClass(e.file,o.opt.inputClass),o.delegate(e.file,"change","upload"),(e=e.file.parentNode)&&e.style.display.match(/^(static)?$/)&&(e.style.position="relative"),f.isTag(n,"fieldset")&&((e=document.createElement("div")).style.position="relative",e.style.overflow="hidden",n.parentNode.insertBefore(e,n),e.appendChild(n))},o.onDragOver=function(e){f.stopEvent(e),e.dataTransfer&&(e.dataTransfer.dropEffect=o.opt.dropEffect)},o.onUpload=function(){for(var e=0;et[1]?1:e[1] fallback in addition to HTML5 drag & drop (only working in Firefox/Chrome/Opera 15+). You can @import this file and override individual styles. Drag & drop zone can be styled in absolutely any way you want so there are no defaults. ***/ /* Essential FileDrop zone element configuration: */ .fd-zone { position: relative; overflow: hidden; /*** This way you can create a pretty box that will be both clickable and droppable: *** width: 15em; margin: 0 auto; text-align: center; */ } /* Hides while simulating "Browse" button: */ .fd-file { opacity: 0; font-size: 118px; position: absolute; right: 0; top: 0; z-index: 1; padding: 0; margin: 0; cursor: pointer; filter: alpha(opacity=0); font-family: sans-serif; } /*** With .over you can provide feedback when user drags a file over the drop zone: *** .fd-zone.over { border-color: maroon; background: #eee; } */ ================================================ FILE: filedrop.js ================================================ /*! FileDrop Revamped - HTML5 & legacy file upload in public domain | http://filedropjs.org by Proger_XP | http://proger.me Supports IE 6+, FF 3.6+, Chrome 7+, Safari 5+, Opera 11+. Fork & report problems at https://github.com/ProgerXP/FileDrop */ ;(function (root, init) { if (typeof define == 'function' && define.amd) { define(['exports'], function (exports) { init(root, exports) }) } else if (typeof exports !== 'undefined') { init(root, exports) } else { init(root, root.fd = root.fd || {}) } })(this, function (root, global) { /*** Global Utility Functions ***/ // Produces random ID (non necessary unique to anything) with given prefix // or 'fd' if it's not passed. // //? randomID() //=> 'fd_9854' //? randomID('foo') //=> 'foo_1582' global.randomID = function (prefix) { return (prefix || 'fd') + '_' + (Math.random() * 10000).toFixed() } // Generates random DOM node ID that's unique to this document with given prefix // or 'fd' if it's not passed. // //? randomID() //=> 'fd_9854' //? randomID('foo') //=> 'foo_1582' global.uniqueID = function (prefix) { do { var id = global.randomID(prefix) } while (global.byID(id)) return id } // Retrieves DOM element by its ID attribute or returns id itself if it's // an element. // //? byID('foo') //=>

//? byID('abracadabra!') //=> null //? byID({foo: 1}) //=> null //? byID(null) //=> null // //? byID(document.createElement('p')) // //=>

global.byID = function (id) { return global.isTag(id) ? id : document.getElementById(id) } // Checks if given object is a proper DOM node. If tag is passed also // checks if that DOM node is of the same tag (case-insensitive). // Returns true or false. // //? isTag('foo') //=> false //? isTag({foo: 1}) //=> false //? isTag(null) //=> false //? isTag(window) //=> false //? isTag(document.body) //=> true //? isTag(document.body, 'BoDy') //=> true //? isTag(document.body, 'head') //=> false // //? var el = byID('foo') //=>

// isTag(el, 'p') //=> true // isTag(el, 'P') //=> true // isTag(el, 'div') //=> false // isTag(el, 'DiV') //=> false // //? isTag(document.createElement('p')) // //=> true // //? isTag(document.createElement('p'), 'div') // //=> false global.isTag = function (element, tag) { return typeof element == 'object' && element && element.nodeType == 1 && ( !tag || element.tagName.toUpperCase() == tag.toUpperCase() ) } // Creates new XMLHttpRequest object. Falls back for ActiveX for IE 6. // Throws an exception if couldn't succeed (this shouldn't happen these days). // //? newXHR() //=> XMLHttpRequest global.newXHR = function () { try { return new XMLHttpRequest } catch (e) { // IE 6. var activex = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'] for (var i = 0; i < activex.length; i++) { try { return new ActiveXObject(activex[i]) } catch (e) {} } } throw 'Cannot create XMLHttpRequest.' } // Checks if given value is a native Array object. Note that jQuery and // other pseudo-arrays are reported as false. // //? isArray([]) //=> true //? isArray([]) //=> true //? isArray(new Array) //=> true //? isArray({}) //=> false //? isArray('foo') //=> false //? isArray(null) //=> false //? isArray($('a')) //=> false //? isArray(arguments) //=> false //? isArray($('a').toArray()) //=> true global.isArray = function (value) { return Object.prototype.toString.call(value) === '[object Array]' } // Converts passed value into an array. If value is already an array its // copy is returned (so changing value later doesn't affect the returned // clone). // // skipFirst, if given, omits specified number of elements from the start. // Useful for turning arguments into arrays. // //? toArray([]) //=> [] (copy) //? toArray(['foo']) //=> ['foo'] (copy) //? toArray(['foo'], 1) //=> [] //? toArray(['foo'], 999) //=> [] //? toArray('foo') //=> ['foo'] //? toArray('foo', 1) //=> [] //? toArray('foo', 999) //=> [] //? toArray({foo: 1}) //=> [{foo: 1}] //? toArray({foo: 1}, 1) //=> [] //? toArray(null) //=> [] //? toArray(new Array('foo', 'bar')) => ['foo', 'bar'] (copy) //? toArray(new Array('foo', 'bar'), 1) => ['bar'] //? toArray(new Array('foo', 'bar'), 2) => [] // //? function showMessage(func, line1, line2, ...) { // window[func](toArray(arguments, 1).join('\n')) // } // // showMessage('confirm', 'It\'s first line.', 'Second line.') // //=> confirm('It\'s first line.\nSecond line.') // // showMessage('alert', 'First', 'Second') // //=> alert('First\nSecond') global.toArray = function (value, skipFirst) { if (value === null || typeof value == 'undefined') { return [] } else if (!global.isArray(value) && (typeof value != 'object' || !('callee' in value))) { // Made sure it's not 'arguments'. value = [value] } return Array.prototype.slice.call(value, skipFirst || 0) } // Adds an event listener to a DOM element. Works for old IE as well // as modern W3C-compliant browsers. type is short event name (without // 'on' prefix). Does nothing if any parameter is invalid. // Returns the DOM element itself or whatever was given as this argument. // //? addEvent(byID('p'), 'mousemove', function () { alert('Whoosh!') }) //? addEvent(window, 'load', function () { alert('Done loading.') }) // //? addEvent(null, 'blur', function () { }) // nothing. //? addEvent(window, null, function () { }) // nothing. //? addEvent(window, 'blur', null) // nothing. // //? addEvent(window, 'nonstandard', function () { }) // // works. global.addEvent = function (element, type, callback) { if (element && type && callback) { if (element.attachEvent) { element['e' + type + callback] = callback element[type + callback] = function() { element['e' + type + callback](window.event) } element.attachEvent('on' + type, element[type + callback]) } else { element.addEventListener(type, callback, false) } } return element } // Stops propagation and default browser action of an event. // Works for old IE and modern W3C-compliant browsers. // //? byID('p').onmousemove = function (e) { stopEvent(e) } global.stopEvent = function (event) { event.cancelBubble = true event.returnValue = false event.stopPropagation && event.stopPropagation() event.preventDefault && event.preventDefault() return event } // Adds or removes HTML class of a DOM element. Keeps old classes. // element can be either ID string or a DOM node. // Returns the element (even if ID was passed) or null if passed value // is neither a string nor a DOM node or if there's no element with // this ID. // //? setClass(byID('p'), 'foo') //=>

//? setClass(byID('p'), 'foo', true) // equivalent to above //? setClass(byID('p'), 'foo', false) //=>

(no 'foo') //? setClass('anID', 'foo') //=> //? setClass('anID', 'foo', false) //=> without 'foo' class //? global.setClass = function (element, className, append) { if ((element = global.byID(element)) && className != null) { if (typeof append != 'undefined' && !append) { element.className = element.className.replace(global.classRegExp(className), ' ') } else if (!global.hasClass(element, className)) { element.className += ' ' + className } } return element } // Determines if given element has class attribute containing the className // word. Accepts DOM element or ID string. Returns true or false. // Examples below refer to

// //? hasClass(byID('anID'), 'cls1') //=> true //? hasClass('anID', 'cls1') // equivalent to above //? hasClass('anID', 'cls') //=> false //? hasClass('anID', 'foo') //=> false //? hasClass('abra!', 'cls1') //=> false (no such element) //? hasClass('anID', '') //=> false (empty class) //? hasClass('anID', null) //=> false //? hasClass('anID', {foo: 1}) //=> false (not a string) //? hasClass(null, 'foo') //=> false //? hasClass({foo: 1}, 'foo') //=> false (not a DOM node) //? hasClass(window, foo) //=> false global.hasClass = function (element, className) { return global.classRegExp(className).test( (global.byID(element) || {}).className ) } // Returns a regular expression suitable for testing of HTML class-like // strings to find out if it contains a given word or not (it's not as // simple as a substring match: 'some class' contains words 'some' and // 'class' but not 'som' and 'cl' or 'ame' and 'ass'). // // Shouldn't be used for testing multiple words (space-separated) - will // only match if they are in the same position in testing string which // doesn't have to be true: classRegExp('some class') would match // 'this is some class' but won't match 'some of the class'. // // Returns a never matching regexp for bad parameter like object or an // empty string. // //? classRegExp('foo') //=> RegExp /(^|\s+)foo(\s+|$)/ig //? classRegExp('x').test('x y z') //=> true //? classRegExp('foo bar') // works but not advised //? classRegExp({foo: 1}) //=> RegExp /$o_O/ //? classRegExp(null) // the same as above //? classRegExp(window) // the same as above //? classRegExp(null).test('foo') //=> false (always) global.classRegExp = function (className) { if (className == '' || typeof className == 'object') { return /$o_O/ // never matches. } else { return new RegExp('(^|\\s+)' + className + '(\\s+|$)', 'gi') } } // Copies properties from object base to object child. If overwrite // is passed and true then base's properties will replace those // in child even if child has its own properties of that name. // Note that it doesn't clone child, it's edited in-place. // Also note that defined properties that are 'undefined' on child are // replaced by base's even if overwrite is false (see examples). // // Returns the modified child (first argument). // //? extend({common: 1, child: false}, {common: 'foo', base: true}) // //=> {common: 1, child: false, base: true} // //? extend({common: 1, child: false}, {common: 'foo', base: true}, true) // //=> {common: 'foo', child: false, base: true} // //? extend({x: undefined}, {x: 1}) //=> {x: 1} //? extend({x: null}, {x: 1}) //=> {x: null} // //? var child = {y: 1} // extend(child, {x: 1}) === child //=> true (same object) // console.dir(child) //=> {y: 1, x: 1} global.extend = function (child, base, overwrite) { child = child || {} base = base || {} for (var prop in base) { if (overwrite || typeof child[prop] == 'undefined') { child[prop] = base[prop] } } return child } /*** Event Manipulation Functions ***/ // Calls every handler of the passed callback list with given arguments // and in context of obj or 'this' if it's omitted. // // list can be undefined, a single function or an array (non-function members // are skipped). Throws exception if list is something else. // args is converted to array with toArray() so it can be a single value, // an arguments object or something else - see that function for info. // // Returns result of the last called function. If any function returns // a non-null and non-undefined value all following handlers are skipped. // //? callAll(function (a) { return a + 'foo' }, 'arg1') // //=> 'arg1foo' //? callAll([ function () { } ], ['arg1']) // // equivalent to above // //? var list = [function (a) { return a[0] == 'a' ? a + 'foo' : null }, // function (a) { alert(a) }] // callAll(list, 'arg1') //=> 'arg1foo' (first handler) // callAll(list, 'foo') //=> alert('foo') (second handler) // //? callAll(function () { alert(this.x) }, [], {x: 'foo'}) // //=> alert('foo') // //? callAll(function () { alert(this.x) }).call({x: 'foo'}) // // equivalent to above // //? window.onload = function () { // callAll([...], arguments, window) // // equivalent to callAll([...], toArray(arguments), window) // } global.callAll = function (list, args, obj) { var res args = global.toArray(args) typeof list == 'function' && (list = [list]) if (global.isArray(list)) { for (var i = 0; i < list.length; i++) { if (typeof list[i] == 'function') { res = list[i].apply(obj || this, args) if (res != null) { break } } } } else if (list) { throw 'FileDrop event list must be either an Array, Function, undefined or' + ' null but ' + (typeof list) + ' was given.' } return res } // Calls event handlers attached on given FileDrop object to passed // event name with arguments. Hands off most work to callAll(). // obj is an object with the 'events' property (object with keys = event // names and values = arrays of functions). // // Before calling handlers of obj looks if global configuration has // a preview handler specified - if it does then calls that handler // and if it returns non-null and non-undefined value doesn't call // obj's handlers but returns that value immediately. After the global // preview function it checks for object-wise preview - its 'any' event // handlers which are treated likewise. // Preview functions are called with event name pushed in front of // the other event args. // //? var obj = {events: { foo: [function (a) { alert(a); return true }] }} // callAllOfObject(obj, 'foo', 'arg1') //=> true after alert('arg1') // //? window.fd.onObjectCall = function (e) { alert(e + ': tee hee'); return false } // var obj = ... // as above // callAllOfObject(obj, 'foo', 'arg1') //=> false after alert('foo: tee hee') // //? var obj = {events: { any: [function (e) { return false }] }} // callAllOfObject(obj, 'anyevent') // // because of the object-wise preview handler that returns false // // any event we call will return false bypassing its actual handlers. global.callAllOfObject = function (obj, event, args) { if (global.logging && global.hasConsole) { var handlers = obj.events[event] ? obj.events[event].length || 0 : 0 console.info('FileDrop ' + event + ' event (' + handlers + ') args:') console.dir([args]) } var preview = [global.onObjectCall].concat(obj.events.any) var res = global.callAll(preview, [event].concat(global.toArray(args)), obj) return res != null ? res : global.callAll(obj.events[event], args, obj) } // Appends event listeners to given object with 'events' property according // to passed parameters. See DropHandle.event() for details. // 'this' must be set to the object which events are updated. global.appendEventsToObject = function (events, funcs) { if (global.addEventsToObject(this, false, arguments)) { return this } switch (arguments.length) { case 0: return global.extend({}, this.events) case 1: if (events === null) { this.events = {} return this } else if (global.isArray(events)) { var res = {} for (var i = 0; i < events.length; i++) { res[events[i]] = global.toArray(this.events[events[i]]) } return res } else if (typeof events == 'function') { return global.funcNS(events) } else if (typeof events == 'string') { return global.toArray(this.events[events]) } case 2: events = global.toArray(events) if (funcs === null) { for (var i = 0; i < events.length; i++) { var ns = global.splitNS(events[i]) if (!ns[0]) { for (var event in this.events) { arguments.callee.call(this, [event + ':' + ns[1]], null) } } else if (!ns[1]) { this.events[ns[0]] = [] } else if (this.events[ns[0]]) { for (var fi = this.events[ns[0]].length - 1; fi >= 0; fi--) { if (global.funcNS( this.events[ns[0]][fi] ) == ns[1]) { this.events[ns[0]].splice(fi, 1) } } } } return this } } throw 'Bad parameters for FileDrop event().' } // Prepends event listeners to given object with 'events' property according // to passed parameters. See DropHandle.event() for details. // 'this' must be set to the object which events are updated. global.previewToObject = function (events, funcs) { if (global.addEventsToObject(this, true, arguments)) { return this } else { throw 'Bad parameters for FileDrop preview().' } } // Adds event listeners to given object with 'events' property according // to passed parameters. See DropHandle.event() for details. // Returns nothing if couldn't handle given parameter combination. global.addEventsToObject = function (obj, prepend, args) { var events = args[0] var funcs = args[1] switch (args.length) { case 1: if (events && typeof events == 'object' && !global.isArray(events)) { for (var event in events) { arguments.callee(obj, prepend, [event, events[event]]) } return true } case 2: if (typeof funcs == 'function' || global.isArray(funcs)) { events = global.toArray(events) funcs = global.toArray(funcs) var pusher = prepend ? 'unshift' : 'push' for (var i = 0; i < events.length; i++) { var ns = global.splitNS(events[i]) for (var fi = 0; fi < funcs.length; fi++) { global.funcNS(funcs[fi], ns[1]) } obj.events[ns[0]] = obj.events[ns[0]] || [] obj.events[ns[0]][pusher].apply(obj.events[ns[0]], funcs) } return true } } } // Adds namespace identifier to a Function object. Used when labeling event // listeners in DropHandle.event(). If given just one parameter reads // attached namespace, if present. // //? funcNS(function () { }, 'foo') //? funcNS(function () { }) //=> 'foo' global.funcNS = function (func, ns) { if (typeof func != 'function') { return func } else if (arguments.length == 1) { return (func[global.nsProp] || '').toString() } else { func[global.nsProp] = (ns || '').toString() return func } } // Extracts namespace identifier from the string. Uses jQuery notation: // 'event:namespace'. Both parts can be empty. If colon is omitted returns // '' instead of namespace. // Returns array with two items - event name (or other prefix) and namespace. // //? splitNS('') //=> ['', ''] //? splitNS(null) // identical to above //? splitNS(':') // identical to above //? splitNS('x:') //=> ['x', ''] //? splitNS(':y') //=> ['', 'y'] //? splitNS('x:y') //=> ['x', 'y'] //? splitNS('x:y:z') //=> ['x', 'y:z'] global.splitNS = function (str) { return (str || '').match(/^([^:]*):?(.*)$/).slice(1) } /*** Global Configuration ***/ global.extend(global, { // If set all event calls will be logged to console if one is present. logging: true, // Indicates if console.log and console.dir are available for usage. hasConsole: 'console' in window && console.log && console.dir, // If set must be a function that's called on every event being fired. // See how it works in callAllOfObject(). onObjectCall: null, // All DropHandle objects that were instantinated on this page. // Note that these are not FileDrop instances as not all DropHandles // might be part of FileDrops. Use DropHandle.filedrop property. all: [], // Tests for IE versions, must be true for 6-7/9 and below and // false for any other version/browser. // IE 6 on XP SP 3 gives JScript version 5.7 while IE 8 - 5.8. // IE 9 on Win7 gives 9. isIE6: /*@cc_on/*@if(@_jscript_version<=5.7)true@else@*/false/*@end@*/, isIE9: /*@cc_on/*@if(@_jscript_version<=9)true@else@*/false/*@end@*/, // Test for Google Chrome. This isn't used to determine available // File API but only to work around certain event glitches. isChrome: (navigator.vendor || '').indexOf('Google') != -1, // Name of Function object property where event namespace is stored. // See funcNS(), splitNS(), DropHandle.event(). nsProp: '_fdns' }) /*** Basic Drop Handle Class *** Has some file upload functionality (mostly legacy ' + '

' + '' + '' + '' //