X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/41578db67d72562346e4dbb2a14889b23d522813..bd54ad7dcd1cbf3b37f7822f71ca57b742f00a77:/wp-includes/js/tinymce/plugins/wordpress/plugin.js diff --git a/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/wp-includes/js/tinymce/plugins/wordpress/plugin.js index 64c5ff1c..968ebd9a 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -1,11 +1,20 @@ -/* 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; tinymce.PluginManager.add( 'wordpress', function( editor ) { - var DOM = tinymce.DOM, wpAdvButton, modKey, style, - last = 0; + var wpAdvButton, style, + DOM = tinymce.DOM, + each = tinymce.each, + __ = editor.editorManager.i18n.translate, + $ = window.jQuery, + wp = window.wp, + hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) ); + + if ( $ ) { + $( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] ); + } function toggleToolbars( state ) { var iframe, initial, toolbars, @@ -25,7 +34,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { state = 'hide'; } - tinymce.each( toolbars, function( toolbar, i ) { + each( toolbars, function( toolbar, i ) { if ( i > 0 ) { if ( state === 'hide' ) { toolbar.hide(); @@ -38,8 +47,11 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); if ( pixels && ! initial ) { - iframe = editor.getContentAreaContainer().firstChild; - DOM.setStyle( iframe, 'height', iframe.clientHeight + pixels ); // Resize iframe + // Resize iframe, not needed in iOS + if ( ! tinymce.Env.iOS ) { + iframe = editor.getContentAreaContainer().firstChild; + DOM.setStyle( iframe, 'height', iframe.clientHeight + pixels ); + } if ( state === 'hide' ) { setUserSetting('hidetb', '0'); @@ -49,6 +61,8 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { wpAdvButton && wpAdvButton.active( true ); } } + + editor.fire( 'wp-toolbar-toggle' ); } // Add the kitchen sink button :) @@ -63,7 +77,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { // Hide the toolbars after loading editor.on( 'PostRender', function() { - if ( getUserSetting('hidetb', '0') === '0' ) { + if ( editor.getParam( 'wordpress_adv_hidden', true ) && getUserSetting( 'hidetb', '0' ) === '0' ) { toggleToolbars( 'hide' ); } }); @@ -77,20 +91,41 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); // Replace Read More/Next Page tags with images - editor.on( 'BeforeSetContent', function( e ) { - if ( e.content ) { - if ( e.content.indexOf( '/g, function( match, moretext ) { - return ''; + editor.on( 'BeforeSetContent', function( event ) { + var title; + + if ( event.content ) { + if ( event.content.indexOf( '/g, function( match, moretext ) { + return ''; }); } - if ( e.content.indexOf( '' ) !== -1 ) { - e.content = e.content.replace( //g, - '' ); + if ( event.content.indexOf( '' ) !== -1 ) { + title = __( 'Page break' ); + + event.content = event.content.replace( //g, + '' ); } + + if ( event.load && event.format !== 'raw' && hasWpautop ) { + event.content = wp.editor.autop( event.content ); + } + + // Remove spaces from empty paragraphs. + // Avoid backtracking, can freeze the editor. See #35890. + // (This is also quite faster than using only one regex.) + event.content = event.content.replace( /

([^<>]+)<\/p>/gi, function( tag, text ) { + if ( /^( |\s|\u00a0|\ufeff)+$/i.test( text ) ) { + return '


'; + } + + return tag; + }); } }); @@ -100,16 +135,14 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { e.content = e.content.replace(/]+>/g, function( image ) { var match, moretext = ''; - if ( image.indexOf('wp-more-tag') !== -1 ) { - if ( image.indexOf('mce-wp-more') !== -1 ) { - if ( match = image.match( /data-wp-more="([^"]+)"/ ) ) { - moretext = match[1]; - } - - image = ''; - } else if ( image.indexOf('mce-wp-nextpage') !== -1 ) { - image = ''; + if ( image.indexOf( 'data-wp-more="more"' ) !== -1 ) { + if ( match = image.match( /data-wp-more-text="([^"]+)"/ ) ) { + moretext = match[1]; } + + image = ''; + } else if ( image.indexOf( 'data-wp-more="nextpage"' ) !== -1 ) { + image = ''; } return image; @@ -118,16 +151,11 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); // Display the tag name instead of img in element path - editor.on( 'ResolveName', function( e ) { - var dom = editor.dom, - target = e.target; - - if ( target.nodeName === 'IMG' && dom.hasClass( target, 'wp-more-tag' ) ) { - if ( dom.hasClass( target, 'mce-wp-more' ) ) { - e.name = 'more'; - } else if ( dom.hasClass( target, 'mce-wp-nextpage' ) ) { - e.name = 'nextpage'; - } + editor.on( 'ResolveName', function( event ) { + var attr; + + if ( event.target.nodeName === 'IMG' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) { + event.name = attr; } }); @@ -140,9 +168,10 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { tag = tag || 'more'; classname += ' mce-wp-' + tag; - title = tag === 'more' ? 'More...' : 'Next Page'; - html = ''; + title = tag === 'more' ? 'Read more...' : 'Next page'; + title = __( title ); + html = ''; // Most common case if ( node.nodeName === 'BODY' || ( node.nodeName === 'P' && node.parentNode.nodeName === 'BODY' ) ) { @@ -179,18 +208,138 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); 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 = [], + header, html, dialog, $wrap; + + each( [ + { c: 'Copy', x: 'Cut' }, + { v: 'Paste', a: 'Select all' }, + { z: 'Undo', y: 'Redo' }, + { b: 'Bold', i: 'Italic' }, + { u: 'Underline', k: 'Insert/edit link' } + ], function( row ) { + table1.push( tr( row ) ); + } ); + + each( [ + { 1: 'Heading 1', 2: 'Heading 2' }, + { 3: 'Heading 3', 4: 'Heading 4' }, + { 5: 'Heading 5', 6: 'Heading 6' }, + { l: 'Align left', c: 'Align center' }, + { r: 'Align right', j: 'Justify' }, + { d: 'Strikethrough', q: 'Blockquote' }, + { u: 'Bullet list', o: 'Numbered list' }, + { a: 'Insert/edit link', s: 'Remove link' }, + { m: 'Insert/edit image', t: 'Insert Read More tag' }, + { h: 'Keyboard Shortcuts', x: 'Code' }, + { p: 'Insert Page Break tag', w: 'Distraction-free writing mode' } + ], function( row ) { + table2.push( tr( row ) ); + } ); + + function tr( row ) { + var out = ''; + + each( row, function( text, key ) { + if ( ! text ) { + out += ''; + } else { + out += '' + key + '' + __( text ) + ''; + } + }); + + return out + ''; + } + + 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, - inline: 1, - classes: 'wp-help' - }); - }); + 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 ); } }); @@ -223,7 +372,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { // 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', @@ -277,11 +426,17 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { doc = editor.getDoc(), dom = editor.dom; + if ( env.iOS ) { + dom.addClass( doc.documentElement, 'ios' ); + } + if ( editor.getParam( 'directionality' ) === 'rtl' ) { bodyClass.push('rtl'); 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'); @@ -290,180 +445,502 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } else if ( env.ie < 8 ) { bodyClass.push('ie7'); } + } else if ( env.webkit ) { + bodyClass.push('webkit'); } bodyClass.push('wp-editor'); - tinymce.each( bodyClass, function( cls ) { + each( bodyClass, function( cls ) { if ( cls ) { dom.addClass( doc.body, cls ); } }); // 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 ).triggerHandler( event.type ); + $( document ).trigger( new $.Event( event ) ); } }); } - }); - // Word count - if ( typeof window.jQuery !== 'undefined' ) { - editor.on( 'keyup', function( e ) { - var key = e.keyCode || e.charCode; + if ( editor.getParam( 'wp_paste_filters', true ) ) { + editor.on( 'PastePreProcess', function( event ) { + // Remove trailing
added by WebKit browsers to the clipboard + event.content = event.content.replace( /
/gi, '' ); - if ( key === last ) { - return; - } + // In WebKit this is handled by removeWebKitStyles() + if ( ! tinymce.Env.webkit ) { + // Remove all inline styles + event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' ); - if ( 13 === key || 8 === last || 46 === last ) { - window.jQuery( document ).triggerHandler( 'wpcountwords', [ editor.getContent({ format : 'raw' }) ] ); - } + // Put back the internal styles + event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' ); + } + }); - last = key; - }); - } + editor.on( 'PastePostProcess', function( event ) { + // Remove empty paragraphs + each( dom.select( 'p', event.node ), function( node ) { + if ( dom.isEmpty( node ) ) { + dom.remove( node ); + } + }); + }); + } + }); - 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.isHidden() ) { - e.content = e.element.value; + if ( ! editor.inline && editor.isHidden() ) { + event.content = event.element.value; return; } // Keep empty paragraphs :( - e.content = e.content.replace( /

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

 

' ); + event.content = event.content.replace( /

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

 

' ); - if ( editor.getParam( 'wpautop', true ) && typeof window.switchEditors !== 'undefined' ) { - e.content = window.switchEditors.pre_wpautop( e.content ); + if ( hasWpautop ) { + event.content = wp.editor.removep( event.content ); } }); editor.on( 'preInit', function() { - // Don't replace with and with and don't remove them when empty - editor.schema.addValidElements( '@[id|accesskey|class|dir|lang|style|tabindex|title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],i,b' ); - }); + var validElementsSetting = '@[id|accesskey|class|dir|lang|style|tabindex|' + + 'title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],' + // Global attributes. + 'i,' + // Don't replace with and with and don't remove them when empty. + 'b,' + + 'script[src|async|defer|type|charset|crossorigin|integrity]'; // Add support for