}
}
+ 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);
}
}
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);
}
}
function indent(li) {
- var sibling, newList;
+ var sibling, newList, listStyle;
function mergeLists(from, to) {
var node;
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);
}
}
- function applyList(listName) {
+ function applyList(listName, detail) {
var rng = selection.getRng(true), bookmark, listItemName = 'LI';
if (dom.getContentEditable(selection.getNode()) === "false") {
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);
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();
moveToBookmark(bookmark);
}
- function toggleList(listName) {
+ function toggleList(listName, detail) {
var parentList = dom.getParent(selection.getStart(), 'OL,UL,DL');
if (isEditorBody(parentList)) {
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);
}
}
}
});
- 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'));