|
371 | 371 | } |
372 | 372 |
|
373 | 373 | //remove active classes after page transition or error |
374 | | - function removeActiveLinkClass( forceRemoval ) { |
375 | | - if( !!$activeClickedLink && ( !$activeClickedLink.closest( '.ui-page-active' ).length || forceRemoval ) ) { |
| 374 | + function removeActiveLinkClass( forceRemoval, delay ) { |
| 375 | + if ( delay ) { |
| 376 | + setTimeout( function() { removeActiveLinkClass( forceRemoval ); }, delay ); |
| 377 | + return; |
| 378 | + } |
| 379 | + |
| 380 | + if( !!$activeClickedLink && ( forceRemoval || !$activeClickedLink.closest( '.ui-page-active' ).length ) ) { |
376 | 381 | $activeClickedLink.removeClass( $.mobile.activeBtnClass ); |
377 | 382 | } |
378 | 383 | $activeClickedLink = null; |
|
582 | 587 | // within the same domain as the document base, it is the site relative |
583 | 588 | // path. For cross-domain pages (Phone Gap only) the entire absolute Url |
584 | 589 | // used to load the page. |
| 590 | + |
| 591 | + |
| 592 | + |
585 | 593 | dataUrl = path.convertUrlToDataUrl( absUrl ); |
586 | 594 |
|
587 | 595 | // Make sure we have a pageContainer to work with. |
|
988 | 996 | event.preventDefault(); |
989 | 997 | }); |
990 | 998 |
|
| 999 | + function getAjaxUrlForLink( $link ) { |
| 1000 | + var url = undefined; |
| 1001 | + if ( $.mobile.ajaxEnabled ) { |
| 1002 | + var baseUrl = getClosestBaseUrl( $link ), |
| 1003 | + |
| 1004 | + //get href, if defined, otherwise default to empty hash |
| 1005 | + url = path.makeUrlAbsolute( $link.attr( "href" ) || "#", baseUrl ); |
| 1006 | + |
| 1007 | + // XXX_jblas: Ideally links to application pages should be specified as |
| 1008 | + // an url to the application document with a hash that is either |
| 1009 | + // the site relative path or id to the page. But some of the |
| 1010 | + // internal code that dynamically generates sub-pages for nested |
| 1011 | + // lists and select dialogs, just write a hash in the link they |
| 1012 | + // create. This means the actual URL path is based on whatever |
| 1013 | + // the current value of the base tag is at the time this code |
| 1014 | + // is called. For now we are just assuming that any url with a |
| 1015 | + // hash in it is an application page reference. |
| 1016 | + if ( url.search( "#" ) != -1 ) { |
| 1017 | + url = url.replace( /[^#]*#/, "" ); |
| 1018 | + if ( url ) { |
| 1019 | + if ( path.isPath( url ) ) { |
| 1020 | + //we have apath so make it the href we want to load. |
| 1021 | + url = path.makeUrlAbsolute( href, baseUrl ); |
| 1022 | + } else { |
| 1023 | + //we have a simple id so use the documentUrl as its base. |
| 1024 | + href = path.makeUrlAbsolute( "#" + url, documentUrl.hrefNoHash ); |
| 1025 | + } |
| 1026 | + } |
| 1027 | + } |
| 1028 | + |
| 1029 | + var useDefaultUrlHandling = $link.is( "[rel='external']" ) || $link.is( ":jqmData(ajax='false')" ) || $link.is( "[target]" ), |
| 1030 | + |
| 1031 | + // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR |
| 1032 | + // requests if the document doing the request was loaded via the file:// protocol. |
| 1033 | + // This is usually to allow the application to "phone home" and fetch app specific |
| 1034 | + // data. We normally let the browser handle external/cross-domain urls, but if the |
| 1035 | + // allowCrossDomainPages option is true, we will allow cross-domain http/https |
| 1036 | + // requests to go through our page loading logic. |
| 1037 | + isCrossDomainPageLoad = ( $.mobile.allowCrossDomainPages && documentUrl.protocol === "file:" && url.search( /^https?:/ ) != -1 ), |
| 1038 | + |
| 1039 | + //check for protocol or rel and its not an embedded page |
| 1040 | + //TODO overlap in logic from isExternal, rel=external check should be |
| 1041 | + // moved into more comprehensive isExternalLink |
| 1042 | + isExternal = useDefaultUrlHandling || ( !isCrossDomainPageLoad) && path.isExternal( url ); |
| 1043 | + |
| 1044 | + if ( isExternal ) { |
| 1045 | + url = undefined; |
| 1046 | + } |
| 1047 | + } |
| 1048 | + return url; |
| 1049 | + } |
| 1050 | + |
| 1051 | + $( document ).bind( "touchend", function( event ) { |
| 1052 | + var link = findClosestLink( event.target ); |
| 1053 | + if ( link ) { |
| 1054 | + var url = getAjaxUrlForLink( $( link ) ); |
| 1055 | + if ( url && url.replace( /[^#]*#/, "" ) ) { |
| 1056 | + event.preventDefault(); |
| 1057 | + } |
| 1058 | + } |
| 1059 | + }); |
| 1060 | + |
991 | 1061 | //add active state on vclick |
992 | 1062 | $( document ).bind( "vclick", function( event ) { |
993 | 1063 | var link = findClosestLink( event.target ); |
994 | 1064 | if ( link ) { |
995 | 1065 | if ( path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" ) { |
996 | | - $( link ).closest( ".ui-btn" ).not( ".ui-disabled" ).addClass( $.mobile.activeBtnClass ); |
| 1066 | + $activeClickedLink = $( link ).closest( ".ui-btn" ).not( ".ui-disabled" ).addClass( $.mobile.activeBtnClass ); |
997 | 1067 | $( "." + $.mobile.activePageClass + " .ui-btn" ).not( link ).blur(); |
998 | 1068 | } |
999 | 1069 | } |
1000 | 1070 | }); |
1001 | 1071 |
|
1002 | 1072 | // click routing - direct to HTTP or Ajax, accordingly |
1003 | | - $( document ).bind( $.mobile.useFastClick ? "vclick" : "click", function( event ) { |
| 1073 | + $( document ).bind( "click", function( event ) { |
1004 | 1074 | var link = findClosestLink( event.target ); |
1005 | 1075 | if ( !link ) { |
1006 | 1076 | return; |
1007 | 1077 | } |
1008 | 1078 |
|
1009 | | - var $link = $( link ), |
1010 | | - //remove active link class if external (then it won't be there if you come back) |
1011 | | - httpCleanup = function(){ |
1012 | | - window.setTimeout( function() { removeActiveLinkClass( true ); }, 200 ); |
1013 | | - }; |
| 1079 | + var $link = $( link ); |
1014 | 1080 |
|
1015 | 1081 | //if there's a data-rel=back attr, go back in history |
1016 | 1082 | if( $link.is( ":jqmData(rel='back')" ) ) { |
| 1083 | + removeActiveLinkClass( true, 200 ); |
1017 | 1084 | window.history.back(); |
1018 | 1085 | return false; |
1019 | 1086 | } |
1020 | | - |
1021 | | - //if ajax is disabled, exit early |
1022 | | - if( !$.mobile.ajaxEnabled ){ |
1023 | | - httpCleanup(); |
1024 | | - //use default click handling |
1025 | | - return; |
1026 | | - } |
1027 | | - |
1028 | | - var baseUrl = getClosestBaseUrl( $link ), |
1029 | 1087 |
|
1030 | | - //get href, if defined, otherwise default to empty hash |
1031 | | - href = path.makeUrlAbsolute( $link.attr( "href" ) || "#", baseUrl ); |
1032 | | - |
1033 | | - // XXX_jblas: Ideally links to application pages should be specified as |
1034 | | - // an url to the application document with a hash that is either |
1035 | | - // the site relative path or id to the page. But some of the |
1036 | | - // internal code that dynamically generates sub-pages for nested |
1037 | | - // lists and select dialogs, just write a hash in the link they |
1038 | | - // create. This means the actual URL path is based on whatever |
1039 | | - // the current value of the base tag is at the time this code |
1040 | | - // is called. For now we are just assuming that any url with a |
1041 | | - // hash in it is an application page reference. |
1042 | | - if ( href.search( "#" ) != -1 ) { |
1043 | | - href = href.replace( /[^#]*#/, "" ); |
1044 | | - if ( !href ) { |
| 1088 | + var href = getAjaxUrlForLink( $link ), |
| 1089 | + hashOrUrl = href && href.replace( /[^#]*#/, "" ); |
| 1090 | + |
| 1091 | + if ( !href || !hashOrUrl ) { |
| 1092 | + //use default click handling |
| 1093 | + if (! hashOrUrl ) { |
1045 | 1094 | //link was an empty hash meant purely |
1046 | 1095 | //for interaction, so we ignore it. |
1047 | 1096 | event.preventDefault(); |
1048 | | - return; |
1049 | | - } else if ( path.isPath( href ) ) { |
1050 | | - //we have apath so make it the href we want to load. |
1051 | | - href = path.makeUrlAbsolute( href, baseUrl ); |
1052 | | - } else { |
1053 | | - //we have a simple id so use the documentUrl as its base. |
1054 | | - href = path.makeUrlAbsolute( "#" + href, documentUrl.hrefNoHash ); |
1055 | 1097 | } |
1056 | | - } |
1057 | | - |
1058 | | - // Should we handle this link, or let the browser deal with it? |
1059 | | - var useDefaultUrlHandling = $link.is( "[rel='external']" ) || $link.is( ":jqmData(ajax='false')" ) || $link.is( "[target]" ), |
1060 | | - |
1061 | | - // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR |
1062 | | - // requests if the document doing the request was loaded via the file:// protocol. |
1063 | | - // This is usually to allow the application to "phone home" and fetch app specific |
1064 | | - // data. We normally let the browser handle external/cross-domain urls, but if the |
1065 | | - // allowCrossDomainPages option is true, we will allow cross-domain http/https |
1066 | | - // requests to go through our page loading logic. |
1067 | | - isCrossDomainPageLoad = ( $.mobile.allowCrossDomainPages && documentUrl.protocol === "file:" && href.search( /^https?:/ ) != -1 ), |
1068 | | - |
1069 | | - //check for protocol or rel and its not an embedded page |
1070 | | - //TODO overlap in logic from isExternal, rel=external check should be |
1071 | | - // moved into more comprehensive isExternalLink |
1072 | | - isExternal = useDefaultUrlHandling || ( path.isExternal( href ) && !isCrossDomainPageLoad ); |
1073 | | - |
1074 | | - $activeClickedLink = $link.closest( ".ui-btn" ); |
1075 | | - |
1076 | | - if( isExternal ) { |
1077 | | - httpCleanup(); |
1078 | | - //use default click handling |
| 1098 | + removeActiveLinkClass( true, 200 ); |
1079 | 1099 | return; |
1080 | 1100 | } |
1081 | 1101 |
|
|
0 commit comments