Skip to content

Commit 6dd1556

Browse files
committedOct 2, 2016
fix(console errors caused by #text nodes): from PR #1346 - damien-otis.
1 parent f9715de commit 6dd1556

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed
 

‎src/DOM.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ angular.module('textAngular.DOM', ['textAngular.factories'])
312312
}catch(e){}
313313
//console.log('************** selectedElement:', selectedElement);
314314
var $selected = angular.element(selectedElement);
315-
var tagName = selectedElement.tagName.toLowerCase();
315+
var tagName = (selectedElement.tagName && selectedElement.tagName.toLowerCase()) ||
316+
/* istanbul ignore next: */ "";
316317
if(command.toLowerCase() === 'insertorderedlist' || command.toLowerCase() === 'insertunorderedlist'){
317318
var selfTag = taBrowserTag((command.toLowerCase() === 'insertorderedlist')? 'ol' : 'ul');
318319
var selectedElements = taSelection.getOnlySelectedElements();
@@ -539,7 +540,7 @@ angular.module('textAngular.DOM', ['textAngular.factories'])
539540
return;
540541
}else if(command.toLowerCase() === 'createlink'){
541542
/* istanbul ignore next: firefox specific fix */
542-
if (taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
543+
if (tagName === 'a') {
543544
// already a link!!! we are just replacing it...
544545
taSelection.getSelectionElement().href = options;
545546
return;

‎src/taBind.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
155155
_defaultTest = (_browserDetect.ie === undefined)? '<div><br></div>' : (_browserDetect.ie >= 11)? '<p><br></p>' : (_browserDetect.ie <= 8)? '<P>&nbsp;</P>' : '<p>&nbsp;</p>';
156156
}else{
157157
_defaultVal = (_browserDetect.ie === undefined || _browserDetect.ie >= 11)?
158-
'<' + attrs.taDefaultWrap + '><br></' + attrs.taDefaultWrap + '>' :
158+
(attrs.taDefaultWrap.toLowerCase() === 'br' ? '<BR><BR>' : '<' + attrs.taDefaultWrap + '><br></' + attrs.taDefaultWrap + '>') :
159159
(_browserDetect.ie <= 8)?
160160
'<' + attrs.taDefaultWrap.toUpperCase() + '></' + attrs.taDefaultWrap.toUpperCase() + '>' :
161161
'<' + attrs.taDefaultWrap + '></' + attrs.taDefaultWrap + '>';
162162
_defaultTest = (_browserDetect.ie === undefined || _browserDetect.ie >= 11)?
163-
'<' + attrs.taDefaultWrap + '><br></' + attrs.taDefaultWrap + '>' :
163+
(attrs.taDefaultWrap.toLowerCase() === 'br' ? '<br><br>' : '<' + attrs.taDefaultWrap + '><br></' + attrs.taDefaultWrap + '>') :
164164
(_browserDetect.ie <= 8)?
165165
'<' + attrs.taDefaultWrap.toUpperCase() + '>&nbsp;</' + attrs.taDefaultWrap.toUpperCase() + '>' :
166166
'<' + attrs.taDefaultWrap + '>&nbsp;</' + attrs.taDefaultWrap + '>';
@@ -861,7 +861,7 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
861861
// we ignore any ENTER_ KEYCODE that is anything but plain or a shift one...
862862
} else {
863863
// if enter - insert new taDefaultWrap, if shift+enter insert <br/>
864-
if(_defaultVal !== '' && event.keyCode === _ENTER_KEYCODE && !event.ctrlKey && !event.metaKey && !event.altKey){
864+
if(_defaultVal !== '' && _defaultVal !== '<BR><BR>' && event.keyCode === _ENTER_KEYCODE && !event.ctrlKey && !event.metaKey && !event.altKey){
865865
if(!event.shiftKey){
866866
// new paragraph, br should be caught correctly
867867
var selection = taSelection.getSelectionElement();

‎src/textAngularSetup.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ angular.module('textAngularSetup', [])
829829
/* istanbul ignore next: don't know how to test this... since it needs a dialogPrompt */
830830
// block javascript here
831831
if (!blockJavascript(imageLink)) {
832-
if (taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
832+
if (taSelection.getSelectionElement().tagName && taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
833833
// due to differences in implementation between FireFox and Chrome, we must move the
834834
// insertion point past the <a> element, otherwise FireFox inserts inside the <a>
835835
// With this change, both FireFox and Chrome behave the same way!
@@ -876,7 +876,7 @@ angular.module('textAngularSetup', [])
876876
// maxresdefault.jpg seems to be undefined on some.
877877
var embed = '<img class="ta-insert-video" src="https://img.youtube.com/vi/' + videoId + '/hqdefault.jpg" ta-insert-video="' + urlLink + '" contenteditable="false" allowfullscreen="true" frameborder="0" />';
878878
/* istanbul ignore next: don't know how to test this... since it needs a dialogPrompt */
879-
if (taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
879+
if (taSelection.getSelectionElement().tagName && taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
880880
// due to differences in implementation between FireFox and Chrome, we must move the
881881
// insertion point past the <a> element, otherwise FireFox inserts inside the <a>
882882
// With this change, both FireFox and Chrome behave the same way!
@@ -901,7 +901,7 @@ angular.module('textAngularSetup', [])
901901
var urlLink;
902902
// if this link has already been set, we need to just edit the existing link
903903
/* istanbul ignore if: we do not test this */
904-
if (taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
904+
if (taSelection.getSelectionElement().tagName && taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
905905
urlLink = $window.prompt(taTranslations.insertLink.dialogPrompt, taSelection.getSelectionElement().href);
906906
} else {
907907
urlLink = $window.prompt(taTranslations.insertLink.dialogPrompt, 'http://');

0 commit comments

Comments
 (0)