scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 83  →  ?path2? @ 84
/bower_components/simple-undo/.bower.json
@@ -0,0 +1,35 @@
{
"name": "simple-undo",
"version": "1.0.1",
"authors": [
"Matthias Jouan <matthias.jouan@gmail.com>"
],
"description": "a very basic javascript undo/redo stack for managing histories of basically anything",
"main": "./lib/simple-undo.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"undo",
"redo",
"history"
],
"license": "THE BEER-WARE LICENSE",
"homepage": "https://github.com/mattjmattj/simple-undo",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"tests"
],
"_release": "1.0.1",
"_resolution": {
"type": "version",
"tag": "1.0.1",
"commit": "5fe0e83e1ab396e10b3ac4f4f564015d4bff727a"
},
"_source": "https://github.com/mattjmattj/simple-undo.git",
"_target": "*",
"_originalSource": "simple-undo"
}
/bower_components/simple-undo/LICENSE
@@ -0,0 +1,10 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Matthias Jouan wrote this piece of software.
* As long as you retain this notice you can do whatever you want with this
* stuff.
* If we meet some day, and you think this stuff is worth it, you can buy me a
* beer in return.
* ----------------------------------------------------------------------------
*/
/bower_components/simple-undo/README.md
@@ -0,0 +1,77 @@
# simple-undo
 
