PluginProbe
wpForo Forum / 3.1.6
wpForo Forum v3.1.6
3.1.6 3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 138 releases
wpforo / assets / js / tinymce-pre.js

tinymce-pre.js in wpForo Forum 3.1.6, at assets/js/tinymce-pre.js

55 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 tinymce.create('tinymce.plugins.wpforo_pre_button', {
3 init: function (ed, url) {
4 function showDialog() {
5 ed.windowManager.open({
6 title: "Code",
7 body: {
8 type: 'textbox',
9 value: ed.selection.getContent({format: 'text'}),
10 name: 'preformatted',
11 multiline: true,
12 minWidth: ed.getParam("code_dialog_width", 600),
13 minHeight: ed.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 500)),
14 spellcheck: false,
15 style: 'direction: ltr; text-align: left'
16 },
17 onSubmit: function (e) {
18 ed.focus();
19 ed.undoManager.transact(function () {
20 ed.insertContent('<pre contenteditable="false">' + escapeHtml(e.data.preformatted) + '</pre>');
21 });
22 ed.selection.setCursorLocation();
23 ed.nodeChanged();
24 }
25 });
26 }
27 function escapeHtml(str) {
28 var div = document.createElement('div');
29 div.appendChild(document.createTextNode(str));
30 return div.innerHTML;
31 }
32 ed.addButton('pre', {
33 title: 'Code',
34 icon: 'code',
35 onclick: showDialog
36 });
37
38 ed.addShortcut('ctrl+0','Format Code', showDialog);
39
40 ed.on('dblclick', function(e){
41 if( e.target.tagName === 'PRE' && 'false' === e.target.getAttribute('contenteditable') ){
42 showDialog();
43 }
44 });
45
46 ed.on('Dirty ExecCommand KeyPress SetContent', function(e) {
47 ed.dom.select('pre').forEach(function(pre){
48 pre.setAttribute('contenteditable', 'false');
49 });
50 });
51
52 }
53 });
54 tinymce.PluginManager.add('wpforo_pre_button', tinymce.plugins.wpforo_pre_button);
55 })();