1
package Foswiki::Configure::JS;
5
use vars qw( $js1 $js2 );
15
document.write("<style type='text/css'>");
16
document.write(".foldableBlockClosed {display:none;}");
17
document.write("<\/style>");
26
var lastOpenBlock = null;
27
var lastOpenBlockLink = null;
28
var allBlocks = null; // array of all foldable blocks
29
var allBlockLinks = null; // array of all foldable block links (headers)
31
function foldBlock(id) {
32
var shouldClose = false;
34
if (lastOpenBlock == null) {
35
block = document.getElementById(id);
43
var o = openBlock(id);
44
if (lastOpenBlock != null) {
45
closeBlockElement(lastOpenBlock, lastOpenBlockLink);
48
window.location.hash = id + "link";
51
lastOpenBlock = (lastOpenBlock == o.block) ? null : o.block;
53
if (o && o.blockLink) {
54
lastOpenBlockLink = (lastOpenBlockLink == o.blockLink) ? null : o.blockLink;
58
function openBlock(id) {
59
var block = document.getElementById(id);
60
var blockLink = document.getElementById('blockLink' + id);
61
openBlockElement(block, blockLink);
62
return {block:block, blockLink:blockLink};
65
function openBlockElement(block, blockLink) {
66
var indicator = getElementsByClassName(blockLink, 'blockLinkIndicator')[0];
67
indicator.innerHTML = '▼';
68
block.className = 'foldableBlock foldableBlockOpen';
70
blockLink.className = 'blockLink blockLinkOn';
73
function closeBlock(id) {
74
var block = document.getElementById(id);
75
var blockLink = document.getElementById('blockLink' + id);
76
closeBlockElement(block, blockLink);
77
return {block:block, blockLink:blockLink};
80
function closeBlockElement(block, blockLink) {
81
var indicator = getElementsByClassName(blockLink, 'blockLinkIndicator')[0];
82
indicator.innerHTML = '►';
83
block.className = 'foldableBlock foldableBlockClosed';
85
blockLink.className = 'blockLink blockLinkOff';
88
function toggleAllOptions(open) {
89
if (allBlocks == null) {
90
allBlocks = getElementsByClassName(document, 'foldableBlock');
92
if (allBlockLinks == null) {
93
allBlockLinks = getElementsByClassName(document, 'blockLink');
95
var i, ilen=allBlocks.length;
97
for (i=0; i<ilen; ++i) {
98
openBlockElement(allBlocks[i], allBlockLinks[i]);
101
for (i=0; i<ilen; ++i) {
102
closeBlockElement(allBlocks[i], allBlockLinks[i]);
105
lastOpenBlock = null;
106
lastOpenBlockLink = null;
109
function getElementsByClassName(inRootElem, inClassName, inTag) {
110
var rootElem = inRootElem || document;
111
var tag = inTag || '*';
112
var elms = rootElem.getElementsByTagName(tag);
113
var className = inClassName.replace(/\-/g, "\\-");
114
var re = new RegExp("\\b" + className + "\\b");
116
var hits = new Array();
117
for (var i = 0; i < elms.length; i++) {
119
if (re.test(el.className)) {
126
function addLoadEvent (inFunction, inDoPrepend) {
127
if (typeof(inFunction) != "function") {
130
var oldonload = window.onload;
131
if (typeof window.onload != 'function') {
132
window.onload = function() {
136
var prependFunc = function() {
137
inFunction(); oldonload();
139
var appendFunc = function() {
140
oldonload(); inFunction();
142
window.onload = inDoPrepend ? prependFunc : appendFunc;
146
function initDeltaIndicators() {
147
var elems = getElementsByClassName(document.forms.update, 'delta' , 'SPAN');
148
var i, ilen = elems.length;
149
for (i=0; i<ilen; ++i) {
154
function initDelta(inElem) {
155
var value = replaceStubChars(inElem.title);
156
var type = inElem.className.split(" ")[0];
157
var title = formatLinkValueInTitle(type, "default=", value);
158
inElem.title = title;
161
function initDefaultLinks() {
162
var elems = getElementsByClassName(document.forms.update, 'defaultValueLink' , 'A');
163
var i, ilen = elems.length;
164
for (i=0; i<ilen; ++i) {
165
initDefaultLink(elems[i]);
170
Initializes the 2 states of "reset to default" links.
171
State 1: restore to default
172
State 2: undo restore
174
function initDefaultLink(inLink) {
177
var type = inLink.className.split(" ")[0];
180
// retrieve value from title tag
181
inLink.defaultValue = replaceStubChars(inLink.title);
183
inLink.setDefaultTitle = 'Set to default value:';
184
inLink.undoDefaultTitle = 'Undo default and use previous value:';
185
// set link label states
186
inLink.setDefaultLinkText = 'use default';
187
inLink.undoDefaultLinkText = 'undo';
190
inLink.title = formatLinkValueInTitle(inLink.type, inLink.setDefaultTitle, inLink.defaultValue);
191
inLink.innerHTML = inLink.setDefaultLinkText;
195
Prepend a string to a human readable value string.
197
function formatLinkValueInTitle (inType, inString, inValue) {
198
return (inString + createHumanReadableValueString(inType, inValue));
202
Called from "reset to default" link.
203
Values are set in Value.pm
205
function resetToDefaultValue (inLink, inFormType, inName, inValue) {
207
var name = replaceStubChars(inName);
208
var elem = document.forms.update[name];
211
var value = replaceStubChars(inValue);
212
if (inLink.oldValue != null) value = inLink.oldValue;
215
var type = elem.type;
217
if (type == 'checkbox') {
218
oldValue = elem.checked;
219
elem.checked = value;
220
} else if (type == 'select-one') {
221
// find selected element
223
for (var i=0; i<elem.options.length; ++i) {
224
if (elem.options[i].value == value) {
229
oldValue = elem.options[elem.selectedIndex].value;
230
elem.selectedIndex = index;
231
} else if (type == 'radio') {
232
oldValue = elem.checked;
233
elem.checked = value;
235
// including type='text'
236
oldValue = elem.value;
240
if (inLink.oldValue == null) {
241
// we have just set the default value
243
inLink.innerHTML = inLink.undoDefaultLinkText;
244
inLink.oldValue = oldValue;
245
inLink.title = formatLinkValueInTitle(inLink.type, inLink.undoDefaultTitle, oldValue);
247
// we have just set the old value
248
inLink.innerHTML = inLink.setDefaultLinkText;
249
inLink.oldValue = null;
250
inLink.title = formatLinkValueInTitle(inLink.type, inLink.setDefaultTitle, value);
256
Translates a value to a readable string that makes sense in a form.
257
For instance, 'false' gets translated to 'off' with checkboxes.
274
function createHumanReadableValueString (inType, inValue) {
275
if (inType == 'NUMBER') {
276
// do not convert numbers
279
if (inType == 'BOOLEAN') {
280
if (isTrue(inValue)) {
286
if (inValue.length == 0) {
294
Checks if a value can be considered true.
296
function isTrue (v) {
297
if (v == 1 || v == '1' || v == 'on' || v == 'true') return 1;
302
Replaces stubs for single and double quotes and newlines with the real characters.
304
function replaceStubChars(v) {
307
re = new RegExp(/#26;/g);
308
v = v.replace(re, "'");
310
re = new RegExp(/#22;/g);
311
v = v.replace(re, '"');
312
re = new RegExp(/#13;/g);
313
v = v.replace(re, "\r");
317
addLoadEvent(toggleAllOptions, 0);
318
addLoadEvent(initDeltaIndicators);
319
addLoadEvent(initDefaultLinks);