We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26931
    • 2,314 Posts
    Hi there,

    following the wiki instructions and reading some threads in the forum, i got my "Picture and thumbnails on same page"-layout working with jquery fade-in effects, the problem is now, that i need a next/previous-link in addition to the thumbnails.
    <a href="[+maxigallery.previous_pic_url+]">[+maxigallery.strings.previous+]</a>
    obviously won’t help, in this case only a javascript will help, right? does anybody know how to accomplish this? the snippet-call is:
    [!MaxiGallery? &pictureTpl=`mgPicture` &display=`pictureview` &max_pic_size=`400x300` &max_thumb_size=`50`!]
    [!MaxiGallery? &galleryPictureTpl=`mgGalleryPicture` &js=`mgJs` &manage_target=`56`!]

    my mgGalleryPicture-chunk is
    <div class="hoverthumb">
    <a href="javascript:showPic ('[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]',
    '[+maxigallery.picture.title:htmlent+]','[+maxigallery.picture.descr:htmlent+]',
    [+maxigallery.picture_width_normal+],[+maxigallery.picture_height_normal+])">
                   <img src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+] " class="thumbnail" 
    title="[+maxigallery.picture.title:htmlent+]"
    alt="[+maxigallery.picture.title:htmlent+]" />
           </a>
    </div>
    my mgPicture-chunk:
    <div class="picturecontainer">
    <img id="maxImage" src="[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]" 
    alt="[+maxigallery.picture.title:htmlent+]" />
    </div>
    and my js are: for no-conflict mode:
      <script type="text/javascript">
      <!-- 
      var jq = jQuery.noConflict(); 
      -->
      </script>
    and the mgJs-chunk:
    <script type="text/javascript">
    //<![CDATA[
    jq(document).ready(function(){
    	jq(".hoverthumb").hover(function(){
    	jq(this).fadeTo("fast", 0.6); // This sets the opacity to 60% on hover
    	},function(){
    	jq(this).fadeTo("fast", 1.0); // This sets the opacity back to 100% on mouseout
    });
    });
    function showPic(url,title,descr,width,height) {
      jq("#maxImage").fadeOut("slow", function(){
          var image = new Image();
          jq(image).load(function() {
            jq(this).hide();
    		// with the holding div #loader, apply:
          jq('#picturecontainer')
            // remove the loading class (so no background spinner), 
            .removeClass('loading')
            // then insert our image
            .append(this);
            jq("#maxImage").attr({
              src: url,
              width: width,
              height: height
            });
            jq("#maxImage").fadeIn("fast");
            jq("#maxTitle").html(title);
            jq("#maxDescr").html(descr);
    		jq('#picturecontainer').addClass('loading')
          });
          jq(image).attr({src: url, width: width, height: height});
      });
    }
    //]]>
    </script>

    i was searching the forum, googeling and experimenting for quite a while without success, so any help/suggestions is very welcome smiley
    thank you, cheers, j
      • 20413
      • 2,877 Posts
      Did you try:
      &pics_per_page=`3`

      Dunno if that works to your approach though.
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 26931
        • 2,314 Posts
        Hi mrhaw!

        thanx for the quick reply, the thing is i need all the thumbnails for that gallery + the prev/next-links

        j
          • 7923
          • 4,213 Posts
          You need to write a js code that collects all thumbnails to an array and then do js functions for prev and next links. In that function you check what is currently displayed in the picture container, find the same from the array that holds all thumbnails and then call the image change function with the information of the next/prev image.


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 26931
            • 2,314 Posts
            hi doze,

            thanx for the reply...i thought it would be something like this, unfortunately i know next to nothing about js, so maybe someone, who already got a working js, would like to share, or point me to the right direction, or a thread in a jquery-forum...

            best regard, j
              • 26931
              • 2,314 Posts
              does anybody know how to change the above mentioned mgJs-chunk in order to update a link to the "_big"-image as well, i try to implement a lightbox function to the maximage.

              i get the link working to the "_big"-image, but obviously the url to the big-image won’t change when the maximage changes. here’s the mgPicture-chunk:
              <div id="picturecontainer" class="loading">
              <a id="bigimage" href="[(base_url)][+maxigallery.path_to_gal+]big_[+maxigallery.picture.filename+]" rel="lightbox">
              <img id="maxImage" src="[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]" 
              alt="[+maxigallery.picture.title:htmlent+]" />
              </a>
              </div>

              thank you & regards, j
                • 7923
                • 4,213 Posts
                You would need to change it so, that instead of sending the picture url to the showPic() js function, you would send gallery id and picture filename. Then in the showPic() js function you would build the paths yourself, eg:

                <div class="hoverthumb">
                <a href="javascript:showPic ('[+maxigallery.picture.gal_id+]','[+maxigallery.picture.filename+]',
                '[+maxigallery.picture.title:htmlent+]','[+maxigallery.picture.descr:htmlent+]',
                [+maxigallery.picture_width_normal+],[+maxigallery.picture_height_normal+])">
                               <img src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+] " class="thumbnail" 
                title="[+maxigallery.picture.title:htmlent+]"
                alt="[+maxigallery.picture.title:htmlent+]" />
                       </a>
                </div>
                


                Then to get big image to open in lightbox, you need to make a link to it from the normal image with rel="ligthbox" attribute, eg:

                You would change the picturecontainer to look like this:
                <div class="picturecontainer">
                <a href="[(base_url)][+maxigallery.path_to_gal+]big_[+maxigallery.picture.filename+]" rel="lightbox" id="bigLink"><img id="maxImage" src="[(base_url)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]" 
                alt="[+maxigallery.picture.title:htmlent+]" /></a>
                </div>
                


                Then change your js function to something like this

                function showPic(gal_id,filename,title,descr,width,height) {
                  jq("#maxImage").fadeOut("slow", function(){
                      var image = new Image();
                      var normalImageUrl = '/assets/galleries/'+gal_id+'/'+filename;
                      var bigImageUrl = '/assets/galleries/'+gal_id+'/big_'+filename;
                      jq(image).load(function() {
                        jq(this).hide();
                		// with the holding div #loader, apply:
                      jq('#picturecontainer')
                        // remove the loading class (so no background spinner), 
                        .removeClass('loading')
                        // then insert our image
                        .append(this);
                        jq("#maxImage").attr({
                          src: normalImageUrl,
                          width: width,
                          height: height
                        });
                        //change url to big image
                        jq("#bigLink").attr({
                          href: bigImageUrl
                        });
                        jq("#maxImage").fadeIn("fast");
                        jq("#maxTitle").html(title);
                        jq("#maxDescr").html(descr);
                		jq('#picturecontainer').addClass('loading')
                      });
                      jq(image).attr({src: normalImageUrl, width: width, height: height});
                  });
                }
                


                But I don’t know why you are setting the picture title and description to #maxTitle and #maxDescr elements, because you don’t have such elements in your picturecontainer.. Also didn’t  test any of this code, but it should work generally like that, might have typos etc..

                EDIT: And ofcourse you need lightbox scripts and proper js libs included to your site head. (Thickbox maybe, because you are using jQuery)


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                  • 26931
                  • 2,314 Posts
                  laugh grin WOW thank you doze!

                  i’m working on it, that’s great! right now maxImage fades out, but the new image is not inserted...but i’ll get there smiley

                  thank you so much!

                  regards, j

                  *edit: It’s working!
                    • 26931
                    • 2,314 Posts
                    just a quick update...

                    since the original post was about the prev/next-links for this setup, and the content of the post changed to a solution to get a lightbox working to for the BigImage, here’s an update for the prev/next-link (assuming you’ve got a setup similar to the first post):

                    the prev/next-link:
                    <a href="javascript:prevPic();">Prev pic</a>  || <a href="javascript:nextPic();">Next pic</a>


                    and the additional javascript:
                    <script type="text/javascript">
                    function nextPic() {
                      // collect thumbnail links
                      var thumbLinks = jq('.thumbnail').parent();
                      // get url parts from current image
                      var currentUrlParts = jq('#maxImage').attr('src').split("/");
                      // get current filename
                      var filename = currentUrlParts[currentUrlParts.length-1];
                      // variable to store the "found current thumbnail" flag
                      var found = false;
                      // go through thumbnails
                      for (i=0; i < thumbLinks.length; i++) {
                        var href = thumbLinks[i].href;
                        // if current thumbnail has been found, we are processing the next thumbnail, execute the showPic
                        if (found) {
                          jq(thumbLinks[i]).parent().addClass('aktiv');
                          // collect only the showPic parameters from href contents
                          var strip = href.substring(href.indexOf("'"), href.length-1);
                          // remove single quotes from the parameters
                          strip = strip.replace(/\'/g,"");
                          // fix encoded spaces
                          strip = strip.replace(/\%20/g," ");
                          // split the params to an array
                          var params = strip.split(',');
                          // call the showPic function
                          showPic(params[0],params[1],params[2],params[3],params[4],params[5]);
                          return;
                        } else {
                          // if this is the current thumbnail, raise the found flag
                          if(href.indexOf(filename) >= 0) {
                          	found = true;
                            // if we are not in last thumbnail
                            if (i+1 < thumbLinks.length) {
                              jq(thumbLinks[i]).parent().removeClass('aktiv');
                            }
                          } 
                        }
                      }
                    }
                    function prevPic() {
                      // collect thumbnail links
                      var thumbLinks = jq('.thumbnail').parent();
                      // get url parts from current image
                      var currentUrlParts = jq('#maxImage').attr('src').split("/");
                      // get current filename
                      var filename = currentUrlParts[currentUrlParts.length-1];
                      // variable to store the "found current thumbnail" flag
                      var found = false;
                      // variable to store previous href
                      var prevHref = "";
                      // go through thumbnails
                      for (i=0; i < thumbLinks.length; i++) {
                        var href = thumbLinks[i].href;
                        // if this is the current thumbnail, change picture to previous
                        if(href.indexOf(filename) >= 0) {
                          if (i==0) {
                            return; //we are in first picture
                          }
                          jq(thumbLinks[i]).parent().removeClass('aktiv');
                          jq(thumbLinks[i-1]).parent().addClass('aktiv');
                        	// collect only the showPic parameters from href contents
                          var strip = prevHref.substring(prevHref.indexOf("'"), prevHref.length-1);
                          // remove single quotes from the parameters
                          strip = strip.replace(/\'/g,"");
                          // fix encoded spaces
                          strip = strip.replace(/\%20/g," ");
                          // split the params to an array
                          var params = strip.split(',');
                          // call the showPic function
                          showPic(params[0],params[1],params[2],params[3],params[4],params[5]);
                          return;
                        } else {
                          // else set this href to be the previous href
                          var prevHref = href;
                        }
                      }
                    } 
                    </script>


                    "aktiv" is in this case the css-class name for the active state

                    this was only possible due to the awesome help of doze! thanks!
                      • 17573
                      • 10 Posts
                      Quote from: sharkbait at Jul 13, 2009, 04:27 AM

                      just a quick update...

                      since the original post was about the prev/next-links for this setup, and the content of the post changed to a solution to get a lightbox working to for the BigImage, here’s an update for the prev/next-link (assuming you’ve got a setup similar to the first post):

                      the prev/next-link:
                      <a href="javascript:prevPic();">Prev pic</a>  || <a href="javascript:nextPic();">Next pic</a>


                      and the additional javascript:
                      <script type="text/javascript">
                      function nextPic() {
                        // collect thumbnail links
                        var thumbLinks = jq('.thumbnail').parent();
                        // get url parts from current image
                        var currentUrlParts = jq('#maxImage').attr('src').split("/");
                        // get current filename
                        var filename = currentUrlParts[currentUrlParts.length-1];
                        // variable to store the "found current thumbnail" flag
                        var found = false;
                        // go through thumbnails
                        for (i=0; i < thumbLinks.length; i++) {
                          var href = thumbLinks[i].href;
                          // if current thumbnail has been found, we are processing the next thumbnail, execute the showPic
                          if (found) {
                            jq(thumbLinks[i]).parent().addClass('aktiv');
                            // collect only the showPic parameters from href contents
                            var strip = href.substring(href.indexOf("'"), href.length-1);
                            // remove single quotes from the parameters
                            strip = strip.replace(/\'/g,"");
                            // fix encoded spaces
                            strip = strip.replace(/\%20/g," ");
                            // split the params to an array
                            var params = strip.split(',');
                            // call the showPic function
                            showPic(params[0],params[1],params[2],params[3],params[4],params[5]);
                            return;
                          } else {
                            // if this is the current thumbnail, raise the found flag
                            if(href.indexOf(filename) >= 0) {
                            	found = true;
                              // if we are not in last thumbnail
                              if (i+1 < thumbLinks.length) {
                                jq(thumbLinks[i]).parent().removeClass('aktiv');
                              }
                            } 
                          }
                        }
                      }
                      function prevPic() {
                        // collect thumbnail links
                        var thumbLinks = jq('.thumbnail').parent();
                        // get url parts from current image
                        var currentUrlParts = jq('#maxImage').attr('src').split("/");
                        // get current filename
                        var filename = currentUrlParts[currentUrlParts.length-1];
                        // variable to store the "found current thumbnail" flag
                        var found = false;
                        // variable to store previous href
                        var prevHref = "";
                        // go through thumbnails
                        for (i=0; i < thumbLinks.length; i++) {
                          var href = thumbLinks[i].href;
                          // if this is the current thumbnail, change picture to previous
                          if(href.indexOf(filename) >= 0) {
                            if (i==0) {
                              return; //we are in first picture
                            }
                            jq(thumbLinks[i]).parent().removeClass('aktiv');
                            jq(thumbLinks[i-1]).parent().addClass('aktiv');
                          	// collect only the showPic parameters from href contents
                            var strip = prevHref.substring(prevHref.indexOf("'"), prevHref.length-1);
                            // remove single quotes from the parameters
                            strip = strip.replace(/\'/g,"");
                            // fix encoded spaces
                            strip = strip.replace(/\%20/g," ");
                            // split the params to an array
                            var params = strip.split(',');
                            // call the showPic function
                            showPic(params[0],params[1],params[2],params[3],params[4],params[5]);
                            return;
                          } else {
                            // else set this href to be the previous href
                            var prevHref = href;
                          }
                        }
                      } 
                      </script>


                      "aktiv" is in this case the css-class name for the active state

                      this was only possible due to the awesome help of doze! thanks!

                      I have tried this solution but it doesn’t work for me. Where should this additional javascript be inserted?