@@ -102,6 +102,30 @@ class FileflyEditor extends StringEditor {
102102 this . theme . afterInputReady ( this . input ) ;
103103 }
104104
105+ hasImageExtension ( path ) {
106+ if ( typeof path !== 'string' ) {
107+ throw 'path is not a string!'
108+ }
109+
110+ var imageExtensions = [ 'jpg' , 'jpeg' , 'gif' , 'svg' , 'png' , 'bmp' ]
111+
112+ if ( window . FILEFLYCONFIG && window . FILEFLYCONFIG [ 'imageExtensions' ] ) {
113+ imageExtensions = window . FILEFLYCONFIG [ 'imageExtensions' ]
114+ }
115+
116+ imageExtensions = imageExtensions . map ( extension => {
117+ return extension . toLowerCase ( )
118+ } )
119+
120+ var extension = path . split ( '.' ) . pop ( ) . toLowerCase ( )
121+
122+ return ( imageExtensions . indexOf ( extension ) !== - 1 )
123+ }
124+
125+ hasThumbnailPreview ( item ) {
126+ return this . hasImageExtension ( item . path )
127+ }
128+
105129 initSelectize ( ) {
106130 var self = this ;
107131 this . destroySelectize ( ) ;
@@ -130,16 +154,24 @@ class FileflyEditor extends StringEditor {
130154 persist : true ,
131155 render : {
132156 item : function ( item , escape ) {
133- return '<div class="" style="height: 70px">' +
134- '<img class="pull-left img-responsive" alt="filefly image" style="max-width: 100px; max-height: 70px" src="' + self . ajaxPath + '?action=stream&path=' + ( item . path ) + '" />' +
135- '<span class="">' + escape ( item . path ) + '</span><br/>' +
136- '</div>' ;
157+ if ( self . hasThumbnailPreview ( item ) ) {
158+ return '<div class="" style="height: 70px">' +
159+ '<img class="pull-left img-responsive" alt="filefly image" style="max-width: 100px; max-height: 70px" src="' + self . ajaxPath + '?action=stream&path=' + ( item . path ) + '" />' +
160+ '<span class="">' + escape ( item . path ) + '</span><br/>' +
161+ '</div>' ;
162+ }
163+
164+ return '<span><i class="fa fa-file"></i> ' + escape ( item . path ) + '</span>'
137165 } ,
138166 option : function ( item , escape ) {
139- return '<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2" style="height: 150px">' +
140- '<img class="img-responsive" alt="filefly image" style="max-height: 100px" src="' + self . ajaxPath + '?action=stream&path=' + ( item . path ) + '" />' +
141- '<span class="">' + escape ( item . path ) + '</span>' +
142- '</div>' ;
167+ if ( self . hasThumbnailPreview ( item ) ) {
168+ return '<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2" style="height: 150px">' +
169+ '<img class="img-responsive" alt="filefly image" style="max-height: 100px" src="' + self . ajaxPath + '?action=stream&path=' + ( item . path ) + '" />' +
170+ '<span class="">' + escape ( item . path ) + '</span>' +
171+ '</div>' ;
172+ }
173+
174+ return '<span><i class="fa fa-file"> ' + escape ( item . path ) + '</span>'
143175 }
144176 } ,
145177 onLoad : function ( ) {
0 commit comments