diff --git a/css/glowingbear.css b/css/glowingbear.css index dbb2e55..a6d10d8 100644 --- a/css/glowingbear.css +++ b/css/glowingbear.css @@ -362,16 +362,20 @@ td.time { } #imgur-upload-progress { - display: none; - content: " "; - width: 0%; - height: 5px; + width: 100%; + height: auto; position: absolute; - top: -5px; + bottom: 100%; left: 0; - background: #428BCA; } + .imgur-progress-bar { + width: 0%; + height: 5px; + margin-top: 1px; + background: #428BCA; + } + /* fix for mobile firefox which ignores :hover */ .nav-pills > li > a:active, .nav-pills > li > a:active span { text-decoration: none; diff --git a/directives/input.html b/directives/input.html index 3fbeb64..38a76f7 100644 --- a/directives/input.html +++ b/directives/input.html @@ -5,7 +5,7 @@ diff --git a/js/imgur-drop-directive.js b/js/imgur-drop-directive.js index 6d8ac36..50a4ca9 100644 --- a/js/imgur-drop-directive.js +++ b/js/imgur-drop-directive.js @@ -21,20 +21,25 @@ weechat.directive('imgurDrop', ['connection','imgur', function(connection, imgur e.stopPropagation(); e.preventDefault(); - // Check files length - if (files.length > 0) { - // Sorry only one file - var file = files[0]; + // Send image url after upload + var sendImageUrl = function(imageUrl) { - // Upload to imgur - imgur.process(file, function(imageUrl) { + // Send image + if(imageUrl !== undefined && imageUrl !== '') { + connection.sendMessage(String(imageUrl)); + } - // Send image - if(imageUrl !== undefined && imageUrl !== '') { - connection.sendMessage( String(imageUrl) ); - } + }; + + // Check files + if(typeof files !== "undefined" && files.length > 0) { + + // Loop through files + for (var i = 0; i < files.length; i++) { + // Upload to imgur + imgur.process(files[i], sendImageUrl); + } - }); } }; } diff --git a/js/imgur.js b/js/imgur.js index e2b46f5..a5a0fd0 100644 --- a/js/imgur.js +++ b/js/imgur.js @@ -29,9 +29,16 @@ weechat.factory('imgur', ['$rootScope', function($rootScope) { // Set client ID (Glowing Bear) var clientId = "164efef8979cd4b"; - // Progress bar DOM elment - var progressBar = document.getElementById("imgur-upload-progress"); - progressBar.style.width = '0'; + // Progress bars container + var progressBars = document.getElementById("imgur-upload-progress"), + currentProgressBar = document.createElement("div"); + + // Set progress bar attributes + currentProgressBar.className='imgur-progress-bar'; + currentProgressBar.style.width = '0'; + + // Append progress bar + progressBars.appendChild(currentProgressBar); // Create new form data var fd = new FormData(); @@ -51,7 +58,8 @@ weechat.factory('imgur', ['$rootScope', function($rootScope) { // Handler for response xhttp.onload = function() { - progressBar.style.display = 'none'; + // Remove progress bar + currentProgressBar.parentNode.removeChild(currentProgressBar); // Check state and response status if(xhttp.status === 200) { @@ -87,8 +95,7 @@ weechat.factory('imgur', ['$rootScope', function($rootScope) { var complete = (event.loaded / event.total * 100 | 0); // Set progress bar width - progressBar.style.display = 'block'; - progressBar.style.width = complete + '%'; + currentProgressBar.style.width = complete + '%'; } }; diff --git a/js/inputbar.js b/js/inputbar.js index 09152f5..aa44927 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -70,12 +70,9 @@ weechat.directive('inputBar', function() { }, 0); }; - $scope.uploadImage = function( $event, files ) { - // Get file - var file = files[0]; - - // Process image - imgur.process(file, function(imageUrl) { + $scope.uploadImage = function($event, files) { + // Send image url after upload + var sendImageUrl = function(imageUrl) { // Send image if(imageUrl !== undefined && imageUrl !== '') { @@ -98,10 +95,21 @@ weechat.directive('inputBar', function() { inputNode.focus(); var pos = $scope.command.length - suffix.length; inputNode.setSelectionRange(pos, pos); + // force refresh? + $scope.$apply(); }, 0); } - }); + }; + + if(typeof files !== "undefined" && files.length > 0) { + // Loop through files + for (var i = 0; i < files.length; i++) { + // Process image + imgur.process(files[i], sendImageUrl); + } + + } }; // Send the message to the websocket