From 71f48f45e0aedc5473b9e4f8ba28195087e34da8 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 29 Mar 2015 03:14:28 +0000 Subject: [PATCH] Press This: - When saving, replace emoji images with chars in the title text. - Clean up the title text on paste. See #31768. Built from https://develop.svn.wordpress.org/trunk@31919 git-svn-id: http://core.svn.wordpress.org/trunk@31898 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/press-this.js | 36 ++++++++++++++++++++++++++++------- wp-admin/js/press-this.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/wp-admin/js/press-this.js b/wp-admin/js/press-this.js index 727948260e..f5591ddf76 100644 --- a/wp-admin/js/press-this.js +++ b/wp-admin/js/press-this.js @@ -117,6 +117,20 @@ } ); } + /** + * Replace emoji images with chars and sanitize the text content. + */ + function getTitleText() { + var $element = $( '#title-container' ); + + $element.find( 'img.emoji' ).each( function() { + var $image = $( this ); + $image.replaceWith( $( '' ).text( $image.attr( 'alt' ) ) ); + }); + + return sanitizeText( $element.text() ); + } + /** * Prepare the form data for saving. */ @@ -126,7 +140,7 @@ editor && editor.save(); - $( '#post_title' ).val( sanitizeText( $( '#title-container' ).text() ) ); + $( '#post_title' ).val( getTitleText() ); // Make sure to flush out the tags with tagBox before saving if ( window.tagBox ) { @@ -502,18 +516,26 @@ * Interactive behavior for the post title's field placeholder */ function monitorPlaceholder() { - var $titleField = $( '#title-container'), - $placeholder = $('.post-title-placeholder'); + var $titleField = $( '#title-container' ), + $placeholder = $( '.post-title-placeholder' ); $titleField.on( 'focus', function() { - $placeholder.addClass('is-hidden'); + $placeholder.addClass( 'is-hidden' ); }).on( 'blur', function() { - if ( ! $titleField.text() ) { - $placeholder.removeClass('is-hidden'); + if ( ! $titleField.text() && ! $titleField.html() ) { + $placeholder.removeClass( 'is-hidden' ); } + }).on( 'keyup', function() { + saveAlert = true; + }).on( 'paste', function() { + saveAlert = true; + + setTimeout( function() { + $titleField.text( getTitleText() ); + }, 100 ); }); - if ( $titleField.text() ) { + if ( $titleField.text() || $titleField.html() ) { $placeholder.addClass('is-hidden'); } } diff --git a/wp-admin/js/press-this.min.js b/wp-admin/js/press-this.min.js index ae9a4ab426..7b618d05a8 100644 --- a/wp-admin/js/press-this.min.js +++ b/wp-admin/js/press-this.min.js @@ -1 +1 @@ -!function(a,b){var c=function(){function c(a){return a&&b.pressThisL10n?b.pressThisL10n[a]||a:a||""}function d(a){return a=a||"",a.replace(/|$)/g,"").replace(/<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/gi,"").replace(/<\/?[a-z][\s\S]*?(>|$)/gi,"")}function e(a){var b=d(a);try{F.innerHTML=b,b=d(F.value)}catch(c){}return b}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(){a("#spinner").addClass("show"),a(".post-actions button").each(function(){a(this).attr("disabled","disabled")})}function h(){a("#spinner").removeClass("show"),a(".post-actions button").each(function(){a(this).removeAttr("disabled")})}function i(){var c=a("#pressthis-form"),d=a('');B&&B.save(),a("#post_title").val(e(a("#title-container").text())),b.tagBox&&a("div.tagsdiv").each(function(){b.tagBox.flushTags(this,!1,1)}),a(".categories-select .category").each(function(b,e){var f=a(e);f.hasClass("selected")&&c.append(d.clone().val(f.attr("data-term-id")||""))})}function j(c){var d;E=!1,g(),"publish"===c&&a("#post_status").val("publish"),i(),d=a("#pressthis-form").serialize(),a.ajax({type:"post",url:b.ajaxurl,data:d,success:function(a){if(a.success){if(a.data.redirect)if(b.opener&&H.redirInParent){try{b.opener.location.href=a.data.redirect}catch(c){}b.self.close()}else b.location.href=a.data.redirect}else o(a.data.errorMessage),h()}})}function k(a){var b,c,d="";B&&(b=f(a.attr("data-wp-src")||""),c=f(I.u),a.hasClass("is-image")?(c||(c=b),d=''):d="[embed]"+b+"[/embed]",K?B.execCommand("mceInsertContent",!1,d):B.setContent("

"+d+"

"+B.getContent()))}function l(){var c,d=a("#new-category").val();d&&(c={action:"press-this-add-category",post_id:a("#post_ID").val()||0,name:d,new_cat_nonce:a("#_ajax_nonce-add-category").val()||"",parent:a("#new-category-parent").val()||0},a.post(b.ajaxurl,c,function(b){if(b.success){var c,d,e=a("ul.categories-select");a.each(b.data,function(b,f){var g=a("
  • ").append(a('