Skip to content

Commit 167938d

Browse files
committed
avoid infinite loop
The following code lead to an infinite loop: ```javascript crop.setImage('/images/storytelling-painting.jpg') crop.setRatio(16/9) ```
1 parent 0b5006a commit 167938d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/crop.coffee

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ module.exports = class Crop
1515
@outlineCssClass = 'crop-outline--active'
1616

1717
# State
18-
@isReady = false
1918
@isPanning = false
2019
@initialCrop = crop
2120

2221
# Events
23-
@readyEvent = $.Callbacks('memory once')
2422
@loadEvent = $.Callbacks()
2523
@changeEvent = $.Callbacks()
2624

25+
# Sets up the ready event and state
26+
@initializeReadyState()
27+
2728
# Confguration
2829
@zoomInStep = zoomStep
2930
@zoomOutStep = 1 / @zoomInStep
@@ -44,11 +45,17 @@ module.exports = class Crop
4445
@setImage(url)
4546

4647

48+
initializeReadyState: ->
49+
@isReady = false
50+
@readyEvent?.empty()
51+
@readyEvent = $.Callbacks('memory once')
52+
53+
4754
setImage: (url) ->
4855
return unless url != @preview.url
4956

5057
@preview.reset() if @isInitialized
51-
@isReady = false
58+
@initializeReadyState()
5259
@view.addClass(@loadingCssClass)
5360
@preview.setImage({ url })
5461

0 commit comments

Comments
 (0)