Hi,

When closing a photobox Dialog and using the "back" function in browser the photobox will ne open again.

Is it possible to change that?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

duozersk’s picture

Title: Using "back" in browser opens photobox after closing » Using "back" in browser opens photobox after closing - make it configurable
Category: Task » Feature request

zwerg,

Thank you for using the module and for the request.

Yep, it's a feature of the Photobox library itself. It is configurable (disable/enable - enabled by default), but there is no option for it in UI yet.

Thanks
AndyB

zwerg’s picture

Thx for your reply! Can you tell me how to configure?

duozersk’s picture

Nope, I can't - there is no UI option for this yet, only code hacks could help. I plan on implementing the UI for it soon.

mvlabat’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
2.26 KB

Here is the patch providing your feature request.
Currently there is a new option in the formatter settings UI called "Use browser history". It defines whether photobox has to change url after hash symbol so writing every slideshow iteration to browser history.
This patch also provides ability to override photobox defaults, so further adding new settings to it will be easy.
Please, feel free to use and test it.

duozersk’s picture

Status: Needs review » Needs work

Vladislav,

Thank you for a patch!

+++ b/photobox.module
@@ -242,6 +249,20 @@ function photobox_field_formatter_view($entity_type, $entity, $field, $instance,
+  drupal_add_js($settings, 'setting');

Please use the #attached value of the element instead of drupal_add_js()

Thanks
AndyB

mvlabat’s picture

I've already tried this approach to use #attached. The problem is that adding the same variables several times (because of attaching js to every field delta) causes messing Drupal.settings variable. I think we can't avoid this behavior so unfortunately the only way to do it is to use drupal_add_js.

duozersk’s picture

Crap... I see :) Will need to test it to see if we can do anything about it. Really don't want to use drupal_add_js() here.

mvlabat’s picture

May I ask you the reason why you don't want to use drupal_add_js in that place? I only heard that it is preferable to use #attached, but I don't know what is the profit.

duozersk’s picture

Sure, it is all about the cache (at least what I know about it).

There might be the code (for instance, https://www.drupal.org/project/render_cache) that caches the renderable array returned by our formatter and so when it is requested again - just returns this cached array (including the #attached property) - and the formatter view function doesn't run and drupal_add_js() doesn't run. I didn't test this exact module - https://www.drupal.org/project/render_cache - but the whole thing about the #attached vs. drupal_add_js/drupal_add_css is about the cache (at least for me, there are also other considerations like easier altering of the assets attached to the rendarable arrays and form arrays).

This is definitely true for blocks when the blocks caching is turned on. Another reason is that drupal_add_js/drupal_add_css are removed from Drupal 8.

Thanks
AndyB

duozersk’s picture

Another thought - this configuration should probably be the global for a site, not on the formatter level. Cause it will cause conflicts if we have different settings in formatters on different view modes or different entities shown on the same page.

  • duozersk committed 9d4f86c on 7.x-1.x
    Implemented [#2413263] - added global Photobox settings form
    
duozersk’s picture

Status: Needs work » Fixed
zwerg’s picture

Status: Fixed » Needs review

Hey,

sorry for the late answer but thanks a lot for your work! In my case it doesn't work. When disabling the 'history' (via UI or settings page), clearing all caches and reloading the nodes, the error is still there.

The URL (using back in browser) looks like: http://mysite/node#http%3A%2F%2mysite%2Fsites%2Fdefault%2Ffiles%2Fstyles...node%2Fimage.jpg%3Fitok%3DBcj-s2rA

I'm using the collage formatter to display all images and load the photobox. Maybe this generates the token (not correctly)?