mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
Reorganize bootstrap mailbox.js
This commit is contained in:
@@ -4,8 +4,57 @@ var mediumDeviceWidth = 980;
|
|||||||
var messageListMargin = 275;
|
var messageListMargin = 275;
|
||||||
var clipboard = null;
|
var clipboard = null;
|
||||||
|
|
||||||
// onDocChange is called each time we load partials into the DOM
|
// deleteMessage sends a delete request for a message
|
||||||
function onDocChange() {
|
function deleteMessage(id) {
|
||||||
|
$('#message-content').empty();
|
||||||
|
$.ajax({
|
||||||
|
type: 'DELETE',
|
||||||
|
url: '/mailbox/' + mailbox + '/' + id,
|
||||||
|
success: reloadList
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// flashTooltip temporarily changes the text of a tooltip
|
||||||
|
function flashTooltip(el, text) {
|
||||||
|
var prevText = $(el).attr('data-original-title');
|
||||||
|
$(el).attr('data-original-title', text).tooltip('show');
|
||||||
|
$(el).attr('data-original-title', prevText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// htmlView pops open another window for viewing message as HTML
|
||||||
|
function htmlView(id) {
|
||||||
|
window.open('/mailbox/' + mailbox + '/' + id + "/html", '_blank',
|
||||||
|
'width=800,height=600,' +
|
||||||
|
'menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes');
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadList displays the message list for this mailbox
|
||||||
|
function loadList() {
|
||||||
|
$('#message-list').load('/mailbox/' + mailbox, onListLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
// messageSource pops open another window for message source
|
||||||
|
function messageSource(id) {
|
||||||
|
window.open('/mailbox/' + mailbox + '/' + id + "/source", '_blank',
|
||||||
|
'width=800,height=600,' +
|
||||||
|
'menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
|
||||||
|
}
|
||||||
|
|
||||||
|
// reloadList reloads the message list for this mailbox
|
||||||
|
function reloadList() {
|
||||||
|
$('#message-list').hide();
|
||||||
|
loadList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// toggleMessageLink shows/hids the message link URL form
|
||||||
|
function toggleMessageLink(id) {
|
||||||
|
var url = baseURL + '/link/' + mailbox + '/' + id;
|
||||||
|
$('#link-input-control').val(url);
|
||||||
|
$('#link-row').slideToggle();
|
||||||
|
}
|
||||||
|
|
||||||
|
// onDocumentChange is called each time we load partials into the DOM
|
||||||
|
function onDocumentChange() {
|
||||||
// Bootstrap tooltips
|
// Bootstrap tooltips
|
||||||
$('[data-toggle="tooltip"]').tooltip()
|
$('[data-toggle="tooltip"]').tooltip()
|
||||||
|
|
||||||
@@ -23,30 +72,22 @@ function onDocChange() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// flashTooltip temporarily changes the text of a tooltip
|
// onDocumentReady is called by mailbox/index.html to initialize
|
||||||
function flashTooltip(el, text) {
|
function onDocumentReady() {
|
||||||
var prevText = $(el).attr('data-original-title');
|
$("#message-list").hide();
|
||||||
$(el).attr('data-original-title', text).tooltip('show');
|
onWindowResize();
|
||||||
$(el).attr('data-original-title', prevText);
|
$(window).resize(onWindowResize);
|
||||||
|
loadList();
|
||||||
}
|
}
|
||||||
|
|
||||||
function messageLoaded(responseText, textStatus, XMLHttpRequest) {
|
// onListLoaded is called when the message list changes
|
||||||
if (textStatus == "error") {
|
function onListLoaded() {
|
||||||
alert("Failed to load message, server said:\n" + responseText);
|
onDocumentChange();
|
||||||
return;
|
|
||||||
}
|
|
||||||
onDocChange();
|
|
||||||
var top = $('#message-container').offset().top - navBarOffset;
|
|
||||||
$(window).scrollTop(top);
|
|
||||||
}
|
|
||||||
|
|
||||||
function listLoaded() {
|
|
||||||
onDocChange();
|
|
||||||
$('.listEntry').click(
|
$('.listEntry').click(
|
||||||
function() {
|
function() {
|
||||||
$('.listEntry').removeClass("disabled");
|
$('.listEntry').removeClass("disabled");
|
||||||
$(this).addClass("disabled");
|
$(this).addClass("disabled");
|
||||||
$('#message-content').load('/mailbox/' + mailbox + '/' + this.id, messageLoaded);
|
$('#message-content').load('/mailbox/' + mailbox + '/' + this.id, onMessageLoaded);
|
||||||
selected = this.id;
|
selected = this.id;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -57,16 +98,19 @@ function listLoaded() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadList() {
|
// onMessageLoaded is called each time a new message is shown
|
||||||
$('#message-list').load('/mailbox/' + mailbox, listLoaded);
|
function onMessageLoaded(responseText, textStatus, XMLHttpRequest) {
|
||||||
|
if (textStatus == "error") {
|
||||||
|
alert("Failed to load message, server said:\n" + responseText);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onDocumentChange();
|
||||||
|
var top = $('#message-container').offset().top - navBarOffset;
|
||||||
|
$(window).scrollTop(top);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadList() {
|
// onWindowResize handles special cases when window is resized
|
||||||
$('#message-list').hide();
|
function onWindowResize() {
|
||||||
loadList();
|
|
||||||
}
|
|
||||||
|
|
||||||
function windowResize() {
|
|
||||||
if ($(window).width() > mediumDeviceWidth) {
|
if ($(window).width() > mediumDeviceWidth) {
|
||||||
var content_height = $(window).height() - messageListMargin;
|
var content_height = $(window).height() - messageListMargin;
|
||||||
$('#message-list-wrapper').height(content_height).addClass("message-list-scroll");
|
$('#message-list-wrapper').height(content_height).addClass("message-list-scroll");
|
||||||
@@ -75,37 +119,3 @@ function windowResize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function listInit() {
|
|
||||||
$("#message-list").hide();
|
|
||||||
windowResize();
|
|
||||||
$(window).resize(windowResize);
|
|
||||||
loadList();
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteMessage(id) {
|
|
||||||
$('#message-content').empty();
|
|
||||||
$.ajax({
|
|
||||||
type: 'DELETE',
|
|
||||||
url: '/mailbox/' + mailbox + '/' + id,
|
|
||||||
success: reloadList
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function htmlView(id) {
|
|
||||||
window.open('/mailbox/' + mailbox + '/' + id + "/html", '_blank',
|
|
||||||
'width=800,height=600,' +
|
|
||||||
'menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes');
|
|
||||||
}
|
|
||||||
|
|
||||||
function messageSource(id) {
|
|
||||||
window.open('/mailbox/' + mailbox + '/' + id + "/source", '_blank',
|
|
||||||
'width=800,height=600,' +
|
|
||||||
'menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleMessageLink(id) {
|
|
||||||
var url = baseURL + '/link/' + mailbox + '/' + id;
|
|
||||||
$('#link-input-control').val(url);
|
|
||||||
$('#link-row').slideToggle();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ var mailbox = "{{.name}}";
|
|||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#nav-mail').addClass("active");
|
$('#nav-mail').addClass("active");
|
||||||
listInit();
|
onDocumentReady();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
Reference in New Issue
Block a user