Skip to content

Commit

Permalink
fix a upload mask bug
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Aug 25, 2014
1 parent 1e4c111 commit 2c6bb22
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 53 deletions.
19 changes: 8 additions & 11 deletions lib/simditor-all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions lib/simditor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions site/assets/scripts/simditor-all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions src/buttons/image.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ImageButton extends Button
return unless $img.hasClass('uploading')
src = if img then img.src else @defaultImage

@loadImage $img, src, () =>
@loadImage $img, src, =>
@popover.refresh()
@popover.srcEl.val('正在上传...')
.prop('disabled', true)
Expand Down Expand Up @@ -229,20 +229,12 @@ class ImageButton extends Button
$mask = $img.data('mask')
if !$mask
$mask = $('<div class="simditor-image-loading"><span></span></div>')
.hide()
.appendTo(@editor.wrapper)
$mask.addClass('uploading') if $img.hasClass('uploading') and @editor.uploader.html5
$img.data('mask', $mask)
$mask.data('img', $img)

imgPosition = $img.position()
toolbarH = @editor.toolbar.wrapper.outerHeight()
$mask.css({
top: imgPosition.top + toolbarH,
left: imgPosition.left,
width: $img.width(),
height: $img.height()
})

img = new Image()

img.onload = =>
Expand All @@ -263,7 +255,12 @@ class ImageButton extends Button
})

if $img.hasClass 'uploading' # img being uploaded
@editor.body[0].offsetHeight # force reflow
imgPosition = $img.position()
toolbarH = @editor.toolbar.wrapper.outerHeight()
$mask.css({
top: imgPosition.top + toolbarH,
left: imgPosition.left,
width: $img.width(),
height: $img.height()
})
Expand All @@ -289,6 +286,10 @@ class ImageButton extends Button
if $block.is('p') and [email protected] $block
$block = $('<p/>').append(@editor.util.phBr).insertAfter($block)
@editor.selection.setRangeAtStartOf $block, range
#else if $block.is('li')
#$block = @editor.util.furthestNode $block, 'ul, ol'
#$block = $('<p/>').append(@editor.util.phBr).insertAfter($block)
#@editor.selection.setRangeAtStartOf $block, range

$img = $('<img/>').attr('alt', name)
range.insertNode $img[0]
Expand Down
21 changes: 11 additions & 10 deletions src/simditor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,7 @@ class ImageButton extends Button
return unless $img.hasClass('uploading')
src = if img then img.src else @defaultImage

@loadImage $img, src, () =>
@loadImage $img, src, =>
@popover.refresh()
@popover.srcEl.val('正在上传...')
.prop('disabled', true)
Expand Down Expand Up @@ -3022,20 +3022,12 @@ class ImageButton extends Button
$mask = $img.data('mask')
if !$mask
$mask = $('<div class="simditor-image-loading"><span></span></div>')
.hide()
.appendTo(@editor.wrapper)
$mask.addClass('uploading') if $img.hasClass('uploading') and @editor.uploader.html5
$img.data('mask', $mask)
$mask.data('img', $img)

imgPosition = $img.position()
toolbarH = @editor.toolbar.wrapper.outerHeight()
$mask.css({
top: imgPosition.top + toolbarH,
left: imgPosition.left,
width: $img.width(),
height: $img.height()
})

img = new Image()

img.onload = =>
Expand All @@ -3056,7 +3048,12 @@ class ImageButton extends Button
})

if $img.hasClass 'uploading' # img being uploaded
@editor.body[0].offsetHeight # force reflow
imgPosition = $img.position()
toolbarH = @editor.toolbar.wrapper.outerHeight()
$mask.css({
top: imgPosition.top + toolbarH,
left: imgPosition.left,
width: $img.width(),
height: $img.height()
})
Expand All @@ -3082,6 +3079,10 @@ class ImageButton extends Button
if $block.is('p') and [email protected] $block
$block = $('<p/>').append(@editor.util.phBr).insertAfter($block)
@editor.selection.setRangeAtStartOf $block, range
#else if $block.is('li')
#$block = @editor.util.furthestNode $block, 'ul, ol'
#$block = $('<p/>').append(@editor.util.phBr).insertAfter($block)
#@editor.selection.setRangeAtStartOf $block, range

$img = $('<img/>').attr('alt', name)
range.insertNode $img[0]
Expand Down

0 comments on commit 2c6bb22

Please sign in to comment.