Skip to content

Commit

Permalink
fix(taBind): Fixes paste lists, more lenient stripping of spans.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonC authored and SimeonC committed Oct 23, 2014
1 parent 9fe51ab commit 5ff572f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/textAngular.js
@@ -1,5 +1,5 @@
/*!
textAngular
/*
@license textAngular
Author : Austin Anderson
License : 2013 MIT
Version 1.3.0-pre8
Expand Down Expand Up @@ -1183,7 +1183,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
for(var i = 0; i <= dom[0].childNodes.length; i++){
if(!dom[0].childNodes[i] || dom[0].childNodes[i].nodeName === "#text" || dom[0].childNodes[i].tagName.toLowerCase() !== "p") continue;
var el = angular.element(dom[0].childNodes[i]);
var _listMatch = (el.attr('class') || '').match(/MsoList(Bullet|Number|Paragraph)(|CxSp(First|Middle|Last))/i);
var _listMatch = (el.attr('class') || '').match(/MsoList(Bullet|Number|Paragraph)(CxSp(First|Middle|Last)|)/i);

if(_listMatch){
if(el[0].childNodes.length < 2 || el[0].childNodes[1].childNodes.length < 1){
Expand All @@ -1194,7 +1194,7 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
var _indentMatch = (el.attr('style') || '').match(/margin-left:([\-\.0-9]*)pt/i);
var indent = parseFloat((_indentMatch)?_indentMatch[1]:0);

if (!_listMatch[2] || _listMatch[2].toLowerCase() === "first" || (_list.lastIndent === null && _list.element === null) || (_list.isUl !== isUl && _list.lastIndent === indent)) {
if (!_listMatch[3] || _listMatch[3].toLowerCase() === "first" || (_list.lastIndent === null) || (_list.isUl !== isUl && _list.lastIndent === indent)) {
_list.isUl = isUl;
_list.element = angular.element(isUl ? "<ul>" : "<ol>");
el.after(_list.element);
Expand Down Expand Up @@ -1226,7 +1226,10 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
node.remove();
};

angular.forEach(dom.find('span'), _unwrapElement);
angular.forEach(dom.find('span'), function(node){
node.removeAttribute('lang');
if(node.attributes.length <= 0) _unwrapElement(node);
});
angular.forEach(dom.find('font'), _unwrapElement);
text = dom.html();
}
Expand Down
2 changes: 1 addition & 1 deletion src/textAngularSetup.js
@@ -1,5 +1,5 @@
/*!
textAngular
@license textAngular
Author : Austin Anderson
License : 2013 MIT
Version 1.3.0-pre8
Expand Down
11 changes: 11 additions & 0 deletions test/taBind/taBind.wordPaste.spec.js
Expand Up @@ -103,6 +103,17 @@ describe('taBind.wordPaste', function () {
$rootScope.$digest();
expect(pasted).toBe('<ul><li>Test1</li><li>Test1</li></ul>');
}));

it('subsequent list', inject(function($timeout, taSelection){
element.triggerHandler('paste', {clipboardData: {types: ['text/html'], getData: function(){
return '<p class="MsoListParagraphCxSpFirst" style="text-indent:-18.0pt;mso-list:l1 level1 lfo1"><!--[if !supportLists]--><span lang="EN-US" style="font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><!--[endif]--><span lang="EN-US">no vidisse partiendocomplectitur has. </span></p><p class="MsoListParagraphCxSpLast" style="text-indent:-18.0pt;mso-list:l1 level1 lfo1"><!--[if !supportLists]--><span lang="EN-US" style="font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><!--[endif]--><span lang="EN-US">Te sit iusto viris tibique, nevoluptaria philosophia cum, cum ad vivendum mediocritatem. </span></p><p style="text-indent:18.0pt"><span lang="EN-US"></span></p><p style="text-indent:18.0pt"><span lang="EN-US">Alii mazimsoleat ne sed, dicta putant ad qui. </span></p><p class="MsoListParagraphCxSpFirst" style="margin-left:18.0pt;mso-add-space:auto;text-indent:-18.0pt;mso-list:l0 level1 lfo2"><!--[if !supportLists]--><span lang="EN-US" style="mso-fareast-font-family:Cambria;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:Cambria;mso-bidi-theme-font:minor-latin"><span style="mso-list:Ignore">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><!--[endif]--><span lang="EN-US">Has accusam scriptorem cu, </span></p><p class="MsoListParagraphCxSpLast" style="margin-left:39.6pt;mso-add-space:auto;text-indent:-21.6pt;mso-list:l0 level2 lfo2"><!--[if !supportLists]--><span lang="EN-US" style="mso-fareast-font-family:Cambria;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:Cambria;mso-bidi-theme-font:minor-latin"><span style="mso-list:Ignore">1.1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span lang="EN-US">aliquam complectitur vim ne.</span></p>';// jshint ignore:line
}}});
$timeout.flush();
$rootScope.$digest();
expect(pasted).toBe('<ul><li>no vidisse partiendocomplectitur has. </li><li>Te sit iusto viris tibique, nevoluptaria philosophia cum, cum ad vivendum mediocritatem. </li></ul><p></p><p>Alii mazimsoleat ne sed, dicta putant ad qui. </p><ol><li>Has accusam scriptorem cu, <ol><li>aliquam complectitur vim ne.</li></ol></li></ol>');
}));


// indents - ul > ul, ul > ol, ol > ol, ol > ul

it('ul > ul nested list', inject(function($timeout, taSelection){
Expand Down

0 comments on commit 5ff572f

Please sign in to comment.