PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/branches/1.0RC1/www/js/class.LibWebta.js

http://scalr.googlecode.com/
JavaScript | 215 lines | 148 code | 46 blank | 21 comment | 40 complexity | b698a0b501455a733b02d02652bcee8d MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, GPL-3.0
  1. // +--------------------------------------------------------------------------+
  2. // | LibWebta scripts. |
  3. // +--------------------------------------------------------------------------+
  4. // | Copyright (c) 2003-2006 Webta Inc, http://webta.net/copyright.html |
  5. // +--------------------------------------------------------------------------+
  6. // | This program is protected by international copyright laws. Any |
  7. // | use of this program is subject to the terms of the license |
  8. // | agreement included as part of this distribution archive. |
  9. // | Any other uses are strictly prohibited without the written permission |
  10. // | of "Webta" and all other rights are reserved. |
  11. // | This notice may not be removed from this source code file. |
  12. // | This source file is subject to version 1.1 of the license, |
  13. // | that is bundled with this package in the file LICENSE. |
  14. // | If the backage does not contain LICENSE file, this source file is |
  15. // | subject to general license, available at http://webta.net/license.html |
  16. // +--------------------------------------------------------------------------+
  17. // | Authors: Alex Kovalyov <ak@webta.net> |
  18. // | Sergey Koksharov <sergey@webta.net> |
  19. // +--------------------------------------------------------------------------+
  20. var LibWebta = Class.create();
  21. LibWebta.prototype = {
  22. allchecked: false,
  23. tweaker: null,
  24. options: {},
  25. initialize: function() {
  26. var options = Object.extend({
  27. load_calendar: 0,
  28. load_treemenu: 0,
  29. topmenu: 'TopMenu',
  30. tabitems: 'Webta_Items',
  31. xmlserver: 'xmlserver.php',
  32. menucss: '../js/dmenu/dmenu.css',
  33. menujs: 'dmenu/dmenu.js',
  34. calendar_js: 'calendar/calendar.js',
  35. calendar_en: 'calendar/lang/calendar-en.js',
  36. calendar_inc: 'calendar/calendar-setup.js',
  37. treemenu_js: 'treemenu/treemenu.js',
  38. treemenu_css: 'js/treemenu/tree.css'
  39. }, arguments[0] || {});
  40. this.options = options;
  41. },
  42. load: function(library) {
  43. if (!library) return false;
  44. if (library.indexOf(".js") != -1) {
  45. // load js library
  46. document.writeln("<script type='text/javascript' src='js/"+ library +"'></script>");
  47. }
  48. if (library.indexOf(".css") != -1) {
  49. // load css style sheet
  50. document.writeln("<link href='css/"+ library +"' rel='stylesheet' type='text/css'>");
  51. }
  52. return true;
  53. },
  54. preloadImages: function() {
  55. var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  56. var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  57. if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  58. },
  59. checkall: function(chk_name)
  60. {
  61. if (!chk_name)
  62. chk_name = "delete[]";
  63. var frm = $("frm");
  64. for (var i=0; i<frm.elements.length; i++)
  65. {
  66. var e = frm.elements[i];
  67. if (((e.name == chk_name || e.name == "actid[]") && e.type=='checkbox') && !e.disabled) {
  68. e.checked = !this.allchecked;
  69. }
  70. }
  71. this.allchecked = !this.allchecked;
  72. if (this.tweaker)
  73. this.tweaker.checkall();
  74. },
  75. generatePass: function(element, passwordlength, isdigits) {
  76. var pwchars = isdigits ? "0123456789" : "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
  77. var passwordlength = (passwordlength > 0) ? passwordlength : 16;
  78. var passwd = '';
  79. for (var i = 0; i < passwordlength; i++ ) {
  80. passwd += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) );
  81. }
  82. var element = document.getElementById(element);
  83. element.value = passwd;
  84. },
  85. setupTweaker: function() {
  86. if (this.tweaker)
  87. this.tweaker.setup();
  88. },
  89. createTweaker: function() {
  90. if (this.tweaker) {
  91. this.tweaker.setup();
  92. this.tweaker.create();
  93. }
  94. },
  95. showTopMenu: function() {
  96. var element = $(this.options.topmenu);
  97. if (element) {
  98. element.style.visibility = 'visible';
  99. DynarchMenu.setup(this.options.topmenu);
  100. }
  101. this.tweaker = new FitoTab(this.options.tabitems);
  102. },
  103. afterload: function() {
  104. this.showTopMenu();
  105. this.createTweaker();
  106. if (window.customOnload == true)
  107. {
  108. window.customOnloadFunction();
  109. }
  110. },
  111. openurl: function(url) {
  112. window.location.href = url;
  113. return true;
  114. },
  115. loadDefautls: function() {
  116. if (this.options.menucss)
  117. this.load(this.options.menucss);
  118. if (this.options.menujs)
  119. this.load(this.options.menujs);
  120. if (this.options.load_calendar)
  121. {
  122. if (this.options.calendar_css)
  123. this.load(this.options.calendar_css);
  124. if (this.options.calendar_js)
  125. this.load(this.options.calendar_js);
  126. if (this.options.calendar_inc)
  127. this.load(this.options.calendar_inc);
  128. if (this.options.calendar_en)
  129. this.load(this.options.calendar_en);
  130. }
  131. if (this.options.load_treemenu) {
  132. if (this.options.treemenu_js)
  133. this.load(this.options.treemenu_js);
  134. if (this.options.treemenu_css)
  135. this.load(this.options.treemenu_css);
  136. }
  137. },
  138. search: function() {
  139. string = $('search_string').value;
  140. if (self.location.href.indexOf("index.php") == -1)
  141. {
  142. document.location = 'index.php?searchpage='+string;
  143. return true;
  144. }
  145. $("search_button").disabled = true;
  146. $("search_image").style.display = "";
  147. $("title_td").innerHTML = "Search results for '"+string+"'";
  148. var ajax = new Ajax.Request(this.options.xmlserver, {
  149. onSuccess : function(response){
  150. $("index_menu_div").innerHTML = response.responseText;
  151. $("search_button").disabled = false;
  152. $("search_image").style.display = "none";
  153. },
  154. method: 'get',
  155. parameters: "_cmd=search&search_string="+string,
  156. onFailure: function() {
  157. $("search_button").disabled = false;
  158. $("search_image").style.display = "none";
  159. }
  160. });
  161. },
  162. collapseSettings: function(id, obj) {
  163. var element = $(id);
  164. element.style.display = (element.style.display == 'none') ? 'block' : 'none';
  165. var img = obj.getElementsByTagName("img");
  166. if (img)
  167. img[0].src = (img[0].src.indexOf("sorta") != -1) ? img[0].src.replace('sorta', 'sortd') : img[0].src.replace('sortd', 'sorta');
  168. }
  169. };