JHtmlBehavior/keepalive: Difference between revisions
From Joomla! Documentation
m clean up |
m preparing for archive only |
||
Line 46: | Line 46: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=keepalive | category=keepalive | ||
category=JHtmlBehavior | category=JHtmlBehavior | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* |
Latest revision as of 01:45, 25 March 2017
Description
Keep session alive, for example, while editing or creating an article.
<! removed transcluded page call, red link never existed >
Syntax
static keepalive()
Defined in
libraries/joomla/html/html/behavior.php
Importing
jimport( 'joomla.html.html.behavior' );
Source Body
public static function keepalive()
{
// Include mootools framework
JHtmlBehavior::mootools();
$config = &JFactory::getConfig();
$lifetime = ($config->getValue('lifetime') * 60000);
$refreshTime = ($lifetime <= 60000) ? 30000 : $lifetime - 60000;
//refresh time is 1 minute less than the liftime assined in the configuration.php file
$document = &JFactory::getDocument();
$script = '';
$script .= 'function keepAlive() {';
$script .= ' var myAjax = new Ajax("index.php", { method: "get" }).request();';
$script .= '}';
$script .= ' window.addEvent("domready", function()';
$script .= '{ keepAlive.periodical('.$refreshTime.'); }';
$script .= ');';
$document->addScriptDeclaration($script);
return;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples