tools.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * This file is part of DotClear.
  3. * Copyright (c) 2004 Olivier Meunier and contributors. All rights
  4. * reserved.
  5. *
  6. * DotClear is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DotClear is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DotClear; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * ***** END LICENSE BLOCK ***** */
  21. /*img = new Image;
  22. img.src = 'images/moins.png';*/
  23. function getE(id)
  24. {
  25. if(document.getElementById) {
  26. return document.getElementById(id);
  27. } else if(document.all) {
  28. return document.all[id];
  29. } else return;
  30. }
  31. function openClose(id,mode)
  32. {
  33. element = getE(id);
  34. img = getE('img_'+id);
  35. if(element.style) {
  36. if(mode == 0) {
  37. if(element.style.display == 'block' ) {
  38. element.style.display = 'none';
  39. img.src = 'images/plus.png';
  40. } else {
  41. element.style.display = 'block';
  42. img.src = 'images/moins.png';
  43. }
  44. } else if(mode == 1) {
  45. element.style.display = 'block';
  46. img.src = 'images/moins.png';
  47. } else if(mode == -1) {
  48. element.style.display = 'none';
  49. img.src = 'images/plus.png';
  50. }
  51. }
  52. }
  53. function mOpenClose(idArray,mode)
  54. {
  55. for(var i=0;i<idArray.length;i++) {
  56. openClose(idArray[i],mode);
  57. }
  58. }
  59. function popup(url)
  60. {
  61. window.open(url,'dc_popup',
  62. 'alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no');
  63. }
  64. function limitArea(e,limit)
  65. {
  66. if (e.value.length > limit) {
  67. e.value = e.value.substring(0,limit);
  68. }
  69. }
  70. function createCookie(name,value) {
  71. document.cookie = name+"="+value+";path=/;";
  72. }
  73. function readCookie(name) {
  74. var nameEQ = name + "=";
  75. var ca = document.cookie.split(';');
  76. for(var i=0;i < ca.length;i++) {
  77. var c = ca[i];
  78. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  79. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  80. }
  81. return null;
  82. }
  83. function openCloseOptions(id,cookie_name,mode)
  84. {
  85. if (mode != null) {
  86. openClose(id,mode);
  87. e = getE(id);
  88. if (e.style.display == 'block') {
  89. cookie_value = '1';
  90. } else {
  91. cookie_value = '-1';
  92. }
  93. createCookie(cookie_name,cookie_value);
  94. } else {
  95. cookie = readCookie(cookie_name);
  96. if (!cookie) {
  97. cookie = -1
  98. }
  99. openClose(id,cookie);
  100. }
  101. }
  102. function setNow()
  103. {
  104. var now = new Date();
  105. var y = now.getFullYear();
  106. var m = now.getMonth();
  107. var d = now.getDate();
  108. var h = now.getHours();
  109. var i = now.getMinutes();
  110. var s = now.getSeconds();
  111. if (m.length == 1) {
  112. m = '0'+m;
  113. }
  114. e = getE('p_dt_y');
  115. e.value = y;
  116. e = getE('p_dt_m');
  117. e.selectedIndex = m;
  118. e = getE('p_dt_d');
  119. e.value = d;
  120. e = getE('p_dt_h');
  121. e.value = h;
  122. e = getE('p_dt_i');
  123. e.value = i;
  124. e = getE('p_dt_s');
  125. e.value = s;
  126. }
  127. function str2url(str,encoding,ucfirst)
  128. {
  129. str = str.toUpperCase();
  130. str = str.toLowerCase();
  131. str = str.replace(/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]/g,'a');
  132. str = str.replace(/[\u00E7]/g,'c');
  133. str = str.replace(/[\u00E8\u00E9\u00EA\u00EB]/g,'e');
  134. str = str.replace(/[\u00EC\u00ED\u00EE\u00EF]/g,'i');
  135. str = str.replace(/[\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8]/g,'o');
  136. str = str.replace(/[\u00F9\u00FA\u00FB\u00FC]/g,'u');
  137. str = str.replace(/[\u00FD\u00FF]/g,'y');
  138. str = str.replace(/[\u00F1]/g,'n');
  139. str = str.replace(/[\u0153]/g,'oe');
  140. str = str.replace(/[\u00E6]/g,'ae');
  141. str = str.replace(/[\u00DF]/g,'ss');
  142. str = str.replace(/[^a-z0-9_\s\'\:\/\[\]-]/g,'');
  143. str = trim(str);
  144. str = str.replace(/[\s\'\:\/\[\]-]+/g,' ');
  145. str = str.replace(/[ ]/g,'-');
  146. if (ucfirst == 1) {
  147. c = str.charAt(0);
  148. str = c.toUpperCase()+str.slice(1);
  149. }
  150. return str;
  151. }
  152. function trim(s) {
  153. s = s.replace(/[ ]*$/,'');
  154. s = s.replace(/^[ ]*/,'');
  155. return s;
  156. }