Album: CMotion template revision

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Caspar

Album: CMotion template revision

Post by Caspar »

Alright, here it is:
  • Old CMotion template: issues
  • CMotion template: solutions (so far...)
  • Personal thoughts
Old CMotion template: issues
  • The "AJAX"-script link
    To make a humiliating story short: it's useless. It was code I had been playing with before I submitted the template. I just forgot to remove it. It has now been removed from the improved template version following below.
  • gallerystyle.css
    If you take a closer look at the default Album stylesheet, you'll find the css-code for the CMotion template at the very end. An external stylesheet named gallerystyle.css is mentioned in the comments. It comes with the original code at dynamicdrive.com, but somehow doesn't seem to have made its way into our Album module. However, when I tested the new version today, its missing didn't seem to have any impact. But: please test yourself.
  • Picture dimensions bug in Safari
    There was a bug in Safari: Upright format pictures would be displayed distorted. The javascript which calls the new image onclick didn't seem to get the new image dimensions .
  • Why use javascript in the thumbnail links at all?
    The original CMotion script provides a popup-window option for viewing the larger image. When I was working on the project I wrote the template for, I preferred to have the larger image displayed in a div instead.
    Now, using a regular link (a href...) for each thumbnail image would cause the whole page being reloaded on each click - and the cmotion row would flip back to its starting position, that is the 1st thumbnail in the row. Annoying, if you have a lot of thumbnails to watch...
    In the revised version below, I've included a little javascript called simplegallery.js I wrote for another template. In my tests, everything went fine with it. Just to be honest: it's the very first javascript function I've ever written in my life. So PLEASE, test it yourself before you use it!
CMotion template: solutions (so far...)
  • Template revision:
    In this revision, picture names and comments are deposited in the thumbnail images alt- and title-tags and are being called from there to be displayed with the big picture. That's my simple, maybe newbee-ish solution for avoiding the page-reload effect described above and still have all relevant image info being changed onclick. Issue: HTML messes up the alt-/title-texts, so I decided just not to use it.
    Note: Default title-texts, noscript-tip etc. are in German.

Code: Select all

{* CMotion gallery template *}

{* Move javascript link inside the <head> of your page template if you want. 
There are also a few parameters you should configure in the script itself such as the speed of the CMotion row, maximum width and starting position for the gallery and a tool tip attached to the cursor. *}

{* Start copy/paste here *}
{literal}
<__script__ type="text/javascript" src="modules/Album/templates/db/js/motiongallery.js">
/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
* Modified by Jscheuer1 for autowidth and optional starting positions
***********************************************/
</__script>

<__script__ src="modules/Album/templates/db/js/simplegallery.js" type="text/javascript">
<!--
/*************************************
SIMPLE GALLERY SCRIPT
by Caspar Huebinger, http://chariotweb.net
Author e-mail: mail@chariotweb.net
*************************************/
//-->
</__script>
{/literal}
{* End copy/paste *}


