2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2021-02-28 01:15:02 +01:00
|
|
|
import _ from "lodash";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2023-02-02 21:22:40 +01:00
|
|
|
import whale_image from "../images/hotspots/whale.svg";
|
2021-02-28 01:15:02 +01:00
|
|
|
import render_hotspot_icon from "../templates/hotspot_icon.hbs";
|
|
|
|
import render_hotspot_overlay from "../templates/hotspot_overlay.hbs";
|
2020-07-25 02:02:35 +02:00
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 01:15:02 +01:00
|
|
|
import * as channel from "./channel";
|
2023-02-03 14:37:01 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:15:02 +01:00
|
|
|
import * as popovers from "./popovers";
|
2021-02-28 00:39:51 +01:00
|
|
|
|
2017-08-01 00:36:09 +02:00
|
|
|
// popover orientations
|
2020-07-15 01:29:15 +02:00
|
|
|
const TOP = "top";
|
|
|
|
const LEFT = "left";
|
|
|
|
const RIGHT = "right";
|
|
|
|
const BOTTOM = "bottom";
|
|
|
|
const LEFT_BOTTOM = "left_bottom";
|
|
|
|
const VIEWPORT_CENTER = "viewport_center";
|
2017-08-01 00:36:09 +02:00
|
|
|
|
|
|
|
// popover orientation can optionally be fixed here (property: popover),
|
|
|
|
// otherwise popovers.compute_placement is used to compute orientation
|
2020-02-09 04:52:10 +01:00
|
|
|
const HOTSPOT_LOCATIONS = new Map([
|
2020-07-15 00:34:28 +02:00
|
|
|
[
|
|
|
|
"intro_streams",
|
|
|
|
{
|
|
|
|
element: "#streams_header .sidebar-title",
|
|
|
|
offset_x: 1.35,
|
|
|
|
offset_y: 0.39,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"intro_topics",
|
|
|
|
{
|
|
|
|
element: ".topic-name",
|
|
|
|
offset_x: 0.8,
|
|
|
|
offset_y: 0.39,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"intro_gear",
|
|
|
|
{
|
|
|
|
element: "#settings-dropdown",
|
|
|
|
offset_x: -0.4,
|
|
|
|
offset_y: 1.2,
|
|
|
|
popover: LEFT_BOTTOM,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"intro_compose",
|
|
|
|
{
|
|
|
|
element: "#left_bar_compose_stream_button_big",
|
|
|
|
offset_x: 0,
|
|
|
|
offset_y: 0,
|
|
|
|
},
|
|
|
|
],
|
2020-02-09 04:52:10 +01:00
|
|
|
]);
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2023-02-03 14:45:40 +01:00
|
|
|
const meta = {
|
|
|
|
opened_hotspot_name: null,
|
|
|
|
};
|
|
|
|
|
2021-02-28 01:15:02 +01:00
|
|
|
export function post_hotspot_as_read(hotspot_name) {
|
2017-01-24 01:48:35 +01:00
|
|
|
channel.post({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/users/me/hotspots",
|
2021-05-04 09:54:27 +02:00
|
|
|
data: {hotspot: hotspot_name},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(err) {
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.error("Failed to fetch hotspots", {
|
|
|
|
status: err.status,
|
|
|
|
body: err.responseText,
|
|
|
|
});
|
2017-07-14 03:21:30 +02:00
|
|
|
},
|
2017-01-24 01:48:35 +01:00
|
|
|
});
|
2021-02-28 01:15:02 +01:00
|
|
|
}
|
2017-07-14 03:21:30 +02:00
|
|
|
|
|
|
|
function place_icon(hotspot) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $element = $(hotspot.location.element);
|
|
|
|
const $icon = $(`#hotspot_${CSS.escape(hotspot.name)}_icon`);
|
2017-08-31 18:00:51 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
2022-01-25 11:36:19 +01:00
|
|
|
$element.length === 0 ||
|
|
|
|
$element.css("display") === "none" ||
|
|
|
|
!$element.is(":visible") ||
|
|
|
|
$element.is(":hidden")
|
2020-07-15 00:34:28 +02:00
|
|
|
) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$icon.css("display", "none");
|
2017-08-31 04:35:32 +02:00
|
|
|
return false;
|
2017-07-14 03:21:30 +02:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const offset = {
|
2022-01-25 11:36:19 +01:00
|
|
|
top: $element.outerHeight() * hotspot.location.offset_y,
|
|
|
|
left: $element.outerWidth() * hotspot.location.offset_x,
|
2017-08-29 23:07:19 +02:00
|
|
|
};
|
2022-01-25 11:36:19 +01:00
|
|
|
const client_rect = $element.get(0).getBoundingClientRect();
|
2019-11-02 00:06:25 +01:00
|
|
|
const placement = {
|
2017-07-14 03:21:30 +02:00
|
|
|
top: client_rect.top + offset.top,
|
|
|
|
left: client_rect.left + offset.left,
|
|
|
|
};
|
2022-01-25 11:36:19 +01:00
|
|
|
$icon.css("display", "block");
|
|
|
|
$icon.css(placement);
|
2017-08-31 04:35:32 +02:00
|
|
|
return true;
|
2017-01-24 01:48:35 +01:00
|
|
|
}
|
|
|
|
|
2017-07-14 03:21:30 +02:00
|
|
|
function place_popover(hotspot) {
|
|
|
|
if (!hotspot.location.element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 23:23:32 +01:00
|
|
|
const popover_width = $(
|
|
|
|
`#hotspot_${CSS.escape(hotspot.name)}_overlay .hotspot-popover`,
|
|
|
|
).outerWidth();
|
2020-07-15 00:34:28 +02:00
|
|
|
const popover_height = $(
|
2021-02-03 23:23:32 +01:00
|
|
|
`#hotspot_${CSS.escape(hotspot.name)}_overlay .hotspot-popover`,
|
2020-07-15 00:34:28 +02:00
|
|
|
).outerHeight();
|
2019-11-02 00:06:25 +01:00
|
|
|
const el_width = $(hotspot.location.element).outerWidth();
|
|
|
|
const el_height = $(hotspot.location.element).outerHeight();
|
|
|
|
const arrow_offset = 20;
|
2017-07-14 03:21:30 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let popover_offset;
|
|
|
|
let arrow_placement;
|
2020-07-15 00:34:28 +02:00
|
|
|
const orientation =
|
|
|
|
hotspot.location.popover ||
|
2017-08-25 19:59:23 +02:00
|
|
|
popovers.compute_placement(
|
|
|
|
$(hotspot.location.element),
|
|
|
|
popover_height,
|
|
|
|
popover_width,
|
2020-07-02 02:16:03 +02:00
|
|
|
false,
|
2017-08-25 19:59:23 +02:00
|
|
|
);
|
2017-08-01 00:36:09 +02:00
|
|
|
|
|
|
|
switch (orientation) {
|
2020-07-15 02:14:03 +02:00
|
|
|
case TOP:
|
|
|
|
popover_offset = {
|
|
|
|
top: -(popover_height + arrow_offset),
|
|
|
|
left: el_width / 2 - popover_width / 2,
|
|
|
|
};
|
|
|
|
arrow_placement = "bottom";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFT:
|
|
|
|
popover_offset = {
|
|
|
|
top: el_height / 2 - popover_height / 2,
|
|
|
|
left: -(popover_width + arrow_offset),
|
|
|
|
};
|
|
|
|
arrow_placement = "right";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOTTOM:
|
|
|
|
popover_offset = {
|
|
|
|
top: el_height + arrow_offset,
|
|
|
|
left: el_width / 2 - popover_width / 2,
|
|
|
|
};
|
|
|
|
arrow_placement = "top";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIGHT:
|
|
|
|
popover_offset = {
|
|
|
|
top: el_height / 2 - popover_height / 2,
|
|
|
|
left: el_width + arrow_offset,
|
|
|
|
};
|
|
|
|
arrow_placement = "left";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFT_BOTTOM:
|
|
|
|
popover_offset = {
|
|
|
|
top: 0,
|
|
|
|
left: -(popover_width + arrow_offset / 2),
|
|
|
|
};
|
|
|
|
arrow_placement = "";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWPORT_CENTER:
|
|
|
|
popover_offset = {
|
|
|
|
top: el_height / 2,
|
|
|
|
left: el_width / 2,
|
|
|
|
};
|
|
|
|
arrow_placement = "";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.error("Invalid popover placement value for hotspot", {name: hotspot.name});
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2017-07-14 03:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// position arrow
|
2020-07-15 01:29:15 +02:00
|
|
|
arrow_placement = "arrow-" + arrow_placement;
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`#hotspot_${CSS.escape(hotspot.name)}_overlay .hotspot-popover`)
|
2020-07-15 01:29:15 +02:00
|
|
|
.removeClass("arrow-top arrow-left arrow-bottom arrow-right")
|
2017-07-14 03:21:30 +02:00
|
|
|
.addClass(arrow_placement);
|
|
|
|
|
|
|
|
// position popover
|
2019-11-02 00:06:25 +01:00
|
|
|
let popover_placement;
|
2017-08-01 00:36:09 +02:00
|
|
|
if (orientation === VIEWPORT_CENTER) {
|
|
|
|
popover_placement = {
|
2020-07-15 01:29:15 +02:00
|
|
|
top: "45%",
|
|
|
|
left: "50%",
|
|
|
|
transform: "translate(-50%, -50%)",
|
2017-08-01 00:36:09 +02:00
|
|
|
};
|
|
|
|
} else {
|
2019-11-02 00:06:25 +01:00
|
|
|
const client_rect = $(hotspot.location.element).get(0).getBoundingClientRect();
|
2017-08-01 00:36:09 +02:00
|
|
|
popover_placement = {
|
|
|
|
top: client_rect.top + popover_offset.top,
|
|
|
|
left: client_rect.left + popover_offset.left,
|
2020-07-15 01:29:15 +02:00
|
|
|
transform: "",
|
2017-08-01 00:36:09 +02:00
|
|
|
};
|
|
|
|
}
|
2017-07-14 03:21:30 +02:00
|
|
|
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`#hotspot_${CSS.escape(hotspot.name)}_overlay .hotspot-popover`).css(popover_placement);
|
2017-07-14 03:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function insert_hotspot_into_DOM(hotspot) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const hotspot_overlay_HTML = render_hotspot_overlay({
|
2017-07-14 03:21:30 +02:00
|
|
|
name: hotspot.name,
|
|
|
|
title: hotspot.title,
|
|
|
|
description: hotspot.description,
|
2023-02-02 21:22:40 +01:00
|
|
|
img: whale_image,
|
2017-01-24 01:48:35 +01:00
|
|
|
});
|
2017-07-14 03:21:30 +02:00
|
|
|
|
2021-02-03 20:38:31 +01:00
|
|
|
const hotspot_icon_HTML = render_hotspot_icon({
|
|
|
|
name: hotspot.name,
|
|
|
|
});
|
2017-07-14 03:21:30 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").prepend(hotspot_icon_HTML);
|
|
|
|
$("body").prepend(hotspot_overlay_HTML);
|
2017-08-31 04:35:32 +02:00
|
|
|
if (place_icon(hotspot)) {
|
|
|
|
place_popover(hotspot);
|
|
|
|
}
|
2017-07-14 03:21:30 +02:00
|
|
|
|
|
|
|
// reposition on any event that might update the UI
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const event_name of ["resize", "scroll", "onkeydown", "click"]) {
|
2020-07-15 00:34:28 +02:00
|
|
|
window.addEventListener(
|
|
|
|
event_name,
|
|
|
|
_.debounce(() => {
|
|
|
|
if (place_icon(hotspot)) {
|
|
|
|
place_popover(hotspot);
|
|
|
|
}
|
|
|
|
}, 10),
|
|
|
|
true,
|
|
|
|
);
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2018-06-06 18:19:09 +02:00
|
|
|
}, hotspot.delay * 1000);
|
2017-07-14 03:21:30 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:15:02 +01:00
|
|
|
export function is_open() {
|
2023-02-03 14:45:40 +01:00
|
|
|
return meta.opened_hotspot_name !== null;
|
2021-02-28 01:15:02 +01:00
|
|
|
}
|
2017-08-02 04:46:56 +02:00
|
|
|
|
2021-02-28 01:15:02 +01:00
|
|
|
export function close_hotspot_icon(elem) {
|
2020-07-15 00:34:28 +02:00
|
|
|
$(elem).animate(
|
|
|
|
{opacity: 0},
|
|
|
|
{
|
|
|
|
duration: 300,
|
|
|
|
done: function () {
|
|
|
|
$(elem).css({display: "none"});
|
|
|
|
}.bind(elem),
|
|
|
|
},
|
|
|
|
);
|
2021-02-28 01:15:02 +01:00
|
|
|
}
|
2018-03-17 19:35:19 +01:00
|
|
|
|
2018-03-17 19:37:40 +01:00
|
|
|
function close_read_hotspots(new_hotspots) {
|
2020-02-09 04:52:10 +01:00
|
|
|
const unwanted_hotspots = _.difference(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...HOTSPOT_LOCATIONS.keys()],
|
2020-07-02 02:16:03 +02:00
|
|
|
new_hotspots.map((hotspot) => hotspot.name),
|
2020-02-09 04:52:10 +01:00
|
|
|
);
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
|
|
|
|
for (const hotspot_name of unwanted_hotspots) {
|
2021-02-28 01:15:02 +01:00
|
|
|
close_hotspot_icon($(`#hotspot_${CSS.escape(hotspot_name)}_icon`));
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2018-03-17 19:37:40 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:15:02 +01:00
|
|
|
export function load_new(new_hotspots) {
|
2018-03-17 19:37:40 +01:00
|
|
|
close_read_hotspots(new_hotspots);
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const hotspot of new_hotspots) {
|
2020-02-09 04:52:10 +01:00
|
|
|
hotspot.location = HOTSPOT_LOCATIONS.get(hotspot.name);
|
2021-01-22 22:29:08 +01:00
|
|
|
insert_hotspot_into_DOM(hotspot);
|
|
|
|
}
|
2021-02-28 01:15:02 +01:00
|
|
|
}
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2021-02-28 01:15:02 +01:00
|
|
|
export function initialize() {
|
|
|
|
load_new(page_params.hotspots);
|
2023-02-03 14:37:01 +01:00
|
|
|
|
|
|
|
// open
|
|
|
|
$("body").on("click", ".hotspot-icon", function (e) {
|
|
|
|
// hide icon
|
|
|
|
close_hotspot_icon(this);
|
|
|
|
|
|
|
|
// show popover
|
|
|
|
const [, hotspot_name] = /^hotspot_(.*)_icon$/.exec(
|
|
|
|
$(e.target).closest(".hotspot-icon").attr("id"),
|
|
|
|
);
|
|
|
|
const overlay_name = "hotspot_" + hotspot_name + "_overlay";
|
|
|
|
|
|
|
|
overlays.open_overlay({
|
|
|
|
name: overlay_name,
|
|
|
|
$overlay: $(`#${CSS.escape(overlay_name)}`),
|
|
|
|
on_close: function () {
|
|
|
|
// close popover
|
|
|
|
$(this).css({display: "block"});
|
|
|
|
$(this).animate(
|
|
|
|
{opacity: 1},
|
|
|
|
{
|
|
|
|
duration: 300,
|
|
|
|
},
|
|
|
|
);
|
2023-02-03 14:45:40 +01:00
|
|
|
|
|
|
|
meta.opened_hotspot_name = null;
|
2023-02-03 14:37:01 +01:00
|
|
|
}.bind(this),
|
|
|
|
});
|
|
|
|
|
2023-02-03 14:45:40 +01:00
|
|
|
meta.opened_hotspot_name = hotspot_name;
|
2023-02-03 14:37:01 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// confirm
|
|
|
|
$("body").on("click", ".hotspot.overlay .hotspot-confirm", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
const overlay_name = $(this).closest(".hotspot.overlay").attr("id");
|
|
|
|
|
|
|
|
const [, hotspot_name] = /^hotspot_(.*)_overlay$/.exec(overlay_name);
|
|
|
|
|
|
|
|
// Comment below to disable marking hotspots as read in production
|
|
|
|
post_hotspot_as_read(hotspot_name);
|
|
|
|
|
|
|
|
overlays.close_overlay(overlay_name);
|
|
|
|
$(`#hotspot_${CSS.escape(hotspot_name)}_icon`).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
// stop propagation
|
|
|
|
$("body").on("click", ".hotspot.overlay .hotspot-popover", (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2021-02-28 01:15:02 +01:00
|
|
|
}
|