Source for file formbehavior.php

Documentation is available at formbehavior.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 form related behaviors
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       3.0
  18.  */
  19. abstract class JHtmlFormbehavior
  20. {
  21.     /**
  22.      * @var    array  Array containing information for loaded files
  23.      * @since  3.0
  24.      */
  25.     protected static $loaded array();
  26.  
  27.     /**
  28.      * Method to load the Chosen JavaScript framework and supporting CSS into the document head
  29.      *
  30.      * If debugging mode is on an uncompressed version of Chosen is included for easier debugging.
  31.      *
  32.      * @param   string  $selector  Class for Chosen elements.
  33.      * @param   mixed   $debug     Is debugging mode on? [optional]
  34.      *
  35.      * @return  void 
  36.      *
  37.      * @since   3.0
  38.      */
  39.     public static function chosen($selector '.advancedSelect'$debug null)
  40.     {
  41.         if (isset(static::$loaded[__METHOD__][$selector]))
  42.         {
  43.             return;
  44.         }
  45.  
  46.         // Include jQuery
  47.         JHtml::_('jquery.framework');
  48.  
  49.         // Add chosen.jquery.js language strings
  50.         JText::script('JGLOBAL_SELECT_SOME_OPTIONS');
  51.         JText::script('JGLOBAL_SELECT_AN_OPTION');
  52.         JText::script('JGLOBAL_SELECT_NO_RESULTS_MATCH');
  53.  
  54.         // If no debugging value is set, use the configuration setting
  55.         if ($debug === null)
  56.         {
  57.             $config JFactory::getConfig();
  58.             $debug  = (boolean) $config->get('debug');
  59.         }
  60.  
  61.         JHtml::_('script''jui/chosen.jquery.min.js'falsetruefalsefalse$debug);
  62.         JHtml::_('stylesheet''jui/chosen.css'falsetrue);
  63.         JFactory::getDocument()->addScriptDeclaration("
  64.                 jQuery(document).ready(function (){
  65.                     jQuery('" $selector "').chosen({
  66.                         disable_search_threshold : 10,
  67.                         allow_single_deselect : true
  68.                     });
  69.                 });
  70.             "
  71.         );
  72.  
  73.         static::$loaded[__METHOD__][$selectortrue;
  74.  
  75.         return;
  76.     }
  77.  
  78.     /**
  79.      * Method to load the AJAX Chosen library
  80.      *
  81.      * If debugging mode is on an uncompressed version of AJAX Chosen is included for easier debugging.
  82.      *
  83.      * @param   JRegistry  $options  Options in a JRegistry object
  84.      * @param   mixed      $debug    Is debugging mode on? [optional]
  85.      *
  86.      * @return  void 
  87.      *
  88.      * @since   3.0
  89.      */
  90.     public static function ajaxchosen(JRegistry $options$debug null)
  91.     {
  92.         // Retrieve options/defaults
  93.         $selector       $options->get('selector''.tagfield');
  94.         $type           $options->get('type''GET');
  95.         $url            $options->get('url'null);
  96.         $dataType       $options->get('dataType''json');
  97.         $jsonTermKey    $options->get('jsonTermKey''term');
  98.         $afterTypeDelay $options->get('afterTypeDelay''500');
  99.         $minTermLength  $options->get('minTermLength''3');
  100.  
  101.         JText::script('JGLOBAL_KEEP_TYPING');
  102.         JText::script('JGLOBAL_LOOKING_FOR');
  103.  
  104.         // Ajax URL is mandatory
  105.         if (!empty($url))
  106.         {
  107.             if (isset(static::$loaded[__METHOD__][$selector]))
  108.             {
  109.                 return;
  110.             }
  111.             // Include jQuery
  112.             JHtml::_('jquery.framework');
  113.  
  114.             // Requires chosen to work
  115.             static::chosen($selector$debug);
  116.  
  117.             JHtml::_('script''jui/ajax-chosen.min.js'falsetruefalsefalse$debug);
  118.             JFactory::getDocument()->addScriptDeclaration("
  119.                 (function($){
  120.                     $(document).ready(function () {
  121.                         $('" $selector "').ajaxChosen({
  122.                             type: '" $type "',
  123.                             url: '" $url "',
  124.                             dataType: '" $dataType "',
  125.                             jsonTermKey: '" $jsonTermKey "',
  126.                             afterTypeDelay: '" $afterTypeDelay "',
  127.                             minTermLength: '" $minTermLength "'
  128.                         }, function (data) {
  129.                             var results = [];
  130.  
  131.                             $.each(data, function (i, val) {
  132.                                 results.push({ value: val.value, text: val.text });
  133.                             });
  134.  
  135.                             return results;
  136.                         });
  137.                     });
  138.                 })(jQuery);
  139.                 "
  140.             );
  141.  
  142.             static::$loaded[__METHOD__][$selectortrue;
  143.         }
  144.  
  145.         return;
  146.     }
  147. }

Documentation generated on Tue, 19 Nov 2013 15:03:45 +0100 by phpDocumentor 1.4.3