From 8f6c123fa74e045e1062001f4b96785e1abbffbe Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 30 Nov 2005 17:15:43 +0000 Subject: [PATCH] TinyMCE directionality for RTL support. Props skeltoac. fixes #1967 git-svn-id: http://svn.automattic.com/wordpress/trunk@3244 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-header.php | 15 ++-- wp-admin/edit-form-advanced.php | 2 +- wp-includes/functions-formatting.php | 2 +- .../plugins/directionality/editor_plugin.js | 83 ++++++++++++++++++ .../plugins/directionality/images/ltr.gif | Bin 0 -> 155 bytes .../plugins/directionality/images/rtl.gif | Bin 0 -> 153 bytes .../plugins/directionality/langs/en.js | 6 ++ 7 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 wp-includes/js/tinymce/plugins/directionality/editor_plugin.js create mode 100644 wp-includes/js/tinymce/plugins/directionality/images/ltr.gif create mode 100644 wp-includes/js/tinymce/plugins/directionality/images/rtl.gif create mode 100644 wp-includes/js/tinymce/plugins/directionality/langs/en.js diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index cb30639213..c3ceef6b6a 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -79,15 +79,20 @@ addLoadEvent(blurry); - - + + diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index c1df52ead8..bceeaba7a9 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -150,7 +150,7 @@ endforeach; ?> -
+
diff --git a/wp-includes/functions-formatting.php b/wp-includes/functions-formatting.php index c179df2d74..8b959d43ff 100644 --- a/wp-includes/functions-formatting.php +++ b/wp-includes/functions-formatting.php @@ -994,7 +994,7 @@ function ent2ncr($text) { function wp_richedit_pre($text) { // Filtering a blank results in an annoying
\n - if ( empty($text) ) return ''; + if ( empty($text) ) return '

'; $output = $text; $output = html_entity_decode($output); // undoes format_to_edit() diff --git a/wp-includes/js/tinymce/plugins/directionality/editor_plugin.js b/wp-includes/js/tinymce/plugins/directionality/editor_plugin.js new file mode 100644 index 0000000000..c866b53dfb --- /dev/null +++ b/wp-includes/js/tinymce/plugins/directionality/editor_plugin.js @@ -0,0 +1,83 @@ +/* Import plugin specific language pack */ +tinyMCE.importPluginLanguagePack('directionality', 'en,sv,fr_ca,zh_cn,cs,da,he,no,de,hu,ru,ru_KOI8-R,ru_UTF-8,es,cy,is,pl'); + +function TinyMCE_directionality_getInfo() { + return { + longname : 'Directionality', + author : 'Moxiecode Systems', + authorurl : 'http://tinymce.moxiecode.com', + infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_directionality.html', + version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion + }; +}; + +function TinyMCE_directionality_getControlHTML(control_name) { + switch (control_name) { + case "ltr": + var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceDirectionLTR\');return false;'; + return '' + + '
'; + + case "rtl": + var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceDirectionRTL\');return false;'; + return '' + + '
'; + } + + return ""; +} + +function TinyMCE_directionality_execCommand(editor_id, element, command, user_interface, value) { + // Handle commands + switch (command) { + case "mceDirectionLTR": + var inst = tinyMCE.getInstanceById(editor_id); + var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address"); + + if (elm) + elm.setAttribute("dir", "ltr"); + + tinyMCE.triggerNodeChange(false); + return true; + + case "mceDirectionRTL": + var inst = tinyMCE.getInstanceById(editor_id); + var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address"); + + if (elm) + elm.setAttribute("dir", "rtl"); + + tinyMCE.triggerNodeChange(false); + return true; + } + + // Pass to next handler in chain + return false; +} + +function TinyMCE_directionality_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { + function getAttrib(elm, name) { + return elm.getAttribute(name) ? elm.getAttribute(name) : ""; + } + + tinyMCE.switchClassSticky(editor_id + '_ltr', 'mceButtonNormal', false); + tinyMCE.switchClassSticky(editor_id + '_rtl', 'mceButtonNormal', false); + + if (node == null) + return; + + var elm = tinyMCE.getParentElement(node, "p,div,td,h1,h2,h3,h4,h5,h6,pre,address"); + if (!elm) { + tinyMCE.switchClassSticky(editor_id + '_ltr', 'mceButtonDisabled', true); + tinyMCE.switchClassSticky(editor_id + '_rtl', 'mceButtonDisabled', true); + return; + } + + var dir = getAttrib(elm, "dir"); + if (dir == "ltr" || dir == "") + tinyMCE.switchClassSticky(editor_id + '_ltr', 'mceButtonSelected', false); + else + tinyMCE.switchClassSticky(editor_id + '_rtl', 'mceButtonSelected', false); + + return true; +} diff --git a/wp-includes/js/tinymce/plugins/directionality/images/ltr.gif b/wp-includes/js/tinymce/plugins/directionality/images/ltr.gif new file mode 100644 index 0000000000000000000000000000000000000000..ac8f30c1208e044ac5ed8f4f82c2e513c56c9f4b GIT binary patch literal 155 zcmV;M0A&A1Nk%w1VH5xq0K*0V6B83EOqQXfrM$epT3%aDeA>#+*g!o%lCtD@cz8l? zx@C{wCodDf2?TZ&Ww46PQZJ;6HbgF) J&uDZ606X)4Hvs?u literal 0 HcmV?d00001 diff --git a/wp-includes/js/tinymce/plugins/directionality/images/rtl.gif b/wp-includes/js/tinymce/plugins/directionality/images/rtl.gif new file mode 100644 index 0000000000000000000000000000000000000000..0348f9965669dd9cfba3c69d71d20ea3928e46fe GIT binary patch literal 153 zcmV;K0A~M3Nk%w1VH5xq0K*Lc6&4jPQl5&6in_+zPfbr=jNa1D%1Uy=K0H3Nv#n}w zX?>#YH($5z?CQtO-2eapA^8LW000jFEC2ui02BZe000C=@X1N5y*TU5yU$K@847`% z$mA5FC73`GOG9yB3IYHR|EvoJCQ;(~3X4J@W03VE4#r`rF-`^yYR0P4Vz}3jcuX#v H%@F`Q*OWXP literal 0 HcmV?d00001 diff --git a/wp-includes/js/tinymce/plugins/directionality/langs/en.js b/wp-includes/js/tinymce/plugins/directionality/langs/en.js new file mode 100644 index 0000000000..5b392fe189 --- /dev/null +++ b/wp-includes/js/tinymce/plugins/directionality/langs/en.js @@ -0,0 +1,6 @@ +// UK lang variables + +tinyMCE.addToLang('',{ +directionality_ltr_desc : 'Direction left to right (Alt-.)', +directionality_rtl_desc : 'Direction right to left (Alt-,)' +});