Skip to content

Commit

Permalink
* Fixed #21 and added denyTags options
Browse files Browse the repository at this point in the history
* Fixed selectin code in source mode
* Alow insert HTML in source mode
* Fixed autosize in source mode when used native textarea (useAceEditor: false)
* Remove all empty tags cleanHTML.removeEmptyElements = true
* Fixed behavior when UL was selected and was executed command formatBlock
  • Loading branch information
xdan committed Mar 13, 2018
1 parent 6d4dff3 commit 0e6e170
Show file tree
Hide file tree
Showing 23 changed files with 357 additions and 142 deletions.
30 changes: 15 additions & 15 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
var webpack = require('webpack')
var webpackDevMiddleware = require('webpack-dev-middleware')
var webpackHotMiddleware = require('webpack-hot-middleware')
var config = require('./webpack.config')
var compression = require('compression')
var app = new (require('express'))()
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const config = require('./webpack.config');
const compression = require('compression');
const app = new (require('express'))();

app.use(compression())
app.use(compression());

var port = 2000
const port = 2000;

var compiler = webpack(config)
const compiler = webpack(config);

app.use(webpackDevMiddleware(compiler, {
stats: { colors: true },
noInfo: true,
publicPath: config.output.publicPath
}))
}));

app.use(webpackHotMiddleware(compiler))
app.use(webpackHotMiddleware(compiler));

app.get("/", function(req, res) {
res.sendFile(__dirname + '/index.html')
})
});

app.get("/test.html", function(req, res) {
res.sendFile(__dirname + '/test.html')
})
});

app.get("/dist/jodit.*", function(req, res) {
app.get("/build/jodit.*", function(req, res) {
res.sendFile(__dirname + '/' + req.url)
})
});

app.use('/node_modules', require('express').static(__dirname + '/node_modules'));

Expand Down
10 changes: 5 additions & 5 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,21 +599,21 @@ Config.prototype.controls = {
editor.i18n('License: %s', !isLicense(editor.options.license) ? editor.i18n('Free Non-commercial Version') : normalizeLicense(editor.options.license)) +
'</div>' +
'<div>' +
'<a href="http://xdsoft.net/jodit/" target="_blank">http://xdsoft.net/jodit/</a>' +
'<a href="https://xdsoft.net/jodit/" target="_blank">http://xdsoft.net/jodit/</a>' +
'</div>' +
'<div>' +
'<a href="http://xdsoft.net/jodit/doc/" target="_blank">' + editor.i18n('Jodit User\'s Guide') + '</a> ' +
'<a href="https://xdsoft.net/jodit/doc/" target="_blank">' + editor.i18n('Jodit User\'s Guide') + '</a> ' +
editor.i18n('contains detailed help for using') +
'</div>' +
'<div>' +
editor.i18n('For information about the license, please go to our website:') +
'</div>' +
'<div>' +
'<a href="http://xdsoft.net/jodit/license.html" target="_blank">http://xdsoft.net/jodit/license.html</a>' +
'<a href="https://xdsoft.net/jodit/license.html" target="_blank">http://xdsoft.net/jodit/license.html</a>' +
'</div>' +
(isLicense(editor.options.license) ? '' :
'<div>' +
'<a href="http://xdsoft.net/jodit/#download" target="_blank">' + editor.i18n('Buy full version') + '</a>' +
'<a href="https://xdsoft.net/jodit/buy.html" target="_blank">' + editor.i18n('Buy full version') + '</a>' +
'</div>'
) +
'<div>' +
Expand All @@ -637,7 +637,7 @@ Config.prototype.controls = {
editor.selection.insertNode(dom('<img src="' + url + '"/>', editor.editorDocument));
};

let sourceImage: HTMLImageElement|null = null;
let sourceImage: HTMLImageElement | null = null;

if (current && current.nodeType !== Node.TEXT_NODE && (current.tagName === 'IMG' || $$('img', current).length)) {
sourceImage = current.tagName === 'IMG' ? current : <HTMLImageElement>$$('img', current)[0];
Expand Down
6 changes: 6 additions & 0 deletions src/Jodit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,16 @@ export class Jodit extends Component {
}
}

isDestructed: boolean = false;
/**
* Jodit's Destructor. Remove editor, and return source input
*/
destruct() {
if (this.isDestructed) {
return;
}

this.isDestructed = true;
/**
* Triggered before {@link events:beforeDestruct|beforeDestruct} executed. If returned false method stopped
*
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const SPACE_REG_EXP_START = /^[\s\n\t\r\uFEFF\u200b]+/g;
export const SPACE_REG_EXP_END = /[\s\n\t\r\uFEFF\u200b]+$/g;

export const IS_BLOCK = /^(PRE|DIV|P|LI|H[1-6]|BLOCKQUOTE|TD|TH|TABLE|BODY|HTML|FIGCAPTION|FIGURE)$/i;
export const IS_SPAN = /^(STRONG|SPAN|I|EM|B)$/;

export const KEY_BACKSPACE = 8;
export const KEY_TAB = 9;
Expand Down
48 changes: 38 additions & 10 deletions src/modules/Dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export class Dom {
/**
*
* @param {Node} current
* @param {String|Node} tag
* @param {String | Node} tag
* @param {Jodit} editor
*
* @return {HTMLElement}
*/
static wrap = (current: Node, tag: Node|string, editor: Jodit): HTMLElement => {
let tmp: false|Node|HTMLElement|HTMLTableCellElement,
static wrapInline = (current: Node, tag: Node|string, editor: Jodit): HTMLElement => {
let tmp: null | Node,
first: Node = current,
last: Node = current;

Expand All @@ -37,7 +37,7 @@ export class Dom {
let needFindNext: boolean = false;
do {
needFindNext = false;
tmp = Dom.prev(first, (elm) => !!elm, editor.editor, false);
tmp = first.previousSibling;
if (tmp && !Dom.isBlock(tmp)) {
needFindNext = true;
first = tmp;
Expand All @@ -46,7 +46,7 @@ export class Dom {

do {
needFindNext = false;
tmp = Dom.next(last, (elm) => !!elm, editor.editor, false);
tmp = last.nextSibling;
if (tmp && !Dom.isBlock(tmp)) {
needFindNext = true;
last = tmp;
Expand All @@ -60,7 +60,7 @@ export class Dom {
first.parentNode.insertBefore(wrapper, first);
}

let next: Node|null = first;
let next: Node | null = first;

while (next) {
next = first.nextSibling;
Expand All @@ -72,6 +72,32 @@ export class Dom {
}


editor.selection.restore(selInfo);

return <HTMLElement>wrapper;
};
/**
*
* @param {Node} current
* @param {String | Node} tag
* @param {Jodit} editor
*
* @return {HTMLElement}
*/
static wrap = (current: Node, tag: Node|string, editor: Jodit): HTMLElement | null => {

const selInfo = editor.selection.save();

const wrapper = typeof tag === 'string' ? Dom.create(tag, '', editor.editorDocument) : tag;

if (!current.parentNode) {
return null;
}

current.parentNode.insertBefore(wrapper, current);

wrapper.appendChild(current);

editor.selection.restore(selInfo);

return <HTMLElement>wrapper;
Expand All @@ -82,7 +108,7 @@ export class Dom {
* @param node
*/
static unwrap(node: Node) {
let parent: Node|null = node.parentNode,
let parent: Node | null = node.parentNode,
el = node;

if (parent) {
Expand All @@ -108,7 +134,7 @@ export class Dom {
* ```
*/
static each (elm: Node|HTMLElement, callback: (this: Node, node: Node) => void|false): boolean {
let node: Node|null|false = elm.firstChild;
let node: Node | null | false = elm.firstChild;

if (node) {
while (node) {
Expand Down Expand Up @@ -375,6 +401,8 @@ export class Dom {
}

static isEmpty(node: Node): boolean {
const isNoEmtyElement: RegExp = /^(img|svg|canvas|input|textarea|form)$/;

if (!node) {
return true;
}
Expand All @@ -383,7 +411,7 @@ export class Dom {
return node.nodeValue === null || trim(node.nodeValue).length === 0;
}

return Dom.each(<HTMLElement>node, (elm: Node | null): false | void => {
return !node.nodeName.toLowerCase().match(isNoEmtyElement) && Dom.each(<HTMLElement>node, (elm: Node | null): false | void => {
if (
(
elm && elm.nodeType === Node.TEXT_NODE &&
Expand All @@ -394,7 +422,7 @@ export class Dom {
) ||
(
elm && elm.nodeType === Node.ELEMENT_NODE &&
elm.nodeName.match(/^(img|table)$/i)
elm.nodeName.toLowerCase().match(isNoEmtyElement)
)
) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ export const debounce = function (this: any, fn: Function, timeout ?: number, i

if (timeout) {
clearTimeout(timer);
timer = window.setTimeout(function () {
timer = window.setTimeout(() => {
if (!invokeAsap) {
fn.apply(ctx, args);
}
Expand Down
25 changes: 21 additions & 4 deletions src/modules/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {each, dom, trim, $$, css, normilizeCSSValue, isIE, isPlainObject, normal
import {Dom} from "./Dom";
import {Jodit} from "../Jodit";
import {INVISIBLE_SPACE_REG_EXP_END, INVISIBLE_SPACE_REG_EXP_START} from "../constants";
import {INVISIBLE_SPACE} from "../constants";

export type markerInfo = {
startId: string,
Expand Down Expand Up @@ -563,9 +564,25 @@ export class Select extends Component{
return node === end;
}, this.jodit.editor, true, 'nextSibling', false);

nodes.forEach((current: Node) => {
let forEvery = (current: Node) => {
if (current.nodeName.match(/^(UL|OL)$/)) {
return [].slice.call(current.childNodes).forEach(forEvery);
}

if (current.nodeName === 'LI') {
if (current.firstChild) {
current = current.firstChild;
} else {
let currentB: Node = this.jodit.editorDocument.createTextNode(INVISIBLE_SPACE);
current.appendChild(currentB);
current = currentB;
}
}

callback(current);
})
};

nodes.forEach(forEvery)
}
};

Expand Down Expand Up @@ -868,7 +885,7 @@ export class Select extends Component{
leftRange.setStartBefore(wrapper);
leftRange.setEndBefore(font);

const leftFragment = leftRange.extractContents();
const leftFragment: DocumentFragment = leftRange.extractContents();

if ((!leftFragment.textContent || !trim(leftFragment.textContent).length) && leftFragment.firstChild) {
Dom.unwrap(leftFragment.firstChild);
Expand Down Expand Up @@ -944,7 +961,7 @@ export class Select extends Component{

if (nodeName.toUpperCase() === defaultTag || !clearStyle) {
const node: Node = Dom.create(nodeName, consts.INVISIBLE_SPACE, this.jodit.editorDocument);
this.insertNode(node);
this.insertNode(node, false, false);
if (nodeName.toUpperCase() === defaultTag && cssRules) {
css(<HTMLElement>node, cssRules);
}
Expand Down
Loading

0 comments on commit 0e6e170

Please sign in to comment.