Skip to content

Commit d6157dd

Browse files
committed
Replacing the deprecated .live() with .on() — And updated references to jQuery to 1.7.1
1 parent d38d416 commit d6157dd

File tree

4 files changed

+58
-33
lines changed

4 files changed

+58
-33
lines changed

ajax_load.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<!--[if lt IE 9]>
1616
<link rel="stylesheet" href="assets/css/ie.css" />
1717
<![endif]-->
18-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
18+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
1919
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
2020
<script>
2121
!window.jQuery && document.write(unescape('%3Cscript src="assets/js/jquery.js"%3E%3C/script%3E'));
@@ -26,10 +26,12 @@
2626
jQuery(document).ready(function($) {
2727
$('#ajax_load_trigger').click(function() {
2828
$(this).remove();
29+
2930
$('body').load('index.html #wrapper', function() {
3031
JQD.init.clock();
3132
JQD.init.wallpaper();
3233
});
34+
3335
return false;
3436
});
3537
});

assets/js/jquery.desktop.js

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ var JQD = (function($, window, document, undefined) {
1919
// Initialize the clock.
2020
//
2121
clock: function() {
22-
if (!$('#clock').length) {
22+
var clock = $('#clock');
23+
24+
if (!clock.length) {
2325
return;
2426
}
2527

@@ -86,7 +88,7 @@ var JQD = (function($, window, document, undefined) {
8688
var clock_date = month + ' ' + day + ', ' + year;
8789

8890
// Shove in the HTML.
89-
$('#clock').html(clock_time).attr('title', clock_date);
91+
clock.html(clock_time).attr('title', clock_date);
9092

9193
// Update every 60 seconds.
9294
setTimeout(JQD.init.clock, 60000);
@@ -95,21 +97,27 @@ var JQD = (function($, window, document, undefined) {
9597
// Initialize the desktop.
9698
//
9799
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) {
100105
var tags = ['a', 'button', 'input', 'select', 'textarea'];
101106

102107
if (!$(ev.target).closest(tags).length) {
103108
JQD.util.clear_active();
104109
ev.preventDefault();
105110
ev.stopPropagation();
106111
}
107-
}).bind('contextmenu', function() {
112+
});
113+
114+
// Cancel right-click.
115+
d.on('contextmenu', function() {
108116
return false;
109117
});
110118

111119
// Relative or remote links?
112-
$('a').live('click', function(ev) {
120+
d.on('click', 'a', function(ev) {
113121
var url = $(this).attr('href');
114122
this.blur();
115123

@@ -123,28 +131,33 @@ var JQD = (function($, window, document, undefined) {
123131
});
124132

125133
// Make top menus active.
126-
$('a.menu_trigger').live('mousedown', function() {
134+
d.on('mousedown', 'a.menu_trigger', function() {
127135
if ($(this).next('ul.menu').is(':hidden')) {
128136
JQD.util.clear_active();
129137
$(this).addClass('active').next('ul.menu').show();
130138
}
131139
else {
132140
JQD.util.clear_active();
133141
}
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() {
136146
if ($('ul.menu').is(':visible')) {
137147
JQD.util.clear_active();
138148
$(this).addClass('active').next('ul.menu').show();
139149
}
140150
});
141151

142-
// Desktop icons.
143-
$('a.icon').live('mousedown', function() {
152+
// Cancel single-click.
153+
d.on('mousedown', 'a.icon', function() {
144154
// Highlight the icon.
145155
JQD.util.clear_active();
146156
$(this).addClass('active');
147-
}).live('dblclick', function() {
157+
});
158+
159+
// Respond to double-click.
160+
d.on('dblclick', 'a.icon', function() {
148161
// Get the link's target.
149162
var x = $(this).attr('href');
150163
var y = $(x).find('a').attr('href');
@@ -158,15 +171,18 @@ var JQD = (function($, window, document, undefined) {
158171
// Bring window to front.
159172
JQD.util.window_flat();
160173
$(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({
163179
revert: true,
164180
containment: 'parent'
165181
});
166182
});
167183

168184
// Taskbar buttons.
169-
$('#dock a').live('click', function() {
185+
d.on('click', '#dock a', function() {
170186
// Get the link's target.
171187
var x = $($(this).attr('href'));
172188

@@ -181,13 +197,16 @@ var JQD = (function($, window, document, undefined) {
181197
}
182198
});
183199

184-
// Make windows movable.
185-
$('div.window').live('mousedown', function() {
200+
// Focus active window.
201+
d.on('mousedown', 'div.window', function() {
186202
// Bring window to front.
187203
JQD.util.window_flat();
188204
$(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({
191210
// Confine to desktop.
192211
// Movable via top bar only.
193212
cancel: 'a',
@@ -198,13 +217,15 @@ var JQD = (function($, window, document, undefined) {
198217
minWidth: 400,
199218
minHeight: 200
200219
});
220+
});
201221

202222
// 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() {
204224
JQD.util.window_resize(this);
225+
});
205226

206227
// 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() {
208229
// Traverse to the close button, and hide its taskbar button.
209230
$($(this).closest('div.window_top').find('a.window_close').attr('href')).hide('fast');
210231

@@ -216,23 +237,23 @@ var JQD = (function($, window, document, undefined) {
216237
});
217238

218239
// Minimize the window.
219-
$('a.window_min').live('click', function() {
240+
d.on('click', 'a.window_min', function() {
220241
$(this).closest('div.window').hide();
221242
});
222243

223244
// Maximize or restore the window.
224-
$('a.window_resize').live('click', function() {
245+
d.on('click', 'a.window_resize', function() {
225246
JQD.util.window_resize(this);
226247
});
227248

228249
// Close the window.
229-
$('a.window_close').live('click', function() {
250+
d.on('click', 'a.window_close', function() {
230251
$(this).closest('div.window').hide();
231252
$($(this).attr('href')).hide('fast');
232253
});
233254

234255
// Show desktop button, ala Windows OS.
235-
$('#show_desktop').live('mousedown', function() {
256+
d.on('mousedown', '#show_desktop', function() {
236257
// If any windows are visible, hide all.
237258
if ($('div.window:visible').length) {
238259
$('div.window').hide();
@@ -248,7 +269,9 @@ var JQD = (function($, window, document, undefined) {
248269
$('table.data').each(function() {
249270
// Add zebra striping, ala Mac OS X.
250271
$(this).find('tbody tr:odd').addClass('zebra');
251-
}).find('tr').live('mousedown', function() {
272+
});
273+
274+
d.on('mousedown', 'table.data tr', function() {
252275
// Highlight row, ala Mac OS X.
253276
$(this).closest('tr').addClass('active');
254277
});

assets/js/jquery.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@
10001000
<a class="menu_trigger" href="#">HTML5 Resources</a>
10011001
<ul class="menu">
10021002
<li>
1003-
<a href="http://diveintohtml5.org/">Dive Into HTML5</a>
1003+
<a href="http://diveintohtml5.info/">Dive Into HTML5</a>
10041004
</li>
10051005
<li>
10061006
<a href="http://www.alistapart.com/articles/get-ready-for-html-5/">Get Ready for HTML5</a>
@@ -1084,7 +1084,7 @@
10841084
</a>
10851085
</div>
10861086
</div>
1087-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
1087+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
10881088
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
10891089
<script>
10901090
!window.jQuery && document.write(unescape('%3Cscript src="assets/js/jquery.js"%3E%3C/script%3E'));

0 commit comments

Comments
 (0)