I'm trying to make ddblock to show different starting slide each time someone come to our website, but still display the slideshow in the same display order every time. The slideshow should also run the slides by the display order.

The random sort order seems to do it, however even though it starts with a different slide each time someone visit our website, it actually change the display order of the slide show randomly.

At the moment what seems to work for me is to put this code in the custom option:

{"random":1}

This gives me a different starting slide, while have the same display order for the slideshow. However, when the slide transits to the next slide, it actually jump randomly from slide to slide. (eg. Slide2 --> slide6 --> Slide 1 … ) . What should I do now to make the slideshow run the slides by the display order (eg. Slide 5 --> Slide 6 --> Slide 7 … )

Hope Someone can help out.

Comments

ppblaauw’s picture

Status: Active » Postponed (maintainer needs more info)

To implement functionality you require, there would be two possible options:

  1. The slide the slideshow started with, needs to be stored.
    This could be done in a cookie on the computer of the user.
    When the user visits again you read the start slide from last time (from the cookie) and start the slideshow with the next slide (slide + 1).
    If (slide + 1) is bigger than the amount of slides, you would need to start the slideshow with slide 1
  2. Another way would be to start with a random start slide, but this could be the same as a previous start slide.

Hope this helps you further, please let me know.

johnshih’s picture

Hi ppblaauw,

OPTION1:

I'm not quite sure how to set up the cookie for drupal.
I never wrote my own cookie before.

This is my attempt. Am I close?


function saveslide($slide) {
  setcookie('starting_slide', $slide, time + 3600 * 24 * 180);
}

function readslide() {
 if ($_COOKIE['starting_slide']==7)
 {
 $slide=0;
 return $slide;
 }
 elseif ($_COOKIE['starting_slide']<7)
 {
   for ( $slide=$_COOKIE['starting_slide']; $slide<7; $slide++ )  
   { 
    return $slide;
   }
 }
 else  $slide=0;

Also, where should I place the cookie? should I put it in the "page.tpl.php" (theme folder)?

OPTION 2:

How to I start with a random start slide?

johnshih’s picture

Hi ppblaauw,

I didn't really know how change the start slideshow using those 2 options you have suggested.

However, I hard code in jquery.cycle.all.min and got it to work.
And here is the code that I've changed.

/******variable numRand will be a random number between 0 and 7********/
var adjustedHigh = (parseFloat(7) - parseFloat(0)) + 1;var numRand = Math.floor(Math.random()*adjustedHigh) + parseFloat(0);
/****************************************************************/

$.fn.cycle.defaults={fx:"fade",timeout:4000,timeoutFn:null,continuous:0,speed:1000,speedIn:null,speedOut:null,next:null,prev:null,prevNextClick:null,pager:null,pagerClick:null,pagerEvent:"click",pagerAnchorBuilder:null,before:null,after:null,end:null,easing:null,easeIn:null,easeOut:null,shuffle:null,animIn:null,animOut:null,cssBefore:null,cssAfter:null,fxFn:null,height:"auto",

/*************startingSlide:0 --> numRand *******************/
startingSlide:numRand,
/********************************************************/

sync:1,random:0,fit:0,containerResize:1,pause:0,pauseOnPagerHover:0,autostop:0,autostopCount:0,delay:0,slideExpr:null,cleartype:!$.support.opacity,nowrap:0,fastOnEvent:0,randomizeEffects:1,rev:0};})(jQuery);

ppblaauw’s picture

Status: Postponed (maintainer needs more info) » Fixed

thanks for the inspiration

Will implement the following in the dev version of ddblock.

First part is to start a slide from the URL.
The second part is to be able to start also random from the custom jquery field.

      //start with slidenr from URL, e.g. example.com/node/1?slidenum=3 (start from 0)
      function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++) {
          hash = hashes[i].split('=');
          vars.push(hash[0]);
          vars[hash[0]] = hash[1];
        }
        return vars;
      }  

      var startThisSlide = getUrlVars()["slidenum"];
      if (startThisSlide > ddblockSettings.nrOfItems) {
        options.startingSlide = 0;
      }
      if (startThisSlide > 0 || startThisSlide == 'random'){
        options.startingSlide = startThisSlide;
      }

      // start with random slide, used in the custom jquery field: e.g. {"startingSlide":"random"}
      function randomFromTo(from, to){
        return Math.floor(Math.random() * (to - from + 1) + from);
      }

      if (options.startingSlide == 'random') {
        options.startingSlide = randomFromTo(0, ddblockSettings.nrOfItems);  
      }

