-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinymce-dialog.js
50 lines (43 loc) · 1.47 KB
/
tinymce-dialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Get arguments passed to dialog.
var passed_arguments = top.tinymce.activeEditor.windowManager.getParams();
var jq_context = document.getElementsByTagName("body")[0];
var searchField = document.getElementById('shortcode_search');
var characters = document.querySelectorAll('.display-icon');
var searchTerm = '';
var selectedChara = null;
characters.forEach(function(character) {
character.addEventListener('click', function(e) {
removeActiveClass();
selectedChara = character.querySelector('i').innerHTML;
character.classList.toggle('active');
});
});
function removeActiveClass() {
selectedChara = null;
characters.forEach(function(character) {
character.classList.remove('active');
});
}
searchField.addEventListener('input', function(e) {
var value = searchField.value;
displayChara(value);
});
function displayChara(value) {
characters.forEach(function(character) {
var name = character.querySelector('i').dataset.name;
if (name.indexOf(value) == -1) {
character.style.display = 'none';
} else {
character.style.display = 'inline-block';
}
});
}
document.getElementById('submit-action').addEventListener('click', function(e) {
event.preventDefault();
var shortcode = selectedChara;
passed_arguments.editor.selection.setContent(shortcode);
passed_arguments.editor.windowManager.close();
});
document.getElementById('cancel-action').addEventListener('click', function() {
passed_arguments.editor.windowManager.close();
});