Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List enhancements #587

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 112 additions & 18 deletions src/formats/bbcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,56 @@
},
bulletlist: {
txtExec: function (caller, selected) {
var editor = this;
var content = '';

each(selected.split(/\r?\n/), function () {
content += (content ? '\n' : '') +
'[li]' + this + '[/li]';
});
getEditorCommand('bulletlist')._dropDown(
editor,
caller,
function (listType) {
selected.split(/\r?\n/).forEach(function (item) {
content += (content ? '\n' : '') +
'[li]' + item + '[/li]';
});

this.insertText('[ul]\n' + content + '\n[/ul]');
if (listType === 'disc') {
editor.insertText(
'[ul]\n' + content + '\n[/ul]'
);
} else {
editor.insertText(
'[ul=' + listType + ']\n' + content + '\n[/ul]'
);
}
}
);
}
},
orderedlist: {
txtExec: function (caller, selected) {
var editor = this;
var content = '';

each(selected.split(/\r?\n/), function () {
content += (content ? '\n' : '') +
'[li]' + this + '[/li]';
});
getEditorCommand('orderedlist')._dropDown(
editor,
caller,
function (tagType) {
selected.split(/\r?\n/).forEach(function (item) {
content += (content ? '\n' : '') +
'[li]' + item + '[/li]';
});

this.insertText('[ol]\n' + content + '\n[/ol]');
if (tagType === '1') {
editor.insertText(
'[ol]\n' + content + '\n[/ol]'
);
} else {
editor.insertText(
'[ol=' + tagType + ']\n' + content + '\n[/ol]'
);
}
}
);
}
},
table: {
Expand Down Expand Up @@ -436,14 +466,41 @@

// START_COMMAND: Lists
ul: {
tags: {
ul: null
styles: {
'list-style-type': null
},
breakStart: true,
isInline: false,
skipLastLineBreak: true,
format: '[ul]{0}[/ul]',
html: '<ul>{0}</ul>'
format: function (element, content) {
var tag = element.nodeName.toLowerCase();
var listType = element.style['list-style-type'];
var validTypes = ['disc', 'circle', 'square', 'none'];

// That call is not for this tag, skip it
if (tag !== 'ul') {
return content;
}

if (listType && listType !== 'disc' &&
validTypes.indexOf(listType) > -1) {
return '[ul=' + listType + ']' + content + '[/ul]';
} else {
return '[ul]' + content + '[/ul]';
}
},
html: function (token, attrs, content) {
var listType = 'disc';
var validTypes = ['disc', 'circle', 'square', 'none'];
var attr = attrs.defaultattr;

if (attr && validTypes.indexOf(attr) > -1) {
listType = attr;
}

return '<ul style="list-style-type:' + listType + '">' +
content + '</ul>';
}
},
list: {
breakStart: true,
Expand All @@ -452,14 +509,51 @@
html: '<ul>{0}</ul>'
},
ol: {
tags: {
ol: null
styles: {
'list-style-type': null
},
breakStart: true,
isInline: false,
skipLastLineBreak: true,
format: '[ol]{0}[/ol]',
html: '<ol>{0}</ol>'
format: function (element, content) {
var tag = element.nodeName.toLowerCase();
var tagType = attr(element, 'data-tagtype');
var validTypes = ['1', 'A', 'a', 'I', 'i'];

// That call is not for this tag, skip it
if (tag !== 'ol') {
return content;
}

if (tagType && tagType !== '1' &&
validTypes.indexOf(tagType) > -1) {
return '[ol=' + tagType + ']' + content + '[/ol]';
} else {
return '[ol]' + content + '[/ol]';
}
},
html: function (token, attrs, content) {
var tagType = '1';
var styleType = 'decimal';
var validTypes = ['1', 'A', 'a', 'I', 'i'];
var attr = attrs.defaultattr;

if (attr && validTypes.indexOf(attr) > -1) {
tagType = attr;
}

switch (tagType) {
case '1': styleType = 'decimal'; break;
case 'A': styleType = 'upper-alpha'; break;
case 'a': styleType = 'lower-alpha'; break;
case 'I': styleType = 'upper-roman'; break;
case 'i': styleType = 'lower-roman'; break;
default: styleType = 'decimal'; break;
}

return '<ol style="list-style-type:' + styleType + '" ' +
'data-tagtype="' + tagType + '">' + content + '</ol>';
}
},
li: {
tags: {
Expand Down
58 changes: 56 additions & 2 deletions src/formats/xhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,54 @@
}
},
bulletlist: {
txtExec: ['<ul><li>', '</li></ul>']
txtExec: function (caller, selected) {
var editor = this;
var content = '';

getEditorCommand('bulletlist')._dropDown(
editor,
caller,
function (listType) {
selected.split(/\r?\n/).forEach(function (item) {
content += (content ? '\n' : '') +
'<li>' + item + '</li>';
});

editor.insertText(
'<ul style="list-style-type:' + listType + '">' +
content + '</ul>'
);
}
);
}
},
orderedlist: {
txtExec: ['<ol><li>', '</li></ol>']
txtExec: function (caller, selected) {
var editor = this;
var content = '';

getEditorCommand('orderedlist')._dropDown(
editor,
caller,
function (tagType, styleType) {
selected.split(/\r?\n/).forEach(function (item) {
content += (content ? '\n' : '') +
'<li>' + item + '</li>';
});

if (styleType === 'decimal') {
editor.insertText(
'<ol>' + content + '</ol>'
);
} else {
editor.insertText(
'<ol style="list-style-type:' + styleType +
'">' + content + '</ol>'
);
}
}
);
}
},
table: {
txtExec: ['<table><tr><td>', '</td></tr></table>']
Expand Down Expand Up @@ -1156,6 +1200,16 @@
conv: function (node) {
node.parentNode.removeChild(node);
}
},
{
tags: {
ol: {
'data-tagtype': null
}
},
conv: function (node) {
removeAttr(node, 'data-tagtype');
}
}
];

Expand Down
91 changes: 85 additions & 6 deletions src/lib/defaultCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,97 @@ var defaultCmds = {
// END_COMMAND
// START_COMMAND: Bullet List
bulletlist: {
exec: function () {
fixFirefoxListBug(this);
this.execCommand('insertunorderedlist');
_dropDown: function (editor, caller, callback) {
var content = dom.createElement('div');

dom.on(content, 'click', 'a', function (e) {
callback(dom.data(this, 'type'));
editor.closeDropDown(true);
e.preventDefault();
});

dom.appendChild(content, _tmpl('ulistTypeOpt',
{ type: 'disc', text: 'Bullet' }, true));
dom.appendChild(content, _tmpl('ulistTypeOpt',
{ type: 'circle', text: 'Circle' }, true));
dom.appendChild(content, _tmpl('ulistTypeOpt',
{ type: 'square', text: 'Square' }, true));
dom.appendChild(content, _tmpl('ulistTypeOpt',
{ type: 'none', text: 'None' }, true));

editor.createDropDown(caller, 'listtype-picker', content);
},
exec: function (caller) {
var editor = this;

defaultCmds.bulletlist._dropDown(editor, caller, function (type) {
fixFirefoxListBug(this);
editor.wysiwygEditorInsertHtml(
'<ul style="list-style-type:' + type +
'"><li><br></li></ul>'
);
});
},
tooltip: 'Bullet list'
},
// END_COMMAND
// START_COMMAND: Ordered List
orderedlist: {
exec: function () {
fixFirefoxListBug(this);
this.execCommand('insertorderedlist');
_dropDown: function (editor, caller, callback) {
var content = dom.createElement('div');

dom.on(content, 'click', 'a', function (e) {
callback(dom.data(this, 'tagtype'),
dom.data(this, 'styletype'));
editor.closeDropDown(true);
e.preventDefault();
});

dom.appendChild(content, _tmpl('olistTypeOpt',
{
tagType: '1',
styleType: 'decimal',
text: 'Decimal numbers (1, 2, 3, 4)'
}, true));
dom.appendChild(content, _tmpl('olistTypeOpt',
{
tagType: 'a',
styleType: 'lower-alpha',
text: 'Alphabetic lowercase (a, b, c, d)'
}, true));
dom.appendChild(content, _tmpl('olistTypeOpt',
{
tagType: 'A',
styleType: 'upper-alpha',
text: 'Alphabetic uppercase (A, B, C, D)'
}, true));
dom.appendChild(content, _tmpl('olistTypeOpt',
{
tagType: 'i',
styleType: 'lower-roman',
text: 'Roman lowercase (i, ii, iii, iv)'
}, true));
dom.appendChild(content, _tmpl('olistTypeOpt',
{
tagType: 'I',
styleType: 'upper-roman',
text: 'Roman uppercase (I, II, III, IV)'
}, true));

editor.createDropDown(caller, 'listtype-picker', content);
},
exec: function (caller) {
var editor = this;

defaultCmds.orderedlist._dropDown(editor, caller,
function (tagType, styleType) {
fixFirefoxListBug(this);
editor.wysiwygEditorInsertHtml(
'<ol style="list-style-type:' + styleType +
'" data-tagtype="' + tagType + '"><li><br></li></ol>'
);
}
);
},
tooltip: 'Numbered list'
},
Expand Down
10 changes: 10 additions & 0 deletions src/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ var _templates = {
sizeOpt: '<a class="sceditor-fontsize-option" data-size="{size}" ' +
'href="#"><font size="{size}">{size}</font></a>',

ulistTypeOpt: '<a class="sceditor-listtype-option" data-type="{type}" ' +
'href="#">' +
'<ul style="list-style-type:{type}" ' +
'class="sceditor-listtype"><li>' +
'{text}</li></ul></a>',

olistTypeOpt: '<a class="sceditor-listtype-option" ' +
'data-styletype="{styleType}" data-tagtype="{tagType}" ' +
'href="#">{text}</a>',

pastetext:
'<div><label for="txt">{label}</label> ' +
'<textarea cols="20" rows="7" id="txt"></textarea></div>' +
Expand Down
Loading