Added uglified (compressed) version

This commit is contained in:
Oliver Sartun 2013-05-28 17:52:05 +02:00
parent 37a9a44a90
commit e3f874236d

10
Backbone.Undo.min.js vendored Normal file
View File

@ -0,0 +1,10 @@
/*!
* Backbone.Undo.js v0.1
*
* Copyright (c)2013 Oliver Sartun
* Released under the MIT License
*
* Documentation and full license available at
* https://github.com/Bloli/Backbone.Undo.js
*/
(function(e,t,n,r,i,s){function o(e,t,n){return n.length<=3?e.call(t,n[0],n[1],n[2]):e.apply(t,n)}function u(e,t){if(e==null)return false;if(!r.isArray(t)){t=v(arguments,1)}for(var n=0,i=t.length;n<i;n++){if(!(t[n]in e))return false}return true}function f(){this.registeredObjects=[]}function l(e,t,n,i){for(var s=0,o=t.length,u;s<o;s++){u=t[s];if(e==="on"){if(i.objectRegistry.isRegistered(u)){continue}else{i.objectRegistry.register(u)}}else{if(!i.objectRegistry.isRegistered(u)){continue}else{i.objectRegistry.unregister(u)}}if(r.isFunction(u[e])){u[e]("all",n,i)}}}function c(e,t){var n=t.type,i=!m[n]||m[n][e];if(r.isFunction(i)){i(t.object,t.before,t.after,r.clone(t))}}function h(e,t){if(t.isCurrentlyUndoRedoing||e==="undo"&&t.pointer===-1||e==="redo"&&t.pointer===t.length-1){return}t.isCurrentlyUndoRedoing=true;var n,r,i=e==="undo";if(i){n=t.at(t.pointer);t.pointer--}else{t.pointer++;n=t.at(t.pointer)}r=t.where({cycleIndex:n.get("cycleIndex")});t.pointer+=(i?-1:1)*(r.length-1);while(n=i?r.pop():r.shift()){n[e]()}t.isCurrentlyUndoRedoing=false}function p(e,t,n,r){if(e.track&&!e.isCurrentlyUndoRedoing&&t in m){var i=o(m[t]["on"],null,n),s;if(u(i,"object","before","after")){i.type=t;i.cycleIndex=a();if(e.pointer<e.length-1){var s=e.length-e.pointer-1;while(s--){e.pop()}}e.pointer=e.length;e.add(i);if(e.length>r){e.shift();e.pointer--}}}}var a=function(){function n(){t++;e=true;r.defer(function(){e=false})}var e=false,t=-1;return function(){if(!e){n()}return t|0}}();f.prototype={isRegistered:function(e){return e&&e.cid?this.registeredObjects[e.cid]:r.contains(this.registeredObjects,e)},register:function(e){if(e&&e.cid){this.registeredObjects[e.cid]=e}else{this.registeredObjects.push(e)}},unregister:function(e){if(e&&e.cid){delete this.registeredObjects[e.cid]}else{var t=r.indexOf(this.registeredObjects,e);if(t>-1){this.registeredObjects.splice(t,1)}}}};var d=Array.prototype.slice,v=function(e,t){return d.call(e,t)},m={add:{undo:function(e,t,n,r){e.remove(n,r.options)},redo:function(e,t,n,r){var i=r.options;if(i.index){i.at=i.index}e.add(n,r.options)},on:function(e,t,n){return{object:t,before:s,after:e,options:r.clone(n)}}},remove:{undo:function(e,t,n,r){var i=r.options;if(i.index){i.at=i.index}e.add(t,i)},redo:function(e,t,n,r){e.remove(t,r.options)},on:function(e,t,n){return{object:t,before:e,after:s,options:r.clone(n)}}},reset:{undo:function(e,t,n){e.reset(t)},redo:function(e,t,n){e.reset(n)},on:function(e,t){return{object:e,before:t.previousModels,after:r.clone(e.models)}}},change:{undo:function(e,t,n){if(r.isEmpty(t)){r.each(r.keys(n),e.unset,e)}else{e.set(t)}},redo:function(e,t,n){if(r.isEmpty(n)){r.each(r.keys(t),e.unset,e)}else{e.set(n)}},on:function(e,t){var n=e.changedAttributes(),i=r.pick(e.previousAttributes(),r.keys(n));return{object:e,before:i,after:n}}}},g=i.Model.extend({defaults:{type:null,object:null,before:null,after:null,cycleIndex:null},undo:function(){c("undo",this.attributes)},redo:function(){c("redo",this.attributes)}}),y=i.Collection.extend({model:g,pointer:-1,track:false,isCurrentlyUndoRedoing:false,maximumStackLength:Infinity,initialize:function(){this.objectRegistry=new f},setMaxLength:function(e){this.maximumStackLength=e},addToStack:function(e){p(this,e,v(arguments,1),this.maximumStackLength)}}),b=i.Model.extend({defaults:{maximumStackLength:Infinity},initialize:function(e){this.stack=new y;this.stack.setMaxLength(this.get("maximumStackLength"));this.on("change:maximumStackLength",function(e,t){this.stack.setMaxLength(t)},this)},startTracking:function(){this.stack.track=true},stopTracking:function(){this.stack.track=false},register:function(){l("on",arguments,this.stack.addToStack,this.stack)},unregister:function(){l("off",arguments,this.stack.addToStack,this.stack)},undo:function(){h("undo",this.stack)},redo:function(){h("redo",this.stack)}});b.addUndoType=function(e,t){if(typeof e==="object"){return r.each(e,function(e,t){b.addUndoType(t,e)})}if(r.isString(e)&&u(t,"undo","redo","on")&&r.all(t,r.isFunction())){m[e]=t}};i.UndoManager=b})(window,window.document,window.jQuery,window._,window.Backbone)