will create a patch later
the code can be placed before the line: // simple block
in the ddblock.js file of the module

johnshih’s picture

Hi ppblaauw,

This did not work for me. I'm not sure why.

I've deleted my code and added in your new code in ddblock.js
Then I've put {"startingSlide":"random"} in the custom jquery field.
However nothing happen. It always start the slide with the first slide.

ppblaauw’s picture

Status: Fixed » Needs review

You would need to use the dev version of the ddblock module, the rc6 version does not set the nrOfItems.

johnshih’s picture

I upgrade my module to 6..x-1.x-dev version and put the new code in. Everything works fine.

However, ddblock stopped working after I put {"startingSlide":"random"} in the custom jquery field.

ppblaauw’s picture

Do you have a link to your site?
Do you see a javascript error?

johnshih’s picture

Hi ppblaauw,

start with slidenr from URL is working.

I do have 1 javascript error after I put {"startingSlide":"random"} in the custom jquery field:

**************************************************************
FIREFOX ERROR
**************************************************************
uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost/sites/all/modules/jquery_update/replace/jquery.min.js?w :: anonymous :: line 22" data: no]

**************************************************************
IE ERROR
**************************************************************
Message: Unterminated string constant
Line: 774
Char: 38
Code: 0
URI: http://localhost/

Message: 'style' is null or not an object
Line: 10
Char: 3164
Code: 0
URI: http://localhost/sites/all/modules/ddblock/js/jquery.cycle.all.min.js?w

ppblaauw’s picture

Do you have a WYSIWYG editor for the custom jQuery field which adds other tags or code?
Do you have a link to your site?

johnshih’s picture

Hi ppblaauw,

No additional tags or code was in the custom jquery field.

When I put this it works : {"startingSlide":2}
but this doesn't work : {"startingSlide":"random"}

Edit: Sorry, start with slider from URL does not work.

http://localhost/?slidenum=2 (This works)
http://localhost/?slidenum=random (This doesn't work)

johnshih’s picture

Hi ppblaauw,

I still couldn't figure out how to get your code working for me.
So I place below code (bold) back into jquery.cycle.all.min.js and it works fine.



...opts.animIn={opacity:1};opts.animOut={opacity:0};opts.cssBefore={top:0,left:0};}};

/*variable numRand will be a random number between 0 and 7*/
var randomSlide = Math.floor(Math.random() * 7);

$.fn.cycle.ver=function(){return ver;};$.fn.cycle.defaults={fx:"fade",timeout:4000,timeoutFn:null,continuous:0,speed:1000,speedIn:null,speedOut:null,next:null,prev:null,onPrevNextEvent:null,prevNextEvent:"click.cycle",pager:null,onPagerEvent:null,pagerEvent:"click.cycle",allowPagerClickBubble:false,pagerAnchorBuilder:null,before:null,after:null,end:null,easing:null,easeIn:null,easeOut:null,shuffle:null,animIn:null,animOut:null,cssBefore:null,cssAfter:null,fxFn:null,height:"auto",

startingSlide:randomSlide

sync:1,random:0,fit:0,containerResize:1,slideResize:1,pause:0,pauseOnPagerHover:0,autostop:0,autostopCount:0,delay:0,slideExpr:null,cleartype:!$.support.opacity,cleartypeNoBg:false,nowrap:0,fastOnEvent:0,randomizeEffects:1,rev:0,manualTrump:true,requeueOnImageNotLoaded:true,requeueTimeout:250,activePagerClass:"activeSlide",updateActivePagerLink:null,backwards:false};})(jQuery);

ppblaauw’s picture

Status: Needs review » Fixed

Set status to fixed.
Working as designed on my testserver.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.