[extensions-web] js: Clean up uploader
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] js: Clean up uploader
- Date: Mon, 2 Apr 2012 14:54:40 +0000 (UTC)
commit 7af16ed144c9602558d69c6edc0cb35fde248185
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Apr 2 09:57:27 2012 -0400
js: Clean up uploader
sweettooth/static/js/uploader.js | 32 +++++++++++---------------------
1 files changed, 11 insertions(+), 21 deletions(-)
---
diff --git a/sweettooth/static/js/uploader.js b/sweettooth/static/js/uploader.js
index 18c0638..b99414f 100644
--- a/sweettooth/static/js/uploader.js
+++ b/sweettooth/static/js/uploader.js
@@ -5,8 +5,6 @@ define(['jquery'], function($) {
$.fn.uploadify = function(url) {
var $elem = $(this), $input = $elem.find('input');
- if ($elem.data('uploader'))
- return;
var BOUNDARY = ' -- 598275094719306587185414';
// Stolen from http://demos.hacks.mozilla.org/openweb/imageUploader/js/extends/xhr.js
@@ -20,14 +18,14 @@ define(['jquery'], function($) {
return body;
}
- function upload(e) {
- function uploadComplete(result) {
- var $old = $elem.children().first();
- var $img = $('<img>', { 'src': result });
- $img.replaceAll($old);
- $elem.removeClass('placeholder');
- }
+ function uploadComplete(result) {
+ var $old = $elem.children().first();
+ var $img = $('<img>', { 'src': result });
+ $img.replaceAll($old);
+ $elem.removeClass('placeholder');
+ }
+ $input.on('change', function(e) {
var dt, file;
if (e.originalEvent.dataTransfer)
dt = e.originalEvent.dataTransfer;
@@ -65,20 +63,12 @@ define(['jquery'], function($) {
return false;
}
- var inClick = false;
- $elem.on('click', function() {
- // Prevent the handler from running twice from bubbling.
- if (inClick)
- return;
+ $elem.on('click', function(e) {
+ var bubbledFromInput = $input.index(e.target) >= 0;
+ if (!bubbledFromInput)
+ $input.get(0).click();
- inClick = true;
- $input[0].click();
- inClick = false;
return false;
});
-
- $input.on('change', upload);
-
- $elem.data('uploader', true);
};
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]