From c83217e24e0a059f568374b6f540cf1859db5f60 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sat, 26 Nov 2011 18:02:16 -0800 Subject: Clean up style --- bookmarks.js | 29 +++++++++--------------- completionDialog.js | 64 +++++++++++++++++++++++++---------------------------- 2 files changed, 41 insertions(+), 52 deletions(-) diff --git a/bookmarks.js b/bookmarks.js index 8551d160..9056c731 100644 --- a/bookmarks.js +++ b/bookmarks.js @@ -63,31 +63,27 @@ function activateBookmarkFindMode() { self.completionDialog = new CompletionDialog({ source: findBookmarks, + onSelect: function(selection) { var url = selection.url; - var isABookmarklet = function(url) { - return url.indexOf("javascript:")===0; - } - - if(!self.newTab || isABookmarklet(url)) { - window.location=url; - } - else { + var isABookmarklet = function(url) { return url.indexOf("javascript:") === 0; } + + if (!self.newTab || isABookmarklet(url)) + window.location = url; + else window.open(url); - } self.disable(); }, - renderOption: function(searchString, selection) { + renderOption: function(searchString, selection) { var displaytext = selection.title + " (" + selection.url + ")" - - if(displaytext.length>70) { - displaytext = displaytext.substr(0, 70)+"..."; - } + if (displaytext.length > 70) + displaytext = displaytext.substr(0, 70) + "..."; return displaytext.split(new RegExp(searchString, "i")).join(""+searchString+"") }, + initialSearchText: "Type a bookmark name or URL" }) @@ -104,9 +100,8 @@ function activateBookmarkFindMode() { return; // TODO(philc): Ignore keys that have modifiers. - if (isEscape(event)) { + if (isEscape(event)) self.disable(); - } event.stopPropagation(); event.preventDefault(); @@ -132,7 +127,5 @@ function activateBookmarkFindMode() { port.postMessage({query:searchString}); }; - //export global window.BookmarkMode = BookmarkMode; - }()) diff --git a/completionDialog.js b/completionDialog.js index 2e8d5de5..fae034fd 100644 --- a/completionDialog.js +++ b/completionDialog.js @@ -1,17 +1,15 @@ (function(window, document) { - var CompletionDialog = function(options) { - this.options = options; - } + var CompletionDialog = function(options) { this.options = options; } CompletionDialog.prototype = { show: function() { - if(!this.isShown) { + if (!this.isShown) { this.isShown=true; this.query = []; - if(!this.initialized) { + if (!this.initialized) { initialize.call(this); - this.initialized=true; + this.initialized = true; } handlerStack.push({ keydown: this.onKeydown }); render.call(this); @@ -20,53 +18,51 @@ this._tweenId = Tween.fade(this.container, 1.0, 150); } }, + hide: function() { - if(this.isShown) { + if (this.isShown) { handlerStack.pop(); - this.isShown=false; - this.currentSelection=0; + this.isShown = false; + this.currentSelection = 0; clearInterval(this._tweenId); var completionContainer = this.container; - var cssHide = function() { - completionContainer.style.display = "none"; - } + var cssHide = function() { completionContainer.style.display = "none"; } this._tweenId = Tween.fade(this.container, 0, 150, cssHide); } }, + getDisplayElement: function() { - if(!this.container) { + if (!this.container) this.container = createDivInside(document.body); - } return this.container; }, - getQueryString: function() { - return this.query.join(""); - } + + getQueryString: function() { return this.query.join(""); } } var initialize = function() { var self = this; addCssToPage(completionCSS); - self.currentSelection=0; + self.currentSelection = 0; self.onKeydown = function(event) { var keyChar = getKeyChar(event); // change selection with up or Shift-Tab - if(keyChar==="up" || (event.keyCode == 9 && event.shiftKey)) { - if(self.currentSelection>0) { + if (keyChar==="up" || (event.keyCode == 9 && event.shiftKey)) { + if (self.currentSelection>0) { self.currentSelection-=1; } render.call(self,self.getQueryString(), self.completions); } // change selection with down or Tab - else if(keyChar==="down" || (event.keyCode == 9 && !event.shiftKey)) { - if(self.currentSelection