| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 // <?php !! This fools phpdocumentor into parsing this file 2 /** 3 * @package Mambo 4 * @author Mambo Foundation Inc see README.php 5 * @copyright Mambo Foundation Inc. 6 * See COPYRIGHT.php for copyright notices and details. 7 * @license http://www.opensource.org/licenses/gpl-2.0.php GNU/GPL, see 8 * LICENSE.php 9 * Mambo is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; version 2 of the 12 * License. 13 */ 14 15 // general utility for browsing a named array or object 16 function xshow(o) { 17 s = ''; 18 for(e in o) {s += e+'='+o[e]+'\n';} 19 alert( s ); 20 } 21 22 /** 23 * Writes a dynamically generated list 24 * @param string The parameters to insert into the <select> tag 25 * @param array A javascript array of list options in the form [key,value,text] 26 * @param string The key to display for the initial state of the list 27 * @param string The original key that was selected 28 * @param string The original item value that was selected 29 */ 30 function writeDynaList( selectParams, source, key, orig_key, orig_val ) { 31 var html = '\n <select ' + selectParams + '>'; 32 var i = 0; 33 for (x in source) { 34 if (source[x][0] == key) { 35 var selected = ''; 36 if ((orig_key == key && orig_val == source[x][1]) || (i == 0 && orig_key != key)) { 37 selected = 'selected="selected"'; 38 } 39 html += '\n <option value="'+source[x][1]+'" '+selected+'>'+source[x][2]+'</option>'; 40 } 41 i++; 42 } 43 html += '\n </select>'; 44 45 document.writeln( html ); 46 } 47 48 /** 49 * Changes a dynamically generated list 50 * @param string The name of the list to change 51 * @param array A javascript array of list options in the form [key,value,text] 52 * @param string The key to display 53 * @param string The original key that was selected 54 * @param string The original item value that was selected 55 */ 56 function changeDynaList( listname, source, key, orig_key, orig_val ) { 57 var list = eval( 'document.adminForm.' + listname ); 58 59 // empty the list 60 for (i in list.options.length) { 61 list.options[i] = null; 62 } 63 i = 0; 64 for (x in source) { 65 if (source[x][0] == key) { 66 opt = new Option(); 67 opt.value = source[x][1]; 68 opt.text = source[x][2]; 69 70 if ((orig_key == key && orig_val == opt.value) || i == 0) { 71 opt.selected = true; 72 } 73 list.options[i++] = opt; 74 } 75 } 76 list.length = i; 77 } 78 79 /** 80 * Adds a select item(s) from one list to another 81 */ 82 function addSelectedToList( frmName, srcListName, tgtListName ) { 83 var form = eval( 'document.' + frmName ); 84 var srcList = eval( 'form.' + srcListName ); 85 var tgtList = eval( 'form.' + tgtListName ); 86 87 var srcLen = srcList.length; 88 var tgtLen = tgtList.length; 89 var tgt = "x"; 90 91 //build array of target items 92 for (var i=tgtLen-1; i > -1; i--) { 93 tgt += "," + tgtList.options[i].value + "," 94 } 95 96 //Pull selected resources and add them to list 97 for (var i=srcLen-1; i > -1; i--) { 98 if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) { 99 opt = new Option( srcList.options[i].text, srcList.options[i].value ); 100 tgtList.options[tgtList.length] = opt; 101 } 102 } 103 } 104 105 function delSelectedFromList( frmName, srcListName ) { 106 var form = eval( 'document.' + frmName ); 107 var srcList = eval( 'form.' + srcListName ); 108 109 var srcLen = srcList.length; 110 111 for (var i=srcLen-1; i > -1; i--) { 112 if (srcList.options[i].selected) { 113 srcList.options[i] = null; 114 } 115 } 116 } 117 118 function moveInList( frmName, srcListName, index, to) { 119 var form = eval( 'document.' + frmName ); 120 var srcList = eval( 'form.' + srcListName ); 121 var total = srcList.options.length-1; 122 123 if (index == -1) { 124 return false; 125 } 126 if (to == +1 && index == total) { 127 return false; 128 } 129 if (to == -1 && index == 0) { 130 return false; 131 } 132 133 var items = new Array; 134 var values = new Array; 135 136 for (i=total; i >= 0; i--) { 137 items[i] = srcList.options[i].text; 138 values[i] = srcList.options[i].value; 139 } 140 for (i = total; i >= 0; i--) { 141 if (index == i) { 142 srcList.options[i + to] = new Option(items[i],values[i], 0, 1); 143 srcList.options[i] = new Option(items[i+to], values[i+to]); 144 i--; 145 } else { 146 srcList.options[i] = new Option(items[i], values[i]); 147 } 148 } 149 srcList.focus(); 150 } 151 152 function getSelectedOption( frmName, srcListName ) { 153 var form = eval( 'document.' + frmName ); 154 var srcList = eval( 'form.' + srcListName ); 155 156 i = srcList.selectedIndex; 157 if (i != null && i > -1) { 158 return srcList.options[i]; 159 } else { 160 return null; 161 } 162 } 163 164 function setSelectedValue( frmName, srcListName, value ) { 165 var form = eval( 'document.' + frmName ); 166 var srcList = eval( 'form.' + srcListName ); 167 168 var srcLen = srcList.length; 169 170 for (var i=0; i < srcLen; i++) { 171 srcList.options[i].selected = false; 172 if (srcList.options[i].value == value) { 173 srcList.options[i].selected = true; 174 } 175 } 176 } 177 178 function getSelectedRadio( frmName, srcGroupName ) { 179 var form = eval( 'document.' + frmName ); 180 var srcGroup = eval( 'form.' + srcGroupName ); 181 182 if (srcGroup[0]) { 183 for (var i=0, n=srcGroup.length; i < n; i++) { 184 if (srcGroup[i].checked) { 185 return srcGroup[i].value; 186 } 187 } 188 } else { 189 if (srcGroup.checked) { 190 return srcGroup.value; 191 } // if the one button is checked, return zero 192 } 193 // if we get to this point, no radio button is selected 194 return null; 195 } 196 197 function getSelectedValue( frmName, srcListName ) { 198 var form = eval( 'document.' + frmName ); 199 var srcList = eval( 'form.' + srcListName ); 200 201 i = srcList.selectedIndex; 202 if (i != null && i > -1) { 203 return srcList.options[i].value; 204 } else { 205 return null; 206 } 207 } 208 209 function getSelectedText( frmName, srcListName ) { 210 var form = eval( 'document.' + frmName ); 211 var srcList = eval( 'form.' + srcListName ); 212 213 i = srcList.selectedIndex; 214 if (i != null && i > -1) { 215 return srcList.options[i].text; 216 } else { 217 return null; 218 } 219 } 220 221 function chgSelectedValue( frmName, srcListName, value ) { 222 var form = eval( 'document.' + frmName ); 223 var srcList = eval( 'form.' + srcListName ); 224 225 i = srcList.selectedIndex; 226 if (i != null && i > -1) { 227 srcList.options[i].value = value; 228 return true; 229 } else { 230 return false; 231 } 232 } 233 234 // Form specific functions for editting content images 235 236 function showImageProps(base_path) { 237 form = document.adminForm; 238 value = getSelectedValue( 'adminForm', 'imagelist' ); 239 parts = value.split( '|' ); 240 form._source.value = parts[0]; 241 setSelectedValue( 'adminForm', '_align', parts[1] || '' ); 242 form._alt.value = parts[2] || ''; 243 form._border.value = parts[3] || '0'; 244 form._caption.value = parts[4] || ''; 245 setSelectedValue( 'adminForm', '_caption_position', parts[5] || '' ); 246 setSelectedValue( 'adminForm', '_caption_align', parts[6] || '' ); 247 form._width.value = parts[7] || ''; 248 249 //previewImage( 'imagelist', 'view_imagelist', base_path ); 250 srcImage = eval( "document." + 'view_imagelist' ); 251 srcImage.src = base_path + parts[0]; 252 } 253 254 function applyImageProps() { 255 form = document.adminForm; 256 if (!getSelectedValue( 'adminForm', 'imagelist' )) { 257 alert( "Select and image from the list" ); 258 return; 259 } 260 value = form._source.value + '|' 261 + getSelectedValue( 'adminForm', '_align' ) + '|' 262 + form._alt.value + '|' 263 + parseInt( form._border.value ) + '|' 264 + form._caption.value + '|' 265 + getSelectedValue( 'adminForm', '_caption_position' ) + '|' 266 + getSelectedValue( 'adminForm', '_caption_align' ) + '|' 267 + form._width.value; 268 chgSelectedValue( 'adminForm', 'imagelist', value ); 269 } 270 271 function previewImage( list, image, base_path ) { 272 form = document.adminForm; 273 srcList = eval( "form." + list ); 274 srcImage = eval( "document." + image ); 275 var fileName = srcList.options[srcList.selectedIndex].text; 276 var fileName2 = srcList.options[srcList.selectedIndex].value; 277 if (fileName.length == 0 || fileName2.length == 0) { 278 srcImage.src = 'images/blank.gif'; 279 } else { 280 srcImage.src = base_path + fileName2; 281 } 282 } 283 284 /** 285 * Toggles the check state of a group of boxes 286 * 287 * Checkboxes must have an id attribute in the form cb0, cb1... 288 * @param The number of box to 'check' 289 * @param An alternative field name 290 */ 291 function checkAll( n, fldName ) { 292 if (!fldName) { 293 fldName = 'cb'; 294 } 295 var f = document.adminForm; 296 var c = f.toggle.checked; 297 var n2 = 0; 298 for (i=0; i < n; i++) { 299 cb = eval( 'f.' + fldName + '' + i ); 300 if (cb) { 301 cb.checked = c; 302 n2++; 303 } 304 } 305 if (c) { 306 document.adminForm.boxchecked.value = n2; 307 } else { 308 document.adminForm.boxchecked.value = 0; 309 } 310 } 311 312 function listItemTask( id, task ) { 313 var f = document.adminForm; 314 cb = eval( 'f.' + id ); 315 if (cb) { 316 for (i = 0; true; i++) { 317 cbx = eval('f.cb'+i); 318 if (!cbx) break; 319 cbx.checked = false; 320 } // for 321 cb.checked = true; 322 f.boxchecked.value = 1; 323 submitbutton(task); 324 } 325 return false; 326 } 327 328 function hideMainMenu() 329 { 330 document.adminForm.hidemainmenu.value=1; 331 } 332 333 function isChecked(isitchecked){ 334 if (isitchecked == true){ 335 document.adminForm.boxchecked.value++; 336 } 337 else { 338 document.adminForm.boxchecked.value--; 339 } 340 } 341 342 /** 343 * Default function. Usually would be overriden by the component 344 */ 345 function submitbutton(pressbutton) { 346 submitform(pressbutton); 347 } 348 349 /** 350 * Submit the admin form 351 */ 352 function submitform(pressbutton){ 353 document.adminForm.task.value=pressbutton; 354 try { 355 document.adminForm.onsubmit(); 356 } 357 catch(e){} 358 document.adminForm.submit(); 359 } 360 361 /** 362 * Submit the control panel admin form 363 */ 364 function submitcpform(sectionid, id){ 365 document.adminForm.sectionid.value=sectionid; 366 document.adminForm.id.value=id; 367 submitbutton("edit"); 368 } 369 370 /** 371 * Getting radio button that is selected. 372 */ 373 function getSelected(allbuttons){ 374 for (i=0;i<allbuttons.length;i++) { 375 if (allbuttons[i].checked) { 376 return allbuttons[i].value 377 } 378 } 379 } 380 381 // JS Calendar 382 var calendar = null; // remember the calendar object so that we reuse 383 // it and avoid creating another 384 385 // This function gets called when an end-user clicks on some date 386 function selected(cal, date) { 387 cal.sel.value = date; // just update the value of the input field 388 } 389 390 // And this gets called when the end-user clicks on the _selected_ date, 391 // or clicks the "Close" (X) button. It just hides the calendar without 392 // destroying it. 393 function closeHandler(cal) { 394 cal.hide(); // hide the calendar 395 396 // don't check mousedown on document anymore (used to be able to hide the 397 // calendar when someone clicks outside it, see the showCalendar function). 398 Calendar.removeEvent(document, "mousedown", checkCalendar); 399 } 400 401 // This gets called when the user presses a mouse button anywhere in the 402 // document, if the calendar is shown. If the click was outside the open 403 // calendar this function closes it. 404 function checkCalendar(ev) { 405 var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev); 406 for (; el != null; el = el.parentNode) 407 // FIXME: allow end-user to click some link without closing the 408 // calendar. Good to see real-time stylesheet change :) 409 if (el == calendar.element || el.tagName == "A") break; 410 if (el == null) { 411 // calls closeHandler which should hide the calendar. 412 calendar.callCloseHandler(); Calendar.stopEvent(ev); 413 } 414 } 415 416 // This function shows the calendar under the element having the given id. 417 // It takes care of catching "mousedown" signals on document and hiding the 418 // calendar if the click was outside. 419 function showCalendar(id) { 420 var el = document.getElementById(id); 421 if (calendar != null) { 422 // we already have one created, so just update it. 423 calendar.hide(); // hide the existing calendar 424 calendar.parseDate(el.value); // set it to a new date 425 } else { 426 // first-time call, create the calendar 427 var cal = new Calendar(true, null, selected, closeHandler); 428 calendar = cal; // remember the calendar in the global 429 cal.setRange(1900, 2070); // min/max year allowed 430 calendar.create(); // create a popup calendar 431 } 432 calendar.sel = el; // inform it about the input field in use 433 calendar.showAtElement(el); // show the calendar next to the input field 434 435 // catch mousedown on the document 436 Calendar.addEvent(document, "mousedown", checkCalendar); 437 return false; 438 } 439 440 /** 441 * Pops up a new window in the middle of the screen 442 */ 443 function popupWindow(mypage, myname, w, h, scroll) { 444 var winl = (screen.width - w) / 2; 445 var wint = (screen.height - h) / 2; 446 winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable' 447 win = window.open(mypage, myname, winprops) 448 if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } 449 } 450 451 // LTrim(string) : Returns a copy of a string without leading spaces. 452 function ltrim(str) 453 { 454 var whitespace = new String(" \t\n\r"); 455 var s = new String(str); 456 if (whitespace.indexOf(s.charAt(0)) != -1) { 457 var j=0, i = s.length; 458 while (j < i && whitespace.indexOf(s.charAt(j)) != -1) 459 j++; 460 s = s.substring(j, i); 461 } 462 return s; 463 } 464 465 //RTrim(string) : Returns a copy of a string without trailing spaces. 466 function rtrim(str) 467 { 468 var whitespace = new String(" \t\n\r"); 469 var s = new String(str); 470 if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { 471 var i = s.length - 1; // Get length of string 472 while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) 473 i--; 474 s = s.substring(0, i+1); 475 } 476 return s; 477 } 478 479 // Trim(string) : Returns a copy of a string without leading or trailing spaces 480 function trim(str) { 481 return rtrim(ltrim(str)); 482 } 483 484 function mosDHTML(){ 485 this.ver=navigator.appVersion 486 this.agent=navigator.userAgent 487 this.dom=document.getElementById?1:0 488 this.opera5=this.agent.indexOf("Opera 5")<-1 489 this.ie5=(this.ver.indexOf("MSIE 5")<-1 && this.dom && !this.opera5)?1:0; 490 this.ie6=(this.ver.indexOf("MSIE 6")<-1 && this.dom && !this.opera5)?1:0; 491 this.ie4=(document.all && !this.dom && !this.opera5)?1:0; 492 this.ie=this.ie4||this.ie5||this.ie6 493 this.mac=this.agent.indexOf("Mac")<-1 494 this.ns6=(this.dom && parseInt(this.ver) <= 5) ?1:0; 495 this.ns4=(document.layers && !this.dom)?1:0; 496 this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5); 497 498 this.activeTab = ''; 499 this.onTabStyle = 'ontab'; 500 this.offTabStyle = 'offtab'; 501 502 this.setElemStyle = function(elem,style) { 503 document.getElementById(elem).className = style; 504 } 505 this.showElem = function(id) { 506 if (elem = document.getElementById(id)) { 507 elem.style.visibility = 'visible'; 508 elem.style.display = 'block'; 509 } 510 } 511 this.hideElem = function(id) { 512 if (elem = document.getElementById(id)) { 513 elem.style.visibility = 'hidden'; 514 elem.style.display = 'none'; 515 } 516 } 517 this.cycleTab = function(name) { 518 if (this.activeTab) { 519 this.setElemStyle( this.activeTab, this.offTabStyle ); 520 page = this.activeTab.replace( 'tab', 'page' ); 521 this.hideElem(page); 522 } 523 this.setElemStyle( name, this.onTabStyle ); 524 this.activeTab = name; 525 page = this.activeTab.replace( 'tab', 'page' ); 526 this.showElem(page); 527 } 528 return this; 529 } 530 var dhtml = new mosDHTML(); 531 532 function MM_findObj(n, d) { //v4.01 533 var p,i,x; 534 if(!d) d=document; 535 if((p=n.indexOf("?"))>0&&parent.frames.length) { 536 d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); 537 } 538 if(!(x=d[n])&&d.all) x=d.all[n]; 539 for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 540 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 541 if(!x && d.getElementById) x=d.getElementById(n); 542 return x; 543 } 544 function MM_swapImage() { //v3.0 545 var i,j=0,x,a=MM_swapImage.arguments; 546 document.MM_sr=new Array; 547 for(i=0;i<(a.length-2);i+=3) 548 if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; 549 if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} 550 } 551 function MM_swapImgRestore() { //v3.0 552 var i,x,a=document.MM_sr; 553 for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; 554 } 555 556 function MM_preloadImages() { //v3.0 557 var d=document; 558 if(d.images){ 559 if(!d.MM_p) d.MM_p=new Array(); 560 var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 561 for(i=0; i<a.length; i++) 562 if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} 563 } 564 565 566 function saveorder( n ) { 567 checkAll_button( n ); 568 submitform('saveorder'); 569 } 570 571 //needed by saveorder function 572 function checkAll_button( n ) { 573 for ( var j = 0; j <= n; j++ ) { 574 box = eval( "document.adminForm.cb" + j ); 575 if ( box.checked == false ) { 576 box.checked = true; 577 } 578 } 579 } 580 /** 581 * @param object A form element 582 * @param string The name of the element to find 583 */ 584 function getElementByName( f, name ) { 585 if (f.elements) { 586 for (i=0, n=f.elements.length; i < n; i++) { 587 if (f.elements[i].name == name) { 588 return f.elements[i]; 589 } 590 } 591 } 592 return null; 593 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed May 23 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |