Skip to content

Commit

Permalink
Item14288: moved all tinymce specifics
Browse files Browse the repository at this point in the history
... down into its engine where it belongs
  • Loading branch information
MichaelDaum committed Mar 24, 2017
1 parent 419c2f5 commit cea4f5c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 57 deletions.
Expand Up @@ -46,35 +46,35 @@ CodemirrorEngine.prototype.init = function() {
var self = this,
pubUrlPath = foswiki.getPreference("PUBURLPATH"),
systemWeb = foswiki.getPreference('SYSTEMWEB'),
codeMirrorPath = pubUrlPath+'/'+systemWeb+'/CodeMirrorContrib',
editorPath = pubUrlPath+'/'+systemWeb+'/CodeMirrorContrib',
dfd = $.Deferred();

$('<link>')
.appendTo('head')
.attr({type : 'text/css', rel : 'stylesheet'})
.attr('href', codeMirrorPath + '/lib/codemirror.css');
.attr('href', editorPath + '/lib/codemirror.css');

$('<link>')
.appendTo('head')
.attr({type : 'text/css', rel : 'stylesheet'})
.attr('href', codeMirrorPath + '/theme/foswiki.css?t='+(new Date()).getTime());
.attr('href', editorPath + '/theme/foswiki.css?t='+(new Date()).getTime());

$('<link>')
.appendTo('head')
.attr({type : 'text/css', rel : 'stylesheet'})
.attr('href', codeMirrorPath + '/addon/search/matchesonscrollbar.css');
.attr('href', editorPath + '/addon/search/matchesonscrollbar.css');

self.shell.getScript(codeMirrorPath+"/lib/codemirror.js").done(function() {
CodeMirror.modeURL = codeMirrorPath+'/'+'/mode/%N/%N.js';
self.shell.getScript(editorPath+"/lib/codemirror.js").done(function() {
CodeMirror.modeURL = editorPath+'/'+'/mode/%N/%N.js';

$.when(
self.shell.getScript(codeMirrorPath+"/addon/mode/loadmode.js"),
self.shell.getScript(codeMirrorPath+"/addon/fold/foldcode.js"),
self.shell.getScript(codeMirrorPath+"/addon/fold/foldgutter.js"),
self.shell.getScript(codeMirrorPath+"/addon/search/searchcursor.js"),
self.shell.getScript(codeMirrorPath+"/addon/scroll/annotatescrollbar.js"),
self.shell.getScript(codeMirrorPath+"/addon/search/matchesonscrollbar.js"),
self.shell.getScript(codeMirrorPath+"/widgets/widgets.js"),
self.shell.getScript(editorPath+"/addon/mode/loadmode.js"),
self.shell.getScript(editorPath+"/addon/fold/foldcode.js"),
self.shell.getScript(editorPath+"/addon/fold/foldgutter.js"),
self.shell.getScript(editorPath+"/addon/search/searchcursor.js"),
self.shell.getScript(editorPath+"/addon/scroll/annotatescrollbar.js"),
self.shell.getScript(editorPath+"/addon/search/matchesonscrollbar.js"),
self.shell.getScript(editorPath+"/widgets/widgets.js"),
self.shell.preloadDialog("searchdialog")
).done(function() {

Expand Down
Expand Up @@ -22,10 +22,17 @@ TinyMCEEngine.prototype.parent = BaseEngine.prototype;

function TinyMCEEngine(shell, opts) {
var self = this,
wikiUserNameUrl = foswiki.getScriptUrlPath("view", foswiki.getPreference("USERSWEB"), foswiki.getPreference("WIKINAME"));
wikiUserNameUrl = foswiki.getScriptUrlPath("view", foswiki.getPreference("USERSWEB"), foswiki.getPreference("WIKINAME")),
pubUrlPath = foswiki.getPreference("PUBURLPATH");

self.shell = shell;
self.opts = $.extend({}, TinyMCEEngine.defaults, self.shell.opts.tinymce, opts);

// prefix them with pubUrlPath
$.each(self.opts.tinymce.content_css, function(i, val) {
self.opts.tinymce.content_css[i] = pubUrlPath + val;
});

self.opts.tinymce.selector = "#"+self.shell.id+" textarea";
self.opts.natedit.signatureMarkup = ['-- ', '<a href="'+wikiUserNameUrl+'">'+foswiki.getPreference("WIKINAME")+'</a>', ' - '+foswiki.getPreference("SERVERTIME")];

Expand All @@ -38,16 +45,24 @@ function TinyMCEEngine(shell, opts) {
*/
TinyMCEEngine.prototype.init = function(editor) {
var self = this,
pubUrlPath = foswiki.getPreference("PUBURLPATH"),
systemWeb = foswiki.getPreference('SYSTEMWEB'),
editorPath = pubUrlPath+'/'+systemWeb+'/TinyMCEPlugin',
dfd = $.Deferred();

self.shell.getScript("//cdn.tinymce.com/4/tinymce.min.js").done(function() {
$('<link>')
.appendTo('head')
.attr({type : 'text/css', rel : 'stylesheet'})
.attr('href', editorPath + '/wysiwyg.css');

self.shell.getScript(editorPath+'/tinymce/js/tinymce/tinymce.min.js').done(function() {

self.opts.tinymce.init_instance_callback = function(editor) {

//self.log("tinymce instance", editor);

self.editor = editor;
//window.editor = editor; // playground
//window.editor = editor; // playground

self.tml2html($(self.shell.txtarea).val())
.done(function(data) {
Expand Down Expand Up @@ -92,6 +107,9 @@ TinyMCEEngine.prototype.initGui = function() {
var self = this,
formatNames = [];

// flag to container ... smell: is this really needed?
self.shell.container.addClass("ui-natedit-wysiwyg-enabled");

$.each(self.opts.tinymce.formats, function(key) {
formatNames.push(key);
});
Expand Down Expand Up @@ -382,6 +400,22 @@ TinyMCEEngine.prototype.getWrapperElement = function() {
return self.editor?$(self.editor.contentAreaContainer).children("iframe"):null;
};

/*************************************************************************
* set the size of editor
*/
TinyMCEEngine.prototype.setSize = function(width, height) {
var self = this,
elem = self.getWrapperElement();

width = width || 'auto';
height = height || 'auto';

if (elem) {
elem.height(height);
}
};


/***************************************************************************
* editor defaults
*/
Expand All @@ -394,8 +428,9 @@ TinyMCEEngine.defaults = {
menubar: false,
toolbar: false,
statusbar: false,
plugins: 'table, searchreplace, paste, lists, advlist, link, image, hr', // contextmenu
plugins: 'contextmenu table searchreplace paste lists link anchor hr legacyoutput image', // save autosave fullscreen anchor charmap code textcolor colorpicker
paste_data_images: true,
content_css: ["/System/TinyMCEPlugin/wysiwyg.css", "/System/SkinTemplates/base.css"], // todo custom onces: ,/pub/System/NatSkin/BaseStyle.css,/pub/System/CustomatoTheme/customato.css"
formats: {
h1Markup: { block: "h1", toolbar: ".ui-natedit-h1" },
h2Markup: { block: "h2", toolbar: ".ui-natedit-h2" },
Expand Down
Expand Up @@ -9,7 +9,7 @@
*
*/

/*global FoswikiTiny:false, tinyMCE:false, StrikeOne:false, plupload:false */
/*global FoswikiTiny:false, StrikeOne:false, plupload:false */
(function($) {
"use strict";

Expand Down Expand Up @@ -206,14 +206,10 @@ $.NatEditor.prototype.initGui = function() {
$txtarea = $(self.txtarea);

/* flag enabled plugins */
if (typeof(tinymce) !== 'undefined') {
self.container.addClass("ui-natedit-wysiwyg-enabled");
}
if (foswiki.getPreference("NatEditPlugin").FarbtasticEnabled) {
self.container.addClass("ui-natedit-colorpicker-enabled");
}


if (self.opts.resizable) {
self.engine.getWrapperElement().resizable();
}
Expand Down Expand Up @@ -270,17 +266,6 @@ $.NatEditor.prototype.initGui = function() {
// switched. Deal with the (string) report and plough on.
});
};
/*************************************************************************
* DEPRECATED tinymce integration
*/
$.NatEditor.prototype.switchToWYSIWYG = function(ev) {
var self = this;

if (typeof(self.tinyMCEEditor) !== 'undefined') {
self.hideToolbar();
self.tinyMCEEditor.execCommand("fwSwitchToWYSIWYG");
}
};

/*************************************************************************
* init the toolbar
Expand Down Expand Up @@ -595,12 +580,6 @@ $.NatEditor.prototype.beforeSubmit = function(editAction) {
StrikeOne.submit(self.form[0]);
}

if (typeof(tinyMCE) !== 'undefined') {
$.each(tinyMCE.editors, function(index, editor) {
editor.execCommand("fwsave");
});
}

self.form.trigger("beforeSubmit.natedit", {
editor: self,
action: editAction
Expand Down Expand Up @@ -1135,20 +1114,13 @@ $.NatEditor.prototype.fixHeight = function() {
var self = this,
elem = self.engine.getWrapperElement(),
windowHeight = $(window).height() || window.innerHeight,
tmceEdContainer = (typeof(tinyMCE) !== 'undefined' && tinyMCE.activeEditor)?$(tinyMCE.activeEditor.contentAreaContainer):null, // DEPRECATED tinymce integration
newHeight,
$debug = $("#DEBUG");

if (typeof(self.bottomHeight) === 'undefined') {
self.bottomHeight = $('.natEditBottomBar').outerHeight(true) + parseInt($('.jqTabContents').css('padding-bottom'), 10) * 2 + 2;
}

if (tmceEdContainer && !tinyMCE.activeEditor.getParam('fullscreen_is_enabled') && tmceEdContainer.is(":visible")) {
/* resize tinyMCE. */
tmceEdContainer.closest(".mceLayout").height('auto'); // remove local height properties
elem = tmceEdContainer.children('iframe');
}

if (!elem) {
return;
}
Expand All @@ -1173,12 +1145,7 @@ $.NatEditor.prototype.fixHeight = function() {

if (elem.is(":visible")) {
//console.log("NATEDIT: fixHeight height=",newHeight);
// DEPRECATED tinymce integration
if (tmceEdContainer) {
elem.height(newHeight);
} else {
self.engine.setSize(undefined, newHeight);
}
self.engine.setSize(undefined, newHeight);
} else {
//console.log("NATEDIT: not fixHeight elem not yet visible");
}
Expand Down Expand Up @@ -2012,11 +1979,6 @@ $.fn.natedit = function(opts) {
// build main options before element iteration
var thisOpts = $.extend({}, $.NatEditor.defaults, opts);

// DEPRECATED tinymce integration
if (this.is(".foswikiWysiwygEdit") && typeof(tinyMCE) !== 'undefined') {
thisOpts.showToolbar = false;
}

return this.each(function() {
if (!$.data(this, "natedit")) {
$.data(this, "natedit", new $.NatEditor(this, thisOpts));
Expand Down

0 comments on commit cea4f5c

Please sign in to comment.