twister HTML + Javascript User Interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.1 KiB

11 years ago
// interface_profile-edit.js
// 2013 Miguel Freitas
//
// Profile editing interface (profile-edit.html)
var newUserWarnDisplayed = false;
function initProfileEdit() {
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
11 years ago
} else {
alert('The File APIs are not fully supported in this browser.');
11 years ago
}
11 years ago
initInterfaceCommon();
$('.profile-card-photo.forEdition').on('click', function () {$('#avatar-file').trigger('click');});
$('#avatar-file').on('change', handleAvatarFileSelect);
$('.submit-changes').on('click', saveProfile);
$('.cancel-changes').on('click', $.MAL.goHome);
11 years ago
initUser(function() {
if (!defaultScreenName) {
alert(polyglot.t('username_undefined'));
11 years ago
$.MAL.goLogin();
return;
}
checkNetworkStatusAndAskRedirect();
11 years ago
loadFollowing(function() {
twisterFollowingO = TwisterFollowing(defaultScreenName);
verifyUserAlreadyInBlockchain();
initMentionsCount();
initDMsCount();
});
11 years ago
$('.profile-card-main h2').text('@' + defaultScreenName);
11 years ago
loadAvatarForEdit();
loadProfileForEdit();
$('.secret-key-container').hide();
$('.toggle-priv-key').on('click', function () {
if ($('.secret-key-container').is(':visible')) {
$('.secret-key-container').fadeOut(function () {
$('.secret-key').text('');
});
} else {
dumpPrivkey(defaultScreenName, function(args, key) {
$('.secret-key').text(key);
$('.secret-key-container').fadeIn();
}, {});
}
});
11 years ago
});
}
function handleAvatarFileSelect(event) {
var files = event.target.files; // FileList object
var file = files[0];
11 years ago
// Only process image files.
if (file.type.match('image.*')) {
11 years ago
var reader = new FileReader();
reader.onload = function(event) {
var img = new Image();
img.onload = function() {
var MAXWidthHeight = 64;
var ratio = MAXWidthHeight / Math.max(this.width, this.height);
var canvas = document.createElement('canvas');
canvas.width = Math.round(this.width * ratio);
canvas.height = Math.round(this.height * ratio);
canvas.getContext('2d').drawImage(this, 0, 0, canvas.width, canvas.height);
var imgURL = undefined;
for (var quality = 1.0; (!imgURL || imgURL.length > 4096) && quality > 0.1; quality -= 0.01) {
imgURL = canvas.toDataURL('image/jpeg', quality);
}
$('.profile-card-photo.forEdition').attr('src', imgURL);
}
img.src = event.target.result;
11 years ago
}
// Read in the image file as a data URL.
reader.readAsDataURL(file);
11 years ago
}
}
function verifyUserAlreadyInBlockchain() {
$.MAL.disableButton($('.submit-changes'));
11 years ago
dumpPubkey(defaultScreenName, function(args, pubkey) {
if (pubkey.length > 0) {
follow('twister', true, function() {
$.MAL.enableButton($('.submit-changes'));
});
} else {
if (!newUserWarnDisplayed) {
alert(polyglot.t('user_not_yet_accepted'));
newUserWarnDisplayed = true;
}
setTimeout(verifyUserAlreadyInBlockchain, 5000);
}
}, {});
11 years ago
}
10 years ago
function localizePlaceholders() {
$('.input-name').attr('placeholder', polyglot.t('Full name here'));
$('.input-description').attr('placeholder', polyglot.t('Describe yourself'));
$('.input-city').attr('placeholder', polyglot.t('Location'));
$('.input-website').attr('placeholder', polyglot.t('website'));
$('.input-tox').attr('placeholder', polyglot.t('Tox address'));
$('.input-bitmessage').attr('placeholder', polyglot.t('Bitmessage address'));
10 years ago
}
$(localizePlaceholders);