mirror of https://github.com/zulip/zulip.git
js: Convert static/js/zcommand.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
1a45d53f3a
commit
9dd03998f8
|
@ -304,7 +304,6 @@
|
||||||
"poll_widget": false,
|
"poll_widget": false,
|
||||||
"vdom": false,
|
"vdom": false,
|
||||||
"widgetize": false,
|
"widgetize": false,
|
||||||
"zcommand": false,
|
|
||||||
"zxcvbn": false
|
"zxcvbn": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -75,7 +75,6 @@ document.location.host = "foo.com";
|
||||||
const fake_now = 555;
|
const fake_now = 555;
|
||||||
MockDate.set(new Date(fake_now * 1000));
|
MockDate.set(new Date(fake_now * 1000));
|
||||||
|
|
||||||
zrequire("zcommand");
|
|
||||||
const compose_ui = zrequire("compose_ui");
|
const compose_ui = zrequire("compose_ui");
|
||||||
const peer_data = zrequire("peer_data");
|
const peer_data = zrequire("peer_data");
|
||||||
const util = zrequire("util");
|
const util = zrequire("util");
|
||||||
|
|
|
@ -61,7 +61,6 @@ import "../sent_messages";
|
||||||
import "../compose_state";
|
import "../compose_state";
|
||||||
import "../compose_actions";
|
import "../compose_actions";
|
||||||
import "../transmit";
|
import "../transmit";
|
||||||
import "../zcommand";
|
|
||||||
import "../compose";
|
import "../compose";
|
||||||
import "../upload";
|
import "../upload";
|
||||||
import "../color_data";
|
import "../color_data";
|
||||||
|
|
|
@ -15,6 +15,7 @@ const people = require("./people");
|
||||||
const rendered_markdown = require("./rendered_markdown");
|
const rendered_markdown = require("./rendered_markdown");
|
||||||
const settings_config = require("./settings_config");
|
const settings_config = require("./settings_config");
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
const zcommand = require("./zcommand");
|
||||||
|
|
||||||
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
||||||
|
|
||||||
|
|
|
@ -167,4 +167,3 @@ declare let user_pill: any;
|
||||||
declare let user_status: any;
|
declare let user_status: any;
|
||||||
declare let user_status_ui: any;
|
declare let user_status_ui: any;
|
||||||
declare let widgetize: any;
|
declare let widgetize: any;
|
||||||
declare let zcommand: any;
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
"use strict";
|
import marked from "../third/marked/lib/marked";
|
||||||
|
|
||||||
const marked = require("../third/marked/lib/marked");
|
import * as feedback_widget from "./feedback_widget";
|
||||||
|
|
||||||
const feedback_widget = require("./feedback_widget");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -22,7 +20,7 @@ What in the heck is a zcommand?
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.send = function (opts) {
|
export function send(opts) {
|
||||||
const command = opts.command;
|
const command = opts.command;
|
||||||
const on_success = opts.on_success;
|
const on_success = opts.on_success;
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -38,12 +36,12 @@ exports.send = function (opts) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error() {
|
error() {
|
||||||
exports.tell_user("server did not respond");
|
tell_user("server did not respond");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.tell_user = function (msg) {
|
export function tell_user(msg) {
|
||||||
// This is a bit hacky, but we don't have a super easy API now
|
// This is a bit hacky, but we don't have a super easy API now
|
||||||
// for just telling users stuff.
|
// for just telling users stuff.
|
||||||
$("#compose-send-status")
|
$("#compose-send-status")
|
||||||
|
@ -52,10 +50,10 @@ exports.tell_user = function (msg) {
|
||||||
.stop(true)
|
.stop(true)
|
||||||
.fadeTo(0, 1);
|
.fadeTo(0, 1);
|
||||||
$("#compose-error-msg").text(msg);
|
$("#compose-error-msg").text(msg);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.enter_day_mode = function () {
|
export function enter_day_mode() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/day",
|
command: "/day",
|
||||||
on_success(data) {
|
on_success(data) {
|
||||||
night_mode.disable();
|
night_mode.disable();
|
||||||
|
@ -65,7 +63,7 @@ exports.enter_day_mode = function () {
|
||||||
container.html(rendered_msg);
|
container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/night",
|
command: "/night",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -74,10 +72,10 @@ exports.enter_day_mode = function () {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.enter_night_mode = function () {
|
export function enter_night_mode() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/night",
|
command: "/night",
|
||||||
on_success(data) {
|
on_success(data) {
|
||||||
night_mode.enable();
|
night_mode.enable();
|
||||||
|
@ -87,7 +85,7 @@ exports.enter_night_mode = function () {
|
||||||
container.html(rendered_msg);
|
container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/day",
|
command: "/day",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -96,10 +94,10 @@ exports.enter_night_mode = function () {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.enter_fluid_mode = function () {
|
export function enter_fluid_mode() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/fluid-width",
|
command: "/fluid-width",
|
||||||
on_success(data) {
|
on_success(data) {
|
||||||
scroll_bar.set_layout_width();
|
scroll_bar.set_layout_width();
|
||||||
|
@ -109,7 +107,7 @@ exports.enter_fluid_mode = function () {
|
||||||
container.html(rendered_msg);
|
container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/fixed-width",
|
command: "/fixed-width",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -118,10 +116,10 @@ exports.enter_fluid_mode = function () {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.enter_fixed_mode = function () {
|
export function enter_fixed_mode() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/fixed-width",
|
command: "/fixed-width",
|
||||||
on_success(data) {
|
on_success(data) {
|
||||||
scroll_bar.set_layout_width();
|
scroll_bar.set_layout_width();
|
||||||
|
@ -131,7 +129,7 @@ exports.enter_fixed_mode = function () {
|
||||||
container.html(rendered_msg);
|
container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
exports.send({
|
send({
|
||||||
command: "/fluid-width",
|
command: "/fluid-width",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -140,22 +138,22 @@ exports.enter_fixed_mode = function () {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.process = function (message_content) {
|
export function process(message_content) {
|
||||||
const content = message_content.trim();
|
const content = message_content.trim();
|
||||||
|
|
||||||
if (content === "/ping") {
|
if (content === "/ping") {
|
||||||
const start_time = new Date();
|
const start_time = new Date();
|
||||||
|
|
||||||
exports.send({
|
send({
|
||||||
command: content,
|
command: content,
|
||||||
on_success() {
|
on_success() {
|
||||||
const end_time = new Date();
|
const end_time = new Date();
|
||||||
let diff = end_time - start_time;
|
let diff = end_time - start_time;
|
||||||
diff = Math.round(diff);
|
diff = Math.round(diff);
|
||||||
const msg = "ping time: " + diff + "ms";
|
const msg = "ping time: " + diff + "ms";
|
||||||
exports.tell_user(msg);
|
tell_user(msg);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -163,23 +161,23 @@ exports.process = function (message_content) {
|
||||||
|
|
||||||
const day_commands = ["/day", "/light"];
|
const day_commands = ["/day", "/light"];
|
||||||
if (day_commands.includes(content)) {
|
if (day_commands.includes(content)) {
|
||||||
exports.enter_day_mode();
|
enter_day_mode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const night_commands = ["/night", "/dark"];
|
const night_commands = ["/night", "/dark"];
|
||||||
if (night_commands.includes(content)) {
|
if (night_commands.includes(content)) {
|
||||||
exports.enter_night_mode();
|
enter_night_mode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content === "/fluid-width") {
|
if (content === "/fluid-width") {
|
||||||
exports.enter_fluid_mode();
|
enter_fluid_mode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content === "/fixed-width") {
|
if (content === "/fixed-width") {
|
||||||
exports.enter_fixed_mode();
|
enter_fixed_mode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,6 +190,4 @@ exports.process = function (message_content) {
|
||||||
// if we don't see an actual zcommand, so that compose.js
|
// if we don't see an actual zcommand, so that compose.js
|
||||||
// knows this is a normal message.
|
// knows this is a normal message.
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
window.zcommand = exports;
|
|
||||||
|
|
Loading…
Reference in New Issue