mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
drafts.js: Create initialize() function.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
global.stub_out_jquery();
|
||||
set_global('$', global.make_zjquery());
|
||||
set_global('window', {});
|
||||
|
||||
add_dependencies({
|
||||
localstorage: 'js/localstorage',
|
||||
@@ -128,3 +129,21 @@ var draft_2 = {
|
||||
stub_draft({});
|
||||
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();
|
||||
}());
|
||||
|
||||
@@ -383,14 +383,13 @@ exports.launch = function () {
|
||||
});
|
||||
};
|
||||
|
||||
$(function () {
|
||||
|
||||
exports.initialize = function () {
|
||||
window.addEventListener("beforeunload", function () {
|
||||
exports.update_draft();
|
||||
});
|
||||
|
||||
$("#new_message_content").focusout(exports.update_draft);
|
||||
});
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
|
||||
@@ -259,6 +259,7 @@ $(function () {
|
||||
reactions.initialize();
|
||||
compose_fade.initialize();
|
||||
stream_list.initialize();
|
||||
drafts.initialize();
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user