-
Notifications
You must be signed in to change notification settings - Fork 0
Foundation 7: JavaScript plugin initialization #13
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
Open
abdullahsalem
wants to merge
1
commit into
master
Choose a base branch
from
f7-js-plugin-initialization-proposal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Foundation 7: JavaScript plugin initialization | ||
|
||
## Introduction | ||
Foundation JavaScript architecture is really a piece of beauty, and you can easily proof that by opening the `foundation.core.js` then you will clearly notice these arguments: | ||
- Wrapping the whole stuff in a namespace | ||
- Registering and Unregistering the plugins | ||
- Smart initializing technique | ||
- Storing the initialized plugins | ||
- And more... | ||
|
||
One more thing, Foundation JavaScript plugins are not defined directly to jQuery, but they are completely live in that isolated namespace which is called Foundation, that kind of isolation gives Foundation the power to manage those plugins and keep them away from jQuery’s plugins and other worlds! | ||
|
||
I am not going to describe the other strengths of the Foundation JavaScript architecture, but I would only like to make you notice that Foundation really has the principles of the Scalable Architecture. | ||
|
||
## Foundation JavaScript plugin initialization | ||
Foundation is smart enough to recognize the elements that should be initialized, it looks for any element that has the data attribute, for example: data-dropdown, and once Foundation finds that plugin name in the registered plugins list, it will initialize that element. Additionally, Foundation will collect and merge the plugin’s options from three resources: plugin’s default options, the value of `data-options`, and the individual data attributes. | ||
|
||
However, what about if Foundation is used with any other non-Foundation JavaScript plugin or framework? I am sure mixing UI frameworks is not recommended, but as you know there are many other front-end frameworks that don’t target the UI but the data binding, so let’s assume this scenario: | ||
|
||
You have a non-Foundation JavaScript plugin that requires this data attribute `data-what-ever`, while you also have a Foundation JavaScript plugin that assume `data-what-ever` is a plugin name or an option name. That is a very simple example of the expected conflicts, and regardless that conflicts, Foundation is assumed to be used even partially, that means you can only use one plugin from Foundation in your application and that implicitly means you will use another bunch of other JavaScript code, so in this case Foundation must not assume that all data attributes are reserved for it! | ||
|
||
## Solution | ||
I would suggest these two steps to solve that: | ||
- Adding a namespace to the data attribute of the plugin name and the plugin’s options, so the data attributes should look like: `data-zf-plugin-name` and `data-zf-options`. | ||
- Removing the previous data individual options, and keep all the passed options in `data-zf-options`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it makes difficult the change of an option through HTML ? If yes, we have to ensure that all options can be modified through |
||
|
||
I think that will help Foundation to be easily mixed with any other JavaScript plugins and avoiding any expected naming conflicts, and the most important is to free the data attribute to be used from others. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wether in Sass, JS, HTML (ect...), everywhere we work on the global namespace, we can't declare names without prefixs. The probability of naming collisions are too high, and they are often incorrigible for the user.
So YES, we should use a Foundation namespace, thank you !
About
data-
attributes :However, I think
zf
is rare enough for we use it as prefix without risk of a naming collision.