{if !$album} {* Keep this if you're not sure what it means. *}
<!-- Album list -->
	<ul class="albumlist">
	{foreach from=$albums item=album}
		<li class="thumb">
 			<a href="{$album->link}">
				<img src="{$album->thumbnail}" alt="{$album->name}" title="{$album->name}" {$album->autothumbnailsize} />
			</a>
			<p class="albumname"><a href="{$album->link}">{$album->name}</a><br />
			<span class="albumpicturecount">({$album->picturecount} Bilder)</span>
			</p>
		</li>
	{/foreach}
	</ul>
<!-- End Album list -->

{else}

<!-- Album name and comment --> {* If there's an Album index page, a link back is displayed here. *}
	<h5>{$album->name}</h5>
	<p>
		<span class="albumcomment">{$album->comment}<br />
			{if $returnlink}<a href="{$returnlink}" title="Zurück zur Galerie-Auswahl">Zurück zur Galerie-Auswahl</a>{/if}
		</span>
	</p>
<!-- End Album name and comment -->

<!-- Album navigation -->
	{if $pagecount>1}
	<p class="albumnav">
		<a href="{$link.page.first}" title="first page"><< </a>
		{if $link.page.previous}<a href="{$link.page.previous}" title="previous page">< </a>{/if}
		page {$pagenumber}/{$pagecount}
		{if $link.page.next}<a href="{$link.page.next}" title="next page"> ></a>{/if}
		<a href="{$link.page.last}" title="last page"> >></a>
	</p>
	{/if}
<!-- End Album navigation -->


<!-- noscript-tip for disabled javascript -->
	<noscript>
		<div id="noscript" style="position:absolute;top:2em;left:2em;padding:1em;width:15em;background:#fff;border:2px solid red;z-index:5000000;-moz-opacity:0.7;-khtml-opacity:0.7;opacity:0.7;">
			<p style="text-align:left;font-size:1.2em;color:red;">
				Für eine bequemere Galerie-Ansicht aktivieren Sie bitte Javascript in Ihrem Browser!<br />Falls dies nicht möglich ist, können Sie die Bilder dennoch vergrößert betrachten; mit dem Zurück-Button Ihres Browsers finden Sie immer wieder zurück zur Bilderliste.
			</p>
			<ul><!-- A text-only picture-list for users with javascript disabled -->
			{foreach from=$pictures item=picturesrow}
				{foreach from=$picturesrow item=onepicture}
				<li>
					<a href="{$onepicture->link}" title="{if $onepicture->name}{$onepicture->name}{else}Foto {$onepicture->number}{/if}">
						{if $onepicture->name}{$onepicture->name}{else}Foto {$onepicture->number}{/if}
					</a>
				</li>
				{if ($onepicture->number==$picturenumber and !$picture)}{assign var=picture value=$onepicture}{/if}
				{/foreach}
			{/foreach}
			</ul>
		</div>
	</noscript>
<!-- End noscript-tip -->

<!-- CMotion row with thumbnail pictures -->
{* You can move this underneath the Big Picture section, than the thumbnail row will display after the large image. *}
	<div style="text-align:center;"> {* To center the whole gallery. Remove if you don't need it. *}
		<div id="motioncontainer" style="position:relative;overflow:hidden;">
			<div id="motiongallery" style="position:absolute;left:0;top:0;white-space:nowrap;">
				<div id="trueContainer">
				{foreach from=$pictures item=picturesrow}
					{foreach from=$picturesrow item=onepicture}
						<img onclick="changePic(this.src,this.alt,this.title);return false;"  id="thumb{$onepicture->number}" src="{$onepicture->thumbnail}" alt="{if $onepicture->name}{$onepicture->name}{else}Foto {$onepicture->number}{/if}" title="{if $onepicture->comment}{$onepicture->comment|escape:'html'}{else}© {sitename}{/if}" {$onepicture->autothumbnailsize} />
      				{if ($onepicture->number==$picturenumber and !$picture)}{assign var=picture value=$onepicture}{/if}
				{/foreach}
			{/foreach}
				</div> {* End #trueContainer *}
			</div> {* End #motiongallery *}
		</div> {* End #motioncontainer *}
<!-- End CMotion row -->

<!-- Big Picture. -->
{* The alt/title-attribute uses the sitename-tag with a copyright-symbol as default. You can also use other Album tags. *}
<div class="largeview">
	<img id="mainpic" src="{$picture->picture}" alt="{if $picture->name}{$picture->name}{else}Foto {$picture->number}{/if}" title="{if $picture->comment}{$picture->comment|escape:'html'}{else}© {sitename}{/if}" />
</div>
<div class="mainpiccomment">
	<h5 id="mainpicname">{if $picture->name}{$picture->name}{else}Foto {$picture->number}{/if}</h5>
	<div id="mainpiccomment">{if $picture->comment}{$picture->comment|escape:'html'}{else}© {sitename}{/if}</div>
</div>
<!-- End Big Picture -->

</div>{* End centering div *}


{if $picturecount==0}No images in this gallery.{/if} {* Message in case there are no images to be displayed. *}


<!-- Clearing div -->
	<div style="clear:both;">
	{if $returnlink} {* Again a link back to the Album index page - if there is one. *}
		<p style="text-align: right; padding-top:2em;">
			<span class="instructiontext">
				<a href="{$returnlink}" title="Zurück zur Galerie-Auswahl">Zurück zur Galerie-Auswahl</a>
			</span>
		</p>
	{/if}
	</div>
<!-- End clearing div -->

{/if} {* Closing "if !$album" from above. *}

  • Included javascript: simplegallery.js
    I put this as an external js-file in the same directory as motiongallery.js
    EDIT: Images and their thumbs must be placed within the same directory. If you want them in different directories, you'll need to customize line 2 of the function.

Code: Select all

/* CMSMS-Users: This file's path is supposed to be modules/Album/templates/db/js/ by default */
/*
SIMPLE GALLERY SCRIPT
by Caspar Huebinger, http://chariotweb.net
Author e-mail: mail@chariotweb.net
*/

function changePic (CurrSrc, CurrAlt, CurrTitle) { // set parameters
	var BigSrc = CurrSrc.replace('thumb_','');// remove "thumb_" from img URI
	var MainPic = document.getElementById('mainpic');// get big img 
	MainPic.setAttribute('src', BigSrc);// set new URI for big img
	MainPic.setAttribute('alt', CurrAlt);// get alt-text containing the user-given name
	MainPic.setAttribute('title', CurrTitle);// get title-text containing the user-given comment
	var NewName = document.createTextNode(CurrAlt);// create new text-node for img name
	document.getElementById('mainpicname').replaceChild(NewName, document.getElementById('mainpicname').firstChild);// replace img name
	var NewComment = document.createTextNode(CurrTitle);// create new text-node for img comment
	document.getElementById('mainpiccomment').replaceChild(NewComment, document.getElementById('mainpiccomment').firstChild);// replace img comment
}
Watch it in action here: http://chariotweb.net/album-template-cmotion/ (CMSMS 1.0.8, not tested in IE, it's damn late in the evening already)

Personal thoughts

I personally think it's legal to have the cmotion script in a module like Album by default, but if you want to be sure, please check the site which provides the original code (mentioned in the ***header*** for legal use).
Hopefully, this solves some issues everyone trying/using the template might have had. I'll be off duty for the weekend and will be able to answer posts from Monday on.

Looking forward to some feedback!
Thanks,
Caspar
Last edited by Caspar on Fri Sep 28, 2007 5:25 am, edited 1 time in total.
gajones76
Forum Members
Forum Members
Posts: 12
Joined: Sun Jul 15, 2007 10:51 am

Re: Album: CMotion template revision

Post by gajones76 »

Hi Caspar,

Thanks a lot for posting this solution!

Unfortunately, whilst your example page works perfectly, I have been unable to get it to work on my site - the images still appear stretched. I have set up a new template with your code and added the javascript into the appropriate folder.

Obviously I'm doing something wrong somewhere, but I think it's beyond the scope of my technical expertise!

The strange thing is that it works fine with just portrait images:

http://iainmckell.com/index.php?page=test

but as soon as you add in landscape images, the portrait images are stretched...

http://iainmckell.com/index.php?page=test2

Well anyway, I'm completely out of ideas now, if you might have any I would really appreciate it!

cheers

Gareth :)
Caspar

Re: Album: CMotion template revision

Post by Caspar »

gajones76 wrote: The strange thing is that it works fine with just portrait images:
http://iainmckell.com/index.php?page=test
but as soon as you add in landscape images, the portrait images are stretched...
http://iainmckell.com/index.php?page=test2
Weird. Don't have any solution out of the box right now, sorry. But the image dimensions are something I wanted to add to the script anyway. The trouble is, from my knowledge this has to be done in PHP - and I'm still a beginner, so it might take another while. I'll definitely keep you posted when I got it.
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

Thankyou for CMotion that is really good!!

I feel a little embarassed to ask such a silly question, but I really cannot find the way to understand it by myself... :-\
Where is the template? How can I have access to it and modify it myself?
It doesn't seem to be accessible anyhow through the admin pages, where should I look? How can I update the template/javascript with the latest revision you made?
gajones76 wrote: I have set up a new template with your code and added the javascript into the appropriate folder.
Other people know how to do it. Don't you have a "CMotion for dummies" guide?
Caspar

Re: Album: CMotion template revision

Post by Caspar »

Hi Eleco,

1) Go to Content->Photo Albums in your admin panel.

2) Click the "Templates" tab: this is where your Album templates are stored.

3) If you DON'T see something like "cmotion image gallery", click "Add a template", copy/paste the larger piece of code from above (starting with "{* CMotion gallery template *}") into your new template, name it "cmotion image gallery" and save it.
If you already have a template named like that (which shoud be the case), backup it by copying/pasting it to a textfile and then replace the old code with the new one from above. (I use ctrl+A for marking all code and ctrl+V for pasting, but this may vary.)

4) Create a textfile on your computer: on Windows you can use the Notepad, on Mac or Linux use another plaintext editor. Copy/paste the smaller piece of code (the one with "SIMPLE GALLERY SCRIPT" at the top) into that textfile and save it on your computer by naming it "simplegallery.js". (I save files like that on my desktop to find them easily later on.)

5) Now you need an FTP connection to your CMSMS install. Once you're connected, go to "[YourCMSMSfolder/]modules/Album/templates/db/js/motiongallery.js".

