From 9e66dee71228e346ccfc7b8e671dc48c907fa4d4 Mon Sep 17 00:00:00 2001 From: slaypni Date: Fri, 24 May 2013 13:14:04 +0900 Subject: [PATCH 1/2] Added option "doShowCommandBoxOnEmergencyMode" --- coffee/mode.coffee | 2 +- coffee/options.coffee | 1 + coffee/settings.coffee | 51 +++++++++++---------- coffee/view.coffee | 30 ++++++------ mode.js | 102 +++++++++++++++++++++++++---------------- options.html | 8 ++++ options.js | 7 ++- settings.js | 7 ++- view.js | 53 ++++++++++++++------- 9 files changed, 162 insertions(+), 99 deletions(-) diff --git a/coffee/mode.coffee b/coffee/mode.coffee index 2188e65..9c14789 100644 --- a/coffee/mode.coffee +++ b/coffee/mode.coffee @@ -320,7 +320,7 @@ class g.EmergencyMode extends g.Mode .replace( />/g, ">" ) .replace( /, $/, " " ) text += "to escape" - g.view.setStatusLineText( text ) + g.view.setStatusLineText( text, undefined, g.model.getSetting("doShowCommandBoxOnEmergencyMode") ) exit : -> g.view.hideStatusLine() diff --git a/coffee/options.coffee b/coffee/options.coffee index 6df941b..e9df4fd 100644 --- a/coffee/options.coffee +++ b/coffee/options.coffee @@ -109,6 +109,7 @@ onSettings = (msg) -> initCheckBox "fModeIgnoreCase" initCheckBox "notifyUpdateSucceeded" initCheckBox "useFModeAnimation" + initCheckBox "doShowCommandBoxOnEmergencyMode" initDropDown "commandBoxAlign" initDropDown "searchEngine" diff --git a/coffee/settings.coffee b/coffee/settings.coffee index 5a9a54c..34cadaa 100644 --- a/coffee/settings.coffee +++ b/coffee/settings.coffee @@ -10,36 +10,37 @@ mapping = g.SettingManager = defaultSettings : - "scrollPixelCount" : 40 - "defaultNewTab" : "home" - "commandWaitTimeOut" : 2000 - "fModeAvailableKeys" : "fdsaghjklwertyuiovbcnm" - "fModeIgnoreCase" : false - "disableAutoFocus" : false - "smoothScroll" : false - "enableCompletion" : true - "searchEngine" : "www.google.com" - "wrapSearch" : true - "incSearch" : true - "ignoreCase" : true - "useMigemo" : false - "minMigemoLength" : 3 - "minIncSearch" : 2 - "ignoredUrls" : [ + "scrollPixelCount" : 40 + "defaultNewTab" : "home" + "commandWaitTimeOut" : 2000 + "fModeAvailableKeys" : "fdsaghjklwertyuiovbcnm" + "fModeIgnoreCase" : false + "disableAutoFocus" : false + "smoothScroll" : false + "enableCompletion" : true + "searchEngine" : "www.google.com" + "wrapSearch" : true + "incSearch" : true + "ignoreCase" : true + "useMigemo" : false + "minMigemoLength" : 3 + "minIncSearch" : 2 + "ignoredUrls" : [ "http*://mail.google.com/*" "http*://www.google.co*/reader/*" "http*://docs.google.com/*" "http*://www.google.com/calendar/*" ] - "commandBoxAlign" : "Left-Bottom" - "commandBoxWidth" : 350 - "hintFontSize" : 10 - "hintBackgroundColor" : "rgba(255, 255, 80, 0.7)" - "hintColor" : "#007" - "hintColorSelected" : "#DD4848" - "useFModeAnimation" : true - "notifyUpdateSucceeded" : true - "keyMappingAndAliases" : "### Sample Settings\n + "commandBoxAlign" : "Left-Bottom" + "commandBoxWidth" : 350 + "doShowCommandBoxOnEmergencyMode" : true + "hintFontSize" : 10 + "hintBackgroundColor" : "rgba(255, 255, 80, 0.7)" + "hintColor" : "#007" + "hintColorSelected" : "#DD4848" + "useFModeAnimation" : true + "notifyUpdateSucceeded" : true + "keyMappingAndAliases" : "### Sample Settings\n \n # aliases\n # in this example you can open extensions page by the command ':ext'\n diff --git a/coffee/view.coffee b/coffee/view.coffee index 2f26fec..4905576 100644 --- a/coffee/view.coffee +++ b/coffee/view.coffee @@ -68,7 +68,7 @@ class g.Surface .addClass( 'vichrome-statuslineinactive' ) .addClass( "vichrome-statusline" + align ) .width( g.model.getSetting "commandBoxWidth" ) - @statusLineVisible = false + @statusLineActivated = false if top? path = chrome.extension.getURL("commandbox.html"); @@ -88,16 +88,19 @@ class g.Surface $('html').append(w) this - activateStatusLine : -> + activateStatusLine : (isVisible = true) -> if @slTimeout clearTimeout( @slTimeout ) @slTimeout = undefined - if @statusLineVisible then return - @statusLine.removeClass( 'vichrome-statuslineinactive' ) - @attach( @statusLine ) - @statusLine.show() - @statusLineVisible = true + if not @statusLineActivated + @statusLine.removeClass( 'vichrome-statuslineinactive' ) + @attach( @statusLine ) + if isVisible + @statusLine.show() + else + @statusLine.hide() + @statusLineActivated = true this @@ -116,14 +119,13 @@ class g.Surface if @slTimeout? clearTimeout( @slTimeout ) @slTimeout = undefined - if not @statusLineVisible then return - - @statusLine.html("").hide() - @statusLine.detach() - @statusLineVisible = false + + @statusLine?.detach() + @statusLineActivated = false + this - setStatusLineText : (text, timeout) -> + setStatusLineText : (text, timeout, isVisible = true) -> unless top? chrome.extension.sendRequest( { command : "TopFrame" @@ -133,7 +135,7 @@ class g.Surface }) return - @activateStatusLine() + @activateStatusLine(isVisible) @statusLine.html( text ) if timeout diff --git a/mode.js b/mode.js index 695c684..87089a7 100644 --- a/mode.js +++ b/mode.js @@ -1,6 +1,6 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.6.2 (function() { - var g, _ref, + var g, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -11,7 +11,6 @@ g = this.vichrome; g.Mode = (function() { - function Mode() {} Mode.prototype.exit = function() {}; @@ -24,6 +23,7 @@ Mode.prototype.enterInteractiveOpen = function(baseCom, opt) { var dscr, executer, sources; + dscr = baseCom; sources = []; if (opt.bookmark) { @@ -78,6 +78,7 @@ Mode.prototype.reqOpen = function(args) { var arg, bookmark, com, history, i, interactive, opt, search, url, urls, web, word, _i, _j, _len, _len1; + urls = []; for (_i = 0, _len = args.length; _i < _len; _i++) { arg = args[_i]; @@ -132,6 +133,7 @@ Mode.prototype.reqTabOpenNew = function(args, times) { var arg, bookmark, com, history, i, interactive, opt, search, url, web, word, words, _i, _j, _len, _len1; + words = []; if (times > 10) { times = 1; @@ -287,6 +289,7 @@ Mode.prototype.reqGoFMode = function(args) { var arg, continuous, newTab, opt, _i, _len; + for (_i = 0, _len = args.length; _i < _len; _i++) { arg = args[_i]; switch (arg) { @@ -306,6 +309,7 @@ Mode.prototype.reqGoCommandMode = function(args) { var sources; + sources = [ { "class": "CandSourceCommand" @@ -323,6 +327,7 @@ Mode.prototype.reqTabList = function() { var executer, sources; + sources = [ { "class": "CandSourceTabs" @@ -345,6 +350,7 @@ Mode.prototype.reqToggleImageSize = function() { var evt; + if (document.images.length === 1) { evt = document.createEvent('MouseEvents'); evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); @@ -372,11 +378,11 @@ })(); g.NormalMode = (function(_super) { - __extends(NormalMode, _super); function NormalMode() { - return NormalMode.__super__.constructor.apply(this, arguments); + _ref1 = NormalMode.__super__.constructor.apply(this, arguments); + return _ref1; } NormalMode.prototype.getName = function() { @@ -410,11 +416,11 @@ })(g.Mode); g.InsertMode = (function(_super) { - __extends(InsertMode, _super); function InsertMode() { - return InsertMode.__super__.constructor.apply(this, arguments); + _ref2 = InsertMode.__super__.constructor.apply(this, arguments); + return _ref2; } InsertMode.prototype.getName = function() { @@ -444,11 +450,11 @@ })(g.Mode); g.SearchMode = (function(_super) { - __extends(SearchMode, _super); function SearchMode() { - return SearchMode.__super__.constructor.apply(this, arguments); + _ref3 = SearchMode.__super__.constructor.apply(this, arguments); + return _ref3; } SearchMode.prototype.getName = function() { @@ -486,6 +492,7 @@ SearchMode.prototype.enter = function() { var param, sources; + sources = [ { "class": "CandSourceSearchHist" @@ -508,6 +515,7 @@ SearchMode.prototype.notifyInputUpdated = function(msg) { var _this = this; + if (this.waiting) { clearTimeout(this.timerId); } @@ -538,11 +546,11 @@ })(g.Mode); g.CommandMode = (function(_super) { - __extends(CommandMode, _super); function CommandMode() { - return CommandMode.__super__.constructor.apply(this, arguments); + _ref4 = CommandMode.__super__.constructor.apply(this, arguments); + return _ref4; } CommandMode.prototype.getName = function() { @@ -550,10 +558,13 @@ }; CommandMode.prototype.reqExecuteCommand = function(req) { + var e; + try { this.executer.set(req.commandLine).parse().execute(); g.view.hideStatusLine(); - } catch (e) { + } catch (_error) { + e = _error; g.view.setStatusLineText("Command Not Found : " + this.executer.get(), 2000); } return g.model.enterNormalMode(); @@ -564,8 +575,9 @@ }; CommandMode.prototype.enter = function() { - var param, _ref1; - if ((_ref1 = this.executer) == null) { + var param, _ref5; + + if ((_ref5 = this.executer) == null) { this.executer = new g.CommandExecuter; } if (this.executer.getDescription() != null) { @@ -605,11 +617,11 @@ })(g.Mode); g.EmergencyMode = (function(_super) { - __extends(EmergencyMode, _super); function EmergencyMode() { - return EmergencyMode.__super__.constructor.apply(this, arguments); + _ref5 = EmergencyMode.__super__.constructor.apply(this, arguments); + return _ref5; } EmergencyMode.prototype.getName = function() { @@ -622,6 +634,7 @@ EmergencyMode.prototype.enter = function() { var key, keyMap, mapped, text; + keyMap = g.model.getEMap(); text = "Emergency Mode: press "; for (key in keyMap) { @@ -632,7 +645,7 @@ } text = text.replace(//g, ">").replace(/, $/, " "); text += "to escape"; - return g.view.setStatusLineText(text); + return g.view.setStatusLineText(text, void 0, g.model.getSetting("doShowCommandBoxOnEmergencyMode")); }; EmergencyMode.prototype.exit = function() { @@ -654,11 +667,11 @@ })(g.Mode); g.FMode = (function(_super) { - __extends(FMode, _super); function FMode() { - return FMode.__super__.constructor.apply(this, arguments); + _ref6 = FMode.__super__.constructor.apply(this, arguments); + return _ref6; } FMode.prototype.getName = function() { @@ -672,6 +685,7 @@ FMode.prototype.hit = function(i) { var primary, target; + primary = false; target = $(this.hints[i].target); if (target.is('a')) { @@ -695,10 +709,11 @@ }; FMode.prototype.searchTarget = function() { - var elem, i, _i, _len, _ref1; - _ref1 = this.hints; - for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { - elem = _ref1[i]; + var elem, i, _i, _len, _ref7; + + _ref7 = this.hints; + for (i = _i = 0, _len = _ref7.length; _i < _len; i = ++_i) { + elem = _ref7[i]; if (this.currentInput === elem.key) { return i; } @@ -708,6 +723,7 @@ FMode.prototype.treatNewInput = function(key) { var idx; + if (key === "BS" || key === "DEL") { if (this.currentInput.length === 0) { g.model.enterNormalMode(); @@ -769,21 +785,22 @@ }; FMode.prototype.updateHints = function() { - var c, hint, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results; - _ref1 = this.hints; + var c, hint, _i, _j, _k, _len, _len1, _len2, _ref7, _ref8, _ref9, _results; + + _ref7 = this.hints; _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - hint = _ref1[_i]; + for (_i = 0, _len = _ref7.length; _i < _len; _i++) { + hint = _ref7[_i]; if (hint.key.indexOf(this.currentInput) === 0) { hint.elem.find("span#vichromehintchar").remove(); - _ref2 = this.currentInput; - for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { - c = _ref2[_j]; + _ref8 = this.currentInput; + for (_j = 0, _len1 = _ref8.length; _j < _len1; _j++) { + c = _ref8[_j]; hint.elem = hint.elem.append($('').css("color", g.model.getSetting("hintColorSelected")).html(c)); } - _ref3 = hint.key.slice(this.currentInput.length); - for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { - c = _ref3[_k]; + _ref9 = hint.key.slice(this.currentInput.length); + for (_k = 0, _len2 = _ref9.length; _k < _len2; _k++) { + c = _ref9[_k]; hint.elem = hint.elem.append($('').css("color", g.model.getSetting("hintColor")).html(c)); } if (!hint.elem.is(':visible')) { @@ -799,7 +816,8 @@ }; FMode.prototype.createHints = function(links) { - var c, elem, hint, hintHeight, i, j, k, key, left, offset, tmpElem, top, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _results; + var c, elem, hint, hintHeight, i, j, k, key, left, offset, tmpElem, top, _i, _j, _k, _len, _len1, _len2, _ref7, _ref8, _results; + for (i = _i = 0, _len = links.length; _i < _len; i = ++_i) { elem = links[i]; key = ''; @@ -816,10 +834,10 @@ } hintHeight = "" + (g.model.getSetting("hintFontSize") + 4) + "px"; tmpElem = $('').css("height", hintHeight).css("line-height", hintHeight).css("font-size", "" + g.model.getSetting("hintFontSize") + "px").css("background-color", g.model.getSetting("hintBackgroundColor")); - _ref1 = this.hints; + _ref7 = this.hints; _results = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - hint = _ref1[_j]; + for (_j = 0, _len1 = _ref7.length; _j < _len1; _j++) { + hint = _ref7[_j]; offset = hint.target._offset_; top = offset.top - 7; left = offset.left - 7; @@ -830,9 +848,9 @@ left = 0; } elem = tmpElem.clone().css("top", top).css("left", left); - _ref2 = hint.key; - for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { - c = _ref2[_k]; + _ref8 = hint.key; + for (_k = 0, _len2 = _ref8.length; _k < _len2; _k++) { + c = _ref8[_k]; elem = elem.append($('').html(c)).css("color", g.model.getSetting("hintColor")).hide(); } hint.elem = elem; @@ -844,6 +862,7 @@ FMode.prototype.enter = function() { var links; + this.currentInput = ""; this.hints = []; if (g.model.getSetting("useFModeAnimation")) { @@ -860,12 +879,14 @@ links = $('a:_visible,*:input:_visible,.button:_visible'); $('img[usemap^="#"]:_visible').each(function() { var areas, mapName, offset; + offset = this._offset_; mapName = $(this).attr('usemap').slice(1); areas = $('map[name="' + mapName + '"] area'); console.log(areas); return areas.each(function() { var coords; + if ($(this).attr('shape') !== 'default') { coords = $(this).attr('coords').split(','); this._offset_ = { @@ -906,6 +927,7 @@ $.extend($.expr[':'], { _visible: function(elem) { var offset, winH, winLeft, winTop, winW; + winLeft = window.pageXOffset; winTop = window.pageYOffset; winH = window.innerHeight; diff --git a/options.html b/options.html index 433621d..6607940 100644 --- a/options.html +++ b/options.html @@ -216,6 +216,14 @@

Command Box

px
+
+ +
diff --git a/options.js b/options.js index ecc3fa6..13a9f67 100644 --- a/options.js +++ b/options.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.6.2 (function() { var escChars, g, initCheckBox, initDropDown, initInputNumber, initInputText, onSettings, setSetting, settings, updateKeyMappingList, _ref; @@ -25,6 +25,7 @@ updateKeyMappingList = function() { var com, curMap, key, map, url, _ref1, _ref10, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _results; + curMap = $('#keyMappingList'); curMap.append($('
').html('

Normal Mode Mapping (nmap)

')); _ref1 = settings.keyMappingNormal; @@ -89,6 +90,7 @@ curMap.append($('
').html('

Command Aliases

')); _results.push((function() { var _ref11, _results1; + _ref11 = map.alias; _results1 = []; for (key in _ref11) { @@ -153,6 +155,7 @@ initCheckBox("fModeIgnoreCase"); initCheckBox("notifyUpdateSucceeded"); initCheckBox("useFModeAnimation"); + initCheckBox("doShowCommandBoxOnEmergencyMode"); initDropDown("commandBoxAlign"); initDropDown("searchEngine"); $('[name="newTabPage"][value="' + settings.defaultNewTab + '"]').attr('checked', true); @@ -182,6 +185,7 @@ $(document).ready(function() { var page; + $('#page-container > div').hide(); page = /#.*$/.exec(window.location.href); if (page != null) { @@ -194,6 +198,7 @@ console.log(page); return $('ul.navbar li:not(.navbar-item-separator)').click(function() { var tab; + $('ul.navbar li').removeClass('navbar-item-selected'); $(this).addClass('navbar-item-selected'); $('#page-container > div').hide(); diff --git a/settings.js b/settings.js index 452ad6e..fd1f49c 100644 --- a/settings.js +++ b/settings.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.6.2 (function() { var g, mapping, _ref; @@ -36,6 +36,7 @@ "ignoredUrls": ["http*://mail.google.com/*", "http*://www.google.co*/reader/*", "http*://docs.google.com/*", "http*://www.google.com/calendar/*"], "commandBoxAlign": "Left-Bottom", "commandBoxWidth": 350, + "doShowCommandBoxOnEmergencyMode": true, "hintFontSize": 10, "hintBackgroundColor": "rgba(255, 255, 80, 0.7)", "hintColor": "#007", @@ -191,6 +192,7 @@ }, _pagecmd: function(map, args) { var _name; + if (this.pageMap[args[0]] == null) { this.pageMap[args[0]] = g.extendDeep(mapping); } @@ -198,6 +200,7 @@ }, parseKeyMappingAndAliases: function() { var args, line, lines, _i, _len, _name; + lines = this.get("keyMappingAndAliases").replace(/^[\t ]*/m, "").replace(/[\t ]*$/m, "").replace(/<[A-Za-z0-9]+>/g, function(v) { return v.toUpperCase(); }).split('\n'); @@ -218,6 +221,7 @@ }, initUserMap: function() { var com, command, defAliases, defCommand, defEmergency, defInsert, defNormal, defPageMap, key, map, url, _ref1, _ref2, _ref3, _ref4, _ref5; + defNormal = this.defaultSettings.keyMappingNormal; defInsert = this.defaultSettings.keyMappingInsert; defCommand = this.defaultSettings.keyMappingCommand; @@ -279,6 +283,7 @@ }, getAll: function() { var name, settings, value, _ref1; + settings = {}; _ref1 = this.defaultSettings; for (name in _ref1) { diff --git a/view.js b/view.js index 6c73ed2..40738d2 100644 --- a/view.js +++ b/view.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.6.2 (function() { var g, _ref; @@ -11,6 +11,7 @@ $.fn.extend({ isWithinScreen: function(padding) { var offset; + if (padding == null) { padding = 10; } @@ -28,6 +29,7 @@ }, scrollTo: function(x, y, speed) { var left, newX, newY, offset, top; + if (speed == null) { speed = 80; } @@ -61,6 +63,7 @@ }, scrollBy: function(x, y, speed) { var left, top; + if (x == null) { x = 0; } @@ -86,6 +89,7 @@ $.extend($.expr[':'], { scrollable: function(elem) { var overflow; + overflow = $.curCSS(elem, 'overflow'); switch (overflow) { case "auto": @@ -97,15 +101,15 @@ }); g.Surface = (function() { - function Surface() {} Surface.prototype.init = function() { var align, path, _this = this; + align = g.model.getSetting("commandBoxAlign"); this.statusLine = $('
').addClass('vichrome-statuslineinactive').addClass("vichrome-statusline" + align).width(g.model.getSetting("commandBoxWidth")); - this.statusLineVisible = false; + this.statusLineActivated = false; if (typeof top !== "undefined" && top !== null) { path = chrome.extension.getURL("commandbox.html"); this.iframe = $("