1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Overlays call xfActivate before running inline JS

Discussion in 'Resolved Bug Reports' started by cclaerhout, Nov 4, 2013.

  1. cclaerhout

    cclaerhout Well-Known Member

  2. Mike

    Mike XenForo Developer Staff Member

    The issue isn't really clear. A simple test case to demonstrate the issue would help.

    I suppose you're doing some sort of (order-dependent) extension/manipulation of the editor (or any other XF JS) object and that the expected load order isn't happening when dependencies are dynamically added. There's no guarantee of order for scripts that are dynamically loaded, just that they're all loaded. Adding an expected execution order is not in the scope of what we're trying to do.

    The XF classes won't be instantiated until this happens so it's not obvious what the purpose of the setTimeout is (unless you're doing something on the same event).
     
  3. cclaerhout

    cclaerhout Well-Known Member

    What I want to achieve is not the most important here. Time simply wanted to edit a message inline on a page that doesn't have any editor previously loaded. He's on the portal, he's got a list of posts, he simply created a link to edit message by loading the editor in the overlay. If you check at the screenshot in the post I gave you, you will see the phrase are not yet available (no matter the Bbm addon is enable or not). As you know the phrases are inside a template and are loaded by the gettext function you wrote. It seems the XenForo loader loads the Javascript faster than the templates. The setTimeout even set to 0 is a just a trick to execute the JS code after the template (and its embedded JS objects directly written inside it, in this case the phrases) is loaded.

    May be there's another solution, I don't know. It's just working. I've no idea if the vocabulary I use is technically correct or not, it's just can be reproduced. Here's the code Time sent to me (to use in the XenPorta "EWRblock_RecentNews" template).

    Now to come back to the idea of having a minimum control on the scripts loading orders, may be It's me and I don't see the way of achieving this, but since the way to extend your framework seems to be to load data before the framework script and since there's no way right now to control the execution order once an overlay is called, this might be a not very comfortable situation for independent developers.
     
  4. cclaerhout

    cclaerhout Well-Known Member

    One more thing, once again I don't know why, the problem is only available for phrases with the "Use Bb Code Editor" phrase (not others). With the setTimeout trick, the problem is not there anymore. The "for" is underline because I think if more parameters have to be loaded, some problems will also occur. This is what I've met in other situations.
     
  5. Mike

    Mike XenForo Developer Staff Member

    This is fixed now. The XF classes were activated before inline JS was run; I've inverted this order now as it's more consistent with how it works for non-overlay triggers. I think this is the only scenario where it comes up.
     
    cclaerhout likes this.
  6. cclaerhout

    cclaerhout Well-Known Member

    Your title is effectively far more precise than mine. So the safest way to extend your framework is to use inline js? There's no other way to be sure that one of the two JS using the helper "require js" inside a same template will be loaded before the other one?
     
  7. Mike

    Mike XenForo Developer Staff Member

    Well, the core issue that you're explaining -- the phrase text in the editor when loaded only via an overlay -- is simply related to inline JS vs xfActivate trigger order, which I've changed. If inline JS is not used (and in this case, it's only used for editor phrases), there won't be any change in behavior.

    I'm not really stating anything about using inline script. If you have JS B that must run after A is loaded, you may need to look at ways to either change that or change how dependencies are loaded (not using the standard ExtLoader system). When we load external dependencies, we load them in parallel to be faster, so the execution order is indeterminate.
     
  8. cclaerhout

    cclaerhout Well-Known Member

    So to be a little more concrete for me, all js loaded with "require js" helper will be loaded with the ExtLoader (when an overlay is called), which means if I want to load a JS file before your Editor framework possible and safe solutions would be:
    1. not to use this helper and use instead the "on" jquery function (with its former pattern live)
    2. extend the XenForo.ExtLoader to match the custom js and reorder the array with it at the top
    3. (edit) insert the js in the template directly since now with the fix it will be executed first
    That doesn't sound super convenient but I will give it a try.
     
    Last edited: Nov 4, 2013

Share This Page