6) Upload simplegallery.js from your computer. Also make sure that there is another js-file called "motiongallery.js".

7) Close FTP, go back to your admin panel and assign whatever album you loke to your "cmotion image gallery" template.

Hope I got it all...  ;)
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

Wow, your explanation sounds perfect! I'll try it and I'll return back if I'm in trouble.
Thankyou!
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

Hi Caspar, I'm back...

It isn't working. The problem must be that I've installed CMSms in a subdirectory.
I've changed in the template the paths to get the two .js, but only motiongallery.js works.

At last I saw your notice in the very first line of simplegallery.js:

Code: Select all

/* CMSMS-Users: This file's path is supposed to be modules/Album/templates/db/js/ by default */
Is there something I can do to change the path, let's say, to cmsms/modules/Album/templates/db/js/?
Caspar

Re: Album: CMotion template revision

Post by Caspar »

Eleco wrote: Is there something I can do to change the path, let's say, to cmsms/modules/Album/templates/db/js/?
Sure you can! Just change the js-path in your template also. Look for:

Code: Select all

<__script__ src="modules/Album/templates/db/js/simplegallery.js" type="text/javascript">
Change to:

Code: Select all

<__script__ src="modules/Album/templates/db/js/simplegallery.js" type="text/javascript">
I just used that particular directory because it's default for the Album module.

