drafts.js: Create initialize() function.

This commit is contained in:
Joshua Pan
2017-06-02 14:12:15 -07:00
committed by Tim Abbott
parent 821ff06629
commit bbc0103183
3 changed files with 23 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
global.stub_out_jquery(); set_global('$', global.make_zjquery());
set_global('window', {});
add_dependencies({ add_dependencies({
localstorage: 'js/localstorage', localstorage: 'js/localstorage',
@@ -128,3 +129,21 @@ var draft_2 = {
stub_draft({}); stub_draft({});
assert.equal(drafts.snapshot_message(), undefined); assert.equal(drafts.snapshot_message(), undefined);
}()); }());
(function test_initialize() {
var message_content = $("#new_message_content");
message_content.focusout = function (f) {
assert.equal(f, drafts.update_draft);
f();
};
global.window.addEventListener = function (event_name, f) {
assert.equal(event_name, "beforeunload");
var called = false;
drafts.update_draft = function () { called = true; };
f();
assert(called);
};
drafts.initialize();
}());

View File

@@ -383,14 +383,13 @@ exports.launch = function () {
}); });
}; };
$(function () { exports.initialize = function () {
window.addEventListener("beforeunload", function () { window.addEventListener("beforeunload", function () {
exports.update_draft(); exports.update_draft();
}); });
$("#new_message_content").focusout(exports.update_draft); $("#new_message_content").focusout(exports.update_draft);
}); };
return exports; return exports;

View File

@@ -259,6 +259,7 @@ $(function () {
reactions.initialize(); reactions.initialize();
compose_fade.initialize(); compose_fade.initialize();
stream_list.initialize(); stream_list.initialize();
drafts.initialize();
}); });