diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-includes/js/tinymce/plugins/wordpress/plugin.js --- a/wp/wp-includes/js/tinymce/plugins/wordpress/plugin.js Tue Jun 09 11:14:17 2015 +0000 +++ b/wp/wp-includes/js/tinymce/plugins/wordpress/plugin.js Mon Oct 14 17:39:30 2019 +0200 @@ -1,17 +1,21 @@ -/* global tinymce, getUserSetting, setUserSetting */ - +/* global getUserSetting, setUserSetting */ +( function( tinymce ) { // Set the minimum value for the modals z-index higher than #wpadminbar (100000) -tinymce.ui.FloatPanel.zIndex = 100100; +if ( ! tinymce.ui.FloatPanel.zIndex || tinymce.ui.FloatPanel.zIndex < 100100 ) { + tinymce.ui.FloatPanel.zIndex = 100100; +} tinymce.PluginManager.add( 'wordpress', function( editor ) { - var DOM = tinymce.DOM, + var wpAdvButton, style, + DOM = tinymce.DOM, each = tinymce.each, __ = editor.editorManager.i18n.translate, - wpAdvButton, style, - last = 0; + $ = window.jQuery, + wp = window.wp, + hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) ); - if ( typeof window.jQuery !== 'undefined' ) { - window.jQuery( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] ); + if ( $ ) { + $( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] ); } function toggleToolbars( state ) { @@ -88,47 +92,88 @@ window.wpActiveEditor = editor.id; }); - // Replace Read More/Next Page tags with images - editor.on( 'BeforeSetContent', function( e ) { + editor.on( 'BeforeSetContent', function( event ) { var title; - if ( e.content ) { - if ( e.content.indexOf( '/g, function( match, moretext ) { + event.content = event.content.replace( //g, function( match, moretext ) { return ''; + 'class="wp-more-tag mce-wp-more" alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />'; }); } - if ( e.content.indexOf( '' ) !== -1 ) { + if ( event.content.indexOf( '' ) !== -1 ) { title = __( 'Page break' ); - e.content = e.content.replace( //g, + event.content = event.content.replace( //g, '' ); + 'alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />' ); + } + + if ( event.load && event.format !== 'raw' ) { + if ( hasWpautop ) { + event.content = wp.editor.autop( event.content ); + } else { + // Prevent creation of paragraphs out of multiple HTML comments. + event.content = event.content.replace( /-->\s+'; + string = ''; } else if ( image.indexOf( 'data-wp-more="nextpage"' ) !== -1 ) { - image = ''; + string = ''; + } else if ( image.indexOf( 'data-wp-preserve' ) !== -1 ) { + if ( match = image.match( / data-wp-preserve="([^"]+)"/ ) ) { + string = decodeURIComponent( match[1] ); + } } - return image; + return string || image; }); } }); @@ -147,24 +192,25 @@ var parent, html, title, classname = 'wp-more-tag', dom = editor.dom, - node = editor.selection.getNode(); + node = editor.selection.getNode(), + rootNode = editor.getBody(); tag = tag || 'more'; classname += ' mce-wp-' + tag; title = tag === 'more' ? 'Read more...' : 'Next page'; title = __( title ); - html = ''; // Most common case - if ( node.nodeName === 'BODY' || ( node.nodeName === 'P' && node.parentNode.nodeName === 'BODY' ) ) { + if ( node === rootNode || ( node.nodeName === 'P' && node.parentNode === rootNode ) ) { editor.insertContent( html ); return; } // Get the top level parent node parent = dom.getParent( node, function( found ) { - if ( found.parentNode && found.parentNode.nodeName === 'BODY' ) { + if ( found.parentNode && found.parentNode === rootNode ) { return true; } @@ -191,18 +237,165 @@ }); editor.addCommand( 'WP_Help', function() { - editor.windowManager.open({ - url: tinymce.baseURL + '/wp-mce-help.php', + var access = tinymce.Env.mac ? __( 'Ctrl + Alt + letter:' ) : __( 'Shift + Alt + letter:' ), + meta = tinymce.Env.mac ? __( 'Cmd + letter:' ) : __( 'Ctrl + letter:' ), + table1 = [], + table2 = [], + row1 = {}, + row2 = {}, + i1 = 0, + i2 = 0, + labels = editor.settings.wp_shortcut_labels, + header, html, dialog, $wrap; + + if ( ! labels ) { + return; + } + + function tr( row, columns ) { + var out = ''; + var i = 0; + + columns = columns || 1; + + each( row, function( text, key ) { + out += '' + key + '' + __( text ) + ''; + i++; + }); + + while ( i < columns ) { + out += ''; + i++; + } + + return out + ''; + } + + each ( labels, function( label, name ) { + var letter; + + if ( label.indexOf( 'meta' ) !== -1 ) { + i1++; + letter = label.replace( 'meta', '' ).toLowerCase(); + + if ( letter ) { + row1[ letter ] = name; + + if ( i1 % 2 === 0 ) { + table1.push( tr( row1, 2 ) ); + row1 = {}; + } + } + } else if ( label.indexOf( 'access' ) !== -1 ) { + i2++; + letter = label.replace( 'access', '' ).toLowerCase(); + + if ( letter ) { + row2[ letter ] = name; + + if ( i2 % 2 === 0 ) { + table2.push( tr( row2, 2 ) ); + row2 = {}; + } + } + } + } ); + + // Add remaining single entries. + if ( i1 % 2 > 0 ) { + table1.push( tr( row1, 2 ) ); + } + + if ( i2 % 2 > 0 ) { + table2.push( tr( row2, 2 ) ); + } + + header = [ __( 'Letter' ), __( 'Action' ), __( 'Letter' ), __( 'Action' ) ]; + header = '' + header.join( '' ) + ''; + + html = '
'; + + // Main section, default and additional shortcuts + html = html + + '

' + __( 'Default shortcuts,' ) + ' ' + meta + '

' + + '' + + header + + table1.join('') + + '
' + + '

' + __( 'Additional shortcuts,' ) + ' ' + access + '

' + + '' + + header + + table2.join('') + + '
'; + + if ( editor.plugins.wptextpattern && ( ! tinymce.Env.ie || tinymce.Env.ie > 8 ) ) { + // Text pattern section + html = html + + '

' + __( 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' ) + '

' + + '' + + tr({ '*': 'Bullet list', '1.': 'Numbered list' }) + + tr({ '-': 'Bullet list', '1)': 'Numbered list' }) + + '
'; + + html = html + + '

