Index: branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.js |
— | — | @@ -770,6 +770,26 @@ |
771 | 771 | return sorted; |
772 | 772 | } |
773 | 773 | |
| 774 | + /** |
| 775 | + * Adds a script tag to the body, either using document.write or low-level DOM manipulation, |
| 776 | + * depending on whether document-ready has occured yet. |
| 777 | + */ |
| 778 | + function addScript( src ) { |
| 779 | + if ( ready ) { |
| 780 | + // jQuery's getScript method is NOT better than doing this the old-fassioned way |
| 781 | + // because jQuery will eval the script's code, and errors will not have sane |
| 782 | + // line numbers. |
| 783 | + var script = document.createElement( 'script' ); |
| 784 | + script.setAttribute( 'src', src ); |
| 785 | + script.setAttribute( 'type', 'text/javascript' ); |
| 786 | + document.body.appendChild( script ); |
| 787 | + } else { |
| 788 | + document.write( mw.html.element( |
| 789 | + 'script', { 'type': 'text/javascript', 'src': src }, '' |
| 790 | + ) ); |
| 791 | + } |
| 792 | + } |
| 793 | + |
774 | 794 | /* Public Methods */ |
775 | 795 | |
776 | 796 | /** |
— | — | @@ -834,22 +854,12 @@ |
835 | 855 | batch = []; |
836 | 856 | // Asynchronously append a script tag to the end of the body |
837 | 857 | function request() { |
838 | | - var html = ''; |
839 | 858 | for ( var r = 0; r < requests.length; r++ ) { |
840 | 859 | requests[r] = sortQuery( requests[r] ); |
841 | | - // Build out the HTML |
842 | 860 | var src = mediaWiki.config.get( 'wgLoadScript' ) + '?' + $.param( requests[r] ); |
843 | | - html += mediaWiki.html.element( 'script', |
844 | | - { type: 'text/javascript', src: src }, '' ); |
| 861 | + addScript( src ); |
845 | 862 | } |
846 | | - return html; |
847 | 863 | } |
848 | | - // Load asynchronously after doumument ready |
849 | | - if ( ready ) { |
850 | | - setTimeout( function() { $( 'body' ).append( request() ); }, 0 ) |
851 | | - } else { |
852 | | - document.write( request() ); |
853 | | - } |
854 | 864 | } |
855 | 865 | }; |
856 | 866 | |
— | — | @@ -1011,13 +1021,7 @@ |
1012 | 1022 | .attr( 'href', modules ) ); |
1013 | 1023 | return true; |
1014 | 1024 | } else if ( type === 'text/javascript' || typeof type === 'undefined' ) { |
1015 | | - var script = mediaWiki.html.element( 'script', |
1016 | | - { type: 'text/javascript', src: modules }, '' ); |
1017 | | - if ( ready ) { |
1018 | | - $( 'body' ).append( script ); |
1019 | | - } else { |
1020 | | - document.write( script ); |
1021 | | - } |
| 1025 | + addScript( modules ); |
1022 | 1026 | return true; |
1023 | 1027 | } |
1024 | 1028 | // Unknown type |
— | — | @@ -1177,7 +1181,6 @@ |
1178 | 1182 | }; |
1179 | 1183 | } )(); |
1180 | 1184 | |
1181 | | - |
1182 | 1185 | /* Extension points */ |
1183 | 1186 | |
1184 | 1187 | this.legacy = {}; |