Source for file sortablelist.php

Documentation is available at sortablelist.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.  * HTML utility class for creating a sortable table list
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       3.0
  18.  */
  19. abstract class JHtmlSortablelist
  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 Sortable script and make table sortable
  29.      *
  30.      * @param   string   $tableId                 DOM id of the table
  31.      * @param   string   $formId                  DOM id of the form
  32.      * @param   string   $sortDir                 Sort direction
  33.      * @param   string   $saveOrderingUrl         Save ordering url, ajax-load after an item dropped
  34.      * @param   boolean  $proceedSaveOrderButton  Set whether a save order button is displayed
  35.      * @param   boolean  $nestedList              Set whether the list is a nested list
  36.      *
  37.      * @return  void 
  38.      *
  39.      * @since   3.0
  40.      */
  41.     public static function sortable($tableId$formId$sortDir 'asc'$saveOrderingUrl$proceedSaveOrderButton true$nestedList false)
  42.     {
  43.         // Only load once
  44.         if (isset(static::$loaded[__METHOD__]))
  45.         {
  46.             return;
  47.         }
  48.  
  49.         // Depends on jQuery UI
  50.         JHtml::_('jquery.ui'array('core''sortable'));
  51.  
  52.         JHtml::_('script''jui/sortablelist.js'falsetrue);
  53.         JHtml::_('stylesheet''jui/sortablelist.css'falsetruefalse);
  54.  
  55.         // Attach sortable to document
  56.         JFactory::getDocument()->addScriptDeclaration("
  57.             (function ($){
  58.                 $(document).ready(function (){
  59.                     var sortableList = new $.JSortableList('#" $tableId " tbody','" $formId "','" $sortDir "' , '" $saveOrderingUrl "','','" $nestedList "');
  60.                 });
  61.             })(jQuery);
  62.             "
  63.         );
  64.  
  65.         if ($proceedSaveOrderButton)
  66.         {
  67.             static::_proceedSaveOrderButton();
  68.         }
  69.  
  70.         // Set static array
  71.         static::$loaded[__METHOD__true;
  72.         return;
  73.     }
  74.  
  75.     /**
  76.      * Method to inject script for enabled and disable Save order button
  77.      * when changing value of ordering input boxes
  78.      *
  79.      * @return  void 
  80.      *
  81.      * @since   3.0
  82.      */
  83.     public static function _proceedSaveOrderButton()
  84.     {
  85.         JFactory::getDocument()->addScriptDeclaration(
  86.             "(function ($){
  87.                 $(document).ready(function (){
  88.                     var saveOrderButton = $('.saveorder');
  89.                     saveOrderButton.css({'opacity':'0.2', 'cursor':'default'}).attr('onclick','return false;');
  90.                     var oldOrderingValue = '';
  91.                     $('.text-area-order').focus(function ()
  92.                     {
  93.                         oldOrderingValue = $(this).attr('value');
  94.                     })
  95.                     .keyup(function (){
  96.                         var newOrderingValue = $(this).attr('value');
  97.                         if (oldOrderingValue != newOrderingValue)
  98.                         {
  99.                             saveOrderButton.css({'opacity':'1', 'cursor':'pointer'}).removeAttr('onclick')
  100.                         }
  101.                     });
  102.                 });
  103.             })(jQuery);"
  104.         );
  105.         return;
  106.     }
  107. }

Documentation generated on Tue, 19 Nov 2013 15:14:01 +0100 by phpDocumentor 1.4.3