~canonical-sysadmins/wordpress/4.6

« back to all changes in this revision

Viewing changes to wp-includes/js/tinymce/plugins/directionality/plugin.js

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * plugin.js
 
3
 *
 
4
 * Copyright, Moxiecode Systems AB
 
5
 * Released under LGPL License.
 
6
 *
 
7
 * License: http://www.tinymce.com/license
 
8
 * Contributing: http://www.tinymce.com/contributing
 
9
 */
 
10
 
 
11
/*global tinymce:true */
 
12
 
 
13
tinymce.PluginManager.add('directionality', function(editor) {
 
14
        function setDir(dir) {
 
15
                var dom = editor.dom, curDir, blocks = editor.selection.getSelectedBlocks();
 
16
 
 
17
                if (blocks.length) {
 
18
                        curDir = dom.getAttrib(blocks[0], "dir");
 
19
 
 
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
                                        }
 
28
                                }
 
29
                        });
 
30
 
 
31
                        editor.nodeChanged();
 
32
                }
 
33
        }
 
34
 
 
35
        function generateSelector(dir) {
 
36
                var selector = [];
 
37
 
 
38
                tinymce.each('h1 h2 h3 h4 h5 h6 div p'.split(' '), function(name) {
 
39
                        selector.push(name + '[dir=' + dir + ']');
 
40
                });
 
41
 
 
42
                return selector.join(',');
 
43
        }
 
44
 
 
45
        editor.addCommand('mceDirectionLTR', function() {
 
46
                setDir("ltr");
 
47
        });
 
48
 
 
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
});
 
 
b'\\ No newline at end of file'