Skip to content

Commit

Permalink
fix(taExecCommand): Fix List conversion bug.
Browse files Browse the repository at this point in the history
Fixes #399
  • Loading branch information
SimeonC authored and SimeonC committed Nov 27, 2014
1 parent f9d7e42 commit d97842c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/textAngular.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/DOM.js
Expand Up @@ -99,6 +99,8 @@ angular.module('textAngular.DOM', ['textAngular.factories'])
if(_nodes[i].tagName.toLowerCase() === 'li') continue;
else if(_nodes[i].tagName.toLowerCase() === 'ol' || _nodes[i].tagName.toLowerCase() === 'ul'){
html += $n[0].innerHTML; // if it's a list, add all it's children
}else if(_nodes[i].tagName.toLowerCase() === 'span' && (_nodes[i].childNodes[0].tagName.toLowerCase() === 'ol' || _nodes[i].childNodes[0].tagName.toLowerCase() === 'ul')){
html += $n[0].childNodes[0].innerHTML; // if it's a list, add all it's children
}else{
html += '<' + taBrowserTag('li') + '>' + $n[0].innerHTML + '</' + taBrowserTag('li') + '>';
}
Expand Down
2 changes: 2 additions & 0 deletions src/textAngular.js
Expand Up @@ -382,6 +382,8 @@ angular.module('textAngular.DOM', ['textAngular.factories'])
if(_nodes[i].tagName.toLowerCase() === 'li') continue;
else if(_nodes[i].tagName.toLowerCase() === 'ol' || _nodes[i].tagName.toLowerCase() === 'ul'){
html += $n[0].innerHTML; // if it's a list, add all it's children
}else if(_nodes[i].tagName.toLowerCase() === 'span' && (_nodes[i].childNodes[0].tagName.toLowerCase() === 'ol' || _nodes[i].childNodes[0].tagName.toLowerCase() === 'ul')){
html += $n[0].childNodes[0].innerHTML; // if it's a list, add all it's children
}else{
html += '<' + taBrowserTag('li') + '>' + $n[0].innerHTML + '</' + taBrowserTag('li') + '>';
}
Expand Down
30 changes: 29 additions & 1 deletion test/taExecCommand/taExecCommand.lists.spec.js
Expand Up @@ -181,7 +181,7 @@ describe('taExecCommand', function(){
}));
});
});
describe('list to other', function(){
describe('list to other/list', function(){
var element;
describe('li selected', function(){
it('from ol', inject(function(taSelection, taExecCommand){
Expand All @@ -198,6 +198,34 @@ describe('taExecCommand', function(){
}));
});
describe('list selected', function(){
describe('edge mixed case', function(){
it('to ol', inject(function(taSelection, taExecCommand){
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><span><ul><li>To the List!</li></ul></span></div>');
taSelection.element = element[0];
taExecCommand()('insertorderedlist', false, null);
expect(element.html()).toBe('<ol><li>To the List!</li><li>To the List!</li></ol>');
}));
it('to ul', inject(function(taSelection, taExecCommand){
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><span><ul><li>To the List!</li></ul></span></div>');
taSelection.element = element[0];
taExecCommand()('insertunorderedlist', false, null);
expect(element.html()).toBe('<ul><li>To the List!</li><li>To the List!</li></ul>');
}));
});
describe('mixed as child of ta-bind', function(){
it('to ol', inject(function(taSelection, taExecCommand){
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><ul><li>To the List!</li></ul></div>');
taSelection.element = element[0];
taExecCommand()('insertorderedlist', false, null);
expect(element.html()).toBe('<ol><li>To the List!</li><li>To the List!</li></ol>');
}));
it('to ul', inject(function(taSelection, taExecCommand){
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><ul><li>To the List!</li></ul></div>');
taSelection.element = element[0];
taExecCommand()('insertunorderedlist', false, null);
expect(element.html()).toBe('<ul><li>To the List!</li><li>To the List!</li></ul>');
}));
});
describe('from ol', function(){
describe('as child of ta-bind', function(){
it('to default', inject(function(taSelection, taExecCommand){
Expand Down

0 comments on commit d97842c

Please sign in to comment.