diff --git a/NatEditPlugin/pub/System/NatEditPlugin/engine/codemirror/engine.uncompressed.js b/NatEditPlugin/pub/System/NatEditPlugin/engine/codemirror/engine.uncompressed.js index 9bcda46896..288a78b246 100644 --- a/NatEditPlugin/pub/System/NatEditPlugin/engine/codemirror/engine.uncompressed.js +++ b/NatEditPlugin/pub/System/NatEditPlugin/engine/codemirror/engine.uncompressed.js @@ -157,14 +157,20 @@ CodemirrorEngine.prototype.init = function() { } }); - // listen to beforeSubmit event - self.shell.form.on("beforeSubmit.natedit", function() { - self.cm.save(); // copy to textarea - }); - return dfd.promise(); }; +/************************************************************************* + * intercept save process + */ +CodemirrorEngine.prototype.beforeSubmit = function(action) { + var self = this; + + self.cm.save(); // copy to textarea + + return $.Deferred().resolve().promise(); +}; + /************************************************************************* * register events to editor engine */ diff --git a/NatEditPlugin/pub/System/NatEditPlugin/engine/tinymce/engine.uncompressed.js b/NatEditPlugin/pub/System/NatEditPlugin/engine/tinymce/engine.uncompressed.js index aa79f92474..80a5eded02 100644 --- a/NatEditPlugin/pub/System/NatEditPlugin/engine/tinymce/engine.uncompressed.js +++ b/NatEditPlugin/pub/System/NatEditPlugin/engine/tinymce/engine.uncompressed.js @@ -29,12 +29,6 @@ function TinyMCEEngine(shell, opts) { 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 = ['-- ', ''+foswiki.getPreference("WIKINAME")+'', ' - '+foswiki.getPreference("SERVERTIME")]; @@ -78,15 +72,6 @@ TinyMCEEngine.prototype.init = function() { }); self.shell.form.on("beforeSubmit.natedit", function(e, params) { - if (params.action !== 'cancel') { - self.html2tml(self.editor.getContent()) - .done(function(data) { - $(self.shell.txtarea).val(data); - }) - .fail(function() { - alert("Error calling html2tml"); // SMELL: better error handling - }); - } }); }; @@ -101,39 +86,46 @@ TinyMCEEngine.prototype.init = function() { return dfd.promise(); }; +/************************************************************************* + * intercept save process + */ +TinyMCEEngine.prototype.beforeSubmit = function(action) { + var self = this, dfd; + + if (action === 'cancel') { + return; + } + + return self.html2tml(self.editor.getContent()) + .done(function(data) { + $(self.shell.txtarea).val(data); + }) + .fail(function() { + alert("Error calling html2tml"); // SMELL: better error handling + }); +}; + + /************************************************************************* * init gui */ TinyMCEEngine.prototype.initGui = function() { - var self = this, - formatNames = []; + var self = this; // 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); - }); - // highlight buttons on toolbar when the cursor moves into a format - self.editor.on("NodeChange", function(/*ev*/) { - var /*elem = ev.element,*/ - formatter = self.editor.formatter, - activeFormats; - - self.shell.toolbar.find(".ui-button, .ui-menu-item").removeClass("ui-natedit-active"); - - activeFormats = formatter.matchAll(formatNames); - - $.each(activeFormats, function(index, name) { - $.each(formatter.get(name), function(index, format) { - var selector = format.toolbar; - if (selector) { - self.shell.toolbar.find(selector).addClass("ui-natedit-active"); + $.each(self.opts.tinymce.formats, function(formatName) { + self.editor.formatter.formatChanged(formatName, function(state, args) { + $.each(self.editor.formatter.get(formatName), function(i, format) { + if (state) { + self.shell.toolbar.find(format.toolbar).addClass("ui-natedit-active"); + } else { + self.shell.toolbar.find(format.toolbar).removeClass("ui-natedit-active"); } }); }); - }); // listen to change events and update stuff @@ -431,7 +423,7 @@ TinyMCEEngine.defaults = { statusbar: false, 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" + content_css: ["/pub/System/TinyMCEPlugin/wysiwyg.css", "/pub/System/SkinTemplates/base.css"], formats: { h1Markup: { block: "h1", toolbar: ".ui-natedit-h1" }, h2Markup: { block: "h2", toolbar: ".ui-natedit-h2" }, @@ -439,7 +431,9 @@ TinyMCEEngine.defaults = { h4Markup: { block: "h4", toolbar: ".ui-natedit-h4" }, h5Markup: { block: "h5", toolbar: ".ui-natedit-h5" }, h6Markup: { block: "h6", toolbar: ".ui-natedit-h6" }, - boldMarkup: { inline: "strong", toolbar: ".ui-natedit-bold" }, + normalMarkup: { block: "p", toolbar: ".ui-natedit-normal"}, + quoteMarkup: { block: "blockquote", toolbar: ".ui-natedit-quoted"}, + boldMarkup: { inline: "b", toolbar: ".ui-natedit-bold" }, italicMarkup: { inline: "em", toolbar: ".ui-natedit-italic" }, monoMarkup: { inline: "code", toolbar: ".ui-natedit-mono" }, underlineMarkup: { inline: "span", styles: { "text-decoration": "underline" }, toolbar: ".ui-natedit-underline" }, @@ -450,7 +444,7 @@ TinyMCEEngine.defaults = { rightMarkup: { block: "p", styles: { "text-align": "right" }, toolbar: ".ui-natedit-right" }, centerMarkup: { block: "p", styles: { "text-align": "center" }, toolbar: ".ui-natedit-center" }, justifyMarkup: { block: "p", styles: { "text-align": "justify" }, toolbar: ".ui-natedit-justify" }, - verbatimMarkup: { block: "pre", toolbar: ".ui-natedit-h1" } + verbatimMarkup: { block: "pre", classes: "TMLverbatim", toolbar: ".ui-natedit-verbatim" } } } }; diff --git a/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js b/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js index 0cab90bee8..bef82c68f9 100644 --- a/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js +++ b/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js @@ -574,10 +574,13 @@ $.NatEditor.prototype.beforeSubmit = function(editAction) { StrikeOne.submit(self.form[0]); } + // WARNING: handlers are not guaranteed to be called or have finished before the content has been submitted self.form.trigger("beforeSubmit.natedit", { editor: self, action: editAction }); + + return self.engine.beforeSubmit(editAction); }; /************************************************************************* @@ -604,12 +607,13 @@ $.NatEditor.prototype.initForm = function() { buttons, doIt = function() { if (self.form.validate().form()) { - self.beforeSubmit("save"); - document.title = $.i18n("Saving ..."); - $.blockUI({ - message: '

'+ $.i18n("Saving ...") + '

' + self.beforeSubmit("save").then(function() { + document.title = $.i18n("Saving ..."); + $.blockUI({ + message: '

'+ $.i18n("Saving ...") + '

' + }); + self.form.submit(); }); - self.form.submit(); } }; @@ -638,38 +642,38 @@ $.NatEditor.prototype.initForm = function() { var editAction = $(ev.currentTarget).attr("href").replace(/^#/, ""); if (self.form.validate().form()) { - self.beforeSubmit(editAction); - - if (topicName.match(/AUTOINC|XXXXXXXXXX/)) { - // don't ajax when we don't know the resultant URL (can change this if the server tells it to us..) - self.form.submit(); - } else { - self.form.ajaxSubmit({ - url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST - beforeSubmit: function() { - self.hideMessages(); - document.title = $.i18n("Saving ..."); - $.blockUI({ - message: '

'+ $.i18n("Saving ...") + '

' - }); - }, - error: function(xhr, textStatus) { - var message = self.extractErrorMessage(xhr.responseText || textStatus); - self.showMessage("error", message); - }, - complete: function(xhr) { - var nonce = xhr.getResponseHeader('X-Foswiki-Validation'); - if (nonce) { - // patch in new nonce - $("input[name='validation_key']").each(function() { - $(this).val("?" + nonce); + self.beforeSubmit(editAction).then(function() { + if (topicName.match(/AUTOINC|XXXXXXXXXX/)) { + // don't ajax when we don't know the resultant URL (can change this if the server tells it to us..) + self.form.submit(); + } else { + self.form.ajaxSubmit({ + url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST + beforeSubmit: function() { + self.hideMessages(); + document.title = $.i18n("Saving ..."); + $.blockUI({ + message: '

'+ $.i18n("Saving ...") + '

' }); + }, + error: function(xhr, textStatus) { + var message = self.extractErrorMessage(xhr.responseText || textStatus); + self.showMessage("error", message); + }, + complete: function(xhr) { + var nonce = xhr.getResponseHeader('X-Foswiki-Validation'); + if (nonce) { + // patch in new nonce + $("input[name='validation_key']").each(function() { + $(this).val("?" + nonce); + }); + } + document.title = origTitle; + $.unblockUI(); } - document.title = origTitle; - $.unblockUI(); - } - }); - } + }); + } + }); } }; @@ -693,35 +697,35 @@ $.NatEditor.prototype.initForm = function() { self.form.find(".ui-natedit-preview").on("click", function() { if (self.form.validate().form()) { - self.beforeSubmit("preview"); - - self.form.ajaxSubmit({ - url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST - beforeSubmit: function() { - self.hideMessages(); - $.blockUI({ - message: '

'+$.i18n("Loading preview ...")+'

' - }); - }, - error: function(xhr, textStatus) { - var message = self.extractErrorMessage(xhr.responseText || textStatus); - $.unblockUI(); - self.showMessage("error", message); - }, - success: function(data) { - var $window = $(window), - height = Math.round(parseInt($window.height() * 0.6, 10)), - width = Math.round(parseInt($window.width() * 0.6, 10)); + self.beforeSubmit("preview").then(function() { + self.form.ajaxSubmit({ + url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST + beforeSubmit: function() { + self.hideMessages(); + $.blockUI({ + message: '

'+$.i18n("Loading preview ...")+'

' + }); + }, + error: function(xhr, textStatus) { + var message = self.extractErrorMessage(xhr.responseText || textStatus); + $.unblockUI(); + self.showMessage("error", message); + }, + success: function(data) { + var $window = $(window), + height = Math.round(parseInt($window.height() * 0.6, 10)), + width = Math.round(parseInt($window.width() * 0.6, 10)); - $.unblockUI(); + $.unblockUI(); - if (width < 640) { - width = 640; - } + if (width < 640) { + width = 640; + } - data = data.replace(/%width%/g, width).replace(/%height%/g, height); - $("body").append(data); - } + data = data.replace(/%width%/g, width).replace(/%height%/g, height); + $("body").append(data); + } + }); }); } return false; @@ -734,20 +738,23 @@ $.NatEditor.prototype.initForm = function() { $("label.error").hide(); $("input.error").removeClass("error"); $(".jqTabGroup a.error").removeClass("error"); - self.beforeSubmit("cancel"); - self.form.submit(); + self.beforeSubmit("cancel").then(function() { + self.form.submit(); + }); return false; }); self.form.find(".ui-natedit-replaceform").on("click", function() { - self.beforeSubmit("replaceform"); - self.form.submit(); + self.beforeSubmit("replaceform").then(function() { + self.form.submit(); + }); return false; }); self.form.find(".ui-natedit-addform").on("click", function() { - self.beforeSubmit("addform"); - self.form.submit(); + self.beforeSubmit("addform").then(function() { + self.form.submit(); + }); return false; }); diff --git a/NatEditPlugin/templates/edittoolbar.natedit.tmpl b/NatEditPlugin/templates/edittoolbar.natedit.tmpl index 98796cd599..6487eb67e8 100644 --- a/NatEditPlugin/templates/edittoolbar.natedit.tmpl +++ b/NatEditPlugin/templates/edittoolbar.natedit.tmpl @@ -25,6 +25,7 @@ %{ ################################################################################ }% %TMPL:DEF{"edittoolbar::paragraphmenu"}%