1<?php
2/**
3 * DokuWiki Default Template
4 *
5 * This is the template you need to change for the overall look
6 * of DokuWiki.
7 *
8 * You should leave the doctype at the very top - It should
9 * always be the very first line of a document.
10 *
11 * @link   http://wiki.splitbrain.org/wiki:tpl:templates
12 * @author Andreas Gohr <andi@splitbrain.org>
13 */
14
15// must be run from within DokuWiki
16if (!defined('DOKU_INC')) die();
17
18if (plugin_isdisabled('npd') || !($npd =& plugin_load('helper', 'npd'))) {
19    die();
20}
21$conf['template'] = $conf['template_original'];
22
23?>
24<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
25 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
26<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $conf['lang']?>"
27 lang="<?php echo $conf['lang']?>" dir="<?php echo $lang['direction']?>">
28<head>
29  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
30  <title>
31    <?php tpl_pagetitle()?>
32    [<?php echo strip_tags($conf['title'])?>]
33  </title>
34
35  <?php tpl_metaheaders()?>
36<script type="text/javascript" language="javascript" charset="utf-8">
37//<![CDATA[
38
39// This is variable for storing callback function
40var ae_cb = null;
41
42// this is a simple function-shortcut
43// to avoid using lengthy document.getElementById
44function ae$(a) { return document.getElementById(a); }
45
46// This is a main ae_prompt function
47// it saves function callback
48// and sets up dialog
49function ae_prompt(cb, q, a) {
50    ae_cb = cb;
51    ae$('aep_t').innerHTML = '&nbsp;';//document.domain + ' question:';
52    ae$('aep_prompt').innerHTML = q;
53    ae$('aep_text').value = a;
54    ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = '';
55    ae$('aep_text').focus();
56    ae$('aep_text').select();
57}
58
59// This function is called when user presses OK(m=0) or Cancel(m=1) button
60// in the dialog. You should not call this function directly.
61function ae_clk(m) {
62    // hide dialog layers
63    ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = 'none';
64    if (!m)
65        ae_cb(null);  // user pressed cancel, call callback with null
66    else
67        ae_cb(ae$('aep_text').value); // user pressed OK
68}
69
70new_folders = new Array();
71addInitEvent(init_index);
72function firstDescendant(element)
73{
74    element = element.firstChild;
75    while (element && element.nodeType != 1) element = element.nextSibling;
76    return element;
77}
78function getEventElement(e)
79{
80    if (typeof e.srcElement != 'undefined') {
81        var node = e.srcElement;
82    } else {
83        var node = e.target;
84    }
85    if (node.nodeType == 3) {
86        node = node.parentNode();
87    }
88    return node;
89}
90function npd_cancel(e)
91{
92    stop_event(e);
93    window.close();
94}
95function npd_save(e)
96{
97    stop_event(e);
98    var page_name = $('npd_page_name').value;
99    var default_page_name = $('npd_page_name').defaultValue;
100    if (page_name == default_page_name) {
101        var answer = confirm('<?php echo htmlspecialchars($npd->getLang("dlg_confirm_page_name")); ?>'+page_name);
102        if (!answer) return;
103    }
104    opener.location.href = "doku.php?do=edit&id=" + $('npd_ns').value + ":" + page_name;
105    window.close();
106}
107function npd_new_folder(e)
108{
109    stop_event(e);
110    ae_prompt(npd_new_folder_cb, "<?php echo str_replace(array("\n", "\r"), " ", $npd->locale_xhtml('dialog_folder_name')); ?>", "Untitled");
111}
112function npd_new_folder_cb(folder_name)
113{
114    if (! folder_name) {
115        return;
116    }
117    folder_name = escapeHTML(folder_name).replace(/^\s*|\s*$/g,"");
118
119    var node = active.parentNode;
120    active.className = "idx_dir";
121
122    node = node.nextSibling;
123    while (node && node.nodeType != 1) node = node.nextSibling;
124
125    if (!node) {
126        // there is no UL yet, create it
127        node = document.createElement("ul");
128        node.className = 'idx';
129        active.parentNode.parentNode.appendChild(node);
130    }
131
132    var npd_ns = $('npd_ns');
133    var ns = npd_ns.value.replace(/:*$/,'') + ":" + folder_name;
134    npd_ns.value = ns;
135
136    // prepare new node
137    var folder = document.createElement('li');
138    folder.innerHTML = '<div class="li"><a class="idx_dir active" href="'+ns+'" ref="'+ns+'"><strong>' + folder_name + '</strong></a><a class="edit">[edit]</a></div><ul class="idx"/>';
139    folder.className = 'new';
140
141    child = firstDescendant(node);
142    if (child) {
143        node.insertBefore(folder, child);
144    } else {
145        node.appendChild(folder);
146    }
147    active = firstDescendant(firstDescendant(folder));
148    addEvent(active, "click", new_folder_click);
149
150    var edit = active.nextSibling;
151    while (edit && edit.nodeType != 1) edit = edit.nextSibling;
152
153    new_folders.push(active);
154
155    addEvent(edit, "click", edit_folder_name);
156
157}
158function edit_folder_name(e)
159{
160    var link = getEventElement(e);
161    if ((typeof link.href) == 'undefined') {
162        // was a link clicked, or its content
163        link = link.parentNode;
164    }
165    stop_event(e);
166    folder = firstDescendant(link.parentNode);
167    text_node = firstDescendant(folder);
168    ae_prompt(edit_folder_name_cb, "<?php echo htmlspecialchars($npd->getLang('dlg_new_folder')); ?>", text_node.innerHTML);
169}
170function edit_folder_name_cb(response)
171{
172    if (!response) {
173        return;
174    }
175    response = escapeHTML(response).replace(/^\s*|\s*$/g,"");;
176    text_node.innerHTML = response;
177    var old_ns = folder.getAttribute('ref');
178    var new_ns = old_ns.replace(/:[^:]*$/, ":" + response);
179
180    npd_ns = $('npd_ns');
181    var regex = new RegExp("^" + old_ns);
182    npd_ns.value = npd_ns.value.replace(regex, new_ns);
183    var length = new_folders.length;
184    if (length > 0) {
185        while (length--) {
186            var f = new_folders[length];
187            console.log(new_ns);
188            console.log(f.getAttribute('ref'));
189            f.setAttribute('ref', f.getAttribute('ref').replace(regex, new_ns));
190        }
191    }
192}
193
194function new_folder_click(e)
195{
196    var link = getEventElement(e);
197    stop_event(e);
198    if (!link.getAttribute('ref')) {
199        // was a link clicked, or its content
200        link = link.parentNode;
201    }
202    active.className = 'idx_dir';
203    $('npd_ns').value = link.getAttribute('ref');
204    active = link;
205    active.className = 'idx_dir active';
206}
207function page_click(e)
208{
209    link = getEventElement(e);
210    stop_event(e);
211    input = $('npd_page_name');
212    input.value = link.innerHTML;
213    input.className = 'text';
214}
215function plus_clicked(e)
216{
217    li = getEventElement(e);
218    switch (li.nodeName.toLowerCase()) {
219    	case "strong":
220            li = li.parentNode.parentNode.parentNode;
221            break;
222        case "a":
223            li = li.parentNode.parentNode;
224            break;
225    }
226    if (li.className != 'closed') {
227        return true;
228    }
229    window.location.href = firstDescendant(firstDescendant(li)).href;
230}
231function init_index()
232{
233    var div = $('dw_page_div');
234    for (i=0; i<2; i++){
235        var to_be_removed = firstDescendant(div);
236        div.removeChild(to_be_removed);
237    }
238    links = document.getElementsByTagName("a");
239    var pattern = new RegExp("(^|\\s)idx_dir(\\s|$)");
240    var links_length = links.length;
241    var li = '';
242    for(i=0; i<links_length; i++) {
243        if ( pattern.test(links[i].className) ) {
244            links[i].href += '&npd=1';
245            var a = links[i].href.replace(/.*idx=:?([^&]*).*/, "$1");
246            var a = a.replace(/%3A/, ":");
247            if (a == $('npd_ns').value) {
248                links[i].className += " active";
249                active = links[i];
250            };
251            li = links[i].parentNode.parentNode;
252            if (li.className == "closed") {
253                addEvent(li, "click", plus_clicked);
254            }
255        } else {
256            addEvent(links[i], "click", page_click);
257        }
258    }
259    // attach events to the buttons
260    addEvent($('npd_save'), "click", npd_save);
261    addEvent($('npd_cancel'), "click", npd_cancel);
262    addEvent($('npd_new_folder'), "click", npd_new_folder);
263    // add a root image
264    // prepare new node
265<?php
266$title = addcslashes($conf['title'], "'");
267if (! $title) {
268    $title = 'Wiki';
269}
270?>
271    var root = document.createElement('div');
272    root.innerHTML = '<div class="li base"><a class="idx_dir" id="npd_root" href=":" ref=":"><strong><?php echo $title;?></strong></a></div>';
273    root.className = 'base';
274    var ul = firstDescendant(div);
275    if (ul) {
276        div.removeChild(ul);
277    } else {
278        ul = document.createElement("UL");
279        ul.className = 'idx';
280    }
281    var root_link = firstDescendant(firstDescendant(root));
282    var child = firstDescendant(div);
283    if (child) {
284        div.insertBefore(root, child);
285    } else {
286        div.appendChild(root);
287    }
288    root.appendChild(ul);
289    addEvent(root_link, "click", new_folder_click);
290
291    if ((typeof active) == 'undefined') {
292        // in case the namespace the popup was called from
293        // does not exist, we just make the root active
294        active = root_link;
295        active.className = "idx_dir active";
296        $('npd_ns').value = "";
297    }
298
299    $('dw_page_div').style.display = '';
300    $('npd_page_name').focus();
301}
302function stop_event(e)
303{
304    if (!!(window.attachEvent && !window.opera)){
305        e.returnValue = false;
306        e.cancelBubble = true;
307    } else {
308        e.preventDefault();
309        e.stopPropagation();
310    }
311    e.stopped = true;
312}
313function escapeHTML(string) {
314    var div = document.createElement('div');
315    var text = document.createTextNode(string);
316    div.appendChild(text);
317    return div.innerHTML;
318}
319//]]>
320</script>
321<style type="text/css">
322#aep_ovrl {
323    background-color: black;
324    -moz-opacity: 0.7; opacity: 0.7;
325    top: 0; left: 0; position: fixed;
326    width: 100%; height:100%; z-index: 99;
327}
328#aep_ww { position: fixed; z-index: 100; top: 0; left: 0; width: 100%; height: 100%; text-align: center;}
329#aep_win { margin: 20% auto 0 auto; width: 400px; text-align: left;}
330#aep_w {background-color: white; padding: 3px; border: 1px solid black; background-color: #EEE;}
331#aep_t {color: white; margin: 0 0 2px 3px; font-family: Arial, sans-serif; font-size: 10pt;}
332#aep_text {width:  98%;}
333#aep_w span {font-family: Arial, sans-serif; font-size: 10pt;}
334#aep_w div {text-align: right; margin-top: 5px;}
335</style>
336<!-- IE specific code: -->
337<!--[if lte IE 7]>
338<style type="text/css">
339#aep_ovrl {
340    position: absolute;
341    filter:alpha(opacity=70);
342    top: expression(eval(document.body.scrollTop));
343    width: expression(eval(document.body.clientWidth));
344}
345#aep_ww {
346    position: absolute;
347    top: expression(eval(document.body.scrollTop));
348}
349</style>
350<![endif]-->
351  <link rel="shortcut icon" href="<?php echo DOKU_TPL?>images/favicon.ico" />
352
353  <?php /*old includehook*/ @include(dirname(__FILE__).'/meta.html')?>
354</head>
355
356<body class="npd">
357<!-- ae_prompt HTML code -->
358<div id="aep_ovrl" style="display: none;">&nbsp;</div>
359<div id="aep_ww" style="display: none;">
360<div id="aep_win"><div id="aep_t"></div>
361<div id="aep_w"><span id="aep_prompt"></span>
362<br /><input type="text" id="aep_text" onKeyPress=
363"if((event.keyCode==10)||(event.keyCode==13)) ae_clk(1); if (event.keyCode==27) ae_clk(0);">
364<br><div><input type="button" id="aep_ok" onclick="ae_clk(1);" value="<?php echo addcslashes($npd->getLang('btn_ok'), '"'); ?>">
365<input type="button" id="aep_cancel" onclick="ae_clk(0);" value="<?php echo addcslashes($lang['btn_cancel'], '"');?>">
366</div></div>
367</div>
368</div>
369<!-- ae_prompt HTML code -->
370<?php /*old includehook*/ @include(dirname(__FILE__).'/topheader.html')?>
371<div class="npd">
372
373  <?php flush()?>
374
375  <?php /*old includehook*/ @include(dirname(__FILE__).'/pageheader.html')?>
376
377  <div class="page" id="dw_page_div" style="display: none;">
378    <!-- wikipage start -->
379    <?php tpl_content()?>
380    <!-- wikipage stop -->
381  </div>
382    <form action=''>
383        <input type="text" class="" style="display: none;" id="npd_ns" value="<?php echo trim($_REQUEST['idx'], ":"); ?>"/>
384        <input type="text" class="text default" id="npd_page_name"
385               value="<?php echo addcslashes($npd->getLang('msc_page_title'), '"'); ?>"
386               class="default"
387               onblur="if(this.value == '') { this.value = this.defaultValue; this.className = 'text default'; }"
388               onfocus="if(this.value==this.defaultValue) {this.value=''; this.className = 'text';}"/>
389        <input type="button" id="npd_save" class="text" value="<?php echo addcslashes($npd->getLang('btn_create_page'), '"');?>"/>
390        <input type="button" id="npd_cancel" class="text" value="<?php echo addcslashes($lang['btn_cancel'], '"');?>"/>
391        <input type="button" id="npd_new_folder" class="button" value="<?php echo addcslashes($npd->getLang('btn_new_folder'), '"')?>"/>
392    </form>
393
394  <div class="clearer">&nbsp;</div>
395
396  <?php flush()?>
397
398<?php /*old includehook*/ @include(dirname(__FILE__).'/footer.html')?>
399
400<div class="no"><?php /* provide DokuWiki housekeeping, required in all templates */ tpl_indexerWebBug()?></div>
401</div>
402</body>
403</html>
404