]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/lists/plugin.js
WordPress 4.5
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / lists / plugin.js
index 4bb987b50bc48b39573bef5ad47c56fbc75da804..d1a1c1c3d059bf18847f564f615a73c55664d3d9 100644 (file)
 tinymce.PluginManager.add('lists', function(editor) {
        var self = this;
 
+       function isChildOfBody(elm) {
+               return editor.$.contains(editor.getBody(), elm);
+       }
+
+       function isBr(node) {
+               return node && node.nodeName == 'BR';
+       }
+
        function isListNode(node) {
-               return node && (/^(OL|UL|DL)$/).test(node.nodeName);
+               return node && (/^(OL|UL|DL)$/).test(node.nodeName) && isChildOfBody(node);
        }
 
        function isFirstChild(node) {
@@ -425,9 +433,9 @@ tinymce.PluginManager.add('lists', function(editor) {
                                return true;
                        }
 
-                       if (sibling && sibling.nodeName == 'LI' && isListNode(li.lastChild)) {
+                       /*if (sibling && sibling.nodeName == 'LI' && isListNode(li.lastChild)) {
                                return false;
-                       }
+                       }*/
 
                        sibling = li.previousSibling;
                        if (sibling && sibling.nodeName == 'LI') {
@@ -498,7 +506,11 @@ tinymce.PluginManager.add('lists', function(editor) {
                }
 
                function applyList(listName) {
-                       var rng = selection.getRng(true), bookmark = createBookmark(rng), listItemName = 'LI';
+                       var rng = selection.getRng(true), bookmark, listItemName = 'LI';
+
+                       if (dom.getContentEditable(selection.getNode()) === "false") {
+                               return;
+                       }
 
                        listName = listName.toUpperCase();
 
@@ -554,8 +566,8 @@ tinymce.PluginManager.add('lists', function(editor) {
                                                return;
                                        }
 
-                                       if (dom.isBlock(node) || node.nodeName == 'BR') {
-                                               if (node.nodeName == 'BR') {
+                                       if (dom.isBlock(node) || isBr(node)) {
+                                               if (isBr(node)) {
                                                        dom.remove(node);
                                                }
 
@@ -583,6 +595,8 @@ tinymce.PluginManager.add('lists', function(editor) {
                                return textBlocks;
                        }
 
+                       bookmark = createBookmark(rng);
+
                        tinymce.each(getSelectedTextBlocks(), function(block) {
                                var listBlock, sibling;
 
@@ -659,6 +673,18 @@ tinymce.PluginManager.add('lists', function(editor) {
                        };
                }
 
+               function isBogusBr(node) {
+                       if (!isBr(node)) {
+                               return false;
+                       }
+
+                       if (dom.isBlock(node.nextSibling) && !isBr(node.previousSibling)) {
+                               return true;
+                       }
+
+                       return false;
+               }
+
                self.backspaceDelete = function(isForward) {
                        function findNextCaretContainer(rng, isForward) {
                                var node = rng.startContainer, offset = rng.startOffset;
@@ -669,9 +695,20 @@ tinymce.PluginManager.add('lists', function(editor) {
                                }
 
                                nonEmptyBlocks = editor.schema.getNonEmptyElements();
-                               walker = new tinymce.dom.TreeWalker(rng.startContainer);
+                               if (node.nodeType == 1) {
+                                       node = tinymce.dom.RangeUtils.getNode(node, offset);
+                               }
+
+                               walker = new tinymce.dom.TreeWalker(node, editor.getBody());
+
+                               // Delete at <li>|<br></li> then jump over the bogus br
+                               if (isForward) {
+                                       if (isBogusBr(node)) {
+                                               walker.next();
+                                       }
+                               }
 
-                               while ((node = walker[isForward ? 'next' : 'prev']())) {
+                               while ((node = walker[isForward ? 'next' : 'prev2']())) {
                                        if (node.nodeName == 'LI' && !node.hasChildNodes()) {
                                                return node;
                                        }
@@ -689,12 +726,22 @@ tinymce.PluginManager.add('lists', function(editor) {
                        function mergeLiElements(fromElm, toElm) {
                                var node, listNode, ul = fromElm.parentNode;
 
+                               if (!isChildOfBody(fromElm) || !isChildOfBody(toElm)) {
+                                       return;
+                               }
+
                                if (isListNode(toElm.lastChild)) {
                                        listNode = toElm.lastChild;
                                }
 
+                               if (ul == toElm.lastChild) {
+                                       if (isBr(ul.previousSibling)) {
+                                               dom.remove(ul.previousSibling);
+                                       }
+                               }
+
                                node = toElm.lastChild;
-                               if (node && node.nodeName == 'BR' && fromElm.hasChildNodes()) {
+                               if (node && isBr(node) && fromElm.hasChildNodes()) {
                                        dom.remove(node);
                                }