Вот код плагина:
<?php
@license http://www.gnu.org/licenses/gpl.html
http://www.joomultra.com
defined('_JEXEC') or die;
@package @subpackage
class plgSystemJUTooltip extends JPlugin
{
var $_body = NULL;
@access @param @param @since
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
private function addheadtag($tagtype, $data)
{
$document = JFactory::getDocument();
$styles = $document->_styleSheets;
$scripts = $document->_scripts;
$style_arr = array();
$script_arr = array();
$data = array_unique($data);
if ($tagtype=="js") {
foreach ($scripts AS $key => $value) {
$script_arr[] = $key;
}
foreach ($data AS $item) {
if (!in_array($item, $script_arr)) {
$headtag_item = '<script src="' . $item . '" type="text/javascript"></script>';
if (strpos($this->_body, $headtag_item)===false) $headtag[] = $headtag_item;
}
}
}
if ($tagtype=="css") {
foreach ($styles AS $key => $value) {
$style_arr[] = $key;
}
foreach ($data AS $item) {
if (!in_array($item, $style_arr)) {
$headtag_item = '<link href="' . $item . '" type="text/css" rel="stylesheet"/>';
if (strpos($this->_body, $headtag_item)===false) $headtag[] = $headtag_item;
}
}
}
if ($tagtype=="javascript") $headtag[] = '<script type="text/javascript">' . implode("\n", $data) . '</script>';
$this->_body = str_replace('</head>', "\t" . implode("\n\t", $headtag) . "\n</head>", $this->_body);
}
private function checkjQuery()
{
$header = JResponse::getBody();
$regex= '#\<script.* src=\".*jquery([0-9\.-]|min|pack)*?.js\".*\>\<\/script\>#m';
preg_match($regex, $header, $matches);
if (empty($matches)) return FALSE;
else return TRUE;
}
public function checkjQueryEasing()
{
$header = JResponse::getBody();
$regex= '#\<script.* src=\".*jquery.easing([0-9\.]|min|pack)*?.js\".*\>\<\/script\>#m';
preg_match($regex, $header, $matches);
if (empty($matches)) return FALSE;
else return TRUE;
}
@since
public function onAfterRender()
{
$app = JFactory::getApplication();
if ($app->isAdmin())
return;
$this->_body = JResponse::getBody();
$ju_tooltip_param[] = "effect: '".$this->params->get('effect','toggle')."'";
$ju_tooltip_param[] = "showDuration: ".$this->params->get('showDuration','200');
$ju_tooltip_param[] = "hideDuration: ".$this->params->get('hideDuration','200');
$ju_tooltip_param[] = "easing: '".$this->params->get('easing','linear')."'";
$ju_tooltip_param[] = "predelay: ".$this->params->get('predelay','0');
$ju_tooltip_param[] = "delay: ".$this->params->get('delay','30');
$ju_tooltip_param[] = "opacity: ".$this->params->get('opacity','1');
$ju_tooltip_param[] = "tip: '".$this->params->get('tip','')."'";
$ju_tooltip_param[] = "fadeIE: ".$this->params->get('fadeIE','false');
$ju_tooltip_param[] = "position : ['".$this->params->get('vertical','top')."','".$this->params->get('horizontal','center')."']";
$ju_tooltip_param[] = "offset: ".$this->params->get('offset','[0, 0]');
$ju_tooltip_param[] = "cancelDefault: ".$this->params->get('cancelDefault','true');
$ju_tooltip_param[] = "manualCloseTooltip: ".$this->params->get('manualCloseTooltip','false');
if ($this->params->get('showtooltipwhen','mouseenter')=='click') {
$ju_tooltip_param[] = "events: {
def: \"click,mouseleave\"
}";
}
$ju_tooltip_param[] = "direction: '".$this->params->get('slide_direction','up')."'";
$ju_tooltip_param[] = "bounce: ".$this->params->get('bounce','false');
$ju_tooltip_param[] = "slideOffset: ".$this->params->get('slideOffset','10');
$ju_tooltip_param_str = implode(", ",$ju_tooltip_param);
if ($this->params->get('slide_direction','up')=='up') {
$dynamic_param = "top: { direction: 'up' } ";
} elseif ($this->params->get('slide_direction','up')=='down') {
$dynamic_param = "bottom: { direction: 'down' } ";
}
$tooltip_javascript[] = "jQuery(document).ready(function($){
jutooltip_api = $('.jutooltip').jutooltip({".$ju_tooltip_param_str."}).jutooltip_dynamic({".$dynamic_param."});
});";
$tooltip_css[] = JURI::Base()."plugins/system/jutooltip/assets/css/styles.css";
$tooltip_css[] = JURI::Base()."plugins/system/jutooltip/assets/themes/".$this->params->get('theme','default')."/styles.css";
if( $this->params->get('loadjquery', '2')==1 || ($this->params->get('loadjquery', '2')==2 && !plgSystemJUTooltip::checkjQuery()) ) {
if($this->params->get('loadjqueryfrom', '1')==1) { $tooltip_js[] = JURI::Base()."plugins/system/jutooltip/assets/js/jquery-1.7.2.min.js"; }
else if($this->params->get('loadjqueryfrom', '1')==2) { $tooltip_js[] = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"; }
}
if ( !plgSystemJUTooltip::checkjQueryEasing() ) $tooltip_js[] = JURI::Base()."plugins/system/jutooltip/assets/js/jquery.easing.1.3.min.js";
$tooltip_js[] = JURI::Base()."plugins/system/jutooltip/assets/js/jutooltip.min.js";
$tooltip_js[] = JURI::Base()."plugins/system/jutooltip/assets/js/jutooltip.effects.min.js";
$tooltip_js[] = JURI::Base()."plugins/system/jutooltip/assets/js/jutooltip.dynamic.min.js";
plgSystemJUTooltip::addheadtag('css', $tooltip_css);
plgSystemJUTooltip::addheadtag('js', $tooltip_js);
plgSystemJUTooltip::addheadtag('javascript', $tooltip_javascript);
JResponse::setBody($this->_body);
}
}
_____________
www.godbook.cc.ua —
Новый Завет!