Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use asynchronous loop when $(document).foundation() #9228

Closed
rkoberg opened this issue Oct 4, 2016 · 4 comments
Closed

use asynchronous loop when $(document).foundation() #9228

rkoberg opened this issue Oct 4, 2016 · 4 comments

Comments

@rkoberg
Copy link

rkoberg commented Oct 4, 2016

I am trying to use foundation as-is in a react/redux app and would like to have a top/App level call to $(document).foundation() (or perhaps a new $(document).foundation('ifNew')) on componentDidUpdate (which means often). If the each/loop that does the plugin creation was async it would not matter how often it is called (??) and you can remove the warning for if ($el.data('zfPlugin')) and just return. I think this could solve several problems for SPAs.

In foundation.core there is:

      // Localize the search to all elements inside elem, as well as elem itself, unless elem === document
      var $elem = $(elem).find('[data-'+name+']').addBack('[data-'+name+']');

      // For each plugin found, initialize it
      $elem.each(function() {
        var $el = $(this),

(Ideally, the find would look for '[data-zf-'+name+']')

Perhaps something like:

function processElems($elem, process) {
    setTimeout(function() {
        process($elem.shift());
        if($elem.length > 0) {
            setTimeout(arguments.callee, 25);
        }
    }, 25);
}
@rkoberg
Copy link
Author

rkoberg commented Oct 5, 2016

One thing I forgot to include (assume this is probably a known issue) was that reInit does not work. foundation.core does not recorgnize jquery elements, that have already been set up with foundation() passsed in to the above iterate.

@Owlbertz
Copy link
Contributor

If you need to re-initialize only a specific part of your page, the lower example on this page may help you.

@colin-marshall
Copy link
Contributor

@ncoden does this tie into #10900 at all?

@ncoden
Copy link
Contributor

ncoden commented Feb 13, 2018

@colin-marshall No. The problem here is not how to reflow but could be reflow asynchronously ?

@DanielRuf DanielRuf added this to Planning and Organizing in Foundation V7 Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Foundation V7
Planning and Organizing
Development

No branches or pull requests

5 participants