SuperScriptMaterializer/SuperScriptViewer/static/site.js

148 lines
4.5 KiB
JavaScript
Raw Normal View History

2020-04-18 12:49:48 +08:00
//=======================================settings
currentSettings = {
"plink": true,
"properties": true,
"highlight": true,
"keyboard": 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
if (realTarget == previousHighlight) {
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) {
$.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
}
});
}
2020-04-17 23:31:27 +08:00
function sidePanelSwitcher(target) {
// 0->property; 1->display; 2->tools
//disable all
$("#sidepanel-properties").hide();
$("#sidepanel-display").hide();
$("#sidepanel-tools").hide();
2020-04-18 12:49:48 +08:00
$(".tabitem").each(function () {
2020-04-17 23:31:27 +08:00
$(this).removeClass("tabitem-activated").addClass("tabitem-deactivated");
});
switch (target) {
case 0:
$("#sidepanel-properties").show();
2020-04-18 12:49:48 +08:00
$(".tabitem1").each(function () {
2020-04-17 23:31:27 +08:00
$(this).removeClass("tabitem-deactivated").addClass("tabitem-activated");
});
break;
case 1:
$("#sidepanel-display").show();
2020-04-18 12:49:48 +08:00
$(".tabitem2").each(function () {
2020-04-17 23:31:27 +08:00
$(this).removeClass("tabitem-deactivated").addClass("tabitem-activated");
});
break;
case 2:
$("#sidepanel-tools").show();
2020-04-18 12:49:48 +08:00
$(".tabitem3").each(function () {
2020-04-17 23:31:27 +08:00
$(this).removeClass("tabitem-deactivated").addClass("tabitem-activated");
});
break;
}
2020-04-13 12:35:41 +08:00
}