@@ -24,8 +24,27 @@ module Popup {
24
24
25
25
addListeners ( id , tabStates ) ;
26
26
restoreState ( id , tabStates ) ;
27
+
28
+ setNextButtonState ( ) ;
29
+ setPrevButtonState ( id , tabStates ) ;
27
30
} ) ;
28
31
32
+ function setNextButtonState ( ) {
33
+ if ( queryInput . value == "" ) {
34
+ nextButton . disabled = true ;
35
+ } else {
36
+ nextButton . disabled = false ;
37
+ }
38
+ }
39
+
40
+ function setPrevButtonState ( tabId : number , tabStates : TabStateManager ) {
41
+ if ( tabStates . isSearching ( tabId ) ) {
42
+ prevButton . disabled = false ;
43
+ } else {
44
+ prevButton . disabled = true ;
45
+ }
46
+ }
47
+
29
48
function addListeners ( id : number , tabStates : TabStateManager ) {
30
49
var prevButtonClick = function ( ) {
31
50
Utils . sendCommand ( "prev" ) ;
@@ -50,18 +69,14 @@ module Popup {
50
69
tabStates . set ( id , "query" , queryInput . value ) ;
51
70
52
71
if ( tabStates . isSearching ( id ) ) {
53
- tabStates . set ( id , "searching" , false ) ;
72
+ setSearching ( id , false , tabStates ) ;
54
73
Utils . sendCommand ( "clear" ) ;
55
74
}
56
75
57
76
// Remove the invalid class if it's there
58
77
queryInput . className = '' ;
59
78
60
- if ( queryInput . value == "" ) {
61
- setEnabled ( "next" , false ) ;
62
- } else {
63
- setEnabled ( "next" , true ) ;
64
- }
79
+ setNextButtonState ( ) ;
65
80
}
66
81
67
82
var checkboxClick = function ( ) {
@@ -78,12 +93,6 @@ module Popup {
78
93
79
94
function restoreState ( tabId : number , tabStates : TabStateManager ) {
80
95
queryInput . value = tabStates . get ( tabId , "query" ) ;
81
- if ( queryInput . value == "" ) {
82
- setEnabled ( "next" , false ) ;
83
- } else {
84
- setEnabled ( "next" , true ) ;
85
- }
86
-
87
96
caseInsensitiveCheckbox . checked = tabStates . get ( tabId , "caseInsensitive" ) ;
88
97
}
89
98
@@ -98,13 +107,18 @@ module Popup {
98
107
caseInsensitive : insensitive ,
99
108
regexp : queryInput . value
100
109
} ) ;
101
- tabStates . set ( tabId , "searching" , true ) ;
110
+ setSearching ( tabId , true , tabStates ) ;
102
111
} else {
103
112
Utils . log ( "Invalid regex" ) ;
104
113
queryInput . className = 'invalid' ;
105
114
}
106
115
}
107
116
117
+ function setSearching ( tabId : number , val : boolean , tabStates : TabStateManager ) {
118
+ tabStates . set ( tabId , "searching" , val ) ;
119
+ setPrevButtonState ( tabId , tabStates ) ;
120
+ }
121
+
108
122
function validate ( regexp : string ) : boolean {
109
123
if ( regexp != "" ) {
110
124
try {
@@ -115,8 +129,4 @@ module Popup {
115
129
}
116
130
return false ;
117
131
}
118
-
119
- function setEnabled ( id : string , val : boolean ) {
120
- document . getElementById ( id ) . disabled = ! val ;
121
- }
122
132
}
0 commit comments