Problem/Motivation

Currently it can happen that the JS settings for the optionsets are messed up if ajax_command_settings() is used with merge enabled. Instead of having the single options in the optionset the options are converted to arrays what makes flexslider very unhappy.
Further we should figure out a way to make the instance id's unique over multiple requests.
Currently a static variable is used to increase the id within the same request. As this starts over within an ajax request we can end up with two flexslider-1 items on the same page.

Proposed resolution

I've used the already prepared cache to set the optionset only once within the same request - that prevents the merge issue.
Related to the id issue, the best solution I could think of was to add the REQUEST_TIME to the id. I think this should work fine even with caching. A possible issue could be that a normal browser request and the ajax request happen in exact the same second, what again would cause colliding id's.
How likely is that?
To reduce the probability of such a collision we could switch to microsecond(TRUE) instead REQUEST_TIME.

Remaining tasks

Reviews needed

User interface changes

None

API changes

No real API changes, but the format of the id's has changed. If someone has custom code that deals with them it's likely that this will break.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

minorOffense’s picture

Related issue #2048723: Allow the ID of the flexslider to be set manually

For ajax pages, having a custom ID generated vs having the user configure a static ID is something we'll have to mull over.

das-peter’s picture

Just struggled again over this. Re-rolled the patch.
To avoid creating "unpredictable" id's we could change to an approach where we use an unique css class (based on the id) to do the initialization (_flexslider_init()).
That way we could ensure that the initialization works even if an id is set manually and the code isn't aware of the ajax issue.

minorOffense’s picture

Status: Needs review » Needs work

That won't work. You could have two requests come in at the same time once again giving you your ID conflict.

Not to mention it would make theming a specific flexslider instance pretty well impossible by ID (even though you aren't really supposed to use ids for theming people still do).

minorOffense’s picture

The cache patch seems ok though. I'd be willing to put that in.

das-peter’s picture

The topic of collision was already mentioned in the summary:

I think this should work fine even with caching. A possible issue could be that a normal browser request and the ajax request happen in exact the same second, what again would cause colliding id's.
How likely is that?
To reduce the probability of such a collision we could switch to microsecond(TRUE) instead REQUEST_TIME.

And I've tried to outline another approach to tackle the issue in #2:

To avoid creating "unpredictable" id's we could change to an approach where we use an unique css class (based on the id) to do the initialization (_flexslider_init()).
That way we could ensure that the initialization works even if an id is set manually and the code isn't aware of the ajax issue.

If we change to this approach we could use random id's I think.
However, before I start working towards another solution I'd like to have feedback first.

das-peter’s picture

Status: Needs work » Needs review

Set to needs review again to gain attention ;)