P.S.: Maybe just make sure, your simplegallery.js is readable (chmod 644). I've had it in the past that when I uploaded a freshly created file it was chmod 000 sometimes.
Last edited by Caspar on Thu Sep 27, 2007 4:55 am, edited 1 time in total.
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

I already did that, I changed in the template these two rows:

Code: Select all

<__script__ type="text/javascript" src="/cmsmadesimple/modules/Album/templates/db/js/motiongallery.js">

Code: Select all

<__script__ type="text/javascript" src="/cmsmadesimple/modules/Album/templates/db/js/simplegallery.js">
Motiongallery.js works only with that slash / at the beginning of the path. For simplegallery.js I tried with and without it, but it didn't work in either way...

This is the url of the page, if this can help. I may post you my username and password, if you want.

Simplegallery.js was chmod 640, changing it into 644 didn't made any difference. :'(
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

Do you think it could be due to the album images being in a subfolder of the default folder, instead of directly into the immages folder?
Caspar

Re: Album: CMotion template revision

Post by Caspar »

Eleco wrote: Do you think it could be due to the album images being in a subfolder of the default folder, instead of directly into the immages folder?
That's it. Didn't I mention that above? My bad. What simplegallery.js does is removing the "thumb_" from a thumbnail image's file name, so you get the original image's file name. Of course, that makes sense only if both, images and thumbs, are stored in the same directory.
The easiest would be if you changed directories. There was a possible modification to the script also, but let it be easy if we can...  ;)
Last edited by Caspar on Fri Sep 28, 2007 5:29 am, edited 1 time in total.
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

Hmmm, but this is not the case. Actually both images and thumbs ARE in the same directory, they are in a subfolder of the default uploads/images directory. I think the Album engine puts them always together.

Uff! This is soooo strange!
Did the album work when you went to see it?
Caspar

Re: Album: CMotion template revision

Post by Caspar »

I think it's a path problem.
As I see, your root folder for your CMSMS install is

Code: Select all

www.yourdomain.xy/cmsmadesimple
So the source path for your js-files should go like:

Code: Select all

src="modules/Album/templates/db/js/simplegallery.js"
Maybe I'm blind, but I don't get why you include your root directory in the path like:

Code: Select all

src="/cmsmadesimple/modules/Album/templates/db/js/motiongallery.js"
.
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

Yeppy! Found!

When I copied/pasted the simplegallery.js from your example to my own file, something went wrong and the longer lines were split in two!! (maybe it happened because I copied the code from your post to Notepad and then from there to Dreamweaver)

This is great! Thankyou of your kindness!
What can I do for you? Would an Italian translation of the German texts in the template be usefull? Let me know!

Cheers
Eleco

P.S. Maybe all this part of the discussion should be stripped away so to leave your post simple and clean. How can this be done? Should I click the "Report to a moderator" link?
User avatar
Eleco
Forum Members
Forum Members
Posts: 24
Joined: Tue Sep 18, 2007 1:16 pm

Re: Album: CMotion template revision

Post by Eleco »

cross posting...
Anyway the two paths do point to the same file, you are right.
Last edited by Eleco on Fri Sep 28, 2007 8:17 am, edited 1 time in total.
Post Reply

Return to “Tips and Tricks”