|
1 | 1 | /*! |
2 | | - * jQuery hashchange event - v1.3pre - 7/5/2010 |
| 2 | + * jQuery hashchange event - v1.3pre - 7/6/2010 |
3 | 3 | * http://benalman.com/projects/jquery-hashchange-plugin/ |
4 | 4 | * |
5 | 5 | * Copyright (c) 2010 "Cowboy" Ben Alman |
|
9 | 9 |
|
10 | 10 | // Script: jQuery hashchange event |
11 | 11 | // |
12 | | -// *Version: 1.3pre, Last updated: 7/5/2010* |
| 12 | +// *Version: 1.3pre, Last updated: 7/6/2010* |
13 | 13 | // |
14 | 14 | // Project Home - http://benalman.com/projects/jquery-hashchange-plugin/ |
15 | 15 | // GitHub - http://github.com/cowboy/jquery-hashchange/ |
|
37 | 37 | // reside (so you can test it yourself). |
38 | 38 | // |
39 | 39 | // jQuery Versions - 1.2.6, 1.3.2, 1.4.1, 1.4.2 |
40 | | -// Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Safari 3-5, Chrome 3-5, Opera 9.6-10.5. |
| 40 | +// Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Chrome 3-5, Safari 3-5, |
| 41 | +// Opera 9.6-10.60, iPhone 3.1, Android 2.1, BlackBerry 4.6-5. |
41 | 42 | // Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/ |
42 | 43 | // |
43 | 44 | // About: Known issues |
|
54 | 55 | // |
55 | 56 | // About: Release History |
56 | 57 | // |
57 | | -// 1.3pre - (7/5/2010) Reorganized IE6/7 Iframe code to make it more |
| 58 | +// 1.3pre - (7/6/2010) Reorganized IE6/7 Iframe code to make it more |
58 | 59 | // "removable" for mobile development. Added <jQuery.hashchangeDomain>, |
59 | 60 | // <jQuery.hashchangeIframeSrc> properties and document-domain.html |
60 | 61 | // file to address access denied issues when setting document.domain in |
|
85 | 86 | var str_hashchange = 'hashchange', |
86 | 87 |
|
87 | 88 | // Method / object references. |
| 89 | + doc = document, |
88 | 90 | fake_onhashchange, |
89 | 91 | jq_event_special = $.event.special, |
90 | 92 |
|
91 | | - // IE6/7 specifically need some special love when it comes to back-button |
92 | | - // support, so let's do a little browser sniffing.. |
93 | | - browser = $.browser, |
94 | | - mode = document.documentMode, |
95 | | - is_old_ie = browser.msie && ( mode === undefined || mode < 8 ), |
96 | | - |
97 | | - // Does the browser support window.onhashchange? |
98 | | - supports_onhashchange = 'on' + str_hashchange in window && ( mode === undefined || mode > 7 ); |
| 93 | + // Does the browser support window.onhashchange? Note that IE8 running in |
| 94 | + // IE7 compatibility mode reports true for 'onhashchange' in window, even |
| 95 | + // though the event isn't supported, so also test document.documentMode. |
| 96 | + doc_mode = doc.documentMode, |
| 97 | + supports_onhashchange = 'on' + str_hashchange in window && ( doc_mode === undefined || doc_mode > 7 ); |
99 | 98 |
|
100 | 99 | // Get location.hash (or what you'd expect location.hash to be) sans any |
101 | 100 | // leading #. Thanks for making this necessary, Firefox! |
|
234 | 233 | // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
235 | 234 | // vvvvvvvvvvvvvvvvvvv REMOVE IF NOT SUPPORTING IE6/7 vvvvvvvvvvvvvvvvvvv |
236 | 235 | // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
237 | | - // |
238 | | - // In IE 6/7, create a hidden Iframe for history handling. |
239 | | - is_old_ie && (function(){ |
240 | | - var iframe, |
| 236 | + (function(){ |
| 237 | + var browser = $.browser, |
| 238 | + iframe, |
241 | 239 | iframe_src; |
242 | 240 |
|
| 241 | + // If browser isn't IE 6/7, abort!! ABORT!!! |
| 242 | + if ( !browser.msie || browser.version > 7 ) { return; } |
| 243 | + |
| 244 | + // When the event is bound and polling starts in IE 6/7, create a hidden |
| 245 | + // Iframe for history handling. |
243 | 246 | self.start = function(){ |
244 | 247 | if ( !iframe ) { |
245 | 248 | iframe_src = $[ str_hashchange + 'IframeSrc' ]; |
|
267 | 270 | // prettify the back/next history menu entries. Since IE sometimes |
268 | 271 | // errors with "Unspecified error" the very first time this is set |
269 | 272 | // (yes, very useful) wrap this with a try/catch block. |
270 | | - document.onpropertychange = function(){ |
| 273 | + doc.onpropertychange = function(){ |
271 | 274 | try { |
272 | 275 | if ( event.propertyName === 'title' ) { |
273 | | - iframe.document.title = document.title; |
| 276 | + iframe.document.title = doc.title; |
274 | 277 | } |
275 | 278 | } catch(e) {} |
276 | 279 | }; |
|
292 | 295 | // document, *then* setting its location.hash. If document.domain has |
293 | 296 | // been set, update that as well. |
294 | 297 | history_set = function( hash, history_hash ) { |
295 | | - var doc = iframe.document, |
| 298 | + var iframe_doc = iframe.document, |
296 | 299 | domain = $[ str_hashchange + 'Domain' ]; |
297 | 300 |
|
298 | 301 | if ( hash !== history_hash ) { |
299 | 302 | // Update Iframe with any initial `document.title` that might be set. |
300 | | - doc.title = document.title; |
| 303 | + iframe_doc.title = doc.title; |
301 | 304 |
|
302 | 305 | // Opening the Iframe's document after it has been closed is what |
303 | 306 | // actually adds a history entry. |
304 | | - doc.open(); |
305 | | - domain && doc.write( '<script>document.domain="' + domain + '"</script>' ); |
306 | | - doc.close(); |
| 307 | + iframe_doc.open(); |
| 308 | + domain && iframe_doc.write( '<script>document.domain="' + domain + '"</script>' ); |
| 309 | + iframe_doc.close(); |
307 | 310 |
|
308 | 311 | // Update the Iframe's hash, for great justice. |
309 | 312 | iframe.location.hash = hash; |
|
0 commit comments