Browse files

Make the multiselect behavior more flexible.

  • Loading branch information...
1 parent 493817f commit 456c817568860b0871f7a932f8e0e2dafc20a7e3 @realityking realityking committed Aug 14, 2011
Showing with 39 additions and 22 deletions.
  1. +32 −11 libraries/joomla/html/html/behavior.php
  2. +7 −11 media/system/js/multiselect.js
View
43 libraries/joomla/html/html/behavior.php
@@ -86,6 +86,8 @@ public static function mootools($debug = null)
/**
* Add unobtrusive javascript support for image captions.
*
+ * @param string $selector The selector for which a caption behaviour is to be applied.
+ *
* @return void
*
* @since 11.1
@@ -111,11 +113,8 @@ public static function caption($selector = 'img.caption')
$uncompressed = JFactory::getConfig()->get('debug') ? '-uncompressed' : '';
JHtml::_('script', 'system/caption' . $uncompressed . '.js', true, true);
- // Attach tooltips to document
- $document = JFactory::getDocument();
- $document
- ->addScriptDeclaration(
- "
+ // Attach caption to document
+ JFactory::getDocument()->addScriptDeclaration("
window.addEvent('load', function() {
new JCaption('".$selector."');
});"
@@ -283,10 +282,7 @@ public static function tooltip($selector = '.hasTip', $params = array())
$options = JHtmlBehavior::_getJSObject($opt);
// Attach tooltips to document
- $document = JFactory::getDocument();
- $document
- ->addScriptDeclaration(
- "
+ JFactory::getDocument()->addScriptDeclaration("
window.addEvent('domready', function() {
$$('$selector').each(function(el) {
var title = el.get('title');
@@ -309,7 +305,7 @@ public static function tooltip($selector = '.hasTip', $params = array())
/**
* Add unobtrusive javascript support for modal links.
*
- * @param string $selector The class selector for which a modal behaviour is to be applied.
+ * @param string $selector The selector for which a modal behaviour is to be applied.
* @param array $params An array of parameters for the modal behaviour.
* Options for the modal behaviour can be:
* - ajaxOptions
@@ -401,16 +397,41 @@ public static function modal($selector = 'a.modal', $params = array())
/**
* JavaScript behavior to allow shift select in grids
*
+ * @param string $id The id of the form for which a multiselect behaviour is to be applied.
+ *
* @return void
*
* @since 11.1
*/
- public static function multiselect()
+ public static function multiselect($id = 'adminForm')
{
+ static $multiselect;
+
+ if (!isset($multiselect))
+ {
+ $multiselect = array();
+ }
+
+ // Only load once
+ if (isset($multiselect[$selector]))
+ {
+ return;
+ }
+
// Include MooTools framework
self::framework();
+
JHtml::_('script', 'system/multiselect.js', true, true);
+ // Attach multiselect to document
+ JFactory::getDocument()->addScriptDeclaration("
+ window.addEvent('domready', function() {
+ new Joomla.JMultiSelect('".$id."');
+ });"
+ );
+
+ // Set static array
+ $multiselect[$selector] = true;
return;
}
View
18 media/system/js/multiselect.js
@@ -12,11 +12,14 @@
Joomla.JMultiSelect = new Class({
initialize : function(table) {
this.table = document.id(table);
- this.boxes = table.getElements('input[type=checkbox]');
- this.boxes.addEvent('click', function(e){
- this.doselect(e);
- }.bind(this));
+ if (table) {
+ this.boxes = table.getElements('input[type=checkbox]');
+ this.boxes.addEvent('click', function(e){
+ this.doselect(e);
+ }.bind(this));
+ }
},
+
doselect: function(e) {
var current = document.id(e.target);
if (e.shift && typeOf(this.last) !== 'null') {
@@ -32,11 +35,4 @@
this.last = current;
}
});
-
- window.addEvent('domready', function() {
- var adminForm = document.id('adminForm');
- if (adminForm) {
- new Joomla.JMultiSelect(adminForm);
- }
- });
})();

0 comments on commit 456c817

Please sign in to comment.