[ Index ] |
|
Code source de Seagull 0.6.1 |
1 // Allows to show/collapse any block element given its #id 2 // Usage: setup a checkbox and call this function with onclick event 3 // ex: <input type="checkbox" name="foo" id="foo" onclick="collapseElement(this.checked,'id_of_block_to_collapse')" /> 4 function collapseElement(display,elementId) 5 { 6 var blockToCollapse = document.getElementById(elementId); 7 if (display){ 8 blockToCollapse.style.display = 'block'; 9 } else { 10 blockToCollapse.style.display = 'none'; 11 } 12 } 13 14 // Allows to highlight a row when hovering it with mouse 15 // Needs every row to have a "back..." class name 16 function switchRowColorOnHover() 17 { 18 var table = document.getElementsByTagName("table"); 19 for (var i=0; i<table.length; i++) { 20 var row = table[i].getElementsByTagName("tr"); 21 for (var j=0; j<row.length; j++) { 22 row[j].onmouseover=function() { 23 if (this.className.search(new RegExp("back"))>=0) { 24 this.className+=" backHighlight"; 25 } 26 27 } 28 row[j].onmouseout=function() { 29 this.className=this.className.replace(new RegExp(" backHighlight\\b"), ""); 30 } 31 } 32 } 33 } 34 35 function lockButtons(whichform) 36 { 37 ua = new String(navigator.userAgent); 38 if (ua.match(/IE/g)) { 39 for (i=1; i<whichform.elements.length; i++) { 40 if ((whichform.elements[i].type == 'submit') || (whichform.elements[i].type == 'button')) 41 whichform.elements[i].disabled = true; 42 } 43 } 44 whichform.submit(); 45 } 46 47 function openWindow() 48 { 49 var newWin = null; 50 var url = openWindow.arguments[0]; 51 nArgs = openWindow.arguments.length; 52 var width = openWindow.arguments[1]; 53 var height = openWindow.arguments[2]; 54 55 // if dynamic window size args are passed 56 if (nArgs > 1) 57 newWin = window.open ("","newWindow","toolbar=no,width=" + width + ",height=" + height + ",directories=no,status=no,scrollbars=yes,resizable=no,menubar=no"); 58 else 59 newWin = window.open ("","newWindow","toolbar=no,width=" + SGL_JS_WINWIDTH + ",height=" + SGL_JS_WINHEIGHT + ",directories=no,status=no,scrollbars=yes,resizable=no,menubar=no"); 60 newWin.location.href = url; 61 } 62 63 function confirmSubmit(item, formName) 64 { 65 var evalFormName = eval('document.' + formName) 66 var flag = false 67 for (var count = 0; count < evalFormName.elements.length; count++) { 68 var tipo = evalFormName.elements[count].type 69 if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '') 70 flag = true 71 } 72 if (flag == false) { 73 alert('You must select an element to delete') 74 return false 75 } 76 var agree = confirm("Are you sure you want to delete this " + item + "?"); 77 if (agree) 78 return true; 79 else 80 return false; 81 } 82 83 function confirmDelete(item, formName) 84 { 85 var evalFormName = eval('document.' + formName) 86 var flag = false 87 var agree = confirm("Are you sure you want to delete this " + item + "?"); 88 if (agree) 89 return true; 90 else 91 return false; 92 } 93 94 function confirmDeleteWithMsg(msg) 95 { 96 var agree = confirm(msg); 97 if (agree) 98 return true; 99 else 100 return false; 101 } 102 103 function confirmSave(formName) 104 { 105 var evalFormName = eval('document.' + formName) 106 var flag = false 107 for (var count = 0; count < evalFormName.elements.length; count++) { 108 var tipo = evalFormName.elements[count].type 109 if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '') 110 flag = true 111 } 112 if (flag == false) { 113 alert('You must select an element to save') 114 return false 115 } 116 } 117 118 function confirmSend(formName) 119 { 120 var evalFormName = eval('document.' + formName) 121 var flag = false 122 for (var count = 0; count < evalFormName.elements.length; count++) { 123 var tipo = evalFormName.elements[count].type 124 if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '') 125 flag = true 126 } 127 if (flag == false) { 128 alert('You must select at least one recipient') 129 return false 130 } 131 } 132 133 function confirmCategoryDelete(item) 134 { 135 var agree = confirm("Are you sure you want to delete this " + item + "?"); 136 if (agree) 137 return true; 138 else 139 return false; 140 } 141 142 function verifySelectionMade() 143 { 144 var moveForm = document.moveCategory.frmNewCatParentID 145 var selectedCat = moveForm.value 146 if (selectedCat == '') { 147 alert('Please select a new parent category') 148 return false; 149 } else 150 return true; 151 } 152 153 function checkInput(formName, fieldName) 154 { 155 var f = eval('document.' + formName + '.' + fieldName) 156 if (f.value == '') { 157 alert('Please enter a value in the field before submitting'); 158 return false; 159 } else 160 return true; 161 } 162 163 function getSelectedValue(selectObj) 164 { 165 return (selectObj.options[selectObj.selectedIndex].value); 166 } 167 168 169 function toggleDisplay(myElement) 170 { 171 boxElement = document.getElementById(myElement); 172 173 if (boxElement.style.display == 'none') { 174 boxElement.style.display = 'block'; 175 } else { 176 // ... otherwise collapse box 177 boxElement.style.display = 'none'; 178 } 179 } 180 181 function confirmCustom(alertText, confirmText, formName) 182 { 183 var evalFormName = eval('document.' + formName) 184 var flag = false 185 for (var count = 0; count < evalFormName.elements.length; count++) { 186 var tipo = evalFormName.elements[count].type 187 if (tipo == 'checkbox' && evalFormName.elements[count].checked == true && evalFormName.elements[count].name != '') 188 flag = true 189 } 190 if (flag == false) { 191 alert(alertText) 192 return false 193 } 194 var agree = confirm(confirmText); 195 if (agree) 196 return true; 197 else 198 return false; 199 } 200 201 // for block manager 202 203 var oldDate; 204 oldDate = new Array(); 205 206 function time_select_reset(prefix, changeBack) { 207 // TODO: Rewrite this whole function (time_select_reset()) when adminGui is implemented. 208 function setEmpty(id) { 209 if (dateSelector = document.getElementById(id)) { 210 oldDate = dateSelector.value; 211 dateSelectorToShow = document.getElementById("frmExpiryDateToShow"); 212 oldDateToShow = dateSelectorToShow.innerHTML; 213 if (dateSelector.value != ''){ 214 //alert(dateSelector.value); 215 dateSelector.value = ''; 216 dateSelectorToShow.innerHTML = ''; 217 } 218 } 219 } 220 221 function setActive(id) { 222 if (dateSelector = document.getElementById(id)) { 223 dateSelector.value = oldDate; 224 dateSelectorToShow.innerHTML = oldDateToShow; 225 } 226 227 } 228 229 if (document.getElementById(prefix+'NoExpire').checked) { 230 setEmpty('frmExpiryDate'); 231 } else { 232 if (changeBack == true) { 233 setActive('frmExpiryDate'); 234 } 235 } 236 } 237 238 function async_load() 239 { 240 var node; 241 try { 242 // variable _asyncDom is set from JavaScript in the iframe 243 // node = top._asyncDom.cloneNode(true); // kills Safari 1.2.4 244 node = top._asyncDom; 245 // try to remove the first script element, the one that 246 // executed all document.writes(). 247 node.removeChild(node.getElementsByTagName("script")[0]); 248 } catch (e) { 249 // alert(e); 250 } 251 try { 252 // insert DOM fragment at a DIV with id "async_demo" on current page 253 document.getElementById("async_demo").appendChild(node); 254 } catch (e) { 255 try { 256 // fallback for some non DOM compliant browsers 257 document.getElementById("async_demo").innerHTML = node.innerHTML; 258 } catch (e1) {}; 259 } 260 } 261 262 // calling -> makeUrl({'module':'mymodule', 'action':'generateReport', 'param2': 'foo bar'}); 263 function makeUrl(params) 264 { 265 var rslt = SGL_JS_WEBROOT + '/' + SGL_JS_FRONT_CONTROLLER; 266 var moduleName = (params.module) ? params.module : ''; 267 var managerName = (params.manager) ? params.manager : moduleName; 268 269 switch (SGL_JS_URL_STRATEGY) { 270 case 'SGL_UrlParser_ClassicStrategy': 271 if (rslt.charAt(rslt.length - 1) != '?') { 272 rslt = rslt + '?'; 273 } 274 rslt = rslt + 'moduleName=' + escape(moduleName) + '&managerName=' + escape(managerName) + '&'; 275 for (x in params) { 276 if ((x == 'module') || (x =='manager')) { 277 continue; 278 } 279 rslt = rslt + escape(x) + '=' + escape(params[x]) + '&'; 280 } 281 break; 282 283 default: 284 rslt = rslt + '/' + escape(moduleName) + '/' + escape(managerName) + '/'; 285 for (x in params) { 286 if ((x == 'module') || (x =='manager')) { 287 continue; 288 } 289 rslt = rslt + escape(x) + '/' + escape(params[x]) + '/'; 290 } 291 break; 292 } 293 return rslt; 294 } 295 296 /** 297 * Checks/unchecks all tables, modified from phpMyAdmin 298 * 299 * @param string the form name 300 * @param boolean whether to check or to uncheck the element 301 * 302 * @return boolean always true 303 */ 304 function setCheckboxes(the_form, element_name, do_check) 305 { 306 var elts = (typeof(document.forms[the_form].elements[element_name]) != 'undefined') 307 ? document.forms[the_form].elements[element_name] 308 : ''; 309 var elts_cnt = (typeof(elts.length) != 'undefined') 310 ? elts.length 311 : 0; 312 //var applyToWholeForm = 313 //alert(element_name) 314 315 316 if (elts_cnt) { 317 for (var i = 0; i < elts_cnt; i++) { 318 elts[i].checked = do_check; 319 } 320 // tick all checkboxes per form 321 } else if (element_name == false) { 322 var f = document.forms[the_form]; 323 for (var c = 0; c < f.elements.length; c++) 324 if (f.elements[c].type == 'checkbox') { 325 f.elements[c].checked = do_check; 326 } 327 328 } else { 329 elts.checked = do_check; 330 } 331 return true; 332 } 333 334 /** 335 * Launches the above function depending on the status of a trigger checkbox 336 * 337 * @param string the form name 338 * @param string the element name 339 * @param boolean the status of triggered checkbox 340 * 341 * @return void 342 */ 343 function applyToAllCheckboxes(formName, elementName, isChecked) 344 { 345 if (isChecked) { 346 setCheckboxes(formName, elementName, true) 347 } else { 348 setCheckboxes(formName, elementName, false) 349 } 350 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 30 01:27:52 2007 | par Balluche grâce à PHPXref 0.7 |