From 926bb725f811c505cc64010385cba18df844248b Mon Sep 17 00:00:00 2001 From: yaoazhen Date: Tue, 26 Nov 2013 15:14:32 +0800 Subject: [PATCH] 1.rename to Flow 2.remove buster test 3.add nest flow control --- .bowerrc | 3 + .gitattributes | 1 + .gitignore | 9 + Gruntfile.js | 35 +++ README.md | 4 +- bower.json | 8 + buster.js | 11 - example/example.html | 74 +++--- example/example_underscore.html | 48 ++++ jumper.js | 262 -------------------- package.json | 10 +- src/Flow.js | 419 ++++++++++++++++++++++++++++++++ src/Flow_underscore.js | 343 ++++++++++++++++++++++++++ tests/jumper-test.js | 22 -- underscore.js | 32 --- 15 files changed, 913 insertions(+), 368 deletions(-) create mode 100644 .bowerrc create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Gruntfile.js create mode 100644 bower.json delete mode 100644 buster.js create mode 100644 example/example_underscore.html delete mode 100644 jumper.js create mode 100644 src/Flow.js create mode 100644 src/Flow_underscore.js delete mode 100644 tests/jumper-test.js delete mode 100644 underscore.js diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000..baa91a3 --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "bower_components" +} \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4d4d7ef --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text = auto \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47278e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +node_modules +dist +.idea +.tmp +.DS_Store +*.log + + +bower_components/ diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..8b6b0c9 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,35 @@ +'use strict'; + +module.exports = function (grunt) { + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); + + grunt.initConfig({ + jshint: { + + }, + clean: { + dist: { + + } + }, + watch: { + + }, + concat:{ + + } + }); + + + grunt.registerTask('server', function () { + + }); + + grunt.registerTask('build', function () { + + }); + + grunt.registerTask('test', function () { + + }); +}; \ No newline at end of file diff --git a/README.md b/README.md index ddf2b59..1589ce8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Jumper +Flow ====== -function flow control library \ No newline at end of file +Flow control library \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..906e847 --- /dev/null +++ b/bower.json @@ -0,0 +1,8 @@ +{ + "name": "Flow", + "version": "0.5.0", + "dependencies": { + "jquery": "~1.9.1", + "underscore": "*" + } +} \ No newline at end of file diff --git a/buster.js b/buster.js deleted file mode 100644 index d8d6bf0..0000000 --- a/buster.js +++ /dev/null @@ -1,11 +0,0 @@ -var config = module.exports; - -config["Jumper tests"] = { - //rootPath: "/", - //env: "browser", - //or - env: "node", - tests: [ - "tests/**/*.js" - ] -} \ No newline at end of file diff --git a/example/example.html b/example/example.html index d37a83e..98cfbc4 100644 --- a/example/example.html +++ b/example/example.html @@ -1,43 +1,47 @@ - -Example - - + + Example + -

Results in the console

- + this.onceInAll('t11', function () { + console.log('ALL 1-1'); // Just run once even you back to this step + }); + console.log(1); + this.once('t12', function () { + console.log('Step 1-2 param:' + a + b + c); // Run once every time go to this step + }); + } + , function (e, f, g) { + console.log(2); + this.once('t22', function () { + console.log('Step 2-1 param:' + e + f + g); + }); + } + , new Flow(function () { + console.log("Sub flow 3.1"); + }, function () { + console.log("Sub flow 3.2"); + }, new Flow() + ) + , function () { + console.log(4); + } + , function () { + console.log(5); + }).go(1, 2, 3).go(4, 5, 6).go().go().go().go().go() + .go().go().go().go().go().go().go() + .back().back().back().back(4, 5, 6).action().back(1, 2, 3).action(); + // Here you can pass the args with go(),back(),action() for functions + diff --git a/example/example_underscore.html b/example/example_underscore.html new file mode 100644 index 0000000..e5d16c7 --- /dev/null +++ b/example/example_underscore.html @@ -0,0 +1,48 @@ + + + + + Example with underscore + + + + +

Results in the console

+ + + diff --git a/jumper.js b/jumper.js deleted file mode 100644 index 623b769..0000000 --- a/jumper.js +++ /dev/null @@ -1,262 +0,0 @@ -// ## Multiple environment support -;(function(name, factory){ - var hasDefine = typeof define === 'function' && define.amd, - hasExports = typeof module !== 'undefined' && module.exports; - if(hasDefine){/*AMD Module*/ - define(['underscore'], factory); - } - else if(hasExports){ - /*Node.js Module*/ - // Node. Does not work with strict CommonJS, but - // only CommonJS-like enviroments that support module.exports, - // like Node. - module.exports = factory(); - } - else{ - /*Assign to common namespaces or simply the global object (window)*/ - this[name] = factory(); - } -})('Jumper', function(undef){ - "use strict"; - - var ver = '0.1.1' - , ArrayProto = Array.prototype - , ObjProto = Object.prototype - , FuncProto = Function.prototype - , slice = Array.prototype.slice - , hasOwnProperty = ObjProto.hasOwnProperty - , nativeSome = ArrayProto.some - , nativeBind = FuncProto.bind - , nativeForEach = ArrayProto.forEach - - , isFunction = function(obj) { - return typeof obj === 'function'; - }; - - // Establish the object that gets returned to break out of a loop iteration. - var breaker = {}; - // Reusable constructor function for prototype setting. - var ctor = function(){}; - - var bind = function(func, context){ - var bound, args; - if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); - if (!isFunction(func)) throw new TypeError; - args = slice.call(arguments, 2); - return bound = function() { - if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments))); - ctor.prototype = func.prototype; - var self = new ctor; - var result = func.apply(self, args.concat(slice.call(arguments))); - if (Object(result) === result) return result; - return self; - }; - }; - - // The cornerstone, an `each` implementation, aka `forEach`. - // Handles objects with the built-in `forEach`, arrays, and raw objects. - // Delegates to **ECMAScript 5**'s native `forEach` if available. - var each = function(obj, iterator, context){ - if(obj == null) return; - if(nativeForEach && obj.forEach === nativeForEach){ - obj.forEach(iterator, context); - } - else if(obj.length === +obj.length){ - for (var i = 0, l = obj.length; i < l; i++) { - if (iterator.call(context, obj[i], i, obj) === breaker) return; - } - } - else{ - for (var key in obj) { - if (hasOwnProperty.call(obj, key)) { - if (iterator.call(context, obj[key], key, obj) === breaker) return; - } - } - } - }; - - // Determine if at least one element in the object matches a truth test. - // Delegates to **ECMAScript 5**'s native `some` if available. - var some = function(obj, iterator, context){ - var result = false; - if (obj == null) return result; - if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); - - each(obj, function(value, index, list) { - if (result || (result = iterator.call(context, value, index, list))) return breaker; - }); - return !!result; - }; - - // Return the first value which passes a truth test. - var find = function(obj, iterator, context) { - var result; - some(obj, function(value, index, list) { - if (iterator.call(context, value, index, list)) { - result = value; - return true; - } - }); - return result; - }; - - var _createTask = function(){ - return { - disable:false - , went:false - }; - }; - - var _createProcess = function(func){ - return { - func : func - , running: false - , tasks : undef - }; - }; - - var _reviveProcess =function(process){ - each(process.tasks, function(task){ - task.went = false; - }); - }; - - var Jumper = function() { - this.index = -1; - this.steps=[]; - - if(arguments.length > 0){ - this.add.apply(this, arguments); - } - - this.go = bind(this.go, this); - this.back = bind(this.back, this); - this.action = bind(this.action, this); - this.jump = bind(this.jump, this); - this.onceInAll = bind(this.onceInAll, this); - this.once = bind(this.once, this); - }; - - var _createTaskInProcess = function(process, taskName, func){ - if(process && !process.tasks){ - process.tasks=[]; - } - - var task = find(process.tasks, function(item){ - return item.taskName === taskName; - }); - - if(!task){ - task = _createTask(); - task.taskName = taskName; - task.func = func; - process.tasks.push(task); - } - return task; - }; - - var _onceAction = function(taskName, func){ - // TODO: What about arguments is a Jumper instance - if(isFunction(func)){ - var process = this.current(); - if(!process){ - new Error('Once only using in a process'); - } - - var task = _createTaskInProcess.call(this, process, taskName, func); - - if(!(task.disable || task.went)){ - func(); - } - return task; - } - else{ - throw new TypeError; - } - }; - - var p = Jumper.prototype; - - p.current = function(){ - return this.steps[this.index]; - }; - - // Just run once even you back to this step - p.onceInAll = function(taskName, func) { - var task = _onceAction.apply(this, arguments); - task.disable = true; - return this; - }; - - // Run once every time go to this step - // it will not run when using action - p.once = function(taskName, func){ - - var task = _onceAction.apply(this, arguments); - task.went = true; - return this; - }; - - // Run this step and keep current process - p.action =function(){ - var process = this.current(); - if(process){ - process.func.apply(this, arguments); - } - return this; - }; - - // Goto next process - p.go = function() { - if(this.index < this.steps.length-1){ - this.index++; - var process = this.current(); - _reviveProcess(process); - this.action.apply(this, arguments); - } - - return this; - }; - - // Back to last process - p.back = function() { - if(this.index > 0){ - this.index--; - var process = this.current(); - _reviveProcess(process); - this.action.apply(this, arguments); - } - - return this; - }; - - // Jump to special process with index - p.jump = function(index){ - index--; - if(index >= -1 && index < this.steps.length){ - this.index = index; - } - return this; - }; - // Add process - p.add = function(func) { - if(arguments.length >1){ - each(arguments, function(func){ - if(isFunction(func)){ - this.add(func); - } - else{ - throw new TypeError; - } - }, this); - } - else{ - var process = _createProcess(func); - this.steps.push(process); - } - - return this; - }; - - return Jumper; -}); diff --git a/package.json b/package.json index a79aab8..8a3ce7a 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,12 @@ { - "name": "Jumper", - "version": "0.0.1", + "name": "Flow", + "version": "0.5.0", "dependencies": { - "underscore":"*" + "underscore":"*", + "jquery": "*" }, "devDependencies": { - "buster": "*" + "mocha": "*", + "grunt-contrib-concat":"~0.3.0" } } \ No newline at end of file diff --git a/src/Flow.js b/src/Flow.js new file mode 100644 index 0000000..39f56d0 --- /dev/null +++ b/src/Flow.js @@ -0,0 +1,419 @@ +; +(function (define) { + + define('Flow', function (require, exports) { + + //If have dependencies, get them here + var _ = require('underscore'); + + var undef = undefined; + var ArrayProto = Array.prototype; + var ObjProto = Object.prototype; + var FuncProto = Function.prototype; + var slice = Array.prototype.slice; + var hasOwnProperty = ObjProto.hasOwnProperty; + var nativeSome = ArrayProto.some; + var nativeBind = FuncProto.bind; + var nativeForEach = ArrayProto.forEach; + var noop = function () { + }; + + var isFunction = function(obj) { + return typeof obj === 'function'; + }; + + // Establish the object that gets returned to break out of a loop iteration. + var breaker = {}; + // Reusable constructor function for prototype setting. + var ctor = function(){}; + + var bind = function(func, context){ + var bound, args; + if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); + if (!isFunction(func)) throw new TypeError; + args = slice.call(arguments, 2); + return bound = function() { + if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments))); + ctor.prototype = func.prototype; + var self = new ctor; + var result = func.apply(self, args.concat(slice.call(arguments))); + if (Object(result) === result) return result; + return self; + }; + }; + + // The cornerstone, an `each` implementation, aka `forEach`. + // Handles objects with the built-in `forEach`, arrays, and raw objects. + // Delegates to **ECMAScript 5**'s native `forEach` if available. + var each = function(obj, iterator, context){ + if(obj == null) return; + if(nativeForEach && obj.forEach === nativeForEach){ + obj.forEach(iterator, context); + } + else if(obj.length === +obj.length){ + for (var i = 0, l = obj.length; i < l; i++) { + if (iterator.call(context, obj[i], i, obj) === breaker) return; + } + } + else{ + for (var key in obj) { + if (hasOwnProperty.call(obj, key)) { + if (iterator.call(context, obj[key], key, obj) === breaker) return; + } + } + } + }; + + // Determine if at least one element in the object matches a truth test. + // Delegates to **ECMAScript 5**'s native `some` if available. + var some = function(obj, iterator, context){ + var result = false; + if (obj == null) return result; + if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); + + each(obj, function(value, index, list) { + if (result || (result = iterator.call(context, value, index, list))) return breaker; + }); + return !!result; + }; + + // Return the first value which passes a truth test. + var find = function(obj, iterator, context) { + var result; + some(obj, function(value, index, list) { + if (iterator.call(context, value, index, list)) { + result = value; + return true; + } + }); + return result; + }; + + + var Task = function (taskName, func) { + this.taskName = taskName; + this.func = func; + }; + + + var Process = function (func) { + this.func = func; + this.tasks = []; + }; + + Process.prototype.reset = function () { + each(this.tasks, function (task) { + task.done = false; + }); + + return this; + } + + Process.prototype.createSubTask = function (taskName, func) { + var task = find(this.tasks, function (item) { + return item.taskName === taskName; + }); + + if (!task) { + task = new Task(taskName, func); + this.tasks.push(task); + } + + return task; + }; + + var _taskAction = function (taskName, func) { + + if (isFunction(func)) { + var process = this.current(); + var task = process.createSubTask(taskName, func); + + if (!(task.disable || task.done)) { + func(); + } + + return task; + } + else { + throw new TypeError; + } + }; + + + var Flow = function () { + var me = this; + + me.index = -1; + me.steps = []; + + me.current = function () { + + if (this.index == -1 || (this.index + 1) > this.steps.length) { + return noop; + } + var obj = me.steps[this.index]; + + if (isFlow(obj)) { + return obj.current(); + } + + return obj; + }; + + var increaseIndex = function (i) { + if (!me.isEOF(me.index + 1)) { + + me.index++; + + var obj = me.steps[me.index]; + + if (isFlow(obj)) { + + if (obj.moveIndex(i)) { + return true; + } + else { + me.moveIndex(i); + } + } + else { + return true; + } + } + }; + + var decreaseIndex = function (i) { + if (!me.isBOF()) { + me.index--; + var obj = me.steps[me.index]; + + if (isFlow(obj)) { + if (obj.moveIndex(i)) { + return true; + } else { + me.moveIndex(i); + } + } + else if (me.isBOF()) { + + return false; + } + else { + return true; + } + } + }; + + + me.moveIndex = function (i, cb) { + if (i > 0) { + if ((this.steps.length - this.index) > 0) { + var obj = this.steps[this.index]; + + if (isFlow(obj)) { + if (obj.moveIndex(i)) { + i--; + } + else if (increaseIndex(i)) { + i--; + } + else { + return false; + } + } + else if (this.isBOF() || isProcess(obj)) { + if (increaseIndex(i)) { + i--; + } + else { + return false; + } + } + else { + return false; + } + } + else { + return false; + } + } + else if (i < 0) { + if (this.isBOF()) { + return false; + } else { + var obj = this.steps[this.index]; + + if (isFlow(obj)) { + if (obj.moveIndex(i)) { + i++; + } + else if (decreaseIndex(i)) { + i++; + } + else { + return false; + } + } + else if (isProcess(obj)) { + if (decreaseIndex(i)) { + i++; + } + else { + return false; + } + } + } + } + + if (i === 0) { + return true; + } + else { + this.moveIndex(i); + } + }; + + + if (arguments.length > 0) { + this.add.apply(this, arguments); + } + + me.go = bind(me.go, this); + me.back = bind(me.back, this); + me.action = bind(me.action, this); + me.jump = bind(me.jump, this); + me.onceInAll = bind(me.onceInAll, this); + me.once = bind(me.once, this); + }; + + var isFlow = function (obj) { + return obj instanceof Flow; + }; + var isProcess = function (obj) { + return obj instanceof Process; + }; + + var p = Flow.prototype; + + p.add = function (scenario) { + var me = this; + if (arguments.length > 1) { + each(arguments, function (scenario) { + + me.add(scenario); + + }, me); + } + else { + + if (isFunction(scenario)) { + scenario = new Process(scenario); + } + else if (!isFlow(scenario)) { + throw new TypeError; + } + + this.steps.push(scenario); + } + + return this; + }; + + // Run this step and keep current process + p.action = function () { + + var process = this.current(); + if (process) { + process.func.apply(this, arguments); + } + + return this; + }; + + // Go to next process + p.go = p.next = function () { + + if (this.moveIndex(1)) { + this.current().reset(); + this.action.apply(this, arguments); + } + + return this; + }; + + // Back to last process + p.back = function () { + if (this.moveIndex(-1)) { + this.current().reset(); + this.action.apply(this, arguments); + } + return this; + }; + + p.once = function (func) { + var task = _taskAction.apply(this, arguments); + task.done = true; + + return this; + }; + + p.onceInAll = function (func) { + var task = _taskAction.apply(this, arguments); + task.disable = true; + + return this; + }; + + // Go to special process with index + p.goto = p.jump = function (index) { + index--; + + if (index >= -1 && index < this.steps.length) { + this.index = index; + } + + return this; + }; + + p.isBOF = function (i) { + if (i === undef) { + i = this.index; + } + + return this.index === -1; + }; + + p.isEOF = function (i) { + if (i === undef) { + i = this.index; + } + + return i === this.steps.length; + }; + + + //Attach properties to exports. + exports.Flow = Flow; + } + ) + ; + +})(typeof define === 'function' && define.amd ? define : function (id, factory) { + if (typeof exports !== 'undefined') { + //commonjs + factory(require, exports); + } else { + //Create a global function. Only works if + //the code does not have dependencies, or + //dependencies fit the call pattern below. + + var mapping = {"underscore": "_"}; + + factory(function (value) { + if(mapping[value]){ + value = mapping[value]; + } + return window[value]; + }, (window)); + } + }); \ No newline at end of file diff --git a/src/Flow_underscore.js b/src/Flow_underscore.js new file mode 100644 index 0000000..a4edfab --- /dev/null +++ b/src/Flow_underscore.js @@ -0,0 +1,343 @@ +; +(function (define) { + + define('Flow', function (require, exports) { + + //If have dependencies, get them here + var _ = require('underscore'); + + var undef = undefined; + var each = _.each; + var bind = _.bind; + var find = _.find; + var isFunction = _.isFunction; + var noop = function () { + }; + + var Task = function (taskName, func) { + this.taskName = taskName; + this.func = func; + }; + + var Process = function (func) { + this.func = func; + this.tasks = []; + }; + + + Process.prototype.reset = function () { + each(this.tasks, function (task) { + task.done = false; + }); + + return this; + } + + Process.prototype.createSubTask = function (taskName, func) { + var task = find(this.tasks, function (item) { + return item.taskName === taskName; + }); + + if (!task) { + task = new Task(taskName, func); + this.tasks.push(task); + } + + return task; + }; + + var _taskAction = function (taskName, func) { + + if (isFunction(func)) { + var process = this.current(); + var task = process.createSubTask(taskName, func); + + if (!(task.disable || task.done)) { + func(); + } + + return task; + } + else { + throw new TypeError; + } + }; + + + var Flow = function () { + var me = this; + + me.index = -1; + me.steps = []; + + me.current = function () { + + if (this.index == -1 || (this.index + 1) > this.steps.length) { + return noop; + } + var obj = me.steps[this.index]; + + if (isFlow(obj)) { + return obj.current(); + } + + return obj; + }; + + var increaseIndex = function (i) { + if (!me.isEOF(me.index + 1)) { + + me.index++; + + var obj = me.steps[me.index]; + + if (isFlow(obj)) { + + if (obj.moveIndex(i)) { + return true; + } + else { + me.moveIndex(i); + } + } + else { + return true; + } + } + }; + + var decreaseIndex = function (i) { + if (!me.isBOF()) { + me.index--; + var obj = me.steps[me.index]; + + if (isFlow(obj)) { + if (obj.moveIndex(i)) { + return true; + } else { + me.moveIndex(i); + } + } + else if (me.isBOF()) { + + return false; + } + else { + return true; + } + } + }; + + + me.moveIndex = function (i, cb) { + if (i > 0) { + if ((this.steps.length - this.index) > 0) { + var obj = this.steps[this.index]; + + if (isFlow(obj)) { + if (obj.moveIndex(i)) { + i--; + } + else if (increaseIndex(i)) { + i--; + } + else { + return false; + } + } + else if (this.isBOF() || isProcess(obj)) { + if (increaseIndex(i)) { + i--; + } + else { + return false; + } + } + else { + return false; + } + } + else { + return false; + } + } + else if (i < 0) { + if (this.isBOF()) { + return false; + } else { + var obj = this.steps[this.index]; + + if (isFlow(obj)) { + if (obj.moveIndex(i)) { + i++; + } + else if (decreaseIndex(i)) { + i++; + } + else { + return false; + } + } + else if (isProcess(obj)) { + if (decreaseIndex(i)) { + i++; + } + else { + return false; + } + } + } + } + + if (i === 0) { + return true; + } + else { + this.moveIndex(i); + } + }; + + + if (arguments.length > 0) { + this.add.apply(this, arguments); + } + + me.go = bind(me.go, this); + me.back = bind(me.back, this); + me.action = bind(me.action, this); + me.jump = bind(me.jump, this); + me.onceInAll = bind(me.onceInAll, this); + me.once = bind(me.once, this); + }; + + var isFlow = function (obj) { + return obj instanceof Flow; + }; + var isProcess = function (obj) { + return obj instanceof Process; + }; + + var p = Flow.prototype; + + p.add = function (scenario) { + var me = this; + if (arguments.length > 1) { + each(arguments, function (scenario) { + + me.add(scenario); + + }, me); + } + else { + + if (isFunction(scenario)) { + scenario = new Process(scenario); + } + else if (!isFlow(scenario)) { + throw new TypeError; + } + + this.steps.push(scenario); + } + + return this; + }; + + // Run this step and keep current process + p.action = function () { + + var process = this.current(); + if (process) { + process.func.apply(this, arguments); + } + + return this; + }; + + // Go to next process + p.go = p.next = function () { + + if (this.moveIndex(1)) { + this.current().reset(); + this.action.apply(this, arguments); + } + + return this; + }; + + // Back to last process + p.back = function () { + if (this.moveIndex(-1)) { + this.current().reset(); + this.action.apply(this, arguments); + } + return this; + }; + + p.once = function (func) { + var task = _taskAction.apply(this, arguments); + task.done = true; + + return this; + }; + + p.onceInAll = function (func) { + var task = _taskAction.apply(this, arguments); + task.disable = true; + + return this; + }; + + // Go to special process with index + p.goto = p.jump = function (index) { + index--; + + if (index >= -1 && index < this.steps.length) { + this.index = index; + } + + return this; + }; + + p.isBOF = function (i) { + if (i === undef) { + i = this.index; + } + + return this.index === -1; + }; + + p.isEOF = function (i) { + if (i === undef) { + i = this.index; + } + + return i === this.steps.length; + }; + + + //Attach properties to exports. + exports.Flow = Flow; + } + ) + ; + +})(typeof define === 'function' && define.amd ? define : function (id, factory) { + if (typeof exports !== 'undefined') { + //commonjs + factory(require, exports); + } else { + //Create a global function. Only works if + //the code does not have dependencies, or + //dependencies fit the call pattern below. + + var mapping = {"underscore": "_"}; + + factory(function (value) { + if(mapping[value]){ + value = mapping[value]; + } + return window[value]; + }, (window)); + } + }); \ No newline at end of file diff --git a/tests/jumper-test.js b/tests/jumper-test.js deleted file mode 100644 index 08cf1a6..0000000 --- a/tests/jumper-test.js +++ /dev/null @@ -1,22 +0,0 @@ -var buster = require("buster"), - Jumper = require("../jumper"); - - -var assert = buster.assert; -// Expose describe and it functions globally -buster.spec.expose(); - -describe("Jumper is a constructor", function(){ - before(function(){ - this.jumper = new Jumper(); - }); - - it('should be a function', function(){ - assert.isFunction(Jumper); - }); - - it('should be instantiatable', function(){ - assert.isObject(this.jumper); - assert(this.jumper instanceof(Jumper)); - }); -}); \ No newline at end of file diff --git a/underscore.js b/underscore.js deleted file mode 100644 index 2deac15..0000000 --- a/underscore.js +++ /dev/null @@ -1,32 +0,0 @@ -// Underscore.js 1.3.3 -// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. -// Underscore is freely distributable under the MIT license. -// Portions of Underscore are inspired or borrowed from Prototype, -// Oliver Steele's Functional, and John Resig's Micro-Templating. -// For all details and documentation: -// http://documentcloud.github.com/underscore -(function(){function r(a,c,d){if(a===c)return 0!==a||1/a==1/c;if(null==a||null==c)return a===c;a._chain&&(a=a._wrapped);c._chain&&(c=c._wrapped);if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return!1;switch(e){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:0==a?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== -c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if("object"!=typeof a||"object"!=typeof c)return!1;for(var f=d.length;f--;)if(d[f]==a)return!0;d.push(a);var f=0,g=!0;if("[object Array]"==e){if(f=a.length,g=f==c.length)for(;f--&&(g=f in a==f in c&&r(a[f],c[f],d)););}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return!1;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c,h)&&!f--)break; -g=!f}}d.pop();return g}var s=this,I=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,J=k.unshift,l=p.toString,K=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,q=k.indexOf,F=k.lastIndexOf,p=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){return new m(a)};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a, -c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a==null&&(a=[]);if(A&& -a.reduce===A){e&&(c=b.bind(c,e));return f?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,i){if(f)d=c.call(e,d,a,b,i);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return f?a.reduceRight(c,d):a.reduceRight(c)}var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a, -c,b){var e;G(a,function(a,g,h){if(c.call(b,a,g,h)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,b);j(a,function(a,g,h){if(!(e=e&&c.call(b, -a,g,h)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= -function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]}; -j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1),true);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a= -i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&& -c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var c={};j(b.flatten(i.call(arguments,1)),function(b){b in a&&(c[b]=a[b])});return c};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty= -function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=function(a){return l.call(a)=="[object Arguments]"};b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFunction=function(a){return l.call(a)=="[object Function]"}; -b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a, -b){return K.call(a,b)};b.noConflict=function(){s._=I;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){M(c,b[c]=a[c])})};var N=0;b.uniqueId= -function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var u=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},v;for(v in n)n[n[v]]=v;var O=/\\|'|\r|\n|\t|\u2028|\u2029/g,P=/\\(\\|'|r|n|t|u2028|u2029)/g,w=function(a){return a.replace(P,function(a,b){return n[b]})};b.template=function(a,c,d){d=b.defaults(d||{},b.templateSettings);a="__p+='"+a.replace(O,function(a){return"\\"+n[a]}).replace(d.escape|| -u,function(a,b){return"'+\n_.escape("+w(b)+")+\n'"}).replace(d.interpolate||u,function(a,b){return"'+\n("+w(b)+")+\n'"}).replace(d.evaluate||u,function(a,b){return"';\n"+w(b)+"\n;__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");var a="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n"+a+"return __p;\n",e=new Function(d.variable||"obj","_",a);if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c}; -b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var x=function(a,c){return c?b(a).chain():a},M=function(a,c){m.prototype[a]=function(){var a=i.call(arguments);J.call(a,this._wrapped);return x(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return x(d, -this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return x(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); \ No newline at end of file