diff options
Diffstat (limited to 'public/javascripts')
| -rw-r--r-- | public/javascripts/admin_interface.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index ffebb694..b2bcaf29 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -32,6 +32,43 @@ $(document).ready(function () { | |||
| 32 | 'img': 'inline-image inline-image--full inline-image--half inline-image--left inline-image--right', | 32 | 'img': 'inline-image inline-image--full inline-image--half inline-image--left inline-image--right', |
| 33 | 'a': 'glightbox' | 33 | 'a': 'glightbox' |
| 34 | }, | 34 | }, |
| 35 | paste_preprocess: function (editor, args) { | ||
| 36 | var doc = new DOMParser().parseFromString(args.content, 'text/html'); | ||
| 37 | var blocks = 'p,h1,h2,h3,h4,h5,h6,ul,ol,li,blockquote,table,pre,div'; | ||
| 38 | |||
| 39 | // Innermost first, so a nested div is resolved before its parent. | ||
| 40 | Array.from(doc.querySelectorAll('div')).reverse().forEach(function (div) { | ||
| 41 | if (div.textContent.trim() === '' && !div.querySelector('img')) { | ||
| 42 | div.remove(); | ||
| 43 | } else if (div.querySelector(blocks)) { | ||
| 44 | div.replaceWith.apply(div, Array.from(div.childNodes)); | ||
| 45 | } else { | ||
| 46 | var p = doc.createElement('p'); | ||
| 47 | while (div.firstChild) { p.appendChild(div.firstChild); } | ||
| 48 | div.replaceWith(p); | ||
| 49 | } | ||
| 50 | }); | ||
| 51 | |||
| 52 | doc.querySelectorAll('strong,em,b,i,span,u').forEach(function (el) { | ||
| 53 | if (el.textContent.trim() === '' && !el.querySelector('img')) { | ||
| 54 | el.replaceWith.apply(el, Array.from(el.childNodes)); | ||
| 55 | } | ||
| 56 | }); | ||
| 57 | |||
| 58 | ['strong', 'em', 'b', 'i', 'u'].forEach(function (tag) { | ||
| 59 | doc.querySelectorAll(tag).forEach(function (el) { | ||
| 60 | var next = el.nextSibling; | ||
| 61 | while (next && next.nodeName && next.nodeName.toLowerCase() === tag) { | ||
| 62 | while (next.firstChild) { el.appendChild(next.firstChild); } | ||
| 63 | var after = next.nextSibling; | ||
| 64 | next.remove(); | ||
| 65 | next = after; | ||
| 66 | } | ||
| 67 | }); | ||
| 68 | }); | ||
| 69 | |||
| 70 | args.content = doc.body.innerHTML; | ||
| 71 | }, | ||
| 35 | setup: function(editor) { | 72 | setup: function(editor) { |
| 36 | editor.on('init', function() { | 73 | editor.on('init', function() { |
| 37 | cccms.setup_autosave(); | 74 | cccms.setup_autosave(); |
