@@ -19,7 +19,9 @@ var JQD = (function($, window, document, undefined) {
19
19
// Initialize the clock.
20
20
//
21
21
clock : function ( ) {
22
- if ( ! $ ( '#clock' ) . length ) {
22
+ var clock = $ ( '#clock' ) ;
23
+
24
+ if ( ! clock . length ) {
23
25
return ;
24
26
}
25
27
@@ -86,7 +88,7 @@ var JQD = (function($, window, document, undefined) {
86
88
var clock_date = month + ' ' + day + ', ' + year ;
87
89
88
90
// Shove in the HTML.
89
- $ ( '# clock' ) . html ( clock_time ) . attr ( 'title' , clock_date ) ;
91
+ clock . html ( clock_time ) . attr ( 'title' , clock_date ) ;
90
92
91
93
// Update every 60 seconds.
92
94
setTimeout ( JQD . init . clock , 60000 ) ;
@@ -95,21 +97,27 @@ var JQD = (function($, window, document, undefined) {
95
97
// Initialize the desktop.
96
98
//
97
99
desktop : function ( ) {
98
- // Cancel mousedown, right-click.
99
- $ ( document ) . mousedown ( function ( ev ) {
100
+ // Alias to document.
101
+ var d = $ ( document ) ;
102
+
103
+ // Cancel mousedown.
104
+ d . mousedown ( function ( ev ) {
100
105
var tags = [ 'a' , 'button' , 'input' , 'select' , 'textarea' ] ;
101
106
102
107
if ( ! $ ( ev . target ) . closest ( tags ) . length ) {
103
108
JQD . util . clear_active ( ) ;
104
109
ev . preventDefault ( ) ;
105
110
ev . stopPropagation ( ) ;
106
111
}
107
- } ) . bind ( 'contextmenu' , function ( ) {
112
+ } ) ;
113
+
114
+ // Cancel right-click.
115
+ d . on ( 'contextmenu' , function ( ) {
108
116
return false ;
109
117
} ) ;
110
118
111
119
// Relative or remote links?
112
- $ ( 'a' ) . live ( 'click' , function ( ev ) {
120
+ d . on ( 'click' , 'a ', function ( ev ) {
113
121
var url = $ ( this ) . attr ( 'href' ) ;
114
122
this . blur ( ) ;
115
123
@@ -123,28 +131,33 @@ var JQD = (function($, window, document, undefined) {
123
131
} ) ;
124
132
125
133
// Make top menus active.
126
- $ ( ' a.menu_trigger' ) . live ( 'mousedown ', function ( ) {
134
+ d . on ( 'mousedown' , ' a.menu_trigger', function ( ) {
127
135
if ( $ ( this ) . next ( 'ul.menu' ) . is ( ':hidden' ) ) {
128
136
JQD . util . clear_active ( ) ;
129
137
$ ( this ) . addClass ( 'active' ) . next ( 'ul.menu' ) . show ( ) ;
130
138
}
131
139
else {
132
140
JQD . util . clear_active ( ) ;
133
141
}
134
- } ) . live ( 'mouseenter' , function ( ) {
135
- // Transfer focus, if already open.
142
+ } ) ;
143
+
144
+ // Transfer focus, if already open.
145
+ d . on ( 'mouseenter' , 'a.menu_trigger' , function ( ) {
136
146
if ( $ ( 'ul.menu' ) . is ( ':visible' ) ) {
137
147
JQD . util . clear_active ( ) ;
138
148
$ ( this ) . addClass ( 'active' ) . next ( 'ul.menu' ) . show ( ) ;
139
149
}
140
150
} ) ;
141
151
142
- // Desktop icons .
143
- $ ( ' a.icon' ) . live ( 'mousedown ', function ( ) {
152
+ // Cancel single-click .
153
+ d . on ( 'mousedown' , ' a.icon', function ( ) {
144
154
// Highlight the icon.
145
155
JQD . util . clear_active ( ) ;
146
156
$ ( this ) . addClass ( 'active' ) ;
147
- } ) . live ( 'dblclick' , function ( ) {
157
+ } ) ;
158
+
159
+ // Respond to double-click.
160
+ d . on ( 'dblclick' , 'a.icon' , function ( ) {
148
161
// Get the link's target.
149
162
var x = $ ( this ) . attr ( 'href' ) ;
150
163
var y = $ ( x ) . find ( 'a' ) . attr ( 'href' ) ;
@@ -158,15 +171,18 @@ var JQD = (function($, window, document, undefined) {
158
171
// Bring window to front.
159
172
JQD . util . window_flat ( ) ;
160
173
$ ( y ) . addClass ( 'window_stack' ) . show ( ) ;
161
- } ) . live ( 'mouseenter' , function ( ) {
162
- $ ( this ) . die ( 'mouseenter' ) . draggable ( {
174
+ } ) ;
175
+
176
+ // Make icons draggable.
177
+ d . on ( 'mouseenter' , 'a.icon' , function ( ) {
178
+ $ ( this ) . off ( 'mouseenter' ) . draggable ( {
163
179
revert : true ,
164
180
containment : 'parent'
165
181
} ) ;
166
182
} ) ;
167
183
168
184
// Taskbar buttons.
169
- $ ( ' #dock a' ) . live ( 'click ', function ( ) {
185
+ d . on ( 'click' , ' #dock a', function ( ) {
170
186
// Get the link's target.
171
187
var x = $ ( $ ( this ) . attr ( 'href' ) ) ;
172
188
@@ -181,13 +197,16 @@ var JQD = (function($, window, document, undefined) {
181
197
}
182
198
} ) ;
183
199
184
- // Make windows movable .
185
- $ ( ' div.window' ) . live ( 'mousedown ', function ( ) {
200
+ // Focus active window .
201
+ d . on ( 'mousedown' , ' div.window', function ( ) {
186
202
// Bring window to front.
187
203
JQD . util . window_flat ( ) ;
188
204
$ ( this ) . addClass ( 'window_stack' ) ;
189
- } ) . live ( 'mouseenter' , function ( ) {
190
- $ ( this ) . die ( 'mouseenter' ) . draggable ( {
205
+ } ) ;
206
+
207
+ // Make windows draggable.
208
+ d . on ( 'mouseenter' , 'div.window' , function ( ) {
209
+ $ ( this ) . off ( 'mouseenter' ) . draggable ( {
191
210
// Confine to desktop.
192
211
// Movable via top bar only.
193
212
cancel : 'a' ,
@@ -198,13 +217,15 @@ var JQD = (function($, window, document, undefined) {
198
217
minWidth : 400 ,
199
218
minHeight : 200
200
219
} ) ;
220
+ } ) ;
201
221
202
222
// Double-click top bar to resize, ala Windows OS.
203
- } ) . find ( ' div.window_top' ) . live ( 'dblclick ', function ( ) {
223
+ d . on ( 'dblclick' , ' div.window_top', function ( ) {
204
224
JQD . util . window_resize ( this ) ;
225
+ } ) ;
205
226
206
227
// Double click top bar icon to close, ala Windows OS.
207
- } ) . find ( 'img' ) . live ( 'dblclick ', function ( ) {
228
+ d . on ( 'dblclick' , 'div.window_top img ', function ( ) {
208
229
// Traverse to the close button, and hide its taskbar button.
209
230
$ ( $ ( this ) . closest ( 'div.window_top' ) . find ( 'a.window_close' ) . attr ( 'href' ) ) . hide ( 'fast' ) ;
210
231
@@ -216,23 +237,23 @@ var JQD = (function($, window, document, undefined) {
216
237
} ) ;
217
238
218
239
// Minimize the window.
219
- $ ( ' a.window_min' ) . live ( 'click ', function ( ) {
240
+ d . on ( 'click' , ' a.window_min', function ( ) {
220
241
$ ( this ) . closest ( 'div.window' ) . hide ( ) ;
221
242
} ) ;
222
243
223
244
// Maximize or restore the window.
224
- $ ( ' a.window_resize' ) . live ( 'click ', function ( ) {
245
+ d . on ( 'click' , ' a.window_resize', function ( ) {
225
246
JQD . util . window_resize ( this ) ;
226
247
} ) ;
227
248
228
249
// Close the window.
229
- $ ( ' a.window_close' ) . live ( 'click ', function ( ) {
250
+ d . on ( 'click' , ' a.window_close', function ( ) {
230
251
$ ( this ) . closest ( 'div.window' ) . hide ( ) ;
231
252
$ ( $ ( this ) . attr ( 'href' ) ) . hide ( 'fast' ) ;
232
253
} ) ;
233
254
234
255
// Show desktop button, ala Windows OS.
235
- $ ( '#show_desktop' ) . live ( 'mousedown' , function ( ) {
256
+ d . on ( 'mousedown' , '#show_desktop ', function ( ) {
236
257
// If any windows are visible, hide all.
237
258
if ( $ ( 'div.window:visible' ) . length ) {
238
259
$ ( 'div.window' ) . hide ( ) ;
@@ -248,7 +269,9 @@ var JQD = (function($, window, document, undefined) {
248
269
$ ( 'table.data' ) . each ( function ( ) {
249
270
// Add zebra striping, ala Mac OS X.
250
271
$ ( this ) . find ( 'tbody tr:odd' ) . addClass ( 'zebra' ) ;
251
- } ) . find ( 'tr' ) . live ( 'mousedown' , function ( ) {
272
+ } ) ;
273
+
274
+ d . on ( 'mousedown' , 'table.data tr' , function ( ) {
252
275
// Highlight row, ala Mac OS X.
253
276
$ ( this ) . closest ( 'tr' ) . addClass ( 'active' ) ;
254
277
} ) ;
0 commit comments