Skip to content

Commit

Permalink
show error when something other than an image is inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBesada committed Aug 16, 2012
1 parent 89d7086 commit 0fad8ba
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion assets/css/main.less
Expand Up @@ -467,7 +467,8 @@ body {

&.error {
p {
margin-bottom: 20px
margin-bottom: 20px;
line-height: 1.6em;
}
}

Expand Down
24 changes: 20 additions & 4 deletions assets/js/appflow.coffee
Expand Up @@ -36,20 +36,36 @@ appFlow = (pasteboard) ->
# An image has been inserted
$pasteboard.on "imageinserted.stateevents", (e, eventData) ->
$pasteboard.off ".stateevents"
$modalWindow.off "cancel"
setState ++state, image: eventData.image

# The image that the user is trying to insert is too large
$pasteboard.on "filetoolarge.stateevents", (e, eventData) ->
$pasteboard.on "filetoolarge.stateevents", (e) ->
pasteboard.modalWindow.show("error",
content: "The file size of the image you are trying to
insert exceeds the current limit of
#{pasteboard.fileHandler.getFileSizeLimit() / (1024 * 1024)} MB.
<br><br>Please try another image."
showCancel: true
)
$modalWindow.on "cancel", () ->
$modalWindow.off "cancel"
pasteboard.modalWindow.hide()

# The user tried to insert something other than an image
$pasteboard.on "noimagefound.stateevents", (e, eventData) ->
content = "No image found"
if eventData.paste
content = "No image data was found in your clipboard,
copy an image first (or take a screenshot)."
else if eventData.drop
content = "The object you dragged in is not an image file."

pasteboard.modalWindow.show("error",
content: content
showCancel: true
)

$modalWindow.on "cancel", () ->
pasteboard.modalWindow.hide()


# State 3: User is looking at / editing the image
when states.editingImage
Expand Down
4 changes: 2 additions & 2 deletions assets/js/copyandpaste.coffee
Expand Up @@ -22,7 +22,7 @@ copyAndPaste = (pasteboard) ->
pasteboard.fileHandler.readFile item.getAsFile()
return

pasteboard.noImageError()
$(pasteboard).trigger "noimagefound", paste: true
else
setTimeout parsePaste, 1

Expand All @@ -35,7 +35,7 @@ copyAndPaste = (pasteboard) ->
pasteboard.fileHandler.readData child.src
return

pasteboard.noImageError()
$(pasteboard).trigger "noimagefound", paste: true

focusPasteArea = () ->
pasteArea.focus()
Expand Down
3 changes: 1 addition & 2 deletions assets/js/draganddrop.coffee
Expand Up @@ -28,8 +28,7 @@ dragAndDrop = (pasteboard) ->
pasteboard.fileHandler.readFile file
return

pasteboard.noImageError()

$(pasteboard).trigger "noimagefound", drop: true

self =
isSupported: () -> !!(Modernizr.draganddrop and pasteboard.fileHandler.isSupported())
Expand Down
4 changes: 1 addition & 3 deletions assets/js/main.coffee
Expand Up @@ -8,9 +8,7 @@ window.log = ->
if window.console
window.console.log.apply window.console, arguments

pasteboard =
noImageError: () ->
log "no images found"
pasteboard = {}

window.moduleLoader.loadAll(pasteboard)

Expand Down

0 comments on commit 0fad8ba

Please sign in to comment.