Two JS One Problem

davidjaymz's picture

He has: 193 posts

Joined: Jul 2001

(hmm... whenever i put in the url code it reloads the homepage. strange and annoying when you lose your well thought out typed post. win xp and FF1.5.0.3)

I'm using Expression Engine (http://pmachine.com) to run my photography portfolio website (http://photography-of-rock.com) and I'm really happy with it. Although I have come across some problems I'm hoping the people here may be able to help me with.

I'm using Lightbox JS 2 (http://www.huddletogether.com/projects/lightbox2/) to enable people to see the "big" images in my portfolio. This works excellently and seemlessly goes with EE. However because I am not using EE to display the big image the "view" count in EE's db is not being increased. So I went looking for another way to do it and came across this (http://www.smart-it-consulting.com/article.htm?node=155&page=96) and with a bit of jiggary pockery I get it to call a php page which increases the view count.

Awesome. Except it doesn't work with Lightbox JS. and I don't know why. I've not done much javascript coding and at the moment the two pieces of code I'm using have been pieced together with that little knowledge.

You can see my test page (http://galleries.photography-of-rock.com/index.php/selects/temp_image) which has both js calls on it.

This isn't my final page (I also have issues with EE calling the correct info) but if i can get the two JS to work together I can figure out the EE problems.

Click Count JS

<script language="javascript" type="text/javascript">
function trackclick(aid) {
    if(document.images){
        (new Image()).src="http://galleries.photography-of-rock.com/index.php/selects/click_count?id="+aid;
    }
    return true;
}
</script>
'

Link Code

<a href="{image_url}" title="{if caption!=""}{caption}{if:else}{filename}{/if}" id="{entry_id}" name="{entry_id}" onclick="return trackclick(this.name);" rel="lightbox[{category_id}]"><img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" title="{filename}" alt="{filename}"  /></a>
'

{ } are EE calls.

rel= is the lightbox activator while the onclick= is the click.counter.

I'm guessing the onclick event must be clashing somewhere but I'm having issues finding where. (the lightbox calls 3 seperate js files.)

Thanks in advance for any and all help

DJ

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

Have you gone to tools > Javascript console in FireFox to see if it spits anything at you in terms of an error?

davidjaymz's picture

He has: 193 posts

Joined: Jul 2001

I have, and it doesn't. Sad

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

Can you link me to the exact page you're having a problem on? and the link name?

davidjaymz's picture

He has: 193 posts

Joined: Jul 2001

http://galleries.photography-of-rock.com/index.php/selects/temp_image and all the images on the page are the "links".

Thanks for looking Cpt.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

My best guess is that LightBox is overriding the onclick funtion when it is detecting the rels and replacing stuff, I would normally check my "view rendered source" FF extension, but I can't seem to get it going. If this is the case, your best bet is to try having the lightbox execute the trackclick function, or when it is detecting the RELs add the trackclick function tot the onclick command.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
anchor.onclick = function () {myLightbox.start(this); return false;}
}
'

(in lightbox.js)

there it is, that's what's killing your trackclick.

davidjaymz's picture

He has: 193 posts

Joined: Jul 2001

Hey Cpt...

I've spent the morning trying to figure this out. I've even been looking at php count scripts and not been getting anywhere.

in the lightbox.js the return false;' stops the link going through to the new page. the lightbox effects kick in.

I tried to replace return false with return trackclick(this.name);' but that broke both items.

can an onclick event call two different things?

I've also been looking through the lightbox.js to see if there's somewhere i could slot in the click count js and I'm proving i don't know enough js.

Sorry to require hand holding on this but I'm not getting anywhere myself

davidjaymz's picture

He has: 193 posts

Joined: Jul 2001

I got it... Whoo...

Thanks for all the help...

if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
anchor.onclick = function () {myLightbox.start(this); trackclick(this.name); return false;}
}
'

easy. just needed to know where to put it.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

Good show

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.