diff --git a/.gitignore b/.gitignore index d6633ca..3120bf6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ tags vichrome.zip *.swp *.swo +/*.js \ No newline at end of file diff --git a/background.js b/background.js deleted file mode 100644 index 8890aac..0000000 --- a/background.js +++ /dev/null @@ -1,611 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var extendURL, g, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - extendURL = function(base) { - var url; - if (base.search(/^javascript:/i) >= 0) { - return base; - } - if (base.indexOf("%clipboard") >= 0) { - url = encodeURI(base.replace(/%clipboard/g, g.clipboard.get())); - } else { - url = encodeURI(base); - } - if (url.indexOf("://") < 0) { - url = "http://" + url; - } - return url; - }; - - g.bg = { - tabHistory: null, - moveTab: function(offset, start, callback) { - return chrome.tabs.getAllInWindow(null, function(tabs) { - var nTabs; - nTabs = tabs.length; - return chrome.tabs.getSelected(null, function(tab) { - var idx; - if (start != null) { - idx = start + offset; - } else { - idx = tab.index + offset; - } - if (idx < 0) { - idx = nTabs + (idx % nTabs); - } else if (idx >= nTabs) { - idx = idx % nTabs; - } - return chrome.tabs.update(tabs[idx].id, { - selected: true - }, callback); - }); - }); - }, - getSettings: function(msg) { - var sendMsg; - sendMsg = {}; - sendMsg.name = msg.name; - if (msg.name === "all") { - sendMsg.value = g.SettingManager.getAll(); - } else { - sendMsg.value = g.SettingManager.get(msg.name); - } - return sendMsg; - }, - setSettings: function(msg, response) { - g.SettingManager.set(msg.name, msg.value); - return {}; - }, - reqSettings: function(msg, response) { - if (msg.type === "get") { - response(this.getSettings(msg)); - } else if (msg.type === "set") { - response(this.setSettings(msg)); - } - return true; - }, - reqInit: function(msg, response, sender) { - var o; - o = this.getSettings({ - name: "all" - }); - o.command = "Init"; - g.logger.d("frameID " + (this.tabHistory.getFrames(sender.tab)) + " added"); - o.frameID = this.tabHistory.getFrames(sender.tab); - this.tabHistory.addFrames(sender.tab); - response(o); - return true; - }, - getDefaultNewTabPage: function() { - switch (g.SettingManager.get("defaultNewTab")) { - case "home": - return void 0; - case "newtab": - return "chrome://newtab"; - case "blank": - return "about:blank"; - } - }, - reqTabOpenNew: function(req) { - var arg, extend, focus, len, next, pinned, times, urls, _i, _len, _ref1, _ref2, _ref3, - _this = this; - urls = []; - focus = true; - pinned = false; - extend = (_ref1 = req.extend) != null ? _ref1 : false; - _ref2 = req.args; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - arg = _ref2[_i]; - switch (arg) { - case "-b": - case "--background": - focus = false; - break; - case "-p": - case "--pinned": - pinned = true; - break; - case "--next": - next = true; - break; - default: - urls.push(arg); - } - } - len = urls.length; - times = (_ref3 = req.times) != null ? _ref3 : 1; - chrome.tabs.getSelected(null, function(tab) { - var index, url, _j, _len1; - if (next) { - index = tab.index + 1; - } - if (len === 0) { - while (times--) { - chrome.tabs.create({ - url: _this.getDefaultNewTabPage(), - selected: focus, - pinned: pinned, - index: index - }); - } - } else { - for (_j = 0, _len1 = urls.length; _j < _len1; _j++) { - url = urls[_j]; - if (extend) { - url = extendURL(url); - } - chrome.tabs.create({ - url: url, - selected: focus, - pinned: pinned, - index: index - }); - } - } - }); - return false; - }, - reqCopy: function(req) { - return chrome.tabs.getSelected(null, function(tab) { - var c, data; - data = req.args[0].replace(/%url/g, tab.url).replace(/%title/g, tab.title); - c = data.charAt(0); - if (c === "'" || c === "\"") { - if (data.charAt(data.length - 1) === c) { - data = data.substr(1, data.length - 2); - } - } - return g.clipboard.set(data); - }); - }, - reqWinOpenNew: function(req) { - var arg, focus, pop, urls, _i, _len, _ref1; - urls = []; - focus = true; - pop = false; - _ref1 = req.args; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - arg = _ref1[_i]; - switch (arg) { - case "-b": - case "--background": - focus = false; - break; - case "-p": - case "--pop": - pop = true; - break; - default: - urls.push(arg.replace(/%url/g, g.view.getHref())); - } - } - if (pop) { - chrome.tabs.getSelected(null, function(tab) { - if (urls.length === 0) { - return chrome.windows.create({ - focused: focus, - tabId: tab.id - }); - } else { - return chrome.windows.create({ - url: urls, - focused: focus, - tabId: tab.id - }); - } - }); - } else { - if (urls.length === 0) { - urls = this.getDefaultNewTabPage(); - } - chrome.windows.create({ - url: urls, - focused: focus - }); - } - return false; - }, - reqTabCloseCurrent: function(req) { - var arg, prev, _i, _len, _ref1, - _this = this; - _ref1 = req.args; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - arg = _ref1[_i]; - switch (arg) { - case "--focusprev": - prev = true; - } - } - chrome.tabs.getSelected(null, function(tab) { - if (prev && tab.index > 0) { - return _this.moveTab(-1, tab.index, function() { - return chrome.tabs.remove(tab.id); - }); - } else { - return chrome.tabs.remove(tab.id); - } - }); - return false; - }, - reqTabCloseAll: function(req) { - var arg, only, _i, _len, _ref1; - _ref1 = req.args; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - arg = _ref1[_i]; - switch (arg) { - case "--only": - only = true; - } - } - if (only) { - chrome.tabs.getAllInWindow(null, function(tabs) { - return chrome.tabs.getSelected(null, function(selected) { - var tab, _j, _len1; - for (_j = 0, _len1 = tabs.length; _j < _len1; _j++) { - tab = tabs[_j]; - if (selected.id !== tab.id) { - chrome.tabs.remove(tab.id); - } - } - }); - }); - } else { - chrome.windows.getCurrent(function(win) { - return chrome.windows.remove(win.id); - }); - } - return false; - }, - reqTabReloadAll: function(req) { - var _ref1; - if ((_ref1 = g.tabs) != null) { - if (typeof _ref1.reloadAllTabs === "function") { - _ref1.reloadAllTabs(); - } - } - return false; - }, - reqTabFocusNext: function(req) { - var _ref1; - if (((_ref1 = req.args) != null ? _ref1[0] : void 0) != null) { - if (req.args[0] <= 0) { - return; - } - this.moveTab(parseInt(req.args[0]) - 1, 0); - } else { - if (req.timesSpecified && req.times > 0) { - this.moveTab(req.times - 1, 0); - } else { - this.moveTab(1); - } - } - return false; - }, - reqTabFocusPrev: function(req) { - var times, _ref1; - times = req.times ? req.times : 1; - if (((_ref1 = req.args) != null ? _ref1[0] : void 0) != null) { - this.moveTab(-parseInt(req.args[0])); - } else { - this.moveTab(-times); - } - return false; - }, - reqTabFocusNextHistory: function(req) { - this.tabSelHist.moveForward(); - return false; - }, - reqTabFocusPrevHistory: function(req) { - this.tabSelHist.moveBackward(); - return false; - }, - reqTabSwitchLast: function(req) { - this.tabSelHist.switchToLast(); - return false; - }, - reqTabFocusFirst: function(req) { - this.moveTab(0, 0); - return false; - }, - reqTabFocusLast: function(req) { - this.moveTab(-1, 0); - return false; - }, - reqRestoreTab: function(req) { - this.tabHistory.restoreLastClosedTab(); - return false; - }, - reqNMap: function(req, sendResponse) { - var msg; - if (!((req.args[0] != null) && (req.args[1] != null))) { - return; - } - msg = { - command: "Settings", - name: "keyMappingNormal", - value: g.SettingManager.setNMap(req.args) - }; - sendResponse(msg); - return true; - }, - reqIMap: function(req, sendResponse) { - var msg; - if (!((req.args[0] != null) && (req.args[1] != null))) { - return; - } - msg = { - command: "Settings", - name: "keyMappingInsert", - value: g.SettingManager.setIMap(req.args) - }; - sendResponse(msg); - return true; - }, - reqAlias: function(req, sendResponse) { - var msg; - if (!((req.args[0] != null) && (req.args[1] != null))) { - return; - } - msg = { - command: "Settings", - name: "aliases", - value: g.SettingManager.setAlias(req.args) - }; - sendResponse(msg); - return true; - }, - reqReadability: function(req) { - chrome.tabs.getSelected(null, function(tab) { - return chrome.extension.sendRequest("jggheggpdocamneaacmfoipeehedigia", { - type: "render", - tab_id: tab.id - }); - }); - return false; - }, - reqPushSearchHistory: function(req) { - var history, idx; - if (req.value == null) { - return; - } - history = JSON.parse(localStorage.getItem("_searchHistory")); - history || (history = []); - if ((idx = history.indexOf(req.value)) >= 0) { - history.splice(idx, 1); - } - history.push(req.value); - if (history.length > 10) { - history.shift(); - } - localStorage.setItem("_searchHistory", JSON.stringify(history)); - return false; - }, - reqGetSearchHistory: function(req, sendResponse) { - var history, msg; - history = JSON.parse(localStorage.getItem("_searchHistory")); - msg = { - command: "GetSearchHistory", - value: history - }; - sendResponse(msg); - return true; - }, - reqGetBookmark: function(req, sendResponse) { - chrome.bookmarks.search(req.value, function(nodes) { - return sendResponse(nodes); - }); - return true; - }, - reqGetHistory: function(req, sendResponse) { - chrome.history.search({ - text: req.value, - maxResults: 5 - }, function(items) { - return sendResponse(items); - }); - return true; - }, - reqGetGoogleSuggest: function(req, sendResponse) { - if (!this.gglLoaded) { - return false; - } - if (this.cWSrch.isExec) { - return false; - } - this.cWSrch.reset().sgst({ - kw: req.value, - hl: g.util.getLang(), - res: function(res) { - return sendResponse(res.raw); - } - }).start(); - return true; - }, - reqGetWebSuggest: function(req, sendResponse) { - var _this = this; - if (!this.gglLoaded) { - return false; - } - if (this.cWSrch.isExec) { - return false; - } - this.cWSrch.init({ - type: "web", - opt: function(obj) { - return obj.setResultSetSize(google.search.Search.LARGE_RESULTSET); - } - }).start(); - this.cWSrch.reset().srch({ - type: "web", - page: 1, - key: req.value, - res: function(res) { - var i, item, msg, obj, _i, _len; - if (!res || res.length <= 0) { - _this.cWSrch.cmndsBreak(); - sendResponse(); - return; - } - msg = []; - for (i = _i = 0, _len = res.length; _i < _len; i = ++_i) { - item = res[i]; - obj = {}; - obj.titleNoFormatting = item.titleNoFormatting; - obj.unescapedUrl = item.unescapedUrl; - obj.url = item.url; - msg.push(obj); - } - return sendResponse(msg); - } - }).start(); - return true; - }, - reqGetTabList: function(req, sendResponse) { - chrome.tabs.getAllInWindow(null, function(tabs) { - return sendResponse(tabs); - }); - return true; - }, - reqOpenOptionPage: function(req) { - var arg, key, url, _i, _len, _ref1; - _ref1 = req.args; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - arg = _ref1[_i]; - switch (arg) { - case "-k": - case "--key": - key = true; - } - } - req = {}; - req.args = []; - req.times = 1; - url = chrome.extension.getURL("options.html"); - if (key) { - url += "#keymapping"; - } - req.args.push(url); - return this.reqTabOpenNew(req); - }, - reqTopFrame: function(req, response, sender) { - var o; - req.command = req.innerCommand; - req.frameID = this.tabHistory.getTopFrameID(sender.tab); - if (req.frameID != null) { - chrome.tabs.sendRequest(sender.tab.id, req); - } else { - g.logger.e("Can't send request to top frame: frame ID is invalid"); - o = {}; - o.error = true; - o.errorMsg = "Something's wrong. Try to reload page"; - response(o); - return true; - } - return false; - }, - reqPassToFrame: function(req, response, sender) { - req.command = req.innerCommand; - chrome.tabs.sendRequest(sender.tab.id, req); - return false; - }, - reqSendToCommandBox: function(req, response, sender) { - var o; - req.command = req.innerCommand; - req.frameID = this.tabHistory.getCommandBoxID(sender.tab); - if (req.frameID != null) { - chrome.tabs.sendRequest(sender.tab.id, req); - } else { - g.logger.e("Can't send request to command box: frame ID is invalid"); - o = {}; - o.error = true; - o.errorMsg = "Can't open commandbox. Try to reload page"; - response(o); - return true; - } - return false; - }, - reqGetCommandTable: function(req, response, sender) { - req.frameID = this.tabHistory.getTopFrameID(sender.tab); - chrome.tabs.sendRequest(sender.tab.id, req, function(msg) { - return response(msg); - }); - return true; - }, - reqGetAliases: function(req, response, sender) { - req.frameID = this.tabHistory.getTopFrameID(sender.tab); - chrome.tabs.sendRequest(sender.tab.id, req, function(msg) { - return response(msg); - }); - return true; - }, - reqGetClipboard: function(req, response, sender) { - response(g.clipboard.get()); - return true; - }, - reqExtendURL: function(req, response, sender) { - response(extendURL(req.url)); - return true; - }, - init: function() { - var $WA, req, storedVersion, - _this = this; - this.tabHistory = (new g.TabHistory).init(); - this.tabSelHist = (new g.TabSelectionHistory).init(); - g.SettingManager.init(); - $WA = crocro.webAi; - this.cWSrch = new $WA.WebSrch(); - this.cWSrch.ready(function() { - return _this.gglLoaded = true; - }); - chrome.extension.onRequest.addListener(function(req, sender, sendResponse) { - var frameID, msg; - g.logger.d("onRequest command: " + req.command); - switch (req.command) { - case "NotifyTopFrame": - g.logger.d("top frame " + req.frameID); - _this.tabHistory.setTopFrameID(sender.tab, req.frameID); - return sendResponse(); - case "InitCommandFrame": - msg = {}; - frameID = _this.tabHistory.getFrames(sender.tab); - _this.tabHistory.setCommandBoxID(sender.tab, frameID); - _this.tabHistory.addFrames(sender.tab); - g.logger.d("commandBoxFrameID: " + frameID); - msg.frameID = frameID; - msg.enableCompletion = g.SettingManager.get("enableCompletion"); - msg.commandBoxWidth = g.SettingManager.get("commandBoxWidth"); - msg.commandBoxAlign = g.SettingManager.get("commandBoxAlign"); - msg.commandWaitTimeOut = g.SettingManager.get("commandWaitTimeOut"); - return sendResponse(msg); - default: - if (_this["req" + req.command]) { - if (!_this["req" + req.command](req, sendResponse, sender)) { - return sendResponse(); - } - } else { - return g.logger.e("INVALID command!:", req.command); - } - } - }); - if (g.SettingManager.get("notifyUpdateSucceeded")) { - storedVersion = localStorage.version; - if ((storedVersion != null) && storedVersion !== g.VICHROME_VERSION) { - req = {}; - req.args = ["https://github.com/k2nr/ViChrome/wiki/Release-History"]; - this.reqTabOpenNew(req); - } - } - return localStorage.version = g.VICHROME_VERSION; - } - }; - - g.bg.init(); - -}).call(this); 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/command.js b/command.js deleted file mode 100644 index 2613e33..0000000 --- a/command.js +++ /dev/null @@ -1,392 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var escape, g, passToTopFrame, sendToBackground, triggerInsideContent, _ref, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - sendToBackground = function(com, args, times, timesSpecified, callback) { - if (callback == null) { - callback = g.handler.onCommandResponse; - } - return chrome.extension.sendRequest({ - command: com, - args: args, - times: times, - timesSpecified: timesSpecified - }, function(msg) { - return callback(msg); - }); - }; - - triggerInsideContent = function(com, args, times, timesSpecified) { - return g.model.triggerCommand("req" + com, args, times, timesSpecified); - }; - - passToTopFrame = function(com, args, times, timesSpecified, callback) { - if (callback == null) { - callback = g.handler.onCommandResponse; - } - return chrome.extension.sendRequest({ - command: "TopFrame", - innerCommand: com, - args: args, - times: times, - timesSpecified: timesSpecified, - senderFrameID: g.model.frameID - }, callback); - }; - - escape = function(com) { - return triggerInsideContent("Escape"); - }; - - g.CommandExecuter = (function() { - - function CommandExecuter() {} - - CommandExecuter.prototype.commandsBeforeReady = ["TabOpenNew", "TabCloseCurrent", "TabCloseAll", "TabFocusNext", "TabFocusPrev", "TabFocusFirst", "TabFocusLast", "TabFocusNextHistory", "TabFocusPrevHistory", "TabSwitchLast", "TabReloadAll", "NMap", "IMap", "Alias", "WinOpenNew", "OpenOptionPage", "RestoreTab"]; - - CommandExecuter.prototype.commandTable = { - Open: passToTopFrame, - TabOpenNew: passToTopFrame, - TabCloseCurrent: sendToBackground, - TabCloseAll: sendToBackground, - TabFocusNext: sendToBackground, - TabFocusPrev: sendToBackground, - TabFocusNextHistory: sendToBackground, - TabFocusPrevHistory: sendToBackground, - TabFocusFirst: sendToBackground, - TabFocusLast: sendToBackground, - TabSwitchLast: sendToBackground, - TabReload: triggerInsideContent, - TabReloadAll: sendToBackground, - TabList: triggerInsideContent, - NMap: sendToBackground, - IMap: sendToBackground, - Alias: sendToBackground, - WinOpenNew: sendToBackground, - ScrollUp: triggerInsideContent, - ScrollDown: triggerInsideContent, - ScrollLeft: triggerInsideContent, - ScrollRight: triggerInsideContent, - PageHalfUp: triggerInsideContent, - PageHalfDown: triggerInsideContent, - PageUp: triggerInsideContent, - PageDown: triggerInsideContent, - GoTop: triggerInsideContent, - GoBottom: triggerInsideContent, - NextSearch: triggerInsideContent, - PrevSearch: triggerInsideContent, - BackHist: triggerInsideContent, - ForwardHist: triggerInsideContent, - GoCommandMode: triggerInsideContent, - GoSearchModeForward: triggerInsideContent, - GoSearchModeBackward: triggerInsideContent, - GoLinkTextSearchMode: triggerInsideContent, - GoFMode: triggerInsideContent, - GoEmergencyMode: triggerInsideContent, - FocusOnFirstInput: triggerInsideContent, - BackToPageMark: triggerInsideContent, - RestoreTab: sendToBackground, - FocusNextCandidate: triggerInsideContent, - FocusPrevCandidate: triggerInsideContent, - Readability: sendToBackground, - OpenOptionPage: sendToBackground, - BarrelRoll: triggerInsideContent, - Copy: sendToBackground, - Escape: escape, - HideJimmy: triggerInsideContent, - ToggleImageSize: triggerInsideContent, - "_ChangeLogLevel": triggerInsideContent - }; - - CommandExecuter.prototype.get = function() { - var _ref1; - return (_ref1 = this.command) != null ? _ref1 : ""; - }; - - CommandExecuter.prototype.getArgs = function() { - return this.args; - }; - - CommandExecuter.prototype.setDescription = function(description) { - this.description = description; - return this; - }; - - CommandExecuter.prototype.getDescription = function() { - return this.description; - }; - - CommandExecuter.prototype.reset = function() { - return this.command = null; - }; - - CommandExecuter.prototype.set = function(command, times) { - if (this.command != null) { - this.command += " "; - } else { - this.command = ""; - } - this.command += command.replace(/^[\t ]*/, "").replace(/[\t ]*$/, ""); - this.times = times != null ? times : 1; - this.timesSpecified = times != null ? true : false; - return this; - }; - - CommandExecuter.prototype.delimLine = function(line) { - var c, i, len, pos, pre, result, start, _i, _ref1; - result = []; - pos = 0; - pre = 0; - len = line.length; - while (pos < len) { - c = line.charAt(pos); - switch (c) { - case " ": - result.push(line.slice(pre, pos)); - while (line.charAt(pos) === " ") { - ++pos; - } - pre = pos; - break; - case "'": - case "\"": - start = pos; - while (line.charAt(++pos) !== c) { - if (pos >= len) { - pos = start; - break; - } - } - ++pos; - break; - default: - ++pos; - } - } - result.push(line.slice(pre, pos)); - for (i = _i = _ref1 = result.length - 1; _ref1 <= 0 ? _i <= 0 : _i >= 0; i = _ref1 <= 0 ? ++_i : --_i) { - if (result[i].length === 0) { - result.splice(i, 1); - } - } - return result; - }; - - CommandExecuter.prototype.solveAlias = function(alias) { - var aliases, command; - aliases = g.model.getAlias(); - alias = aliases[alias]; - while (alias != null) { - command = alias; - alias = aliases[alias]; - } - return command; - }; - - CommandExecuter.prototype.parse = function() { - var command; - if (!this.command) { - throw "invalid command"; - } - this.args = this.delimLine(this.command); - command = this.solveAlias(this.args[0]); - if (command != null) { - this.args = this.delimLine(command).concat(this.args.slice(1)); - } - command = this.command; - this.args = []; - while (command) { - this.args = this.delimLine(command).concat(this.args.slice(1)); - command = this.solveAlias(this.args[0]); - } - if (this.commandTable[this.args[0]]) { - return this; - } else { - throw "invalid command"; - } - }; - - CommandExecuter.prototype.execute = function() { - var com, - _this = this; - com = this.args[0]; - if (!(g.model.isReady() || __indexOf.call(this.commandsBeforeReady, com) >= 0)) { - return; - } - return setTimeout(function() { - return _this.commandTable[com](com, _this.args.slice(1), _this.times, _this.timesSpecified); - }, 0); - }; - - return CommandExecuter; - - })(); - - g.CommandManager = (function() { - - CommandManager.prototype.keyQueue = { - init: function(model, timeout, useNumPrefix) { - this.model = model; - this.timeout = timeout; - this.useNumPrefix = useNumPrefix != null ? useNumPrefix : true; - this.a = ""; - this.times = ""; - this.timerId = 0; - return this.waiting = false; - }, - stopTimer: function() { - if (this.waiting) { - g.logger.d("stop timeout"); - clearTimeout(this.timerId); - return this.waiting = false; - } - }, - startTimer: function(callback, ms) { - if (this.waiting) { - return; - } - this.waiting = true; - return this.timerId = setTimeout(callback, ms); - }, - queue: function(s) { - if (this.useNumPrefix && s.length === 1 && s.search(/[0-9]/) >= 0 && this.a.length === 0) { - this.times += s; - } else { - this.a += s; - } - return this; - }, - reset: function() { - this.a = ""; - this.times = ""; - return this.stopTimer(); - }, - isWaiting: function() { - return this.waiting; - }, - getTimes: function() { - if (this.times.length > 0) { - return parseInt(this.times, 10); - } else { - return null; - } - }, - getNextKeySequence: function() { - var ret, - _this = this; - this.stopTimer(); - if (this.model.isValidKeySeq(this.times + this.a)) { - ret = { - times: null, - seq: this.times + this.a - }; - this.reset(); - return ret; - } else if (this.model.isValidKeySeq(this.a)) { - ret = { - times: this.getTimes(), - seq: "" + this.a - }; - this.reset(); - return ret; - } else { - if (this.model.isValidKeySeqAvailable(this.times + this.a) || this.model.isValidKeySeqAvailable(this.a)) { - this.startTimer(function() { - _this.a = ""; - _this.times = ""; - return _this.waiting = false; - }, this.timeout); - } else { - g.logger.d("invalid key sequence: " + this.a); - this.reset(); - } - return null; - } - }, - setUseNumPrefix: function(useNumPrefix) { - this.useNumPrefix = useNumPrefix; - return this; - } - }; - - function CommandManager(model, timeout, useNumPrefix) { - this.model = model; - if (timeout == null) { - timeout = 2000; - } - if (useNumPrefix == null) { - useNumPrefix = true; - } - this.keyQueue.init(this.model, timeout, useNumPrefix); - } - - CommandManager.prototype.setTimeout = function(timeout) { - return this.keyQueue.timeout = timeout; - }; - - CommandManager.prototype.getCommandFromKeySeq = function(s, keyMap) { - var keySeq; - this.keyQueue.queue(s); - keySeq = this.keyQueue.getNextKeySequence(); - if (keyMap && keySeq) { - return { - times: keySeq.times, - str: keyMap[keySeq.seq] - }; - } else { - return null; - } - }; - - CommandManager.prototype.reset = function() { - return this.keyQueue.reset(); - }; - - CommandManager.prototype.isWaitingNextKey = function() { - return this.keyQueue.isWaiting(); - }; - - CommandManager.prototype.setUseNumPrefix = function(use) { - return this.keyQueue.setUseNumPrefix(use); - }; - - CommandManager.prototype.handleKey = function(msg, keyMap) { - var com, s; - s = g.KeyManager.getKeyCodeStr(msg); - com = this.getCommandFromKeySeq(s, keyMap); - if (!com) { - if (this.isWaitingNextKey()) { - event.stopPropagation(); - event.preventDefault(); - } - return; - } - switch (com) { - case "": - break; - case "": - event.stopPropagation(); - return event.preventDefault(); - default: - this.execCommand(com); - event.stopPropagation(); - return event.preventDefault(); - } - }; - - CommandManager.prototype.execCommand = function(com) { - return (new g.CommandExecuter).set(com.str, com.times).parse().execute(); - }; - - return CommandManager; - - })(); - -}).call(this); diff --git a/commandbox.js b/commandbox.js deleted file mode 100644 index ef7fc32..0000000 --- a/commandbox.js +++ /dev/null @@ -1,1043 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var MyCommandManager, commandFixedListener, frameID, g, onRequest, opt, searchFixedListener, searchUpdatedListener, sender, _ref, - __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; }; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - opt = {}; - - frameID = void 0; - - g.CommandExecuter.prototype.solveAlias = function(alias) { - var aliases, command; - aliases = g.commandBox.getAlias(); - alias = aliases[alias]; - while (alias != null) { - command = alias; - alias = aliases[alias]; - } - return command; - }; - - MyCommandManager = (function(_super) { - - __extends(MyCommandManager, _super); - - function MyCommandManager(model, timeout) { - MyCommandManager.__super__.constructor.call(this, model, timeout, false); - } - - MyCommandManager.prototype.execCommand = function(com) { - var args, executer, _base, _name; - executer = (new g.CommandExecuter).set(com.str).parse(); - args = executer.getArgs(); - return typeof (_base = this.model)[_name = "req" + args[0]] === "function" ? _base[_name](args.slice(1)) : void 0; - }; - - return MyCommandManager; - - })(g.CommandManager); - - g.CommandBox = (function() { - - function CommandBox() { - this.inputListeners = []; - } - - CommandBox.prototype.init = function(width, align) { - this.width = width; - this.align = align; - this.box = $('div#vichromebox'); - this.input = $('input#vichromeinput'); - this.modeChar = $('div#vichromemodechar'); - this.inputField = $('div#vichromefield'); - this.box.width(this.width).addClass('vichrome-commandbox' + this.align); - this.input.width(this.width - this.modeChar.width() - 5).val(""); - this.commandManager = new MyCommandManager(this, opt.commandWaitTimeOut); - return this; - }; - - CommandBox.prototype.addInputUpdateListener = function(fn) { - this.inputListeners.push(fn); - return this; - }; - - CommandBox.prototype.attachTo = function() { - $(document.body).append(this.box); - return this; - }; - - CommandBox.prototype.detachFrom = function() { - if (this.candidateBox != null) { - this.candidateBox.stop(); - this.candidateBox.detachFrom(); - } - this.input.val(""); - $(document).unbind(); - document.removeEventListener("keydown", this.onKeyDown); - return this; - }; - - CommandBox.prototype.setFixedListener = function(fixedListener) { - this.fixedListener = fixedListener; - return this; - }; - - CommandBox.prototype.reqFocusNextCandidate = function(args) { - return this.nextCandidate(); - }; - - CommandBox.prototype.reqFocusPrevCandidate = function(args) { - return this.prevCandidate(); - }; - - CommandBox.prototype.reqEscape = function(args) { - chrome.extension.sendRequest({ - command: "PassToFrame", - innerCommand: "Escape" - }); - return this.detachFrom(); - }; - - CommandBox.prototype.handleKey = function(key) { - event.stopPropagation(); - if (this.value().length === 0 && (key.code === "BS" || key.code === "DEL")) { - event.preventDefault(); - this.reqEscape(); - return; - } - if (key.code === "CR") { - if (typeof this.fixedListener === "function") { - this.fixedListener(this.value()); - } - this.detachFrom(); - return; - } - this.commandManager.handleKey(key, this.keyMap); - }; - - CommandBox.prototype.onKeyDown = function(e) { - var code, key; - if (g.KeyManager.isOnlyModifier(e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey)) { - g.logger.d("getHandlableKey:only modefier"); - return; - } - code = g.KeyManager.getLocalKeyCode(e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey); - if (code == null) { - g.logger.d("getHandlableKey:cant be handled"); - return; - } - key = { - code: code, - shift: e.shiftKey, - ctrl: e.ctrlKey, - alt: e.altKey, - meta: e.metaKey - }; - return g.commandBox.handleKey(key); - }; - - CommandBox.prototype.setKeyMap = function(keyMap) { - this.keyMap = keyMap; - return this; - }; - - CommandBox.prototype.setAlias = function(aliases) { - this.aliases = aliases; - return this; - }; - - CommandBox.prototype.getAlias = function() { - return this.aliases; - }; - - CommandBox.prototype.setIncremental = function(incremental) { - this.incremental = incremental; - return this; - }; - - CommandBox.prototype.show = function(modeChar, input) { - var _this = this; - if (input == null) { - input = ""; - } - this.input.attr("value", input); - this.modeChar.html(modeChar); - this.bfInput = input; - this.box.show(); - this.inputField.show(); - $(document).keyup(function(e) { - var listener, val, _i, _len, _ref1; - val = _this.input.val(); - if (_this.selectedCand === val) { - return; - } - if (_this.bfInput !== val && _this.isVisible()) { - _ref1 = _this.inputListeners; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - listener = _ref1[_i]; - listener(val); - } - } - return _this.bfInput = val; - }); - document.addEventListener("keydown", this.onKeyDown, true); - return this; - }; - - CommandBox.prototype.hide = function() { - if (this.isVisible()) { - this.inputField.hide(); - this.input.blur(); - } - return this; - }; - - CommandBox.prototype.focus = function() { - var _ref1; - if ((_ref1 = this.input.get(0)) != null) { - _ref1.focus(); - } - return this; - }; - - CommandBox.prototype.isVisible = function() { - return this.inputField.css('display') !== 'none'; - }; - - CommandBox.prototype.value = function(a) { - if (a != null) { - return this.input.val(a); - } else { - return this.input.val(); - } - }; - - CommandBox.prototype.setCandidateBox = function(candBox) { - if (!opt.enableCompletion) { - return this; - } - if (this.candidateBox != null) { - this.candidateBox.stop(); - this.candidateBox.detachFrom(); - } - this.candidateBox = candBox.init(this.width, this.align); - this.candidateBox.setCommandBox(this); - this.candidateBox.attachTo(this.view).show(); - return this; - }; - - CommandBox.prototype.nextCandidate = function() { - var focused, _ref1; - if (this.candidateBox != null) { - focused = this.candidateBox.focusNext(); - if (focused == null) { - return this; - } - this.selectedCand = (_ref1 = focused.value) != null ? _ref1 : focused.str; - this.value(this.selectedCand); - } - return this; - }; - - CommandBox.prototype.prevCandidate = function() { - var focused, _ref1, _ref2; - if (this.candidateBox != null) { - focused = (_ref1 = this.candidateBox) != null ? _ref1.focusPrev() : void 0; - if (focused == null) { - return this; - } - this.selectedCand = (_ref2 = focused.value) != null ? _ref2 : focused.str; - this.value(this.selectedCand); - } - return this; - }; - - CommandBox.prototype.isValidKeySeq = function(keySeq) { - if (this.keyMap[keySeq]) { - return true; - } else { - return false; - } - }; - - CommandBox.prototype.isValidKeySeqAvailable = function(keySeq) { - var cmpStr, command, length, pos, seq, _ref1; - length = keySeq.length; - _ref1 = this.keyMap; - for (seq in _ref1) { - command = _ref1[seq]; - cmpStr = seq.slice(0, length); - pos = cmpStr.indexOf("<", 0); - if (pos >= 0) { - pos = seq.indexOf(">", pos); - if (pos >= length) { - cmpStr = seq.slice(0, pos + 1); - } - } - if (keySeq === cmpStr) { - return true; - } - } - return false; - }; - - return CommandBox; - - })(); - - g.CandidateBox = (function() { - - CandidateBox.prototype.itemHeight = 22; - - CandidateBox.prototype.winColumns = 20; - - function CandidateBox() { - this.items = {}; - this.sources = {}; - this.selectedListeners = []; - this.index = 0; - this.scrIndex = 0; - } - - CandidateBox.prototype.init = function(width, align) { - this.width = width; - this.align = align; - this.box = $('
').css('min-width', this.width).addClass('vichrome-candbox' + this.align); - return this; - }; - - CandidateBox.prototype.show = function() { - this.box.show(); - return this; - }; - - CandidateBox.prototype.hide = function() { - this.box.hide(); - return this; - }; - - CandidateBox.prototype.addItem = function(id, item) { - this.items[id].push(item); - return this; - }; - - CandidateBox.prototype.getItemCnt = function() { - var items, result, src, _ref1; - result = 0; - _ref1 = this.items; - for (src in _ref1) { - items = _ref1[src]; - result += items.length; - } - return result; - }; - - CandidateBox.prototype.addSource = function(src) { - var _this = this; - this.sources[src.id] = src; - this.items[src.id] = []; - src.addSrcUpdatedListener(function(items) { - _this.items[src.id] = items; - return _this.update(src.id); - }); - return this; - }; - - CandidateBox.prototype.attachTo = function() { - $(document.body).append(this.box); - return this; - }; - - CandidateBox.prototype.detachFrom = function() { - this.box.detach(); - return this; - }; - - CandidateBox.prototype.resetItem = function() { - this.candidates = []; - return this; - }; - - CandidateBox.prototype.makeItemLine = function(src, id, item) { - var dscr, line, srcType, text; - line = $("
"); - text = $("
").html(item.str); - dscr = $("
").html(item.dscr); - srcType = $("
").html(item.source); - line.append(text).append(srcType).append(dscr); - if (item.value != null) { - line.attr("value", item.value); - } - return line; - }; - - CandidateBox.prototype.update = function(id) { - var i, item, _i, _len, _ref1; - $('#vichromecanditem' + ("[source=" + id + "]")).remove(); - _ref1 = this.items[id]; - for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { - item = _ref1[i]; - this.box.append(this.makeItemLine(id, i, item)); - } - return this; - }; - - CandidateBox.prototype.getItem = function(id, num) { - return this.items[id][num]; - }; - - CandidateBox.prototype.scrollTo = function(scrIndex) { - this.scrIndex = scrIndex; - return this.box.get(0).scrollTop = this.itemHeight * this.scrIndex; - }; - - CandidateBox.prototype.scrollDown = function() { - if (this.index >= this.scrIndex + this.winColumns) { - return this.scrollTo(this.scrIndex + 1); - } else if (this.index < this.scrIndex) { - return this.scrollTo(this.index); - } - }; - - CandidateBox.prototype.scrollUp = function() { - if (this.index >= this.scrIndex + this.winColumns) { - return this.scrollTo(this.getItemCnt() - this.winColumns); - } else if (this.index < this.scrIndex) { - return this.scrollTo(this.index); - } - }; - - CandidateBox.prototype.getFocusedValue = function() { - return this.focusedValue; - }; - - CandidateBox.prototype.setFocusedValue = function(focusedValue) { - this.focusedValue = focusedValue; - }; - - CandidateBox.prototype.scrollTop = function() { - return this.scrollTo(0); - }; - - CandidateBox.prototype.scrollBottom = function() { - this.scrIndex = 0; - return this.box.get(0).scrollTop = 0; - }; - - CandidateBox.prototype.removeFocus = function($focused) { - $focused.removeClass("vichrome-canditemfocused"); - return $focused.children().removeClass("vichrome-canditemfocused"); - }; - - CandidateBox.prototype.setFocus = function($settee) { - var val; - $settee.addClass("vichrome-canditemfocused"); - $settee.children().addClass("vichrome-canditemfocused"); - if ((val = $settee.attr("value"))) { - return this.setFocusedValue(val); - } - }; - - CandidateBox.prototype.focusNext = function() { - var $focused, $next; - if (!(this.getItemCnt() > 0)) { - return null; - } - $focused = $("#vichromecanditem.vichrome-canditemfocused"); - this.removeFocus($focused); - $next = $focused.next(); - this.index++; - if ($next.attr("id") !== "vichromecanditem") { - this.index = 0; - $next = $("#vichromecanditem:first-child").first(); - } - this.scrollDown(); - this.setFocus($next); - return this.getItem($next.attr("source"), parseInt($next.attr("num"))); - }; - - CandidateBox.prototype.focusPrev = function() { - var $focused, $next; - if (!(this.getItemCnt() > 0)) { - return null; - } - $focused = $("#vichromecanditem.vichrome-canditemfocused"); - this.removeFocus($focused); - $next = $focused.prev(); - this.index--; - if ($next.attr("id") !== "vichromecanditem") { - $next = $("#vichromecanditem:last-child").last(); - this.index = this.getItemCnt() - 1; - } - this.scrollUp(); - this.setFocus($next); - return this.getItem($next.attr("source"), parseInt($next.attr("num"))); - }; - - CandidateBox.prototype.getFocused = function() { - var $focused; - $focused = $("#vichromecanditem.vichrome-canditemfocused"); - return this.getItem($focused.attr("source"), parseInt($focused.attr("num"))); - }; - - CandidateBox.prototype.onInput = function(word) { - var id, src, _ref1; - if (this.stopped) { - return; - } - _ref1 = this.sources; - for (id in _ref1) { - src = _ref1[id]; - src.cbInputUpdated(word); - } - }; - - CandidateBox.prototype.setCommandBox = function(box) { - var _this = this; - box.addInputUpdateListener(function(word) { - return _this.onInput(word); - }); - return this; - }; - - CandidateBox.prototype.stop = function() { - return this.stopped = true; - }; - - return CandidateBox; - - })(); - - g.CandidateSource = (function() { - - function CandidateSource(maxItems) { - this.maxItems = maxItems != null ? maxItems : 5; - this.updatedListeners = []; - this.items = []; - } - - CandidateSource.prototype.requirePrefix = function(reqPrefix) { - this.reqPrefix = reqPrefix; - return this; - }; - - CandidateSource.prototype.addSrcUpdatedListener = function(listener) { - this.updatedListeners.push(listener); - return this; - }; - - CandidateSource.prototype.addItem = function(item) { - if (this.items.length < this.maxItems || this.maxItems < 0) { - this.items.push(item); - } - return this; - }; - - CandidateSource.prototype.resetItem = function() { - this.items = []; - return this; - }; - - CandidateSource.prototype.notifyUpdated = function() { - var listener, _i, _len, _ref1; - _ref1 = this.updatedListeners; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - listener = _ref1[_i]; - listener(this.items); - } - return this; - }; - - CandidateSource.prototype.cbInputUpdated = function(word) { - var _this = this; - if (this.timer != null) { - clearTimeout(this.timer); - } - if ((this.prefix != null) && word.charAt(1) === " " && word.charAt(0) !== this.prefix) { - g.logger.d("different prefix:" + this.prefix); - this.resetItem(); - this.notifyUpdated(); - return; - } - if (this.reqPrefix && (this.prefix != null)) { - if (word.length < 2 || word.charAt(1) !== " " || word.charAt(0) !== this.prefix) { - this.resetItem(); - this.notifyUpdated(); - return; - } else { - word = word.slice(2); - } - } - return this.timer = setTimeout(function() { - _this.timer = null; - return typeof _this.onInput === "function" ? _this.onInput(word) : void 0; - }, 150); - }; - - return CandidateSource; - - })(); - - g.CandSourceCommand = (function(_super) { - - __extends(CandSourceCommand, _super); - - CandSourceCommand.prototype.id = "Command"; - - function CandSourceCommand(maxItems) { - var _this = this; - this.maxItems = maxItems != null ? maxItems : -1; - CandSourceCommand.__super__.constructor.call(this, this.maxItems); - chrome.extension.sendRequest({ - command: "GetCommandTable" - }, function(msg) { - return _this.commands = msg; - }); - } - - CandSourceCommand.prototype.onInput = function(word) { - var com, _i, _len, _ref1; - if (!(word.length > 0)) { - return; - } - if (this.commands == null) { - return; - } - this.resetItem(); - word = word.toUpperCase(); - _ref1 = this.commands; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - com = _ref1[_i]; - if (com.toUpperCase().slice(0, word.length) === word) { - this.addItem({ - str: com, - source: "Command", - dscr: "" - }); - } - } - return this.notifyUpdated(); - }; - - return CandSourceCommand; - - })(g.CandidateSource); - - g.CandSourceAlias = (function(_super) { - - __extends(CandSourceAlias, _super); - - CandSourceAlias.prototype.id = "Alias"; - - function CandSourceAlias(maxItems) { - var _this = this; - this.maxItems = maxItems != null ? maxItems : -1; - CandSourceAlias.__super__.constructor.call(this, this.maxItems); - chrome.extension.sendRequest({ - command: "GetAliases" - }, function(msg) { - return _this.aliases = msg; - }); - } - - CandSourceAlias.prototype.onInput = function(word) { - var alias, com, _ref1; - if (!(word.length > 0)) { - return; - } - if (this.aliases == null) { - return; - } - this.resetItem(); - word = word.toUpperCase(); - _ref1 = this.aliases; - for (alias in _ref1) { - com = _ref1[alias]; - if (alias.toUpperCase().slice(0, word.length) === word) { - this.addItem({ - str: alias, - source: "Alias", - dscr: com - }); - } - } - return this.notifyUpdated(); - }; - - return CandSourceAlias; - - })(g.CandidateSource); - - g.CandSourceHistory = (function(_super) { - - __extends(CandSourceHistory, _super); - - function CandSourceHistory() { - return CandSourceHistory.__super__.constructor.apply(this, arguments); - } - - CandSourceHistory.prototype.id = "WebHistory"; - - CandSourceHistory.prototype.prefix = "h"; - - CandSourceHistory.prototype.onInput = function(word) { - var _this = this; - if (!(word.length > 0)) { - return; - } - this.resetItem(); - return chrome.extension.sendRequest({ - command: "GetHistory", - value: word - }, function(items) { - var item, str, _i, _len; - if (items == null) { - _this.notifyUpdated(); - return; - } - for (_i = 0, _len = items.length; _i < _len; _i++) { - item = items[_i]; - str = item.title ? item.title : item.url; - _this.addItem({ - str: str, - source: "History", - dscr: item.url, - value: item.url - }); - } - return _this.notifyUpdated(); - }); - }; - - return CandSourceHistory; - - })(g.CandidateSource); - - g.CandSourceBookmark = (function(_super) { - - __extends(CandSourceBookmark, _super); - - function CandSourceBookmark() { - return CandSourceBookmark.__super__.constructor.apply(this, arguments); - } - - CandSourceBookmark.prototype.id = "Bookmark"; - - CandSourceBookmark.prototype.prefix = "b"; - - CandSourceBookmark.prototype.onInput = function(word) { - var _this = this; - if (!(word.length > 0)) { - return; - } - this.resetItem(); - return chrome.extension.sendRequest({ - command: "GetBookmark", - value: word - }, function(nodes) { - var node, _i, _len; - if (nodes == null) { - _this.notifyUpdated(); - return; - } - for (_i = 0, _len = nodes.length; _i < _len; _i++) { - node = nodes[_i]; - _this.addItem({ - str: node.title, - source: "Bookmark", - dscr: node.url, - value: node.url - }); - } - return _this.notifyUpdated(); - }); - }; - - return CandSourceBookmark; - - })(g.CandidateSource); - - g.CandSourceSearchHist = (function(_super) { - - __extends(CandSourceSearchHist, _super); - - CandSourceSearchHist.prototype.id = "SearchHistory"; - - function CandSourceSearchHist(maxItems) { - var _this = this; - this.maxItems = maxItems; - CandSourceSearchHist.__super__.constructor.call(this, this.maxItems); - chrome.extension.sendRequest({ - command: "GetSearchHistory" - }, function(msg) { - var len; - len = msg.value.length; - _this.history = msg.value.slice(len - _this.maxItems, len); - return _this.onInput(""); - }); - } - - CandSourceSearchHist.prototype.onInput = function(word) { - var hist, _i, _len, _ref1; - if (this.history == null) { - return; - } - this.resetItem(); - word = word.toUpperCase(); - _ref1 = this.history; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - hist = _ref1[_i]; - if (hist.toUpperCase().slice(0, word.length) === word) { - this.addItem({ - str: hist, - source: "Search History", - dscr: "" - }); - } - } - return this.notifyUpdated(); - }; - - return CandSourceSearchHist; - - })(g.CandidateSource); - - g.CandSourceGoogleSuggest = (function(_super) { - - __extends(CandSourceGoogleSuggest, _super); - - function CandSourceGoogleSuggest() { - return CandSourceGoogleSuggest.__super__.constructor.apply(this, arguments); - } - - CandSourceGoogleSuggest.prototype.id = "GoogleSuggest"; - - CandSourceGoogleSuggest.prototype.prefix = "g"; - - CandSourceGoogleSuggest.prototype.onInput = function(word) { - var _this = this; - if (!(word.length > 0)) { - return; - } - this.resetItem(); - return chrome.extension.sendRequest({ - command: "GetGoogleSuggest", - value: word - }, function(raws) { - var raw, value, _i, _len; - if (raws == null) { - _this.notifyUpdated(); - return; - } - for (_i = 0, _len = raws.length; _i < _len; _i++) { - raw = raws[_i]; - value = _this.reqPrefix ? "g " + raw : raw; - _this.addItem({ - str: raw, - source: "Google Search", - dscr: "", - value: value - }); - } - return _this.notifyUpdated(); - }); - }; - - return CandSourceGoogleSuggest; - - })(g.CandidateSource); - - g.CandSourceWebSuggest = (function(_super) { - - __extends(CandSourceWebSuggest, _super); - - function CandSourceWebSuggest() { - return CandSourceWebSuggest.__super__.constructor.apply(this, arguments); - } - - CandSourceWebSuggest.prototype.id = "WebSuggest"; - - CandSourceWebSuggest.prototype.prefix = "w"; - - CandSourceWebSuggest.prototype.onInput = function(word) { - var _this = this; - if (!(word.length > 0)) { - return; - } - this.resetItem(); - if (word.charAt(1) === " " && word.charAt(0) !== "w") { - this.notifyUpdated(); - return; - } - return chrome.extension.sendRequest({ - command: "GetWebSuggest", - value: word - }, function(results) { - var res, _i, _len; - if (results == null) { - _this.notifyUpdated(); - return; - } - for (_i = 0, _len = results.length; _i < _len; _i++) { - res = results[_i]; - _this.addItem({ - str: res.titleNoFormatting, - source: "Web", - dscr: res.unescapedUrl, - value: res.url - }); - } - return _this.notifyUpdated(); - }); - }; - - return CandSourceWebSuggest; - - })(g.CandidateSource); - - g.CandSourceTabs = (function(_super) { - - __extends(CandSourceTabs, _super); - - CandSourceTabs.prototype.id = "Tabs"; - - function CandSourceTabs(maxItems) { - var _this = this; - this.maxItems = maxItems != null ? maxItems : -1; - chrome.extension.sendRequest({ - command: "GetTabList" - }, function(tabs) { - _this.tabs = tabs; - return _this.onInput(""); - }); - CandSourceTabs.__super__.constructor.call(this, this.maxItems); - } - - CandSourceTabs.prototype.onInput = function(word) { - var a, tab, _i, _len, _ref1; - if (this.tabs == null) { - return; - } - this.resetItem(); - word = word.toUpperCase(); - _ref1 = this.tabs; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - tab = _ref1[_i]; - a = tab.title.toUpperCase(); - if (tab.title.toUpperCase().indexOf(word) >= 0) { - this.addItem({ - str: tab.title, - source: "", - dscr: "index:" + (tab.index + 1), - value: "" + (tab.index + 1) - }); - } - } - return this.notifyUpdated(); - }; - - return CandSourceTabs; - - })(g.CandidateSource); - - sender = 0; - - searchFixedListener = function(word) { - return chrome.extension.sendRequest({ - command: "PassToFrame", - innerCommand: "NotifySearchFixed", - word: word, - frameID: sender - }); - }; - - searchUpdatedListener = function(word) { - return chrome.extension.sendRequest({ - command: "PassToFrame", - innerCommand: "NotifyInputUpdated", - word: word, - frameID: sender - }); - }; - - commandFixedListener = function(word) { - chrome.extension.sendRequest({ - command: "TopFrame", - innerCommand: "HideCommandFrame" - }); - return chrome.extension.sendRequest({ - command: "PassToFrame", - innerCommand: "ExecuteCommand", - commandLine: word, - frameID: sender - }); - }; - - onRequest = function(req) { - var candBox, obj, reqPrefix, src, _i, _j, _len, _len1, _ref1, _ref2, _ref3, _ref4; - switch (req.mode) { - case "Command": - sender = req.sender; - window.focus(); - candBox = new g.CandidateBox; - _ref1 = req.sources; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - src = _ref1[_i]; - reqPrefix = (_ref2 = src.reqPrefix) != null ? _ref2 : false; - obj = (new g[src["class"]](src.num)).requirePrefix(reqPrefix); - candBox.addSource(obj); - } - if (g.commandBox != null) { - g.commandBox.detachFrom(); - } - return g.commandBox = (new g.CommandBox).init(opt.commandBoxWidth, opt.commandBoxAlign).attachTo().show(req.modeChar).focus().setKeyMap(req.keyMap).setAlias(req.aliases).setFixedListener(commandFixedListener).setCandidateBox(candBox); - case "Search": - sender = req.sender; - window.focus(); - candBox = new g.CandidateBox; - _ref3 = req.sources; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - src = _ref3[_j]; - reqPrefix = (_ref4 = src.reqPrefix) != null ? _ref4 : false; - obj = (new g[src["class"]](src.num)).requirePrefix(reqPrefix); - candBox.addSource(obj); - } - if (g.commandBox != null) { - g.commandBox.detachFrom(); - } - g.commandBox = (new g.CommandBox).init(opt.commandBoxWidth, opt.commandBoxAlign).attachTo().show(req.modeChar).focus().setIncremental(req.incSearch).setKeyMap(req.keyMap).setAlias(req.aliases).setFixedListener(searchFixedListener).setCandidateBox(candBox); - if (req.incSearch) { - return g.commandBox.addInputUpdateListener(searchUpdatedListener); - } - } - }; - - $(document).ready(function() { - g.logger.d("commandbox ready", this); - chrome.extension.sendRequest({ - command: "InitCommandFrame" - }, function(msg) { - frameID = msg.frameID; - opt.enableCompletion = msg.enableCompletion; - opt.commandBoxWidth = msg.commandBoxWidth; - opt.commandBoxAlign = msg.commandBoxAlign; - return opt.commandWaitTimeOut = msg.commandWaitTimeOut; - }); - return chrome.extension.onRequest.addListener(function(req, sender, sendResponse) { - if (!((req.frameID != null) && req.frameID === frameID)) { - g.logger.d("onRequest: different frameID"); - sendResponse(); - return; - } - return onRequest(req); - }); - }); - -}).call(this); diff --git a/eventhandler.js b/eventhandler.js deleted file mode 100644 index 6cb8469..0000000 --- a/eventhandler.js +++ /dev/null @@ -1,174 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.EventHandler = (function() { - - function EventHandler(model) { - this.model = model; - } - - EventHandler.prototype.onBlur = function(e) { - g.logger.d("onBlur", e); - return this.model.onBlur(e.target); - }; - - EventHandler.prototype.onKeyPress = function(e) { - if (g.model.isInSearchMode() || g.model.isInCommandMode()) { - if (!e.ctrlKey && !e.altKey && !e.metaKey) { - return event.stopPropagation(); - } - } - }; - - EventHandler.prototype.onKeyDown = function(e) { - var msg; - g.logger.d("onKeyDown", e); - msg = this.getHandlableKey(e); - if (msg != null) { - return this.model.handleKey(msg); - } - }; - - EventHandler.prototype.getHandlableKey = function(e) { - var code; - if (g.KeyManager.isOnlyModifier(e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey)) { - g.logger.d("getHandlableKey:only modifier"); - return void 0; - } - code = g.KeyManager.getLocalKeyCode(e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey); - if (code == null) { - g.logger.d("getHandlableKey:cant be handled"); - return void 0; - } - if (this.model.prePostKeyEvent(code, e.ctrlKey, e.altKey, e.metaKey)) { - return { - code: code, - shift: e.shiftKey, - ctrl: e.ctrlKey, - alt: e.altKey, - meta: e.metaKey - }; - } else { - g.logger.d("prePostKeyEvent:key ignored by current mode"); - } - }; - - EventHandler.prototype.onFocus = function(e) { - g.logger.d("onFocus", e.target); - return this.model.onFocus(e.target); - }; - - EventHandler.prototype.onMouseDown = function(e) { - g.logger.d("onFocus", e); - return this.model.onMouseDown(e); - }; - - EventHandler.prototype.addWindowListeners = function() { - var _this = this; - document.addEventListener("keydown", (function(e) { - return _this.onKeyDown(e); - }), true); - document.addEventListener("keypress", (function(e) { - return _this.onKeyPress(e); - }), true); - document.addEventListener("focus", (function(e) { - return _this.onFocus(e); - }), true); - document.addEventListener("blur", (function(e) { - return _this.onBlur(e); - }), true); - return document.addEventListener("mousedown", (function(e) { - return _this.onMouseDown(e); - }), true); - }; - - EventHandler.prototype.addExtListener = function() { - var _this = this; - return chrome.extension.onRequest.addListener(function(req, sender, sendResponse) { - var a, aliases, com, commands, method, _ref1, _ref2; - g.logger.d("onRequest command: " + req.command); - if ((req.frameID != null) && req.frameID !== g.model.frameID) { - g.logger.d("onRequest: different frameID"); - return; - } - switch (req.command) { - case "GetCommandTable": - commands = []; - _ref1 = g.CommandExecuter.prototype.commandTable; - for (com in _ref1) { - method = _ref1[com]; - commands.push(com); - } - return sendResponse(commands); - case "GetAliases": - aliases = {}; - _ref2 = g.model.getAlias(); - for (a in _ref2) { - com = _ref2[a]; - aliases[a] = com; - } - return sendResponse(aliases); - case "OpenCommandBox": - g.model.openCommandBox(req); - return sendResponse(); - case "ExecuteCommand": - g.model.curMode.reqExecuteCommand(req); - return sendResponse(); - case "NotifyInputUpdated": - g.model.curMode.notifyInputUpdated(req); - return sendResponse(); - case "NotifySearchFixed": - g.model.curMode.notifySearchFixed(req); - return sendResponse(); - case "HideCommandFrame": - g.view.hideCommandFrame(); - return sendResponse(); - case "SetStatusLine": - g.view.setStatusLineText(req.text, req.timeout); - return sendResponse(); - case "HideStatusLine": - g.view.hideStatusLine(); - return sendResponse(); - default: - g.model.triggerCommand("req" + req.command, req.args, req.times, req.timesSpecified); - return sendResponse(); - } - }); - }; - - EventHandler.prototype.init = function() { - this.addWindowListeners(); - return this.addExtListener(); - }; - - EventHandler.prototype.onInitEnabled = function(msg) { - this.init(); - return this.model.onInitEnabled(msg); - }; - - EventHandler.prototype.onCommandResponse = function(msg) { - if (msg == null) { - return; - } - if (msg.command === "Settings") { - this.model.onSettings(msg); - } - if ((msg.error != null) && msg.error === true) { - g.logger.e("onCommandResponse: error occured!!!", msg); - g.model.curMode.reqEscape(); - return g.view.setStatusLineText("Error:" + msg.errorMsg, 3000); - } - }; - - return EventHandler; - - })(); - -}).call(this); diff --git a/key.js b/key.js deleted file mode 100644 index 3e4440f..0000000 --- a/key.js +++ /dev/null @@ -1,321 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, keyCodes, keyIdentifier, shiftWinKeyIdentifier_ja, shiftWinKeyIdentifier_us, util, winKeyIdentifier_ja, winKeyIdentifier_us, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.key = {}; - - g.key.keyCodes = { - ESC: 27, - TAB: 9, - SHIFT: 16, - BS: 8, - ALT: 18, - CTRL: 17, - META: 91, - DEL: 46, - CR: 13, - SPACE: 32, - LEFT: 128, - UP: 129, - RIGHT: 130, - DOWN: 131, - F1: 132, - F2: 133, - F3: 134, - F4: 135, - F5: 136, - F6: 137, - F7: 138, - F8: 139, - F9: 140, - F10: 141, - F11: 142, - F12: 143 - }; - - g.key.keyIdentifier = { - "U+0031": "1", - "U+0032": "2", - "U+0033": "3", - "U+0034": "4", - "U+0035": "5", - "U+0036": "6", - "U+0037": "7", - "U+0038": "8", - "U+0039": "9", - "U+0030": "0", - "U+0021": "!", - "U+0022": '"', - "U+0023": "#", - "U+0024": "$", - "U+0025": "%", - "U+0026": "&", - "U+0027": "'", - "U+0028": "(", - "U+0029": ")", - "U+002D": "-", - "U+003D": "=", - "U+005E": "^", - "U+007E": "~", - "U+00A5": "\\", - "U+005C": "\\", - "U+007C": "|", - "U+0041": "a", - "U+0042": "b", - "U+0043": "c", - "U+0044": "d", - "U+0045": "e", - "U+0046": "f", - "U+0047": "g", - "U+0048": "h", - "U+0049": "i", - "U+004A": "j", - "U+004B": "k", - "U+004C": "l", - "U+004D": "m", - "U+004E": "n", - "U+004F": "o", - "U+0050": "p", - "U+0051": "q", - "U+0052": "r", - "U+0053": "s", - "U+0054": "t", - "U+0055": "u", - "U+0056": "v", - "U+0057": "w", - "U+0058": "x", - "U+0059": "y", - "U+005A": "z", - "U+0040": "@", - "U+0060": "`", - "U+005B": "[", - "U+007B": "{", - "U+003B": ";", - "U+002B": "+", - "U+003A": ":", - "U+002A": "*", - "U+005D": "]", - "U+007D": "}", - "U+002C": ",", - "U+003C": "<", - "U+002E": ".", - "U+003E": ">", - "U+002F": "/", - "U+003F": "?", - "U+005F": "_", - "U+0020": "SPACE", - "Left": "LEFT", - "Down": "DOWN", - "Up": "UP", - "Right": "RIGHT", - "Enter": "CR", - "U+0008": "BS", - "U+007F": "DEL", - "U+0009": "TAB", - "F1": "F1", - "F2": "F2", - "F3": "F3", - "F4": "F4", - "F5": "F5", - "F6": "F6", - "F7": "F7", - "F8": "F8", - "F9": "F9", - "F10": "F10", - "F11": "F11", - "F12": "F12", - "U+001B": "ESC", - "Home": "HOME", - "End": "END", - "Control": "CTRL", - "Shift": "SHIFT", - "Alt": "ALT", - "Meta": "META", - "PageDown": "PAGEDOWN", - "PageUp": "PAGEUP", - "CapsLock": "CAPSLOCK" - }; - - g.key.winKeyIdentifier_ja = { - "U+00BC": ",", - "U+00BE": ".", - "U+00BF": "/", - "U+00E2": "\\", - "U+00BB": ";", - "U+00BA": ":", - "U+00DD": "]", - "U+00C0": "@", - "U+00DB": "[", - "U+00BD": "-", - "U+00DE": "^", - "U+00DC": "\\" - }; - - g.key.shiftWinKeyIdentifier_ja = { - "U+00BC": "<", - "U+00BE": ">", - "U+00BF": "?", - "U+00E2": "_", - "U+00BB": "+", - "U+00BA": "*", - "U+00DD": "}", - "U+00C0": "`", - "U+00DB": "{", - "U+00BD": "=", - "U+00DE": "~", - "U+00DC": "|", - "U+0031": "!", - "U+0032": '"', - "U+0033": "#", - "U+0034": "$", - "U+0035": "%", - "U+0036": "&", - "U+0037": "'", - "U+0038": "(", - "U+0039": ")" - }; - - g.key.winKeyIdentifier_us = { - "U+00BC": ",", - "U+00BE": ".", - "U+00BF": "/", - "U+00BB": "=", - "U+00BA": ";", - "U+00DD": "]", - "U+00DB": "[", - "U+00BD": "-", - "U+00DC": "\\", - "U+00DE": "'", - "U+0060": "`" - }; - - g.key.shiftWinKeyIdentifier_us = { - "U+00BC": "<", - "U+00BE": ">", - "U+00BF": "?", - "U+00BB": "+", - "U+00BA": ":", - "U+00DD": "}", - "U+00DB": "{", - "U+00BD": "_", - "U+0038": "*", - "U+00DC": "|", - "U+007E": "~", - "U+0036": "^", - "U+0031": "!", - "U+00DE": '"', - "U+0032": "@", - "U+0033": "#", - "U+0034": "$", - "U+0035": "%", - "U+0037": "&", - "U+0039": "(", - "U+0030": ")" - }; - - keyCodes = g.key.keyCodes; - - keyIdentifier = g.key.keyIdentifier; - - winKeyIdentifier_ja = g.key.winKeyIdentifier_ja; - - shiftWinKeyIdentifier_ja = g.key.shiftWinKeyIdentifier_ja; - - winKeyIdentifier_us = g.key.winKeyIdentifier_us; - - shiftWinKeyIdentifier_us = g.key.shiftWinKeyIdentifier_us; - - util = g.util; - - g.KeyManager = { - isAlphabet: function(str) { - var c; - if (str.length !== 1) { - return false; - } - c = str.charCodeAt(0); - return ((65 <= c && c <= 90)) || ((97 <= c && c <= 122)); - }, - isNumber: function(str) { - var c; - if (str.length !== 1) { - return false; - } - c = str.charCodeAt(0); - return (48 <= c && c <= 57); - }, - isOnlyModifier: function(code, ctrl, shift, alt, meta) { - switch (keyCodes[this.getLocalKeyCode(code, ctrl, shift, alt, meta)]) { - case keyCodes.CTRL: - case keyCodes.SHIFT: - case keyCodes.META: - case keyCodes.ALT: - return true; - default: - return false; - } - }, - getKeyCodeStr: function(msg) { - var result; - result = msg.code; - if (msg.ctrl) { - result = "C-" + result; - } - if (msg.alt) { - result = "A-" + result; - } - if (msg.meta) { - result = "M-" + result; - } - if (msg.ctrl || msg.alt || msg.meta || keyCodes[msg.code]) { - if (keyCodes[msg.code] ? msg.shift : void 0) { - result = "S-" + result; - } - result = "<" + result + ">"; - } - return result; - }, - getLocalKeyCode: function(code, ctrl, shift, alt, meta) { - var result; - result = keyIdentifier[code]; - if (util.getPlatform() !== "Mac") { - if (g.util.getLang() === "ja") { - if (shift) { - if (shiftWinKeyIdentifier_ja[code] != null) { - result = shiftWinKeyIdentifier_ja[code]; - } - } else { - if (winKeyIdentifier_ja[code] != null) { - result = winKeyIdentifier_ja[code]; - } - } - } else { - if (shift) { - if (shiftWinKeyIdentifier_us[code] != null) { - result = shiftWinKeyIdentifier_us[code]; - } - } else { - if (winKeyIdentifier_us[code] != null) { - result = winKeyIdentifier_us[code]; - } - } - } - } - if ((result != null) && this.isAlphabet(result)) { - if (shift) { - result = result.toUpperCase(); - } else { - result = result.toLowerCase(); - } - } - return result; - } - }; - -}).call(this); diff --git a/mode.js b/mode.js deleted file mode 100644 index 695c684..0000000 --- a/mode.js +++ /dev/null @@ -1,931 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref, - __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; }; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.Mode = (function() { - - function Mode() {} - - Mode.prototype.exit = function() {}; - - Mode.prototype.enter = function() {}; - - Mode.prototype.getUseNumPrefix = function() { - return false; - }; - - Mode.prototype.enterInteractiveOpen = function(baseCom, opt) { - var dscr, executer, sources; - dscr = baseCom; - sources = []; - if (opt.bookmark) { - dscr += " Bookmark"; - sources.push({ - "class": "CandSourceBookmark" - }); - } - if (opt.history) { - dscr += " History"; - sources.push({ - "class": "CandSourceHistory" - }); - } - if (opt.web) { - dscr += " Web"; - sources.push({ - "class": "CandSourceWebSuggest" - }); - } - if (!opt.bookmark && !opt.history && !opt.web) { - if (opt.search) { - baseCom += " g"; - dscr += " Google Search"; - sources = [ - { - "class": "CandSourceGoogleSuggest" - } - ]; - } else { - sources = [ - { - "class": "CandSourceGoogleSuggest", - num: 3, - reqPrefix: true - }, { - "class": "CandSourceWebSuggest", - num: 3 - }, { - "class": "CandSourceBookmark", - num: 3 - }, { - "class": "CandSourceHistory", - num: 3 - } - ]; - } - } - executer = (new g.CommandExecuter).setDescription(dscr).set(baseCom); - return g.model.enterCommandMode(executer, sources); - }; - - 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]; - switch (arg) { - case "-i": - interactive = true; - break; - case "-b": - bookmark = true; - break; - case "-w": - web = true; - break; - case "-h": - history = true; - break; - case "-g": - case "g": - search = true; - break; - default: - urls.push(arg.replace(/%url/g, g.view.getHref())); - } - } - if (interactive || bookmark || history || web) { - opt = { - bookmark: bookmark, - history: history, - web: web, - search: search - }; - com = "Open" + urls.join(' '); - return this.enterInteractiveOpen(com, opt); - } else if (search) { - word = ""; - for (_j = 0, _len1 = urls.length; _j < _len1; _j++) { - i = urls[_j]; - word += "+" + encodeURIComponent(i); - } - word = word.substr(1); - url = "http://" + g.model.getSetting("searchEngine") + "/search?gcx=c&sourceid=chrome&ie=UTF-8&q=" + word + "&qscrl=1"; - return g.view.open(url, "_self"); - } else { - return chrome.extension.sendRequest({ - command: "ExtendURL", - url: urls[0] - }, function(url) { - return g.view.open(url, "_self"); - }); - } - }; - - 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; - } - for (_i = 0, _len = args.length; _i < _len; _i++) { - arg = args[_i]; - switch (arg) { - case "-i": - interactive = true; - break; - case "-b": - bookmark = true; - break; - case "-w": - web = true; - break; - case "-h": - history = true; - break; - case "-g": - case "g": - search = true; - break; - default: - words.push(arg.replace(/%url/g, g.view.getHref())); - } - } - if (interactive || bookmark || history || web) { - opt = { - bookmark: bookmark, - history: history, - web: web, - search: search - }; - com = "TabOpenNew " + words.join(' '); - return this.enterInteractiveOpen(com, opt); - } else if (search) { - word = ""; - for (_j = 0, _len1 = words.length; _j < _len1; _j++) { - i = words[_j]; - word += "+" + encodeURIComponent(i); - } - word = word.substr(1); - url = "http://" + g.model.getSetting("searchEngine") + "/search?gcx=c&sourceid=chrome&ie=UTF-8&q=" + word + "&qscrl=1"; - return chrome.extension.sendRequest({ - command: "TabOpenNew", - args: [url], - times: times - }, g.handler.onCommandResponse); - } else { - return chrome.extension.sendRequest({ - command: "TabOpenNew", - args: words, - times: times, - extend: true - }, g.handler.onCommandResponse); - } - }; - - Mode.prototype.blur = function() {}; - - Mode.prototype.reqScrollDown = function(args, times) { - return g.view.scrollBy(0, g.model.getSetting("scrollPixelCount") * times); - }; - - Mode.prototype.reqScrollUp = function(args, times) { - return g.view.scrollBy(0, -g.model.getSetting("scrollPixelCount") * times); - }; - - Mode.prototype.reqScrollLeft = function(args, times) { - return g.view.scrollBy(-g.model.getSetting("scrollPixelCount") * times, 0); - }; - - Mode.prototype.reqScrollRight = function(args, times) { - return g.view.scrollBy(g.model.getSetting("scrollPixelCount") * times, 0); - }; - - Mode.prototype.reqPageHalfDown = function(args, times) { - return g.view.scrollHalfPage({ - hor: 0, - ver: times - }); - }; - - Mode.prototype.reqPageHalfUp = function(args, times) { - return g.view.scrollHalfPage({ - hor: 0, - ver: -times - }); - }; - - Mode.prototype.reqPageDown = function(args, times) { - return g.view.scrollHalfPage({ - hor: 0, - ver: 2 * times - }); - }; - - Mode.prototype.reqPageUp = function(args, times) { - return g.view.scrollHalfPage({ - hor: 0, - ver: -2 * times - }); - }; - - Mode.prototype.reqGoTop = function() { - g.model.setPageMark(); - return g.view.goTop(); - }; - - Mode.prototype.reqGoBottom = function() { - g.model.setPageMark(); - return g.view.goBottom(); - }; - - Mode.prototype.reqBackHist = function() { - return g.view.backHist(); - }; - - Mode.prototype.reqForwardHist = function() { - return g.view.forwardHist(); - }; - - Mode.prototype.reqTabReload = function() { - return g.view.reload(); - }; - - Mode.prototype.reqGoSearchModeForward = function() { - return g.model.enterSearchMode(false); - }; - - Mode.prototype.reqGoSearchModeBackward = function() { - return g.model.enterSearchMode(true); - }; - - Mode.prototype.reqGoLinkTextSearchMode = function() { - return g.model.enterSearchMode(false, new g.LinkTextSearcher); - }; - - Mode.prototype.reqGoEmergencyMode = function() { - return g.model.enterEmergencyMode(); - }; - - Mode.prototype.reqBackToPageMark = function() { - return g.model.goPageMark(); - }; - - Mode.prototype.reqEscape = function() { - g.view.blurActiveElement(); - g.model.escape(); - return typeof this.escape === "function" ? this.escape() : void 0; - }; - - 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) { - case "--newtab": - newTab = true; - break; - case "--continuous": - continuous = true; - } - } - opt = { - newTab: newTab, - continuous: continuous - }; - return g.model.enterFMode(opt); - }; - - Mode.prototype.reqGoCommandMode = function(args) { - var sources; - sources = [ - { - "class": "CandSourceCommand" - }, { - "class": "CandSourceAlias" - } - ]; - return g.model.enterCommandMode(new g.CommandExecuter, sources); - }; - - Mode.prototype.reqFocusOnFirstInput = function(args, times) { - g.model.setPageMark(); - return g.view.focusInput(times - 1); - }; - - Mode.prototype.reqTabList = function() { - var executer, sources; - sources = [ - { - "class": "CandSourceTabs" - } - ]; - executer = (new g.CommandExecuter).set("MoveToNextTab").setDescription("TabList"); - return g.model.enterCommandMode(executer, sources); - }; - - Mode.prototype.reqBarrelRoll = function() { - $(document.body).addClass('vichrome-barrelroll'); - return setTimeout(function() { - return $(document.body).removeClass('vichrome-barrelroll'); - }, 2000); - }; - - Mode.prototype.reqHideJimmy = function() { - return $("div#centralNotice").hide(); - }; - - 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); - return document.images[0].dispatchEvent(evt); - } - }; - - Mode.prototype.req_ChangeLogLevel = function(args) { - if (!args || args.length < 1) { - return; - } - if (g.logLevels[args[0]] != null) { - return g.LOG_LEVEL = g.logLevels[args[0]]; - } else { - return g.view.setStatusLineText("log level '" + args[0] + "' doesn't exist", 2000); - } - }; - - Mode.prototype.getKeyMapping = function() { - return g.model.getNMap(); - }; - - return Mode; - - })(); - - g.NormalMode = (function(_super) { - - __extends(NormalMode, _super); - - function NormalMode() { - return NormalMode.__super__.constructor.apply(this, arguments); - } - - NormalMode.prototype.getName = function() { - return "NormalMode"; - }; - - NormalMode.prototype.getUseNumPrefix = function() { - return true; - }; - - NormalMode.prototype.prePostKeyEvent = function(key, ctrl, alt, meta) { - return true; - }; - - NormalMode.prototype.escape = function() { - return g.model.cancelSearchHighlight(); - }; - - NormalMode.prototype.enter = function() {}; - - NormalMode.prototype.reqNextSearch = function() { - return g.model.goNextSearchResult(false); - }; - - NormalMode.prototype.reqPrevSearch = function() { - return g.model.goNextSearchResult(true); - }; - - return NormalMode; - - })(g.Mode); - - g.InsertMode = (function(_super) { - - __extends(InsertMode, _super); - - function InsertMode() { - return InsertMode.__super__.constructor.apply(this, arguments); - } - - InsertMode.prototype.getName = function() { - return "InsertMode"; - }; - - InsertMode.prototype.blur = function() { - return g.model.enterNormalMode(); - }; - - InsertMode.prototype.getKeyMapping = function() { - return g.model.getIMap(); - }; - - InsertMode.prototype.prePostKeyEvent = function(key, ctrl, alt, meta) { - if (ctrl || alt || meta) { - return true; - } - if (g.KeyManager.isNumber(key) || g.KeyManager.isAlphabet(key)) { - return false; - } - return true; - }; - - return InsertMode; - - })(g.Mode); - - g.SearchMode = (function(_super) { - - __extends(SearchMode, _super); - - function SearchMode() { - return SearchMode.__super__.constructor.apply(this, arguments); - } - - SearchMode.prototype.getName = function() { - return "SearchMode"; - }; - - SearchMode.prototype.init = function(searcher_, backward_, opt_) { - this.opt = opt_ != null ? opt_ : { - wrap: g.model.getSetting("wrapSearch"), - ignoreCase: g.model.getSetting("ignoreCase"), - incSearch: g.model.getSetting("incSearch"), - useMigemo: g.model.getSetting("useMigemo"), - minIncSearch: g.model.getSetting("minIncSearch"), - minMigemoLength: g.model.getSetting("minMigemoLength"), - backward: backward_ - }; - this.searcher = searcher_.init(this.opt); - this.backward = backward_; - return this; - }; - - SearchMode.prototype.cancelSearch = function() { - g.model.goPageMark(); - this.searcher.finalize(); - return g.model.enterNormalMode(); - }; - - SearchMode.prototype.prePostKeyEvent = function(key, ctrl, alt, meta) { - return true; - }; - - SearchMode.prototype.escape = function() { - return this.cancelSearch(); - }; - - SearchMode.prototype.enter = function() { - var param, sources; - sources = [ - { - "class": "CandSourceSearchHist" - } - ]; - g.view.setStatusLineText(""); - param = { - sources: sources, - mode: 'Search', - modeChar: this.backward === true ? '?' : '/', - incSearch: this.opt.incSearch - }; - return g.model.openCommandBox(param); - }; - - SearchMode.prototype.exit = function() { - g.view.hideCommandFrame(); - return window.focus(); - }; - - SearchMode.prototype.notifyInputUpdated = function(msg) { - var _this = this; - if (this.waiting) { - clearTimeout(this.timerId); - } - this.timerId = setTimeout(function() { - g.logger.e("set"); - _this.searcher.updateInput(msg.word); - return _this.waiting = false; - }, 200); - return this.waiting = true; - }; - - SearchMode.prototype.notifySearchFixed = function(msg) { - if (this.waiting) { - clearTimeout(this.timerId); - this.waiting = false; - } - this.searcher.fix(msg.word); - g.model.setSearcher(this.searcher); - return g.model.enterNormalMode(); - }; - - SearchMode.prototype.getKeyMapping = function() { - return g.model.getCMap(); - }; - - return SearchMode; - - })(g.Mode); - - g.CommandMode = (function(_super) { - - __extends(CommandMode, _super); - - function CommandMode() { - return CommandMode.__super__.constructor.apply(this, arguments); - } - - CommandMode.prototype.getName = function() { - return "CommandMode"; - }; - - CommandMode.prototype.reqExecuteCommand = function(req) { - try { - this.executer.set(req.commandLine).parse().execute(); - g.view.hideStatusLine(); - } catch (e) { - g.view.setStatusLineText("Command Not Found : " + this.executer.get(), 2000); - } - return g.model.enterNormalMode(); - }; - - CommandMode.prototype.prePostKeyEvent = function(key, ctrl, alt, meta) { - return true; - }; - - CommandMode.prototype.enter = function() { - var param, _ref1; - if ((_ref1 = this.executer) == null) { - this.executer = new g.CommandExecuter; - } - if (this.executer.getDescription() != null) { - g.view.setStatusLineText(this.executer.getDescription()); - } else { - g.view.setStatusLineText(this.executer.get()); - } - param = { - sources: this.sources, - mode: 'Command', - modeChar: ':' - }; - return g.model.openCommandBox(param); - }; - - CommandMode.prototype.exit = function() { - g.view.hideCommandFrame(); - return window.focus(); - }; - - CommandMode.prototype.getKeyMapping = function() { - return g.model.getCMap(); - }; - - CommandMode.prototype.setExecuter = function(executer) { - this.executer = executer; - return this; - }; - - CommandMode.prototype.setSources = function(sources) { - this.sources = sources; - return this; - }; - - return CommandMode; - - })(g.Mode); - - g.EmergencyMode = (function(_super) { - - __extends(EmergencyMode, _super); - - function EmergencyMode() { - return EmergencyMode.__super__.constructor.apply(this, arguments); - } - - EmergencyMode.prototype.getName = function() { - return "EmergencyMode"; - }; - - EmergencyMode.prototype.prePostKeyEvent = function(key, ctrl, alt, meta) { - return true; - }; - - EmergencyMode.prototype.enter = function() { - var key, keyMap, mapped, text; - keyMap = g.model.getEMap(); - text = "Emergency Mode: press "; - for (key in keyMap) { - mapped = keyMap[key]; - if (mapped === "Escape") { - text += key + ", "; - } - } - text = text.replace(//g, ">").replace(/, $/, " "); - text += "to escape"; - return g.view.setStatusLineText(text); - }; - - EmergencyMode.prototype.exit = function() { - return g.view.hideStatusLine(); - }; - - EmergencyMode.prototype.blur = function(target) { - if (g.util.isEmbededFlash(target)) { - return g.model.enterNormalMode(); - } - }; - - EmergencyMode.prototype.getKeyMapping = function() { - return g.model.getEMap(); - }; - - return EmergencyMode; - - })(g.Mode); - - g.FMode = (function(_super) { - - __extends(FMode, _super); - - function FMode() { - return FMode.__super__.constructor.apply(this, arguments); - } - - FMode.prototype.getName = function() { - return "FMode"; - }; - - FMode.prototype.setOption = function(opt) { - this.opt = opt; - return this; - }; - - FMode.prototype.hit = function(i) { - var primary, target; - primary = false; - target = $(this.hints[i].target); - if (target.is('a')) { - primary = this.opt.newTab; - if (!this.opt.continuous) { - g.model.enterNormalMode(); - } - } else { - target.focus(); - if (g.util.isEditable(target.get(0))) { - g.model.enterInsertMode(); - } else { - g.model.enterNormalMode(); - } - } - return g.util.dispatchMouseClickEvent(target.get(0), primary, false, false); - }; - - FMode.prototype.isValidKey = function(key) { - return (this.keys.indexOf(key) >= 0 && key.length === 1) || (key === 'BS') || (key === 'DEL'); - }; - - 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]; - if (this.currentInput === elem.key) { - return i; - } - } - return -1; - }; - - FMode.prototype.treatNewInput = function(key) { - var idx; - if (key === "BS" || key === "DEL") { - if (this.currentInput.length === 0) { - g.model.enterNormalMode(); - return; - } - this.currentInput = this.currentInput.slice(0, this.currentInput.length - 1); - } else { - this.currentInput += key; - } - g.view.setStatusLineText('f Mode : ' + this.currentInput); - if (this.currentInput.length < this.keyLength) { - this.updateHints(); - } else { - idx = this.searchTarget(); - if (idx >= 0) { - this.hit(idx); - } else { - if (!this.opt.continuous) { - g.model.enterNormalMode(); - } - } - if (this.opt.continuous) { - this.currentInput = ""; - return g.view.setStatusLineText('f Mode : '); - } else { - return g.view.hideStatusLine(); - } - } - }; - - FMode.prototype.prePostKeyEvent = function(key, ctrl, alt, meta) { - if (key === "ESC") { - return true; - } - if (ctrl || alt || meta) { - return true; - } - if (g.model.getSetting("fModeIgnoreCase")) { - key = key.toUpperCase(); - } - if (this.isValidKey(key)) { - event.stopPropagation(); - event.preventDefault(); - this.treatNewInput(key); - return false; - } else { - return true; - } - }; - - FMode.prototype.getKeyLength = function(candiNum) { - if (candiNum === 1) { - return 1; - } - if (this.keys.length === 1) { - return 1; - } - return Math.ceil(Math.log(candiNum) / Math.log(this.keys.length)); - }; - - FMode.prototype.updateHints = function() { - var c, hint, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results; - _ref1 = this.hints; - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - hint = _ref1[_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]; - 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]; - hint.elem = hint.elem.append($('').css("color", g.model.getSetting("hintColor")).html(c)); - } - if (!hint.elem.is(':visible')) { - this.showFunc.call(hint.elem); - } - _results.push($(hint.target).addClass('vichrome-fModeTarget')); - } else { - this.hideFunc.call(hint.elem); - _results.push($(hint.target).removeClass('vichrome-fModeTarget')); - } - } - return _results; - }; - - 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; - for (i = _i = 0, _len = links.length; _i < _len; i = ++_i) { - elem = links[i]; - key = ''; - j = this.keyLength; - k = i; - while (j--) { - key = this.keys.charAt(k % this.keys.length) + key; - k /= this.keys.length; - } - this.hints[i] = {}; - this.hints[i].key = key; - this.hints[i].target = elem; - $(elem).addClass('vichrome-fModeTarget'); - } - 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; - _results = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - hint = _ref1[_j]; - offset = hint.target._offset_; - top = offset.top - 7; - left = offset.left - 7; - if (top < 0) { - top = 0; - } - if (left < 0) { - 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]; - elem = elem.append($('').html(c)).css("color", g.model.getSetting("hintColor")).hide(); - } - hint.elem = elem; - $('html').append(hint.elem); - _results.push(this.showFunc.call(hint.elem)); - } - return _results; - }; - - FMode.prototype.enter = function() { - var links; - this.currentInput = ""; - this.hints = []; - if (g.model.getSetting("useFModeAnimation")) { - this.showFunc = function() { - return this.fadeIn(200); - }; - this.hideFunc = function() { - return this.fadeOut(200); - }; - } else { - this.showFunc = $.fn.show; - this.hideFunc = $.fn.hide; - } - 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_ = { - top: offset.top + ~~coords[1], - left: offset.left + ~~coords[0] - }; - } else { - this._offset_ = offset; - } - return links.push(this); - }); - }); - if (links.length === 0) { - g.view.setStatusLineText("No visible links found", 2000); - setTimeout((function() { - return g.model.enterNormalMode(); - }), 0); - return; - } - this.keys = g.model.getSetting("fModeAvailableKeys"); - if (g.model.getSetting("fModeIgnoreCase")) { - this.keys = this.keys.toUpperCase(); - } - this.keyLength = this.getKeyLength(links.length); - this.createHints(links); - return g.view.setStatusLineText('f Mode : '); - }; - - FMode.prototype.exit = function() { - $('span#vichromehint').remove(); - return $('.vichrome-fModeTarget').removeClass('vichrome-fModeTarget'); - }; - - return FMode; - - })(g.Mode); - - $.extend($.expr[':'], { - _visible: function(elem) { - var offset, winH, winLeft, winTop, winW; - winLeft = window.pageXOffset; - winTop = window.pageYOffset; - winH = window.innerHeight; - winW = window.innerWidth; - offset = $(elem).offset(); - if (winTop > offset.top || winTop + winH < offset.top) { - return false; - } - if (winLeft > offset.left || offset.left > winLeft + winW) { - return false; - } - if ($.expr[':'].hidden(elem)) { - return false; - } - if ($.curCSS(elem, 'visibility') === 'hidden') { - return false; - } - elem._offset_ = offset; - return true; - } - }); - -}).call(this); diff --git a/model.js b/model.js deleted file mode 100644 index 349aa2d..0000000 --- a/model.js +++ /dev/null @@ -1,405 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, getAliasFirst, getCMapFirst, getEMapFirst, getIMapFirst, getNMapFirst, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - getNMapFirst = function() { - var map, myMap, nmap, pageMap, url, _ref1; - nmap = g.object(this.getSetting("keyMappingNormal")); - pageMap = this.getSetting("pageMap"); - if (!(((_ref1 = g.view.getHref()) != null ? _ref1.length : void 0) > 0)) { - return nmap; - } - myMap = nmap; - for (url in pageMap) { - map = pageMap[url]; - if (this.isUrlMatched(g.view.getHref(), url)) { - g.extend(map.nmap, myMap); - } - } - this.getNMap = function() { - return myMap; - }; - return myMap; - }; - - getIMapFirst = function() { - var imap, map, myMap, pageMap, url, _ref1; - imap = g.object(this.getSetting("keyMappingInsert")); - pageMap = this.getSetting("pageMap"); - if (!(((_ref1 = g.view.getHref()) != null ? _ref1.length : void 0) > 0)) { - return imap; - } - myMap = imap; - for (url in pageMap) { - map = pageMap[url]; - if (this.isUrlMatched(g.view.getHref(), url)) { - g.extend(map.imap, myMap); - } - } - this.getIMap = function() { - return myMap; - }; - return myMap; - }; - - getCMapFirst = function() { - var cmap, map, myMap, pageMap, url, _ref1; - cmap = g.object(this.getSetting("keyMappingCommand")); - pageMap = this.getSetting("pageMap"); - if (!(((_ref1 = g.view.getHref()) != null ? _ref1.length : void 0) > 0)) { - return cmap; - } - myMap = cmap; - for (url in pageMap) { - map = pageMap[url]; - if (this.isUrlMatched(g.view.getHref(), url)) { - g.extend(map.cmap, myMap); - } - } - this.getCMap = function() { - return myMap; - }; - return myMap; - }; - - getEMapFirst = function() { - var emap, map, myMap, pageMap, url, _ref1; - emap = g.object(this.getSetting("keyMappingEmergency")); - pageMap = this.getSetting("pageMap"); - if (!(((_ref1 = g.view.getHref()) != null ? _ref1.length : void 0) > 0)) { - return emap; - } - myMap = emap; - for (url in pageMap) { - map = pageMap[url]; - if (this.isUrlMatched(g.view.getHref(), url)) { - g.extend(map.emap, myMap); - } - } - this.getEMap = function() { - return myMap; - }; - return myMap; - }; - - getAliasFirst = function() { - var aliases, map, myAlias, pageMap, url, _ref1; - aliases = g.object(this.getSetting("aliases")); - pageMap = this.getSetting("pageMap"); - if (!(((_ref1 = g.view.getHref()) != null ? _ref1.length : void 0) > 0)) { - return aliases; - } - myAlias = aliases; - for (url in pageMap) { - map = pageMap[url]; - if (this.isUrlMatched(g.view.getHref(), url)) { - g.extend(map.alias, myAlias); - } - } - this.getAlias = function() { - return myAlias; - }; - return myAlias; - }; - - g.model = { - initEnabled: false, - domReady: false, - disAutoFocus: false, - searcher: null, - pmRegister: null, - curMode: null, - settings: null, - frameID: 0, - init: function(commandManager, pmRegister) { - this.commandManager = commandManager != null ? commandManager : new g.CommandManager(this); - return this.pmRegister = pmRegister != null ? pmRegister : new g.PageMarkRegister; - }, - changeMode: function(newMode) { - var _ref1; - if (this.curMode != null) { - this.curMode.exit(); - } - this.curMode = newMode; - this.curMode.enter(); - return (_ref1 = this.commandManager) != null ? _ref1.setUseNumPrefix(this.curMode.getUseNumPrefix()) : void 0; - }, - isReady: function() { - return this.initEnabled && this.domReady; - }, - setPageMark: function(key) { - var mark; - mark = { - top: window.pageYOffset, - left: window.pageXOffset - }; - return this.pmRegister.set(mark, key); - }, - goPageMark: function(key) { - var offset; - offset = this.pmRegister.get(key); - if (offset) { - return g.view.scrollTo(offset.left, offset.top); - } - }, - setSearcher: function(searcher) { - this.searcher = searcher; - }, - cancelSearchHighlight: function() { - var _ref1; - return (_ref1 = this.searcher) != null ? _ref1.cancelHighlight() : void 0; - }, - enterNormalMode: function() { - g.logger.d("enterNormalMode"); - return this.changeMode(new g.NormalMode); - }, - enterInsertMode: function() { - g.logger.d("enterInsertMode"); - return this.changeMode(new g.InsertMode); - }, - enterEmergencyMode: function() { - g.logger.d("enterEmergencyMode"); - return this.changeMode(new g.EmergencyMode); - }, - enterCommandMode: function(executer, sources) { - var mode; - mode = new g.CommandMode; - mode.setExecuter(executer).setSources(sources); - g.logger.d("enterCommandMode"); - this.cancelSearchHighlight(); - return this.changeMode(mode); - }, - enterSearchMode: function(backward, searcher_) { - this.searcher = searcher_ != null ? searcher_ : new g.NormalSearcher; - g.logger.d("enterSearchMode"); - this.changeMode((new g.SearchMode).init(this.searcher, backward)); - return this.setPageMark(); - }, - enterFMode: function(opt) { - g.logger.d("enterFMode"); - return this.changeMode((new g.FMode).setOption(opt)); - }, - isInNormalMode: function() { - return this.curMode.getName() === "NormalMode"; - }, - isInInsertMode: function() { - return this.curMode.getName() === "InsertMode"; - }, - isInSearchMode: function() { - return this.curMode.getName() === "SearchMode"; - }, - isInCommandMode: function() { - return this.curMode.getName() === "CommandMode"; - }, - isInFMode: function() { - return this.curMode.getName() === "FMode"; - }, - isInEmergencyMode: function() { - return this.curMode.getName() === "EmergencyMode"; - }, - goNextSearchResult: function(reverse) { - if (this.searcher == null) { - return; - } - this.setPageMark(); - return this.searcher.goNext(reverse); - }, - getNMap: getNMapFirst, - getIMap: getIMapFirst, - getCMap: getCMapFirst, - getEMap: getEMapFirst, - getAlias: getAliasFirst, - getSetting: function(name) { - return this.settings[name]; - }, - escape: function() { - this.commandManager.reset(); - g.view.hideStatusLine(); - if (!this.isInNormalMode()) { - return this.enterNormalMode(); - } - }, - onBlur: function(target) { - return this.curMode.blur(target); - }, - prePostKeyEvent: function(key, ctrl, alt, meta) { - this.disAutoFocus = false; - return this.curMode.prePostKeyEvent(key, ctrl, alt, meta); - }, - isValidKeySeq: function(keySeq) { - if (this.getKeyMapping()[keySeq]) { - return true; - } else { - return false; - } - }, - isValidKeySeqAvailable: function(keySeq) { - var cmpStr, command, keyMapping, length, pos, seq; - keyMapping = this.getKeyMapping(); - length = keySeq.length; - for (seq in keyMapping) { - command = keyMapping[seq]; - cmpStr = seq.slice(0, length); - pos = cmpStr.indexOf("<", 0); - if (pos >= 0) { - pos = seq.indexOf(">", pos); - if (pos >= length) { - cmpStr = seq.slice(0, pos + 1); - } - } - if (keySeq === cmpStr) { - return true; - } - } - return false; - }, - isUrlMatched: function(url, matchPattern) { - var regexp, str; - str = matchPattern.replace(/\*/g, ".*").replace(/\/$/g, "").replace(/\//g, "\\/"); - str = "^" + str + "$"; - url = url.replace(/\/$/g, ""); - regexp = new RegExp(str, "m"); - if (regexp.test(url)) { - g.logger.d("URL pattern matched:" + url + ":" + matchPattern); - return true; - } - return false; - }, - isEnabled: function() { - var url, urls, _i, _len; - urls = this.getSetting("ignoredUrls"); - for (_i = 0, _len = urls.length; _i < _len; _i++) { - url = urls[_i]; - if (this.isUrlMatched(g.view.getHref(), url)) { - g.logger.d("matched ignored list"); - return false; - } - } - return true; - }, - handleKey: function(msg) { - return this.commandManager.handleKey(msg, this.getKeyMapping()); - }, - triggerCommand: function(method, args, times, timesSpecified) { - if (this.curMode[method] != null) { - return this.curMode[method](args, times, timesSpecified); - } else { - return g.logger.e("INVALID command!:", method); - } - }, - onSettings: function(msg) { - if (msg.name === "all") { - this.settings = msg.value; - } else { - this.settings[msg.name] = msg.value; - } - if (!this.isEnabled()) { - this.settings.keyMappingNormal = {}; - this.settings.keyMappingInsert = {}; - } - switch (msg.name) { - case "keyMappingNormal": - return this.getNMap = getNMapFirst; - case "keyMappingInsert": - return this.getIMap = getIMapFirst; - case "keyMappingCommand": - return this.getCMap = getCMapFirst; - case "keyMappingEmergency": - return this.getEMap = getEMapFirst; - case "aliases": - return this.getAlias = getAliasFirst; - } - }, - onFocus: function(target) { - var _this = this; - if (this.isInCommandMode() || this.isInSearchMode() || this.isInEmergencyMode()) { - g.logger.d("onFocus:nothing should be done in the cur mode"); - return; - } - if (this.disAutoFocus) { - setTimeout((function() { - return _this.disAutoFocus = false; - }), 500); - this.enterNormalMode(); - g.view.blurActiveElement(); - return; - } - if (g.util.isEmbededFlash(target)) { - return this.enterEmergencyMode(); - } else if (g.util.isEditable(target)) { - return this.enterInsertMode(); - } else { - return this.enterNormalMode(); - } - }, - onMouseDown: function(e) { - return this.disAutoFocus = false; - }, - getKeyMapping: function() { - return this.curMode.getKeyMapping(); - }, - onInitEnabled: function(msg) { - g.logger.d("onInitEnabled"); - this.onSettings(msg); - this.disAutoFocus = this.getSetting("disableAutoFocus"); - this.commandManager.setTimeout(this.getSetting("commandWaitTimeOut")); - this.enterNormalMode(); - this.frameID = msg.frameID; - this.initEnabled = true; - if (typeof top !== "undefined" && top !== null) { - chrome.extension.sendRequest({ - command: "NotifyTopFrame", - frameID: this.frameID - }); - } - if (this.domReady) { - return this.onDomReady(); - } - }, - onDomReady: function() { - g.logger.d("onDomReady"); - this.domReady = true; - if (!this.initEnabled) { - g.logger.w("onDomReady is called before onInitEnabled"); - return; - } - g.view.init(); - g.logger.d("disAutoFocus", this.disAutoFocus); - if (g.util.isEditable(document.activeElement) && !this.disAutoFocus) { - return this.enterInsertMode(); - } else { - g.view.blurActiveElement(); - return this.enterNormalMode(); - } - }, - openCommandBox: function(param) { - var _ref1, _ref2, _ref3; - if (typeof top !== "undefined" && top !== null) { - param.command = "SendToCommandBox"; - g.view.showCommandFrame(); - } else { - param.command = "TopFrame"; - } - param.innerCommand = 'OpenCommandBox'; - if ((_ref1 = param.sender) == null) { - param.sender = this.frameID; - } - if ((_ref2 = param.keyMap) == null) { - param.keyMap = g.extendDeep(this.getCMap()); - } - if ((_ref3 = param.aliases) == null) { - param.aliases = g.extendDeep(this.getAlias()); - } - return chrome.extension.sendRequest(param, function(msg) { - return g.handler.onCommandResponse(msg); - }); - } - }; - -}).call(this); 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 deleted file mode 100644 index ecc3fa6..0000000 --- a/options.js +++ /dev/null @@ -1,206 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var escChars, g, initCheckBox, initDropDown, initInputNumber, initInputText, onSettings, setSetting, settings, updateKeyMappingList, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - settings = null; - - setSetting = function(name, val, response) { - return chrome.extension.sendRequest({ - command: "Settings", - type: "set", - name: name, - value: val - }); - }; - - escChars = function(str) { - return str.replace("<", "<").replace(">", ">").replace(" ", " "); - }; - - 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; - for (key in _ref1) { - com = _ref1[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Insert Mode Mapping (imap)

')); - _ref2 = settings.keyMappingInsert; - for (key in _ref2) { - com = _ref2[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Search/Command Mode Mapping (cmap)

')); - _ref3 = settings.keyMappingCommand; - for (key in _ref3) { - com = _ref3[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Emergency Mode Mapping (emap)

')); - _ref4 = settings.keyMappingEmergency; - for (key in _ref4) { - com = _ref4[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Command Aliases (alias)

')); - _ref5 = settings.aliases; - for (key in _ref5) { - com = _ref5[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

PageCmd Mapping

')); - _ref6 = settings.pageMap; - _results = []; - for (url in _ref6) { - map = _ref6[url]; - curMap.append($('
').html("

" + url + "

")); - curMap.append($('
').html('

Normal Mode Mapping

')); - _ref7 = map.nmap; - for (key in _ref7) { - com = _ref7[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Insert Mode Mapping

')); - _ref8 = map.imap; - for (key in _ref8) { - com = _ref8[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Search/Command Mode Mapping

')); - _ref9 = map.cmap; - for (key in _ref9) { - com = _ref9[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Emergency Mode Mapping

')); - _ref10 = map.emap; - for (key in _ref10) { - com = _ref10[key]; - curMap.append($('
').html(escChars(key + " : " + escChars(com)))); - } - curMap.append($('
').html('

Command Aliases

')); - _results.push((function() { - var _ref11, _results1; - _ref11 = map.alias; - _results1 = []; - for (key in _ref11) { - com = _ref11[key]; - _results1.push(curMap.append($('
').html(escChars(key + " : " + escChars(com))))); - } - return _results1; - })()); - } - return _results; - }; - - initInputText = function(name) { - return $('#' + name).val(settings[name]).keyup(function() { - return setSetting(name, $(this).val()); - }); - }; - - initInputNumber = function(name) { - return $('#' + name).val(settings[name]).keyup(function() { - return setSetting(name, parseInt($(this).val())); - }).click(function() { - return setSetting(name, parseInt($(this).val())); - }).mousewheel(function() { - return setSetting(name, parseInt($(this).val())); - }); - }; - - initCheckBox = function(name) { - return $('#' + name).attr('checked', settings[name]).change(function() { - return setSetting(name, $(this).is(':checked')); - }); - }; - - initDropDown = function(name) { - return $('#' + name).val(settings[name]).change(function() { - return setSetting(name, $(this).val()); - }); - }; - - onSettings = function(msg) { - if (msg.name === "all") { - settings = msg.value; - } - initInputNumber("scrollPixelCount"); - initInputNumber("commandWaitTimeOut"); - initInputNumber("minIncSearch"); - initInputNumber("commandBoxWidth"); - initInputNumber("minMigemoLength"); - initInputNumber("hintFontSize"); - initInputText("fModeAvailableKeys"); - initInputText("hintBackgroundColor"); - initInputText("hintColor"); - initInputText("hintColorSelected"); - initCheckBox("disableAutoFocus"); - initCheckBox("smoothScroll"); - initCheckBox("enableCompletion"); - initCheckBox("wrapSearch"); - initCheckBox("incSearch"); - initCheckBox("ignoreCase"); - initCheckBox("useMigemo"); - initCheckBox("fModeIgnoreCase"); - initCheckBox("notifyUpdateSucceeded"); - initCheckBox("useFModeAnimation"); - initDropDown("commandBoxAlign"); - initDropDown("searchEngine"); - $('[name="newTabPage"][value="' + settings.defaultNewTab + '"]').attr('checked', true); - $('[name="newTabPage"]').change(function() { - if ($(this).is(':checked')) { - return setSetting("defaultNewTab", $(this).val()); - } - }); - $('#ignoredUrls').val(settings.ignoredUrls.join('\n')); - $('#ignoredUrlsButton').click(function() { - return setSetting("ignoredUrls", $('#ignoredUrls').val().split('\n')); - }); - $('#keyMapping').val(settings.keyMappingAndAliases); - $('#keyMappingButton').click(function() { - return setSetting("keyMappingAndAliases", $('#keyMapping').val()); - }); - return updateKeyMappingList(); - }; - - $(document).ready(function() { - return chrome.extension.sendRequest({ - command: "Settings", - type: "get", - name: "all" - }, onSettings); - }); - - $(document).ready(function() { - var page; - $('#page-container > div').hide(); - page = /#.*$/.exec(window.location.href); - if (page != null) { - page = page[0]; - } else { - page = '#general'; - } - $("ul.navbar li:has(a[href=\"" + page + "\"])").addClass('navbar-item-selected').show(); - $(page).show(); - 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(); - tab = $(this).find('a').attr('href'); - $(tab).fadeIn(200); - return false; - }); - }); - -}).call(this); diff --git a/register.js b/register.js deleted file mode 100644 index 5caca2f..0000000 --- a/register.js +++ /dev/null @@ -1,38 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.PageMarkRegister = (function() { - - function PageMarkRegister() { - this.values = {}; - } - - PageMarkRegister.prototype.defaultKeyName = "unnamed"; - - PageMarkRegister.prototype.set = function(pos, key) { - if (key == null) { - key = this.defaultKeyName; - } - this.values[key] = pos; - return this; - }; - - PageMarkRegister.prototype.get = function(key) { - if (key == null) { - key = this.defaultKeyName; - } - return this.values[key]; - }; - - return PageMarkRegister; - - })(); - -}).call(this); diff --git a/search.js b/search.js deleted file mode 100644 index b51dff5..0000000 --- a/search.js +++ /dev/null @@ -1,243 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref, - __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; }; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.NormalSearcher = (function() { - - function NormalSearcher() {} - - NormalSearcher.prototype.buildSortedResults = function() { - var results; - this.sortedResults = []; - results = this.sortedResults; - $('span.vichrome-highlight:visible').each(function(i) { - results[i] = {}; - results[i].offset = $(this).offset(); - return results[i].value = $(this); - }); - return this.sortedResults.sort(function(a, b) { - if (a.offset.top === b.offset.top) { - return a.offset.left - b.offset.left; - } else { - return a.offset.top - b.offset.top; - } - }); - }; - - NormalSearcher.prototype.getResultCnt = function() { - return this.sortedResults.length; - }; - - NormalSearcher.prototype.getFirstInnerSearchResultIndex = function() { - var i, idx, span, total, _i, _ref1; - total = this.getResultCnt(); - for (i = _i = 0, _ref1 = total - 1; 0 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 0 <= _ref1 ? ++_i : --_i) { - idx = this.opt.backward ? total - 1 - i : i; - span = this.getResult(idx); - if ((span != null) && span.isWithinScreen()) { - return idx; - } - } - return -1; - }; - - NormalSearcher.prototype.updateInput = function(word) { - this.word = word; - if (this.word.length >= this.opt.minIncSearch) { - this.searchAndHighlight(this.word); - if (this.getResultCnt() === 0) { - g.view.setStatusLineText("no matches"); - return; - } - this.curIndex = this.getFirstInnerSearchResultIndex(); - if (this.curIndex < 0) { - if (this.opt.backward) { - this.curIndex = this.getResultCnt() - 1; - } else { - this.curIndex = 0; - } - } - this.moveTo(this.curIndex); - } else { - g.view.setStatusLineText(""); - this.removeHighlight(); - } - }; - - NormalSearcher.prototype.init = function(opt) { - this.opt = opt; - return this; - }; - - NormalSearcher.prototype.getOption = function() { - var ret; - ret = g.object(this.opt); - if (this.opt.useMigemo && this.word.length < this.opt.minMigemoLength) { - ret.useMigemo = false; - } - return ret; - }; - - NormalSearcher.prototype.highlight = function(word) { - var opt; - opt = this.getOption(); - return $(document.body).highlight(word, { - ignoreCase: opt.ignoreCase, - useMigemo: opt.useMigemo - }); - }; - - NormalSearcher.prototype.getCurIndex = function() { - return this.curIndex; - }; - - NormalSearcher.prototype.removeHighlight = function() { - return $(document.body).removeHighlight(); - }; - - NormalSearcher.prototype.searchAndHighlight = function(word) { - this.removeHighlight(); - this.highlight(word); - return this.buildSortedResults(); - }; - - NormalSearcher.prototype.getResult = function(cnt) { - var _ref1; - return (_ref1 = this.sortedResults[cnt]) != null ? _ref1.value : void 0; - }; - - NormalSearcher.prototype.fix = function(word) { - var span, _ref1; - if (!this.opt.incSearch || word.length < this.opt.minIncSearch || this.word !== word) { - if (this.opt.useMigemo && word.length < this.opt.minMigemoLength) { - this.opt.useMigemo = false; - } - this.word = word; - this.searchAndHighlight(word); - if (this.getResultCnt() === 0) { - g.view.setStatusLineText("no matches"); - return; - } - this.curIndex = this.getFirstInnerSearchResultIndex(); - if (this.curIndex < 0) { - if (this.opt.backward) { - this.curIndex = this.getResultCnt() - 1; - } else { - this.curIndex = 0; - } - } - this.moveTo(this.curIndex); - } else { - this.word = word; - } - chrome.extension.sendRequest({ - command: "PushSearchHistory", - value: this.word - }); - span = this.getResult(this.getCurIndex()); - if (span != null) { - if ((_ref1 = span.closest("a").get(0)) != null) { - _ref1.focus(); - } - } - return this.fixed = true; - }; - - NormalSearcher.prototype.moveTo = function(pos) { - var span, _ref1; - if (this.getResultCnt() > pos) { - span = this.getResult(pos); - if (span != null) { - $('span').removeClass('vichrome-highlightFocus'); - span.addClass('vichrome-highlightFocus'); - span.scrollTo(); - g.view.setStatusLineText((pos + 1) + " / " + this.getResultCnt()); - if (this.fixed) { - g.view.blurActiveElement(); - return (_ref1 = span.closest("a").get(0)) != null ? _ref1.focus() : void 0; - } - } - } else { - return g.logger.e("out of searchResults length", pos); - } - }; - - NormalSearcher.prototype.goNext = function(reverse) { - var forward; - forward = this.opt.backward === reverse; - if (this.removed) { - this.searchAndHighlight(this.word); - this.removed = false; - } - if (forward) { - this.curIndex++; - } else { - this.curIndex--; - } - if (forward && this.curIndex >= this.getResultCnt()) { - if (this.opt.wrap) { - this.curIndex = 0; - } else { - this.curIndex = this.getResultCnt() - 1; - return false; - } - } else if (!forward && this.curIndex < 0) { - if (this.opt.wrap) { - this.curIndex = this.getResultCnt() - 1; - } else { - this.curIndex = 0; - return false; - } - } - this.moveTo(this.curIndex); - return true; - }; - - NormalSearcher.prototype.cancelHighlight = function() { - g.logger.d("cancelHighlight"); - this.removeHighlight(); - return this.removed = true; - }; - - NormalSearcher.prototype.finalize = function() { - g.logger.d("finalize"); - this.sortedResults = void 0; - this.opt = void 0; - g.view.hideStatusLine(); - return this.removeHighlight(); - }; - - return NormalSearcher; - - })(); - - g.LinkTextSearcher = (function(_super) { - - __extends(LinkTextSearcher, _super); - - function LinkTextSearcher() { - return LinkTextSearcher.__super__.constructor.apply(this, arguments); - } - - LinkTextSearcher.prototype.highlight = function(word) { - var opt; - opt = this.getOption(); - return $("a").highlight(word, { - ignoreCase: opt.ignoreCase, - useMigemo: opt.useMigemo - }); - }; - - return LinkTextSearcher; - - })(g.NormalSearcher); - -}).call(this); diff --git a/settings.js b/settings.js deleted file mode 100644 index 452ad6e..0000000 --- a/settings.js +++ /dev/null @@ -1,347 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, mapping, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - mapping = { - nmap: {}, - imap: {}, - cmap: {}, - emap: {}, - alias: {} - }; - - 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": ["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\n# aliases\n# in this example you can open extensions page by the command ':ext'\n# and Chrome's option page by the command ':option'\nalias ext TabOpenNew chrome://extensions/\nalias option TabOpenNew chrome://settings/browser\nalias downloads TabOpenNew chrome://downloads\nalias history TabOpenNew chrome://history\n\n# mappings for opening your favorite web page\nnmap tw :TabOpenNew http://www.twitter.com\nnmap gr :TabOpenNew http://www.google.com/reader\nnmap m :TabOpenNew https://mail.google.com/mail/#inbox\n\n# F for continuous f-Mode\n# this is recomended setting but commented out by default.\n# if you want to use this setting, use the following\n#nmap F :GoFMode --newtab --continuous\n\n# you can use to discard the key so that chrome's default\n# action isn't triggered.\n#nmap \n\n# if you want to change the key used to escape EmergencyMode mode,\n# use emap like the following\n#emap :Escape\n\n## pagecmd offers you page specific key mapping.\n# in this example you can use , for moving between tabs\n# on all web pages regardless of your ignored list setting\n# because pagecmd has higher priority than ignored URLs.\npagecmd * nmap :TabFocusNext\npagecmd * nmap :TabFocusPrev\n\n# almost all Vichrome functions don't work properly for pdf contents\n# so it's useful to enable default key bindings for pdf file.\npagecmd *.pdf nmap \n\n# if you want to use twitter web's key binding, write settings like below\n#pagecmd http*://twitter.com/* nmap f \n#pagecmd http*://twitter.com/* nmap r ", - "keyMappingNormal": { - "j": "ScrollDown", - "": "ScrollDown", - "k": "ScrollUp", - "": "ScrollUp", - "h": "ScrollLeft", - "l": "ScrollRight", - "": "PageDown", - "": "PageUp", - "": "PageHalfDown", - "": "PageHalfUp", - "gg": "GoTop", - "G": "GoBottom", - "t": "TabOpenNew", - "x": "TabCloseCurrent", - "X": "TabCloseCurrent --focusprev", - "n": "NextSearch", - "N": "PrevSearch", - "gt": "TabFocusNext", - "gT": "TabFocusPrev", - "": "TabFocusNext", - "": "TabFocusPrev", - "r": "TabReload", - "H": "BackHist", - "L": "ForwardHist", - ":": "GoCommandMode", - "/": "GoSearchModeForward", - "?": "GoSearchModeBackward", - "a": "GoLinkTextSearchMode", - "f": "GoFMode", - "F": "GoFMode --newtab", - "i": "FocusOnFirstInput", - "u": "RestoreTab", - "gp": "WinOpenNew --pop", - "gs": "TabOpenNew --next view-source:%url", - "yy": "copyurl", - "p": "Open %clipboard", - "P": "TabOpenNew %clipboard", - "o": "Open -i", - "O": "TabOpenNew -i", - "s": "Open -i g", - "S": "TabOpenNew -i g", - "b": "Open -b", - "B": "TabOpenNew -b", - "''": "BackToPageMark", - "": "TabSwitchLast", - "": "GoEmergencyMode", - "": "Escape", - "": "Escape", - ",z": "ToggleImageSize" - }, - "keyMappingInsert": { - "": "Escape", - "": "Escape" - }, - "keyMappingCommand": { - "": "FocusNextCandidate", - "": "FocusPrevCandidate", - "": "FocusNextCandidate", - "": "FocusPrevCandidate", - "": "Escape", - "": "Escape" - }, - "keyMappingEmergency": { - "": "Escape" - }, - "aliases": { - "o": "Open", - "ot": "TabOpenNew", - "opt": "OpenOptionPage", - "help": "TabOpenNew http://github.com/k2nr/ViChrome/wiki/Vichrome-User-Manual", - "map": "NMap", - "tabe": "TabOpenNew", - "tabnew": "TabOpenNew", - "tabn": "TabFocusNext", - "tabp": "TabFocusPrev", - "tabN": "TabFocusPrev", - "tabr": "TabFocusFirst", - "tabl": "TabFocusLast", - "tabc": "TabCloseCurrent", - "tabo": "TabCloseAll --only", - "tabs": "TabList", - "q": "TabCloseAll", - "copyurl": "Copy %url", - "copytitle": "Copy %title", - "viewsource": "TabOpenNew --next view-source:%url", - "OpenNewTab": "TabOpenNew", - "MoveToNextTab": "TabFocusNext", - "MoveToPrevTab": "TabFocusPrev", - "MoveToFirstTab": "TabFocusFirst", - "MoveToLastTab": "TabFocusLast", - "CloseCurTab": "TabCloseCurrent", - "CloseAllTabs": "TabCloseAll", - "ShowTabList": "TabList", - "ReloadTab": "TabReload", - "OpenNewWindow": "WinOpenNew" - }, - "pageMap": {} - }, - userMap: null, - pageMap: null, - setCb: null, - mapApplied: function(args) { - if (args.length < 2) { - g.logger.w("less arguments", args); - return this; - } - if (args[1].charAt(0) === ':') { - this[args[0]] = args.slice(1).join(' ').slice(1); - } else { - switch (args[1].toUpperCase()) { - case "": - this[args[0]] = ""; - break; - case "": - this[args[0]] = ""; - break; - default: - this[args[0]] = this[args[1]]; - } - } - return this; - }, - _map: function(map, args) { - return this.mapApplied.call(map.nmap, args); - }, - _nmap: function(map, args) { - return this.mapApplied.call(map.nmap, args); - }, - _imap: function(map, args) { - return this.mapApplied.call(map.imap, args); - }, - _cmap: function(map, args) { - return this.mapApplied.call(map.cmap, args); - }, - _emap: function(map, args) { - return this.mapApplied.call(map.emap, args); - }, - _alias: function(map, args) { - if (args.length < 2) { - g.logger.w("less arguments", args); - return map.alias; - } - map.alias[args[0]] = args.slice(1).join(' '); - return map.alias; - }, - _pagecmd: function(map, args) { - var _name; - if (this.pageMap[args[0]] == null) { - this.pageMap[args[0]] = g.extendDeep(mapping); - } - return typeof this[_name = "_" + args[1]] === "function" ? this[_name](this.pageMap[args[0]], args.slice(2)) : void 0; - }, - 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'); - for (_i = 0, _len = lines.length; _i < _len; _i++) { - line = lines[_i]; - if (line.length === 0) { - continue; - } - if (line.charAt(0) === '#') { - continue; - } - args = line.split(/[\t ]+/); - if (typeof this[_name = "_" + args[0]] === "function") { - this[_name](this.userMap, args.slice(1)); - } - } - return this; - }, - 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; - defEmergency = this.defaultSettings.keyMappingEmergency; - defAliases = this.defaultSettings.aliases; - defPageMap = this.defaultSettings.pageMap; - this.userMap = g.extendDeep(mapping); - for (key in defNormal) { - command = defNormal[key]; - this.userMap.nmap[key] = command; - } - for (key in defInsert) { - command = defInsert[key]; - this.userMap.imap[key] = command; - } - for (key in defCommand) { - command = defCommand[key]; - this.userMap.cmap[key] = command; - } - for (key in defEmergency) { - command = defEmergency[key]; - this.userMap.emap[key] = command; - } - for (key in defAliases) { - command = defAliases[key]; - this.userMap.alias[key] = command; - } - this.pageMap = {}; - for (url in defPageMap) { - map = defPageMap[url]; - this.pageMap[url] = g.extendDeep(mapping); - _ref1 = map.nmap; - for (key in _ref1) { - com = _ref1[key]; - this.pageMap[url].nmap[key] = com; - } - _ref2 = map.imap; - for (key in _ref2) { - com = _ref2[key]; - this.pageMap[url].imap[key] = com; - } - _ref3 = map.cmap; - for (key in _ref3) { - com = _ref3[key]; - this.pageMap[url].cmap[key] = com; - } - _ref4 = map.emap; - for (key in _ref4) { - com = _ref4[key]; - this.pageMap[url].emap[key] = com; - } - _ref5 = map.alias; - for (key in _ref5) { - com = _ref5[key]; - this.pageMap[url].alias[key] = com; - } - } - return this; - }, - getAll: function() { - var name, settings, value, _ref1; - settings = {}; - _ref1 = this.defaultSettings; - for (name in _ref1) { - value = _ref1[name]; - switch (name) { - case "keyMappingNormal": - settings[name] = this.userMap.nmap; - break; - case "keyMappingInsert": - settings[name] = this.userMap.imap; - break; - case "keyMappingCommand": - settings[name] = this.userMap.cmap; - break; - case "keyMappingEmergency": - settings[name] = this.userMap.emap; - break; - case "aliases": - settings[name] = this.userMap.alias; - break; - case "pageMap": - settings[name] = this.pageMap; - break; - default: - settings[name] = this.get(name); - } - } - return settings; - }, - get: function(name) { - if (localStorage[name] != null) { - return JSON.parse(localStorage.getItem(name)); - } else { - return this.defaultSettings[name]; - } - }, - set: function(name, value) { - localStorage.setItem(name, JSON.stringify(value)); - if (name === "keyMappingAndAliases") { - this.initUserMap(); - this.parseKeyMappingAndAliases(); - } - return typeof this.setCb === "function" ? this.setCb(name, value) : void 0; - }, - setNMap: function(args) { - return this._map(this.userMap, args); - }, - setIMap: function(args) { - return this._imap(this.userMap, args); - }, - setCMap: function(args) { - return this._cmap(this.userMap, args); - }, - setEMap: function(args) { - return this._emap(this.userMap, args); - }, - setAlias: function(args) { - return this._alias(this.userMap, args); - }, - init: function() { - this.initUserMap(); - return this.parseKeyMappingAndAliases(); - } - }; - -}).call(this); diff --git a/storage.js b/storage.js deleted file mode 100644 index 13dc475..0000000 --- a/storage.js +++ /dev/null @@ -1,18 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.storage = { - set: function(items, callback) { - return storage.set; - }, - remove: function(keys, callback) {} - }; - -}).call(this); diff --git a/tab.js b/tab.js deleted file mode 100644 index 539b126..0000000 --- a/tab.js +++ /dev/null @@ -1,342 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.tabs = {}; - - g.TabSelectionHistory = (function() { - - function TabSelectionHistory() {} - - TabSelectionHistory.prototype.init = function() { - var _this = this; - this.array = []; - this.curPos = 0; - this.isUpdating = false; - chrome.tabs.onSelectionChanged.addListener(function(tabId, info) { - var elem, i, _i, _len, _ref1, _ref2; - g.logger.d("selhist selChanged id:" + tabId, _this); - if (((_ref1 = _this.array[_this.curPos]) != null ? _ref1.id : void 0) === tabId) { - return; - } - _this.array.splice(_this.curPos + 1); - _ref2 = _this.array; - for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) { - elem = _ref2[i]; - if (elem.id === tabId) { - _this.array.splice(i, 1); - break; - } - } - _this.array.push({ - id: tabId, - info: info - }); - return _this.curPos = _this.array.length - 1; - }); - chrome.tabs.onRemoved.addListener(function(tabId, info) { - var elem, i, _i, _len, _ref1, _results; - g.logger.d("selhist tab removed id:" + tabId, _this); - _ref1 = _this.array; - _results = []; - for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { - elem = _ref1[i]; - if (elem.id === tabId) { - _this.array.splice(i, 1); - if (_this.curPos >= i) { - _this.curPos--; - } - break; - } else { - _results.push(void 0); - } - } - return _results; - }); - return this; - }; - - TabSelectionHistory.prototype.moveBackward = function() { - var _this = this; - if (!(this.array.length > 0)) { - return; - } - if (this.isUpdating) { - return; - } - if (this.curPos > 0) { - --this.curPos; - } else { - this.curPos = this.array.length - 1; - } - chrome.tabs.update(this.array[this.curPos].id, { - selected: true - }, function() { - return _this.isUpdating = false; - }); - this.isUpdating = true; - return this; - }; - - TabSelectionHistory.prototype.moveForward = function() { - var _this = this; - if (!(this.array.length > 0)) { - return; - } - if (this.isUpdating) { - return; - } - if (this.curPos < this.array.length - 1) { - ++this.curPos; - } else { - this.curPos = 0; - } - chrome.tabs.update(this.array[this.curPos].id, { - selected: true - }, function() { - return _this.isUpdating = false; - }); - this.isUpdating = true; - return this; - }; - - TabSelectionHistory.prototype.switchToLast = function() { - var _this = this; - if (!(this.array.length > 0)) { - return; - } - if (!(this.curPos > 0)) { - return; - } - if (this.isUpdating) { - return; - } - chrome.tabs.update(this.array[this.curPos - 1].id, { - selected: true - }, function() { - return _this.isUpdating = false; - }); - this.isUpdating = true; - return this; - }; - - return TabSelectionHistory; - - })(); - - g.TabHistory = (function() { - - function TabHistory() {} - - TabHistory.prototype.closeHistStack = []; - - TabHistory.prototype.openTabs = {}; - - TabHistory.prototype.findOpenTabItem = function(tabId) { - var tabs, win, _ref1; - _ref1 = this.openTabs; - for (win in _ref1) { - tabs = _ref1[win]; - if (tabs[tabId]) { - return tabs[tabId]; - } - } - }; - - TabHistory.prototype.popOpenTabItem = function(tabId) { - var result, tabs, win, _ref1; - _ref1 = this.openTabs; - for (win in _ref1) { - tabs = _ref1[win]; - if (tabs[tabId]) { - result = tabs[tabId]; - tabs[tabId] = void 0; - return result; - } - } - }; - - TabHistory.prototype.addOpenTabItem = function(tab, history) { - this.openTabs[tab.windowId][tab.id] = {}; - this.openTabs[tab.windowId][tab.id].tab = tab; - this.openTabs[tab.windowId][tab.id].frames = 0; - if (history) { - return this.openTabs[tab.windowId][tab.id].history = history; - } else { - this.openTabs[tab.windowId][tab.id].history = []; - return this.openTabs[tab.windowId][tab.id].history.push(tab.url); - } - }; - - TabHistory.prototype.setTopFrameID = function(tab, id) { - var _ref1; - if (((_ref1 = this.openTabs[tab.windowId]) != null ? _ref1[tab.id] : void 0) != null) { - return this.openTabs[tab.windowId][tab.id].topFrame = id; - } - }; - - TabHistory.prototype.getTopFrameID = function(tab) { - var _ref1, _ref2; - return (_ref1 = this.openTabs[tab.windowId]) != null ? (_ref2 = _ref1[tab.id]) != null ? _ref2.topFrame : void 0 : void 0; - }; - - TabHistory.prototype.setCommandBoxID = function(tab, id) { - var _ref1; - if (((_ref1 = this.openTabs[tab.windowId]) != null ? _ref1[tab.id] : void 0) != null) { - return this.openTabs[tab.windowId][tab.id].comBoxID = id; - } - }; - - TabHistory.prototype.getCommandBoxID = function(tab) { - var _ref1, _ref2; - return (_ref1 = this.openTabs[tab.windowId]) != null ? (_ref2 = _ref1[tab.id]) != null ? _ref2.comBoxID : void 0 : void 0; - }; - - TabHistory.prototype.setFrames = function(tab, frames) { - var _ref1; - if (((_ref1 = this.openTabs[tab.windowId]) != null ? _ref1[tab.id] : void 0) != null) { - return this.openTabs[tab.windowId][tab.id].frames = frames; - } - }; - - TabHistory.prototype.addFrames = function(tab) { - var _ref1; - if (((_ref1 = this.openTabs[tab.windowId]) != null ? _ref1[tab.id] : void 0) != null) { - return ++this.openTabs[tab.windowId][tab.id].frames; - } - }; - - TabHistory.prototype.getFrames = function(tab) { - var _ref1, _ref2; - return (_ref1 = this.openTabs[tab.windowId]) != null ? (_ref2 = _ref1[tab.id]) != null ? _ref2.frames : void 0 : void 0; - }; - - TabHistory.prototype.initTabHist = function(winId) { - var _this = this; - return chrome.windows.getAll({ - populate: true - }, function(wins) { - var tab, win, _i, _len, _results; - _results = []; - for (_i = 0, _len = wins.length; _i < _len; _i++) { - win = wins[_i]; - _this.openTabs[win.id] = {}; - _results.push((function() { - var _j, _len1, _ref1, _results1; - _ref1 = win.tabs; - _results1 = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - tab = _ref1[_j]; - _results1.push(this.addOpenTabItem(tab)); - } - return _results1; - }).call(_this)); - } - return _results; - }); - }; - - TabHistory.prototype.setupListeners = function() { - var _this = this; - chrome.tabs.onRemoved.addListener(function(tabId, info) { - var item; - g.logger.d("tab removed id:" + tabId); - if (info.isWindowClosing) { - return; - } - item = _this.popOpenTabItem(tabId); - if (item) { - _this.closeHistStack.push(item); - if (_this.closeHistStack.length > 10) { - _this.closeHistStack.shift(); - } - } - }); - chrome.tabs.onCreated.addListener(function(tab) { - g.logger.d("tab created id:" + tab.id); - return _this.addOpenTabItem(tab); - }); - chrome.tabs.onAttached.addListener(function(tabId, aInfo) { - g.logger.d("tab attached tab:" + tabId + " -> win:" + aInfo.newWindowId); - return chrome.tabs.get(tabId, function(tab) { - return _this.addOpenTabItem(tab); - }); - }); - chrome.tabs.onDetached.addListener(function(tabId, dInfo) { - g.logger.d("tab detached tab:" + tabId + " <- win:" + dInfo.oldWindowId); - return _this.popOpenTabItem(tabId); - }); - chrome.tabs.onUpdated.addListener(function(tabId, info, tab) { - var target; - target = _this.openTabs[tab.windowId][tabId]; - if (info.url) { - target.tab.url = info.url; - target.history.push(info.url); - } - if (info.pinned) { - return target.tab.pinned = info.pinned; - } - }); - chrome.windows.onCreated.addListener(function(win) { - g.logger.d("win created id:" + win.id); - return _this.openTabs[win.id] = {}; - }); - chrome.windows.onRemoved.addListener(function(winId) { - return delete _this.openTabs[winId]; - }); - return this; - }; - - TabHistory.prototype.init = function() { - this.initTabHist(); - this.setupListeners(); - return this; - }; - - TabHistory.prototype.restoreLastClosedTab = function() { - var item, opt, - _this = this; - item = this.closeHistStack.pop(); - while ((item != null) && !this.openTabs[item.tab.windowId]) { - item = this.closeHistStack.pop(); - } - if (item == null) { - return; - } - chrome.windows.update(item.tab.windowId, { - focused: true - }); - opt = { - windowId: item.tab.windowId, - url: item.tab.url, - index: item.tab.index, - pinned: item.tab.pinned - }; - return chrome.tabs.create(opt, function(tab) {}); - }; - - return TabHistory; - - })(); - - g.tabs.reloadAllTabs = function() { - return chrome.tabs.getAllInWindow(null, function(tabs) { - var tab, _i, _len, _results; - _results = []; - for (_i = 0, _len = tabs.length; _i < _len; _i++) { - tab = tabs[_i]; - _results.push(chrome.tabs.update(tab.id, { - url: tab.url - })); - } - return _results; - }); - }; - -}).call(this); diff --git a/utils.js b/utils.js deleted file mode 100644 index b488f6a..0000000 --- a/utils.js +++ /dev/null @@ -1,254 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var createCLTextArea, editableList, g, include, levels, objectList, _ref, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - g.VICHROME_VERSION = "0.11"; - - g.object = function(obj) { - var F; - F = function() {}; - F.prototype = obj; - return new F; - }; - - g.extend = function(mixin, obj) { - var member, name; - if (obj == null) { - obj = {}; - } - for (name in mixin) { - member = mixin[name]; - obj[name] = member; - } - return obj; - }; - - g.extendDeep = function(parent, child) { - var astr, member, name, toStr; - if (child == null) { - child = {}; - } - toStr = Object.prototype.toString; - astr = "[object Array]"; - for (name in parent) { - member = parent[name]; - if (typeof member === "object") { - child[name] = toStr.call(member) === astr ? [] : {}; - g.extendDeep(member, child[name]); - } else { - child[name] = member; - } - } - return child; - }; - - include = function(klass, mixin) { - return extend(klass.prototype, mixin); - }; - - g.logLevels = { - DEBUG: 1, - WARNING: 2, - ERROR: 3, - FATAL: 4, - NONE: 5 - }; - - g.LOG_LEVEL = g.logLevels.ERROR; - - levels = g.logLevels; - - g.logger = { - printLog: function(a, o) { - if (o) { - return console.log("vichrome: " + a + " :%o", o); - } else { - return console.log("vichrome:" + a); - } - }, - d: function(a, o) { - if (g.LOG_LEVEL <= g.logLevels.DEBUG) { - return this.printLog(a, o); - } - }, - w: function(a, o) { - if (g.LOG_LEVEL <= g.logLevels.WARNING) { - return this.printLog(a, o); - } - }, - e: function(a, o) { - if (g.LOG_LEVEL <= g.logLevels.ERROR) { - return this.printLog(a, o); - } - }, - f: function(a, o) { - if (g.LOG_LEVEL <= g.logLevels.FATAL) { - return this.printLog(a, o); - } - } - }; - - g.util = {}; - - editableList = ["TEXT", "PASSWORD", "NUMBER", "SEARCH", "TEL", "URL", "EMAIL", "TIME", "DATETIME", "DATETIME-LOCAL", "DEATE", "WEEK", "COLOR"]; - - objectList = ["EMBED", "OBJECT", "APPLET"]; - - g.util.isEditable = function(target) { - var ignoreList, _ref1, _ref2, _ref3; - ignoreList = ["TEXTAREA"]; - if (target == null) { - return false; - } - if (target.isContentEditable) { - return true; - } - if (_ref1 = target.nodeName, __indexOf.call(ignoreList, _ref1) >= 0) { - return true; - } - if (((_ref2 = target.nodeName) != null ? _ref2.toUpperCase() : void 0) === "INPUT" && (_ref3 = target.type.toUpperCase(), __indexOf.call(editableList, _ref3) >= 0)) { - return true; - } - return false; - }; - - g.util.isEmbededFlash = function(target) { - var _ref1; - if (target == null) { - return false; - } - if (_ref1 = target.nodeName, __indexOf.call(objectList, _ref1) < 0) { - return false; - } - if (target.type.indexOf("x-shockwave-flash") >= 0) { - return true; - } - if (target.innerHTML.indexOf("x-shockwave-flash") >= 0) { - return true; - } - return false; - }; - - g.util.getPlatform = function() { - var platform; - if (navigator.userAgent.indexOf("Mac") >= 0) { - platform = "Mac"; - } else if (navigator.userAgent.indexOf("Linux") >= 0) { - platform = "Linux"; - } else if (navigator.userAgent.indexOf("Win") >= 0) { - platform = "Windows"; - } else { - platform = ""; - } - g.util.getPlatform = function() { - return platform; - }; - return platform; - }; - - g.util.dispatchKeyEvent = function(target, identifier, primary, shift, alt) { - var e, modifier; - e = document.createEvent("KeyboardEvent"); - modifier = ""; - if (primary) { - modifier += "Meta "; - } - if (shift) { - modifier += "Shift "; - } - if (alt) { - modifier += "Alt"; - } - e.initKeyboardEvent("keydown", true, true, window, identifier, 0x00, modifier, true); - return target.dispatchEvent(e); - }; - - g.util.dispatchMouseClickEvent = function(target, primary, shift, alt) { - var ctrl, e, event, meta, secondary, _i, _len, _ref1; - secondary = false; - if ((target != null ? target.dispatchEvent : void 0) == null) { - g.logger.e("target is invalid"); - return false; - } - switch (g.util.getPlatform()) { - case "Mac": - meta = primary; - ctrl = secondary; - break; - case "Linux": - case "Windows": - meta = secondary; - ctrl = primary; - break; - default: - meta = secondary; - ctrl = primary; - } - _ref1 = ['mousedown', 'mouseup', 'click']; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - event = _ref1[_i]; - e = document.createEvent("MouseEvents"); - e.initMouseEvent(event, true, true, window, 1, 0, 0, 0, 0, ctrl, alt, shift, meta, 0, null); - target.dispatchEvent(e); - } - return true; - }; - - g.util.getLang = function() { - var lang; - lang = (navigator.userLanguage || navigator.browserLanguage || navigator.language).substr(0, 2); - g.util.getLang = function() { - return lang; - }; - return lang; - }; - - g.util.benchmark = function(cb, text) { - var getCurrentTime, start; - getCurrentTime = function() { - return (new Date).getTime(); - }; - start = getCurrentTime(); - cb(); - text || (text = ""); - return g.logger.e(text + ("::benchmark result:" + (getCurrentTime() - start) + "ms")); - }; - - createCLTextArea = function(data) { - var area; - area = document.createElement('textarea'); - area.style.position = "absolute"; - area.style.left = "-100%"; - area.value = data || ""; - return area; - }; - - g.clipboard = {}; - - g.clipboard.set = function(data) { - var area; - area = createCLTextArea(data); - document.body.appendChild(area); - area.select(); - document.execCommand('Copy'); - return document.body.removeChild(area); - }; - - g.clipboard.get = function() { - var area; - area = createCLTextArea(); - document.body.appendChild(area); - area.focus(); - document.execCommand('Paste'); - document.body.removeChild(area); - return area.value; - }; - -}).call(this); diff --git a/vichrome.js b/vichrome.js deleted file mode 100644 index f82ec5c..0000000 --- a/vichrome.js +++ /dev/null @@ -1,26 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - setTimeout(function() { - g.model.init(); - g.view = new g.Surface; - g.handler = new g.EventHandler(g.model); - return chrome.extension.sendRequest({ - command: "Init" - }, function(msg) { - return g.handler.onInitEnabled(msg); - }); - }, 0); - - $(document).ready(function() { - return g.model.onDomReady(); - }); - -}).call(this); diff --git a/view.js b/view.js deleted file mode 100644 index 6c73ed2..0000000 --- a/view.js +++ /dev/null @@ -1,316 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var g, _ref; - - if ((_ref = this.vichrome) == null) { - this.vichrome = {}; - } - - g = this.vichrome; - - $.fn.extend({ - isWithinScreen: function(padding) { - var offset; - if (padding == null) { - padding = 10; - } - offset = $(this).offset(); - if (offset == null) { - return false; - } - if (offset.left + padding > window.pageXOffset + window.innerWidth || offset.left - padding < window.pageXOffset) { - return false; - } - if (offset.top + padding > window.pageYOffset + window.innerHeight || offset.top - padding < window.pageYOffset) { - return false; - } - return true; - }, - scrollTo: function(x, y, speed) { - var left, newX, newY, offset, top; - if (speed == null) { - speed = 80; - } - offset = $($(this).get(0)).offset(); - if (!((x != null) || (y != null))) { - if (offset == null) { - return $(this); - } - if ($(this).isWithinScreen()) { - return $(this); - } - } - newX = offset.left - window.innerWidth / 2; - newY = offset.top - window.innerHeight / 2; - if (newX > document.body.scrollLeft - window.innerWidth) { - newX - document.body.scrollLeft - window.innerWidth; - } - if (newY > document.body.scrollHeight - window.innerHeight) { - newX = document.body.scrollHeight - window.innerHeight; - } - left = x != null ? x : newX; - top = y != null ? y : newY; - if (!g.model.getSetting("smoothScroll")) { - speed = 0; - } - $(document.body).animate({ - scrollTop: top, - scrollLeft: left - }, speed); - return $(this); - }, - scrollBy: function(x, y, speed) { - var left, top; - if (x == null) { - x = 0; - } - if (y == null) { - y = 0; - } - if (speed == null) { - speed = 35; - } - top = window.pageYOffset + y; - left = window.pageXOffset + x; - if (!g.model.getSetting("smoothScroll")) { - speed = 0; - } - $(document.body).animate({ - scrollTop: top, - scrollLeft: left - }, speed); - return $(this); - } - }); - - $.extend($.expr[':'], { - scrollable: function(elem) { - var overflow; - overflow = $.curCSS(elem, 'overflow'); - switch (overflow) { - case "auto": - case "scroll": - return true; - } - return false; - } - }); - - 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; - if (typeof top !== "undefined" && top !== null) { - path = chrome.extension.getURL("commandbox.html"); - this.iframe = $("