~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-includes/js/tinymce/plugins/lists/plugin.js

  • Committer: Barry Price
  • Date: 2016-08-17 04:50:12 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: barry.price@canonical.com-20160817045012-qfui81zhqnqv2ba9
Merge WP4.6 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
270
270
                        }
271
271
                }
272
272
 
 
273
                var shouldMerge = function (listBlock, sibling) {
 
274
                        var targetStyle = editor.dom.getStyle(listBlock, 'list-style-type', true);
 
275
                        var style = editor.dom.getStyle(sibling, 'list-style-type', true);
 
276
                        return targetStyle === style;
 
277
                };
 
278
 
273
279
                function mergeWithAdjacentLists(listBlock) {
274
280
                        var sibling, node;
275
281
 
276
282
                        sibling = listBlock.nextSibling;
277
 
                        if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName) {
 
283
                        if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName && shouldMerge(listBlock, sibling)) {
278
284
                                while ((node = sibling.firstChild)) {
279
285
                                        listBlock.appendChild(node);
280
286
                                }
283
289
                        }
284
290
 
285
291
                        sibling = listBlock.previousSibling;
286
 
                        if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName) {
 
292
                        if (sibling && isListNode(sibling) && sibling.nodeName == listBlock.nodeName && shouldMerge(listBlock, sibling)) {
287
293
                                while ((node = sibling.firstChild)) {
288
294
                                        listBlock.insertBefore(node, listBlock.firstChild);
289
295
                                }
394
400
                }
395
401
 
396
402
                function indent(li) {
397
 
                        var sibling, newList;
 
403
                        var sibling, newList, listStyle;
398
404
 
399
405
                        function mergeLists(from, to) {
400
406
                                var node;
440
446
                        sibling = li.previousSibling;
441
447
                        if (sibling && sibling.nodeName == 'LI') {
442
448
                                newList = dom.create(li.parentNode.nodeName);
 
449
                                listStyle = dom.getStyle(li.parentNode, 'listStyleType');
 
450
                                if (listStyle) {
 
451
                                        dom.setStyle(newList, 'listStyleType', listStyle);
 
452
                                }
443
453
                                sibling.appendChild(newList);
444
454
                                newList.appendChild(li);
445
455
                                mergeLists(li.lastChild, newList);
505
515
                        }
506
516
                }
507
517
 
508
 
                function applyList(listName) {
 
518
                function applyList(listName, detail) {
509
519
                        var rng = selection.getRng(true), bookmark, listItemName = 'LI';
510
520
 
511
521
                        if (dom.getContentEditable(selection.getNode()) === "false") {
600
610
                        tinymce.each(getSelectedTextBlocks(), function(block) {
601
611
                                var listBlock, sibling;
602
612
 
 
613
                                var hasCompatibleStyle = function (sib) {
 
614
                                        var sibStyle = dom.getStyle(sib, 'list-style-type');
 
615
                                        var detailStyle = detail ? detail['list-style-type'] : '';
 
616
 
 
617
                                        detailStyle = detailStyle === null ? '' : detailStyle;
 
618
 
 
619
                                        return sibStyle === detailStyle;
 
620
                                };
 
621
 
603
622
                                sibling = block.previousSibling;
604
 
                                if (sibling && isListNode(sibling) && sibling.nodeName == listName) {
 
623
                                if (sibling && isListNode(sibling) && sibling.nodeName == listName && hasCompatibleStyle(sibling)) {
605
624
                                        listBlock = sibling;
606
625
                                        block = dom.rename(block, listItemName);
607
626
                                        sibling.appendChild(block);
612
631
                                        block = dom.rename(block, listItemName);
613
632
                                }
614
633
 
 
634
                                updateListStyle(listBlock, detail);
615
635
                                mergeWithAdjacentLists(listBlock);
616
636
                        });
617
637
 
618
638
                        moveToBookmark(bookmark);
619
639
                }
620
640
 
 
641
                var updateListStyle = function (el, detail) {
 
642
                        dom.setStyle(el, 'list-style-type', detail ? detail['list-style-type'] : null);
 
643
                };
 
644
 
621
645
                function removeList() {
622
646
                        var bookmark = createBookmark(selection.getRng(true)), root = editor.getBody();
623
647
 
645
669
                        moveToBookmark(bookmark);
646
670
                }
647
671
 
648
 
                function toggleList(listName) {
 
672
                function toggleList(listName, detail) {
649
673
                        var parentList = dom.getParent(selection.getStart(), 'OL,UL,DL');
650
674
 
651
675
                        if (isEditorBody(parentList)) {
657
681
                                        removeList(listName);
658
682
                                } else {
659
683
                                        var bookmark = createBookmark(selection.getRng(true));
 
684
                                        updateListStyle(parentList, detail);
660
685
                                        mergeWithAdjacentLists(dom.rename(parentList, listName));
 
686
 
661
687
                                        moveToBookmark(bookmark);
662
688
                                }
663
689
                        } else {
664
 
                                applyList(listName);
 
690
                                applyList(listName, detail);
665
691
                        }
666
692
                }
667
693
 
819
845
                        }
820
846
                });
821
847
 
822
 
                editor.addCommand('InsertUnorderedList', function() {
823
 
                        toggleList('UL');
824
 
                });
825
 
 
826
 
                editor.addCommand('InsertOrderedList', function() {
827
 
                        toggleList('OL');
828
 
                });
829
 
 
830
 
                editor.addCommand('InsertDefinitionList', function() {
831
 
                        toggleList('DL');
 
848
                editor.addCommand('InsertUnorderedList', function(ui, detail) {
 
849
                        toggleList('UL', detail);
 
850
                });
 
851
 
 
852
                editor.addCommand('InsertOrderedList', function(ui, detail) {
 
853
                        toggleList('OL', detail);
 
854
                });
 
855
 
 
856
                editor.addCommand('InsertDefinitionList', function(ui, detail) {
 
857
                        toggleList('DL', detail);
832
858
                });
833
859
 
834
860
                editor.addQueryStateHandler('InsertUnorderedList', queryListCommandState('UL'));