forked from crazystear/Practice01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme_config.php
95 lines (91 loc) · 3.23 KB
/
theme_config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<style>
.typecho-option-submit{
position: fixed !important;
bottom: 10px !important;
right: 30px !important;
}
.typecho-option-submit li{
display: inline;
margin-right: 5px;
}
</style>
<script type="text/javascript" src="https://cdn.staticfile.org/jquery/2.2.1/jquery.min.js"></script>
<script type="text/javascript">
function backData() {
var newLocal= localStorage.backupData;
if (newLocal!= "" && newLocal!= undefined) {
var jsonData = JSON.parse(newLocal);
var data = jsonData;
for(var i in data){
switch (data[i].type) {
case "text":
$('#'+document.getElementsByName(data[i].name)[0].id).val(data[i].value);
break;
case "textarea":
$('#'+document.getElementsByName(data[i].name)[0].id).val(data[i].val);
break;
case "checkbox":
switch (data[i].checked) {
case 'true':
document.getElementById(data[i].id).checked = true;
break;
case 'false':
document.getElementById(data[i].id).checked = false;
break;
}
break;
case "radio":
switch (data[i].checked) {
case 'true':
$('#'+data[i].id).prop("checked","checked");
break;
case 'false':
$('#'+data[i].id).removeAttr("checked");
}
break;
}
}
}
}
function backupData() {
var json = [];
var inputs = $("input");
var textareas = $("textarea");
for (i = 0, len = inputs.length; i < len; i++) {
var j = {};
var input = inputs[i];
j.name = input.name;
j.type = input.type;
j.id = input.id;
switch (input.type){
case "text":
j.value = input.value;
break;
case "radio":
j.checked = ''+input.checked+'';
break;
case "checkbox":
j.checked = ''+input.checked+'';
break;
default:
}
json.push(j);
}
for (i = 0, len = textareas.length; i < len; i++) {
var j = {};
var textarea = textareas[i];
j.name = textarea.name;
j.type = 'textarea';
j.id = textarea.id;
j.val = $('#'+textarea.id).val();
json.push(j);
}
var dataUp = JSON.stringify(json);
localStorage.backupData = dataUp;
alert("主题设置参数已备份!若需要恢复,请使用相同浏览器点击本页右下方的恢复按钮进行恢复!");
}
jQuery(function(){
$(".typecho-option-submit").append("<li><button type=\"button\" class=\"btn primary\" onclick=\"backupData()\">备份</button></li><li><button type=\"button\" class=\"btn primary\" onclick=\"backData()\">恢复</button></li>");
});
</script>