WordPress.org

Make WordPress Core

Changeset 31545


Ignore:
Timestamp:
02/25/2015 08:15:46 PM (5 years ago)
Author:
azaozz
Message:

PressThis: go back to loading the minified bookmarklet content with file_get_contents(). Add Grunt task to minify bookmarklet.js on precommit and update it in /src. See #31373.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r31385 r31545  
    377377                    '!wp-admin/js/farbtastic.js',
    378378                    '!wp-admin/js/iris.min.js',
     379                    '!wp-admin/js/bookmarklet.js', // Minified and updated in /src with the precommit task. See uglify:bookmarklet.
    379380                    '!wp-includes/js/backbone.min.js',
    380381                    '!wp-includes/js/swfobject.js',
     
    404405                ext: '.min.js',
    405406                src: ['wp-includes/js/jquery/ui/*.js']
     407            },
     408            bookmarklet: {
     409                options: {
     410                    compress: {
     411                        negate_iife: false
     412                    }
     413                },
     414                src: SOURCE_DIR + 'wp-admin/js/bookmarklet.js',
     415                dest: SOURCE_DIR + 'wp-admin/js/bookmarklet.min.js'
    406416            }
    407417        },
     
    529539    // Pre-commit task.
    530540    grunt.registerTask('precommit', 'Runs front-end dev/test tasks in preparation for a commit.',
    531         ['autoprefixer:core', 'imagemin:core', 'jshint:corejs', 'qunit:compiled']);
     541        ['autoprefixer:core', 'imagemin:core', 'jshint:corejs', 'qunit:compiled', 'uglify:bookmarklet']);
    532542
    533543    // Copy task.
  • trunk/src/wp-includes/link-template.php

    r31537 r31545  
    26222622
    26232623    if ( empty( $link ) ) {
    2624         $url = wp_json_encode( admin_url( 'press-this.php' ) . '?v=' . $bookmarklet_version );
    2625 
    2626         /**
    2627          * A non-minified version if this script is in /wp-admin/js/bookmarklet.js
    2628          */                     
    2629         $link = 'javascript:!function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");' .
    2630             'd.name=a,d.value=c,d.type="hidden",p.appendChild(d)}}var f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),' .
    2631             'q=b.getElementsByTagName("head")[0],r=new Image,s="_press_this_app";if(d){if(a.getSelection?n=a.getSelection()+"":' .
    2632             'b.getSelection?n=b.getSelection()+"":b.selection&&(n=b.selection.createRange().text),d+=(d.indexOf("?")>-1?"&":"?")+' .
    2633             '"buster="+(new Date).getTime(),b.title.length&&b.title.length<=512&&(d+="&t="+o(b.title)),n&&n.length<=512&&(d+="&s="+o(n)),' .
    2634             '!c.match(/^https?:/))return void(top.location.href=d);d+="&u="+o(c),c.match(/\/\/www\.youtube\.com\/watch/)?e("_embed[]",c):' .
    2635             'c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)?e("_embed[]",c):c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?e("_embed[]",c):' .
    2636             'c.match(/\/\/soundcloud\.com\/.+$/)?e("_embed[]",c):c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?e("_embed[]",c):' .
    2637             'c.match(/\/\/vine\.co\/v\/[^\/]+/)&&e("_embed[]",c),h=q.getElementsByTagName("meta")||[];for(var t=0;' .
    2638             't<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");' .
    2639             'v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=q.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++)' .
    2640             '{var z=i[y],A=z.getAttribute("rel");if(A)switch(A){case"canonical":case"icon":case"shortlink":e("_links["+A+"]",' .
    2641             'z.getAttribute("href"));break;case"alternate":"application/json+oembed"===z.getAttribute("type")?e("_links["+A+"]",' .
    2642             'z.getAttribute("href")):"handheld"===z.getAttribute("media")&&e("_links["+A+"]",z.getAttribute("href"))}}' .
    2643             'b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,' .
    2644             'k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=100);B++)k[B].src.indexOf("avatar")>-1||' .
    2645             'k[B].className.indexOf("avatar")>-1||(r.src=k[B].src,r.width>=256&&r.height>=128&&e("_img[]",r.src));' .
    2646             'l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=100);C++)' .
    2647             'm=l[C].src.match(/\/\/www\.youtube\.com\/embed\/([^\?]+)\?.+$/),m&&2===m.length&&e("_embed[]",' .
    2648             '"https://www.youtube.com/watch?v="+m[1]),m=l[C].src.match(/\/\/player\.vimeo\.com\/video\/([\d]+)$/),' .
    2649             'm&&2===m.length&&e("_embed[]","https://vimeo.com/"+m[1]),m=l[C].src.match(/\/\/vine\.co\/v\/([^\/]+)\/embed/),' .
    2650             'm&&2===m.length&&e("_embed[]","https://vine.co/v/"+m[1]);b.title&&b.title>512&&e("t",b.title),n&&n.length>512&&e("s",n),' .
    2651             'p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",s),p.setAttribute("style","display: none;"),' .
    2652             'f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,' .
    2653             'g=800>g||g>3e3?700:.9*g,a.open("about:blank",s,"width="+f+",height="+g),b.body.appendChild(p),p.submit()}}' .
    2654             '(window,document,top.location.href,' . $url . ');';
     2624        $src = @file_get_contents( ABSPATH . 'wp-admin/js/bookmarklet.min.js' );
     2625
     2626        if ( $src ) {
     2627            $url = wp_json_encode( admin_url( 'press-this.php' ) . '?v=' . $bookmarklet_version );
     2628            $link = 'javascript:' . str_replace( 'window.pt_url', $url, $src );
     2629        }
    26552630    }
    26562631
Note: See TracChangeset for help on using the changeset viewer.