@@ -868,12 +868,46 @@ App.editor.float = function(elem, mode, attr, position, options) {
868868 App . float ( elem , mode , attr , position , options ) ;
869869 } ) ;
870870} ;
871- App . editor . fileInput = function ( elem , options , successCallback , errorCallback ) {
871+ App . editor . detectImageByFileName = function ( fileURL ) {
872+ var dotIndex = fileURL . lastIndexOf ( '.' ) ;
873+ if ( dotIndex < 0 ) {
874+ return false ;
875+ }
876+ var fileExt = fileURL . substring ( dotIndex + 1 ) ;
877+ switch ( fileExt . toLowerCase ( ) ) {
878+ case 'jpg' :
879+ case 'png' :
880+ case 'jpeg' :
881+ case 'gif' :
882+ case 'webp' :
883+ case 'svg' :
884+ case 'bmp' :
885+ case 'ico' :
886+ case 'tiff' :
887+ case 'tif' :
888+ case 'apng' :
889+ case 'avif' :
890+ case 'heic' :
891+ case 'heif' :
892+ case 'jxl' :
893+ case 'jxr' :
894+ case 'pjpeg' :
895+ case 'pjp' :
896+ case 'raw' :
897+ case 'webm' :
898+ case 'wmf' :
899+ return true ;
900+ default :
901+ return false ;
902+ }
903+ } ;
904+ App . editor . fileInput = function ( elem , options , successCallback , errorCallback , imageDetector ) {
872905 if ( ! elem ) {
873906 elem = '' ;
874907 } else {
875908 elem = App . utils . elemToId ( elem ) + ' ' ;
876909 }
910+ if ( ! imageDetector ) imageDetector = App . editor . detectImageByFileName ;
877911 App . loader . defined ( typeof ( $ . fn . powerFloat ) , 'powerFloat' ) ;
878912 App . loader . defined ( typeof ( $ . fn . uploadPreviewer ) , 'uploadPreviewer' ) ;
879913 var changeVal = function ( obj , fileURL ) {
@@ -887,6 +921,7 @@ App.editor.fileInput = function (elem, options, successCallback, errorCallback)
887921 dataInput = $input [ 0 ] ;
888922 }
889923 if ( dataInput ) $ ( dataInput ) . val ( fileURL ) ;
924+ if ( ! imageDetector ( fileURL ) ) fileURL = '' ;
890925 var previewButton = $ ( obj ) . data ( 'preview-btn' ) ;
891926 if ( ! previewButton ) {
892927 previewButton = $parent . siblings ( '.preview-btn' ) [ 0 ] ;
@@ -956,6 +991,7 @@ App.editor.fileInput = function (elem, options, successCallback, errorCallback)
956991 $ ( elem + 'span.preview-btn + input.fileinput-value' ) . on ( 'change' , function ( ) {
957992 var $preview = $ ( this ) . prev ( 'span.preview-btn' ) ;
958993 var val = $ ( this ) . val ( ) ;
994+ if ( ! imageDetector ( val ) ) val = '' ;
959995 if ( val ) {
960996 $preview . removeClass ( 'hidden' ) ;
961997 } else if ( ! $preview . hasClass ( 'hidden' ) ) {
0 commit comments