diff --git a/Gruntfile.js b/Gruntfile.js index 49b0c269..dd7a0115 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -251,7 +251,7 @@ module.exports = function(grunt) { grunt.registerTask('watching', ['fastBuild', 'jasmine_node', 'jshint', 'lintStrings']); grunt.registerTask('default', ['build']); - grunt.registerTask('test', ['jasmine_node', 'shell:casperTest']); + grunt.registerTask('test', ['jasmine_node']); grunt.registerTask('casperTest', ['shell:casperTest']); }; diff --git a/src/js/app/index.js b/src/js/app/index.js index 6af036eb..e087ee58 100644 --- a/src/js/app/index.js +++ b/src/js/app/index.js @@ -1,7 +1,8 @@ -var _ = require('underscore'); var Backbone = require('backbone'); +var EventEmitter = require('events').EventEmitter; var React = require('react'); +var assign = require('object-assign'); var util = require('../util'); var intl = require('../intl'); var LocaleStore = require('../stores/LocaleStore'); @@ -10,7 +11,16 @@ var LocaleActions = require('../actions/LocaleActions'); /** * Globals */ -var events = _.clone(Backbone.Events); +var events = assign( + {}, + EventEmitter.prototype, + { + trigger: function() { + // alias this for backwards compatibility + this.emit.apply(this, arguments); + } + } +); var commandUI; var sandbox; var eventBaton; @@ -118,7 +128,7 @@ var initRootEvents = function(eventBaton) { var makeKeyListener = function(name) { return function() { var args = [name]; - _.each(arguments, function(arg) { + Array.prototype.slice.apply(arguments).forEach(function(arg) { args.push(arg); }); eventBaton.trigger.apply(eventBaton, args); diff --git a/src/js/util/debug.js b/src/js/util/debug.js index ec247133..f70b6dfb 100644 --- a/src/js/util/debug.js +++ b/src/js/util/debug.js @@ -1,5 +1,3 @@ -var _ = require('underscore'); - var toGlobalize = { App: require('../app/index.js'), Tree: require('../visuals/tree'), @@ -37,7 +35,9 @@ var toGlobalize = { Intl: require('../intl') }; -_.each(toGlobalize, function(module, moduleName) { +Object.keys(toGlobalize).forEach(function(moduleName) { + var module = toGlobalize[moduleName]; + for (var key in module) { var value = module[key]; if (value instanceof Function) { @@ -53,7 +53,6 @@ $(document).ready(function() { window.debug_sandbox = toGlobalize.Main.getSandbox(); window.debug_modules = toGlobalize; window.debug_levelDropdown = toGlobalize.Main.getLevelDropdown(); - window.debug_under = _; window.debug_copyTree = function() { return toGlobalize.Main.getSandbox().mainVis.gitEngine.printAndCopyTree(); }; diff --git a/src/js/util/errors.js b/src/js/util/errors.js index 4cf5bab1..53d362d2 100644 --- a/src/js/util/errors.js +++ b/src/js/util/errors.js @@ -1,17 +1,18 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var MyError = Backbone.Model.extend({ defaults: { - type: 'MyError', - msg: 'Unknown Error' + type: 'MyError' }, toString: function() { return this.get('type') + ': ' + this.get('msg'); }, getMsg: function() { - return this.get('msg') || 'Unknown Error'; + if (!this.get('msg')) { + console.warn('mye rror without message'); + } + return this.get('msg'); } }); diff --git a/src/js/util/escapeString.js b/src/js/util/escapeString.js new file mode 100644 index 00000000..3ecfe807 --- /dev/null +++ b/src/js/util/escapeString.js @@ -0,0 +1,14 @@ +var mapping = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', + '/': '/' +}; + +module.exports = function(string) { + return ('' + string).replace(/[&<>"'\/]/g, function(match) { + return mapping[match]; + }); +}; diff --git a/src/js/util/eventBaton.js b/src/js/util/eventBaton.js index 8614a74a..e6059d43 100644 --- a/src/js/util/eventBaton.js +++ b/src/js/util/eventBaton.js @@ -1,5 +1,3 @@ -var _ = require('underscore'); - function EventBaton(options) { this.eventMap = {}; this.options = options || {}; @@ -70,13 +68,13 @@ EventBaton.prototype.passBatonBack = function(name, func, context, args) { var listeners = this.getListenersThrow(name); var indexBefore; - _.each(listeners, function(listenerObj, index) { + listeners.forEach(function(listenerObj, index) { // skip the first if (index === 0) { return; } if (listenerObj.func === func && listenerObj.context === context) { indexBefore = index - 1; } - }, this); + }); if (indexBefore === undefined) { throw new Error('you are the last baton holder! or i didnt find you'); } @@ -92,7 +90,7 @@ EventBaton.prototype.releaseBaton = function(name, func, context) { var newListeners = []; var found = false; - _.each(listeners, function(listenerObj) { + listeners.forEach(function(listenerObj) { if (listenerObj.func === func && listenerObj.context === context) { if (found) { console.warn('woah duplicates!!!'); @@ -102,7 +100,7 @@ EventBaton.prototype.releaseBaton = function(name, func, context) { } else { newListeners.push(listenerObj); } - }, this); + }); if (!found) { console.log('did not find that function', func, context, name, arguments); @@ -113,4 +111,3 @@ EventBaton.prototype.releaseBaton = function(name, func, context) { }; exports.EventBaton = EventBaton; - diff --git a/src/js/util/index.js b/src/js/util/index.js index 8e6dc085..ceab3013 100644 --- a/src/js/util/index.js +++ b/src/js/util/index.js @@ -1,4 +1,4 @@ -var _ = require('underscore'); +var escapeString = require('../util/escapeString'); var constants = require('../util/constants'); exports.parseQueryString = function(uri) { @@ -17,9 +17,9 @@ exports.isBrowser = function() { }; exports.splitTextCommand = function(value, func, context) { - func = _.bind(func, context); - _.each(value.split(';'), function(command, index) { - command = _.escape(command); + func = func.bind(context); + value.split(';').forEach(function(command, index) { + command = escapeString(command); command = command .replace(/^(\s+)/, '') .replace(/(\s+)$/, '') @@ -38,8 +38,8 @@ exports.genParseCommand = function(regexMap, eventName) { var method; var regexResults; - _.each(regexMap, function(regex, _method) { - var results = regex.exec(str); + Object.keys(regexMap).forEach(function(_method) { + var results = regexMap[_method].exec(str); if (results) { method = _method; regexResults = results; diff --git a/src/js/util/keyboard.js b/src/js/util/keyboard.js index dcb77d89..cbe2d279 100644 --- a/src/js/util/keyboard.js +++ b/src/js/util/keyboard.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var Main = require('../app'); @@ -17,7 +16,7 @@ var mapKeycodeToKey = function(keycode) { }; function KeyboardListener(options) { - this.events = options.events || _.clone(Backbone.Events); + this.events = options.events; this.aliasMap = options.aliasMap || {}; if (!options.wait) { diff --git a/src/js/util/zoomLevel.js b/src/js/util/zoomLevel.js index 8e04bfa6..84f8e899 100644 --- a/src/js/util/zoomLevel.js +++ b/src/js/util/zoomLevel.js @@ -1,5 +1,3 @@ -var _ = require('underscore'); - var _warnOnce = true; function detectZoom() { /** diff --git a/src/js/views/commandViews.js b/src/js/views/commandViews.js index 4019e5d5..baae769d 100644 --- a/src/js/views/commandViews.js +++ b/src/js/views/commandViews.js @@ -113,7 +113,7 @@ var CommandPromptView = Backbone.View.extend({ // 10px for monospaced font at "1" zoom var zoom = require('../util/zoomLevel').detectZoom(); - var widthPerChar = 10 * zoom; + var widthPerChar = 9.65 * zoom; var heightPerRow = 22 * zoom; var widthOfParagraph = $(this.commandParagraph).width(); diff --git a/src/style/main.css b/src/style/main.css index 90205df0..18da8cba 100644 --- a/src/style/main.css +++ b/src/style/main.css @@ -442,7 +442,6 @@ div.controls div.box.flex1 div.plus { } /* Command Line */ - div.reactCommandView p.commandLine i { margin: 0 5px; }