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 ) { 172alert(); 173 var form = eval( 'document.' + frmName ); 174 var srcList = eval( 'form.' + srcListName ); 175 176 var srcLen = srcList.length; 177 178 for (var i=0; i < srcLen; i++) { 179 srcList.options[i].selected = false;
180 if (srcList.options[i].value == value) { 181 srcList.options[i].selected = true; 182 } 183 } 184} 185 186function getSelectedRadio( frmName, srcGroupName ) { 187 var form = eval( 'document.' + frmName ); 188 var srcGroup = eval( 'form.' + srcGroupName ); 189 190 return radioGetCheckedValue( srcGroup ); 191} 192 193// return the value of the radio button that is checked 194// return an empty string if none are checked, or 195// there are no radio buttons 196function radioGetCheckedValue(radioObj) { 197 if (!radioObj) { 198 return ''; 199 } 200 var n = radioObj.length; 201 if (n == undefined) { 202 if (radioObj.checked) { 203 return radioObj.value; 204 } else { 205 return ''; 206 } 207 } 208 for (var i = 0; i < n; i++) { 209 if(radioObj[i].checked) { 210 return radioObj[i].value; 211 } 212 } 213 return ''; 214} 215 216function getSelectedValue( frmName, srcListName ) { 217 var form = eval( 'document.' + frmName ); 218 var srcList = eval( 'form.' + srcListName ); 219 220 i = srcList.selectedIndex; 221 if (i != null && i > -1) { 222 return srcList.options[i].value; 223 } else { 224 return null; 225 } 226} 227 228function getSelectedText( frmName, srcListName ) { 229 var form = eval( 'document.' + frmName ); 230 var srcList = eval( 'form.' + srcListName ); 231 232 i = srcList.selectedIndex; 233 if (i != null && i > -1) { 234 return srcList.options[i].text; 235 } else { 236 return null; 237 } 238} 239 240function chgSelectedValue( frmName, srcListName, value ) { 241 var form = eval( 'document.' + frmName ); 242 var srcList = eval( 'form.' + srcListName ); 243 244 i = srcList.selectedIndex; 245 if (i != null && i > -1) { 246 srcList.options[i].value = value; 247 return true; 248 } else { 249 return false; 250 } 251} 252 253/** 254* Toggles the check state of a group of boxes 255* 256* Checkboxes must have an id attribute in the form cb0, cb1... 257* @param The number of box to 'check' 258* @param An alternative field name 259*/ 260 261function listItemTask( id, task ) { 262 var f = document.adminForm; 263 cb = eval( 'f.' + id ); 264 if (cb) { 265 for (i = 0; true; i++) { 266 cbx = eval('f.cb'+i); 267 if (!cbx) break; 268 cbx.checked = false; 269 } // for 270 cb.checked = true; 271 f.boxchecked.value = 1; 272 submitbutton(task); 273 } 274 return false; 275} 276 277function hideMainMenu() { 278 if (document.adminForm.hidemainmenu) { 279 document.adminForm.hidemainmenu.value=1; 280 } 281} 282 283function isChecked(isitchecked){ 284 if (isitchecked == true){ 285 document.adminForm.boxchecked.value++; 286 } 287 else { 288 document.adminForm.boxchecked.value--; 289 } 290} 291 292/** 293* Default function. Usually would be overriden by the component 294*//* 295function submitbutton(pressbutton) { 296 submitform(pressbutton); 297} 298*/ 299/** 300* Submit the admin form 301*/ 302function submitform(pressbutton){ 303 if (pressbutton) { 304 document.adminForm.task.value=pressbutton; 305 } 306 if (typeof document.adminForm.onsubmit == "function") { 307 document.adminForm.onsubmit(); 308 } 309 document.adminForm.submit(); 310} 311 312/** 313* Submit the control panel admin form 314*/ 315function submitcpform(sectionid, id){ 316 document.adminForm.sectionid.value=sectionid; 317 document.adminForm.id.value=id; 318 submitbutton("edit"); 319} 320 321/** 322* Getting radio button that is selected. 323*/ 324function getSelected(allbuttons){ 325 for (i=0;i<allbuttons.length;i++) { 326 if (allbuttons[i].checked) { 327 return allbuttons[i].value 328 } 329 } 330 return null; 331} 332 333// JS Calendar 334var calendar = null; // remember the calendar object so that we reuse 335// it and avoid creating another 336 337// This function gets called when an end-user clicks on some date 338function selected(cal, date) { 339 cal.sel.value = date; // just update the value of the input field 340 cal.sel.focus(); 341} 342 343// And this gets called when the end-user clicks on the _selected_ date, 344// or clicks the "Close" (X) button. It just hides the calendar without 345// destroying it. 346function closeHandler(cal) { 347 cal.hide(); // hide the calendar 348 349 // don't check mousedown on document anymore (used to be able to hide the 350 // calendar when someone clicks outside it, see the showCalendar function). 351 Calendar.removeEvent(document, "mousedown", checkCalendar); 352} 353 354// This gets called when the user presses a mouse button anywhere in the 355// document, if the calendar is shown. If the click was outside the open 356// calendar this function closes it. 357function checkCalendar(ev) { 358 var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev); 359 for (; el != null; el = el.parentNode) 360 // FIXME: allow end-user to click some link without closing the 361 // calendar. Good to see real-time stylesheet change :) 362 if (el == calendar.element || el.tagName == "A") break; 363 if (el == null) { 364 // calls closeHandler which should hide the calendar. 365 calendar.callCloseHandler(); Calendar.stopEvent(ev); 366 } 367} 368 369// This function shows the calendar under the element having the given id. 370// It takes care of catching "mousedown" signals on document and hiding the 371// calendar if the click was outside. 372 373 374function showCalendar(id, dateFormat, dis_past_days) { 375 var el = document.getElementById(id); 376 if (calendar != null) { 377 if ( dateFormat ) // optional date format 378 { 379 calendar.setDateFormat(dateFormat); 380 } 381// we already have one created, so just update it. 382 calendar.hide(); // hide the existing calendar 383 calendar.parseDate(el.value); // set it to a new date 384 if(dis_past_days) 385 calendar.getDateStatus = getDisabledDates; // disable past days 386 else 387 calendar.getDateStatus = null; // disable past days 388 calendar.refresh(); 389 } else { 390// first-time call, create the calendar 391 var cal = new Calendar(true, null, selected, closeHandler); 392 calendar = cal; // remember the calendar in the global 393 cal.setRange(1900, 2070); // min/max year allowed 394 395 if ( dateFormat ) // optional date format 396 { 397 cal.setDateFormat(dateFormat); 398 } 399 if(dis_past_days) 400 cal.getDateStatus = getDisabledDates; // disable past days 401 calendar.create(); // create a popup calendar 402 calendar.parseDate(el.value); // set it to a new date 403 } 404 calendar.sel = el; // inform it about the input field in use 405 calendar.showAtElement(el); // show the calendar next to the input field 406 407 // catch mousedown on the document 408 Calendar.addEvent(document, "mousedown", checkCalendar); 409 return false;
410} 411 412 413 414 415 416 417 418 419function getDisabledDates(date) { 420 var currentDate = new Date(); 421 if( date.getDate() == currentDate.getDate() && date.getMonth() == currentDate.getMonth() && date.getFullYear() == currentDate.getFullYear() ) 422 return 'today'; 423 424 if( date.getTime() < currentDate.getTime() ) 425 return true; 426} 427 428/** 429* Pops up a new window in the middle of the screen 430*/ 431function popupWindow(mypage, myname, w, h, scroll) { 432 var winl = (screen.width - w) / 2; 433 var wint = (screen.height - h) / 2; 434 winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable' 435 win = window.open(mypage, myname, winprops) 436 if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } 437} 438 439// LTrim(string) : Returns a copy of a string without leading spaces. 440function ltrim(str) 441{ 442 var whitespace = new String(" \t\n\r"); 443 var s = new String(str); 444 if (whitespace.indexOf(s.charAt(0)) != -1) { 445 var j=0, i = s.length; 446 while (j < i && whitespace.indexOf(s.charAt(j)) != -1) 447 j++; 448 s = s.substring(j, i); 449 } 450 return s; 451} 452 453//RTrim(string) : Returns a copy of a string without trailing spaces. 454function rtrim(str) 455{ 456 var whitespace = new String(" \t\n\r"); 457 var s = new String(str); 458 if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { 459 var i = s.length - 1; // Get length of string 460 while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) 461 i--; 462 s = s.substring(0, i+1); 463 } 464 return s; 465} 466 467// Trim(string) : Returns a copy of a string without leading or trailing spaces 468function trim(str) { 469 return rtrim(ltrim(str)); 470} 471 472function mosDHTML(){ 473 this.ver=navigator.appVersion 474 this.agent=navigator.userAgent 475 this.dom=document.getElementById?1:0 476 this.opera5=this.agent.indexOf("Opera 5")<-1 477 this.ie5=(this.ver.indexOf("MSIE 5")<-1 && this.dom && !this.opera5)?1:0; 478 this.ie6=(this.ver.indexOf("MSIE 6")<-1 && this.dom && !this.opera5)?1:0; 479 this.ie4=(document.all && !this.dom && !this.opera5)?1:0; 480 this.ie=this.ie4||this.ie5||this.ie6 481 this.mac=this.agent.indexOf("Mac")<-1 482 this.ns6=(this.dom && parseInt(this.ver) <= 5) ?1:0; 483 this.ns4=(document.layers && !this.dom)?1:0; 484 this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5); 485 486 this.activeTab = ''; 487 this.onTabStyle = 'ontab'; 488 this.offTabStyle = 'offtab'; 489 490 this.setElemStyle = function(elem,style) { 491 document.getElementById(elem).className = style; 492 } 493 this.showElem = function(id) { 494 if ((elem = document.getElementById(id))) { 495 elem.style.visibility = 'visible'; 496 elem.style.display = 'block'; 497 } 498 } 499 this.hideElem = function(id) { 500 if ((elem = document.getElementById(id))) { 501 elem.style.visibility = 'hidden'; 502 elem.style.display = 'none'; 503 } 504 } 505 this.cycleTab = function(name) { 506 if (this.activeTab) { 507 this.setElemStyle( this.activeTab, this.offTabStyle ); 508 page = this.activeTab.replace( 'tab', 'page' ); 509 this.hideElem(page); 510 } 511 this.setElemStyle( name, this.onTabStyle ); 512 this.activeTab = name; 513 page = this.activeTab.replace( 'tab', 'page' ); 514 this.showElem(page); 515 } 516 return this; 517} 518var dhtml = new mosDHTML(); 519 520// needed for Table Column ordering 521function tableOrdering( order, dir, task ) { 522 var form = document.adminForm; 523 524 form.filter_order.value = order; 525 form.filter_order_Dir.value = dir; 526 submitform( task ); 527} 528 529function saveorder( n, task ) { 530 checkAll_button( n, task ); 531} 532 533//needed by saveorder function 534function checkAll_button( n, task ) { 535 536 if (!task ) { 537 task = 'saveorder'; 538 } 539 540 for ( var j = 0; j <= n; j++ ) { 541 box = eval( "document.adminForm.cb" + j ); 542 if ( box ) { 543 if ( box.checked == false ) { 544 box.checked = true; 545 } 546 } else { 547 alert("You cannot change the order of items, as an item in the list is `Checked Out`"); 548 return; 549 } 550 } 551 submitform(task); 552} 553/** 554* @param object A form element 555* @param string The name of the element to find 556*/ 557function getElementByName( f, name ) { 558 if (f.elements) { 559 for (i=0, n=f.elements.length; i < n; i++) { 560 if (f.elements[i].name == name) { 561 return f.elements[i]; 562 } 563 } 564 } 565 return null; 566} 567 568function go2( pressbutton, menu, id ) { 569 var form = document.adminForm; 570 571 if (form.imagelist && form.images) { 572 // assemble the images back into one field 573 var temp = new Array; 574 for (var i=0, n=form.imagelist.options.length; i < n; i++) { 575 temp[i] = form.imagelist.options[i].value; 576 } 577 form.images.value = temp.join( '\n' ); 578 } 579 580 if (pressbutton == 'go2menu') { 581 form.menu.value = menu; 582 submitform( pressbutton ); 583 return; 584 } 585 586 if (pressbutton == 'go2menuitem') { 587 form.menu.value = menu; 588 form.menuid.value = id; 589 submitform( pressbutton ); 590 return; 591 } 592} 593/** 594 * Verifies if the string is in a valid email format 595 * @param string 596 * @return boolean 597 */ 598function isEmail( text ) 599{ 600 var pattern = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$"; 601 var regex = new RegExp( pattern ); 602 return regex.test( text ); 603}
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.