From a62ef6d8273f352b1ee6b4f5ccb57689d0105a35 Mon Sep 17 00:00:00 2001 From: azaozz Date: Thu, 12 Apr 2012 17:52:54 +0000 Subject: [PATCH] Add RTL/LTR button to the html editor, props yoavf, fixes #13070 git-svn-id: http://svn.automattic.com/wordpress/trunk@20451 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/quicktags.dev.js | 21 +++++++++++++++++++++ wp-includes/script-loader.php | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/wp-includes/js/quicktags.dev.js b/wp-includes/js/quicktags.dev.js index eed3b92ec..10f87db69 100644 --- a/wp-includes/js/quicktags.dev.js +++ b/wp-includes/js/quicktags.dev.js @@ -264,6 +264,12 @@ function edButton(id, display, tagStart, tagEnd, access, open) { html += theButtons['fullscreen'].html(name + '_'); } + + if ( 'rtl' == document.getElementsByTagName('html')[0].dir ) { + theButtons['textdirection'] = new qt.TextDirectionButton(); + html += theButtons['textdirection'].html(name + '_'); + } + ed.toolbar.innerHTML = html; ed.theButtons = theButtons; } @@ -605,6 +611,21 @@ function edButton(id, display, tagStart, tagEnd, access, open) { fullscreen.on(); }; + qt.TextDirectionButton = function() { + qt.Button.call(this, 'textdirection', quicktagsL10n.textdirection, '', quicktagsL10n.toggleTextdirection) + }; + qt.TextDirectionButton.prototype = new qt.Button(); + qt.TextDirectionButton.prototype.callback = function(e, c) { + var isRTL = ( 'rtl' == document.getElementsByTagName('html')[0].dir ), + currentDirection = c.style.direction; + + if ( ! currentDirection ) + currentDirection = ( isRTL ) ? 'rtl' : 'ltr'; + + c.style.direction = ( 'rtl' == currentDirection ) ? 'ltr' : 'rtl'; + c.focus(); + } + // ensure backward compatibility edButtons[10] = new qt.TagButton('strong','b','','','b'); edButtons[20] = new qt.TagButton('em','i','','','i'), diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index f44307761..2811e3521 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -79,7 +79,9 @@ function wp_default_scripts( &$scripts ) { 'enterImageURL' => __('Enter the URL of the image'), 'enterImageDescription' => __('Enter a description of the image'), 'fullscreen' => __('fullscreen'), - 'toggleFullscreen' => esc_attr( __('Toggle fullscreen mode') ) + 'toggleFullscreen' => esc_attr( __('Toggle fullscreen mode') ), + 'textdirection' => esc_attr( __('text direction') ), + 'toggleTextdirection' => esc_attr( __('Toggle Editor Text Direction') ) ) ); $scripts->add( 'colorpicker', "/wp-includes/js/colorpicker$suffix.js", array('prototype'), '3517m' );