yes, righ ...
so my idea now is:
make own Joomla event listener (if need independence from a frameworks) .... then the extension developer do like next:
In add the init script as other scripts $doc->addScript('extension/path/init.js');
Init script looks like next:
Joomla.addEvent('domready, domchanged' ,function(event, element){
  //init code for "element"
})
or
Joomla.addEvent(['load', 'domchanged'] ,function(event, element){
 	  //init code for "element"
})
and unload, can be useful for clean up before the elemend will be removed
Joomla.addEvent('unload' ,function(event, element){
  //init code for "element"
})
where 'load', 'domready' - default events, that all know/use
'domchanged' - custome event that fires from AJAX script for notify that in DOM something changed
'element' - changed element, default is document
AJAX developer in own script do next if need change something on page (delete some elements etc.):
//before change
Joomla.fireEvent('unload', oldElement);
//after changes is done
Joomla.fireEvent('domchanged', element);
For pass the script options in the init.js we can make Joomla.optionsStorage. For this can be need two methods in JDocument like:
/**
 * Add option for script
 * @param string $tag = extension name
 * @param array $options
 * @param string $prefix = can be
 * 					'com' (for components),
 * 					'mod' (for modules),
 * 					'plg' (for plugins),
 * 					'sys' (for joomla core),
 */
public function setScriptOptions( $options, $tag, $prefix )
{
	$this->_scripts_otions[$prefix.'_'.$tag] = $options;
	return $this;
}
and get options like:
public function getScriptOptions($tag = null,  $prefix = 'sys')
{
	if ($tag && $prefix)
	{
		return (empty($this->_scripts_otions[$prefix.'_'.$tag])) ? array() : $this->_scripts_otions[$prefix.'_'.$tag];
	}
	else {
		return $this->_scripts_otions;
	}
}
and some addittional action in DocumentRendererHead (also the result we can try put in some JS file that allow cach it in the browser):
if (!empty($document->_scripts_otions))
{
	$buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
	$buffer .= 'Joomla.optionsStorage = ' . json_encode($document->_scripts_otions) . ';' . $lnEnd;
	$buffer .= $tab . '</script>' . $lnEnd;
}
return $buffer;
after it init.js of the extension will look like:
Joomla.addEvent('domready, domchanged' ,function(event, element){
  var options = Joomla.optionsStorage.plg_verycoolgallery;
  //init code for "element"
})
Четвер, 29 листопада 2012 р. 16:20:02 UTC+2 користувач Ian написав: