SuperScriptMaterializer/SuperScriptViewer/static/js/viewer.js

159 lines
5.1 KiB
JavaScript
Raw Normal View History

2020-04-18 12:49:48 +08:00
//=======================================settings
currentSettings = {
"plink": true,
"properties": true,
"highlight": true,
"move": true
};
$(document).ready(function () {
//read settings and apply it
for (var key in currentSettings) {
currentSettings[key] = localstorageAssist_Get("ssm-settings-" + key, "true") == "true";
if (currentSettings[key]) $("#sidepanel-display-" + key).prop("checked", true);
else $("#sidepanel-display-" + key).removeProp("checked");
}
//additional settings
if (!currentSettings["plink"]) {
$(".link-elink").hide();
$(".link-plink").hide();
}
// read sidepanel display property
var sidepanelDisplay = localstorageAssist_Get("ssm-settings-sidepanelDisplay", "true") == "true";
if (sidepanelDisplay){
$("#sidepanelContainer").show();
$("#sidepanelToggle").text(">>>");
} else {
$("#sidepanelContainer").hide();
$("#sidepanelToggle").text("<<<");
}
2020-04-18 12:49:48 +08:00
});
function settingChange(target) {
newValue = $("#sidepanel-display-" + target).prop("checked");
currentSettings[target] = newValue;
localstorageAssist_Set("ssm-settings-" + target, newValue);
if (target == "plink") {
if (currentSettings["plink"]) {
$(".link-elink").show();
$(".link-plink").show();
} else {
$(".link-elink").hide();
$(".link-plink").hide();
}
}
}
function sidepanelDisplayChange() {
$("#sidepanelContainer").toggle();
if ($("#sidepanelContainer").is(":hidden")) {
$("#sidepanelToggle").text("<<<");
localstorageAssist_Set("ssm-settings-sidepanelDisplay", false)
} else {
$("#sidepanelToggle").text(">>>");
localstorageAssist_Set("ssm-settings-sidepanelDisplay", true)
}
}
2020-04-18 12:49:48 +08:00
function localstorageAssist_Get(index, defaultValue) {
var cache = localStorage.getItem(index);
if (cache == null) {
localstorageAssist_Set(index, defaultValue);
return defaultValue;
} else return cache;
}
function localstorageAssist_Set(index, value) {
localStorage.setItem(index, value);
}
2020-04-13 09:46:01 +08:00
2020-04-18 12:49:48 +08:00
//=======================================internal event
previousHighlight = "";
2020-04-13 09:46:01 +08:00
function highlightLink(target) {
2020-08-12 15:07:41 +08:00
realTarget = ".target" + target;
2020-04-13 09:46:01 +08:00
if (previousHighlight != "") {
//need restore
2020-04-18 12:49:48 +08:00
$(previousHighlight).each(function () {
2020-04-13 09:46:01 +08:00
if ($(this).hasClass("link-blink")) {
2020-08-12 15:07:41 +08:00
$(this).attr("stroke", "black");
2020-04-13 09:46:01 +08:00
}
if ($(this).hasClass("link-blinkDelay")) {
2020-08-12 15:07:41 +08:00
$(this).attr("fill", "black");
2020-04-13 09:46:01 +08:00
}
if ($(this).hasClass("link-plink")) {
2020-08-12 15:07:41 +08:00
$(this).attr("stroke", "blue");
}
if ($(this).hasClass("link-elink")) {
2020-08-12 15:07:41 +08:00
$(this).attr("stroke", "cyan");
}
2020-04-13 09:46:01 +08:00
});
}
2020-04-13 15:36:37 +08:00
// double one-click, only cancel highlight and don't apply any hightlight
2020-05-02 15:10:08 +08:00
// or user disable hightlight
if ((realTarget == previousHighlight) || !currentSettings["highlight"]) {
2020-04-13 15:36:37 +08:00
previousHighlight = "";
} else {
//apply new highlight
2020-04-18 12:49:48 +08:00
$(realTarget).each(function () {
2020-04-13 15:36:37 +08:00
if ($(this).hasClass("link-blink")) {
2020-08-12 15:07:41 +08:00
$(this).attr("stroke", "yellow");
2020-04-13 15:36:37 +08:00
}
if ($(this).hasClass("link-blinkDelay")) {
2020-08-12 15:07:41 +08:00
$(this).attr("fill", "yellow");
2020-04-13 15:36:37 +08:00
}
if ($(this).hasClass("link-plink")) {
2020-08-12 15:07:41 +08:00
$(this).attr("stroke", "orange");
}
if ($(this).hasClass("link-elink")) {
2020-08-13 15:01:37 +08:00
$(this).attr("stroke", "orangered");
}
2020-04-13 15:36:37 +08:00
});
2020-08-12 15:07:41 +08:00
previousHighlight = realTarget;
2020-04-13 15:36:37 +08:00
}
2020-04-13 09:46:01 +08:00
//cancel event seperate
event.stopPropagation();
}
2020-04-13 12:35:41 +08:00
2020-08-12 12:06:55 +08:00
// type = 0: call from cell
// type = 1: call from bb
function queryInfo(type, obj) {
2020-05-02 15:10:08 +08:00
// confirm user enable this function
if (!currentSettings["properties"])
return;
2020-04-13 12:35:41 +08:00
$.post(window.location,
{
operation: "info",
2020-08-12 12:06:55 +08:00
tag: type,
2020-04-13 12:35:41 +08:00
target: obj
},
2020-04-18 12:49:48 +08:00
function (data, status) {
2020-08-12 15:07:41 +08:00
//set target
$("#sidepanel-properties-target b").text(obj);
2020-04-13 12:35:41 +08:00
//set data
2020-08-12 15:07:41 +08:00
$("#sidepanel-properties-container").empty();
2020-04-13 12:35:41 +08:00
for (var key in data) {
2020-08-12 12:06:55 +08:00
$("#sidepanel-properties-container").append("<div class=\"propertyItem\"></div>");
2020-08-12 15:07:41 +08:00
var box = $("#sidepanel-properties-container div:last");
2020-08-12 12:06:55 +08:00
if (data[key]["is_setting"])
$(box).append("<p><code class=\"propertyItem\">S</code><b></b><i></i></p>");
else
$(box).append("<p><b></b><i></i></p>");
$(box).find("p b").text(data[key]["name"]);
$(box).find("p i").text("(" + key + ")");
for (var i = 0; i < data[key]['data'].length; i++) {
2020-08-12 15:07:41 +08:00
$(box).append("<p></p><pre class=\"propertyItem\"></pre>");
$(box).find("p:last").text(data[key]['data'][i][0]);
$(box).find("pre:last").text(data[key]['data'][i][1]);
2020-08-12 12:06:55 +08:00
}
2020-04-13 12:35:41 +08:00
}
});
}