Convert indention to spaces

paste-quickfix
Lorenz Hübschle-Schneider 10 years ago
parent f2953d1190
commit 3b4f91249f
  1. 159
      js/imgur.js

@ -5,115 +5,114 @@ var weechat = angular.module('weechat');
weechat.factory('imgur', ['$rootScope', function($rootScope) { weechat.factory('imgur', ['$rootScope', function($rootScope) {
var process = function(image, callback) { var process = function(image, callback) {
// Is it an image? // Is it an image?
if (!image || !image.type.match(/image.*/)) return; if (!image || !image.type.match(/image.*/)) return;
// New file reader // New file reader
var reader = new FileReader(); var reader = new FileReader();
// When image is read // When image is read
reader.onload = function (event) { reader.onload = function (event) {
var image = event.target.result.split(',')[1]; var image = event.target.result.split(',')[1];
upload(image, callback); upload(image, callback);
}; };
// Read image as data url // Read image as data url
reader.readAsDataURL(image); reader.readAsDataURL(image);
}; };
// Upload image to imgur from base64
var upload = function( base64img, callback ) {
// Set client ID (Glowing Bear)
var clientId = "164efef8979cd4b";
// Progress bar DOM elment // Upload image to imgur from base64
var progressBar = document.getElementById("imgur-upload-progress"); var upload = function( base64img, callback ) {
progressBar.style.width = '0'; // Set client ID (Glowing Bear)
var clientId = "164efef8979cd4b";
// Create new form data // Progress bar DOM elment
var fd = new FormData(); var progressBar = document.getElementById("imgur-upload-progress");
fd.append("image", base64img); // Append the file progressBar.style.width = '0';
fd.append("type", "base64"); // Set image type to base64
// Create new XMLHttpRequest // Create new form data
var xhttp = new XMLHttpRequest(); var fd = new FormData();
fd.append("image", base64img); // Append the file
fd.append("type", "base64"); // Set image type to base64
// Post request to imgur api // Create new XMLHttpRequest
xhttp.open("POST", "https://api.imgur.com/3/image", true); var xhttp = new XMLHttpRequest();
// Set headers // Post request to imgur api
xhttp.setRequestHeader("Authorization", "Client-ID " + clientId); xhttp.open("POST", "https://api.imgur.com/3/image", true);
xhttp.setRequestHeader("Accept", "application/json");
// Handler for response // Set headers
xhttp.onload = function() { xhttp.setRequestHeader("Authorization", "Client-ID " + clientId);
xhttp.setRequestHeader("Accept", "application/json");
progressBar.style.display = 'none'; // Handler for response
xhttp.onload = function() {
// Check state and response status progressBar.style.display = 'none';
if(xhttp.status === 200) {
// Get response text // Check state and response status
var response = JSON.parse(xhttp.responseText); if(xhttp.status === 200) {
// Send link as message // Get response text
if( response.data && response.data.link ) { var response = JSON.parse(xhttp.responseText);
if (callback && typeof(callback) === "function") { // Send link as message
callback(response.data.link); if( response.data && response.data.link ) {
}
} else { if (callback && typeof(callback) === "function") {
showErrorMsg(); callback(response.data.link);
} }
} else { } else {
showErrorMsg(); showErrorMsg();
} }
}; } else {
showErrorMsg();
}
if( "upload" in xhttp ) { };
// Set progress if( "upload" in xhttp ) {
xhttp.upload.onprogress = function (event) {
// Check if we can compute progress // Set progress
if (event.lengthComputable) { xhttp.upload.onprogress = function (event) {
// Complete in percent
var complete = (event.loaded / event.total * 100 | 0);
// Set progress bar width // Check if we can compute progress
progressBar.style.display = 'block'; if (event.lengthComputable) {
progressBar.style.width = complete + '%'; // Complete in percent
} var complete = (event.loaded / event.total * 100 | 0);
};
} // Set progress bar width
progressBar.style.display = 'block';
progressBar.style.width = complete + '%';
}
};
// Send request with form data }
xhttp.send(fd);
}; // Send request with form data
xhttp.send(fd);
var showErrorMsg = function() { };
// Show error msg
$rootScope.uploadError = true;
$rootScope.$apply();
// Hide after 5 seconds var showErrorMsg = function() {
setTimeout(function(){ // Show error msg
// Hide error msg $rootScope.uploadError = true;
$rootScope.uploadError = false; $rootScope.$apply();
$rootScope.$apply();
}, 5000); // Hide after 5 seconds
}; setTimeout(function(){
// Hide error msg
$rootScope.uploadError = false;
$rootScope.$apply();
}, 5000);
};
return { return {
process: process process: process
}; };

Loading…
Cancel
Save