[![Build Status](https://travis-ci.org/mattjmattj/simple-undo.svg)](https://travis-ci.org/mattjmattj/simple-undo)
 
simple-undo is a very basic javascript undo/redo stack for managing histories of basically anything.
 
Initially created to help fixing an issue in [drawingboard.js](https://github.com/Leimi/drawingboard.js/issues/29).
 
## Installation
 
### Bower
 
`bower install simple-undo`.
 
### NPM
 
`npm install simple-undo`
 
## Usage
 
If you are using simple-undo in the browser, a SimpleUndo object is exported in `window` after including simple-undo in your page, so it is very easy to use.
 
If you are using simple-undo as a nodejs module, just do `var SimpleUndo = require('simple-undo');`
 
```javascript
 
var myObject = {};
 
function myObjectSerializer(done) {
done(JSON.stringify(myObject));
}
 
function myObjectUnserializer(serialized) {
myObject = JSON.parse(serialized);
}
 
var history = new SimpleUndo({
maxLength: 10,
provider: myObjectSerializer
});
 
myObject.foo = 'bar';
history.save();
myObject.foo = 'baz';
history.save();
 
history.undo(myObjectUnserializer);
// myObject.foo == 'bar'
history.redo(myObjectUnserializer);
// myObject.foo == 'baz'
 
```
 
Another example is available on the [GitHub page of the project](http://mattjmattj.github.io/simple-undo/)
 
## Options and API
 
Accepted options are
 
* `provider` : required. a function to call on `save`, which should provide the current state of the historized object through the given `done` callback
* `maxLength` : the maximum number of items in history
* `opUpdate` : a function to call to notify of changes in history. Will be called on `save`, `undo`, `redo` and `clear`
 
SimpleUndo
 
* `initialize (initialState)` : registers the initial state of the managed object. If not call the default initial state is NULL
* `save ()` : calls the `provider` and registers whatever it gives
* `undo (callback)` : calls the callback with the previous state of the managed object in history
* `redo (callback)` : calls the callback with the next state of the managed object in history
* `clear ()` : clears the whole history, except the inital state if any
* `count ()` : returns the count of elements in history, apart from the inital state
 
## License
 
simple-undo is licensed under the terms of the [Beerware license](LICENSE).
 
2014 - Matthias Jouan
/bower_components/simple-undo/bower.json
@@ -0,0 +1,26 @@
{
"name": "simple-undo",
"version": "1.0.1",
"authors": [
"Matthias Jouan <matthias.jouan@gmail.com>"
],
"description": "a very basic javascript undo/redo stack for managing histories of basically anything",
"main": "./lib/simple-undo.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"undo",
"redo",
"history"
],
"license": "THE BEER-WARE LICENSE",
"homepage": "https://github.com/mattjmattj/simple-undo",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"tests"
]
}
/bower_components/simple-undo/gulpfile.js
@@ -0,0 +1,14 @@
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var gulp = require('gulp');
 
gulp.task('lint', function() {
return gulp.src('./lib/simple-undo.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
 
gulp.task('test', function() {
return gulp.src('./tests/simple-undo.js', {read: false})
.pipe(mocha({reporter: 'spec'}));
});
/bower_components/simple-undo/lib/simple-undo.js
@@ -0,0 +1,113 @@
(function() {
'use strict';
 
/**
* SimpleUndo is a very basic javascript undo/redo stack for managing histories of basically anything.
*
* options are: {
* * `provider` : required. a function to call on `save`, which should provide the current state of the historized object through the given "done" callback
* * `maxLength` : the maximum number of items in history
* * `opUpdate` : a function to call to notify of changes in history. Will be called on `save`, `undo`, `redo` and `clear`
* }
*
*/
var SimpleUndo = function(options) {
var settings = options ? options : {};
var defaultOptions = {
provider: function() {
throw new Error("No provider!");
},
maxLength: 30,
onUpdate: function() {}
};
this.provider = (typeof settings.provider != 'undefined') ? settings.provider : defaultOptions.provider;
this.maxLength = (typeof settings.maxLength != 'undefined') ? settings.maxLength : defaultOptions.maxLength;
this.onUpdate = (typeof settings.onUpdate != 'undefined') ? settings.onUpdate : defaultOptions.onUpdate;
this.initialItem = null;
this.clear();
};
 
function truncate (stack, limit) {
while (stack.length > limit) {
stack.shift();
}
}
 
SimpleUndo.prototype.initialize = function(initialItem) {
this.stack[0] = initialItem;
this.initialItem = initialItem;
};
 
 
SimpleUndo.prototype.clear = function() {
this.stack = [this.initialItem];
this.position = 0;
this.onUpdate();
};
 
SimpleUndo.prototype.save = function() {
this.provider(function(current) {
truncate(this.stack, this.maxLength);
this.position = Math.min(this.position,this.stack.length - 1);
this.stack = this.stack.slice(0, this.position + 1);
this.stack.push(current);
this.position++;
this.onUpdate();
}.bind(this));
};
 
SimpleUndo.prototype.undo = function(callback) {
if (this.canUndo()) {
var item = this.stack[--this.position];
this.onUpdate();
if (callback) {
callback(item);
}
}
};
 
SimpleUndo.prototype.redo = function(callback) {
if (this.canRedo()) {
var item = this.stack[++this.position];
this.onUpdate();
if (callback) {
callback(item);
}
}
};
 
SimpleUndo.prototype.canUndo = function() {
return this.position > 0;
};
 
SimpleUndo.prototype.canRedo = function() {
return this.position < this.count();
};
 
SimpleUndo.prototype.count = function() {
return this.stack.length - 1; // -1 because of initial item
};
 
 
 
 
 
//exports
// node module
if (typeof module != 'undefined') {
module.exports = SimpleUndo;
}
 
// browser global
if (typeof window != 'undefined') {
window.SimpleUndo = SimpleUndo;
}
 
})();
/bower_components/simple-undo/package.json
@@ -0,0 +1,35 @@
{
"name": "simple-undo",
"version": "1.0.1",
"description": "a very basic javascript undo/redo stack for managing histories of basically anything",
"main": "./lib/simple-undo.js",
"scripts": {
"test": "node_modules/.bin/gulp test"
},
"repository": {
"type": "git",
"url": "https://github.com/mattjmattj/simple-undo.git"
},
"keywords": [
"undo",
"redo",
"history"
],
"author": "Matthias Jouan",
"license": {
"type": "THE BEER-WARE LICENSE",
"url": "https://fedoraproject.org/wiki/Licensing/Beerware"
},
"bugs": {
"url": "https://github.com/mattjmattj/simple-undo/issues"
},
"homepage": "https://github.com/mattjmattj/simple-undo",
"devDependencies": {
"gulp": "^3.8.8",
"gulp-jshint": "^1.8.5",
"gulp-mocha": "^1.1.0",
"jshint": "^2.5.6",
"mocha": "^1.21.4",
"should": "^4.0.4"
}
}