Skip to content

Commit 85ef909

Browse files
committed
Fixed undefined bug
1 parent 7648b4a commit 85ef909

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

src/Utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/// <reference path="d.ts/DefinitelyTyped/chrome/chrome.d.ts"/>
22

33
module Utils {
4-
var logging = true;
5-
export function log(message: string) {
4+
var logging = false;
5+
export function log(message: any) {
66
if (logging) {
77
console.log(message);
88
}
@@ -14,16 +14,16 @@ module Utils {
1414

1515
export function withActiveTab(callback: ActiveTabCallback) {
1616
chrome.tabs.query({ active: true, lastFocusedWindow: true },
17-
function (tabs: chrome.tabs.Tab[]) {
17+
function(tabs: chrome.tabs.Tab[]) {
1818

1919
console.assert(tabs.length == 1);
2020
callback(tabs[0]);
2121
});
2222
}
2323

2424
export function sendCommand(commandName: string, responseHandler?: any): void {
25-
(function (commandName, responseHandler) {
26-
withActiveTab(function (tab: chrome.tabs.Tab) {
25+
(function(commandName, responseHandler) {
26+
withActiveTab(function(tab: chrome.tabs.Tab) {
2727
if (typeof responseHandler === "undefined") {
2828
responseHandler = null;
2929
}

src/background/TabStateManager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ class TabStateManager {
2323
public set(tabId: number, propName: string, propVal: any);
2424
public set(tabId: number, stateOrPropName: any, propVal?: any) {
2525
if (typeof propVal === "undefined") {
26+
Utils.log("Set " + tabId + " to:");
27+
Utils.log(stateOrPropName);
2628
this.tabStates[tabId] = stateOrPropName;
27-
}
28-
else {
29+
} else {
30+
Utils.log("Set " + stateOrPropName + " for " + tabId + " to " + propVal);
2931
this.tabStates[tabId][stateOrPropName] = propVal;
3032
}
3133
}
@@ -34,9 +36,7 @@ class TabStateManager {
3436
public get(tabId: number, propName: string): any;
3537
public get(tabId: number, propName?: string) {
3638
if (typeof propName === "undefined") {
37-
return this.tabStates[tabId];
38-
}
39-
else {
39+
} else {
4040
return this.tabStates[tabId][propName];
4141
}
4242
}

src/popup/popup.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Popup {
88
var queryInput = <HTMLInputElement> document.getElementById("query");
99
var caseInsensitiveCheckbox = <HTMLInputElement> document.getElementById("case-insensitive");
1010

11-
Utils.withActiveTab(function (tab: chrome.tabs.Tab) {
11+
Utils.withActiveTab(function(tab: chrome.tabs.Tab) {
1212
var id = tab.id;
1313
var tabStates = BackgroundInterface.getTabStateManager();
1414

@@ -18,6 +18,8 @@ module Popup {
1818
if (!tabStates.exists(id)) {
1919
Utils.log("ID doesn't exist. Initializing entry.")
2020
tabStates.resetState(id);
21+
var tabState = tabStates.get(id);
22+
Utils.log(tabState);
2123
}
2224

2325
addListeners(id, tabStates);
@@ -44,27 +46,27 @@ module Popup {
4446
}
4547
}
4648

47-
var queryInputInput = () => {
48-
tabStates.set(id, "query", this.value);
49+
var queryInputInput = function() {
50+
tabStates.set(id, "query", queryInput.value);
4951

5052
if (tabStates.isSearching(id)) {
5153
tabStates.set(id, "searching", false);
5254
Utils.sendCommand("clear");
5355
}
5456

5557
// Remove the invalid class if it's there
56-
this.className = '';
58+
queryInput.className = '';
5759

58-
if (this.value == "") {
60+
if (queryInput.value == "") {
5961
setEnabled("next", false);
6062
} else {
6163
setEnabled("next", true);
6264
}
6365
}
6466

6567
var checkboxClick = function() {
66-
Utils.log("Set checkbox state to " + this.checked);
67-
tabStates.set(id, "caseInsensitive", this.checked);
68+
Utils.log("Set checkbox state to " + caseInsensitiveCheckbox.checked);
69+
tabStates.set(id, "caseInsensitive", caseInsensitiveCheckbox.checked);
6870
}
6971

7072
prevButton.addEventListener("click", prevButtonClick);

0 commit comments

Comments
 (0)