From cd0ef555b07e042c35a3e24328f7842575309e2c Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 18 Sep 2013 21:11:53 -0700 Subject: [PATCH] Make fallback uploader work --- clientapp/pages/main.js | 15 +++++++++++++-- clientapp/templates.js | 2 +- clientapp/templates/pages/main.jade | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/clientapp/pages/main.js b/clientapp/pages/main.js index 56ff8cc..da3a60f 100644 --- a/clientapp/pages/main.js +++ b/clientapp/pages/main.js @@ -16,7 +16,8 @@ module.exports = BasePage.extend({ events: { 'click .enableAlerts': 'enableAlerts', 'dragover': 'handleAvatarChangeDragOver', - 'drop': 'handleAvatarChange' + 'drop': 'handleAvatarChange', + 'change #uploader': 'handleAvatarChange' }, initialize: function (spec) { me.shouldAskForAlertsPermission = app.notifier.shouldAskPermission(); @@ -38,8 +39,18 @@ module.exports = BasePage.extend({ return false; }, handleAvatarChange: function (e) { + var file; + e.preventDefault(); - var file = e.dataTransfer.files[0]; + + if (e.dataTransfer) { + file = e.dataTransfer.files[0]; + } else if (e.target.files) { + file = e.target.files[0]; + } else { + return; + } + if (file.type.match('image.*')) { console.log('Got an image file!', file.type); var fileTracker = new FileReader(); diff --git a/clientapp/templates.js b/clientapp/templates.js index 3247277..38b8e5b 100644 --- a/clientapp/templates.js +++ b/clientapp/templates.js @@ -131,7 +131,7 @@ exports.pages.groupchat = function anonymous(locals) { exports.pages.main = function anonymous(locals) { var buf = []; with (locals || {}) { - buf.push('

Change Avatar

Drag and drop a new avatar here

This space intentionally blank

'); + buf.push('

Change Avatar

Drag and drop a new avatar here

This space intentionally blank

'); } return buf.join(""); }; diff --git a/clientapp/templates/pages/main.jade b/clientapp/templates/pages/main.jade index f2e299d..d6dd4c8 100644 --- a/clientapp/templates/pages/main.jade +++ b/clientapp/templates/pages/main.jade @@ -5,7 +5,7 @@ section.page.main h1 Change Avatar div.uploadRegion p Drag and drop a new avatar here - img(width="40", height="40") + img form input#uploader(type="file")