SuperScriptMaterializer/SuperScriptViewer/static/viewer.js

120 lines
3.6 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();
}
});
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 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) {
realTarget = ".target" + target
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")) {
$(this).attr("stroke", "black")
}
if ($(this).hasClass("link-blinkDelay")) {
$(this).attr("fill", "black")
}
if ($(this).hasClass("link-plink")) {
$(this).attr("stroke", "blue")
}
if ($(this).hasClass("link-elink")) {
$(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")) {
$(this).attr("stroke", "yellow")
}
if ($(this).hasClass("link-blinkDelay")) {
$(this).attr("fill", "yellow")
}
if ($(this).hasClass("link-plink")) {
$(this).attr("stroke", "orange")
}
if ($(this).hasClass("link-elink")) {
$(this).attr("stroke", "orange")
}
2020-04-13 15:36:37 +08:00
});
previousHighlight = realTarget
}
2020-04-13 09:46:01 +08:00
//cancel event seperate
event.stopPropagation();
}
2020-04-13 12:35:41 +08:00
function queryInfo(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",
target: obj
},
2020-04-18 12:49:48 +08:00
function (data, status) {
2020-04-13 12:35:41 +08:00
//set id
2020-04-17 23:31:27 +08:00
$("#sidepanel-properties-id").text(obj);
2020-04-13 12:35:41 +08:00
//set data
2020-04-17 23:31:27 +08:00
$("#sidepanel-properties-container").empty()
2020-04-13 12:35:41 +08:00
for (var key in data) {
2020-04-18 12:49:48 +08:00
$("#sidepanel-properties-container").append("<p><b>" + key + ":</b><br /><pre>" + data[key] + "</pre></p>")
2020-04-13 12:35:41 +08:00
}
});
}