Topic: How to configure Image click to open url in a part of the page?

Hi everyone!
I have a complicated (for me, LOL) issue to solve.
The website I'm working with uses a code to dynamically load the rest of the pages into the index.php

<script>
$('.link').click(function(){
        callDinamicPage('mainContent', $(this).attr('data-toggle'), 'page', '');
    });
</script>

If I use the imageClickMode="OPEN_URL" in the config options, the gallery opens the link in a new page or over the index depending on the target I set.

Is there any way or place where I can insert the dynamic script to make the linked pages open as the rest?

Thanks all for any help  you can provide!

Re: How to configure Image click to open url in a part of the page?

I'n not really sure exactly what it is you are looking to do.
Perhaps you could provide a link to your website and explain further what you are looking to do (and what you would like to happen).

In the meantime, from your topic subject ("How to configure Image click to open url in a part of the page?"), it sounds like you might want the content of the linkURL to appear on your gallery's web page, alongside your gallery. If so, then you could maybe create an <iframe> on your gallery's web page, with a specific id and name, and then use this id/name as the linkTarget to load the linkURL into the <iframe>.

For example:

    <!--START JUICEBOX EMBED-->
    <script src="jbcore/juicebox.js"></script>
    <script>
    new juicebox({
        containerId: 'juicebox-container',
        imageClickMode: 'OPEN_URL',
        galleryWidth: '600',
        galleryHeight: '400'
    });
    </script>
    <div id="juicebox-container"></div>
    <iframe id="xyz" name="xyz" width="600" height="400"></iframe>
    <!--END JUICEBOX EMBED-->

A sample <image entry in your gallery's 'config.xml' file might look something like this:

  <image imageURL="images/image_0001.jpg"
    thumbURL="thumbs/image_0001.jpg"
    linkURL="http://www.example.com"
    linkTarget="xyz">
    <title><![CDATA[Image title goes here.]]></title>
    <caption><![CDATA[Image caption goes here.]]></caption>
  </image>

I hope this helps.
If not, then please try to explain in greater detail what you are looking to do and I'll try to help further.
Thank you.

3 (edited by made2105 2018-08-23 11:53:40)

Re: How to configure Image click to open url in a part of the page?

Hi Steve! Thanks for your prompt answer!

I've just uploaded the updated site. You can take a look at www.sapu.org.uy

What I was trying to explain is that all the pages load into the index page "mainContent" area through the script I posted above. That is dynamically and not into an iframe.

My gallery is embedded in the home.php page. So if I use the imageClickMode: 'OPEN_URL' the target can't be an iframe id/name.
Somehow, and that's my issue, the pages linked to each image should also be able to "call" that script and load into the index.php.

Don't know if this is even possible to do in juicebox pro.

Thanks a lot for any help you can provide!

Re: How to configure Image click to open url in a part of the page?

Thank you for the clarification.
So you want to run a custom JavaScript function when a main image is clicked...
Juicebox-Pro was not designed with this in mind but you could try the following:

