-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 1.0.1-envato version to public repo
- Loading branch information
Ben Smithett
committed
Oct 21, 2014
1 parent
da1086c
commit fd357d1
Showing
4 changed files
with
73 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,49 +1,18 @@ | ||
viewloader is a tiny little framework-agnostic JS bootstrapping thing that lets you attach JS behaviour to a HTML element using data attributes. | ||
A slightly tweaked version of https://github.com/bensmithett/viewloader/tree/1.x-master to help us | ||
incrementally update to v2. | ||
|
||
## How to use it | ||
|
||
Add `data-view` attributes to your HTML: | ||
With this HTML: | ||
|
||
```html | ||
<div data-view="dropdown"> | ||
... | ||
</div> | ||
<div data-view="someThing"></div> | ||
``` | ||
|
||
Create an object for your app that lists setup functions for each type of view. | ||
and this JS: | ||
|
||
```javascript | ||
MyApp.Views = { | ||
dropdown: function( $el ) { $el.fancyDropdown(); }, | ||
chatWindow: function( $el, el ) { new ChatWindowView({ el: el }); }, | ||
// ... etc etc | ||
}; | ||
viewloader.execute(SomeNamespace); | ||
``` | ||
|
||
Once the DOM is ready, run: | ||
|
||
```javascript | ||
viewloader.execute( MyApp.Views ); | ||
``` | ||
|
||
viewloader will find every element on the page with a `data-view` attribute and check to see if a function with that name exists on the supplied object. | ||
|
||
If such a function exists, it will be called 2 arguments: | ||
|
||
- `$el`: the jQuery-wrapped DOM element (i.e. `$(el)`) | ||
- `el`: the DOM element | ||
|
||
`viewloader.execute` takes an optional second argument so you can scope execution to a particular element/set of elements. This is useful if you've updated the DOM and need to re-bind behaviour to new elements. | ||
|
||
```javascript | ||
viewloader.execute( myApp.views, $("#updated-dom-container") ); | ||
``` | ||
|
||
## Dependencies | ||
viewloader needs either [jQuery](http://jquery.com/) or [Zepto](http://zeptojs.com/). If you're not using either of those, it's 13 whole lines of JavaScript... I'm sure you can rewrite it to suit your needs :) | ||
|
||
## License | ||
viewloader is released under the [MIT License](http://ben.mit-license.org/) | ||
viewloader will automagically call `new SomeNamespace.SomeThing($el, el)` | ||
|
||
## Shoutout | ||
viewloader is just a slightly-tweaked and bower-componentized version of an idea that [Toby](https://github.com/tobico) showed me. | ||
(Transforming the first letter to lowercase is a specific requirement of our use case) |
This file contains 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"name": "viewloader", | ||
"name": "viewloader-envato", | ||
"main": "viewloader.js", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/bensmithett/viewloader", | ||
"version": "1.0.1-envato", | ||
"homepage": "https://github.com/envato/viewloader", | ||
"authors": [ | ||
"Ben Smithett <[email protected]>" | ||
], | ||
|
This file contains 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
This file contains 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