help with adding YAHOO.widget.Tooltip

hamba

Joined: 2005-06-25
Posts: 54
Posted: Sat, 2006-12-30 12:54

Hi

I'm nearly done with my custom theme and would like to add this code from the ItemEditCaptions.tpl file to show the resized image in the thumbnail view when you hover the mouse over it.

<script type="text/javascript">
  //<![CDATA[
  {foreach from=$form.children item=child}
  {if isset($child.resize)}
  {* force and alt/longdesc parameter here so that we avoid issues with single quotes in the title/description *}
  new YAHOO.widget.Tooltip("gTooltip", {ldelim}
      context: "thumb_{$child.id}", text: '{g->image item=$child image=$child.resize class="giThumbnail" maxSize=640 alt="" longdesc="" }',
      showDelay: 250 {rdelim});
  {elseif isset($child.thumbnail)}
  new YAHOO.widget.Tooltip("gTooltip", {ldelim}
      context: "thumb_{$child.id}", text: '{g->image item=$child image=$child.thumbnail class="giThumbnail" alt="" longdesc=""}',
      showDelay: 250 {rdelim});
  {/if}
  {/foreach}
  //]]>
</script>

What I want to do is to display the resized image when you hover over a thumbnail the same way its done in ItemEditCaptions.tpl

There are two problems that I came across,
One: how can I add these files
$template->javascript('lib/yui/yahoo-min.js');
$template->javascript('lib/yui/dom-min.js');
$template->javascript('lib/yui/event-min.js');
$template->javascript('lib/yui/container-min.js');
so that they only get loaded when the album.tpl is called?

Two: Just for testing I added these file into the modules/search/Preloads.inc which is called from my theme.inc file. (This does not really work because I have the search in my header and will get called twice when it is called by another template.) But for testing it worked the only thing was that it loaded the thumbnails rather then the resized images.

Or is there an easier way to do this with css?

Cheers
hamba

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2006-12-31 00:52

@adding those files:
you can hardcode it in your album.tpl or you can add it in function showAlbumPage() in your theme.inc.

@Preloads.inc:
preloads usually get called from GalleryTheme.inc.
anyhow, what's the problem? that it gets called twice?

 
hamba

Joined: 2005-06-25
Posts: 54
Posted: Sun, 2006-12-31 03:33

Thanks I have added the files into showAlbumPage() function.

Now for the second problem. This is the code I'm using to show the thumbnails taken from the siriux theme.

      {foreach from=$theme.children item=child}
        {if !$child.canContainChildren}
          {if $firstItem}
            <div class="gallery-items">
            <div class="gallery-items-all">
            {assign var="firstItem" value=false}
          {/if}
              <div class="gallery-item-thumb">
                {if isset($child.thumbnail)}{strip}
                <a id="thumb_{$child.id}" href="{g->url arg1="view=core.ShowItem" arg2="itemId=`$child.id`"}">
                  {g->image item=$child image=$child.thumbnail class="giThumbnail"}</a>
                {/strip}{/if}
                {if !isset($child.thumbnail)}
                <a href="{g->url arg1="view=core.ShowItem" arg2="itemId=`$child.id`"}">
                  {g->text text="no thumbnail"}</a>
                {/if}
              {g->block type="core.ItemLinks" item=$child links=$child.itemLinks}
              </div>
        {/if}
      {/foreach}
      <script type="text/javascript">
        //<![CDATA[
        {foreach from=$theme.children item=child}
        {if isset($child.resize)}
        {* force and alt/longdesc parameter here so that we avoid issues with single quotes in the title/description *}
        new YAHOO.widget.Tooltip("gTooltip", {ldelim}
            context: "thumb_{$child.id}", text: '{g->image item=$child image=$child.resize class="giThumbnail" maxSize=640 alt="" longdesc="" }',
            showDelay: 250 {rdelim});
        {elseif isset($child.thumbnail)}
        new YAHOO.widget.Tooltip("gTooltip", {ldelim}
            context: "thumb_{$child.id}", text: '{g->image item=$child image=$child.thumbnail class="giThumbnail" alt="" longdesc=""}',
            showDelay: 250 {rdelim});
        {/if}
        {/foreach}
        //]]>
      </script>

This does work but it shows the thumbnail instead of the resized image.

 
willfei

Joined: 2003-05-03
Posts: 33
Posted: Thu, 2007-02-22 18:40
Quote:
This does work but it shows the thumbnail instead of the resized image.

Did you solve the problem ? I have this problem too. I want to show the resized image in the ablum page.

 
lvthunder

Joined: 2003-09-12
Posts: 804
Posted: Fri, 2007-02-23 02:48

willfei, why do you want to show the resized image on the album page. Are you using the thumbnails for something else? If not just increase the size of the thumbnails.

 
hamba

Joined: 2005-06-25
Posts: 54
Posted: Fri, 2007-02-23 10:02

Hi

I never figured out why it is loading the thumbnails. The reason why I wanted this was to show the resized images when the mouse hovers over the thumbnails, but I scraped the idea because it preloaded all the images and my server is just not strong enough to handle that kind of load.

I'll look into it one day when I have a more powerful server and more bandwidth.

 
willfei

Joined: 2003-05-03
Posts: 33
Posted: Sat, 2007-02-24 06:02
lvthunder wrote:
willfei, why do you want to show the resized image on the album page. Are you using the thumbnails for something else? If not just increase the size of the thumbnails.

I am thinking that if the resized photo would be shown as a on mouse effect in ablum page, it would be very convenient for users. Would you mind to help me ?

 
lvthunder

Joined: 2003-09-12
Posts: 804
Posted: Sat, 2007-02-24 16:18
willfei wrote:
I am thinking that if the resized photo would be shown as a on mouse effect in ablum page, it would be very convenient for users. Would you mind to help me ?

OK Here goes.

Edit the "theme.inc" file for the Gallery2 theme(s) you are using. You'll need to ADD these lines of text to the file, after the line that says $theme['columnWidthPct'] = floor(100 / $params['columns']);:

/* Add resizedId to child values, required for Lightbox JS */
if ( $theme['children'] ){
    foreach ( $theme['children'] as $key => $value ){
        if ( $value['id'] ){
            list($ret,$resizedIds) =                                             GalleryCoreApi::fetchResizesByItemIds(array($value['id']));
            if ($ret)
               return $ret;
        }
        $theme['children'][$key]['resizedId'] = $value['id'];
        if ( $resizedIds ){
            /* Find the best resized option
             * 
             * Use width/height max=800; */
            $lboxMaxEdge = 800;
            $resizedEdge = NULL;
            $resizedId = NULL;
            foreach ( $resizedIds[$value['id']] as $resize ){
		$width = $resize->getWidth();
                $height = $resize->getHeight();
                $edge = ( $width > $height )? $width : $height;
                if ( $edge <= $lboxMaxEdge ){
                    if ( !isset($resizedEdge) ){
                        $resizedId = $resize->getId();
                        $resizedEdge = $edge;
                    } else if ( $edge > $resizedEdge ){ 
                        $resizedId = $resize->getId();
                        $resizedEdge = $edge;
                    } 
                }
            }
            $theme['children'][$key]['resizedId'] = $resizedId;
        }
    }
}
/* end add resizedId to child values, required for Lightbox JS */

Then whenever you need the URL to the resized image use.

{g->url arg1="view=core.DownloadItem" arg2="itemId=`$child.resizedId`"}

Let me know if you have any questions. This code was borrowed from the Lightbox implementation since it needs resized links on the album page too.