Skip to content

Commit

Permalink
Moved more JS from .ready to Mailpile.UI.init
Browse files Browse the repository at this point in the history
  • Loading branch information
bnvk committed Oct 24, 2014
1 parent 3995387 commit 14e8e23
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 104 deletions.
60 changes: 0 additions & 60 deletions static/default/html/jsapi/global/drag_drop.js

This file was deleted.

36 changes: 0 additions & 36 deletions static/default/html/jsapi/index-app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* JS App Files */
{% include("jsapi/global/eventlog.js") %}
{% include("jsapi/global/activities.js") %}
{% include("jsapi/global/drag_drop.js") %}
{% include("jsapi/global/global.js") %}
{% include("jsapi/global/keybindings.js") %}
{% include("jsapi/global/notifications.js") %}
Expand Down Expand Up @@ -54,38 +53,3 @@
{% include("jsapi/ui/sidebar.js") %}
{% include("jsapi/ui/tooltips.js") %}


{% set tags_json = mailpile("tags", "display=*", "mode=flat").result.tags|json %}
$(document).ready(function() {

// Print JSON for JS Use
Mailpile.instance['tags'] = {{ tags_json|safe }};

// Favicon
var inbox = _.findWhere(Mailpile.instance.tags, {slug: 'inbox'});
var favicon = new Favico({animation:'popFade'});
favicon.badge(inbox.stats.new);

// Show Typeahead
Mailpile.activities.render_typeahead();

// Start Eventlog
//EventLog.init();
setTimeout(function() {

// make event log start async (e.g. for proper page load event handling)
EventLog.timer = $.timer();
EventLog.timer.set({ time : 22500, autostart : false });
EventLog.poll();

// Run Composer Autosave
if (Mailpile.instance.state.context_url === '/message/' ||
Mailpile.instance.state.context_url === '/message/draft/') {
Mailpile.Composer.AutosaveTimer.play();
Mailpile.Composer.AutosaveTimer.set({ time : 20000, autostart : true });
}

}, 1000);

});

90 changes: 88 additions & 2 deletions static/default/html/jsapi/ui/init.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,100 @@
/* UI */

Mailpile.UI = {
ModalOptions: { backdrop: true, keyboard: true, show: true, remote: false }
ModalOptions: { backdrop: true, keyboard: true, show: true, remote: false },
SidebarDroppableOptions: {
accept: ['td.draggable', 'div.thread-draggable'],
activeClass: 'sidebar-tags-draggable-hover',
hoverClass: 'sidebar-tags-draggable-active',
tolerance: 'pointer',
over: function(event, ui) {
var tid = $(this).find('a').data('tid');
setTimeout(function() {
//Mailpile.ui_sidebar_toggle_subtags(tid, 'open');
}, 500);
},
out: function(event, ui) {
var tid = $(this).find('a').data('tid');
setTimeout(function() {
//Mailpile.ui_sidebar_toggle_subtags(tid, 'close');
}, 1000);
},
drop: function(event, ui) {

var tid = $(this).find('a').data('tid');

// Add MID to Cache
Mailpile.bulk_cache_add('messages_cache', ui.draggable.parent().data('mid'));

// Add / Delete
if (Mailpile.instance.state.command_url == '/message/') {
var tags_delete = ['inbox'];
} else {
var tags_delete = Mailpile.instance.search_tag_ids;
}

Mailpile.API.tag_post({ add: tid, del: tags_delete, mid: Mailpile.messages_cache}, function(result) {

// Show
Mailpile.notification(result);

// Update Pile View
if (Mailpile.instance.state.command_url == '/search/') {
$.each(Mailpile.messages_cache, function(key, mid) {
$('#pile-message-' + mid).fadeOut('fast');
});

// Empty Bulk Cache
Mailpile.messages_cache = [];

// Update Bulk UI
Mailpile.bulk_actions_update_ui();

// Hide Collapsible
Mailpile.ui_sidebar_toggle_subtags(tid, 'close');

} else {
// FIXME: this action is up for discussion
// Github Issue - https://github.com/pagekite/Mailpile/issues/794
window.location.href = '/in/inbox/';
}
});
}
}
};


Mailpile.UI.init = function() {


/* Make search items draggable to sidebar */
$('li.sidebar-tags-draggable').droppable(Mailpile.sidebar_tags_droppable_opts);
$('li.sidebar-tags-draggable').droppable(Mailpile.UI.SidebarDroppableOptions);


// Favicon
var inbox = _.findWhere(Mailpile.instance.tags, {slug: 'inbox'});
var favicon = new Favico({animation:'popFade'});
favicon.badge(inbox.stats.new);

// Show Typeahead
Mailpile.activities.render_typeahead();

// Start Eventlog
//EventLog.init();
setTimeout(function() {

// make event log start async (e.g. for proper page load event handling)
EventLog.timer = $.timer();
EventLog.timer.set({ time : 22500, autostart : false });
EventLog.poll();

// Run Composer Autosave
if (Mailpile.instance.state.context_url === '/message/' ||
Mailpile.instance.state.context_url === '/message/draft/') {
Mailpile.Composer.AutosaveTimer.play();
Mailpile.Composer.AutosaveTimer.set({ time : 20000, autostart : true });
}

}, 1000);

};
11 changes: 5 additions & 6 deletions static/default/html/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
{% if result.data and result.data.metadata %}
{% set metadata_json = result.data.metadata|json %}
{% endif %}
{% set tags_json = mailpile("tags", "display=*", "mode=flat").result.tags|json %}
$(document).ready(function() {

// Start It
Mailpile.render();

// Print JSON for JS Use
Mailpile.instance = {
"command": "{{ command }}",
Expand All @@ -49,9 +47,10 @@
"messages": {% if result.data and result.data.messages %}{{ messages_json|safe }}{% else %}{}{% endif %},
"metadata": {% if result.data and result.data.metadata %}{{ metadata_json|safe }}{% else %}{}{% endif %},
"search_tag_ids": {% if result.search_tag_ids %}{{result.search_tag_ids|safe }}{% else %}[]{% endif %},
"search_addresses": []
"search_addresses": [],
"tags": {{ tags_json|safe }}
};

// Nagifications
{% if show_nagification(config.web.nag_backup_key) %}
Mailpile.notification({
Expand All @@ -70,7 +69,7 @@
$('#notifications-permission-option').click(function() {
Notification.requestPermission();
});

});

/* Plugins */
Expand Down
6 changes: 6 additions & 0 deletions static/default/html/partials/javascript.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!-- Javscript - just a lonely, empty file where there used to be some JS... might reuse -->
<script>
$(document).ready(function() {

// Start It
Mailpile.render();

Mailpile.UI.init();

});
</script>

0 comments on commit 14e8e23

Please sign in to comment.