| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: behavior.php 18130 2010-07-14 11:21:35Z louis $ 4 * @package Joomla.Framework 5 * @subpackage HTML 6 * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * 9 * Joomla! is free software. This version may have been modified pursuant 10 * to the GNU General Public License, and as distributed it includes or 11 * is derivative of works licensed under the GNU General Public License or 12 * other free or open source software licenses. 13 * See COPYRIGHT.php for copyright notices and details. 14 */ 15 16 defined('JPATH_BASE') or die(); 17 18 /** 19 * JHTML helper class for loading JavaScript behaviors into the document head. This version is 20 * designed to load MooTools version 1.2 plus the 1.1 compatibility layer. 21 * 22 * @package Joomla.Framework 23 * @subpackage HTML 24 * 25 * @since 1.5.19 26 * @static 27 */ 28 class JHTMLBehavior 29 { 30 /** 31 * Method to load the mootools framework and compatibility layer into the document head. If the 32 * optional debug flag is set then a uncompressed version of the files will be loaded. 33 * 34 * @param boolean $debug True to enable debugging mode. If no value is set the value will 35 * be taken from the application configuration settings. 36 * 37 * @return void 38 * 39 * @since 1.5.19 40 * @static 41 */ 42 function mootools($debug = null) 43 { 44 // Check to see if it has already been loaded. 45 static $loaded; 46 if (!empty($loaded)) { 47 return; 48 } 49 50 // If no debugging value is set, use the setting from the application configuration. 51 if ($debug === null) { 52 $debug = JFactory::getConfig()->getValue('config.debug'); 53 } 54 55 /* 56 * Note: Konqueror browser check. 57 * - If they fix thier issue with compressed javascript we can remove this. 58 */ 59 $kcheck = isset($_SERVER['HTTP_USER_AGENT']) ? strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'konqueror') : null; 60 61 // If the debugging flag is set or the browser is Konqueror use the uncompressed file. 62 if ($debug || $kcheck) { 63 JHTML::script('mootools-uncompressed.js', 'plugins/system/mtupgrade/', false); 64 } 65 else { 66 JHTML::script('mootools.js', 'plugins/system/mtupgrade/', false); 67 } 68 69 // Set the MooTools version string in the application object. 70 JFactory::getApplication()->set('MooToolsVersion', '1.2.4 +Compat'); 71 72 // Ensure the files aren't loaded more than once. 73 $loaded = true; 74 } 75 76 /** 77 * Method to load the system caption behavior. 78 * 79 * @return void 80 * 81 * @since 1.5.19 82 * @static 83 */ 84 function caption() 85 { 86 JHTML::script('caption.js'); 87 } 88 89 /** 90 * Method to load the system form validation behavior. 91 * 92 * @return void 93 * 94 * @since 1.5.19 95 * @static 96 */ 97 function formvalidation() 98 { 99 JHTML::script('validate.js'); 100 } 101 102 /** 103 * Method to load the system container switcher behavior. 104 * 105 * @return void 106 * 107 * @since 1.5.19 108 * @static 109 */ 110 function switcher() 111 { 112 JHTML::script('switcher.js'); 113 } 114 115 /** 116 * Method to load the system combobox behavior. 117 * 118 * @return void 119 * 120 * @since 1.5.19 121 * @static 122 */ 123 function combobox() 124 { 125 JHTML::script('combobox.js'); 126 } 127 128 /** 129 * Method to load the system tooltips behavior. Because the tooltips class and interface has 130 * changed between Mootools 1.2 and 1.1, we are including our 1.2 version and making it to work 131 * in the same way as the old one. 132 * 133 * @param string $selector The CSS selector for elements to apply the behavior. 134 * @param array $params The array of options to use for the behavior. 135 * 136 * @return void 137 * 138 * @since 1.5.19 139 * @static 140 */ 141 function tooltip($selector='.hasTip', $params = array()) 142 { 143 // Setup the static array of tooltip instance options. 144 static $instances; 145 if (!isset($instances)) { 146 $instances = array(); 147 } 148 149 // Generate the behavior/option signature and check to see if it has already been loaded. 150 $sig = md5(serialize(array($selector,$params))); 151 if (!empty($instances[$sig])) { 152 return; 153 } 154 155 // Load the Mootools framework. 156 JHTMLBehavior::mootools(); 157 158 // Setup the options object. 159 $opt['maxTitleChars'] = (isset($params['maxTitleChars']) && ($params['maxTitleChars'])) ? (int)$params['maxTitleChars'] : 50 ; 160 $opt['showDelay'] = (isset($params['showDelay'])) ? (int)$params['showDelay'] : null; 161 $opt['hideDelay'] = (isset($params['hideDelay'])) ? (int)$params['hideDelay'] : null; 162 $opt['className'] = (isset($params['className'])) ? $params['className'] : null; 163 $opt['fixed'] = (isset($params['fixed']) && ($params['fixed'])) ? '\\true' : '\\false'; 164 165 // Optional event handler methods. 166 $opt['onShow'] = (isset($params['onShow'])) ? '\\'.$params['onShow'] : null; 167 $opt['onHide'] = (isset($params['onHide'])) ? '\\'.$params['onHide'] : null; 168 169 // Offsets needs an array in the format: array('x'=>20, 'y'=>30). 170 $opt['offsets'] = (isset($params['offsets']) && (is_array($params['offsets']))) ? $params['offsets'] : null; 171 172 // Build the script. 173 $script = array( 174 'window.addEvent("domready", function() {', 175 ' var JTooltips = new Tips($$("'.$selector.'"), '.JHTMLBehavior::_getJSObject($opt).');', 176 '});' 177 ); 178 179 // Load the script into the document head. 180 JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); 181 182 // Ensure the same instance isn't loaded more than once. 183 $instances[$sig] = true; 184 } 185 186 /** 187 * Method to load the system modal behavior. 188 * 189 * @param string $selector The CSS selector for elements to apply the behavior. 190 * @param array $params The array of options to use for the behavior. 191 * 192 * @return void 193 * 194 * @since 1.5.19 195 * @static 196 */ 197 function modal($selector='a.modal', $params = array()) 198 { 199 // Setup the static array of modal instance options. 200 static $instances; 201 if (!isset($instances)) { 202 $instances = array(); 203 } 204 205 // Generate the behavior/option signature and check to see if it has already been loaded. 206 $sig = md5(serialize(array($selector,$params))); 207 if (!empty($instances[$sig])) { 208 return; 209 } 210 211 // Load the behavior and stylesheet files into the document head. 212 JHTML::script('modal.js'); 213 JHTML::stylesheet('modal.css'); 214 215 // Setup the options object. 216 $opt['ajaxOptions'] = (isset($params['ajaxOptions']) && (is_array($params['ajaxOptions']))) ? $params['ajaxOptions'] : null; 217 $opt['size'] = (isset($params['size']) && (is_array($params['size']))) ? $params['size'] : null; 218 219 // Optional event handler methods. 220 $opt['onOpen'] = (isset($params['onOpen'])) ? $params['onOpen'] : null; 221 $opt['onClose'] = (isset($params['onClose'])) ? $params['onClose'] : null; 222 $opt['onUpdate'] = (isset($params['onUpdate'])) ? $params['onUpdate'] : null; 223 $opt['onResize'] = (isset($params['onResize'])) ? $params['onResize'] : null; 224 $opt['onMove'] = (isset($params['onMove'])) ? $params['onMove'] : null; 225 $opt['onShow'] = (isset($params['onShow'])) ? $params['onShow'] : null; 226 $opt['onHide'] = (isset($params['onHide'])) ? $params['onHide'] : null; 227 228 // Build the script. 229 $script = array( 230 'window.addEvent("domready", function() {', 231 ' SqueezeBox.initialize('.JHTMLBehavior::_getJSObject($opt).');', 232 ' $$("'.$selector.'").each(function(el) {', 233 ' el.addEvent("click", function(e) {', 234 ' new Event(e).stop();', 235 ' SqueezeBox.fromElement(el);', 236 ' });', 237 ' });', 238 '});' 239 ); 240 241 // Load the script into the document head. 242 JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); 243 244 // Ensure the same instance isn't loaded more than once. 245 $instances[$sig] = true; 246 } 247 248 /** 249 * Method to load the system file uploader behavior. 250 * 251 * @param string $id The DOM node id for the element to apply the behavior. 252 * @param array $params The array of options to use for the behavior. 253 * 254 * @return void 255 * 256 * @since 1.5.19 257 * @static 258 */ 259 function uploader($id='file-upload', $params = array()) 260 { 261 // Setup the static array of behavior instances. 262 static $instances; 263 if (!isset($instances)) { 264 $instances = array(); 265 } 266 267 // Check to see if it has already been loaded. 268 if (!empty($instances[$id])) { 269 return; 270 } 271 272 // Load the behavior files into the document head. 273 JHTML::script('swf.js'); 274 JHTML::script('uploader.js'); 275 276 // Setup the options object. 277 $opt['url'] = (isset($params['targetURL'])) ? $params['targetURL'] : null ; 278 $opt['swf'] = (isset($params['swf'])) ? $params['swf'] : JURI::root(true).'/media/system/swf/uploader.swf'; 279 $opt['multiple'] = (isset($params['multiple']) && !($params['multiple'])) ? '\\false' : '\\true'; 280 $opt['queued'] = (isset($params['queued']) && !($params['queued'])) ? '\\false' : '\\true'; 281 $opt['queueList'] = (isset($params['queueList'])) ? $params['queueList'] : 'upload-queue'; 282 $opt['instantStart'] = (isset($params['instantStart']) && ($params['instantStart'])) ? '\\true' : '\\false'; 283 $opt['allowDuplicates'] = (isset($params['allowDuplicates']) && !($params['allowDuplicates'])) ? '\\false' : '\\true'; 284 $opt['limitSize'] = (isset($params['limitSize']) && ($params['limitSize'])) ? (int)$params['limitSize'] : null; 285 $opt['limitFiles'] = (isset($params['limitFiles']) && ($params['limitFiles'])) ? (int)$params['limitFiles'] : null; 286 $opt['optionFxDuration'] = (isset($params['optionFxDuration'])) ? (int)$params['optionFxDuration'] : null; 287 $opt['container'] = (isset($params['container'])) ? '\\$('.$params['container'].')' : '\\$(\''.$id.'\').getParent()'; 288 289 // JSON object with ('description': 'extension') pairs. eg. (default: Images (*.jpg; *.jpeg; *.gif; *.png)); 290 $opt['types'] = (isset($params['types'])) ?'\\'.$params['types'] : '\\{\'All Files (*.*)\': \'*.*\'}'; 291 292 // Optional functions. 293 $opt['createReplacement'] = (isset($params['createReplacement'])) ? '\\'.$params['createReplacement'] : null; 294 $opt['onComplete'] = (isset($params['onComplete'])) ? '\\'.$params['onComplete'] : null; 295 $opt['onAllComplete'] = (isset($params['onAllComplete'])) ? '\\'.$params['onAllComplete'] : null; 296 297 // Build the script. 298 $script = array( 299 'sBrowseCaption="'.JText::_('Browse Files', true).'";', 300 'sRemoveToolTip="'.JText::_('Remove from queue', true).'";', 301 '', 302 'window.addEvent("load", function() {', 303 ' var Uploader = new FancyUpload($("'.$id.'"), '.JHTMLBehavior::_getJSObject($opt).');', 304 ' $("upload-clear").adopt(new Element("input", {type: "button", events: { click: Uploader.clearList.bind(Uploader, [false])}, value: "'.JText::_('Clear Completed').'" }));', 305 '});' 306 ); 307 308 // Load the script into the document head. 309 JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); 310 311 // Ensure the same instance isn't loaded more than once. 312 $instances[$id] = true; 313 } 314 315 /** 316 * Method to load the system tree behavior. 317 * 318 * @param string $id The DOM node id for the element to apply the behavior. 319 * @param array $params The array of options to use for the behavior. 320 * @param array $root The array of root node options. 321 * 322 * @return void 323 * 324 * @since 1.5.19 325 * @static 326 */ 327 function tree($id, $params = array(), $root = array()) 328 { 329 // Setup the static array of behavior instances. 330 static $instances; 331 if (!isset($instances)) { 332 $instances = array(); 333 } 334 335 // Check to see if it has already been loaded. 336 if (!empty($instances[$id])) { 337 return; 338 } 339 340 // Load the behavior and stylesheet files into the document head. 341 JHTML::script('mootree.js'); 342 JHTML::stylesheet('mootree.css'); 343 344 // Setup the options object. 345 $opt['div'] = (isset($params['div'])) ? $params['div'] : $id.'_tree'; 346 $opt['mode'] = (isset($params['mode'])) ? $params['mode'] : 'folders'; 347 $opt['grid'] = (isset($params['grid'])) ? '\\'.$params['grid'] : '\\true'; 348 $opt['theme'] = (isset($params['theme'])) ? $params['theme'] : JURI::root(true).'/media/system/images/mootree.gif'; 349 350 // Optional event handler methods. 351 $opt['onExpand'] = (isset($params['onExpand'])) ? '\\'.$params['onExpand'] : null; 352 $opt['onSelect'] = (isset($params['onSelect'])) ? '\\'.$params['onSelect'] : null; 353 $opt['onClick'] = (isset($params['onClick'])) ? '\\'.$params['onClick'] : '\\function(node){ window.open(node.data.url, $chk(node.data.target) ? node.data.target : \'_self\'); }'; 354 355 // Setup the root node options. 356 $rt['text'] = (isset($root['text'])) ? $root['text'] : 'Root'; 357 $rt['id'] = (isset($root['id'])) ? $root['id'] : null; 358 $rt['color'] = (isset($root['color'])) ? $root['color'] : null; 359 $rt['open'] = (isset($root['open'])) ? '\\'.$root['open'] : '\\true'; 360 $rt['icon'] = (isset($root['icon'])) ? $root['icon'] : null; 361 $rt['openicon'] = (isset($root['openicon'])) ? $root['openicon'] : null; 362 $rt['data'] = (isset($root['data'])) ? $root['data'] : null; 363 364 // Get the optional name of the tree. 365 $name = (isset($params['treeName'])) ? $params['treeName'] : ''; 366 367 // Build the script. 368 $script = array( 369 'window.addEvent(\'domready\', function(){', 370 ' tree'.$name.' = new MooTreeControl('.JHTMLBehavior::_getJSObject($opt).','.JHTMLBehavior::_getJSObject($rt).');', 371 ' tree'.$name.'.adopt(\''.$id.'\');', 372 '})' 373 ); 374 375 // Load the script into the document head. 376 JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); 377 378 // Ensure the same instance isn't loaded more than once. 379 $instances[$id] = true; 380 } 381 382 /** 383 * Method to load the system calendar behavior. 384 * 385 * @return void 386 * 387 * @since 1.5.19 388 * @static 389 */ 390 function calendar() 391 { 392 // Load the behavior and stylesheet files into the document head. 393 JHTML::stylesheet('calendar-jos.css', 'media/system/css/', array(' title' => JText::_('green') ,' media' => 'all')); 394 JHTML::script('calendar.js'); 395 JHTML::script('calendar-setup.js'); 396 397 // Get and load the calendar translation string into the document head. 398 if ($translation = JHTMLBehavior::_calendartranslation()) { 399 JFactory::getDocument()->addScriptDeclaration($translation); 400 } 401 } 402 403 /** 404 * Method to load the system keepalive behavior. This will send an ascynchronous request to the 405 * server via AJAX on an interval just under the session expiration lifetime so that the session 406 * does not expire. 407 * 408 * @return void 409 * 410 * @since 1.5.19 411 * @static 412 */ 413 function keepalive() 414 { 415 // Load the behavior framework into the document head. 416 JHTMLBehavior::mootools(); 417 418 // Get the session lifetime in microseconds. 419 $lifetime = (JFactory::getConfig()->getValue('lifetime', 900) * 60000); 420 421 // Set the session refresh period to one minute less than the session lifetime. 422 $refreshTime = (int) ($lifetime <= 60000) ? 30000 : $lifetime - 60000; 423 424 // Build the keepalive script. 425 $script = array( 426 'function keepAlive() { new Ajax("index.php", {method: "get"}).request(); }', 427 'window.addEvent("domready", function() { keepAlive.periodical('.$refreshTime.'); });' 428 ); 429 430 // Load the keepalive script into the document head. 431 JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); 432 } 433 434 /** 435 * Method to get a simple JavaScript Object Notation (JSON) representation of an input 436 * associative array. 437 * 438 * @param array $array The array to convert to JavaScript Object Notation. 439 * 440 * @return string JavaScript Object Notation representation of the array. 441 * 442 * @access protected 443 * @since 1.5.19 444 * @static 445 */ 446 function _getJSObject($array = array()) 447 { 448 // Initialize variables 449 $json = '{'; 450 451 // Iterate over array to build objects 452 foreach ((array)$array as $k => $v) 453 { 454 if (is_null($v)) { 455 continue; 456 } 457 458 if (!is_array($v) && !is_object($v)) { 459 $json .= ' '.$k.': '; 460 $json .= (is_numeric($v) || strpos($v, '\\') === 0) ? (is_numeric($v)) ? $v : substr($v, 1) : "'".$v."'"; 461 $json .= ','; 462 } 463 else { 464 $json .= ' '.$k.': '.JHTMLBehavior::_getJSObject($v).','; 465 } 466 } 467 468 if (substr($json, -1) == ',') { 469 $json = substr($json, 0, -1); 470 } 471 472 $json .= '}'; 473 474 return $json; 475 } 476 477 /** 478 * Method to get the internationalisation script/settings for the JavaScript Calendar behavior. 479 * 480 * @return mixed JavaScript calendar internationalisation settings script or null if already loaded. 481 * 482 * @access protected 483 * @since 1.5.19 484 * @static 485 */ 486 function _calendartranslation() 487 { 488 // Check to see if it has already been loaded. 489 static $loaded; 490 if (!empty($loaded)) { 491 return; 492 } 493 494 // Build the day names array. 495 $dayNames = array( 496 '"'.JText::_('Sunday').'"', 497 '"'.JText::_('Monday').'"', 498 '"'.JText::_('Tuesday').'"', 499 '"'.JText::_('Wednesday').'"', 500 '"'.JText::_('Thursday').'"', 501 '"'.JText::_('Friday').'"', 502 '"'.JText::_('Saturday').'"', 503 '"'.JText::_('Sunday').'"' 504 ); 505 506 // Build the short day names array. 507 $shortDayNames = array( 508 '"'.JText::_('Sun').'"', 509 '"'.JText::_('Mon').'"', 510 '"'.JText::_('Tue').'"', 511 '"'.JText::_('Wed').'"', 512 '"'.JText::_('Thu').'"', 513 '"'.JText::_('Fri').'"', 514 '"'.JText::_('Sat').'"', 515 '"'.JText::_('Sun').'"' 516 ); 517 518 // Build the month names array. 519 $monthNames = array( 520 '"'.JText::_('January').'"', 521 '"'.JText::_('February').'"', 522 '"'.JText::_('March').'"', 523 '"'.JText::_('April').'"', 524 '"'.JText::_('May').'"', 525 '"'.JText::_('June').'"', 526 '"'.JText::_('July').'"', 527 '"'.JText::_('August').'"', 528 '"'.JText::_('September').'"', 529 '"'.JText::_('October').'"', 530 '"'.JText::_('November').'"', 531 '"'.JText::_('December').'"' 532 ); 533 534 // Build the short month names array. 535 $shortMonthNames = array( 536 '"'.JText::_('January_short').'"', 537 '"'.JText::_('February_short').'"', 538 '"'.JText::_('March_short').'"', 539 '"'.JText::_('April_short').'"', 540 '"'.JText::_('May_short').'"', 541 '"'.JText::_('June_short').'"', 542 '"'.JText::_('July_short').'"', 543 '"'.JText::_('August_short').'"', 544 '"'.JText::_('September_short').'"', 545 '"'.JText::_('October_short').'"', 546 '"'.JText::_('November_short').'"', 547 '"'.JText::_('December_short').'"' 548 ); 549 550 // Build the script. 551 $i18n = array( 552 '// Calendar i18n Setup.', 553 'Calendar._FD = 0;', 554 'Calendar._DN = new Array ('.implode(', ', $dayNames).');', 555 'Calendar._SDN = new Array ('.implode(', ', $shortDayNames).');', 556 'Calendar._MN = new Array ('.implode(', ', $monthNames).');', 557 'Calendar._SMN = new Array ('.implode(', ', $shortMonthNames).');', 558 '', 559 'Calendar._TT = {};', 560 'Calendar._TT["INFO"] = "'.JText::_('About the calendar').'";', 561 'Calendar._TT["PREV_YEAR"] = "'.JText::_('Prev. year (hold for menu)').'";', 562 'Calendar._TT["PREV_MONTH"] = "'.JText::_('Prev. month (hold for menu)').'";', 563 'Calendar._TT["GO_TODAY"] = "'.JText::_('Go Today').'";', 564 'Calendar._TT["NEXT_MONTH"] = "'.JText::_('Next month (hold for menu)').'";', 565 'Calendar._TT["NEXT_YEAR"] = "'.JText::_('Next year (hold for menu)').'";', 566 'Calendar._TT["SEL_DATE"] = "'.JText::_('Select date').'";', 567 'Calendar._TT["DRAG_TO_MOVE"] = "'.JText::_('Drag to move').'";', 568 'Calendar._TT["PART_TODAY"] = "'.JText::_('(Today)').'";', 569 'Calendar._TT["DAY_FIRST"] = "'.JText::_('Display %s first').'";', 570 'Calendar._TT["WEEKEND"] = "0,6";', 571 'Calendar._TT["CLOSE"] = "'.JText::_('Close').'";', 572 'Calendar._TT["TODAY"] = "'.JText::_('Today').'";', 573 'Calendar._TT["TIME_PART"] = "'.JText::_('(Shift-)Click or drag to change value').'";', 574 'Calendar._TT["DEF_DATE_FORMAT"] = "'.JText::_('%Y-%m-%d').'";', 575 'Calendar._TT["TT_DATE_FORMAT"] = "'.JText::_('%a, %b %e').'";', 576 'Calendar._TT["WK"] = "'.JText::_('wk').'";', 577 'Calendar._TT["TIME"] = "'.JText::_('Time:').'";', 578 '', 579 'Calendar._TT["ABOUT"] =', 580 '"DHTML Date/Time Selector\n" +', 581 '"(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" +', 582 '"For latest version visit: http://www.dynarch.com/projects/calendar/\n" +', 583 '"Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." +', 584 '"\n\n" +', 585 '"Date selection:\n" +', 586 '"- Use the \xab, \xbb buttons to select year\n" +', 587 '"- Use the " + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " buttons to select month\n" +', 588 '"- Hold mouse button on any of the above buttons for faster selection.";', 589 '', 590 'Calendar._TT["ABOUT_TIME"] = "\n\n" +', 591 '"Time selection:\n" +', 592 '"- Click on any of the time parts to increase it\n" +', 593 '"- or Shift-click to decrease it\n" +', 594 '"- or click and drag for faster selection.";', 595 '' 596 ); 597 598 // Ensure the i18n data isn't loaded more than once. 599 $loaded = true; 600 601 return implode("\n", $i18n); 602 } 603 } 604
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |