Skip to content

Commit f5e9bd4

Browse files
committedJul 9, 2016
Fix(textAngularSetup): bug #1223 InsertImage tool failed on Firefox only. Firefox would insert into the <a> following a link!
This also will fix the same issue with InsertVideo - not reported.
1 parent 1d4c72a commit f5e9bd4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎src/textAngularSetup.js

+14
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,13 @@ angular.module('textAngularSetup', [])
731731
var imageLink;
732732
imageLink = $window.prompt(taTranslations.insertImage.dialogPrompt, 'http://');
733733
if(imageLink && imageLink !== '' && imageLink !== 'http://'){
734+
/* istanbul ignore next: don't know how to test this... since it needs a dialogPrompt */
735+
if (taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
736+
// due to differences in implementation between FireFox and Chrome, we must move the
737+
// insertion point past the <a> element, otherwise FireFox inserts inside the <a>
738+
// With this change, both FireFox and Chrome behave the same way!
739+
taSelection.setSelectionAfterElement(taSelection.getSelectionElement());
740+
}
734741
return this.$editor().wrapSelection('insertImage', imageLink, true);
735742
}
736743
},
@@ -757,6 +764,13 @@ angular.module('textAngularSetup', [])
757764
// for all options see: http://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
758765
// maxresdefault.jpg seems to be undefined on some.
759766
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" />';
767+
/* istanbul ignore next: don't know how to test this... since it needs a dialogPrompt */
768+
if (taSelection.getSelectionElement().tagName.toLowerCase() === 'a') {
769+
// due to differences in implementation between FireFox and Chrome, we must move the
770+
// insertion point past the <a> element, otherwise FireFox inserts inside the <a>
771+
// With this change, both FireFox and Chrome behave the same way!
772+
taSelection.setSelectionAfterElement(taSelection.getSelectionElement());
773+
}
760774
// insert
761775
return this.$editor().wrapSelection('insertHTML', embed, true);
762776
}

0 commit comments

Comments
 (0)