@@ -723,6 +723,13 @@ angular.module('textAngularSetup', [])
723
723
}
724
724
} ) ;
725
725
726
+ /* istanbul ignore next: if it's javascript don't worry - though probably should show some kind of error message */
727
+ var blockJavascript = function ( link ) {
728
+ if ( link . toLowerCase ( ) . indexOf ( 'javascript' ) !== - 1 ) {
729
+ return true ;
730
+ }
731
+ return false ;
732
+ } ;
726
733
727
734
taRegisterTool ( 'insertImage' , {
728
735
iconclass : 'fa fa-picture-o' ,
@@ -732,22 +739,25 @@ angular.module('textAngularSetup', [])
732
739
imageLink = $window . prompt ( taTranslations . insertImage . dialogPrompt , 'http://' ) ;
733
740
if ( imageLink && imageLink !== '' && imageLink !== 'http://' ) {
734
741
/* 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 ( ) ) ;
742
+ // block javascript here
743
+ if ( ! blockJavascript ( imageLink ) ) {
744
+ if ( taSelection . getSelectionElement ( ) . tagName . toLowerCase ( ) === 'a' ) {
745
+ // due to differences in implementation between FireFox and Chrome, we must move the
746
+ // insertion point past the <a> element, otherwise FireFox inserts inside the <a>
747
+ // With this change, both FireFox and Chrome behave the same way!
748
+ taSelection . setSelectionAfterElement ( taSelection . getSelectionElement ( ) ) ;
749
+ }
750
+ // In the past we used the simple statement:
751
+ //return this.$editor().wrapSelection('insertImage', imageLink, true);
752
+ //
753
+ // However on Firefox only, when the content is empty this is a problem
754
+ // See Issue #1201
755
+ // Investigation reveals that Firefox only inserts a <p> only!!!!
756
+ // So now we use insertHTML here and all is fine.
757
+ // NOTE: this is what 'insertImage' is supposed to do anyway!
758
+ var embed = '<img src="' + imageLink + '">' ;
759
+ return this . $editor ( ) . wrapSelection ( 'insertHTML' , embed , true ) ;
740
760
}
741
- // In the past we used the simple statement:
742
- //return this.$editor().wrapSelection('insertImage', imageLink, true);
743
- //
744
- // However on Firefox only, when the content is empty this is a problem
745
- // See Issue #1201
746
- // Investigation reveals that Firefox only inserts a <p> only!!!!
747
- // So now we use insertHTML here and all is fine.
748
- // NOTE: this is what 'insertImage' is supposed to do anyway!
749
- var embed = '<img src="' + imageLink + '">' ;
750
- return this . $editor ( ) . wrapSelection ( 'insertHTML' , embed , true ) ;
751
761
}
752
762
} ,
753
763
onElementSelect : {
@@ -761,27 +771,32 @@ angular.module('textAngularSetup', [])
761
771
action : function ( ) {
762
772
var urlPrompt ;
763
773
urlPrompt = $window . prompt ( taTranslations . insertVideo . dialogPrompt , 'https://' ) ;
764
- if ( urlPrompt && urlPrompt !== '' && urlPrompt !== 'https://' ) {
774
+ // block javascript here
775
+ /* istanbul ignore else: if it's javascript don't worry - though probably should show some kind of error message */
776
+ if ( ! blockJavascript ( urlPrompt ) ) {
765
777
766
- videoId = taToolFunctions . extractYoutubeVideoId ( urlPrompt ) ;
778
+ if ( urlPrompt && urlPrompt !== '' && urlPrompt !== 'https://' ) {
767
779
768
- /* istanbul ignore else: if it's invalid don't worry - though probably should show some kind of error message */
769
- if ( videoId ) {
770
- // create the embed link
771
- var urlLink = "https://www.youtube.com/embed/" + videoId ;
772
- // create the HTML
773
- // for all options see: http://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
774
- // maxresdefault.jpg seems to be undefined on some.
775
- 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" />' ;
776
- /* istanbul ignore next: don't know how to test this... since it needs a dialogPrompt */
777
- if ( taSelection . getSelectionElement ( ) . tagName . toLowerCase ( ) === 'a' ) {
778
- // due to differences in implementation between FireFox and Chrome, we must move the
779
- // insertion point past the <a> element, otherwise FireFox inserts inside the <a>
780
- // With this change, both FireFox and Chrome behave the same way!
781
- taSelection . setSelectionAfterElement ( taSelection . getSelectionElement ( ) ) ;
780
+ videoId = taToolFunctions . extractYoutubeVideoId ( urlPrompt ) ;
781
+
782
+ /* istanbul ignore else: if it's invalid don't worry - though probably should show some kind of error message */
783
+ if ( videoId ) {
784
+ // create the embed link
785
+ var urlLink = "https://www.youtube.com/embed/" + videoId ;
786
+ // create the HTML
787
+ // for all options see: http://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
788
+ // maxresdefault.jpg seems to be undefined on some.
789
+ 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" />' ;
790
+ /* istanbul ignore next: don't know how to test this... since it needs a dialogPrompt */
791
+ if ( taSelection . getSelectionElement ( ) . tagName . toLowerCase ( ) === 'a' ) {
792
+ // due to differences in implementation between FireFox and Chrome, we must move the
793
+ // insertion point past the <a> element, otherwise FireFox inserts inside the <a>
794
+ // With this change, both FireFox and Chrome behave the same way!
795
+ taSelection . setSelectionAfterElement ( taSelection . getSelectionElement ( ) ) ;
796
+ }
797
+ // insert
798
+ return this . $editor ( ) . wrapSelection ( 'insertHTML' , embed , true ) ;
782
799
}
783
- // insert
784
- return this . $editor ( ) . wrapSelection ( 'insertHTML' , embed , true ) ;
785
800
}
786
801
}
787
802
} ,
@@ -798,7 +813,11 @@ angular.module('textAngularSetup', [])
798
813
var urlLink ;
799
814
urlLink = $window . prompt ( taTranslations . insertLink . dialogPrompt , 'http://' ) ;
800
815
if ( urlLink && urlLink !== '' && urlLink !== 'http://' ) {
801
- return this . $editor ( ) . wrapSelection ( 'createLink' , urlLink , true ) ;
816
+ // block javascript here
817
+ /* istanbul ignore else: if it's javascript don't worry - though probably should show some kind of error message */
818
+ if ( ! blockJavascript ( urlLink ) ) {
819
+ return this . $editor ( ) . wrapSelection ( 'createLink' , urlLink , true ) ;
820
+ }
802
821
}
803
822
} ,
804
823
activeState : function ( commonElement ) {
0 commit comments