- Timestamp:
- 12/28/2013 11:52:04 PM (10 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/tinymce/plugins/directionality/plugin.js
r26862 r26876 1 1 /** 2 * editor_plugin_src.js2 * plugin.js 3 3 * 4 * Copyright 2009, Moxiecode Systems AB4 * Copyright, Moxiecode Systems AB 5 5 * Released under LGPL License. 6 6 * 7 * License: http:// tinymce.moxiecode.com/license8 * Contributing: http:// tinymce.moxiecode.com/contributing7 * License: http://www.tinymce.com/license 8 * Contributing: http://www.tinymce.com/contributing 9 9 */ 10 10 11 (function() { 12 tinymce.create('tinymce.plugins.Directionality', { 13 init : function(ed, url) { 14 var t = this; 11 /*global tinymce:true */ 15 12 16 t.editor = ed; 13 tinymce.PluginManager.add('directionality', function(editor) { 14 function setDir(dir) { 15 var dom = editor.dom, curDir, blocks = editor.selection.getSelectedBlocks(); 17 16 18 function setDir(dir) {19 var dom = ed.dom, curDir, blocks = ed.selection.getSelectedBlocks();17 if (blocks.length) { 18 curDir = dom.getAttrib(blocks[0], "dir"); 20 19 21 if (blocks.length) { 22 curDir = dom.getAttrib(blocks[0], "dir"); 23 24 tinymce.each(blocks, function(block) { 25 // Add dir to block if the parent block doesn't already have that dir 26 if (!dom.getParent(block.parentNode, "*[dir='" + dir + "']", dom.getRoot())) { 27 if (curDir != dir) { 28 dom.setAttrib(block, "dir", dir); 29 } else { 30 dom.setAttrib(block, "dir", null); 31 } 32 } 33 }); 34 35 ed.nodeChanged(); 20 tinymce.each(blocks, function(block) { 21 // Add dir to block if the parent block doesn't already have that dir 22 if (!dom.getParent(block.parentNode, "*[dir='" + dir + "']", dom.getRoot())) { 23 if (curDir != dir) { 24 dom.setAttrib(block, "dir", dir); 25 } else { 26 dom.setAttrib(block, "dir", null); 27 } 36 28 } 37 }38 39 ed.addCommand('mceDirectionLTR', function() {40 setDir("ltr");41 29 }); 42 30 43 ed .addCommand('mceDirectionRTL', function() {44 setDir("rtl");45 });31 editor.nodeChanged(); 32 } 33 } 46 34 47 ed.addButton('ltr', {title : 'directionality.ltr_desc', cmd : 'mceDirectionLTR'});48 ed.addButton('rtl', {title : 'directionality.rtl_desc', cmd : 'mceDirectionRTL'});35 function generateSelector(dir) { 36 var selector = []; 49 37 50 ed.onNodeChange.add(t._nodeChange, t); 51 }, 38 tinymce.each('h1 h2 h3 h4 h5 h6 div p'.split(' '), function(name) { 39 selector.push(name + '[dir=' + dir + ']'); 40 }); 52 41 53 getInfo : function() { 54 return { 55 longname : 'Directionality', 56 author : 'Moxiecode Systems AB', 57 authorurl : 'http://tinymce.moxiecode.com', 58 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality', 59 version : tinymce.majorVersion + "." + tinymce.minorVersion 60 }; 61 }, 42 return selector.join(','); 43 } 62 44 63 // Private methods 64 65 _nodeChange : function(ed, cm, n) { 66 var dom = ed.dom, dir; 67 68 n = dom.getParent(n, dom.isBlock); 69 if (!n) { 70 cm.setDisabled('ltr', 1); 71 cm.setDisabled('rtl', 1); 72 return; 73 } 74 75 dir = dom.getAttrib(n, 'dir'); 76 cm.setActive('ltr', dir == "ltr"); 77 cm.setDisabled('ltr', 0); 78 cm.setActive('rtl', dir == "rtl"); 79 cm.setDisabled('rtl', 0); 80 } 45 editor.addCommand('mceDirectionLTR', function() { 46 setDir("ltr"); 81 47 }); 82 48 83 // Register plugin 84 tinymce.PluginManager.add('directionality', tinymce.plugins.Directionality); 85 })(); 49 editor.addCommand('mceDirectionRTL', function() { 50 setDir("rtl"); 51 }); 52 53 editor.addButton('ltr', { 54 title: 'Left to right', 55 cmd: 'mceDirectionLTR', 56 stateSelector: generateSelector('ltr') 57 }); 58 59 editor.addButton('rtl', { 60 title: 'Right to left', 61 cmd: 'mceDirectionRTL', 62 stateSelector: generateSelector('rtl') 63 }); 64 });
Note: See TracChangeset
for help on using the changeset viewer.