]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/lists/plugin.js
Wordpress 4.6
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / lists / plugin.js
index d1a1c1c3d059bf18847f564f615a73c55664d3d9..4a778ff05b98ba2a415973ca23ba47bf11957ada 100644 (file)
@@ -270,11 +270,17 @@ tinymce.PluginManager.add('lists', function(editor) {
                        }
                }
 
+               var shouldMerge = function (listBlock, sibling) {
+                       var targetStyle = editor.dom.getStyle(listBlock, 'list-style-type', true);
+                       var style = editor.dom.getStyle(sibling, 'list-style-type', true);
+                       return targetStyle === style;
+               };
+
                function mergeWithAdjacentLists(listBlock) {
                        var sibling, node;
 
                        sibling = listBlock.nextSibling;
-                       if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName) {
+                       if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName && shouldMerge(listBlock, sibling)) {
                                while ((node = sibling.firstChild)) {
                                        listBlock.appendChild(node);
                                }
@@ -283,7 +289,7 @@ tinymce.PluginManager.add('lists', function(editor) {
                        }
 
                        sibling = listBlock.previousSibling;
-                       if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName) {
+                       if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName && shouldMerge(listBlock, sibling)) {
                                while ((node = sibling.firstChild)) {
                                        listBlock.insertBefore(node, listBlock.firstChild);
                                }
@@ -394,7 +400,7 @@ tinymce.PluginManager.add('lists', function(editor) {
                }
 
                function indent(li) {
-                       var sibling, newList;
+                       var sibling, newList, listStyle;
 
                        function mergeLists(from, to) {
                                var node;
@@ -440,6 +446,10 @@ tinymce.PluginManager.add('lists', function(editor) {
                        sibling = li.previousSibling;
                        if (sibling && sibling.nodeName == 'LI') {
                                newList = dom.create(li.parentNode.nodeName);
+                               listStyle = dom.getStyle(li.parentNode, 'listStyleType');
+                               if (listStyle) {
+                                       dom.setStyle(newList, 'listStyleType', listStyle);
+                               }
                                sibling.appendChild(newList);
                                newList.appendChild(li);
                                mergeLists(li.lastChild, newList);
@@ -505,7 +515,7 @@ tinymce.PluginManager.add('lists', function(editor) {
                        }
                }
 
-               function applyList(listName) {
+               function applyList(listName, detail) {
                        var rng = selection.getRng(true), bookmark, listItemName = 'LI';
 
                        if (dom.getContentEditable(selection.getNode()) === "false") {
@@ -600,8 +610,17 @@ tinymce.PluginManager.add('lists', function(editor) {
                        tinymce.each(getSelectedTextBlocks(), function(block) {
                                var listBlock, sibling;
 
+                               var hasCompatibleStyle = function (sib) {
+                                       var sibStyle = dom.getStyle(sib, 'list-style-type');
+                                       var detailStyle = detail ? detail['list-style-type'] : '';
+
+                                       detailStyle = detailStyle === null ? '' : detailStyle;
+
+                                       return sibStyle === detailStyle;
+                               };
+
                                sibling = block.previousSibling;
-                               if (sibling && isListNode(sibling) && sibling.nodeName == listName) {
+                               if (sibling && isListNode(sibling) && sibling.nodeName == listName && hasCompatibleStyle(sibling)) {
                                        listBlock = sibling;
                                        block = dom.rename(block, listItemName);
                                        sibling.appendChild(block);
@@ -612,12 +631,17 @@ tinymce.PluginManager.add('lists', function(editor) {
                                        block = dom.rename(block, listItemName);
                                }
 
+                               updateListStyle(listBlock, detail);
                                mergeWithAdjacentLists(listBlock);
                        });
 
                        moveToBookmark(bookmark);
                }
 
+               var updateListStyle = function (el, detail) {
+                       dom.setStyle(el, 'list-style-type', detail ? detail['list-style-type'] : null);
+               };
+
                function removeList() {
                        var bookmark = createBookmark(selection.getRng(true)), root = editor.getBody();
 
@@ -645,7 +669,7 @@ tinymce.PluginManager.add('lists', function(editor) {
                        moveToBookmark(bookmark);
                }
 
-               function toggleList(listName) {
+               function toggleList(listName, detail) {
                        var parentList = dom.getParent(selection.getStart(), 'OL,UL,DL');
 
                        if (isEditorBody(parentList)) {
@@ -657,11 +681,13 @@ tinymce.PluginManager.add('lists', function(editor) {
                                        removeList(listName);
                                } else {
                                        var bookmark = createBookmark(selection.getRng(true));
+                                       updateListStyle(parentList, detail);
                                        mergeWithAdjacentLists(dom.rename(parentList, listName));
+
                                        moveToBookmark(bookmark);
                                }
                        } else {
-                               applyList(listName);
+                               applyList(listName, detail);
                        }
                }
 
@@ -819,16 +845,16 @@ tinymce.PluginManager.add('lists', function(editor) {
                        }
                });
 
-               editor.addCommand('InsertUnorderedList', function() {
-                       toggleList('UL');
+               editor.addCommand('InsertUnorderedList', function(ui, detail) {
+                       toggleList('UL', detail);
                });
 
-               editor.addCommand('InsertOrderedList', function() {
-                       toggleList('OL');
+               editor.addCommand('InsertOrderedList', function(ui, detail) {
+                       toggleList('OL', detail);
                });
 
-               editor.addCommand('InsertDefinitionList', function() {
-                       toggleList('DL');
+               editor.addCommand('InsertDefinitionList', function(ui, detail) {
+                       toggleList('DL', detail);
                });
 
                editor.addQueryStateHandler('InsertUnorderedList', queryListCommandState('UL'));