PDA

View Full Version : adding on click event



noobie123
10-08-2014, 03:02 PM
1) Script Title: Continuous Reel Slideshow

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex14/reelslideshow.htm

3) Describe problem: I want to add an on click event to the urls

I want to add an on click event to track which banners are clicked the most is that possible? Before I was using:



<a onclick="return clicktrack( 'tab',<?php echo $value2['id'] ?>,'' );" href="<?php echo $value2['url'] ?>"<?php if( $value2['newwin']==1 ) { ?> target="_blank"<?php } ?>>


but now I'm just using:



imagearray: [<?php shuffle($tabblock);
foreach( $tabblock as $key=>$value2 ) { ?>
<?php
echo '["/images/dynamic/'.$value2['image'].'", "'.$value2['url'].'"],';
?> <?php } ?>],

noobie123
10-09-2014, 11:39 AM
I changed line 137 in the reelslideshow.js file to:


var layerHTML=(imgref[1])? '<a onclick="return clicktrack( \'tab\','+imgref[3]+',\'\' );" href="'+imgref[1]+'" target="'+imgref[2]+'">' : '' //hyperlink slide?

Then added this to the code in the php file:


imagearray: [
<?php shuffle($tabblock); foreach( $tabblock as $key=>$value2 ) { ?>
<?php echo '["/images/dynamic/'.$value2['image'].'", "'.$value2['url'].'"'; if( $value2['newwin']==1 ) { echo ', "_blank",'; } else { echo ', "_self",'; } echo '"'.$value2['id'].'"]'; if( $key<count( $tabblock )-1 ) { echo ","; } ?>
<?php } ?>
],


I also removed the jquery.touchSwipe.min.js file as that was stopping the links from working in everything but Chrome

vwphillips
10-09-2014, 01:09 PM
or

modify function


function reelslideshow(options){
var $=jQuery
this.setting={displaymode:{type:'auto', pause:2000, cycles:2, pauseonmouseover:true}, orientation:'h', persist:true, slideduration:500} //default settings
reelslideshow[options.wrapperid]=this;
this.cnt=[];
jQuery.extend(this.setting, options) //merge default settings with options
var curslide=(this.setting.persist)? reelslideshow.routines.getCookie("slider-"+this.setting.wrapperid) : 0
this.curslide=(curslide==null || curslide>this.setting.imagearray.length-1)? 0 : parseInt(curslide) //make sure curslide index is within bounds
this.curstep=0
this.zIndex=1
this.animation_isrunning=false //variable to indicate whether an image is currently being slided in
this.posprop=(this.setting.orientation=="h")? "left" : "top"
options=null
var slideshow=this, setting=this.setting, preloadimages=[], slidesHTML=''
for (var i=0; i<setting.imagearray.length; i++){ //preload images
preloadimages[i]=new Image()
preloadimages[i].src=setting.imagearray[i][0];
this.cnt[i]=0;
slidesHTML+=reelslideshow.routines.getSlideHTML(setting.imagearray[i], setting.dimensions[0]+'px', setting.dimensions[1]+'px', this.posprop,this.setting.wrapperid,i)+'\n'
}
jQuery(function($){ //on document.ready
slideshow.init($, slidesHTML)
})
$(window).bind('unload', function(){ //on window onload
if (slideshow.setting.persist) //remember last shown slide's index?
reelslideshow.routines.setCookie("slider-"+setting.wrapperid, slideshow.curslide)
})
}



modify function


getSlideHTML:function(imgref, w, h, posprop,id,i){
var posstr=posprop+":"+((posprop=="left")? w : h)
var layerHTML=(imgref[1])? '<a href="'+imgref[1]+'" target="'+imgref[2]+'">' : '' //hyperlink slide?
layerHTML+='<img src="'+imgref[0]+'" style="border-width:0;" dataid='+id+' datanu='+i+' onclick="Count(this);" />'
layerHTML+=(imgref[1])? '</a>' : ''
return '<div class="slide" style="position:absolute;'+posstr+';width:'+w+';height:'+h+';text-align:center;">'
+'<div style="width:'+w+';height:'+h+';display:table-cell;vertical-align:middle;">'
+layerHTML
+'</div></div>' //return HTML for this layer
},



new function


function Count(o,i){
var oop=reelslideshow[o.dataid],n=o.datanu,op=document.getElementById(o.dataid+'op');
if (oop){
oop.cnt[n]++;
op?op.value=oop.cnt:null;
}
}



html


<div id="myreel"></div>

<div class="paginate">
≤ <a href="javascript:firstreel.navigate('back')" style="margin-right:200px;">back</a> <a href="javascript:firstreel.navigate('forth')">forth</a> ≥
</div>

<input id="myreelop" />