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