OSDN Git Service

Subversion由来のタグを削除
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / javascript / templateEdit.js
1 /**
2   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
3   * Copyright (C) 2002-2012 The Nucleus Group
4   *
5   * This program is free software; you can redistribute it and/or
6   * modify it under the terms of the GNU General Public License
7   * as published by the Free Software Foundation; either version 2
8   * of the License, or (at your option) any later version.
9   * (see nucleus/documentation/index.html#license for more info)
10   *
11   *     Javascript code to hide empty textareas when editing templates.
12   *
13   * compatibility.js is required.
14   */
15
16 var amountOfFields = 1;
17 var editText = 'empty field (click to edit)';
18
19 function hideUnused() {
20         while (document.getElementById('textarea' + amountOfFields)) 
21                 amountOfFields++;
22         amountOfFields--;
23
24         for (var i=1;i<=amountOfFields;i++) {
25                 var el = document.getElementById('textarea' + i);
26
27                 // hide textareas when empty, and add onclick event
28                 // to make them visible again
29                 if (el.value == '') {
30                         el.style.display = 'none';
31                         var tdEl = document.getElementById('td' + i);
32                         
33                         var aHref = createElement('a');
34                         aHref.href = '';
35                         aHref.className = "expandLink";
36                         aHref.id = "expandLink" + i;
37                         aHref.onclick = new Function("return makeVisible("+i+")");
38                         aHref.tabIndex = el.tabIndex;
39                         aHref.title = editText;
40                         aHref.appendChild(document.createTextNode(editText));
41
42                         tdEl.appendChild(aHref);
43                         
44                 }
45         }
46
47 }
48
49 function setTemplateEditText(newText) {
50         editText = newText;
51 }
52
53 function makeVisible(i) {
54         var textareaEl = document.getElementById('textarea' + i);
55         var expandEl = document.getElementById('expandLink' + i);
56
57         textareaEl.style.display = 'block';
58         expandEl.style.display = 'none';
59
60         textareaEl.focus();
61         return false;
62 }
63
64 window.onload = hideUnused;