|
612 | 612 | $.mobile.showPageLoadingMsg(); |
613 | 613 | } |
614 | 614 |
|
615 | | - // Load the new page. |
616 | | - $.ajax({ |
617 | | - url: fileUrl, |
618 | | - type: settings.type, |
619 | | - data: settings.data, |
620 | | - dataType: "html", |
621 | | - success: function( html ) { |
622 | | - //pre-parse html to check for a data-url, |
623 | | - //use it as the new fileUrl, base path, etc |
624 | | - var all = $( "<div></div>" ), |
| 615 | + if ( !( $.mobile.allowCrossDomainPages || path.isSameDomain( documentUrl, absUrl ) ) ) { |
| 616 | + deferred.reject( absUrl, options ); |
| 617 | + } else { |
| 618 | + // Load the new page. |
| 619 | + $.ajax({ |
| 620 | + url: fileUrl, |
| 621 | + type: settings.type, |
| 622 | + data: settings.data, |
| 623 | + dataType: "html", |
| 624 | + success: function( html ) { |
| 625 | + //pre-parse html to check for a data-url, |
| 626 | + //use it as the new fileUrl, base path, etc |
| 627 | + var all = $( "<div></div>" ), |
625 | 628 |
|
626 | 629 | //page title regexp |
627 | 630 | newPageTitle = html.match( /<title[^>]*>([^<]*)/ ) && RegExp.$1, |
|
631 | 634 | dataUrlRegex = new RegExp( "\\bdata-" + $.mobile.ns + "url=[\"']?([^\"'>]*)[\"']?" ); |
632 | 635 |
|
633 | 636 |
|
634 | | - // data-url must be provided for the base tag so resource requests can be directed to the |
635 | | - // correct url. loading into a temprorary element makes these requests immediately |
636 | | - if( pageElemRegex.test( html ) |
637 | | - && RegExp.$1 |
638 | | - && dataUrlRegex.test( RegExp.$1 ) |
639 | | - && RegExp.$1 ) { |
640 | | - url = fileUrl = path.getFilePath( RegExp.$1 ); |
641 | | - } |
| 637 | + // data-url must be provided for the base tag so resource requests can be directed to the |
| 638 | + // correct url. loading into a temprorary element makes these requests immediately |
| 639 | + if( pageElemRegex.test( html ) |
| 640 | + && RegExp.$1 |
| 641 | + && dataUrlRegex.test( RegExp.$1 ) |
| 642 | + && RegExp.$1 ) { |
| 643 | + url = fileUrl = path.getFilePath( RegExp.$1 ); |
| 644 | + } |
642 | 645 |
|
643 | | - if ( base ) { |
644 | | - base.set( fileUrl ); |
645 | | - } |
| 646 | + if ( base ) { |
| 647 | + base.set( fileUrl ); |
| 648 | + } |
646 | 649 |
|
647 | | - //workaround to allow scripts to execute when included in page divs |
648 | | - all.get( 0 ).innerHTML = html; |
649 | | - page = all.find( ":jqmData(role='page'), :jqmData(role='dialog')" ).first(); |
| 650 | + //workaround to allow scripts to execute when included in page divs |
| 651 | + all.get( 0 ).innerHTML = html; |
| 652 | + page = all.find( ":jqmData(role='page'), :jqmData(role='dialog')" ).first(); |
650 | 653 |
|
651 | | - if ( newPageTitle && !page.jqmData( "title" ) ) { |
652 | | - page.jqmData( "title", newPageTitle ); |
653 | | - } |
| 654 | + if ( newPageTitle && !page.jqmData( "title" ) ) { |
| 655 | + page.jqmData( "title", newPageTitle ); |
| 656 | + } |
654 | 657 |
|
655 | | - //rewrite src and href attrs to use a base url |
656 | | - if( !$.support.dynamicBaseTag ) { |
657 | | - var newPath = path.get( fileUrl ); |
658 | | - page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() { |
659 | | - var thisAttr = $( this ).is( '[href]' ) ? 'href' : |
660 | | - $(this).is('[src]') ? 'src' : 'action', |
661 | | - thisUrl = $( this ).attr( thisAttr ); |
662 | | - |
663 | | - // XXX_jblas: We need to fix this so that it removes the document |
664 | | - // base URL, and then prepends with the new page URL. |
665 | | - //if full path exists and is same, chop it - helps IE out |
666 | | - thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' ); |
667 | | - |
668 | | - if( !/^(\w+:|#|\/)/.test( thisUrl ) ) { |
669 | | - $( this ).attr( thisAttr, newPath + thisUrl ); |
670 | | - } |
671 | | - }); |
672 | | - } |
| 658 | + //rewrite src and href attrs to use a base url |
| 659 | + if( !$.support.dynamicBaseTag ) { |
| 660 | + var newPath = path.get( fileUrl ); |
| 661 | + page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() { |
| 662 | + var thisAttr = $( this ).is( '[href]' ) ? 'href' : |
| 663 | + $(this).is('[src]') ? 'src' : 'action', |
| 664 | + thisUrl = $( this ).attr( thisAttr ); |
| 665 | + |
| 666 | + // XXX_jblas: We need to fix this so that it removes the document |
| 667 | + // base URL, and then prepends with the new page URL. |
| 668 | + //if full path exists and is same, chop it - helps IE out |
| 669 | + thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' ); |
| 670 | + |
| 671 | + if( !/^(\w+:|#|\/)/.test( thisUrl ) ) { |
| 672 | + $( this ).attr( thisAttr, newPath + thisUrl ); |
| 673 | + } |
| 674 | + }); |
| 675 | + } |
673 | 676 |
|
674 | | - //append to page and enhance |
675 | | - page |
676 | | - .attr( "data-" + $.mobile.ns + "url", path.convertUrlToDataUrl( fileUrl ) ) |
677 | | - .appendTo( settings.pageContainer ); |
| 677 | + //append to page and enhance |
| 678 | + page |
| 679 | + .attr( "data-" + $.mobile.ns + "url", path.convertUrlToDataUrl( fileUrl ) ) |
| 680 | + .appendTo( settings.pageContainer ); |
678 | 681 |
|
679 | | - enhancePage( page, settings.role ); |
| 682 | + enhancePage( page, settings.role ); |
680 | 683 |
|
681 | | - // Enhancing the page may result in new dialogs/sub pages being inserted |
682 | | - // into the DOM. If the original absUrl refers to a sub-page, that is the |
683 | | - // real page we are interested in. |
684 | | - if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) { |
685 | | - page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" ); |
686 | | - } |
| 684 | + // Enhancing the page may result in new dialogs/sub pages being inserted |
| 685 | + // into the DOM. If the original absUrl refers to a sub-page, that is the |
| 686 | + // real page we are interested in. |
| 687 | + if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) { |
| 688 | + page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" ); |
| 689 | + } |
687 | 690 |
|
688 | | - // Remove loading message. |
689 | | - if ( settings.showLoadMsg ) { |
690 | | - $.mobile.hidePageLoadingMsg(); |
691 | | - } |
| 691 | + // Remove loading message. |
| 692 | + if ( settings.showLoadMsg ) { |
| 693 | + $.mobile.hidePageLoadingMsg(); |
| 694 | + } |
692 | 695 |
|
693 | | - deferred.resolve( absUrl, options, page, dupCachedPage ); |
694 | | - }, |
695 | | - error: function() { |
696 | | - //set base back to current path |
697 | | - if( base ) { |
698 | | - base.set( path.get() ); |
699 | | - } |
| 696 | + deferred.resolve( absUrl, options, page, dupCachedPage ); |
| 697 | + }, |
| 698 | + error: function() { |
| 699 | + //set base back to current path |
| 700 | + if( base ) { |
| 701 | + base.set( path.get() ); |
| 702 | + } |
700 | 703 |
|
701 | | - // Remove loading message. |
702 | | - if ( settings.showLoadMsg ) { |
703 | | - $.mobile.hidePageLoadingMsg(); |
704 | | - |
705 | | - //show error message |
706 | | - $( "<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>" ) |
707 | | - .css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 }) |
708 | | - .appendTo( settings.pageContainer ) |
709 | | - .delay( 800 ) |
710 | | - .fadeOut( 400, function() { |
711 | | - $( this ).remove(); |
712 | | - }); |
713 | | - } |
| 704 | + // Remove loading message. |
| 705 | + if ( settings.showLoadMsg ) { |
| 706 | + $.mobile.hidePageLoadingMsg(); |
| 707 | + |
| 708 | + //show error message |
| 709 | + $( "<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>" ) |
| 710 | + .css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 }) |
| 711 | + .appendTo( settings.pageContainer ) |
| 712 | + .delay( 800 ) |
| 713 | + .fadeOut( 400, function() { |
| 714 | + $( this ).remove(); |
| 715 | + }); |
| 716 | + } |
714 | 717 |
|
715 | | - deferred.reject( absUrl, options ); |
716 | | - } |
717 | | - }); |
| 718 | + deferred.reject( absUrl, options ); |
| 719 | + } |
| 720 | + }); |
| 721 | + } |
718 | 722 |
|
719 | 723 | return deferred.promise(); |
720 | 724 | }; |
|
0 commit comments