' + __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ) + '

' + + '' + + tr({ '>': 'Blockquote' }) + + tr({ '##': 'Heading 2' }) + + tr({ '###': 'Heading 3' }) + + tr({ '####': 'Heading 4' }) + + tr({ '#####': 'Heading 5' }) + + tr({ '######': 'Heading 6' }) + + tr({ '---': 'Horizontal line' }) + + '
'; + } + + // Focus management section + html = html + + '

' + __( 'Focus shortcuts:' ) + '

' + + '' + + tr({ 'Alt + F8': 'Inline toolbar (when an image, link or preview is selected)' }) + + tr({ 'Alt + F9': 'Editor menu (when enabled)' }) + + tr({ 'Alt + F10': 'Editor toolbar' }) + + tr({ 'Alt + F11': 'Elements path' }) + + '
' + + '

' + __( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ) + '

'; + + html += '
'; + + dialog = editor.windowManager.open( { title: 'Keyboard Shortcuts', - width: 450, - height: 420, - classes: 'wp-help', - buttons: { text: 'Close', onclick: 'close' } - }); - }); + items: { + type: 'container', + classes: 'wp-help', + html: html + }, + buttons: { + text: 'Close', + onclick: 'close' + } + } ); + + if ( dialog.$el ) { + dialog.$el.find( 'div[role="application"]' ).attr( 'role', 'document' ); + $wrap = dialog.$el.find( '.mce-wp-help' ); + + if ( $wrap[0] ) { + $wrap.attr( 'tabindex', '0' ); + $wrap[0].focus(); + $wrap.on( 'keydown', function( event ) { + // Prevent use of: page up, page down, end, home, left arrow, up arrow, right arrow, down arrow + // in the dialog keydown handler. + if ( event.keyCode >= 33 && event.keyCode <= 40 ) { + event.stopPropagation(); + } + }); + } + } + } ); editor.addCommand( 'WP_Medialib', function() { - if ( typeof wp !== 'undefined' && wp.media && wp.media.editor ) { + if ( wp && wp.media && wp.media.editor ) { wp.media.editor.open( editor.id ); } }); @@ -235,7 +428,7 @@ // Menubar // Insert->Add Media - if ( typeof wp !== 'undefined' && wp.media && wp.media.editor ) { + if ( wp && wp.media && wp.media.editor ) { editor.addMenuItem( 'add_media', { text: 'Add Media', icon: 'wp-media-library', @@ -289,7 +482,7 @@ doc = editor.getDoc(), dom = editor.dom; - if ( tinymce.Env.iOS ) { + if ( env.iOS ) { dom.addClass( doc.documentElement, 'ios' ); } @@ -298,6 +491,8 @@ dom.setAttrib( doc.documentElement, 'dir', 'rtl' ); } + dom.setAttrib( doc.documentElement, 'lang', editor.getParam( 'wp_lang_attr' ) ); + if ( env.ie ) { if ( parseInt( env.ie, 10 ) === 9 ) { bodyClass.push('ie9'); @@ -319,94 +514,119 @@ }); // Remove invalid parent paragraphs when inserting HTML - // TODO: still needed? - editor.on( 'BeforeSetContent', function( e ) { - if ( e.content ) { - e.content = e.content.replace(/

