Skip to content

Commit

Permalink
Fullscreen support (#2)
Browse files Browse the repository at this point in the history
* Add instructions to generate plugin.min.js

* Add support for fullscreen.
  • Loading branch information
chadcallahan authored and ThGraham committed Aug 16, 2016
1 parent 9362371 commit 92ebf57
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ object to the TinyMCE configuration.
the indentOnInit option, you tell the Source Code editor to indent all code when
the editor opens. This might be slow for large documents.

**fullscreen** boolean (false) Whether to load the tinymce plugin and codemirror
in full screen mode.

**path**: string (codemirror) You might already have CodeMirror hosted elsewhere
(outside TinyMCE). In that case, you can reuse that CodeMirror instance, by
overriding the default path. For example:
Expand Down
12 changes: 9 additions & 3 deletions plugins/codemirror/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ tinymce.PluginManager.add('codemirror', function(editor, url) {
editor.selection.collapse(true);
editor.selection.setContent('<span class="CmCaReT" style="display:none">&#0;</span>');

// Open editor window
var win = editor.windowManager.open({
var config = {
title: 'HTML source code',
url: url + '/source.html',
width: 800,
height: 550,
resizable : true,
maximizable : true,
fullScreen: editor.settings.codemirror.fullscreen,
buttons: [
{ text: 'Ok', subtype: 'primary', onclick: function(){
var doc = document.querySelectorAll('.mce-container-body>iframe')[0];
Expand All @@ -34,7 +34,13 @@ tinymce.PluginManager.add('codemirror', function(editor, url) {
}},
{ text: 'Cancel', onclick: 'close' }
]
});
};

var win = editor.windowManager.open(config);

if (editor.settings.codemirror.fullscreen) {
win.fullscreen(true);
}
};

// Add a button to the button bar
Expand Down
2 changes: 1 addition & 1 deletion plugins/codemirror/plugin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions plugins/codemirror/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@
]
};

if (userSettings.fullscreen) {
CMsettings.jsFiles.push('addon/display/fullscreen.js');
CMsettings.cssFiles.push('addon/display/fullscreen.css');
}

// Merge config
for (i in userSettings.config) {
CMsettings.config[i] = userSettings.config[i];
}

// Merge jsFiles
for (i in userSettings.jsFiles) {
if (!inArray(userSettings.jsFiles[i], CMsettings.jsFiles)) {
Expand Down Expand Up @@ -96,6 +101,10 @@
document.write('<scr'+'ipt type="text/javascript" src="' + CMsettings.path + CMsettings.jsFiles[i] + '"></scr'+'ipt>');
}

// Borrowed from codemirror.js themeChanged function. Sets the theme's class names to the html element.
// Without this, the background color outside of the codemirror wrapper element remains white.
document.documentElement.className += CMsettings.config.theme.replace(/(^|\s)\s*/g, " cm-s-");

window.onload = start;
}());

Expand Down Expand Up @@ -124,7 +133,7 @@
html = html.replace(/<span\s+class="CmCaReT"([^>]*)>([^<]*)<\/span>/gm, String.fromCharCode(chr));
editor.dom.remove(editor.dom.select('.CmCaReT'));

CodeMirror.defineInitHook(function(inst)
CodeMirror.defineInitHook(function(inst)
{
// Move cursor to correct position:
inst.focus();
Expand All @@ -133,7 +142,7 @@
inst.setCursor(cursor.to());
cursor.replace('');
}

// Indent all code, if so requested:
if (editor.settings.codemirror.indentOnInit) {
var last = inst.lineCount();
Expand Down Expand Up @@ -173,7 +182,7 @@
function submit()
{
"use strict";

var cc = '&#x0;', isDirty = codemirror.isDirty, doc = codemirror.doc;

if (doc.somethingSelected()) {
Expand Down

0 comments on commit 92ebf57

Please sign in to comment.