forked from Harvie/DokuWiki-Plugin-SVGEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
126 lines (108 loc) · 3.82 KB
/
script.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var svgeditor_path = 'http://svg-edit.googlecode.com/svn/tags/stable/editor/'; //online stable
//var svgeditor_path = 'http://svg-edit.googlecode.com/svn/trunk/editor/'; //online latest (unstable)
//var svgeditor_path = DOKU_BASE+'lib/plugins/svgedit/svg-edit/'; //offline
//load embedapi.js
var head = document.getElementsByTagName("head")[0];
script = document.createElement('script');
script.type = 'text/javascript';
script.src = svgeditor_path + 'embedapi.js';
head.appendChild(script);
function svgedit_load() {
var field = jQuery('#wiki__text');
if (!field) return;
field = field[0];
var timeout = setTimeout('svgedit_load();', 500); //load ASAP
window.svgedit.setSvgString(field.value) (function(a) {
clearTimeout(timeout);
}
);
}
function svgedit_save(page) {
window.svgedit.getSvgString()(function(data) {
var field = jQuery('#wiki__text');
if (!field) return;
field = field[0];
field.value = data;
if (page) {
field = jQuery('#edbtn__save');
field.click();
}
}) ;
}
function showhide(elem) {
elem.style.display = (elem.style.display == 'none' ? '' : 'none');
}
function insertAfter(newNode, preNode) {
if (preNode.nextSibling)
preNode.parentNode.insertBefore(newNode, preNode.nextSibling);
else
preNode.parentNode(newNode);
}
var svgedit = null;
function svgedit_init() {
var field = jQuery('#wiki__text');
if (!field) return;
field = field[0];
//toggle view
showhide(field);
showhide(jQuery('#tool__bar')[0]);
showhide(jQuery('#edbtn__save')[0]);
//lock
if (jQuery('#svg__edit').length) return;
//create iframe
var el = document.createElement('iframe');
el.setAttribute("src", svgeditor_path + 'svg-editor.html');
el.setAttribute("id", "svg__edit");
el.setAttribute("name", "svg__edit");
el.setAttribute("frameborder", "0");
el.setAttribute("width", "100%");
el.setAttribute("height", "70%");
el.setAttribute("style", "min-height: 600px;");
insertAfter(el, field);
//create save button
field = jQuery('#edbtn__save');
if (!field) return;
field = field[0];
el = document.createElement('input');
el.setAttribute("type", "button");
el.setAttribute("onclick", "svgedit_save(true)");
el.setAttribute("value", "SVG-SAVE");
el.setAttribute("title", "Save SVG to server");
el.setAttribute("class", "button");
field.parentNode.insertBefore(el, field);
el = document.createElement('input');
el.setAttribute("type", "button");
el.setAttribute("onclick", "svgedit_load()");
el.setAttribute("value", "TXT->SVG");
el.setAttribute("title", "Copy SVG from textarea to svg-editor");
el.setAttribute("class", "button");
field.parentNode.insertBefore(el, field);
el = document.createElement('input');
el.setAttribute("type", "button");
el.setAttribute("onclick", "svgedit_save()");
el.setAttribute("value", "SVG->TXT");
el.setAttribute("title", "Copy SVG from svg-editor to textarea");
el.setAttribute("class", "button");
field.parentNode.insertBefore(el, field);
//create embedapi
window.svgedit = new embedded_svg_edit(jQuery('#svg__edit')[0]);
//load image
svgedit_load();
};
jQuery(function() {
if (!jQuery('#wiki__text').length || jQuery('#wiki__text').attr("readOnly")) return;
var field = jQuery('#tool__bar');
if (!field.length) return;
field = field[0];
field.style.float = 'left';
var el = document.createElement('button');
el.setAttribute("id", "TZT");
el.setAttribute("class", "toolbutton");
el.setAttribute("onclick", "svgedit_init();");
el.setAttribute("title", "Edit this page as SVG!");
el.setAttribute("style", "float: left;");
field.parentNode.insertBefore(el, field);
el.appendChild(document.createTextNode("SVG"));
var el = document.createElement('br');
el.setAttribute('style', "clear: left;");
field.appendChild(el);}) ;