\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)( [^>]*)?>/gi, '<$1$2>'); - e.content = e.content.replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)>\s*<\/p>/gi, ''); + editor.on( 'BeforeSetContent', function( event ) { + if ( event.content ) { + event.content = event.content.replace( /

\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' ) + .replace( /<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi, '' ); } }); - if ( typeof window.jQuery !== 'undefined' ) { - window.jQuery( document ).triggerHandler( 'tinymce-editor-init', [editor] ); + if ( $ ) { + $( document ).triggerHandler( 'tinymce-editor-init', [editor] ); } if ( window.tinyMCEPreInit && window.tinyMCEPreInit.dragDropUpload ) { dom.bind( doc, 'dragstart dragend dragover drop', function( event ) { - if ( typeof window.jQuery !== 'undefined' ) { + if ( $ ) { // Trigger the jQuery handlers. - window.jQuery( document ).trigger( new window.jQuery.Event( event ) ); + $( document ).trigger( new $.Event( event ) ); } }); } if ( editor.getParam( 'wp_paste_filters', true ) ) { - if ( ! tinymce.Env.webkit ) { - // In WebKit handled by removeWebKitStyles() - editor.on( 'PastePreProcess', function( event ) { + editor.on( 'PastePreProcess', function( event ) { + // Remove trailing
added by WebKit browsers to the clipboard + event.content = event.content.replace( /
/gi, '' ); + + // In WebKit this is handled by removeWebKitStyles() + if ( ! tinymce.Env.webkit ) { // Remove all inline styles event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' ); // Put back the internal styles event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' ); - }); - } + } + }); editor.on( 'PastePostProcess', function( event ) { // Remove empty paragraphs - each( dom.select( 'p', event.node ), function( node ) { + editor.$( 'p', event.node ).each( function( i, node ) { if ( dom.isEmpty( node ) ) { dom.remove( node ); } }); + + if ( tinymce.isIE ) { + editor.$( 'a', event.node ).find( 'font, u' ).each( function( i, node ) { + dom.remove( node, true ); + }); + } }); } + + if ( editor.settings.wp_shortcut_labels && editor.theme.panel ) { + var labels = {}; + var access = 'Shift+Alt+'; + var meta = 'Ctrl+'; + + // For Mac: ctrl = \u2303, cmd = \u2318, alt = \u2325 + + if ( tinymce.Env.mac ) { + access = '\u2303\u2325'; + meta = '\u2318'; + } + + each( editor.settings.wp_shortcut_labels, function( value, name ) { + labels[ name ] = value.replace( 'access', access ).replace( 'meta', meta ); + } ); + + each( editor.theme.panel.find('button'), function( button ) { + if ( button && button.settings.tooltip && labels.hasOwnProperty( button.settings.tooltip ) ) { + // Need to translate now. We are changing the string so it won't match and cannot be translated later. + button.settings.tooltip = editor.translate( button.settings.tooltip ) + ' (' + labels[ button.settings.tooltip ] + ')'; + } + } ); + + // listbox for the "blocks" drop-down + each( editor.theme.panel.find('listbox'), function( listbox ) { + if ( listbox && listbox.settings.text === 'Paragraph' ) { + each( listbox.settings.values, function( item ) { + if ( item.text && labels.hasOwnProperty( item.text ) ) { + item.shortcut = '(' + labels[ item.text ] + ')'; + } + } ); + } + } ); + } }); - // Word count - if ( typeof window.jQuery !== 'undefined' ) { - editor.on( 'keyup', function( e ) { - var key = e.keyCode || e.charCode; - - if ( key === last ) { - return; - } - - if ( 13 === key || 8 === last || 46 === last ) { - window.jQuery( document ).triggerHandler( 'wpcountwords', [ editor.getContent({ format : 'raw' }) ] ); - } - - last = key; - }); - } - - editor.on( 'SaveContent', function( e ) { + editor.on( 'SaveContent', function( event ) { // If editor is hidden, we just want the textarea's value to be saved if ( ! editor.inline && editor.isHidden() ) { - e.content = e.element.value; + event.content = event.element.value; return; } // Keep empty paragraphs :( - e.content = e.content.replace( /

(?:
|\u00a0|\uFEFF| )*<\/p>/g, '

 

' ); - - if ( editor.getParam( 'wpautop', true ) && typeof window.switchEditors !== 'undefined' ) { - e.content = window.switchEditors.pre_wpautop( e.content ); - } - }); + event.content = event.content.replace( /

(?:
|\u00a0|\uFEFF| )*<\/p>/g, '

 

' ); - // Remove spaces from empty paragraphs. - editor.on( 'BeforeSetContent', function( event ) { - var paragraph = tinymce.Env.webkit ? '


' : '

'; - - if ( event.content ) { - event.content = event.content.replace( /

(?: |\u00a0|\uFEFF|\s)+<\/p>/gi, paragraph ); + if ( hasWpautop ) { + event.content = wp.editor.removep( event.content ); + } else { + // Restore formatting of block boundaries. + event.content = event.content.replace( /-->\s*\n\n