function initProfile(recips) {
Search.initInpage();
$(".linkify-text").each(function() {
var text = jQuery(this).text();
jQuery(this).html(linkifyWithoutImage(text));
});
$(".linkify-full").each(function() {
$(this).html(buildMsgContent($(this).text(), recips));
});
$('#edit-toggle').click(enableProfileEdit);
activateProfileEditable();
$('.dash-dump .content').each(function() {
var t = $(this);
t.html(buildMsgContent(t.text()));
});
};
function enableProfileEdit() {
$('img#contact').replaceWith('
');
$('img#bio').replaceWith('');
$('#contact, #bio, #avatar').addClass('editable');
$('#avatar-editing').show();
var resetPage = function() { location.reload() };
$('#edit-toggle a').text('done editing').click(resetPage);
activateProfileEditable();
}
function activateProfileEditable() {
var onSubmit = function(attr, newVal, oldVal) {
newVal = $.trim(newVal);
if (newVal == oldVal) { return oldVal };
$.ajax({
type: "POST",
timeout: 5000,
url: "/update-profile",
data: { 'attr': attr, 'val': newVal }
});
if (attr == 'avatar') {
if (newVal != "") {
var s = '
';
$('#avatarPic').replaceWith(s).show();
} else {
$('#avatarPic').hide();
}
}
return escapeHtml(newVal);
};
if ($('#avatar-editing').length > 0)
setupUploadAvatar('uploadp');
var textareaOpts = { 'default_text': 'Enter here!',
'callback': onSubmit,
'field_type': 'textarea',
'callbackShowErrors': false };
$('#contact.editable, #bio.editable')
.editInPlace(textareaOpts)
.each(makePlainText);
}
function setupUploadAvatar(elementId) {
// NOTE: AjaxUpload responses aren't converted from JSON.
var onSubmit = function(file, error) {
$('#spinner').show();
};
var onComplete = function(file, resp) {
$('#spinner').hide();
var r = $.trim(resp);
if (r == 'INVALID_REQUEST') {
location.reload();
} else if (r == 'NOT_LOGGED_IN') {
location.reload();
} else if (r == 'INVALID_IMAGE') {
alert("Sorry, dump.fm can't deal with your image. Pick another :(");
return;
} else if (r.match(/FILE_TOO_BIG/)) {
var maxSize = r.split(" ")[1] / 1024;
alert("Sorry. Your avatar is just too fucking big. "
+ maxSize + "KB or less please.");
return;
} else if (r.match(/INVALID_RESOLUTION/)) {
var maxWidth = r.split(" ")[1];
var maxHeight = r.split(" ")[2];
alert("Sorry, the maximum avatar resolution is "
+ maxWidth + "x" + maxHeight);
return;
}
var s = '
';
$('#dashavatar').html(s).show();
$('#dashtotal').css('background-image', 'url(' + r + ')');
};
new AjaxUpload(elementId, {
action: '/upload/avatar',
autoSubmit: true,
name: 'image',
onSubmit: onSubmit,
onComplete: onComplete
});
}