[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/html/html/ -> behavior.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: behavior.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla.Framework
   5  * @subpackage    HTML
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  defined('JPATH_BASE') or die();
  15  /**
  16   * Utility class for javascript behaviors
  17   *
  18   * @static
  19   * @package     Joomla.Framework
  20   * @subpackage    HTML
  21   * @version        1.5
  22   */
  23  class JHTMLBehavior
  24  {
  25      /**
  26       * Method to load the mootools framework into the document head
  27       *
  28       * - If debugging mode is on an uncompressed version of mootools is included for easier debugging.
  29       *
  30       * @static
  31       * @param    boolean    $debug    Is debugging mode on? [optional]
  32       * @return    void
  33       * @since    1.5
  34       */
  35  	function mootools($debug = null)
  36      {
  37          static $loaded;
  38  
  39          // Only load once
  40          if ($loaded) {
  41              return;
  42          }
  43  
  44          // If no debugging value is set, use the configuration setting
  45          if ($debug === null) {
  46              $config = &JFactory::getConfig();
  47              $debug = $config->getValue('config.debug');
  48          }
  49  
  50          // TODO NOTE: Here we are checking for Konqueror - If they fix thier issue with compressed, we will need to update this
  51          $konkcheck = isset($_SERVER['HTTP_USER_AGENT']) ? strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "konqueror") : null;
  52  
  53          if ($debug || $konkcheck) {
  54              JHTML::script('mootools-uncompressed.js', 'media/system/js/', false);
  55          } else {
  56              JHTML::script('mootools.js', 'media/system/js/', false);
  57          }
  58          $loaded = true;
  59          return;
  60      }
  61  
  62  		function caption() {
  63          JHTML::script('caption.js');
  64      }
  65  
  66  	function formvalidation() {
  67          JHTML::script('validate.js' );
  68      }
  69  
  70  	function switcher() {
  71          JHTML::script('switcher.js' );
  72      }
  73  
  74  	function combobox() {
  75          JHTML::script('combobox.js' );
  76      }
  77  
  78  	function tooltip($selector='.hasTip', $params = array())
  79      {
  80          static $tips;
  81  
  82          if (!isset($tips)) {
  83              $tips = array();
  84          }
  85  
  86          // Include mootools framework
  87          JHTMLBehavior::mootools();
  88  
  89          $sig = md5(serialize(array($selector,$params)));
  90          if (isset($tips[$sig]) && ($tips[$sig])) {
  91              return;
  92          }
  93  
  94          // Setup options object
  95          $opt['maxTitleChars']    = (isset($params['maxTitleChars']) && ($params['maxTitleChars'])) ? (int)$params['maxTitleChars'] : 50 ;
  96          // offsets needs an array in the format: array('x'=>20, 'y'=>30)
  97          $opt['offsets']            = (isset($params['offsets']) && (is_array($params['offsets']))) ? $params['offsets'] : null;
  98          $opt['showDelay']        = (isset($params['showDelay'])) ? (int)$params['showDelay'] : null;
  99          $opt['hideDelay']        = (isset($params['hideDelay'])) ? (int)$params['hideDelay'] : null;
 100          $opt['className']        = (isset($params['className'])) ? $params['className'] : null;
 101          $opt['fixed']            = (isset($params['fixed']) && ($params['fixed'])) ? '\\true' : '\\false';
 102          $opt['onShow']            = (isset($params['onShow'])) ? '\\'.$params['onShow'] : null;
 103          $opt['onHide']            = (isset($params['onHide'])) ? '\\'.$params['onHide'] : null;
 104  
 105          $options = JHTMLBehavior::_getJSObject($opt);
 106  
 107          // Attach tooltips to document
 108          $document =& JFactory::getDocument();
 109          $tooltipInit = '        window.addEvent(\'domready\', function(){ var JTooltips = new Tips($$(\''.$selector.'\'), '.$options.'); });';
 110          $document->addScriptDeclaration($tooltipInit);
 111  
 112          // Set static array
 113          $tips[$sig] = true;
 114          return;
 115      }
 116  
 117  	function modal($selector='a.modal', $params = array())
 118      {
 119          static $modals;
 120          static $included;
 121  
 122          $document =& JFactory::getDocument();
 123  
 124          // Load the necessary files if they haven't yet been loaded
 125          if (!isset($included)) {
 126  
 127              // Load the javascript and css
 128              JHTML::script('modal.js');
 129              JHTML::stylesheet('modal.css');
 130  
 131              $included = true;
 132          }
 133  
 134          if (!isset($modals)) {
 135              $modals = array();
 136          }
 137  
 138          $sig = md5(serialize(array($selector,$params)));
 139          if (isset($modals[$sig]) && ($modals[$sig])) {
 140              return;
 141          }
 142  
 143          // Setup options object
 144          $opt['ajaxOptions']    = (isset($params['ajaxOptions']) && (is_array($params['ajaxOptions']))) ? $params['ajaxOptions'] : null;
 145          $opt['size']        = (isset($params['size']) && (is_array($params['size']))) ? $params['size'] : null;
 146          $opt['onOpen']        = (isset($params['onOpen'])) ? $params['onOpen'] : null;
 147          $opt['onClose']        = (isset($params['onClose'])) ? $params['onClose'] : null;
 148          $opt['onUpdate']    = (isset($params['onUpdate'])) ? $params['onUpdate'] : null;
 149          $opt['onResize']    = (isset($params['onResize'])) ? $params['onResize'] : null;
 150          $opt['onMove']        = (isset($params['onMove'])) ? $params['onMove'] : null;
 151          $opt['onShow']        = (isset($params['onShow'])) ? $params['onShow'] : null;
 152          $opt['onHide']        = (isset($params['onHide'])) ? $params['onHide'] : null;
 153  
 154          $options = JHTMLBehavior::_getJSObject($opt);
 155  
 156          // Attach modal behavior to document
 157          $document->addScriptDeclaration("
 158          window.addEvent('domready', function() {
 159  
 160              SqueezeBox.initialize(".$options.");
 161  
 162              $$('".$selector."').each(function(el) {
 163                  el.addEvent('click', function(e) {
 164                      new Event(e).stop();
 165                      SqueezeBox.fromElement(el);
 166                  });
 167              });
 168          });");
 169  
 170          // Set static array
 171          $modals[$sig] = true;
 172          return;
 173      }
 174  
 175  	function uploader($id='file-upload', $params = array())
 176      {
 177          JHTML::script('swf.js' );
 178          JHTML::script('uploader.js' );
 179  
 180          static $uploaders;
 181  
 182          if (!isset($uploaders)) {
 183              $uploaders = array();
 184          }
 185  
 186          if (isset($uploaders[$id]) && ($uploaders[$id])) {
 187              return;
 188          }
 189  
 190          // Setup options object
 191          $opt['url']                    = (isset($params['targetURL'])) ? $params['targetURL'] : null ;
 192          $opt['swf']                    = (isset($params['swf'])) ? $params['swf'] : JURI::root(true).'/media/system/swf/uploader.swf';
 193          $opt['multiple']            = (isset($params['multiple']) && !($params['multiple'])) ? '\\false' : '\\true';
 194          $opt['queued']                = (isset($params['queued']) && !($params['queued'])) ? '\\false' : '\\true';
 195          $opt['queueList']            = (isset($params['queueList'])) ? $params['queueList'] : 'upload-queue';
 196          $opt['instantStart']        = (isset($params['instantStart']) && ($params['instantStart'])) ? '\\true' : '\\false';
 197          $opt['allowDuplicates']        = (isset($params['allowDuplicates']) && !($params['allowDuplicates'])) ? '\\false' : '\\true';
 198          $opt['limitSize']            = (isset($params['limitSize']) && ($params['limitSize'])) ? (int)$params['limitSize'] : null;
 199          $opt['limitFiles']            = (isset($params['limitFiles']) && ($params['limitFiles'])) ? (int)$params['limitFiles'] : null;
 200          $opt['optionFxDuration']    = (isset($params['optionFxDuration'])) ? (int)$params['optionFxDuration'] : null;
 201          $opt['container']            = (isset($params['container'])) ? '\\$('.$params['container'].')' : '\\$(\''.$id.'\').getParent()';
 202          $opt['types']                = (isset($params['types'])) ?'\\'.$params['types'] : '\\{\'All Files (*.*)\': \'*.*\'}';
 203  
 204  
 205          // Optional functions
 206          $opt['createReplacement']    = (isset($params['createReplacement'])) ? '\\'.$params['createReplacement'] : null;
 207          $opt['onComplete']            = (isset($params['onComplete'])) ? '\\'.$params['onComplete'] : null;
 208          $opt['onAllComplete']        = (isset($params['onAllComplete'])) ? '\\'.$params['onAllComplete'] : null;
 209  
 210  /*  types: Object with (description: extension) pairs, default: Images (*.jpg; *.jpeg; *.gif; *.png)
 211   */
 212  
 213          $options = JHTMLBehavior::_getJSObject($opt);
 214  
 215          // Attach tooltips to document
 216          $document =& JFactory::getDocument();
 217          $uploaderInit = 'sBrowseCaption=\''.JText::_('Browse Files', true).'\';
 218                  sRemoveToolTip=\''.JText::_('Remove from queue', true).'\';
 219                  window.addEvent(\'load\', function(){
 220                  var Uploader = new FancyUpload($(\''.$id.'\'), '.$options.');
 221                  $(\'upload-clear\').adopt(new Element(\'input\', { type: \'button\', events: { click: Uploader.clearList.bind(Uploader, [false])}, value: \''.JText::_('Clear Completed').'\' }));                });';
 222          $document->addScriptDeclaration($uploaderInit);
 223  
 224          // Set static array
 225          $uploaders[$id] = true;
 226          return;
 227      }
 228  
 229  	function tree($id, $params = array(), $root = array())
 230      {
 231          static $trees;
 232  
 233          if (!isset($trees)) {
 234              $trees = array();
 235          }
 236  
 237          // Include mootools framework
 238          JHTMLBehavior::mootools();
 239          JHTML::script('mootree.js');
 240          JHTML::stylesheet('mootree.css');
 241  
 242          if (isset($trees[$id]) && ($trees[$id])) {
 243              return;
 244          }
 245  
 246          // Setup options object
 247          $opt['div']        = (array_key_exists('div', $params)) ? $params['div'] : $id.'_tree';
 248          $opt['mode']    = (array_key_exists('mode', $params)) ? $params['mode'] : 'folders';
 249          $opt['grid']    = (array_key_exists('grid', $params)) ? '\\'.$params['grid'] : '\\true';
 250          $opt['theme']    = (array_key_exists('theme', $params)) ? $params['theme'] : JURI::root(true).'/media/system/images/mootree.gif';
 251  
 252          // Event handlers
 253          $opt['onExpand']    = (array_key_exists('onExpand', $params)) ? '\\'.$params['onExpand'] : null;
 254          $opt['onSelect']    = (array_key_exists('onSelect', $params)) ? '\\'.$params['onSelect'] : null;
 255          $opt['onClick']        = (array_key_exists('onClick', $params)) ? '\\'.$params['onClick'] : '\\function(node){  window.open(node.data.url, $chk(node.data.target) ? node.data.target : \'_self\'); }';
 256          $options = JHTMLBehavior::_getJSObject($opt);
 257  
 258          // Setup root node
 259          $rt['text']        = (array_key_exists('text', $root)) ? $root['text'] : 'Root';
 260          $rt['id']        = (array_key_exists('id', $root)) ? $root['id'] : null;
 261          $rt['color']    = (array_key_exists('color', $root)) ? $root['color'] : null;
 262          $rt['open']        = (array_key_exists('open', $root)) ? '\\'.$root['open'] : '\\true';
 263          $rt['icon']        = (array_key_exists('icon', $root)) ? $root['icon'] : null;
 264          $rt['openicon']    = (array_key_exists('openicon', $root)) ? $root['openicon'] : null;
 265          $rt['data']        = (array_key_exists('data', $root)) ? $root['data'] : null;
 266          $rootNode = JHTMLBehavior::_getJSObject($rt);
 267  
 268          $treeName        = (array_key_exists('treeName', $params)) ? $params['treeName'] : '';
 269  
 270          $js = '        window.addEvent(\'domready\', function(){
 271              tree'.$treeName.' = new MooTreeControl('.$options.','.$rootNode.');
 272              tree'.$treeName.'.adopt(\''.$id.'\');})';
 273  
 274          // Attach tooltips to document
 275          $document =& JFactory::getDocument();
 276          $document->addScriptDeclaration($js);
 277  
 278          // Set static array
 279          $trees[$id] = true;
 280          return;
 281      }
 282  
 283  	function calendar()
 284      {
 285          $document =& JFactory::getDocument();
 286          JHTML::stylesheet('calendar-jos.css', 'media/system/css/', array(' title' => JText::_( 'green' ) ,' media' => 'all' ));
 287          JHTML::script( 'calendar.js', 'media/system/js/' );
 288          JHTML::script( 'calendar-setup.js', 'media/system/js/' );
 289  
 290          $translation = JHTMLBehavior::_calendartranslation();
 291          if($translation) {
 292              $document->addScriptDeclaration($translation);
 293          }
 294      }
 295  
 296      /**
 297       * Keep session alive, for example, while editing or creating an article.
 298       */
 299  	function keepalive()
 300      {
 301          // Include mootools framework
 302          JHTMLBehavior::mootools();
 303  
 304          $config      =& JFactory::getConfig();
 305          $lifetime      = ( $config->getValue('lifetime') * 60000 );
 306          $refreshTime =  ( $lifetime <= 60000 ) ? 30000 : $lifetime - 60000;
 307          //refresh time is 1 minute less than the liftime assined in the configuration.php file
 308  
 309          $document =& JFactory::getDocument();
 310          $script  = '';
 311          $script .= 'function keepAlive( ) {';
 312          $script .=  '    var myAjax = new Ajax( "index.php", { method: "get" } ).request();';
 313          $script .=  '}';
 314          $script .=     ' window.addEvent("domready", function()';
 315          $script .=     '{ keepAlive.periodical('.$refreshTime.' ); }';
 316          $script .=  ');';
 317  
 318          $document->addScriptDeclaration($script);
 319  
 320          return;
 321      }
 322  
 323      /**
 324       * Internal method to get a JavaScript object notation string from an array
 325       *
 326       * @param    array    $array    The array to convert to JavaScript object notation
 327       * @return    string    JavaScript object notation representation of the array
 328       * @since    1.5
 329       */
 330  	function _getJSObject($array=array())
 331      {
 332          // Initialize variables
 333          $object = '{';
 334  
 335          // Iterate over array to build objects
 336          foreach ((array)$array as $k => $v)
 337          {
 338              if (is_null($v)) {
 339                  continue;
 340              }
 341              if (!is_array($v) && !is_object($v)) {
 342                  $object .= ' '.$k.': ';
 343                  $object .= (is_numeric($v) || strpos($v, '\\') === 0) ? (is_numeric($v)) ? $v : substr($v, 1) : "'".$v."'";
 344                  $object .= ',';
 345              } else {
 346                  $object .= ' '.$k.': '.JHTMLBehavior::_getJSObject($v).',';
 347              }
 348          }
 349          if (substr($object, -1) == ',') {
 350              $object = substr($object, 0, -1);
 351          }
 352          $object .= '}';
 353  
 354          return $object;
 355      }
 356  
 357      /**
 358       * Internal method to translate the JavaScript Calendar
 359       *
 360       * @return    string    JavaScript that translates the object
 361       * @since    1.5
 362       */
 363  	function _calendartranslation()
 364      {
 365          static $jsscript = 0;
 366  
 367          if($jsscript == 0)
 368          {
 369              $return = 'Calendar._DN = new Array ("'.JText::_('Sunday').'", "'.JText::_('Monday').'", "'.JText::_('Tuesday').'", "'.JText::_('Wednesday').'", "'.JText::_('Thursday').'", "'.JText::_('Friday').'", "'.JText::_('Saturday').'", "'.JText::_('Sunday').'");Calendar._SDN = new Array ("'.JText::_('Sun').'", "'.JText::_('Mon').'", "'.JText::_('Tue').'", "'.JText::_('Wed').'", "'.JText::_('Thu').'", "'.JText::_('Fri').'", "'.JText::_('Sat').'", "'.JText::_('Sun').'"); Calendar._FD = 0;    Calendar._MN = new Array ("'.JText::_('January').'", "'.JText::_('February').'", "'.JText::_('March').'", "'.JText::_('April').'", "'.JText::_('May').'", "'.JText::_('June').'", "'.JText::_('July').'", "'.JText::_('August').'", "'.JText::_('September').'", "'.JText::_('October').'", "'.JText::_('November').'", "'.JText::_('December').'");    Calendar._SMN = new Array ("'.JText::_('January_short').'", "'.JText::_('February_short').'", "'.JText::_('March_short').'", "'.JText::_('April_short').'", "'.JText::_('May_short').'", "'.JText::_('June_short').'", "'.JText::_('July_short').'", "'.JText::_('August_short').'", "'.JText::_('September_short').'", "'.JText::_('October_short').'", "'.JText::_('November_short').'", "'.JText::_('December_short').'");Calendar._TT = {};Calendar._TT["INFO"] = "'.JText::_('About the calendar').'";
 370           Calendar._TT["ABOUT"] =
 371   "DHTML Date/Time Selector\n" +
 372   "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" +
 373  "For latest version visit: http://www.dynarch.com/projects/calendar/\n" +
 374  "Distributed under GNU LGPL.  See http://gnu.org/licenses/lgpl.html for details." +
 375  "\n\n" +
 376  "Date selection:\n" +
 377  "- Use the \xab, \xbb buttons to select year\n" +
 378  "- Use the " + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " buttons to select month\n" +
 379  "- Hold mouse button on any of the above buttons for faster selection.";
 380  Calendar._TT["ABOUT_TIME"] = "\n\n" +
 381  "Time selection:\n" +
 382  "- Click on any of the time parts to increase it\n" +
 383  "- or Shift-click to decrease it\n" +
 384  "- or click and drag for faster selection.";
 385  
 386          Calendar._TT["PREV_YEAR"] = "'.JText::_('Prev. year (hold for menu)').'";Calendar._TT["PREV_MONTH"] = "'.JText::_('Prev. month (hold for menu)').'";    Calendar._TT["GO_TODAY"] = "'.JText::_('Go Today').'";Calendar._TT["NEXT_MONTH"] = "'.JText::_('Next month (hold for menu)').'";Calendar._TT["NEXT_YEAR"] = "'.JText::_('Next year (hold for menu)').'";Calendar._TT["SEL_DATE"] = "'.JText::_('Select date').'";Calendar._TT["DRAG_TO_MOVE"] = "'.JText::_('Drag to move').'";Calendar._TT["PART_TODAY"] = "'.JText::_('(Today)').'";Calendar._TT["DAY_FIRST"] = "'.JText::_('Display %s first').'";Calendar._TT["WEEKEND"] = "0,6";Calendar._TT["CLOSE"] = "'.JText::_('Close').'";Calendar._TT["TODAY"] = "'.JText::_('Today').'";Calendar._TT["TIME_PART"] = "'.JText::_('(Shift-)Click or drag to change value').'";Calendar._TT["DEF_DATE_FORMAT"] = "'.JText::_('%Y-%m-%d').'"; Calendar._TT["TT_DATE_FORMAT"] = "'.JText::_('%a, %b %e').'";Calendar._TT["WK"] = "'.JText::_('wk').'";Calendar._TT["TIME"] = "'.JText::_('Time:').'";';
 387              $jsscript = 1;
 388              return $return;
 389          } else {
 390              return false;
 391          }
 392      }
 393  }
 394  
element ', [['libraries/joomla/html','html.php',159]], 29], 'stop': ['stop', '', [['plugins/editors/tinymce/jscripts/tiny_mce','tiny_mce_src.js',355],['libraries/domit','timer.php',11]], 26], 'is_array': ['is_array', '', [], 378], 'each': ['each', '', [], 455], 'array_key_exists': ['array_key_exists', '', [], 137], 'substr': ['substr', '', [], 890], 'strtolower': ['strtolower', '', [], 393], 'is_null': ['is_null', '', [], 94], 'is_numeric': ['is_numeric', '', [], 37], 'strpos': ['strpos', '', [], 458], 'defined': ['defined', '', [], 1004], 'serialize': ['serialize', '', [], 74], 'is_object': ['is_object', '', [], 199]}; CLASS_DATA={ 'juri': ['juri', 'JURI Class ', [['libraries/joomla/environment','uri.php',18]], 149], 'jhtml': ['jhtml', 'Utility class for all HTML drawing classes ', [['libraries/joomla/html','html.php',15]], 1096], 'jfactory': ['jfactory', 'Joomla Framework Factory class ', [['libraries/joomla','factory.php',14]], 981], 'jtext': ['jtext', 'Text handling class ', [['libraries/joomla','methods.php',99]], 3334], 'jhtmlbehavior': ['jhtmlbehavior', 'JHTML helper class for loading JavaScript behaviors into the document head. This version is designed to load MooTools version 1.2 plus the 1.1 compatibility layer. ', [['plugins/system/mtupgrade','behavior.php',18],['libraries/joomla/html/html','behavior.php',15]], 19]}; CONST_DATA={ 'JPATH_BASE': ['JPATH_BASE', '', [['','index.php',17],['administrator','index.php',17],['xmlrpc','index.php',15],['installation/installer','jajax.php',24],['installation','index.php',15],['xmlrpc','client.php',16]], 331]};


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1