From 419124d8a02e3e957454b349285fe63c7723d6fa Mon Sep 17 00:00:00 2001 From: Emanuel Holzmann Date: Sun, 16 Feb 2020 23:03:20 +0100 Subject: [PATCH 1/5] add the possibility to add classes to the paragraph. this is possible for h1-h5 an p. --- src/trumbowyg.js | 79 +++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/src/trumbowyg.js b/src/trumbowyg.js index 5464a3c73..fe1f257b7 100644 --- a/src/trumbowyg.js +++ b/src/trumbowyg.js @@ -77,6 +77,12 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { imageWidthModalEdit: false, prefix: 'trumbowyg-', +// classes for inputs + h1Class: null, + h2Class: null, + h3Class: null, + h4Class: null, + pClass: null, semantic: true, semanticKeepAttributes: false, @@ -496,7 +502,7 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { return; } - if (typeof(protocol) !== 'string') { + if (typeof (protocol) !== 'string') { return 'https://'; } return protocol.replace('://', '') + '://'; @@ -591,7 +597,8 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { try { t.execCmd(key.fn, key.param); return false; - } catch (c) {} + } catch (c) { + } } else { if (t.o.tabToIndent && e.key === 'Tab') { try { @@ -601,7 +608,8 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { t.execCmd('indent', true, null); } return false; - } catch (c) {} + } catch (c) { + } } } }) @@ -659,8 +667,7 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { if (e.type === 'focus') { t.autogrowOnEnterWasFocused = true; t.autogrowEditorOnEnter(); - } - else if (!t.o.autogrow) { + } else if (!t.o.autogrow) { t.$ed.css({height: t.$ed.css('min-height')}); t.$c.trigger('tbwresize'); } @@ -872,8 +879,8 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { type: 'button', class: prefix + btnName + '-dropdown-button ' + (btn.class || '') + (btn.ico ? ' ' + prefix + btn.ico + '-button' : ''), html: t.hasSvg && hasIcon ? - '' + (btn.text || btn.title || t.lang[btnName] || btnName) : - (btn.text || btn.title || t.lang[btnName] || btnName), + '' + (btn.text || btn.title || t.lang[btnName] || btnName) : + (btn.text || btn.title || t.lang[btnName] || btnName), title: (btn.key ? '(' + (t.isMac ? 'Cmd' : 'Ctrl') + ' + ' + btn.key + ')' : null), style: btn.style || null, mousedown: function () { @@ -1207,7 +1214,7 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { $(oldTag, this.$ed).each(function () { var $oldTag = $(this); - if($oldTag.contents().length === 0) { + if ($oldTag.contents().length === 0) { return false; } @@ -1433,6 +1440,24 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { t.syncCode(); t.semanticCode(false, true); + try { + var listId = window.getSelection().focusNode.parentNode; + var arrayKey = param + 'Class'; + + var arr = t.o[arrayKey]; + if (arr) { + $(listId).removeClass(); + + for (var i = 0; i < arr.length; i++) { + $(listId).addClass(arr[i]); + } + + + } + } catch (e) { + + } + } if (cmd !== 'dropdown') { @@ -1485,19 +1510,19 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { action: '', html: content }) - .on('submit', function () { - $modal.trigger(CONFIRM_EVENT); - return false; - }) - .on('reset', function () { - $modal.trigger(CANCEL_EVENT); - return false; - }) - .on('submit reset', function () { - if (t.o.autogrowOnEnter) { - t.autogrowOnEnterDontClose = false; - } - }); + .on('submit', function () { + $modal.trigger(CONFIRM_EVENT); + return false; + }) + .on('reset', function () { + $modal.trigger(CANCEL_EVENT); + return false; + }) + .on('submit reset', function () { + if (t.o.autogrowOnEnter) { + t.autogrowOnEnterDontClose = false; + } + }); } else { formOrContent = content; } @@ -1809,9 +1834,9 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { clearButtonPaneStatus: function () { var t = this, - prefix = t.o.prefix, - activeClasses = prefix + 'active-button ' + prefix + 'active', - originalIconClass = prefix + 'original-icon'; + prefix = t.o.prefix, + activeClasses = prefix + 'active-button ' + prefix + 'active', + originalIconClass = prefix + 'original-icon'; // Reset all buttons and dropdown state $('.' + prefix + 'active-button', t.$btnPane).removeClass(activeClasses); @@ -1849,12 +1874,12 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { if (t.o.changeActiveDropdownIcon && $btnSvgUse.length > 0) { // Save original icon $dropdownBtn - .addClass(originalIconClass) - .data(originalIconClass, $dropdownBtnSvgUse.attr('xlink:href')); + .addClass(originalIconClass) + .data(originalIconClass, $dropdownBtnSvgUse.attr('xlink:href')); // Put the active sub-button's icon $dropdownBtnSvgUse - .attr('xlink:href', $btnSvgUse.attr('xlink:href')); + .attr('xlink:href', $btnSvgUse.attr('xlink:href')); } } catch (e) { } From 1f35a0b0f840c610f6a95b6cd3e7c4252c276882 Mon Sep 17 00:00:00 2001 From: Emanuel Holzmann Date: Mon, 17 Feb 2020 00:25:46 +0100 Subject: [PATCH 2/5] change the input to a classObject. --- package.json | 4 ++-- src/trumbowyg.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index c49fa1a83..34b232fa2 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "trumbowyg", + "name": "holematrumbowyg", "title": "Trumbowyg", "description": "A lightweight WYSIWYG editor", - "version": "2.21.0", + "version": "2.21.1", "main": "dist/trumbowyg.js", "homepage": "http://alex-d.github.io/Trumbowyg", "author": { diff --git a/src/trumbowyg.js b/src/trumbowyg.js index fe1f257b7..42f5f6eb5 100644 --- a/src/trumbowyg.js +++ b/src/trumbowyg.js @@ -78,12 +78,13 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { prefix: 'trumbowyg-', // classes for inputs - h1Class: null, - h2Class: null, - h3Class: null, - h4Class: null, - pClass: null, - + tagClasses:{ + 'h1': null, + 'h2': null, + 'h3': null, + 'h4': null, + 'p': null, + }, semantic: true, semanticKeepAttributes: false, resetCss: false, @@ -1442,12 +1443,12 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { t.semanticCode(false, true); try { var listId = window.getSelection().focusNode.parentNode; - var arrayKey = param + 'Class'; - - var arr = t.o[arrayKey]; + var arr = t.o.tagClasses[param]; if (arr) { $(listId).removeClass(); - + for (var i = 0; i < arr.length; i++) { + $(listId).removeClass(arr[i]); + } for (var i = 0; i < arr.length; i++) { $(listId).addClass(arr[i]); } From c3eaeecf26df60383480b6f6bec55892b43f215b Mon Sep 17 00:00:00 2001 From: Emanuel Holzmann Date: Mon, 17 Feb 2020 00:29:07 +0100 Subject: [PATCH 3/5] revert the packeage json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 34b232fa2..c49fa1a83 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "holematrumbowyg", + "name": "trumbowyg", "title": "Trumbowyg", "description": "A lightweight WYSIWYG editor", - "version": "2.21.1", + "version": "2.21.0", "main": "dist/trumbowyg.js", "homepage": "http://alex-d.github.io/Trumbowyg", "author": { From bb1fce9e65c840ed91613359f8385f3b1d3ea08c Mon Sep 17 00:00:00 2001 From: Emanuel Holzmann Date: Mon, 13 Apr 2020 19:42:30 +0200 Subject: [PATCH 4/5] fix the trumbowyg.js --- src/trumbowyg.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/trumbowyg.js b/src/trumbowyg.js index 42f5f6eb5..5f4e8cd7b 100644 --- a/src/trumbowyg.js +++ b/src/trumbowyg.js @@ -1442,7 +1442,10 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { t.syncCode(); t.semanticCode(false, true); try { - var listId = window.getSelection().focusNode.parentNode; + var listId = window.getSelection().focusNode; + if(!$(window.getSelection().focusNode.parentNode).hasClass('trumbowyg-editor')){ + listId = window.getSelection().focusNode.parentNode; + } var arr = t.o.tagClasses[param]; if (arr) { $(listId).removeClass(); From 867d7cede17beacb213d47facd6c99883cad6177 Mon Sep 17 00:00:00 2001 From: Emanuel Holzmann Date: Thu, 16 Apr 2020 21:18:24 +0200 Subject: [PATCH 5/5] clear code to not remove the classes. --- src/trumbowyg.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/trumbowyg.js b/src/trumbowyg.js index 5f4e8cd7b..4af5a351c 100644 --- a/src/trumbowyg.js +++ b/src/trumbowyg.js @@ -1448,15 +1448,9 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', { } var arr = t.o.tagClasses[param]; if (arr) { - $(listId).removeClass(); - for (var i = 0; i < arr.length; i++) { - $(listId).removeClass(arr[i]); - } for (var i = 0; i < arr.length; i++) { $(listId).addClass(arr[i]); } - - } } catch (e) {