filer/dist/filer.min.js

4 lines
75 KiB
JavaScript
Raw Normal View History

/*! filer 0.0.41 2015-06-01 */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Filer=t()}}(function(){var t;return function e(t,n,r){function i(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var c=n[a]={exports:{}};t[a][0].call(c.exports,function(e){var n=t[a][1][e];return i(n?n:e)},c,c.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({1:[function(e,n){(function(){var e={};"undefined"!=typeof process&&process.nextTick?(e.nextTick=process.nextTick,e.setImmediate="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:e.nextTick):"function"==typeof setImmediate?(e.nextTick=function(t){setImmediate(t)},e.setImmediate=e.nextTick):(e.nextTick=function(t){setTimeout(t,0)},e.setImmediate=e.nextTick),e.eachSeries=function(t,e,n){if(n=n||function(){},!t.length)return n();var r=0,i=function(){e(t[r],function(e){e?(n(e),n=function(){}):(r+=1,r>=t.length?n():i())})};i()},e.forEachSeries=e.eachSeries,t!==void 0&&t.amd?t([],function(){return e}):n!==void 0&&n.exports?n.exports=e:root.async=e})()},{}],2:[function(t,e){function n(t,e){for(var n=e.length-1;n>=0;n--)e[n]===t&&e.splice(n,1);return e}var r=function(){};r.createInterface=function(t){var e={};return e.on=function(e,n){this[t]===void 0&&(this[t]={}),this[t].hasOwnProperty(e)||(this[t][e]=[]),this[t][e].push(n)},e.off=function(e,r){void 0!==this[t]&&this[t].hasOwnProperty(e)&&n(r,this[t][e])},e.trigger=function(e){if(this[t]!==void 0&&this[t].hasOwnProperty(e))for(var n=Array.prototype.slice.call(arguments,1),r=0;this[t][e].length>r;r++)this[t][e][r].apply(this[t][e][r],n)},e.removeAllListeners=function(e){if(void 0!==this[t]){var n=this;n[t][e].forEach(function(t){n.off(e,t)})}},e};var i=r.createInterface("_handlers");r.prototype._on=i.on,r.prototype._off=i.off,r.prototype._trigger=i.trigger;var o=r.createInterface("handlers");r.prototype.on=function(){o.on.apply(this,arguments),Array.prototype.unshift.call(arguments,"on"),this._trigger.apply(this,arguments)},r.prototype.off=o.off,r.prototype.trigger=o.trigger,r.prototype.removeAllListeners=o.removeAllListeners,e.exports=r},{}],3:[function(t,e){(function(n){function r(t,e){var n=0;return function(){var r=Date.now();r-n>t&&(n=r,e.apply(this,arguments))}}function i(t,e){if(void 0!==t&&t||(t={}),"object"==typeof e)for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function o(){var t=this,e=Date.now();this.origin=s(),this.lastMessage=e,this.receivedIDs={},this.previousValues={};var r=function(){t._onStorageEvent.apply(t,arguments)};"undefined"!=typeof document&&(document.attachEvent?document.attachEvent("onstorage",r):n.addEventListener("storage",r,!1))}var a=t("./eventemitter.js"),s=t("../src/shared.js").guid,u=function(t){return t===void 0||t.localStorage===void 0?{getItem:function(){},setItem:function(){},removeItem:function(){}}:t.localStorage}(n);o.prototype._transaction=function(t){function e(){if(!a){var f=Date.now(),h=0|u.getItem(l);if(h&&r>f-h)return s||(o._on("storage",e),s=!0),c=setTimeout(e,i),void 0;a=!0,u.setItem(l,f),t(),n()}}function n(){s&&o._off("storage",e),c&&clearTimeout(c),u.removeItem(l)}var r=1e3,i=20,o=this,a=!1,s=!1,c=null;e()},o.prototype._cleanup_emit=r(100,function(){var t=this;t._transaction(function(){var t,e=Date.now(),n=e-h,r=0;try{t=JSON.parse(u.getItem(c)||"[]")}catch(i){t=[]}for(var o=t.length-1;o>=0;o--)n>t[o].timestamp&&(t.splice(o,1),r++);r>0&&u.setItem(c,JSON.stringify(t))})}),o.prototype._cleanup_once=r(100,function(){var t=this;t._transaction(function(){var e,n;Date.now();var r=0;try{n=JSON.parse(u.getItem(f)||"{}")}catch(i){n={}}for(e in n)t._once_expired(e,n)&&(delete n[e],r++);r>0&&u.setItem(f,JSON.stringify(n))})}),o.prototype._once_expired=function(t,e){if(!e)return!0;if(!e.hasOwnProperty(t))return!0;if("object"!=
return!0}for(;a>f;){var h=t[f];if(this.debug("\nglobstar while",t,f,e,l,h),this.matchOne(t.slice(f),e.slice(l),n))return this.debug("globstar found match!",f,a,h),!0;if("."===h||".."===h||!r.dot&&"."===h.charAt(0)){this.debug("dot detected!",t,f,e,l);break}this.debug("globstar swallow a segment, and continue"),f++}return n&&(this.debug("\n>>> no match, partial?",t,f,e,l),f===a)?!0:!1}var p;if("string"==typeof u?(p=r.nocase?c.toLowerCase()===u.toLowerCase():c===u,this.debug("string match",u,c,p)):(p=c.match(u),this.debug("pattern match",u,c,p)),!p)return!1}if(i===a&&o===s)return!0;if(i===a)return n;if(o===s){var d=i===a-1&&""===t[i];return d}throw Error("wtf?")}},{"brace-expansion":12,path:10}],12:[function(t,e){function n(t){return parseInt(t,10)==t?parseInt(t,10):t.charCodeAt(0)}function r(t){return t.split("\\\\").join(d).split("\\{").join(g).split("\\}").join(v).split("\\,").join(m).split("\\.").join(E)}function i(t){return t.split(d).join("\\").split(g).join("{").split(v).join("}").split(m).join(",").split(E).join(".")}function o(t){if(!t)return[""];var e=[],n=p("{","}",t);if(!n)return t.split(",");var r=n.pre,i=n.body,a=n.post,s=r.split(",");s[s.length-1]+="{"+i+"}";var u=o(a);return a.length&&(s[s.length-1]+=u.shift(),s.push.apply(s,u)),e.push.apply(e,s),e}function a(t){return t?l(r(t),!0).map(i):[]}function s(t){return"{"+t+"}"}function u(t){return/^-?0\d/.test(t)}function c(t,e){return e>=t}function f(t,e){return t>=e}function l(t,e){var r=[],i=p("{","}",t);if(!i||/\$$/.test(i.pre))return[t];var a=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body),d=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body),g=a||d,m=/^(.*,)+(.+)?$/.test(i.body);if(!g&&!m)return i.post.match(/,.*}/)?(t=i.pre+"{"+i.body+v+i.post,l(t)):[t];var E;if(g)E=i.body.split(/\.\./);else if(E=o(i.body),1===E.length&&(E=l(E[0],!1).map(s),1===E.length)){var y=i.post.length?l(i.post,!1):[""];return y.map(function(t){return i.pre+E[0]+t})}var b,w=i.pre,y=i.post.length?l(i.post,!1):[""];if(g){var O=n(E[0]),I=n(E[1]),A=Math.max(E[0].length,E[1].length),T=3==E.length?Math.abs(n(E[2])):1,j=c,R=O>I;R&&(T*=-1,j=f);var S=E.some(u);b=[];for(var x=O;j(x,I);x+=T){var D;if(d)D=String.fromCharCode(x),"\\"===D&&(D="");else if(D=x+"",S){var _=A-D.length;if(_>0){var N=Array(_+1).join("0");D=0>x?"-"+N+D.slice(1):N+D}}b.push(D)}}else b=h(E,function(t){return l(t,!1)});for(var L=0;b.length>L;L++)for(var B=0;y.length>B;B++){var M=w+b[L]+y[B];(!e||g||M)&&r.push(M)}return r}var h=t("concat-map"),p=t("balanced-match");e.exports=a;var d="\0SLASH"+Math.random()+"\0",g="\0OPEN"+Math.random()+"\0",v="\0CLOSE"+Math.random()+"\0",m="\0COMMA"+Math.random()+"\0",E="\0PERIOD"+Math.random()+"\0"},{"balanced-match":13,"concat-map":14}],13:[function(t,e){function n(t,e,r){for(var i=0,o={},a=!1,s=0;r.length>s;s++)if(t==r.substr(s,t.length))"start"in o||(o.start=s),i++;else if(e==r.substr(s,e.length)&&"start"in o&&(a=!0,i--,!i))return o.end=s,o.pre=r.substr(0,o.start),o.body=o.end-o.start>1?r.substring(o.start+t.length,o.end):"",o.post=r.slice(o.end+e.length),o;if(i&&a){var u=o.start+t.length;return o=n(t,e,r.substr(u)),o&&(o.start+=u,o.end+=u,o.pre=r.slice(0,u)+o.pre),o}}e.exports=n},{}],14:[function(t,e){e.exports=function(t,e){for(var r=[],i=0;t.length>i;i++){var o=e(t[i],i);n(o)?r.push.apply(r,o):r.push(o)}return r};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],15:[function(t,e){(function(t){function n(e,n,r){return e instanceof ArrayBuffer&&(e=new Uint8Array(e)),new t(e,n,r)}n.prototype=Object.create(t.prototype),n.prototype.constructor=n,Object.keys(t).forEach(function(e){t.hasOwnProperty(e)&&(n[e]=t[e])}),e.exports=n}).call(this,t("buffer").Buffer)},{buffer:6}],16:[function(t,e){var n="READ",r="WRITE",i="CREATE",o="EXCLUSIVE",a="TRUNCATE",s="APPEND",u="CREATE",c="REPLACE";e.exports={FILE_SYSTEM_NAME:"local",FILE_STORE_NAME:"files",IDB_RO:"readonly",IDB_RW:"readwrite",WSQL_VERSION:"1",WSQL_SIZE:5242880,WSQL_DESC:"FileSystem Storage",MODE_FILE:"FILE",MODE_DIRECTORY:"DIRECTORY",MODE_SYMBOLIC_LINK:"SYMLINK",MODE_META:"META",SYMLOOP_MAX:10
};e.exports={normalize:o,resolve:i,join:a,relative:s,sep:"/",delimiter:":",dirname:u,basename:c,extname:f,isAbsolute:l,isNull:h,addTrailing:p,removeTrailing:d}},{}],27:[function(t,e){var n=t("./indexeddb.js"),r=t("./websql.js"),i=t("./memory.js");e.exports={IndexedDB:n,WebSQL:r,Memory:i,Default:n,Fallback:function(){function t(){throw"[Filer Error] Your browser doesn't support IndexedDB or WebSQL."}return n.isSupported()?n:r.isSupported()?r:(t.isSupported=function(){return!1},t)}()}},{"./indexeddb.js":28,"./memory.js":29,"./websql.js":30}],28:[function(t,e){(function(n,r){function i(t,e){var n=t.transaction(c,e);this.objectStore=n.objectStore(c)}function o(t,e,n){try{var r=t.get(e);r.onsuccess=function(t){var e=t.target.result;n(null,e)},r.onerror=function(t){n(t)}}catch(i){n(i)}}function a(t,e,n,r){try{var i=t.put(n,e);i.onsuccess=function(t){var e=t.target.result;r(null,e)},i.onerror=function(t){r(t)}}catch(o){r(o)}}function s(t){this.name=t||u,this.db=null}var u=t("../constants.js").FILE_SYSTEM_NAME,c=t("../constants.js").FILE_STORE_NAME,f=t("../constants.js").IDB_RW;t("../constants.js").IDB_RO;var l=t("../errors.js"),h=t("../buffer.js"),p=n.indexedDB||n.mozIndexedDB||n.webkitIndexedDB||n.msIndexedDB;i.prototype.clear=function(t){try{var e=this.objectStore.clear();e.onsuccess=function(){t()},e.onerror=function(e){t(e)}}catch(n){t(n)}},i.prototype.getObject=function(t,e){o(this.objectStore,t,e)},i.prototype.getBuffer=function(t,e){o(this.objectStore,t,function(t,n){return t?e(t):(e(null,new h(n)),void 0)})},i.prototype.putObject=function(t,e,n){a(this.objectStore,t,e,n)},i.prototype.putBuffer=function(t,e,n){var i;i=r._useTypedArrays?e.buffer:e.toArrayBuffer(),a(this.objectStore,t,i,n)},i.prototype.delete=function(t,e){try{var n=this.objectStore.delete(t);n.onsuccess=function(t){var n=t.target.result;e(null,n)},n.onerror=function(t){e(t)}}catch(r){e(r)}},s.isSupported=function(){return!!p},s.prototype.open=function(t){var e=this;if(e.db)return t();var n=p.open(e.name);n.onupgradeneeded=function(t){var e=t.target.result;e.objectStoreNames.contains(c)&&e.deleteObjectStore(c),e.createObjectStore(c)},n.onsuccess=function(n){e.db=n.target.result,t()},n.onerror=function(){t(new l.EINVAL("IndexedDB cannot be accessed. If private browsing is enabled, disable it."))}},s.prototype.getReadOnlyContext=function(){return new i(this.db,f)},s.prototype.getReadWriteContext=function(){return new i(this.db,f)},e.exports=s}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},t("buffer").Buffer)},{"../buffer.js":15,"../constants.js":16,"../errors.js":19,buffer:6}],29:[function(t,e){function n(t,e){this.readOnly=e,this.objectStore=t}function r(t){this.name=t||i}var i=t("../constants.js").FILE_SYSTEM_NAME,o=t("../../lib/async.js").setImmediate,a=function(){var t={};return function(e){return t.hasOwnProperty(e)||(t[e]={}),t[e]}}();n.prototype.clear=function(t){if(this.readOnly)return o(function(){t("[MemoryContext] Error: write operation on read only context")}),void 0;var e=this.objectStore;Object.keys(e).forEach(function(t){delete e[t]}),o(t)},n.prototype.getObject=n.prototype.getBuffer=function(t,e){var n=this;o(function(){e(null,n.objectStore[t])})},n.prototype.putObject=n.prototype.putBuffer=function(t,e,n){return this.readOnly?(o(function(){n("[MemoryContext] Error: write operation on read only context")}),void 0):(this.objectStore[t]=e,o(n),void 0)},n.prototype.delete=function(t,e){return this.readOnly?(o(function(){e("[MemoryContext] Error: write operation on read only context")}),void 0):(delete this.objectStore[t],o(e),void 0)},r.isSupported=function(){return!0},r.prototype.open=function(t){this.db=a(this.name),o(t)},r.prototype.getReadOnlyContext=function(){return new n(this.db,!0)},r.prototype.getReadWriteContext=function(){return new n(this.db,!1)},e.exports=r},{"../../lib/async.js":1,"../constants.js":16}],30:[function(t,e){(function(n){function r(t,e){var n=this;this.getTransaction=function(r){return n.transaction?(r(n.transaction),void 0):(t[e?"readTransaction":"transaction"](function(t){n.transactio