Permalink
Browse files

Make JCaption more flexible.

  • Loading branch information...
1 parent afb0b0a commit 493817fe1446af2e0ad7f456b9d266dbc89b0006 @realityking realityking committed Aug 14, 2011
Showing with 27 additions and 11 deletions.
  1. +21 −4 libraries/joomla/html/html/behavior.php
  2. +1 −6 media/system/js/caption-uncompressed.js
  3. +5 −1 media/system/js/caption.js
View
25 libraries/joomla/html/html/behavior.php
@@ -90,12 +90,17 @@ public static function mootools($debug = null)
*
* @since 11.1
*/
- public static function caption()
+ public static function caption($selector = 'img.caption')
{
- static $loaded = false;
+ static $caption;
+
+ if (!isset($caption))
+ {
+ $caption = array();
+ }
// Only load once
- if ($loaded)
+ if (isset($caption[$selector]))
{
return;
}
@@ -105,7 +110,19 @@ public static function caption()
$uncompressed = JFactory::getConfig()->get('debug') ? '-uncompressed' : '';
JHtml::_('script', 'system/caption' . $uncompressed . '.js', true, true);
- $loaded = true;
+
+ // Attach tooltips to document
+ $document = JFactory::getDocument();
+ $document
+ ->addScriptDeclaration(
+ "
+ window.addEvent('load', function() {
+ new JCaption('".$selector."');
+ });"
+ );
+
+ // Set static array
+ $tips[$selector] = true;
}
/**
View
7 media/system/js/caption-uncompressed.js
@@ -48,7 +48,7 @@ var JCaption = new Class({
element.parentNode.insertBefore(container, element);
container.appendChild(element);
- if ( element.title != "" ) {
+ if (element.title != "") {
container.appendChild(text);
}
container.className = this.selector.replace('.', '_');
@@ -60,8 +60,3 @@ var JCaption = new Class({
}
});
-document.caption = null;
-window.addEvent('load', function() {
- var caption = new JCaption('img.caption')
- document.caption = caption
-});
View
6 media/system/js/caption.js
@@ -1 +1,5 @@
-var JCaption=new Class({initialize:function(b){this.selector=b;var a=$$(b);a.each(function(c){this.createCaption(c)},this)},createCaption:function(c){var b=document.createTextNode(c.title);var a=document.createElement("div");var e=document.createElement("p");var d=c.getAttribute("width");var f=c.getAttribute("align");if(!d){d=c.width}if(!f){f=c.getStyle("float")}if(!f){f=c.style.styleFloat}if(f==""||!f){f="none"}e.appendChild(b);e.className=this.selector.replace(".","_");c.parentNode.insertBefore(a,c);a.appendChild(c);if(c.title!=""){a.appendChild(e)}a.className=this.selector.replace(".","_");a.className=a.className+" "+f;a.setAttribute("style","float:"+f);a.style.width=d+"px"}});document.caption=null;window.addEvent("load",function(){var a=new JCaption("img.caption");document.caption=a});
+/*
+ GNU General Public License version 2 or later; see LICENSE.txt
+*/
+var JCaption=new Class({initialize:function(a){this.selector=a;$$(a).each(function(a){this.createCaption(a)},this)},createCaption:function(a){var f=document.createTextNode(a.title),c=document.createElement("div"),d=document.createElement("p"),e=a.getAttribute("width"),b=a.getAttribute("align");if(!e)e=a.width;b||(b=a.getStyle("float"));if(!b)b=a.style.styleFloat;if(b==""||!b)b="none";d.appendChild(f);d.className=this.selector.replace(".","_");a.parentNode.insertBefore(c,a);c.appendChild(a);a.title!=
+""&&c.appendChild(d);c.className=this.selector.replace(".","_");c.className=c.className+" "+b;c.setAttribute("style","float:"+b);c.style.width=e+"px"}});

0 comments on commit 493817f

Please sign in to comment.