Skip to content

Commit

Permalink
Item14288: raw and codemirror are ready to be used
Browse files Browse the repository at this point in the history
- tinymce is loading from CDN but does not yet implement all toolbar actions
- prosemirror is barely more than a placeholder atm
- switch between them using NATEDIT_ENGINE = raw/tinymce/codemirror/prosemirror
  • Loading branch information
MichaelDaum committed Feb 27, 2017
1 parent 0410a3b commit 7745f59
Show file tree
Hide file tree
Showing 18 changed files with 3,144 additions and 7 deletions.
9 changes: 7 additions & 2 deletions NatEditPlugin/.gitignore
Expand Up @@ -8,5 +8,10 @@
/NatEditPlugin.zip
/NatEditPlugin_installer
/NatEditPlugin_installer.pl
/pub/System/NatEditPlugin/jquery.natedit.js
/pub/System/NatEditPlugin/styles.css
pub/System/NatEditPlugin/jquery.natedit.js
pub/System/NatEditPlugin/styles.css
pub/System/NatEditPlugin/engine/base/engine.js
pub/System/NatEditPlugin/engine/codemirror/engine.js
pub/System/NatEditPlugin/engine/prosemirror/engine.js
pub/System/NatEditPlugin/engine/raw/engine.js
pub/System/NatEditPlugin/engine/tinymce/engine.js
7 changes: 3 additions & 4 deletions NatEditPlugin/data/System/NatEditPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1485156553" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1488191908" format="1.1" version="1"}%
---+!! Natural Edit Plugin
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -55,8 +55,7 @@ is sufficient.
%$DEPENDENCIES%

---++ Change History
| Copyright ©: | 2007-2015 Michael Daum http://michaeldaumconsulting.com |
| Change History: | |
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 20 Jan 2017 | Foswikitask:Item14265: NatEdit plugin leaves UI blocked after some save errors<br/>\
Foswikitask:Item14285: fixed error clicking on disabled toolbar buttons |
| 06 Jan 2016 | Add helper to insert a data form table header. |
Expand Down Expand Up @@ -181,4 +180,4 @@ is sufficient.
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/distro"}%
%META:FIELD{name="Support" title="Support" value="https://foswiki.org/Support/%25$ROOTMODULE%25"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FILEATTACHMENT{name="screenshot1.png" attr="h" comment="" date="1485156553" size="64487" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="screenshot1.png" attr="h" comment="" date="1488191908" size="64487" user="ProjectContributor" version="1"}%
1 change: 1 addition & 0 deletions NatEditPlugin/lib/Foswiki/Plugins/NatEditPlugin/MANIFEST
@@ -1,3 +1,4 @@
!noci
data/System/NatEditHelpText.txt 0644
data/System/NatEditPluginJSUnitTests.txt 0644
data/System/NatEditPlugin.txt 0644
Expand Down
10 changes: 10 additions & 0 deletions NatEditPlugin/pub/System/NatEditPlugin/engine/Makefile
@@ -0,0 +1,10 @@
FOSWIKI_ROOT?=~/foswiki/core
SUBDIRS=\
base \
raw \
codemirror \
prosemirror \
tinymce

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include

4 changes: 4 additions & 0 deletions NatEditPlugin/pub/System/NatEditPlugin/engine/base/Makefile
@@ -0,0 +1,4 @@
FOSWIKI_ROOT?=~/foswiki/core
TARGET= engine.js

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include
@@ -0,0 +1,264 @@
/*
* jQuery NatEdit: base engine
*
* Copyright (c) 2015-2016 Michael Daum http://michaeldaumconsulting.com
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
'use strict';

(function($) {

/*****************************************************************************
* constructor
*/
window.BaseEngine = function BaseEngine() {
var self = this;

if (typeof(self.opts) === 'undefined') {
self.opts = {};
}
self.log("BaseEngine::constructor");
};


/*************************************************************************
* init this engine
*/
BaseEngine.prototype.init = function() {
//var self = this;

//self.log("BaseEngine::init");
// return dfd.promise();
};

/*************************************************************************
* init gui
*/
BaseEngine.prototype.initGui = function() {
// nop
};

/*************************************************************************
* register events to editor engine
*/
BaseEngine.prototype.on = function(eventName, func) {
var self = this;

// by default forward it to wrapper element
return self.getWrapperElement().on(eventName, func);
};

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

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

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

/*************************************************************************
* set the value of the editor
*/
BaseEngine.prototype.setValue = function(val) {
var self = this,
elem = self.getWrapperElement();

elem.val(val);
};

/*************************************************************************
* debug logging
*/
BaseEngine.prototype.log = function() {
var self = this;

if (console && self.opts.debug) {
console.log.apply(console, arguments);
}
};

/*************************************************************************
* insert stuff at the given cursor position
*/
BaseEngine.prototype.insert = function(newText) {
var self = this;

throw("not implemented: insert()");
};

/*************************************************************************
* remove the selected substring
*/
BaseEngine.prototype.remove = function() {
var self = this;

throw("not implemented: remove()");
};

/*************************************************************************
* returns the current selection
*/
BaseEngine.prototype.getSelection = function() {
var self = this;

throw("not implemented: getSelection()");
};

/*************************************************************************
* returns the currently selected lines
*/
BaseEngine.prototype.getSelectionLines = function() {
var self = this;

throw("not implemented: getSelectionLines()");
};

/*************************************************************************
* set the selection
*/
BaseEngine.prototype.setSelectionRange = function(start, end) {
var self = this;

throw("not implemented: setSelectionRange()");
};

/*************************************************************************
* set the caret position to a specific position. thats done by setting
* the selection range to a single char at the given position
*/
BaseEngine.prototype.setCaretPosition = function(caretPos) {
var self = this;

throw("not implemented: setCaretPosition()");
};

/*************************************************************************
* get the caret position
*/
BaseEngine.prototype.getCaretPosition = function() {
var self = this;

throw("not implemented: getCaretPosition()");
};

/*************************************************************************
* undo recent change
*/
BaseEngine.prototype.undo = function() {
var self = this;

throw("not implemented: undo()");
};

/*************************************************************************
* redo recent change
*/
BaseEngine.prototype.redo = function() {
var self = this;

throw("not implemented: redo()");
};

/*****************************************************************************
* handle toolbar action. returns the data to be used by the toolbar action.
* return undef to intercept the shell's actions
*/
BaseEngine.prototype.handleToolbarAction = function(ui) {
return ui.data();
};

/*************************************************************************
* used for line oriented tags - like bulleted lists
* if you have a multiline selection, the tagOpen/tagClose is added to each line
* if there is no selection, select the entire current line
* if there is a selection, select the entire line for each line selected
*/
BaseEngine.prototype.insertLineTag = function(markup) {
var self = this;

throw("not implemented: insertLineTag()");
};

/*************************************************************************
* insert a topic markup tag
*/
BaseEngine.prototype.insertTag = function(markup) {
var self = this;

throw("not implemented: insertTag()");
};

/*************************************************************************
* insert a TML table with the given header rows, rows and cols
* opts:
* {
* heads: integer, // number of header rows
* rows: integer, // number of rows
* cols: integer, // number of columns
* editable: boolean, // add %EDITTABLE markup
* }
*/
BaseEngine.prototype.insertTable = function(opts) {
var self = this, output = [], editTableLine, i, j, line;

if (typeof(opts.heads) === 'undefined') {
opts.heads = 0;
}
if (typeof(opts.rows) === 'undefined') {
opts.rows = 0;
}
if (typeof(opts.cols) === 'undefined') {
opts.cols = 0;
}

if (opts.editable) {
editTableLine = '%EDITTABLE{format="';

for (i = 0; i < opts.cols; i++) {
editTableLine += '| text,20';
}

editTableLine += '|"}%';
output.push(editTableLine);
}

for (i = 0; i < opts.heads; i++) {
line = '|';
for (j = 0; j < opts.cols; j++) {
line += ' *head* |';
}
output.push(line);
}
for (i = 0; i < opts.rows; i++) {
line = '|';
for (j = 0; j < opts.cols; j++) {
line += ' data |';
}
output.push(line);
}
self.remove();
self.insertTag(['', output.join("\n")+"\n", '']);
};

/*****************************************************************************
* search & replace a term in the textarea
*/
BaseEngine.prototype.searchReplace = function(term, text, ignoreCase) {
var self = this;

throw("not implemented: searchReplace()");
};

})(jQuery);
@@ -0,0 +1,4 @@
FOSWIKI_ROOT?=~/foswiki/core
TARGET= engine.js

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include

0 comments on commit 7745f59

Please sign in to comment.