Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds a cancel option to the uploader.

  • Loading branch information...
commit 95e6decf9fd1b2a7f705e45b64c210e86cd2c885 1 parent e309854
@jejacks0n authored
View
1  lib/javascripts/mercury/templates/uploader.coffee
@@ -1,6 +1,7 @@
JST['/mercury/templates/uploader'] = ->
"""
<div class="mercury-uploader-dialog">
+ <div class="mercury-uploader-close"><em>&times;</em></div>
<div class="mercury-uploader-preview"><b><img/></b></div>
<div class="mercury-uploader-details"></div>
<div class="mercury-uploader-progress">
View
14 lib/javascripts/mercury/views/uploader.coffee
@@ -17,6 +17,9 @@ class Mercury.Uploader extends Mercury.View
indicator: '.mercury-uploader-indicator div'
percent: '.mercury-uploader-indicator b'
+ @events:
+ 'click .mercury-uploader-close': 'cancel'
+
constructor: (files, @options = {}) ->
return @notify(@t('Is unsupported in this browser')) unless @constructor.supported
super(@options)
@@ -59,6 +62,11 @@ class Mercury.Uploader extends Mercury.View
@delay(50, => @css(opacity: 1))
+ cancel: ->
+ @release()
+ try @xhr.abort()
+
+
release: (ms = 0) ->
@delay ms, ->
@css(opacity: 0)
@@ -70,9 +78,9 @@ class Mercury.Uploader extends Mercury.View
@file = @files.shift()
@update(@t('Uploading...'))
@loadDetails()
- if xhr = @file.save(uploadEvents: @uploadEvents())
- xhr.success => @success()
- xhr.error => @error()
+ if @xhr = @file.save(uploadEvents: @uploadEvents())
+ @xhr.success => @success()
+ @xhr.error => @error()
update: (message, loaded = 0) ->
View
2  lib/stylesheets/mercury/_config.scss
@@ -26,6 +26,8 @@ $uploader_preview_border_color: $dialog_border_color !default;
$uploader_preview_bg: #fff !default;
$uploader_progress_bg: $primary_color !default;
$uploader_progress_color: rgba(255, 255, 255, .8) !default;
+$uploader_close_color: #333 !default;
+$uploader_close_hover_color: #000 !default;
// _lightview
$lightview_overlay_bg: $overlay_bg !default;
View
21 lib/stylesheets/mercury/views/_uploader.scss
@@ -9,6 +9,27 @@ mercury .mercury-uploader {
background: $uploader_overlay_bg;
opacity: 0;
+ .mercury-uploader-close {
+ position: absolute;
+ z-index: 1;
+ top: 12px;
+ right: 9px;
+ text-align: center;
+ em {
+ display: block;
+ width: 20px;
+ border-radius: 20px;
+ background: $uploader_dialog_bg;
+ font-size: 20px;
+ font-style: normal;
+ color: $uploader_close_color;
+ cursor: pointer;
+ &:hover {
+ color: $uploader_close_hover_color;
+ }
+ }
+ }
+
.mercury-uploader-dialog {
@include mercury-border-radius(10px);
@include mercury-border-box();
View
15 spec/mercury/views/uploader_spec.coffee
@@ -144,6 +144,21 @@ describe "Mercury.Uploader", ->
expect( subject.$el.css('opacity') ).to.eq('1')
+ describe "#cancel", ->
+
+ beforeEach ->
+ spyOn(subject, 'release')
+
+ it "calls #release", ->
+ subject.cancel()
+ expect( subject.release ).called
+
+ it "calls abort on the xhr", ->
+ subject.xhr = {abort: spy()}
+ subject.cancel()
+ expect( subject.xhr.abort ).called
+
+
describe "#release", ->
it "delays a given number of milliseconds", ->

0 comments on commit 95e6dec

Please sign in to comment.
Something went wrong with that request. Please try again.