From 2fb11a4ae45d58d51dca18a8e25c2aaef010c5c3 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 25 Feb 2015 20:15:46 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@31545 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 12 +++++++++- src/wp-admin/js/bookmarklet.min.js | 1 + src/wp-includes/link-template.php | 35 +++++------------------------- 3 files changed, 17 insertions(+), 31 deletions(-) create mode 100644 src/wp-admin/js/bookmarklet.min.js diff --git a/Gruntfile.js b/Gruntfile.js index a6a9901902..04c2caf97c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -376,6 +376,7 @@ module.exports = function(grunt) { '!wp-admin/js/custom-header.js', // Why? We should minify this. '!wp-admin/js/farbtastic.js', '!wp-admin/js/iris.min.js', + '!wp-admin/js/bookmarklet.js', // Minified and updated in /src with the precommit task. See uglify:bookmarklet. '!wp-includes/js/backbone.min.js', '!wp-includes/js/swfobject.js', '!wp-includes/js/underscore.min.js', @@ -403,6 +404,15 @@ module.exports = function(grunt) { dest: BUILD_DIR, ext: '.min.js', src: ['wp-includes/js/jquery/ui/*.js'] + }, + bookmarklet: { + options: { + compress: { + negate_iife: false + } + }, + src: SOURCE_DIR + 'wp-admin/js/bookmarklet.js', + dest: SOURCE_DIR + 'wp-admin/js/bookmarklet.min.js' } }, concat: { @@ -528,7 +538,7 @@ module.exports = function(grunt) { // Pre-commit task. grunt.registerTask('precommit', 'Runs front-end dev/test tasks in preparation for a commit.', - ['autoprefixer:core', 'imagemin:core', 'jshint:corejs', 'qunit:compiled']); + ['autoprefixer:core', 'imagemin:core', 'jshint:corejs', 'qunit:compiled', 'uglify:bookmarklet']); // Copy task. grunt.registerTask('copy:all', ['copy:files', 'copy:wp-admin-rtl', 'copy:version']); diff --git a/src/wp-admin/js/bookmarklet.min.js b/src/wp-admin/js/bookmarklet.min.js new file mode 100644 index 0000000000..5625a8ce36 --- /dev/null +++ b/src/wp-admin/js/bookmarklet.min.js @@ -0,0 +1 @@ +(function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");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"),q=b.getElementsByTagName("head")[0],r=new Image,s="_press_this_app";if(d){if(a.getSelection?n=a.getSelection()+"":b.getSelection?n=b.getSelection()+"":b.selection&&(n=b.selection.createRange().text),d+=(d.indexOf("?")>-1?"&":"?")+"buster="+(new Date).getTime(),b.title.length&&b.title.length<=512&&(d+="&t="+o(b.title)),n&&n.length<=512&&(d+="&s="+o(n)),!c.match(/^https?:/))return void(top.location.href=d);d+="&u="+o(c),c.match(/\/\/www\.youtube\.com\/watch/)?e("_embed[]",c):c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)?e("_embed[]",c):c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?e("_embed[]",c):c.match(/\/\/soundcloud\.com\/.+$/)?e("_embed[]",c):c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?e("_embed[]",c):c.match(/\/\/vine\.co\/v\/[^\/]+/)&&e("_embed[]",c),h=q.getElementsByTagName("meta")||[];for(var t=0;t=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=q.getElementsByTagName("link")||[];for(var y=0;y=50);y++){var z=i[y],A=z.getAttribute("rel");if(A)switch(A){case"canonical":case"icon":case"shortlink":e("_links["+A+"]",z.getAttribute("href"));break;case"alternate":"application/json+oembed"===z.getAttribute("type")?e("_links["+A+"]",z.getAttribute("href")):"handheld"===z.getAttribute("media")&&e("_links["+A+"]",z.getAttribute("href"))}}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B=100);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(r.src=k[B].src,r.width>=256&&r.height>=128&&e("_img[]",r.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C=100);C++)m=l[C].src.match(/\/\/www\.youtube\.com\/embed\/([^\?]+)\?.+$/),m&&2===m.length&&e("_embed[]","https://www.youtube.com/watch?v="+m[1]),m=l[C].src.match(/\/\/player\.vimeo\.com\/video\/([\d]+)$/),m&&2===m.length&&e("_embed[]","https://vimeo.com/"+m[1]),m=l[C].src.match(/\/\/vine\.co\/v\/([^\/]+)\/embed/),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),p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",s),p.setAttribute("style","display: none;"),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,a.open("about:blank",s,"width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,window.pt_url); \ No newline at end of file diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 37d2be01c8..7db8f285e2 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -2621,37 +2621,12 @@ function get_shortcut_link() { } if ( empty( $link ) ) { - $url = wp_json_encode( admin_url( 'press-this.php' ) . '?v=' . $bookmarklet_version ); + $src = @file_get_contents( ABSPATH . 'wp-admin/js/bookmarklet.min.js' ); - /** - * A non-minified version if this script is in /wp-admin/js/bookmarklet.js - */ - $link = 'javascript:!function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");' . - '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"),' . - 'q=b.getElementsByTagName("head")[0],r=new Image,s="_press_this_app";if(d){if(a.getSelection?n=a.getSelection()+"":' . - 'b.getSelection?n=b.getSelection()+"":b.selection&&(n=b.selection.createRange().text),d+=(d.indexOf("?")>-1?"&":"?")+' . - '"buster="+(new Date).getTime(),b.title.length&&b.title.length<=512&&(d+="&t="+o(b.title)),n&&n.length<=512&&(d+="&s="+o(n)),' . - '!c.match(/^https?:/))return void(top.location.href=d);d+="&u="+o(c),c.match(/\/\/www\.youtube\.com\/watch/)?e("_embed[]",c):' . - 'c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)?e("_embed[]",c):c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?e("_embed[]",c):' . - 'c.match(/\/\/soundcloud\.com\/.+$/)?e("_embed[]",c):c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?e("_embed[]",c):' . - 'c.match(/\/\/vine\.co\/v\/[^\/]+/)&&e("_embed[]",c),h=q.getElementsByTagName("meta")||[];for(var t=0;' . - 't=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");' . - 'v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=q.getElementsByTagName("link")||[];for(var y=0;y=50);y++)' . - '{var z=i[y],A=z.getAttribute("rel");if(A)switch(A){case"canonical":case"icon":case"shortlink":e("_links["+A+"]",' . - 'z.getAttribute("href"));break;case"alternate":"application/json+oembed"===z.getAttribute("type")?e("_links["+A+"]",' . - 'z.getAttribute("href")):"handheld"===z.getAttribute("media")&&e("_links["+A+"]",z.getAttribute("href"))}}' . - 'b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,' . - 'k=j.getElementsByTagName("img")||[];for(var B=0;B=100);B++)k[B].src.indexOf("avatar")>-1||' . - 'k[B].className.indexOf("avatar")>-1||(r.src=k[B].src,r.width>=256&&r.height>=128&&e("_img[]",r.src));' . - 'l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C=100);C++)' . - 'm=l[C].src.match(/\/\/www\.youtube\.com\/embed\/([^\?]+)\?.+$/),m&&2===m.length&&e("_embed[]",' . - '"https://www.youtube.com/watch?v="+m[1]),m=l[C].src.match(/\/\/player\.vimeo\.com\/video\/([\d]+)$/),' . - 'm&&2===m.length&&e("_embed[]","https://vimeo.com/"+m[1]),m=l[C].src.match(/\/\/vine\.co\/v\/([^\/]+)\/embed/),' . - '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),' . - 'p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",s),p.setAttribute("style","display: none;"),' . - 'f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,' . - 'g=800>g||g>3e3?700:.9*g,a.open("about:blank",s,"width="+f+",height="+g),b.body.appendChild(p),p.submit()}}' . - '(window,document,top.location.href,' . $url . ');'; + if ( $src ) { + $url = wp_json_encode( admin_url( 'press-this.php' ) . '?v=' . $bookmarklet_version ); + $link = 'javascript:' . str_replace( 'window.pt_url', $url, $src ); + } } $link = str_replace( array( "\r", "\n", "\t" ), '', $link );