Make WordPress Core

Ticket #31468: 31468.2.diff

File 31468.2.diff, 3.2 KB (added by azaozz, 10 years ago)
  • src/wp-admin/js/bookmarklet.js

     
    11( function( window, document, href, pt_url ) {
    2         var encodeURI = window.encodeURIComponent,
     2        var encURI = window.encodeURIComponent,
    33                form = document.createElement( 'form' ),
    44                head = document.getElementsByTagName( 'head' )[0],
    55                img = new Image(),
    66                target = '_press_this_app',
     7                canPost = true,
    78                windowWidth, windowHeight,
    89                metas, links, content, imgs, ifrs,
    9                 vid, selection;
     10                vid, selection, newWin;
    1011
    1112        if ( ! pt_url ) {
    1213                return;
    1314        }
    1415
     16        if ( href.match( /^https?:/ ) ) {
     17                pt_url += '&u=' + encURI( href );
     18                if ( window.navigator.userAgent.indexOf( 'Firefox/' ) !== -1 && href.match( /^https:/ ) && pt_url.match( /^http:/ ) ) {
     19                        canPost = false;
     20                }
     21        } else {
     22                top.location.href = pt_url;
     23                return;
     24        }
     25
    1526        if ( window.getSelection ) {
    1627                selection = window.getSelection() + '';
    1728        } else if ( document.getSelection ) {
     
    2233
    2334        pt_url += ( pt_url.indexOf( '?' ) > -1 ? '&' : '?' ) + 'buster=' + ( new Date().getTime() );
    2435
    25         if ( document.title.length && document.title.length <= 512 ) {
    26                 pt_url += '&t=' + encodeURI( document.title );
     36        if ( document.title.length && ( document.title.length <= 256 || ! canPost ) ) {
     37                pt_url += '&t=' + encURI( document.title.substr( 0, 256 ) );
    2738        }
    2839
    29         if ( selection && selection.length <= 512 ) {
    30                 pt_url += '&s=' + encodeURI( selection );
     40        if ( selection && ( selection.length <= 512 || ! canPost ) ) {
     41                pt_url += '&s=' + encURI( selection.substr( 0, 512 ) );
    3142        }
    3243
    33         if ( href.match( /^https?:/ ) ) {
    34                 pt_url += '&u=' + encodeURI( href );
    35         } else {
    36                 top.location.href = pt_url;
     44        windowWidth  = window.outerWidth || document.documentElement.clientWidth || 600;
     45        windowHeight = window.outerHeight || document.documentElement.clientHeight || 700;
     46
     47        windowWidth = ( windowWidth < 800 || windowWidth > 5000 ) ? 600 : ( windowWidth * 0.7 );
     48        windowHeight = ( windowHeight < 800 || windowHeight > 3000 ) ? 700 : ( windowHeight * 0.9 );
     49
     50        if ( ! canPost ) {
     51                newWin = window.open( pt_url, target, 'location,resizable,scrollbars,width=' + windowWidth + ',height=' + windowHeight );
     52                newWin.focus();
    3753                return;
    3854        }
    3955
     
    173189        form.setAttribute( 'target', target );
    174190        form.setAttribute( 'style', 'display: none;' );
    175191
    176         windowWidth  = window.outerWidth || document.documentElement.clientWidth || 600;
    177         windowHeight = window.outerHeight || document.documentElement.clientHeight || 700;
     192        newWin = window.open( 'about:blank', target, 'location,resizable,scrollbars,width=' + windowWidth + ',height=' + windowHeight );
    178193
    179         windowWidth = ( windowWidth < 800 || windowWidth > 5000 ) ? 600 : ( windowWidth * 0.7 );
    180         windowHeight = ( windowHeight < 800 || windowHeight > 3000 ) ? 700 : ( windowHeight * 0.9 );
    181 
    182         window.open( 'about:blank', target, 'location,resizable,scrollbars,width=' + windowWidth + ',height=' + windowHeight );
    183 
    184194        document.body.appendChild( form );
     195        form.submit();
    185196
    186         form.submit();
     197        newWin.focus();
    187198} )( window, document, top.location.href, window.pt_url );