1 From dc926a4b6bd820cc6fa50dabba5066073a56c9b5 Mon Sep 17 00:00:00 2001
2 From: Daehyeon Jung <darrenh.jung@samsung.com>
3 Date: Thu, 9 Aug 2012 10:53:27 +0900
4 Subject: [PATCH] JQM: merge navigation from 1.2.0a for popup
6 Signed-off-by: Jung, Daehyeon <darrenh.jung@samsung.com>
8 .../js/jquery.mobile.navigation.js | 96 ++++++++++++++++++--
9 1 file changed, 86 insertions(+), 10 deletions(-)
11 diff --git a/libs/js/jquery-mobile-1.1.0/js/jquery.mobile.navigation.js b/libs/js/jquery-mobile-1.1.0/js/jquery.mobile.navigation.js
12 index ad2f67c..f6e11b3 100644
13 --- a/libs/js/jquery-mobile-1.1.0/js/jquery.mobile.navigation.js
14 +++ b/libs/js/jquery-mobile-1.1.0/js/jquery.mobile.navigation.js
15 @@ -138,6 +138,10 @@ define( [
19 + if ( absUrl === undefined ) {
20 + absUrl = documentBase;
23 var relObj = path.parseUrl( relUrl ),
24 absObj = path.parseUrl( absUrl ),
25 protocol = relObj.protocol || absObj.protocol,
26 @@ -168,7 +172,8 @@ define( [
27 } else if ( path.isSameDomain( u, documentBase ) ) {
28 return u.hrefNoHash.replace( documentBase.domain, "" );
32 + return window.decodeURIComponent(absUrl);
35 //get path from current hash, or from a file path
36 @@ -211,6 +216,10 @@ define( [
37 return path.stripHash( hash.replace( /\?.*$/, "" ).replace( dialogHashKey, "" ) );
40 + isHashValid: function( hash ) {
41 + return ( /^#[^#]+$/ ).test( hash );
44 //check whether a url is referencing the same domain, or an external domain or different protocol
45 //could be mailto, etc
46 isExternal: function( url ) {
47 @@ -253,7 +262,20 @@ define( [
48 if ( u.protocol !== "" ) {
49 return ( u.hash && ( u.hrefNoHash === documentUrl.hrefNoHash || ( documentBaseDiffers && u.hrefNoHash === documentBase.hrefNoHash ) ) );
51 - return (/^#/).test( u.href );
52 + return ( /^#/ ).test( u.href );
56 + // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
57 + // requests if the document doing the request was loaded via the file:// protocol.
58 + // This is usually to allow the application to "phone home" and fetch app specific
59 + // data. We normally let the browser handle external/cross-domain urls, but if the
60 + // allowCrossDomainPages option is true, we will allow cross-domain http/https
61 + // requests to go through our page loading logic.
62 + isPermittedCrossDomainRequest: function( docUrl, reqUrl ) {
63 + return $.mobile.allowCrossDomainPages &&
64 + docUrl.protocol === "file:" &&
65 + reqUrl.search( /^https?:/ ) !== -1;
69 @@ -307,7 +329,7 @@ define( [
70 $.each( urlHistory.stack, function( i, historyEntry ) {
72 //if the url is in the stack, it's a forward or a back
73 - if( opts.currentUrl === historyEntry.url ) {
74 + if ( decodeURIComponent( opts.currentUrl ) === decodeURIComponent( historyEntry.url ) ) {
75 //define back and forward by whether url is older or newer than current page
76 back = i < urlHistory.activeIndex;
78 @@ -398,7 +420,7 @@ define( [
80 //remove active classes after page transition or error
81 function removeActiveLinkClass( forceRemoval ) {
82 - if( !!$activeClickedLink && ( !$activeClickedLink.closest( '.ui-page-active' ).length || forceRemoval ) ) {
83 + if ( !!$activeClickedLink && ( !$activeClickedLink.closest( "." + $.mobile.activePageClass ).length || forceRemoval ) ) {
84 $activeClickedLink.removeClass( $.mobile.activeBtnClass );
86 $activeClickedLink = null;
87 @@ -667,7 +689,8 @@ define( [
88 // attribute and in need of enhancement.
89 if ( page.length === 0 && dataUrl && !path.isPath( dataUrl ) ) {
90 page = settings.pageContainer.children( "#" + dataUrl )
91 - .attr( "data-" + $.mobile.ns + "url", dataUrl );
92 + .attr( "data-" + $.mobile.ns + "url", dataUrl )
93 + .jqmData( "url", dataUrl );
96 // If we failed to find a page in the DOM, check the URL to see if it
97 @@ -1002,6 +1025,16 @@ define( [
98 if( fromPage && fromPage[0] === toPage[0] && !settings.allowSamePageTransition ) {
99 isPageTransitioning = false;
100 mpc.trigger( "pagechange", triggerData );
102 + // Even if there is no page change to be done, we should keep the urlHistory in sync with the hash changes
103 + if ( settings.fromHashChange ) {
104 + urlHistory.directHashChange({
106 + isBack: function() {},
107 + isForward: function() {}
114 @@ -1033,6 +1066,9 @@ define( [
118 + // Record whether we are at a place in history where a dialog used to be - if so, do not add a new history entry and do not change the hash either
119 + var alreadyThere = false;
121 // If we're displaying the page as a dialog, we don't want the url
122 // for the dialog content to be used in the hash. Instead, we want
123 // to append the dialogHashKey to the url of the current page.
124 @@ -1041,7 +1077,24 @@ define( [
125 // be an empty string. Moving the undefined -> empty string back into
126 // urlHistory.addNew seemed imprudent given undefined better represents
129 + // If we are at a place in history that once belonged to a dialog, reuse
130 + // this state without adding to urlHistory and without modifying the hash.
131 + // However, if a dialog is already displayed at this point, and we're
132 + // about to display another dialog, then we must add another hash and
133 + // history entry on top so that one may navigate back to the original dialog
134 + if ( active.url.indexOf( dialogHashKey ) > -1 && !$.mobile.activePage.is( ".ui-dialog" ) ) {
135 + settings.changeHash = false;
136 + alreadyThere = true;
139 url = ( active.url || "" ) + dialogHashKey;
141 + // tack on another dialogHashKey if this is the same as the initial hash
142 + // this makes sure that a history entry is created for this dialog
143 + if ( urlHistory.activeIndex === 0 && url === urlHistory.initialDst ) {
144 + url += dialogHashKey;
148 // Set the location hash.
149 @@ -1068,7 +1121,7 @@ define( [
150 || ( isDialog ? $.mobile.defaultDialogTransition : $.mobile.defaultPageTransition );
152 //add page to history stack if it's not back or forward
153 - if( !historyDir ) {
154 + if ( !historyDir && !alreadyThere ) {
155 urlHistory.addNew( url, settings.transition, pageTitle, pageUrl, settings.role );
158 @@ -1193,8 +1246,7 @@ define( [
160 url = path.makeUrlAbsolute( url, getClosestBaseUrl($this) );
162 - //external submits use regular HTTP
163 - if( path.isExternal( url ) || target ) {
164 + if ( ( path.isExternal( url ) && !path.isPermittedCrossDomainRequest( documentUrl, url ) ) || target ) {
168 @@ -1344,7 +1396,7 @@ define( [
169 //this may need to be more specific as we use data-rel more
170 role = $link.attr( "data-" + $.mobile.ns + "rel" ) || undefined;
172 - $.mobile.changePage( href, { transition: transition, reverse: reverse, role: role } );
173 + $.mobile.changePage( href, { transition: transition, reverse: reverse, role: role, link: $link } );
174 event.preventDefault();
177 @@ -1369,6 +1421,9 @@ define( [
178 //transition is false if it's the first page, undefined otherwise (and may be overridden by default)
179 transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
181 + // "navigate" event fired to allow others to take advantage of the more robust hashchange handling
182 + navEvent = new $.Event( "navigate" ),
184 // default options for the changPage calls made after examining the current state
185 // of the page and the hash
186 changePageOptions = {
187 @@ -1377,6 +1432,17 @@ define( [
191 + if ( 0 === urlHistory.stack.length ) {
192 + urlHistory.initialDst = to;
195 + // We should probably fire the "navigate" event from those places that make calls to _handleHashChange,
196 + // and have _handleHashChange hook into the "navigate" event instead of triggering it here
197 + $.mobile.pageContainer.trigger( navEvent );
198 + if ( navEvent.isDefaultPrevented() ) {
202 //if listening is disabled (either globally or temporarily), or it's a dialog hash
203 if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
204 urlHistory.ignoreNextHashChange = false;
205 @@ -1432,6 +1498,14 @@ define( [
206 // since the hashchange could've been the result of a forward/backward navigation
207 // that crosses from an external page/dialog to an internal page/dialog.
208 to = ( typeof to === "string" && !path.isPath( to ) ) ? ( path.makeUrlAbsolute( '#' + to, documentBase ) ) : to;
210 + // If we're about to go to an initial URL that contains a reference to a non-existent
211 + // internal page, go to the first page instead. We know that the initial hash refers to a
212 + // non-existent page, because the initial hash did not end up in the initial urlHistory entry
213 + if ( to === path.makeUrlAbsolute( '#' + urlHistory.initialDst, documentBase ) &&
214 + urlHistory.stack.length && urlHistory.stack[0].url !== urlHistory.initialDst.replace( dialogHashKey, "" ) ) {
215 + to = $.mobile.firstPage;
217 $.mobile.changePage( to, changePageOptions );
219 //there's no hash, go to the first page in the dom
220 @@ -1441,7 +1515,9 @@ define( [
222 //hashchange event handler
223 $window.bind( "hashchange", function( e, triggered ) {
224 - $.mobile._handleHashChange( location.hash );
225 + // Firefox auto-escapes the location.hash as for v13 but
226 + // leaves the href untouched
227 + $.mobile._handleHashChange( path.parseUrl(location.href).hash );
230 //set page min-heights to be device specific