OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@906 1ca29b...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / javascript / templateEdit.js
1 /**
2   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
3   * Copyright (C) 2002-2009 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   * @require compatibility.js
14   *
15   * $Id$
16   * $NucleusJP: templateEdit.js,v 1.4 2006/07/12 07:11:47 kimitake Exp $
17   */
18
19 var amountOfFields = 1;
20 var editText = 'empty field (click to edit)';
21
22 function hideUnused() {
23         while (document.getElementById('textarea' + amountOfFields)) 
24                 amountOfFields++;
25         amountOfFields--;
26
27         for (var i=1;i<=amountOfFields;i++) {
28                 var el = document.getElementById('textarea' + i);
29
30                 // hide textareas when empty, and add onclick event
31                 // to make them visible again
32                 if (el.value == '') {
33                         el.style.display = 'none';
34                         var tdEl = document.getElementById('td' + i);
35                         
36                         var aHref = createElement('a');
37                         aHref.href = '';
38                         aHref.className = "expandLink";
39                         aHref.id = "expandLink" + i;
40                         aHref.onclick = new Function("return makeVisible("+i+")");
41                         aHref.tabIndex = el.tabIndex;
42                         aHref.title = editText;
43                         aHref.appendChild(document.createTextNode(editText));
44
45                         tdEl.appendChild(aHref);
46                         
47                 }
48         }
49
50 }
51
52 function setTemplateEditText(newText) {
53         editText = newText;
54 }
55
56 function makeVisible(i) {
57         var textareaEl = document.getElementById('textarea' + i);
58         var expandEl = document.getElementById('expandLink' + i);
59
60         textareaEl.style.display = 'block';
61         expandEl.style.display = 'none';
62
63         textareaEl.focus();
64         return false;
65 }
66
67 window.onload = hideUnused;