Source for file behavior.php
Documentation is available at behavior.php
* @package Joomla.Libraries
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Utility class for JavaScript behaviors
* @package Joomla.Libraries
* Array containing information for loaded files
protected static $loaded =
array();
* Method to load the MooTools framework into the document head
* If debugging mode is on an uncompressed version of MooTools is included for easier debugging.
* @param boolean $extras Flag to determine whether to load MooTools More in addition to Core
* @param mixed $debug Is debugging mode on? [optional]
public static function framework($extras =
false, $debug =
null)
$type =
$extras ?
'more' :
'core';
if (!empty(static::$loaded[__METHOD__
][$type]))
// If no debugging value is set, use the configuration setting
$config =
JFactory::getConfig();
$debug =
$config->get('debug');
if ($type !=
'core' &&
empty(static::$loaded[__METHOD__
]['core']))
static::framework(false, $debug);
JHtml::_('script', 'system/mootools-' .
$type .
'.js', false, true, false, false, $debug);
JHtml::_('script', 'system/core.js', false, true);
static::$loaded[__METHOD__
][$type] =
true;
* Add unobtrusive JavaScript support for image captions.
* @param string $selector The selector for which a caption behaviour is to be applied.
public static function caption($selector =
'img.caption')
if (isset
(static::$loaded[__METHOD__
][$selector]))
JHtml::_('script', 'system/caption.js', true, true);
// Attach caption to document
"jQuery(window).on('load', function() {
new JCaption('" .
$selector .
"');
static::$loaded[__METHOD__
][$selector] =
true;
* Add unobtrusive JavaScript support for form validation.
* To enable form validation the form tag must have class="form-validate".
* Each field that needs to be validated needs to have class="validate".
* Additional handlers can be added to the handler for username, password,
* numeric and email. To use these add class="validate-email" and so on.
if (isset
(static::$loaded[__METHOD__
]))
// Add validate.js language strings
// Include MooTools More framework
static::framework('more');
JHtml::_('script', 'system/validate.js', false, true);
static::$loaded[__METHOD__
] =
true;
* Add unobtrusive JavaScript support for submenu switcher support
if (isset
(static::$loaded[__METHOD__
]))
JHtml::_('script', 'system/switcher.js', true, true);
document.switcher = null;
var toggler = document.getElementById('submenu');
var element = document.getElementById('config-document');
document.switcher = new JSwitcher(toggler, element);
static::$loaded[__METHOD__
] =
true;
* Add unobtrusive JavaScript support for a combobox effect.
* Note that this control is only reliable in absolutely positioned elements.
* Avoid using a combobox in a slider or dynamic pane.
if (isset
(static::$loaded[__METHOD__
]))
// Include MooTools framework
JHtml::_('script', 'system/combobox.js', true, true);
static::$loaded[__METHOD__
] =
true;
* Add unobtrusive JavaScript support for a hover tooltips.
* Add a title attribute to any element in the form
* Uses the core Tips class in MooTools.
* @param string $selector The class selector for the tooltip.
* @param array $params An array of options for the tooltip.
* Options for the tooltip can be:
* - maxTitleChars integer The maximum number of characters in the tooltip title (defaults to 50).
* - offsets object The distance of your tooltip from the mouse (defaults to {'x': 16, 'y': 16}).
* - showDelay integer The millisecond delay the show event is fired (defaults to 100).
* - hideDelay integer The millisecond delay the hide hide is fired (defaults to 100).
* - className string The className your tooltip container will get.
* - fixed boolean If set to true, the toolTip will not follow the mouse.
* - onShow function The default function for the show event, passes the tip element
* and the currently hovered element.
* - onHide function The default function for the hide event, passes the currently
public static function tooltip($selector =
'.hasTip', $params =
array())
if (isset
(static::$loaded[__METHOD__
][$sig]))
// Include MooTools framework
$opt['maxTitleChars'] =
(isset
($params['maxTitleChars']) &&
($params['maxTitleChars'])) ? (int)
$params['maxTitleChars'] :
50;
// Offsets needs an array in the format: array('x'=>20, 'y'=>30)
$opt['offset'] =
(isset
($params['offset']) &&
(is_array($params['offset']))) ?
$params['offset'] :
null;
$opt['showDelay'] =
(isset
($params['showDelay'])) ? (int)
$params['showDelay'] :
null;
$opt['hideDelay'] =
(isset
($params['hideDelay'])) ? (int)
$params['hideDelay'] :
null;
$opt['className'] =
(isset
($params['className'])) ?
$params['className'] :
null;
$opt['fixed'] =
(isset
($params['fixed']) &&
($params['fixed'])) ?
true :
false;
$opt['onShow'] =
(isset
($params['onShow'])) ?
'\\' .
$params['onShow'] :
null;
$opt['onHide'] =
(isset
($params['onHide'])) ?
'\\' .
$params['onHide'] :
null;
$options =
JHtml::getJSObject($opt);
// Attach tooltips to document
"window.addEvent('domready', function() {
$$('$selector').each(function(el) {
var title = el.get('title');
var parts = title.split('::', 2);
el.store('tip:title', parts[0]);
el.store('tip:text', parts[1]);
var JTooltips = new Tips($$('$selector'), $options);
static::$loaded[__METHOD__
][$sig] =
true;
* Add unobtrusive JavaScript support for modal links.
* @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:
public static function modal($selector =
'a.modal', $params =
array())
// Load the necessary files if they haven't yet been loaded
if (!isset
(static::$loaded[__METHOD__
]))
// Include MooTools framework
// Load the JavaScript and css
JHtml::_('script', 'system/modal.js', true, true);
JHtml::_('stylesheet', 'system/modal.css', array(), true);
if (isset
(static::$loaded[__METHOD__
][$sig]))
$opt['ajaxOptions'] =
(isset
($params['ajaxOptions']) &&
(is_array($params['ajaxOptions']))) ?
$params['ajaxOptions'] :
null;
$opt['handler'] =
(isset
($params['handler'])) ?
$params['handler'] :
null;
$opt['parseSecure'] =
(isset
($params['parseSecure'])) ? (bool)
$params['parseSecure'] :
null;
$opt['closable'] =
(isset
($params['closable'])) ? (bool)
$params['closable'] :
null;
$opt['closeBtn'] =
(isset
($params['closeBtn'])) ? (bool)
$params['closeBtn'] :
null;
$opt['iframePreload'] =
(isset
($params['iframePreload'])) ? (bool)
$params['iframePreload'] :
null;
$opt['iframeOptions'] =
(isset
($params['iframeOptions']) &&
(is_array($params['iframeOptions']))) ?
$params['iframeOptions'] :
null;
$opt['size'] =
(isset
($params['size']) &&
(is_array($params['size']))) ?
$params['size'] :
null;
$opt['shadow'] =
(isset
($params['shadow'])) ?
$params['shadow'] :
null;
$opt['overlay'] =
(isset
($params['overlay'])) ?
$params['overlay'] :
null;
$opt['onOpen'] =
(isset
($params['onOpen'])) ?
$params['onOpen'] :
null;
$opt['onClose'] =
(isset
($params['onClose'])) ?
$params['onClose'] :
null;
$opt['onUpdate'] =
(isset
($params['onUpdate'])) ?
$params['onUpdate'] :
null;
$opt['onResize'] =
(isset
($params['onResize'])) ?
$params['onResize'] :
null;
$opt['onMove'] =
(isset
($params['onMove'])) ?
$params['onMove'] :
null;
$opt['onShow'] =
(isset
($params['onShow'])) ?
$params['onShow'] :
null;
$opt['onHide'] =
(isset
($params['onHide'])) ?
$params['onHide'] :
null;
if (isset
($params['fullScreen']) && (bool)
$params['fullScreen'])
$opt['size'] =
array('x' =>
'\\window.getSize().x-80', 'y' =>
'\\window.getSize().y-80');
$options =
JHtml::getJSObject($opt);
// Attach modal behavior to document
window.addEvent('domready', function() {
SqueezeBox.initialize(" .
$options .
");
SqueezeBox.assign($$('" .
$selector .
"'), {
static::$loaded[__METHOD__
][$sig] =
true;
* 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.
if (isset
(static::$loaded[__METHOD__
][$id]))
JHtml::_('script', 'system/multiselect.js', true, true);
// Attach multiselect to document
"window.addEvent('domready', function() {
new Joomla.JMultiSelect('" .
$id .
"');
static::$loaded[__METHOD__
][$id] =
true;
* Add unobtrusive javascript support for a collapsible tree.
* @param string $id An index
* @param array $params An array of options.
* @param array $root The root node
public static function tree($id, $params =
array(), $root =
array())
// Include MooTools framework
JHtml::_('script', 'system/mootree.js', true, true, false, false);
JHtml::_('stylesheet', 'system/mootree.css', array(), true);
if (isset
(static::$loaded[__METHOD__
][$id]))
$opt['div'] =
(array_key_exists('div', $params)) ?
$params['div'] :
$id .
'_tree';
$opt['mode'] =
(array_key_exists('mode', $params)) ?
$params['mode'] :
'folders';
$opt['grid'] =
(array_key_exists('grid', $params)) ?
'\\' .
$params['grid'] :
true;
$opt['theme'] =
(array_key_exists('theme', $params)) ?
$params['theme'] :
JHtml::_('image', 'system/mootree.gif', '', array(), true, true);
$opt['onExpand'] =
(array_key_exists('onExpand', $params)) ?
'\\' .
$params['onExpand'] :
null;
$opt['onSelect'] =
(array_key_exists('onSelect', $params)) ?
'\\' .
$params['onSelect'] :
null;
$opt['onClick'] =
(array_key_exists('onClick', $params)) ?
'\\' .
$params['onClick']
:
'\\function(node){ window.open(node.data.url, node.data.target != null ? node.data.target : \'_self\'); }';
$options =
JHtml::getJSObject($opt);
$rt['openicon'] =
(array_key_exists('openicon', $root)) ?
$root['openicon'] :
null;
$rootNode =
JHtml::getJSObject($rt);
$js =
' window.addEvent(\'domready\', function(){
tree' .
$treeName .
' = new MooTreeControl(' .
$options .
',' .
$rootNode .
');
tree' .
$treeName .
'.adopt(\'' .
$id .
'\');})';
// Attach tooltips to document
$document->addScriptDeclaration($js);
static::$loaded[__METHOD__
][$id] =
true;
* Add unobtrusive JavaScript support for a calendar control.
if (isset
(static::$loaded[__METHOD__
]))
JHtml::_('stylesheet', 'system/calendar-jos.css', array(' title' =>
JText::_('JLIB_HTML_BEHAVIOR_GREEN'), ' media' =>
'all'), true);
JHtml::_('script', $tag .
'/calendar.js', false, true);
JHtml::_('script', $tag .
'/calendar-setup.js', false, true);
$translation =
static::calendartranslation();
$document->addScriptDeclaration($translation);
static::$loaded[__METHOD__
] =
true;
* Add unobtrusive JavaScript support for a color picker.
if (isset
(static::$loaded[__METHOD__
]))
JHtml::_('script', 'jui/jquery.minicolors.min.js', false, true);
JHtml::_('stylesheet', 'jui/jquery.minicolors.css', false, true);
jQuery(document).ready(function (){
jQuery('.minicolors').each(function() {
jQuery(this).minicolors({
control: jQuery(this).attr('data-control') || 'hue',
position: jQuery(this).attr('data-position') || 'right',
static::$loaded[__METHOD__
] =
true;
* Add unobtrusive JavaScript support for a simple color picker.
if (isset
(static::$loaded[__METHOD__
]))
JHtml::_('script', 'jui/jquery.simplecolors.min.js', false, true);
JHtml::_('stylesheet', 'jui/jquery.simplecolors.css', false, true);
jQuery(document).ready(function (){
jQuery('select.simplecolors').simplecolors();
static::$loaded[__METHOD__
] =
true;
* Keep session alive, for example, while editing or creating an article.
if (isset
(static::$loaded[__METHOD__
]))
// Include MooTools framework
$lifetime =
($config->get('lifetime') *
60000);
$refreshTime =
($lifetime <=
60000) ?
30000 :
$lifetime -
60000;
// Refresh time is 1 minute less than the liftime assined in the configuration.php file.
// The longest refresh period is one hour to prevent integer overflow.
if ($refreshTime >
3600000 ||
$refreshTime <=
0)
$script .=
'function keepAlive() {';
$script .=
' var myAjax = new Request({method: "get", url: "index.php"}).send();';
$script .=
' window.addEvent("domready", function()';
$script .=
'{ keepAlive.periodical(' .
$refreshTime .
'); }';
$document->addScriptDeclaration($script);
static::$loaded[__METHOD__
] =
true;
* Highlight some words via Javascript.
* @param array $terms Array of words that should be highlighted.
* @param string $start ID of the element that marks the begin of the section in which words
* should be highlighted. Note this element will be removed from the DOM.
* @param string $end ID of the element that end this section.
* Note this element will be removed from the DOM.
* @param string $className Class name of the element highlights are wrapped in.
* @param string $tag Tag that will be used to wrap the highlighted words.
public static function highlighter(array $terms, $start =
'highlighter-start', $end =
'highlighter-end', $className =
'highlight', $tag =
'span')
$sig =
md5(serialize(array($terms, $start, $end)));
if (isset
(static::$loaded[__METHOD__
][$sig]))
JHtml::_('script', 'system/highlighter.js', true, true);
$document->addScriptDeclaration("
var start = document.getElementById('" .
$start .
"');
var end = document.getElementById('" .
$end .
"');
if (!start || !end || !Joomla.Highlighter) {
highlighter = new Joomla.Highlighter({
className: '" .
$className .
"',
}).highlight([\"" .
implode('","', $terms) .
"\"]);
static::$loaded[__METHOD__
][$sig] =
true;
* Break us out of any containing iframes
if (isset
(static::$loaded[__METHOD__
]))
// Include MooTools framework
$js =
"window.addEvent('domready', function () {if (top == self) {document.documentElement.style.display = 'block'; }" .
" else {top.location = self.location; }});";
$document->addStyleDeclaration('html { display:none }');
$document->addScriptDeclaration($js);
static::$loaded[__METHOD__
] =
true;
* Internal method to get a JavaScript object notation string from an array
* @param array $array The array to convert to JavaScript object notation
* @return string JavaScript object notation representation of the array
* @deprecated 13.3 (Platform) & 4.0 (CMS) - Use JHtml::getJSObject() instead.
JLog::add('JHtmlBehavior::_getJSObject() is deprecated. JHtml::getJSObject() instead..', JLog::WARNING, 'deprecated');
return JHtml::getJSObject($array);
* Internal method to translate the JavaScript Calendar
* @return string JavaScript that translates the object
// Guard clause, avoids unnecessary nesting
// To keep the code simple here, run strings through JText::_() using array_map()
$callback =
array('JText','_');
'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY'
'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'
'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE',
'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'
'JANUARY_SHORT', 'FEBRUARY_SHORT', 'MARCH_SHORT', 'APRIL_SHORT', 'MAY_SHORT', 'JUNE_SHORT',
'JULY_SHORT', 'AUGUST_SHORT', 'SEPTEMBER_SHORT', 'OCTOBER_SHORT', 'NOVEMBER_SHORT', 'DECEMBER_SHORT'
// This will become an object in Javascript but define it first in PHP for readability
$today =
" " .
JText::_('JLIB_HTML_BEHAVIOR_TODAY') .
" ";
'INFO' =>
JText::_('JLIB_HTML_BEHAVIOR_ABOUT_THE_CALENDAR'),
'ABOUT' =>
"DHTML Date/Time Selector\n"
.
"(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n"
.
"For latest version visit: http://www.dynarch.com/projects/calendar/\n"
.
"Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details."
.
JText::_('JLIB_HTML_BEHAVIOR_DATE_SELECTION')
.
JText::_('JLIB_HTML_BEHAVIOR_YEAR_SELECT')
.
JText::_('JLIB_HTML_BEHAVIOR_MONTH_SELECT')
.
JText::_('JLIB_HTML_BEHAVIOR_HOLD_MOUSE'),
.
"- Click on any of the time parts to increase it\n"
.
"- or Shift-click to decrease it\n"
.
"- or click and drag for faster selection.",
'PREV_YEAR' =>
JText::_('JLIB_HTML_BEHAVIOR_PREV_YEAR_HOLD_FOR_MENU'),
'PREV_MONTH' =>
JText::_('JLIB_HTML_BEHAVIOR_PREV_MONTH_HOLD_FOR_MENU'),
'GO_TODAY' =>
JText::_('JLIB_HTML_BEHAVIOR_GO_TODAY'),
'NEXT_MONTH' =>
JText::_('JLIB_HTML_BEHAVIOR_NEXT_MONTH_HOLD_FOR_MENU'),
'SEL_DATE' =>
JText::_('JLIB_HTML_BEHAVIOR_SELECT_DATE'),
'DRAG_TO_MOVE' =>
JText::_('JLIB_HTML_BEHAVIOR_DRAG_TO_MOVE'),
'DAY_FIRST' =>
JText::_('JLIB_HTML_BEHAVIOR_DISPLAY_S_FIRST'),
'CLOSE' =>
JText::_('JLIB_HTML_BEHAVIOR_CLOSE'),
'TODAY' =>
JText::_('JLIB_HTML_BEHAVIOR_TODAY'),
'TIME_PART' =>
JText::_('JLIB_HTML_BEHAVIOR_SHIFT_CLICK_OR_DRAG_TO_CHANGE_VALUE'),
'DEF_DATE_FORMAT' =>
"%Y-%m-%d",
'TT_DATE_FORMAT' =>
JText::_('JLIB_HTML_BEHAVIOR_TT_DATE_FORMAT'),
'WK' =>
JText::_('JLIB_HTML_BEHAVIOR_WK'),
'TIME' =>
JText::_('JLIB_HTML_BEHAVIOR_TIME')
return 'Calendar._DN = ' .
json_encode($weekdays_full) .
';'
.
' Calendar._SDN = ' .
json_encode($weekdays_short) .
';'
.
' Calendar._SMN = ' .
json_encode($months_short) .
';'
* Add unobtrusive JavaScript support to keep a tab state.
* Note that keeping tab state only works for inner tabs if in accordance with the following example
* parent tab = permissions
* child tab = permission-<identifier>
* Each tab header "a" tag also should have a unique href attribute
if (isset
(self::$loaded[__METHOD__
]))
JHtml::_('jquery.framework');
JHtml::_('script', 'system/tabs-state.js', true, true);
self::$loaded[__METHOD__
] =
true;
Documentation generated on Tue, 19 Nov 2013 14:54:30 +0100 by phpDocumentor 1.4.3