author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1 |
(function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2 |
var directionality = (function () { |
9 | 3 |
'use strict'; |
4 |
||
5 |
var global = tinymce.util.Tools.resolve('tinymce.PluginManager'); |
|
6 |
||
7 |
var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools'); |
|
5 | 8 |
|
9 | 9 |
var setDir = function (editor, dir) { |
10 |
var dom = editor.dom; |
|
11 |
var curDir; |
|
12 |
var blocks = editor.selection.getSelectedBlocks(); |
|
13 |
if (blocks.length) { |
|
14 |
curDir = dom.getAttrib(blocks[0], 'dir'); |
|
15 |
global$1.each(blocks, function (block) { |
|
16 |
if (!dom.getParent(block.parentNode, '*[dir="' + dir + '"]', dom.getRoot())) { |
|
17 |
dom.setAttrib(block, 'dir', curDir !== dir ? dir : null); |
|
18 |
} |
|
19 |
}); |
|
20 |
editor.nodeChanged(); |
|
21 |
} |
|
22 |
}; |
|
23 |
var Direction = { setDir: setDir }; |
|
5 | 24 |
|
9 | 25 |
var register = function (editor) { |
26 |
editor.addCommand('mceDirectionLTR', function () { |
|
27 |
Direction.setDir(editor, 'ltr'); |
|
28 |
}); |
|
29 |
editor.addCommand('mceDirectionRTL', function () { |
|
30 |
Direction.setDir(editor, 'rtl'); |
|
31 |
}); |
|
32 |
}; |
|
33 |
var Commands = { register: register }; |
|
34 |
||
35 |
var generateSelector = function (dir) { |
|
36 |
var selector = []; |
|
37 |
global$1.each('h1 h2 h3 h4 h5 h6 div p'.split(' '), function (name) { |
|
38 |
selector.push(name + '[dir=' + dir + ']'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
}); |
9 | 40 |
return selector.join(','); |
41 |
}; |
|
42 |
var register$1 = function (editor) { |
|
43 |
editor.addButton('ltr', { |
|
44 |
title: 'Left to right', |
|
45 |
cmd: 'mceDirectionLTR', |
|
46 |
stateSelector: generateSelector('ltr') |
|
47 |
}); |
|
48 |
editor.addButton('rtl', { |
|
49 |
title: 'Right to left', |
|
50 |
cmd: 'mceDirectionRTL', |
|
51 |
stateSelector: generateSelector('rtl') |
|
52 |
}); |
|
53 |
}; |
|
54 |
var Buttons = { register: register$1 }; |
|
5 | 55 |
|
9 | 56 |
global.add('directionality', function (editor) { |
57 |
Commands.register(editor); |
|
58 |
Buttons.register(editor); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
}); |
9 | 60 |
function Plugin () { |
61 |
} |
|
5 | 62 |
|
9 | 63 |
return Plugin; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
}()); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
})(); |