mirror of
https://github.com/moparisthebest/mail
synced 2025-01-30 22:50:17 -05:00
upgrade several js libs
This commit is contained in:
parent
558ac6153d
commit
8cfd6ea0a6
@ -12,7 +12,7 @@
|
||||
<script src="lib/cordova-2.5.0.js"></script>
|
||||
<script src="lib/jquery-1.8.2.min.js"></script>
|
||||
<script src="lib/underscore-1.4.4.min.js"></script>
|
||||
<script src="lib/backbone-0.9.10.min.js"></script>
|
||||
<script src="lib/backbone-1.0.0.min.js"></script>
|
||||
<script src="js/jqm-config.js"></script>
|
||||
<script src="lib/jquery.mobile-1.2.0.min.js"></script>
|
||||
<script src="lib/lawnchair/lawnchair-git.min.js"></script>
|
||||
|
42
src/lib/backbone-0.9.10.min.js
vendored
42
src/lib/backbone-0.9.10.min.js
vendored
@ -1,42 +0,0 @@
|
||||
// Backbone.js 0.9.10
|
||||
|
||||
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
||||
// Backbone may be freely distributed under the MIT license.
|
||||
// For all details and documentation:
|
||||
// http://backbonejs.org
|
||||
(function(){var n=this,B=n.Backbone,h=[],C=h.push,u=h.slice,D=h.splice,g;g="undefined"!==typeof exports?exports:n.Backbone={};g.VERSION="0.9.10";var f=n._;!f&&"undefined"!==typeof require&&(f=require("underscore"));g.$=n.jQuery||n.Zepto||n.ender;g.noConflict=function(){n.Backbone=B;return this};g.emulateHTTP=!1;g.emulateJSON=!1;var v=/\s+/,q=function(a,b,c,d){if(!c)return!0;if("object"===typeof c)for(var e in c)a[b].apply(a,[e,c[e]].concat(d));else if(v.test(c)){c=c.split(v);e=0;for(var f=c.length;e<
|
||||
f;e++)a[b].apply(a,[c[e]].concat(d))}else return!0},w=function(a,b){var c,d=-1,e=a.length;switch(b.length){case 0:for(;++d<e;)(c=a[d]).callback.call(c.ctx);break;case 1:for(;++d<e;)(c=a[d]).callback.call(c.ctx,b[0]);break;case 2:for(;++d<e;)(c=a[d]).callback.call(c.ctx,b[0],b[1]);break;case 3:for(;++d<e;)(c=a[d]).callback.call(c.ctx,b[0],b[1],b[2]);break;default:for(;++d<e;)(c=a[d]).callback.apply(c.ctx,b)}},h=g.Events={on:function(a,b,c){if(!q(this,"on",a,[b,c])||!b)return this;this._events||(this._events=
|
||||
{});(this._events[a]||(this._events[a]=[])).push({callback:b,context:c,ctx:c||this});return this},once:function(a,b,c){if(!q(this,"once",a,[b,c])||!b)return this;var d=this,e=f.once(function(){d.off(a,e);b.apply(this,arguments)});e._callback=b;this.on(a,e,c);return this},off:function(a,b,c){var d,e,t,g,j,l,k,h;if(!this._events||!q(this,"off",a,[b,c]))return this;if(!a&&!b&&!c)return this._events={},this;g=a?[a]:f.keys(this._events);j=0;for(l=g.length;j<l;j++)if(a=g[j],d=this._events[a]){t=[];if(b||
|
||||
c){k=0;for(h=d.length;k<h;k++)e=d[k],(b&&b!==e.callback&&b!==e.callback._callback||c&&c!==e.context)&&t.push(e)}this._events[a]=t}return this},trigger:function(a){if(!this._events)return this;var b=u.call(arguments,1);if(!q(this,"trigger",a,b))return this;var c=this._events[a],d=this._events.all;c&&w(c,b);d&&w(d,arguments);return this},listenTo:function(a,b,c){var d=this._listeners||(this._listeners={}),e=a._listenerId||(a._listenerId=f.uniqueId("l"));d[e]=a;a.on(b,"object"===typeof b?this:c,this);
|
||||
return this},stopListening:function(a,b,c){var d=this._listeners;if(d){if(a)a.off(b,"object"===typeof b?this:c,this),!b&&!c&&delete d[a._listenerId];else{"object"===typeof b&&(c=this);for(var e in d)d[e].off(b,c,this);this._listeners={}}return this}}};h.bind=h.on;h.unbind=h.off;f.extend(g,h);var r=g.Model=function(a,b){var c,d=a||{};this.cid=f.uniqueId("c");this.attributes={};b&&b.collection&&(this.collection=b.collection);b&&b.parse&&(d=this.parse(d,b)||{});if(c=f.result(this,"defaults"))d=f.defaults({},
|
||||
d,c);this.set(d,b);this.changed={};this.initialize.apply(this,arguments)};f.extend(r.prototype,h,{changed:null,idAttribute:"id",initialize:function(){},toJSON:function(){return f.clone(this.attributes)},sync:function(){return g.sync.apply(this,arguments)},get:function(a){return this.attributes[a]},escape:function(a){return f.escape(this.get(a))},has:function(a){return null!=this.get(a)},set:function(a,b,c){var d,e,g,p,j,l,k;if(null==a)return this;"object"===typeof a?(e=a,c=b):(e={})[a]=b;c||(c={});
|
||||
if(!this._validate(e,c))return!1;g=c.unset;p=c.silent;a=[];j=this._changing;this._changing=!0;j||(this._previousAttributes=f.clone(this.attributes),this.changed={});k=this.attributes;l=this._previousAttributes;this.idAttribute in e&&(this.id=e[this.idAttribute]);for(d in e)b=e[d],f.isEqual(k[d],b)||a.push(d),f.isEqual(l[d],b)?delete this.changed[d]:this.changed[d]=b,g?delete k[d]:k[d]=b;if(!p){a.length&&(this._pending=!0);b=0;for(d=a.length;b<d;b++)this.trigger("change:"+a[b],this,k[a[b]],c)}if(j)return this;
|
||||
if(!p)for(;this._pending;)this._pending=!1,this.trigger("change",this,c);this._changing=this._pending=!1;return this},unset:function(a,b){return this.set(a,void 0,f.extend({},b,{unset:!0}))},clear:function(a){var b={},c;for(c in this.attributes)b[c]=void 0;return this.set(b,f.extend({},a,{unset:!0}))},hasChanged:function(a){return null==a?!f.isEmpty(this.changed):f.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?f.clone(this.changed):!1;var b,c=!1,d=this._changing?
|
||||
this._previousAttributes:this.attributes,e;for(e in a)if(!f.isEqual(d[e],b=a[e]))(c||(c={}))[e]=b;return c},previous:function(a){return null==a||!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},fetch:function(a){a=a?f.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=a.success;a.success=function(a,d,e){if(!a.set(a.parse(d,e),e))return!1;b&&b(a,d,e)};return this.sync("read",this,a)},save:function(a,b,c){var d,e,g=this.attributes;
|
||||
null==a||"object"===typeof a?(d=a,c=b):(d={})[a]=b;if(d&&(!c||!c.wait)&&!this.set(d,c))return!1;c=f.extend({validate:!0},c);if(!this._validate(d,c))return!1;d&&c.wait&&(this.attributes=f.extend({},g,d));void 0===c.parse&&(c.parse=!0);e=c.success;c.success=function(a,b,c){a.attributes=g;var k=a.parse(b,c);c.wait&&(k=f.extend(d||{},k));if(f.isObject(k)&&!a.set(k,c))return!1;e&&e(a,b,c)};a=this.isNew()?"create":c.patch?"patch":"update";"patch"===a&&(c.attrs=d);a=this.sync(a,this,c);d&&c.wait&&(this.attributes=
|
||||
g);return a},destroy:function(a){a=a?f.clone(a):{};var b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};a.success=function(a,b,e){(e.wait||a.isNew())&&d();c&&c(a,b,e)};if(this.isNew())return a.success(this,null,a),!1;var e=this.sync("delete",this,a);a.wait||d();return e},url:function(){var a=f.result(this,"urlRoot")||f.result(this.collection,"url")||x();return this.isNew()?a:a+("/"===a.charAt(a.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},
|
||||
isNew:function(){return null==this.id},isValid:function(a){return!this.validate||!this.validate(this.attributes,a)},_validate:function(a,b){if(!b.validate||!this.validate)return!0;a=f.extend({},this.attributes,a);var c=this.validationError=this.validate(a,b)||null;if(!c)return!0;this.trigger("invalid",this,c,b||{});return!1}});var s=g.Collection=function(a,b){b||(b={});b.model&&(this.model=b.model);void 0!==b.comparator&&(this.comparator=b.comparator);this.models=[];this._reset();this.initialize.apply(this,
|
||||
arguments);a&&this.reset(a,f.extend({silent:!0},b))};f.extend(s.prototype,h,{model:r,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},sync:function(){return g.sync.apply(this,arguments)},add:function(a,b){a=f.isArray(a)?a.slice():[a];b||(b={});var c,d,e,g,p,j,l,k,h,m;l=[];k=b.at;h=this.comparator&&null==k&&!1!=b.sort;m=f.isString(this.comparator)?this.comparator:null;c=0;for(d=a.length;c<d;c++)(e=this._prepareModel(g=a[c],b))?(p=this.get(e))?b.merge&&(p.set(g===
|
||||
e?e.attributes:g,b),h&&(!j&&p.hasChanged(m))&&(j=!0)):(l.push(e),e.on("all",this._onModelEvent,this),this._byId[e.cid]=e,null!=e.id&&(this._byId[e.id]=e)):this.trigger("invalid",this,g,b);l.length&&(h&&(j=!0),this.length+=l.length,null!=k?D.apply(this.models,[k,0].concat(l)):C.apply(this.models,l));j&&this.sort({silent:!0});if(b.silent)return this;c=0;for(d=l.length;c<d;c++)(e=l[c]).trigger("add",e,this,b);j&&this.trigger("sort",this,b);return this},remove:function(a,b){a=f.isArray(a)?a.slice():[a];
|
||||
b||(b={});var c,d,e,g;c=0;for(d=a.length;c<d;c++)if(g=this.get(a[c]))delete this._byId[g.id],delete this._byId[g.cid],e=this.indexOf(g),this.models.splice(e,1),this.length--,b.silent||(b.index=e,g.trigger("remove",g,this,b)),this._removeReference(g);return this},push:function(a,b){a=this._prepareModel(a,b);this.add(a,f.extend({at:this.length},b));return a},pop:function(a){var b=this.at(this.length-1);this.remove(b,a);return b},unshift:function(a,b){a=this._prepareModel(a,b);this.add(a,f.extend({at:0},
|
||||
b));return a},shift:function(a){var b=this.at(0);this.remove(b,a);return b},slice:function(a,b){return this.models.slice(a,b)},get:function(a){if(null!=a)return this._idAttr||(this._idAttr=this.model.prototype.idAttribute),this._byId[a.id||a.cid||a[this._idAttr]||a]},at:function(a){return this.models[a]},where:function(a){return f.isEmpty(a)?[]:this.filter(function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){if(!this.comparator)throw Error("Cannot sort a set without a comparator");
|
||||
a||(a={});f.isString(this.comparator)||1===this.comparator.length?this.models=this.sortBy(this.comparator,this):this.models.sort(f.bind(this.comparator,this));a.silent||this.trigger("sort",this,a);return this},pluck:function(a){return f.invoke(this.models,"get",a)},update:function(a,b){b=f.extend({add:!0,merge:!0,remove:!0},b);b.parse&&(a=this.parse(a,b));var c,d,e,g,h=[],j=[],l={};f.isArray(a)||(a=a?[a]:[]);if(b.add&&!b.remove)return this.add(a,b);d=0;for(e=a.length;d<e;d++)c=a[d],g=this.get(c),
|
||||
b.remove&&g&&(l[g.cid]=!0),(b.add&&!g||b.merge&&g)&&h.push(c);if(b.remove){d=0;for(e=this.models.length;d<e;d++)c=this.models[d],l[c.cid]||j.push(c)}j.length&&this.remove(j,b);h.length&&this.add(h,b);return this},reset:function(a,b){b||(b={});b.parse&&(a=this.parse(a,b));for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);b.previousModels=this.models.slice();this._reset();a&&this.add(a,f.extend({silent:!0},b));b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a=
|
||||
a?f.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=a.success;a.success=function(a,d,e){a[e.update?"update":"reset"](d,e);b&&b(a,d,e)};return this.sync("read",this,a)},create:function(a,b){b=b?f.clone(b):{};if(!(a=this._prepareModel(a,b)))return!1;b.wait||this.add(a,b);var c=this,d=b.success;b.success=function(a,b,f){f.wait&&c.add(a,f);d&&d(a,b,f)};a.save(null,b);return a},parse:function(a){return a},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0;this.models.length=
|
||||
0;this._byId={}},_prepareModel:function(a,b){if(a instanceof r)return a.collection||(a.collection=this),a;b||(b={});b.collection=this;var c=new this.model(a,b);return!c._validate(a,b)?!1:c},_removeReference:function(a){this===a.collection&&delete a.collection;a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"===a||"remove"===a)&&c!==this||("destroy"===a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],null!=b.id&&(this._byId[b.id]=
|
||||
b)),this.trigger.apply(this,arguments))},sortedIndex:function(a,b,c){b||(b=this.comparator);var d=f.isFunction(b)?b:function(a){return a.get(b)};return f.sortedIndex(this.models,a,d,c)}});f.each("forEach each map collect reduce foldl inject reduceRight foldr find detect filter select reject every all some any include contains invoke max min toArray size first head take initial rest tail drop last without indexOf shuffle lastIndexOf isEmpty chain".split(" "),function(a){s.prototype[a]=function(){var b=
|
||||
u.call(arguments);b.unshift(this.models);return f[a].apply(f,b)}});f.each(["groupBy","countBy","sortBy"],function(a){s.prototype[a]=function(b,c){var d=f.isFunction(b)?b:function(a){return a.get(b)};return f[a](this.models,d,c)}});var y=g.Router=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize.apply(this,arguments)},E=/\((.*?)\)/g,F=/(\(\?)?:\w+/g,G=/\*\w+/g,H=/[\-{}\[\]+?.,\\\^$|#\s]/g;f.extend(y.prototype,h,{initialize:function(){},route:function(a,b,c){f.isRegExp(a)||
|
||||
(a=this._routeToRegExp(a));c||(c=this[b]);g.history.route(a,f.bind(function(d){d=this._extractParameters(a,d);c&&c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d));this.trigger("route",b,d);g.history.trigger("route",this,b,d)},this));return this},navigate:function(a,b){g.history.navigate(a,b);return this},_bindRoutes:function(){if(this.routes)for(var a,b=f.keys(this.routes);null!=(a=b.pop());)this.route(a,this.routes[a])},_routeToRegExp:function(a){a=a.replace(H,"\\$&").replace(E,"(?:$1)?").replace(F,
|
||||
function(a,c){return c?a:"([^/]+)"}).replace(G,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});var m=g.History=function(){this.handlers=[];f.bindAll(this,"checkUrl");"undefined"!==typeof window&&(this.location=window.location,this.history=window.history)},z=/^[#\/]|\s+$/g,I=/^\/+|\/+$/g,J=/msie [\w.]+/,K=/\/$/;m.started=!1;f.extend(m.prototype,h,{interval:50,getHash:function(a){return(a=(a||this).location.href.match(/#(.*)$/))?a[1]:""},getFragment:function(a,
|
||||
b){if(null==a)if(this._hasPushState||!this._wantsHashChange||b){a=this.location.pathname;var c=this.root.replace(K,"");a.indexOf(c)||(a=a.substr(c.length))}else a=this.getHash();return a.replace(z,"")},start:function(a){if(m.started)throw Error("Backbone.history has already been started");m.started=!0;this.options=f.extend({},{root:"/"},this.options,a);this.root=this.options.root;this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=!(!this.options.pushState||
|
||||
!this.history||!this.history.pushState);a=this.getFragment();var b=document.documentMode,b=J.exec(navigator.userAgent.toLowerCase())&&(!b||7>=b);this.root=("/"+this.root+"/").replace(I,"/");b&&this._wantsHashChange&&(this.iframe=g.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a));if(this._hasPushState)g.$(window).on("popstate",this.checkUrl);else if(this._wantsHashChange&&"onhashchange"in window&&!b)g.$(window).on("hashchange",this.checkUrl);
|
||||
else this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval));this.fragment=a;a=this.location;b=a.pathname.replace(/[^\/]$/,"$&/")===this.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),this.location.replace(this.root+this.location.search+"#"+this.fragment),!0;this._wantsPushState&&(this._hasPushState&&b&&a.hash)&&(this.fragment=this.getHash().replace(z,""),this.history.replaceState({},document.title,
|
||||
this.root+this.fragment+a.search));if(!this.options.silent)return this.loadUrl()},stop:function(){g.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);m.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a===this.fragment&&this.iframe&&(a=this.getFragment(this.getHash(this.iframe)));if(a===this.fragment)return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(this.getHash())},
|
||||
loadUrl:function(a){var b=this.fragment=this.getFragment(a);return f.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){if(!m.started)return!1;if(!b||!0===b)b={trigger:b};a=this.getFragment(a||"");if(this.fragment!==a){this.fragment=a;var c=this.root+a;if(this._hasPushState)this.history[b.replace?"replaceState":"pushState"]({},document.title,c);else if(this._wantsHashChange)this._updateHash(this.location,a,b.replace),this.iframe&&a!==this.getFragment(this.getHash(this.iframe))&&
|
||||
(b.replace||this.iframe.document.open().close(),this._updateHash(this.iframe.location,a,b.replace));else return this.location.assign(c);b.trigger&&this.loadUrl(a)}},_updateHash:function(a,b,c){c?(c=a.href.replace(/(javascript:|#).*$/,""),a.replace(c+"#"+b)):a.hash="#"+b}});g.history=new m;var A=g.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()},L=/^(\S+)\s*(.*)$/,M="model collection el id attributes className tagName events".split(" ");
|
||||
f.extend(A.prototype,h,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();this.stopListening();return this},setElement:function(a,b){this.$el&&this.undelegateEvents();this.$el=a instanceof g.$?a:g.$(a);this.el=this.$el[0];!1!==b&&this.delegateEvents();return this},delegateEvents:function(a){if(a||(a=f.result(this,"events"))){this.undelegateEvents();for(var b in a){var c=a[b];f.isFunction(c)||(c=this[a[b]]);
|
||||
if(!c)throw Error('Method "'+a[b]+'" does not exist');var d=b.match(L),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);if(""===d)this.$el.on(e,c);else this.$el.on(e,d,c)}}},undelegateEvents:function(){this.$el.off(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},f.result(this,"options"),a));f.extend(this,f.pick(a,M));this.options=a},_ensureElement:function(){if(this.el)this.setElement(f.result(this,"el"),!1);else{var a=f.extend({},f.result(this,"attributes"));
|
||||
this.id&&(a.id=f.result(this,"id"));this.className&&(a["class"]=f.result(this,"className"));a=g.$("<"+f.result(this,"tagName")+">").attr(a);this.setElement(a,!1)}}});var N={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};g.sync=function(a,b,c){var d=N[a];f.defaults(c||(c={}),{emulateHTTP:g.emulateHTTP,emulateJSON:g.emulateJSON});var e={type:d,dataType:"json"};c.url||(e.url=f.result(b,"url")||x());if(null==c.data&&b&&("create"===a||"update"===a||"patch"===a))e.contentType="application/json",
|
||||
e.data=JSON.stringify(c.attrs||b.toJSON(c));c.emulateJSON&&(e.contentType="application/x-www-form-urlencoded",e.data=e.data?{model:e.data}:{});if(c.emulateHTTP&&("PUT"===d||"DELETE"===d||"PATCH"===d)){e.type="POST";c.emulateJSON&&(e.data._method=d);var h=c.beforeSend;c.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d);if(h)return h.apply(this,arguments)}}"GET"!==e.type&&!c.emulateJSON&&(e.processData=!1);var m=c.success;c.success=function(a){m&&m(b,a,c);b.trigger("sync",b,a,c)};
|
||||
var j=c.error;c.error=function(a){j&&j(b,a,c);b.trigger("error",b,a,c)};a=c.xhr=g.ajax(f.extend(e,c));b.trigger("request",b,a,c);return a};g.ajax=function(){return g.$.ajax.apply(g.$,arguments)};r.extend=s.extend=y.extend=A.extend=m.extend=function(a,b){var c=this,d;d=a&&f.has(a,"constructor")?a.constructor:function(){return c.apply(this,arguments)};f.extend(d,c,b);var e=function(){this.constructor=d};e.prototype=c.prototype;d.prototype=new e;a&&f.extend(d.prototype,a);d.__super__=c.prototype;return d};
|
||||
var x=function(){throw Error('A "url" property or function must be specified');}}).call(this);
|
@ -59,7 +59,7 @@ Lawnchair.adapter('webkit-sqlite', (function () {
|
||||
// you think thats air you're breathing now?
|
||||
save: function (obj, callback, error) {
|
||||
var that = this
|
||||
objs = (this.isArray(obj) ? obj : [obj]).map(function(o){if(!o.key) { o.key = that.uuid()} return o})
|
||||
, objs = (this.isArray(obj) ? obj : [obj]).map(function(o){if(!o.key) { o.key = that.uuid()} return o})
|
||||
, ins = "INSERT OR REPLACE INTO " + this.record + " (value, timestamp, id) VALUES (?,?,?)"
|
||||
, win = function () { if (callback) { that.lambda(callback).call(that, that.isArray(obj)?objs:objs[0]) }}
|
||||
, error= error || function() {}
|
||||
|
16
src/lib/lawnchair/lawnchair-git.min.js
vendored
16
src/lib/lawnchair/lawnchair-git.min.js
vendored
@ -1,14 +1,14 @@
|
||||
var Lawnchair=function(e,h){if(!(this instanceof Lawnchair))return new Lawnchair(e,h);if(!JSON)throw"JSON unavailable! Include http://www.json.org/json2.js to fix.";if(arguments.length<=2&&arguments.length>0){h=typeof arguments[0]==="function"?arguments[0]:arguments[1];e=typeof arguments[0]==="function"?{}:arguments[0]}else throw"Incorrect # of ctor args!";if(typeof h!=="function")throw"No callback was provided";this.record=e.record||"record";this.name=e.name||"records";var a;if(e.adapter){if(typeof e.adapter===
|
||||
"string")e.adapter=[e.adapter];for(var b=0,c=e.adapter.length;b<c;b++){for(var d=Lawnchair.adapters.length-1;d>=0;d--)if(Lawnchair.adapters[d].adapter===e.adapter[b])if(a=Lawnchair.adapters[d].valid()?Lawnchair.adapters[d]:undefined)break;if(a)break}}else{d=0;for(c=Lawnchair.adapters.length;d<c;d++)if(a=Lawnchair.adapters[d].valid()?Lawnchair.adapters[d]:undefined)break}if(!a)throw"No valid adapter.";for(b in a)this[b]=a[b];d=0;for(c=Lawnchair.plugins.length;d<c;d++)Lawnchair.plugins[d].call(this);
|
||||
this.init(e,h)};Lawnchair.adapters=[];Lawnchair.adapter=function(e,h){h.adapter=e;var a="adapter valid init keys save batch get exists all remove nuke".split(" "),b=this.prototype.indexOf,c;for(c in h)if(b(a,c)===-1)throw"Invalid adapter! Nonstandard method: "+c;Lawnchair.adapters.splice(0,0,h)};Lawnchair.plugins=[];Lawnchair.plugin=function(e){for(var h in e)h==="init"?Lawnchair.plugins.push(e[h]):this.prototype[h]=e[h]};
|
||||
var Lawnchair=function(e,h){if(!(this instanceof Lawnchair))return new Lawnchair(e,h);if(!JSON)throw"JSON unavailable! Include http://www.json.org/json2.js to fix.";if(arguments.length<=2){h=typeof arguments[0]==="function"?arguments[0]:arguments[1];e=typeof arguments[0]==="function"?{}:arguments[0]||{}}else throw"Incorrect # of ctor args!";this.record=e.record||"record";this.name=e.name||"records";var a;if(e.adapter){if(typeof e.adapter==="string")e.adapter=[e.adapter];for(var b=0,c=e.adapter.length;b<
|
||||
c;b++){for(var d=Lawnchair.adapters.length-1;d>=0;d--)if(Lawnchair.adapters[d].adapter===e.adapter[b])if(a=Lawnchair.adapters[d].valid()?Lawnchair.adapters[d]:undefined)break;if(a)break}}else{d=0;for(c=Lawnchair.adapters.length;d<c;d++)if(a=Lawnchair.adapters[d].valid()?Lawnchair.adapters[d]:undefined)break}if(!a)throw"No valid adapter.";for(b in a)this[b]=a[b];d=0;for(c=Lawnchair.plugins.length;d<c;d++)Lawnchair.plugins[d].call(this);this.init(e,h)};Lawnchair.adapters=[];
|
||||
Lawnchair.adapter=function(e,h){h.adapter=e;var a="adapter valid init keys save batch get exists all remove nuke".split(" "),b=this.prototype.indexOf,c;for(c in h)if(b(a,c)===-1)throw"Invalid adapter! Nonstandard method: "+c;Lawnchair.adapters.splice(0,0,h)};Lawnchair.plugins=[];Lawnchair.plugin=function(e){for(var h in e)h==="init"?Lawnchair.plugins.push(e[h]):this.prototype[h]=e[h]};
|
||||
Lawnchair.prototype={isArray:Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"},indexOf:function(e,h,a,b){if(e.indexOf)return e.indexOf(h);a=0;for(b=e.length;a<b;a++)if(e[a]===h)return a;return-1},lambda:function(e){return this.fn(this.record,e)},fn:function(e,h){return typeof h=="string"?new Function(e,h):h},uuid:function(){var e=function(){return((1+Math.random())*65536|0).toString(16).substring(1)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},each:function(e){var h=
|
||||
this.lambda(e);if(this.__results){e=0;for(var a=this.__results.length;e<a;e++)h.call(this,this.__results[e],e)}else this.all(function(b){for(var c=0,d=b.length;c<d;c++)h.call(this,b[c],c)});return this}};
|
||||
Lawnchair.adapter("window-name",function(){if(typeof window==="undefined")window={top:{}};var e={};try{e=JSON.parse(window.top.name)}catch(h){}return{valid:function(){return typeof window.top.name!="undefined"},init:function(a,b){e[this.name]=e[this.name]||{index:[],store:{}};this.index=e[this.name].index;this.store=e[this.name].store;this.fn(this.name,b).call(this,this);return this},keys:function(a){this.fn("keys",a).call(this,this.index);return this},save:function(a,b){var c=a.key||this.uuid();
|
||||
this.exists(c,function(d){if(!d){a.key&&delete a.key;this.index.push(c)}this.store[c]=a;try{window.top.name=JSON.stringify(e)}catch(g){if(!d){this.index.pop();delete this.store[c]}throw g;}if(b){a.key=c;this.lambda(b).call(this,a)}});return this},batch:function(a,b){for(var c=[],d=0,g=a.length;d<g;d++)this.save(a[d],function(f){c.push(f)});b&&this.lambda(b).call(this,c);return this},get:function(a,b){var c;if(this.isArray(a)){c=[];for(var d=0,g=a.length;d<g;d++)c.push(this.store[a[d]])}else if(c=
|
||||
this.store[a])c.key=a;b&&this.lambda(b).call(this,c);return this},exists:function(a,b){this.lambda(b).call(this,!!this.store[a]);return this},all:function(a){for(var b=[],c=0,d=this.index.length;c<d;c++){var g=this.store[this.index[c]];g.key=this.index[c];b.push(g)}this.fn(this.name,a).call(this,b);return this},remove:function(a,b){for(var c=this.isArray(a)?a:[a],d=0,g=c.length;d<g;d++){var f=c[d].key?c[d].key:c[d],i=this.indexOf(this.index,f);if(!(i<0)){delete this.store[f];this.index.splice(i,1)}}window.top.name=
|
||||
JSON.stringify(e);b&&this.lambda(b).call(this);return this},nuke:function(a){this.store=e[this.name].store={};this.index=e[this.name].index=[];window.top.name=JSON.stringify(e);a&&this.lambda(a).call(this);return this}}}());
|
||||
Lawnchair.adapter("dom",function(){var e=window.localStorage,h=function(a){return{key:a+"._index_",all:function(){var b=e.getItem(this.key);if(b)b=JSON.parse(b);b===null&&e.setItem(this.key,JSON.stringify([]));return JSON.parse(e.getItem(this.key))},add:function(b){var c=this.all();c.push(b);e.setItem(this.key,JSON.stringify(c))},del:function(b){for(var c=this.all(),d=[],g=0,f=c.length;g<f;g++)c[g]!=b&&d.push(c[g]);e.setItem(this.key,JSON.stringify(d))},find:function(b){for(var c=this.all(),d=0,g=
|
||||
c.length;d<g;d++)if(b===c[d])return d;return false}}};return{valid:function(){return!!e&&function(){var a=true,b=Math.random();try{e.setItem(b,b)}catch(c){a=false}e.removeItem(b);return a}()},init:function(a,b){this.indexer=h(this.name);b&&this.fn(this.name,b).call(this,this)},save:function(a,b){var c=a.key?this.name+"."+a.key:this.name+"."+this.uuid();delete a.key;e.setItem(c,JSON.stringify(a));this.indexer.find(c)===false&&this.indexer.add(c);a.key=c.slice(this.name.length+1);b&&this.lambda(b).call(this,
|
||||
a);return this},batch:function(a,b){for(var c=[],d=0,g=a.length;d<g;d++)this.save(a[d],function(f){c.push(f)});b&&this.lambda(b).call(this,c);return this},keys:function(a){if(a){var b=this.name,c=this.indexer.all(),d=[];if(Array.prototype.map)d=c.map(function(f){return f.replace(b+".","")});else for(var g in c)d.push(g.replace(b+".",""));this.fn("keys",a).call(this,d)}return this},get:function(a,b){if(this.isArray(a)){for(var c=[],d=0,g=a.length;d<g;d++){var f=this.name+"."+a[d];if(f=e.getItem(f)){f=
|
||||
JSON.parse(f);f.key=a[d]}c.push(f)}b&&this.lambda(b).call(this,c)}else{f=this.name+"."+a;if(f=e.getItem(f)){f=JSON.parse(f);f.key=a}b&&this.lambda(b).call(this,f)}return this},exists:function(a,b){var c=this.indexer.find(this.name+"."+a)===false?false:true;this.lambda(b).call(this,c);return this},all:function(a){for(var b=this.indexer.all(),c=[],d,g,f=0,i=b.length;f<i;f++){g=b[f];d=JSON.parse(e.getItem(g));d.key=g.replace(this.name+".","");c.push(d)}a&&this.fn(this.name,a).call(this,c);return this},
|
||||
remove:function(a,b){var c=this;if(this.isArray(a)){var d,g=a.length,f=function(i){c.remove(a[i],function(){--g>0||b&&c.lambda(b).call(c)})};for(d=0;d<a.length;d++)f(d);return this}d=this.name+"."+(a.key?a.key:a);this.indexer.del(d);e.removeItem(d);b&&this.lambda(b).call(this);return this},nuke:function(a){this.all(function(b){for(var c=0,d=b.length;c<d;c++)this.remove(b[c]);a&&this.lambda(a).call(this)});return this}}}());
|
||||
Lawnchair.adapter("dom",function(){var e=window.localStorage,h=function(a){return{key:a+"._index_",all:function(){var b=e.getItem(JSON.stringify(this.key));if(b)b=JSON.parse(b);b===null&&e.setItem(JSON.stringify(this.key),JSON.stringify([]));return JSON.parse(e.getItem(JSON.stringify(this.key)))},add:function(b){var c=this.all();c.push(b);e.setItem(JSON.stringify(this.key),JSON.stringify(c))},del:function(b){for(var c=this.all(),d=[],g=0,f=c.length;g<f;g++)c[g]!=b&&d.push(c[g]);e.setItem(JSON.stringify(this.key),
|
||||
JSON.stringify(d))},find:function(b){for(var c=this.all(),d=0,g=c.length;d<g;d++)if(b===c[d])return d;return false}}};return{valid:function(){return!!e&&function(){var a=true,b=Math.random();try{e.setItem(b,b)}catch(c){a=false}e.removeItem(b);return a}()},init:function(a,b){this.indexer=h(this.name);b&&this.fn(this.name,b).call(this,this)},save:function(a,b){var c=a.key?this.name+"."+a.key:this.name+"."+this.uuid();delete a.key;e.setItem(c,JSON.stringify(a));this.indexer.find(c)===false&&this.indexer.add(c);
|
||||
a.key=c.slice(this.name.length+1);b&&this.lambda(b).call(this,a);return this},batch:function(a,b){for(var c=[],d=0,g=a.length;d<g;d++)this.save(a[d],function(f){c.push(f)});b&&this.lambda(b).call(this,c);return this},keys:function(a){if(a){var b=this.name,c=this.indexer.all(),d=[];if(Array.prototype.map)d=c.map(function(f){return f.replace(b+".","")});else for(var g in c)d.push(g.replace(b+".",""));this.fn("keys",a).call(this,d)}return this},get:function(a,b){if(this.isArray(a)){for(var c=[],d=0,
|
||||
g=a.length;d<g;d++){var f=this.name+"."+a[d];if(f=e.getItem(f)){f=JSON.parse(f);f.key=a[d]}c.push(f)}b&&this.lambda(b).call(this,c)}else{f=this.name+"."+a;if(f=e.getItem(f)){f=JSON.parse(f);f.key=a}b&&this.lambda(b).call(this,f)}return this},exists:function(a,b){var c=this.indexer.find(this.name+"."+a)===false?false:true;this.lambda(b).call(this,c);return this},all:function(a){for(var b=this.indexer.all(),c=[],d,g,f=0,i=b.length;f<i;f++){g=b[f];d=JSON.parse(e.getItem(g));d.key=g.replace(this.name+
|
||||
".","");c.push(d)}a&&this.fn(this.name,a).call(this,c);return this},remove:function(a,b){var c=this;if(this.isArray(a)){var d,g=a.length,f=function(i){c.remove(a[i],function(){--g>0||b&&c.lambda(b).call(c)})};for(d=0;d<a.length;d++)f(d);return this}d=this.name+"."+(a.key?a.key:a);this.indexer.del(d);e.removeItem(d);b&&this.lambda(b).call(this);return this},nuke:function(a){this.all(function(b){for(var c=0,d=b.length;c<d;c++)this.remove(b[c]);a&&this.lambda(a).call(this)});return this}}}());
|
||||
|
114
src/lib/uuid.js
114
src/lib/uuid.js
@ -1,55 +1,52 @@
|
||||
// node-uuid/uuid.js
|
||||
// uuid.js
|
||||
//
|
||||
// Copyright (c) 2010 Robert Kieffer
|
||||
// Dual licensed under the MIT and GPL licenses.
|
||||
// Documentation and details at https://github.com/broofa/node-uuid
|
||||
// (c) 2010-2012 Robert Kieffer
|
||||
// MIT License
|
||||
// https://github.com/broofa/node-uuid
|
||||
(function() {
|
||||
var _global = this;
|
||||
|
||||
// Unique ID creation requires a high quality random # generator, but
|
||||
// Math.random() does not guarantee "cryptographic quality". So we feature
|
||||
// detect for more robust APIs, normalizing each method to return 128-bits
|
||||
// (16 bytes) of random data.
|
||||
var mathRNG, nodeRNG, whatwgRNG;
|
||||
|
||||
// Math.random()-based RNG. All platforms, very fast, unknown quality
|
||||
var _rndBytes = new Array(16);
|
||||
mathRNG = function() {
|
||||
var r, b = _rndBytes, i = 0;
|
||||
|
||||
for (var i = 0, r; i < 16; i++) {
|
||||
if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
|
||||
b[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
// WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
|
||||
// WebKit only (currently), moderately fast, high quality
|
||||
if (_global.crypto && crypto.getRandomValues) {
|
||||
var _rnds = new Uint32Array(4);
|
||||
whatwgRNG = function() {
|
||||
crypto.getRandomValues(_rnds);
|
||||
|
||||
for (var c = 0 ; c < 16; c++) {
|
||||
_rndBytes[c] = _rnds[c >> 2] >>> ((c & 0x03) * 8) & 0xff;
|
||||
}
|
||||
return _rndBytes;
|
||||
}
|
||||
}
|
||||
// Unique ID creation requires a high quality random # generator. We feature
|
||||
// detect to determine the best RNG source, normalizing to a function that
|
||||
// returns 128-bits of randomness, since that's what's usually required
|
||||
var _rng;
|
||||
|
||||
// Node.js crypto-based RNG - http://nodejs.org/docs/v0.6.2/api/crypto.html
|
||||
// Node.js only, moderately fast, high quality
|
||||
try {
|
||||
var _rb = require('crypto').randomBytes;
|
||||
nodeRNG = _rb && function() {
|
||||
return _rb(16);
|
||||
};
|
||||
} catch (e) {}
|
||||
//
|
||||
// Moderately fast, high quality
|
||||
if (typeof(require) == 'function') {
|
||||
try {
|
||||
var _rb = require('crypto').randomBytes;
|
||||
_rng = _rb && function() {return _rb(16);};
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
// Select RNG with best quality
|
||||
var _rng = nodeRNG || whatwgRNG || mathRNG;
|
||||
if (!_rng && _global.crypto && crypto.getRandomValues) {
|
||||
// WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
|
||||
//
|
||||
// Moderately fast, high quality
|
||||
var _rnds8 = new Uint8Array(16);
|
||||
_rng = function whatwgRNG() {
|
||||
crypto.getRandomValues(_rnds8);
|
||||
return _rnds8;
|
||||
};
|
||||
}
|
||||
|
||||
if (!_rng) {
|
||||
// Math.random()-based (RNG)
|
||||
//
|
||||
// If all else fails, use Math.random(). It's fast, but is of unspecified
|
||||
// quality.
|
||||
var _rnds = new Array(16);
|
||||
_rng = function() {
|
||||
for (var i = 0, r; i < 16; i++) {
|
||||
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
||||
_rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
||||
}
|
||||
|
||||
return _rnds;
|
||||
};
|
||||
}
|
||||
|
||||
// Buffer class to use
|
||||
var BufferClass = typeof(Buffer) == 'function' ? Buffer : Array;
|
||||
@ -227,27 +224,22 @@
|
||||
uuid.unparse = unparse;
|
||||
uuid.BufferClass = BufferClass;
|
||||
|
||||
// Export RNG options
|
||||
uuid.mathRNG = mathRNG;
|
||||
uuid.nodeRNG = nodeRNG;
|
||||
uuid.whatwgRNG = whatwgRNG;
|
||||
|
||||
//
|
||||
// module is defined in qunit, so comment node.js option out
|
||||
//
|
||||
|
||||
// if (typeof(module) != 'undefined') {
|
||||
// // Play nice with node.js
|
||||
// module.exports = uuid;
|
||||
// } else {
|
||||
// Play nice with browsers
|
||||
if (_global.define && define.amd) {
|
||||
// Publish as AMD module
|
||||
define(function() {return uuid;});
|
||||
} else if (typeof(module) != 'undefined' && module.exports) {
|
||||
// Publish as node.js module
|
||||
module.exports = uuid;
|
||||
} else {
|
||||
// Publish as global (in browsers)
|
||||
var _previousRoot = _global.uuid;
|
||||
|
||||
// **`noConflict()` - (browser only) to reset global 'uuid' var**
|
||||
uuid.noConflict = function() {
|
||||
_global.uuid = _previousRoot;
|
||||
return uuid;
|
||||
}
|
||||
};
|
||||
|
||||
_global.uuid = uuid;
|
||||
// }
|
||||
}
|
||||
}());
|
||||
|
@ -19,7 +19,7 @@
|
||||
<script src="../qunit-1.11.0.js"></script>
|
||||
<script src="../../src/lib/jquery-1.8.2.min.js"></script>
|
||||
<script src="../../src/lib/underscore-1.4.4.min.js"></script>
|
||||
<script src="../../src/lib/backbone-0.9.10.min.js"></script>
|
||||
<script src="../../src/lib/backbone-1.0.0.min.js"></script>
|
||||
<script src="../../src/lib/lawnchair/lawnchair-git.min.js"></script>
|
||||
<script src="../../src/lib/lawnchair/lawnchair-adapter-indexed-db-git.js"></script>
|
||||
<script src="../../src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js"></script>
|
||||
|
@ -19,7 +19,7 @@
|
||||
<script src="../qunit-1.11.0.js"></script>
|
||||
<script src="../../src/lib/jquery-1.8.2.min.js"></script>
|
||||
<script src="../../src/lib/underscore-1.4.4.min.js"></script>
|
||||
<script src="../../src/lib/backbone-0.9.10.min.js"></script>
|
||||
<script src="../../src/lib/backbone-1.0.0.min.js"></script>
|
||||
<script src="../../src/lib/lawnchair/lawnchair-git.min.js"></script>
|
||||
<script src="../../src/lib/lawnchair/lawnchair-adapter-indexed-db-git.js"></script>
|
||||
<script src="../../src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user