9
9
* https://opensource.org/licenses/MIT
10
10
*/
11
11
12
- /* global loadImage, HTMLCanvasElement, $ */
12
+ /* global loadImage, $ */
13
13
14
- $ ( function ( ) {
14
+ $ ( function ( ) {
15
15
'use strict'
16
16
17
17
var result = $ ( '#result' )
@@ -23,13 +23,19 @@ $(function () {
23
23
var coordinates
24
24
var jcropAPI
25
25
26
- function displayTagData ( node , tags ) {
26
+ /**
27
+ * Displays tag data
28
+ *
29
+ * @param {* } node jQuery node
30
+ * @param {object } tags Tags object
31
+ */
32
+ function displayTagData ( node , tags ) {
27
33
var table = node . find ( 'table' ) . empty ( )
28
34
var row = $ ( '<tr></tr>' )
29
35
var cell = $ ( '<td></td>' )
30
36
var prop
31
37
for ( prop in tags ) {
32
- if ( tags . hasOwnProperty ( prop ) ) {
38
+ if ( Object . prototype . hasOwnProperty . call ( tags , prop ) ) {
33
39
table . append (
34
40
row
35
41
. clone ( )
@@ -41,20 +47,32 @@ $(function () {
41
47
node . show ( )
42
48
}
43
49
44
- function displayThumbnailImage ( node , thumbnail , options ) {
50
+ /**
51
+ * Displays the thumbnal image
52
+ *
53
+ * @param {* } node jQuery node
54
+ * @param {string } thumbnail Thumbnail URL
55
+ * @param {object } [options] Options object
56
+ */
57
+ function displayThumbnailImage ( node , thumbnail , options ) {
45
58
if ( thumbnail ) {
46
59
thumbNode . empty ( )
47
60
loadImage (
48
61
thumbnail ,
49
- function ( img ) {
62
+ function ( img ) {
50
63
node . append ( img ) . show ( )
51
64
} ,
52
65
options
53
66
)
54
67
}
55
68
}
56
69
57
- function displayMetaData ( data ) {
70
+ /**
71
+ * Displays meta data
72
+ *
73
+ * @param {object } [data] Meta data object
74
+ */
75
+ function displayMetaData ( data ) {
58
76
if ( ! data ) return
59
77
var exif = data . exif
60
78
var iptc = data . iptc
@@ -69,7 +87,13 @@ $(function () {
69
87
}
70
88
}
71
89
72
- function updateResults ( img , data ) {
90
+ /**
91
+ * Updates the results view
92
+ *
93
+ * @param {* } img Image or canvas element
94
+ * @param {object } [data] Meta data object
95
+ */
96
+ function updateResults ( img , data ) {
73
97
var fileName = currentFile . name
74
98
var href = img . src
75
99
var dataURLStart
@@ -97,7 +121,13 @@ $(function () {
97
121
displayMetaData ( data )
98
122
}
99
123
100
- function displayImage ( file , options ) {
124
+ /**
125
+ * Displays the image
126
+ *
127
+ * @param {File|Blob|string } file File or Blob object or image URL
128
+ * @param {object } [options] Options object
129
+ */
130
+ function displayImage ( file , options ) {
101
131
currentFile = file
102
132
if ( ! loadImage ( file , updateResults , options ) ) {
103
133
result
@@ -112,10 +142,15 @@ $(function () {
112
142
}
113
143
}
114
144
115
- function dropChangeHandler ( e ) {
116
- e . preventDefault ( )
117
- e = e . originalEvent
118
- var target = e . dataTransfer || e . target
145
+ /**
146
+ * Handles drop and file selection change events
147
+ *
148
+ * @param {event } event Drop or file selection change event
149
+ */
150
+ function dropChangeHandler ( event ) {
151
+ event . preventDefault ( )
152
+ var originalEvent = event . originalEvent
153
+ var target = originalEvent . dataTransfer || originalEvent . target
119
154
var file = target && target . files && target . files [ 0 ]
120
155
var options = {
121
156
maxWidth : result . width ( ) ,
@@ -144,21 +179,22 @@ $(function () {
144
179
}
145
180
146
181
$ ( document )
147
- . on ( 'dragover' , function ( e ) {
182
+ . on ( 'dragover' , function ( e ) {
148
183
e . preventDefault ( )
149
- e = e . originalEvent
150
- e . dataTransfer . dropEffect = 'copy'
184
+ var originalEvent = event . originalEvent
185
+ originalEvent . dataTransfer . dropEffect = 'copy'
151
186
} )
152
187
. on ( 'drop' , dropChangeHandler )
153
188
154
189
$ ( '#file-input' ) . on ( 'change' , dropChangeHandler )
155
190
156
- $ ( '#edit' ) . on ( 'click' , function ( event ) {
191
+ $ ( '#edit' ) . on ( 'click' , function ( event ) {
157
192
event . preventDefault ( )
158
193
var imgNode = result . find ( 'img, canvas' )
159
194
var img = imgNode [ 0 ]
160
195
var pixelRatio = window . devicePixelRatio || 1
161
196
imgNode
197
+ // eslint-disable-next-line new-cap
162
198
. Jcrop (
163
199
{
164
200
setSelect : [
@@ -167,24 +203,24 @@ $(function () {
167
203
img . width / pixelRatio - 40 ,
168
204
img . height / pixelRatio - 40
169
205
] ,
170
- onSelect : function ( coords ) {
206
+ onSelect : function ( coords ) {
171
207
coordinates = coords
172
208
} ,
173
- onRelease : function ( ) {
209
+ onRelease : function ( ) {
174
210
coordinates = null
175
211
}
176
212
} ,
177
- function ( ) {
213
+ function ( ) {
178
214
jcropAPI = this
179
215
}
180
216
)
181
217
. parent ( )
182
- . on ( 'click' , function ( event ) {
218
+ . on ( 'click' , function ( event ) {
183
219
event . preventDefault ( )
184
220
} )
185
221
} )
186
222
187
- $ ( '#crop' ) . on ( 'click' , function ( event ) {
223
+ $ ( '#crop' ) . on ( 'click' , function ( event ) {
188
224
event . preventDefault ( )
189
225
var img = result . find ( 'img, canvas' ) [ 0 ]
190
226
var pixelRatio = window . devicePixelRatio || 1
@@ -205,7 +241,7 @@ $(function () {
205
241
}
206
242
} )
207
243
208
- $ ( '#cancel' ) . on ( 'click' , function ( event ) {
244
+ $ ( '#cancel' ) . on ( 'click' , function ( event ) {
209
245
event . preventDefault ( )
210
246
if ( jcropAPI ) {
211
247
jcropAPI . release ( )
0 commit comments