1
1
$ ( function ( ) {
2
2
$ ( 'body' ) . on ( "change" , "#my-profile-file-selector" , function ( ) {
3
- checkProfileSize ( {
4
- // size: 200,
5
- // width: 1280,
6
- // height: null
7
- } ) ;
3
+ checkProfileSize ( ) ;
8
4
} )
9
5
$ ( '#remove-profile-btn' ) . on ( 'click' , function ( event ) {
10
6
event . preventDefault ( ) ;
@@ -142,6 +138,78 @@ function checkProfileSize1(arg){
142
138
}
143
139
}
144
140
141
+ $ ( function ( ) {
142
+ $ ( 'body' ) . on ( "change" , "#my-profile-file-selector-2" , function ( ) {
143
+ checkProfileSize2 ( {
144
+ width : 1280 ,
145
+ height : 720
146
+ } ) ;
147
+ } )
148
+ $ ( '#remove-profile-btn-2' ) . on ( 'click' , function ( event ) {
149
+ event . preventDefault ( ) ;
150
+ // make image view empty
151
+ $ ( '#upload-profile-image-2' ) . attr ( 'src' , '' ) ;
152
+ // make file name empty
153
+ $ ( '#upload-profile-file-info-2' ) . html ( '' ) ;
154
+ // make input file value empty
155
+ $ ( 'input#my-profile-file-selector-2[type=file]' ) . val ( '' )
156
+ // remove hide button
157
+ $ ( '#remove-profile-btn-2' ) . hide ( ) ;
158
+ // show upload button again
159
+ $ ( 'label.profile-2' ) . show ( ) ;
160
+ } ) ;
161
+ } ) ;
162
+ function checkProfileSize2 ( arg ) {
163
+ $ ( '#upload-profile-image-2' ) . attr ( 'src' , '' ) ;
164
+ $ ( '#upload-profile-file-info-2' ) . html ( '' ) ;
165
+ $ ( '#upload-profile-error-2' ) . html ( '' ) ;
166
+ var fileInput = $ ( 'form' ) . find ( "input#my-profile-file-selector-2[type=file]" ) [ 0 ] ,
167
+ file = fileInput . files && fileInput . files [ 0 ] ;
168
+ var sizeKB = file . size / 1024 ;
169
+ var tmppath = URL . createObjectURL ( fileInput . files [ 0 ] ) ;
170
+ var maxSize = arg . size || sizeKB ;
171
+ var imgHeight , imgWidth ;
172
+ console . log ( "maxSize " + maxSize ) ;
173
+ if ( file ) {
174
+ var img = new Image ( ) ;
175
+ img . src = window . URL . createObjectURL ( file ) ;
176
+ img . onload = function ( ) {
177
+ var width = img . naturalWidth , height = img . naturalHeight ;
178
+ window . URL . revokeObjectURL ( img . src ) ;
179
+ imgWidth = arg . width || width ;
180
+ console . log ( "imgWidth " + imgWidth ) ;
181
+ imgHeight = arg . height || height ;
182
+ if ( sizeKB <= maxSize ) {
183
+ if ( width == imgWidth && height == imgHeight ) {
184
+ var fileName = $ ( 'input#my-profile-file-selector-2[type=file]' ) . val ( ) ;
185
+ fileName = fileName . substr ( fileName . lastIndexOf ( "\\" ) + 1 ) ;
186
+ $ ( '#upload-profile-image-2' ) . attr ( 'src' , tmppath ) ;
187
+ $ ( '#upload-profile-file-info-2' ) . html ( fileName ) ;
188
+ $ ( 'label.profile-2' ) . hide ( ) ;
189
+ $ ( '#remove-profile-btn-2' ) . show ( ) ;
190
+ }
191
+ else {
192
+ imgWidth = arg . width || "any" ;
193
+ imgHeight = arg . height || "any" ;
194
+ $ ( '#upload-profile-error-2' )
195
+ . html ( 'Uploaded Picture Width should be ' +
196
+ imgWidth + ' and Height should be ' + imgHeight ) ;
197
+ var fileName = $ ( 'input#my-profile-file-selector-2[type=file]' ) . val ( ) ;
198
+ console . log ( fileName ) ;
199
+ }
200
+ }
201
+ else {
202
+ $ ( '#upload-profile-error-2' ) . html ( 'Uploaded Profile picture size should be less than ' + maxSize + 'KB' ) ;
203
+ var fileName = $ ( 'input#my-profile-file-selector-2[type=file]' ) . val ( ) ;
204
+ console . log ( fileName ) ;
205
+ }
206
+ } ;
207
+ }
208
+ else { //No file was input or browser doesn't support client side reading
209
+ console . log ( 'No file selected' ) ;
210
+ }
211
+ }
212
+
145
213
146
214
// Copy to Clipboard
147
215
function copyToClipboard ( element ) {
@@ -189,6 +257,19 @@ $(function(){
189
257
placement : 'top'
190
258
} ) ;
191
259
260
+ $ ( '.html-copy-2' ) . tooltip ( {
261
+ trigger : 'click' ,
262
+ placement : 'top'
263
+ } ) ;
264
+ $ ( '.css-copy-2' ) . tooltip ( {
265
+ trigger : 'click' ,
266
+ placement : 'top'
267
+ } ) ;
268
+ $ ( '.js-copy-2' ) . tooltip ( {
269
+ trigger : 'click' ,
270
+ placement : 'top'
271
+ } ) ;
272
+
192
273
$ ( '.html-copy' ) . on ( 'click' , function ( ) {
193
274
copyToClipboard ( '#html-code' ) ;
194
275
setTooltip ( $ ( this ) , 'Copied!' ) ;
@@ -221,5 +302,21 @@ $(function(){
221
302
hideTooltip ( $ ( this ) ) ;
222
303
} ) ;
223
304
305
+ $ ( '.html-copy-2' ) . on ( 'click' , function ( ) {
306
+ copyToClipboard ( '#html-code-2' ) ;
307
+ setTooltip ( $ ( this ) , 'Copied!' ) ;
308
+ hideTooltip ( $ ( this ) ) ;
309
+ } ) ;
310
+ $ ( '.css-copy-2' ) . on ( 'click' , function ( ) {
311
+ copyToClipboard ( '#css-code-2' ) ;
312
+ setTooltip ( $ ( this ) , 'Copied!' ) ;
313
+ hideTooltip ( $ ( this ) ) ;
314
+ } ) ;
315
+ $ ( '.js-copy-2' ) . on ( 'click' , function ( ) {
316
+ copyToClipboard ( '#js-code-2' ) ;
317
+ setTooltip ( $ ( this ) , 'Copied!' ) ;
318
+ hideTooltip ( $ ( this ) ) ;
319
+ } ) ;
320
+
224
321
225
322
} ) ;
0 commit comments