-
Notifications
You must be signed in to change notification settings - Fork 16
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
Comments
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. |
I agree with you, Ken. I invoke the script on certain portions of the DOM that I create on the fly using Angular: |
Trial auto-invocation of foundation, foundationextend for #77
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();
} |
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();
}
}); |
This ticket also has a relationship with #115 (Warn when invoking default functions on an empty document) |
Marking this one as finished. |
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:
It would also potentially allow us to use the
defer
attribute on the loading offoundation.js
andfoundationExtendEBI.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, saybody.no-self-invoke-foundation
The text was updated successfully, but these errors were encountered: