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

Improve loading of foundation, foundationExtendEBI, script.js #77

Closed
khawkins98 opened this issue Apr 13, 2017 · 6 comments
Closed

Improve loading of foundation, foundationExtendEBI, script.js #77

khawkins98 opened this issue Apr 13, 2017 · 6 comments
Labels
Milestone

Comments

@khawkins98
Copy link
Contributor

khawkins98 commented Apr 13, 2017

There's an opportunity to simplify the boilerplate code by self-inoking the Foundation JS at the bottom of foundationExtendEBI.js.

This would allow us to remove:

  <script type="text/JavaScript">$(document).foundation();</script>
  <script type="text/JavaScript">$(document).foundationExtendEBI();</script>

It would also potentially allow us to use the defer attribute on the loading of foundation.js and foundationExtendEBI.js -- which would improve the page interaction time.

At present I don't see a downside to doing this, as users of foundationExtendEBI.js will need to have jQuery and Foundation. Only possible downside would be if a site has other complex foundation extensions ... that could perhaps be overcome by setting a body class to not self invoke, say body.no-self-invoke-foundation

@khawkins98
Copy link
Contributor Author

Generally we seem to get more requests to partially invoke the scripts, rather than a desire for a more auto-pilot solution.

Won't close this, but generally I think this idea won't be favoured.

@khawkins98 khawkins98 added this to the 1.3 milestone Jun 12, 2017
@esanzgar
Copy link
Contributor

esanzgar commented Aug 3, 2017

I agree with you, Ken.

I invoke the script on certain portions of the DOM that I create on the fly using Angular:
$(newDOMPortion).foundation()

khawkins98 added a commit that referenced this issue Aug 11, 2017
Trial auto-invocation of foundation, foundationextend for #77
@khawkins98
Copy link
Contributor Author

khawkins98 commented Aug 11, 2017

I think we could do it like so, using data-attributes so we can 1) say if we want it to auto-invoke, and 2) if we want it not to execute on the document root.

This also keeps the expected behaviour of not invoking unless requested.

  /* Allow invocation of of foundation and foundationExtendEBI with data attributes

    <body data-foundationInvoke="document" data-foundationExtendEBI="document">

    This saves the need of placing the below on your page:
    <script type="text/JavaScript">$(document).foundation();</script>
    <script type="text/JavaScript">$(document).foundationExtendEBI();</script>

    Background: https://github.com/ebiwd/EBI-Framework/issues/77
  */
  var bodyData = $('body').data();
  if (bodyData.foundationInvoke) {
    bodyData.foundationInvoke = bodyData.foundationInvoke || 'document';
    if (bodyData.foundationInvoke === 'true') bodyData.foundationInvoke = 'document';
    $(bodyData.foundationInvoke).foundation();
  }
  if (bodyData.foundationExtendEBI) {
    bodyData.foundationExtendEBI = bodyData.foundationExtendEBI || 'document';
    if (bodyData.foundationExtendEBI === 'true') bodyData.foundationExtendEBI = 'document';
    $(bodyData.foundationExtendEBI).foundationExtendEBI();
  }

@khawkins98 khawkins98 changed the title Self-invoke foundation and foundationExtendEBI Improve loading of foundation, foundationExtendEBI, script.js Aug 11, 2017
khawkins98 added a commit that referenced this issue Aug 11, 2017
@khawkins98
Copy link
Contributor Author

We can also use the same approach to not invoke script.js automatically.

/* All scripts are automatically loaded, unless the page asked us not to.
 *   Configurable with a data attribute:
 *   <body data-ebiFrameworkInvokeScripts="false">
 **/
document.addEventListener("DOMContentLoaded", function(event) {
  var bodyData = document.body.dataset;
  if (bodyData.ebiFrameworkInvokeScripts != false) {
    ebiFrameworkInvokeScripts();
  }
});

@khawkins98
Copy link
Contributor Author

This ticket also has a relationship with #115 (Warn when invoking default functions on an empty document)

khawkins98 added a commit to ebiwd/EBI-Style-lab that referenced this issue Feb 22, 2018
@khawkins98
Copy link
Contributor Author

Marking this one as finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants