Source for file behavior.php

Documentation is available at behavior.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  HTML
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Utility class for JavaScript behaviors
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       1.5
  18.  */
  19. abstract class JHtmlBehavior
  20. {
  21.     /**
  22.      * Array containing information for loaded files
  23.      *
  24.      * @var    array 
  25.      * @since  2.5
  26.      */
  27.     protected static $loaded array();
  28.  
  29.     /**
  30.      * Method to load the MooTools framework into the document head
  31.      *
  32.      * If debugging mode is on an uncompressed version of MooTools is included for easier debugging.
  33.      *
  34.      * @param   boolean  $extras  Flag to determine whether to load MooTools More in addition to Core
  35.      * @param   mixed    $debug   Is debugging mode on? [optional]
  36.      *
  37.      * @return  void 
  38.      *
  39.      * @since   1.6
  40.      */
  41.     public static function framework($extras false$debug null)
  42.     {
  43.         $type $extras 'more' 'core';
  44.  
  45.         // Only load once
  46.         if (!empty(static::$loaded[__METHOD__][$type]))
  47.         {
  48.             return;
  49.         }
  50.  
  51.         // If no debugging value is set, use the configuration setting
  52.         if ($debug === null)
  53.         {
  54.             $config JFactory::getConfig();
  55.             $debug $config->get('debug');
  56.         }
  57.  
  58.         if ($type != 'core' && empty(static::$loaded[__METHOD__]['core']))
  59.         {
  60.             static::framework(false$debug);
  61.         }
  62.  
  63.         JHtml::_('script''system/mootools-' $type '.js'falsetruefalsefalse$debug);
  64.         JHtml::_('script''system/core.js'falsetrue);
  65.         static::$loaded[__METHOD__][$typetrue;
  66.  
  67.         return;
  68.     }
  69.  
  70.     /**
  71.      * Add unobtrusive JavaScript support for image captions.
  72.      *
  73.      * @param   string  $selector  The selector for which a caption behaviour is to be applied.
  74.      *
  75.      * @return  void 
  76.      *
  77.      * @since   1.5
  78.      */
  79.     public static function caption($selector 'img.caption')
  80.     {
  81.         // Only load once
  82.         if (isset(static::$loaded[__METHOD__][$selector]))
  83.         {
  84.             return;
  85.         }
  86.  
  87.         // Include jQuery
  88.         JHtml::_('jquery.framework');
  89.  
  90.         JHtml::_('script''system/caption.js'truetrue);
  91.  
  92.         // Attach caption to document
  93.         JFactory::getDocument()->addScriptDeclaration(
  94.             "jQuery(window).on('load',  function() {
  95.                 new JCaption('" $selector "');
  96.             });"
  97.         );
  98.  
  99.         // Set static array
  100.         static::$loaded[__METHOD__][$selectortrue;
  101.     }
  102.  
  103.     /**
  104.      * Add unobtrusive JavaScript support for form validation.
  105.      *
  106.      * To enable form validation the form tag must have class="form-validate".
  107.      * Each field that needs to be validated needs to have class="validate".
  108.      * Additional handlers can be added to the handler for username, password,
  109.      * numeric and email. To use these add class="validate-email" and so on.
  110.      *
  111.      * @return  void 
  112.      *
  113.      * @since   1.5
  114.      */
  115.     public static function formvalidation()
  116.     {
  117.         // Only load once
  118.         if (isset(static::$loaded[__METHOD__]))
  119.         {
  120.             return;
  121.         }
  122.  
  123.         // Add validate.js language strings
  124.         JText::script('JLIB_FORM_FIELD_INVALID');
  125.  
  126.         // Include MooTools More framework
  127.         static::framework('more');
  128.  
  129.         JHtml::_('script''system/validate.js'falsetrue);
  130.         static::$loaded[__METHOD__true;
  131.     }
  132.  
  133.     /**
  134.      * Add unobtrusive JavaScript support for submenu switcher support
  135.      *
  136.      * @return  void 
  137.      *
  138.      * @since   1.5
  139.      */
  140.     public static function switcher()
  141.     {
  142.         // Only load once
  143.         if (isset(static::$loaded[__METHOD__]))
  144.         {
  145.             return;
  146.         }
  147.  
  148.         // Include jQuery
  149.         JHtml::_('jquery.framework');
  150.  
  151.         JHtml::_('script''system/switcher.js'truetrue);
  152.  
  153.         $script "
  154.             document.switcher = null;
  155.             jQuery(function($){
  156.                 var toggler = document.getElementById('submenu');
  157.                 var element = document.getElementById('config-document');
  158.                 if (element) {
  159.                     document.switcher = new JSwitcher(toggler, element);
  160.                 }
  161.             });";
  162.  
  163.         JFactory::getDocument()->addScriptDeclaration($script);
  164.         static::$loaded[__METHOD__true;
  165.     }
  166.  
  167.     /**
  168.      * Add unobtrusive JavaScript support for a combobox effect.
  169.      *
  170.      * Note that this control is only reliable in absolutely positioned elements.
  171.      * Avoid using a combobox in a slider or dynamic pane.
  172.      *
  173.      * @return  void 
  174.      *
  175.      * @since   1.5
  176.      */
  177.     public static function combobox()
  178.     {
  179.         if (isset(static::$loaded[__METHOD__]))
  180.         {
  181.             return;
  182.         }
  183.         // Include MooTools framework
  184.         static::framework();
  185.  
  186.         JHtml::_('script''system/combobox.js'truetrue);
  187.         static::$loaded[__METHOD__true;
  188.     }
  189.  
  190.     /**
  191.      * Add unobtrusive JavaScript support for a hover tooltips.
  192.      *
  193.      * Add a title attribute to any element in the form
  194.      * title="title::text"
  195.      *
  196.      * Uses the core Tips class in MooTools.
  197.      *
  198.      * @param   string  $selector  The class selector for the tooltip.
  199.      * @param   array   $params    An array of options for the tooltip.
  200.      *                              Options for the tooltip can be:
  201.      *                              - maxTitleChars  integer   The maximum number of characters in the tooltip title (defaults to 50).
  202.      *                              - offsets        object    The distance of your tooltip from the mouse (defaults to {'x': 16, 'y': 16}).
  203.      *                              - showDelay      integer   The millisecond delay the show event is fired (defaults to 100).
  204.      *                              - hideDelay      integer   The millisecond delay the hide hide is fired (defaults to 100).
  205.      *                              - className      string    The className your tooltip container will get.
  206.      *                              - fixed          boolean   If set to true, the toolTip will not follow the mouse.
  207.      *                              - onShow         function  The default function for the show event, passes the tip element
  208.      *                                and the currently hovered element.
  209.      *                              - onHide         function  The default function for the hide event, passes the currently
  210.      *                                hovered element.
  211.      *
  212.      * @return  void 
  213.      *
  214.      * @since   1.5
  215.      */
  216.     public static function tooltip($selector '.hasTip'$params array())
  217.     {
  218.         $sig md5(serialize(array($selector$params)));
  219.  
  220.         if (isset(static::$loaded[__METHOD__][$sig]))
  221.         {
  222.             return;
  223.         }
  224.  
  225.         // Include MooTools framework
  226.         static::framework(true);
  227.  
  228.         // Setup options object
  229.         $opt['maxTitleChars'(isset($params['maxTitleChars']&& ($params['maxTitleChars'])) ? (int) $params['maxTitleChars'50;
  230.  
  231.         // Offsets needs an array in the format: array('x'=>20, 'y'=>30)
  232.         $opt['offset']    (isset($params['offset']&& (is_array($params['offset']))) $params['offset'null;
  233.         $opt['showDelay'(isset($params['showDelay'])) ? (int) $params['showDelay'null;
  234.         $opt['hideDelay'(isset($params['hideDelay'])) ? (int) $params['hideDelay'null;
  235.         $opt['className'(isset($params['className'])) $params['className'null;
  236.         $opt['fixed']     (isset($params['fixed']&& ($params['fixed'])) true false;
  237.         $opt['onShow']    (isset($params['onShow'])) '\\' $params['onShow'null;
  238.         $opt['onHide']    (isset($params['onHide'])) '\\' $params['onHide'null;
  239.  
  240.         $options JHtml::getJSObject($opt);
  241.  
  242.         // Attach tooltips to document
  243.         JFactory::getDocument()->addScriptDeclaration(
  244.             "window.addEvent('domready', function() {
  245.             $$('$selector').each(function(el) {
  246.                 var title = el.get('title');
  247.                 if (title) {
  248.                     var parts = title.split('::', 2);
  249.                     el.store('tip:title', parts[0]);
  250.                     el.store('tip:text', parts[1]);
  251.                 }
  252.             });
  253.             var JTooltips = new Tips($$('$selector'), $options);
  254.         });"
  255.         );
  256.  
  257.         // Set static array
  258.         static::$loaded[__METHOD__][$sigtrue;
  259.  
  260.         return;
  261.     }
  262.  
  263.     /**
  264.      * Add unobtrusive JavaScript support for modal links.
  265.      *
  266.      * @param   string  $selector  The selector for which a modal behaviour is to be applied.
  267.      * @param   array   $params    An array of parameters for the modal behaviour.
  268.      *                              Options for the modal behaviour can be:
  269.      *                             - ajaxOptions
  270.      *                             - size
  271.      *                             - shadow
  272.      *                             - overlay
  273.      *                             - onOpen
  274.      *                             - onClose
  275.      *                             - onUpdate
  276.      *                             - onResize
  277.      *                             - onShow
  278.      *                             - onHide
  279.      *
  280.      * @return  void 
  281.      *
  282.      * @since   1.5
  283.      */
  284.     public static function modal($selector 'a.modal'$params array())
  285.     {
  286.         $document JFactory::getDocument();
  287.  
  288.         // Load the necessary files if they haven't yet been loaded
  289.         if (!isset(static::$loaded[__METHOD__]))
  290.         {
  291.             // Include MooTools framework
  292.             static::framework(true);
  293.  
  294.             // Load the JavaScript and css
  295.             JHtml::_('script''system/modal.js'truetrue);
  296.             JHtml::_('stylesheet''system/modal.css'array()true);
  297.         }
  298.  
  299.         $sig md5(serialize(array($selector$params)));
  300.  
  301.         if (isset(static::$loaded[__METHOD__][$sig]))
  302.         {
  303.             return;
  304.         }
  305.  
  306.         // Setup options object
  307.         $opt['ajaxOptions']   (isset($params['ajaxOptions']&& (is_array($params['ajaxOptions']))) $params['ajaxOptions'null;
  308.         $opt['handler']       (isset($params['handler'])) $params['handler'null;
  309.         $opt['parseSecure']   (isset($params['parseSecure'])) ? (bool) $params['parseSecure'null;
  310.         $opt['closable']      (isset($params['closable'])) ? (bool) $params['closable'null;
  311.         $opt['closeBtn']      (isset($params['closeBtn'])) ? (bool) $params['closeBtn'null;
  312.         $opt['iframePreload'(isset($params['iframePreload'])) ? (bool) $params['iframePreload'null;
  313.         $opt['iframeOptions'(isset($params['iframeOptions']&& (is_array($params['iframeOptions']))) $params['iframeOptions'null;
  314.         $opt['size']          (isset($params['size']&& (is_array($params['size']))) $params['size'null;
  315.         $opt['shadow']        (isset($params['shadow'])) $params['shadow'null;
  316.         $opt['overlay']       (isset($params['overlay'])) $params['overlay'null;
  317.         $opt['onOpen']        (isset($params['onOpen'])) $params['onOpen'null;
  318.         $opt['onClose']       (isset($params['onClose'])) $params['onClose'null;
  319.         $opt['onUpdate']      (isset($params['onUpdate'])) $params['onUpdate'null;
  320.         $opt['onResize']      (isset($params['onResize'])) $params['onResize'null;
  321.         $opt['onMove']        (isset($params['onMove'])) $params['onMove'null;
  322.         $opt['onShow']        (isset($params['onShow'])) $params['onShow'null;
  323.         $opt['onHide']        (isset($params['onHide'])) $params['onHide'null;
  324.  
  325.         if (isset($params['fullScreen']&& (bool) $params['fullScreen'])
  326.         {
  327.             $opt['size']      array('x' => '\\window.getSize().x-80''y' => '\\window.getSize().y-80');
  328.         }
  329.  
  330.         $options JHtml::getJSObject($opt);
  331.  
  332.         // Attach modal behavior to document
  333.         $document
  334.             ->addScriptDeclaration(
  335.             "
  336.         window.addEvent('domready', function() {
  337.  
  338.             SqueezeBox.initialize(" $options ");
  339.             SqueezeBox.assign($$('" $selector "'), {
  340.                 parse: 'rel'
  341.             });
  342.         });"
  343.         );
  344.  
  345.         // Set static array
  346.         static::$loaded[__METHOD__][$sigtrue;
  347.  
  348.         return;
  349.     }
  350.  
  351.     /**
  352.      * JavaScript behavior to allow shift select in grids
  353.      *
  354.      * @param   string  $id  The id of the form for which a multiselect behaviour is to be applied.
  355.      *
  356.      * @return  void 
  357.      *
  358.      * @since   1.7
  359.      */
  360.     public static function multiselect($id 'adminForm')
  361.     {
  362.         // Only load once
  363.         if (isset(static::$loaded[__METHOD__][$id]))
  364.         {
  365.             return;
  366.         }
  367.  
  368.         // Include jQuery
  369.         JHtml::_('jquery.framework');
  370.  
  371.         JHtml::_('script''system/multiselect.js'truetrue);
  372.  
  373.         // Attach multiselect to document
  374.         JFactory::getDocument()->addScriptDeclaration(
  375.             "window.addEvent('domready', function() {
  376.                 new Joomla.JMultiSelect('" $id "');
  377.             });"
  378.         );
  379.  
  380.         // Set static array
  381.         static::$loaded[__METHOD__][$idtrue;
  382.  
  383.         return;
  384.     }
  385.  
  386.     /**
  387.      * Add unobtrusive javascript support for a collapsible tree.
  388.      *
  389.      * @param   string  $id      An index
  390.      * @param   array   $params  An array of options.
  391.      * @param   array   $root    The root node
  392.      *
  393.      * @return  void 
  394.      *
  395.      * @since   1.5
  396.      */
  397.     public static function tree($id$params array()$root array())
  398.     {
  399.         // Include MooTools framework
  400.         static::framework();
  401.  
  402.         JHtml::_('script''system/mootree.js'truetruefalsefalse);
  403.         JHtml::_('stylesheet''system/mootree.css'array()true);
  404.  
  405.         if (isset(static::$loaded[__METHOD__][$id]))
  406.         {
  407.             return;
  408.         }
  409.  
  410.         // Setup options object
  411.         $opt['div']   (array_key_exists('div'$params)) $params['div'$id '_tree';
  412.         $opt['mode']  (array_key_exists('mode'$params)) $params['mode''folders';
  413.         $opt['grid']  (array_key_exists('grid'$params)) '\\' $params['grid'true;
  414.         $opt['theme'(array_key_exists('theme'$params)) $params['theme'JHtml::_('image''system/mootree.gif'''array()truetrue);
  415.  
  416.         // Event handlers
  417.         $opt['onExpand'(array_key_exists('onExpand'$params)) '\\' $params['onExpand'null;
  418.         $opt['onSelect'(array_key_exists('onSelect'$params)) '\\' $params['onSelect'null;
  419.         $opt['onClick']  (array_key_exists('onClick'$params)) '\\' $params['onClick']
  420.         : '\\function(node){  window.open(node.data.url, node.data.target != null ? node.data.target : \'_self\'); }';
  421.  
  422.         $options JHtml::getJSObject($opt);
  423.  
  424.         // Setup root node
  425.         $rt['text']     (array_key_exists('text'$root)) $root['text''Root';
  426.         $rt['id']       (array_key_exists('id'$root)) $root['id'null;
  427.         $rt['color']    (array_key_exists('color'$root)) $root['color'null;
  428.         $rt['open']     (array_key_exists('open'$root)) '\\' $root['open'true;
  429.         $rt['icon']     (array_key_exists('icon'$root)) $root['icon'null;
  430.         $rt['openicon'(array_key_exists('openicon'$root)) $root['openicon'null;
  431.         $rt['data']     (array_key_exists('data'$root)) $root['data'null;
  432.         $rootNode JHtml::getJSObject($rt);
  433.  
  434.         $treeName (array_key_exists('treeName'$params)) $params['treeName''';
  435.  
  436.         $js '        window.addEvent(\'domready\', function(){
  437.             tree' $treeName ' = new MooTreeControl(' $options ',' $rootNode ');
  438.             tree' $treeName '.adopt(\'' $id '\');})';
  439.  
  440.         // Attach tooltips to document
  441.         $document JFactory::getDocument();
  442.         $document->addScriptDeclaration($js);
  443.  
  444.         // Set static array
  445.         static::$loaded[__METHOD__][$idtrue;
  446.  
  447.         return;
  448.     }
  449.  
  450.     /**
  451.      * Add unobtrusive JavaScript support for a calendar control.
  452.      *
  453.      * @return  void 
  454.      *
  455.      * @since   1.5
  456.      */
  457.     public static function calendar()
  458.     {
  459.         // Only load once
  460.         if (isset(static::$loaded[__METHOD__]))
  461.         {
  462.             return;
  463.         }
  464.  
  465.         $document JFactory::getDocument();
  466.         $tag JFactory::getLanguage()->getTag();
  467.  
  468.         JHtml::_('stylesheet''system/calendar-jos.css'array(' title' => JText::_('JLIB_HTML_BEHAVIOR_GREEN')' media' => 'all')true);
  469.         JHtml::_('script'$tag '/calendar.js'falsetrue);
  470.         JHtml::_('script'$tag '/calendar-setup.js'falsetrue);
  471.  
  472.         $translation static::calendartranslation();
  473.  
  474.         if ($translation)
  475.         {
  476.             $document->addScriptDeclaration($translation);
  477.         }
  478.         static::$loaded[__METHOD__true;
  479.     }
  480.  
  481.     /**
  482.      * Add unobtrusive JavaScript support for a color picker.
  483.      *
  484.      * @return  void 
  485.      *
  486.      * @since   1.7
  487.      */
  488.     public static function colorpicker()
  489.     {
  490.         // Only load once
  491.         if (isset(static::$loaded[__METHOD__]))
  492.         {
  493.             return;
  494.         }
  495.  
  496.         // Include jQuery
  497.         JHtml::_('jquery.framework');
  498.  
  499.         JHtml::_('script''jui/jquery.minicolors.min.js'falsetrue);
  500.         JHtml::_('stylesheet''jui/jquery.minicolors.css'falsetrue);
  501.         JFactory::getDocument()->addScriptDeclaration("
  502.                 jQuery(document).ready(function (){
  503.                     jQuery('.minicolors').each(function() {
  504.                         jQuery(this).minicolors({
  505.                             control: jQuery(this).attr('data-control') || 'hue',
  506.                             position: jQuery(this).attr('data-position') || 'right',
  507.                             theme: 'bootstrap'
  508.                         });
  509.                     });
  510.                 });
  511.             "
  512.         );
  513.  
  514.         static::$loaded[__METHOD__true;
  515.     }
  516.  
  517.     /**
  518.      * Add unobtrusive JavaScript support for a simple color picker.
  519.      *
  520.      * @return  void 
  521.      *
  522.      * @since   3.1
  523.      */
  524.     public static function simplecolorpicker()
  525.     {
  526.         // Only load once
  527.         if (isset(static::$loaded[__METHOD__]))
  528.         {
  529.             return;
  530.         }
  531.  
  532.         // Include jQuery
  533.         JHtml::_('jquery.framework');
  534.  
  535.         JHtml::_('script''jui/jquery.simplecolors.min.js'falsetrue);
  536.         JHtml::_('stylesheet''jui/jquery.simplecolors.css'falsetrue);
  537.         JFactory::getDocument()->addScriptDeclaration("
  538.                 jQuery(document).ready(function (){
  539.                     jQuery('select.simplecolors').simplecolors();
  540.                 });
  541.             "
  542.         );
  543.  
  544.         static::$loaded[__METHOD__true;
  545.     }
  546.  
  547.     /**
  548.      * Keep session alive, for example, while editing or creating an article.
  549.      *
  550.      * @return  void 
  551.      *
  552.      * @since   1.5
  553.      */
  554.     public static function keepalive()
  555.     {
  556.         // Only load once
  557.         if (isset(static::$loaded[__METHOD__]))
  558.         {
  559.             return;
  560.         }
  561.  
  562.         // Include MooTools framework
  563.         static::framework();
  564.  
  565.         $config JFactory::getConfig();
  566.         $lifetime ($config->get('lifetime'60000);
  567.         $refreshTime ($lifetime <= 6000030000 $lifetime 60000;
  568.  
  569.         // Refresh time is 1 minute less than the liftime assined in the configuration.php file.
  570.  
  571.         // The longest refresh period is one hour to prevent integer overflow.
  572.         if ($refreshTime 3600000 || $refreshTime <= 0)
  573.         {
  574.             $refreshTime 3600000;
  575.         }
  576.  
  577.         $document JFactory::getDocument();
  578.         $script '';
  579.         $script .= 'function keepAlive() {';
  580.         $script .= '    var myAjax = new Request({method: "get", url: "index.php"}).send();';
  581.         $script .= '}';
  582.         $script .= ' window.addEvent("domready", function()';
  583.         $script .= '{ keepAlive.periodical(' $refreshTime '); }';
  584.         $script .= ');';
  585.  
  586.         $document->addScriptDeclaration($script);
  587.         static::$loaded[__METHOD__true;
  588.  
  589.         return;
  590.     }
  591.  
  592.     /**
  593.      * Highlight some words via Javascript.
  594.      *
  595.      * @param   array   $terms      Array of words that should be highlighted.
  596.      * @param   string  $start      ID of the element that marks the begin of the section in which words
  597.      *                               should be highlighted. Note this element will be removed from the DOM.
  598.      * @param   string  $end        ID of the element that end this section.
  599.      *                               Note this element will be removed from the DOM.
  600.      * @param   string  $className  Class name of the element highlights are wrapped in.
  601.      * @param   string  $tag        Tag that will be used to wrap the highlighted words.
  602.      *
  603.      * @return  void 
  604.      *
  605.      * @since   2.5
  606.      */
  607.     public static function highlighter(array $terms$start 'highlighter-start'$end 'highlighter-end'$className 'highlight'$tag 'span')
  608.     {
  609.         $sig md5(serialize(array($terms$start$end)));
  610.  
  611.         if (isset(static::$loaded[__METHOD__][$sig]))
  612.         {
  613.             return;
  614.         }
  615.  
  616.         // Include jQuery
  617.         JHtml::_('jquery.framework');
  618.  
  619.         JHtml::_('script''system/highlighter.js'truetrue);
  620.  
  621.         $terms str_replace('"''\"'$terms);
  622.  
  623.         $document JFactory::getDocument();
  624.         $document->addScriptDeclaration("
  625.             jQuery(function ($) {
  626.                 var start = document.getElementById('" $start "');
  627.                 var end = document.getElementById('" $end "');
  628.                 if (!start || !end || !Joomla.Highlighter) {
  629.                     return true;
  630.                 }
  631.                 highlighter = new Joomla.Highlighter({
  632.                     startElement: start,
  633.                     endElement: end,
  634.                     className: '" $className "',
  635.                     onlyWords: false,
  636.                     tag: '" $tag "'
  637.                 }).highlight([\"" implode('","'$terms"\"]);
  638.                 $(start).remove();
  639.                 $(end).remove();
  640.             });
  641.         ");
  642.  
  643.         static::$loaded[__METHOD__][$sigtrue;
  644.  
  645.         return;
  646.     }
  647.  
  648.     /**
  649.      * Break us out of any containing iframes
  650.      *
  651.      * @return  void 
  652.      *
  653.      * @since   1.5
  654.      */
  655.     public static function noframes()
  656.     {
  657.         // Only load once
  658.         if (isset(static::$loaded[__METHOD__]))
  659.         {
  660.             return;
  661.         }
  662.  
  663.         // Include MooTools framework
  664.         static::framework();
  665.  
  666.         $js "window.addEvent('domready', function () {if (top == self) {document.documentElement.style.display = 'block'; }" .
  667.             " else {top.location = self.location; }});";
  668.         $document JFactory::getDocument();
  669.         $document->addStyleDeclaration('html { display:none }');
  670.         $document->addScriptDeclaration($js);
  671.  
  672.         JFactory::getApplication()->setHeader('X-Frames-Options''SAMEORIGIN');
  673.  
  674.         static::$loaded[__METHOD__true;
  675.     }
  676.  
  677.     /**
  678.      * Internal method to get a JavaScript object notation string from an array
  679.      *
  680.      * @param   array  $array  The array to convert to JavaScript object notation
  681.      *
  682.      * @return  string  JavaScript object notation representation of the array
  683.      *
  684.      * @since       1.5
  685.      * @deprecated  13.3 (Platform) & 4.0 (CMS) - Use JHtml::getJSObject() instead.
  686.      */
  687.     protected static function _getJSObject($array array())
  688.     {
  689.         JLog::add('JHtmlBehavior::_getJSObject() is deprecated. JHtml::getJSObject() instead..'JLog::WARNING'deprecated');
  690.  
  691.         return JHtml::getJSObject($array);
  692.     }
  693.  
  694.     /**
  695.      * Internal method to translate the JavaScript Calendar
  696.      *
  697.      * @return  string  JavaScript that translates the object
  698.      *
  699.      * @since   1.5
  700.      */
  701.     protected static function calendartranslation()
  702.     {
  703.         static $jsscript 0;
  704.  
  705.         // Guard clause, avoids unnecessary nesting
  706.         if ($jsscript)
  707.         {
  708.             return false;
  709.         }
  710.  
  711.         $jsscript 1;
  712.  
  713.         // To keep the code simple here, run strings through JText::_() using array_map()
  714.         $callback array('JText','_');
  715.         $weekdays_full array_map(
  716.             $callbackarray(
  717.                 'SUNDAY''MONDAY''TUESDAY''WEDNESDAY''THURSDAY''FRIDAY''SATURDAY''SUNDAY'
  718.             )
  719.         );
  720.         $weekdays_short array_map(
  721.             $callback,
  722.             array(
  723.                 'SUN''MON''TUE''WED''THU''FRI''SAT''SUN'
  724.             )
  725.         );
  726.         $months_long array_map(
  727.             $callbackarray(
  728.                 'JANUARY''FEBRUARY''MARCH''APRIL''MAY''JUNE',
  729.                 'JULY''AUGUST''SEPTEMBER''OCTOBER''NOVEMBER''DECEMBER'
  730.             )
  731.         );
  732.         $months_short array_map(
  733.             $callbackarray(
  734.                 'JANUARY_SHORT''FEBRUARY_SHORT''MARCH_SHORT''APRIL_SHORT''MAY_SHORT''JUNE_SHORT',
  735.                 'JULY_SHORT''AUGUST_SHORT''SEPTEMBER_SHORT''OCTOBER_SHORT''NOVEMBER_SHORT''DECEMBER_SHORT'
  736.             )
  737.         );
  738.  
  739.         // This will become an object in Javascript but define it first in PHP for readability
  740.         $today " " JText::_('JLIB_HTML_BEHAVIOR_TODAY'" ";
  741.         $text array(
  742.             'INFO'            => JText::_('JLIB_HTML_BEHAVIOR_ABOUT_THE_CALENDAR'),
  743.  
  744.             'ABOUT'            => "DHTML Date/Time Selector\n"
  745.                 . "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n"
  746.                 . "For latest version visit: http://www.dynarch.com/projects/calendar/\n"
  747.                 . "Distributed under GNU LGPL.  See http://gnu.org/licenses/lgpl.html for details."
  748.                 . "\n\n"
  749.                 . JText::_('JLIB_HTML_BEHAVIOR_DATE_SELECTION')
  750.                 . JText::_('JLIB_HTML_BEHAVIOR_YEAR_SELECT')
  751.                 . JText::_('JLIB_HTML_BEHAVIOR_MONTH_SELECT')
  752.                 . JText::_('JLIB_HTML_BEHAVIOR_HOLD_MOUSE'),
  753.  
  754.             'ABOUT_TIME'    => "\n\n"
  755.                 . "Time selection:\n"
  756.                 . "- Click on any of the time parts to increase it\n"
  757.                 . "- or Shift-click to decrease it\n"
  758.                 . "- or click and drag for faster selection.",
  759.  
  760.             'PREV_YEAR'        => JText::_('JLIB_HTML_BEHAVIOR_PREV_YEAR_HOLD_FOR_MENU'),
  761.             'PREV_MONTH'    => JText::_('JLIB_HTML_BEHAVIOR_PREV_MONTH_HOLD_FOR_MENU'),
  762.             'GO_TODAY'        => JText::_('JLIB_HTML_BEHAVIOR_GO_TODAY'),
  763.             'NEXT_MONTH'    => JText::_('JLIB_HTML_BEHAVIOR_NEXT_MONTH_HOLD_FOR_MENU'),
  764.             'SEL_DATE'        => JText::_('JLIB_HTML_BEHAVIOR_SELECT_DATE'),
  765.             'DRAG_TO_MOVE'    => JText::_('JLIB_HTML_BEHAVIOR_DRAG_TO_MOVE'),
  766.             'PART_TODAY'    => $today,
  767.             'DAY_FIRST'        => JText::_('JLIB_HTML_BEHAVIOR_DISPLAY_S_FIRST'),
  768.             'WEEKEND'        => JFactory::getLanguage()->getWeekEnd(),
  769.             'CLOSE'            => JText::_('JLIB_HTML_BEHAVIOR_CLOSE'),
  770.             'TODAY'            => JText::_('JLIB_HTML_BEHAVIOR_TODAY'),
  771.             'TIME_PART'        => JText::_('JLIB_HTML_BEHAVIOR_SHIFT_CLICK_OR_DRAG_TO_CHANGE_VALUE'),
  772.             'DEF_DATE_FORMAT'    => "%Y-%m-%d",
  773.             'TT_DATE_FORMAT'    => JText::_('JLIB_HTML_BEHAVIOR_TT_DATE_FORMAT'),
  774.             'WK'            => JText::_('JLIB_HTML_BEHAVIOR_WK'),
  775.             'TIME'            => JText::_('JLIB_HTML_BEHAVIOR_TIME')
  776.         );
  777.  
  778.         return 'Calendar._DN = ' json_encode($weekdays_full';'
  779.             . ' Calendar._SDN = ' json_encode($weekdays_short';'
  780.             . ' Calendar._FD = 0;'
  781.             . ' Calendar._MN = ' json_encode($months_long';'
  782.             . ' Calendar._SMN = ' json_encode($months_short';'
  783.             . ' Calendar._TT = ' json_encode($text';';
  784.     }
  785.  
  786.     /**
  787.      * Add unobtrusive JavaScript support to keep a tab state.
  788.      *
  789.      * Note that keeping tab state only works for inner tabs if in accordance with the following example
  790.      * parent tab = permissions
  791.      * child tab = permission-<identifier>
  792.      *
  793.      * Each tab header "a" tag also should have a unique href attribute
  794.      *
  795.      * @return  void 
  796.      *
  797.      * @since   3.2
  798.      */
  799.     public static function tabstate()
  800.     {
  801.         if (isset(self::$loaded[__METHOD__]))
  802.         {
  803.             return;
  804.         }
  805.         // Include jQuery
  806.         JHtml::_('jquery.framework');
  807.         JHtml::_('script''system/tabs-state.js'truetrue);
  808.         self::$loaded[__METHOD__true;
  809.     }
  810. }

Documentation generated on Tue, 19 Nov 2013 14:54:30 +0100 by phpDocumentor 1.4.3