| 1 |
(function() { |
| 2 |
|
| 3 |
tinymce.create('tinymce.plugins.wpforo_source_code_button', { |
| 4 |
/** |
| 5 |
* Initializes the plugin, this will be executed after the plugin has been created. |
| 6 |
* This call is done before the editor instance has finished it's initialization so use the onInit event |
| 7 |
* of the editor instance to intercept that event. |
| 8 |
* |
| 9 |
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. |
| 10 |
* @param {string} url Absolute URL to where the plugin is located. |
| 11 |
*/ |
| 12 |
init : function(ed, url) { |
| 13 |
|
| 14 |
function showDialog() { |
| 15 |
var win = ed.windowManager.open({ |
| 16 |
title: "Source code", |
| 17 |
body: { |
| 18 |
type: 'textbox', |
| 19 |
name: 'code', |
| 20 |
multiline: true, |
| 21 |
minWidth: ed.getParam("code_dialog_width", 600), |
| 22 |
minHeight: ed.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 500)), |
| 23 |
spellcheck: false, |
| 24 |
style: 'direction: ltr; text-align: left' |
| 25 |
}, |
| 26 |
onSubmit: function(e) { |
| 27 |
// We get a lovely "Wrong document" error in IE 11 if we |
| 28 |
// don't move the focus to the editor before creating an undo |
| 29 |
// transation since it tries to make a bookmark for the current selection |
| 30 |
ed.focus(); |
| 31 |
|
| 32 |
ed.undoManager.transact(function() { |
| 33 |
ed.setContent(e.data.code); |
| 34 |
}); |
| 35 |
|
| 36 |
ed.selection.setCursorLocation(); |
| 37 |
ed.nodeChanged(); |
| 38 |
} |
| 39 |
}); |
| 40 |
|
| 41 |
// Gecko has a major performance issue with textarea |
| 42 |
// contents so we need to set it when all reflows are done |
| 43 |
win.find('#code').value(ed.getContent({source_view: true})); |
| 44 |
} |
| 45 |
|
| 46 |
ed.addCommand("mceCodeEditor", showDialog); |
| 47 |
|
| 48 |
ed.addButton('source_code', { |
| 49 |
icon: 'codesample', |
| 50 |
tooltip: 'Source code', |
| 51 |
onclick: showDialog |
| 52 |
}); |
| 53 |
|
| 54 |
ed.addMenuItem('code', { |
| 55 |
icon: 'code', |
| 56 |
text: 'Source code', |
| 57 |
context: 'tools', |
| 58 |
onclick: showDialog |
| 59 |
}); |
| 60 |
|
| 61 |
}, |
| 62 |
}); |
| 63 |
|
| 64 |
// Register plugin |
| 65 |
tinymce.PluginManager.add('wpforo_source_code_button', tinymce.plugins.wpforo_source_code_button); |
| 66 |
|
| 67 |
})(); |