This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
tiny_mce_gzip.js
54 lines (44 loc) · 1.6 KB
/
tiny_mce_gzip.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
51
52
53
54
(function($, undefined) {
window.initTinyMCE = function(context, customConfig) {
customConfig = customConfig || {};
$('textarea.mce_editable', context).each(function() {
var $el = $(this),
$field = $el.parents('.field'),
tinymceActive = false,
$textFormatSelector = $('.fieldTextFormat > select', $field),
config = $.extend(true, {},
$.parseJSON($el.attr('data-mce-config')),
customConfig);
$('.suppressVisualEditor', $field).hide();
$textFormatSelector.bind('change', function(e) {
e.stopPropagation();
if ($(e.target).val() === 'text/html') {
// only activate if it unactive
if (!tinymceActive) {
$el.tinymce(config);
tinymceActive = true;
}
// only deactivate if active
} else if (tinymceActive) {
tinyMCE.execCommand('mceRemoveControl', false, $el.attr('id'));
tinymceActive = false;
}
// set Text Format dropdown untabbable for better UX
}).attr('tabindex', '-1');
if(!$textFormatSelector.length){
// If there is no selector, honour the intent of the mce_editable
// class on this textarea.
$el.tinymce(config);
tinymceActive = true;
} else if ($textFormatSelector.val() === 'text/html') {
// If there is a format selector, only initialise when it asks
// for html.
$el.tinymce(config);
tinymceActive = true;
}
});
};
$(document).ready(function() {
window.initTinyMCE(document);
});
}(window.jQuery));