(1) Set imageClickMode="OPEN_URL".
(2) Set all your linkURL entries (in the gallery's XML file) to linkURL="javascript: custom_function();" (to run a custom JavaScript function named custom_function() in the gallery's embedding page when the image is clicked).
(3) Set all your linkTarget entries (also in the gallery's XML file) to linkTarget="_self".

In  order for your function to know which image has been clicked (and, therefore, how to proceed), you could either:

(1) Pass a parameter (or parameters) to the custom function, e.g.:

linkURL="javascript: custom_function('abcdef');"
linkTarget="_self"
<!--START JUICEBOX EMBED-->
<script>
    function custom_function(text) {
        alert(text);
    }
</script>
<script src="jbcore/juicebox.js"></script>
<script>
    new juicebox({
        containerId: "juicebox-container",
        imageClickMode: "OPEN_URL"
    });
</script>
<div id="juicebox-container"></div>
<!--END JUICEBOX EMBED-->

... or:

(2) Use the Juicebox-Pro API (in this example, the getImageIndex() function) within the custom JavaScript function to determine which image has been clicked.

linkURL="javascript: custom_function();"
linkTarget="_self"
<!--START JUICEBOX EMBED-->
<script>
    function custom_function() {
        var index = jb.getImageIndex();
        alert('Image #' + index + ' has been clicked.');
    }
</script>
<script src="jbcore/juicebox.js"></script>
<script>
    var jb = new juicebox({
        containerId: "juicebox-container",
        imageClickMode: "OPEN_URL"
    });
</script>
<div id="juicebox-container"></div>
<!--END JUICEBOX EMBED-->

Please note that this will not work if you use a baseUrl or when the gallery has been expanded.

I hope that this points you in the right direction. (Just replace the contents of the custom JavaScript function with your own code.)

5 (edited by made2105 2018-08-23 20:03:34)

Re: How to configure Image click to open url in a part of the page?

Thanks so much Steve! Sorry to bother you further with this! Java is way out of my league and I've "inherited" the website, LOL.
Personally, I would have done it differently.

Let's see if I understood...

Are you saying I should replace the custom JavaScript function you used:
<script>
    function custom_function(text) {
        alert(text);
    }
</script>

with my original code?
<script>
$('.link').click(function(){
        callDinamicPage('mainContent', $(this).attr('data-toggle'), 'page', '');
    });
</script>

AND, in order to use the linkURL what should I replace "custom_function" with? Let's say I have an image called photo1

linkURL="javascript: custom_function('photo1');"

???
I'll very much appreciate your help with this! But hey, do not worry if it's too much to ask! I'll totally understand :)

Re: How to configure Image click to open url in a part of the page?

Using my example, you'd still need to use the custom_function() JavaScript function but setting imageClickMode="OPEN_URL" would essentially take the place of your jQuery click handler (at least for clicks on the gallery images... you'd still need your own custom click handler for your regular non-gallery links).
Instead of:

<script>
    function custom_function(text) {
        alert(text);
    }
</script>

... use:

<script>
    function custom_function(parameter) {
        callDinamicPage('mainContent', parameter, 'page', '');
    }
</script>

You'd also need to pass the value of what would be the data-toggle attribute (in a regular non-gallery link) as a parameter in the call to the function (in the linkURL), e.g.:

linkURL="javascript: custom_function('xyz');"

(This assumes that 'xyz' is a valid data-toggle attribute for your scenario. Just change this for each linkURL as necessary.)

As I mentioned above, you'd still need to include your own custom click handler:

<script>
    $('.link').click(function() {
        callDinamicPage('mainContent', $(this).attr('data-toggle'), 'page', '');
    });
</script>

... on your web page to handle your regular non-gallery links.

Re: How to configure Image click to open url in a part of the page?

Awesome Steve! Can't thank you enough. I'll try that and let you know. :)

8 (edited by made2105 2018-08-24 17:10:37)

Re: How to configure Image click to open url in a part of the page?

I got everything except this part... sorryyy!!!

You'd also need to pass the value of what would be the data-toggle attribute (in a regular non-gallery link) as a parameter in the call to the function (in the linkURL), e.g.:

linkURL="javascript: custom_function('xyz');"

(This assumes that 'xyz' is a valid data-toggle attribute for your scenario. Just change this for each linkURL as necessary.)

In the non-gallery pages, data-toggle calls a page to load. For example I have a page called congreso2019.php so my script is data-toggle="congreso2019"

In the link option you describe I tried linkURL="javascript: custom_function('congreso2019');" Is this correct? Because it didn't work...

I'm sure I followed the rest of your instructions correctly.

Thanks again for all your help :)

Re: How to configure Image click to open url in a part of the page?

In the link option you describe I tried linkURL="javascript: custom_function('congreso2019');" Is this correct?

Yes.

Because it didn't work...

It looks like you have not yet implemented this solution in your live web page which is fine (I understand that you do not want to have a dysfunctional web page) but it makes troubleshooting the problem a little difficult as I am not able to see the problem for myself and do not know exactly what you have tried).

First of all, I do not know where your gallery's embedding code is stored or how it is inserted into your web page but you'll need to make sure that when you insert the gallery's embedding code, you insert the following code, too:

<script>
    function custom_function(parameter) {
        callDinamicPage('mainContent', parameter, 'page', '');
    }
</script>

Also, I notice that you use a baseUrl (baseUrl: "index-slider",).
I noted in a post above that the solution I suggested does not work with a baseUrl so you'll need to use the regular embedding method and structure noted here instead. Essentially, copy the contents of your gallery folder (not the gallery folder itself) into the directory that contains the web page where the gallery's embedding code is to be inserted (in your case, your root directory) and adjust the path to your 'juicebox.js' file in the <script> tag (and remove the baseUrl).

I hope this points you in the right direction.