Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 04636aa

Browse files
committed
create content widget, move navigate binding in
1 parent 94b59a3 commit 04636aa

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

js/jquery.mobile.init.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ define([
7676
$.mobile.firstPage = $pages.first();
7777

7878
// define page container
79-
$.mobile.pageContainer = $.mobile.firstPage.parent().addClass( "ui-mobile-viewport" );
79+
$.mobile.pageContainer = $.mobile.firstPage
80+
.parent()
81+
.addClass( "ui-mobile-viewport" )
82+
.content();
8083

8184
// initialize navigation events now, after mobileinit has occurred and the page container
8285
// has been created but before the rest of the library is alerted to that fact

js/jquery.mobile.navigation.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@ define( [
1818
//>>excludeEnd("jqmBuildExclude");
1919
(function( $, undefined ) {
2020

21+
$.widget( "mobile.content", $.mobile.widget, {
22+
// element should be the $.mobile.pageContainer
23+
24+
_create: function() {
25+
// TODO roll the logic here into the handleHashChange method
26+
this._on( $window, { navigate: 'filterNavigateEvents' });
27+
28+
// navigate binding using _on
29+
},
30+
31+
filterNavigateEvents: function( e, data ) {
32+
var url;
33+
34+
if ( e.originalEvent && e.originalEvent.isDefaultPrevented() ) {
35+
return;
36+
}
37+
38+
url = $.event.special.navigate.originalEventName.indexOf( "hashchange" ) > -1 ? data.state.hash : data.state.url;
39+
40+
if( !url ) {
41+
url = $.mobile.path.parseLocation().hash;
42+
}
43+
44+
if( !url || url === "#" || url.indexOf( "#" + $.mobile.path.uiStateKey ) === 0 ){
45+
url = location.href;
46+
}
47+
48+
$.mobile._handleHashChange( url, data.state );
49+
}
50+
51+
// handle hashchange
52+
// focus page
53+
// scroll position
54+
// transitionPages
55+
// resetActivePageHeight
56+
// enhancePage
57+
// _bindPageRemove
58+
// enhancePage
59+
// loadPage
60+
// changePage
61+
});
62+
2163
//define vars for interal use
2264
var $window = $.mobile.window,
2365
$head = $( "head" ),
@@ -1361,27 +1403,6 @@ define( [
13611403
}
13621404
};
13631405

1364-
// TODO roll the logic here into the handleHashChange method
1365-
$window.bind( "navigate", function( e, data ) {
1366-
var url;
1367-
1368-
if ( e.originalEvent && e.originalEvent.isDefaultPrevented() ) {
1369-
return;
1370-
}
1371-
1372-
url = $.event.special.navigate.originalEventName.indexOf( "hashchange" ) > -1 ? data.state.hash : data.state.url;
1373-
1374-
if( !url ) {
1375-
url = $.mobile.path.parseLocation().hash;
1376-
}
1377-
1378-
if( !url || url === "#" || url.indexOf( "#" + $.mobile.path.uiStateKey ) === 0 ){
1379-
url = location.href;
1380-
}
1381-
1382-
$.mobile._handleHashChange( url, data.state );
1383-
});
1384-
13851406
//set page min-heights to be device specific
13861407
$.mobile.document.bind( "pageshow", $.mobile.resetActivePageHeight );
13871408
$.mobile.window.bind( "throttledresize", $.mobile.resetActivePageHeight );

0 commit comments

Comments
 (0)