2016-08-22 10:30:46 -04:00
Locomotive's Front-end Boilerplate
==================================
2014-03-01 09:33:24 -08:00
2016-08-22 10:30:46 -04:00
Front-end boilerplate for projects by [Locomotive][locomtl].
2015-02-15 15:44:11 -05:00
2015-12-07 10:35:27 -05:00
## Requirements
2016-08-22 10:30:46 -04:00
| Prerequisite | How to check | How to install |
| --------------- | ------------- | -------------------------------- |
| Node.js 4.1.1 | `node -v` | [nodejs.org ](https://nodejs.org ) |
| Grunt >= 0.1.13 | `grunt -v` | `npm install -g grunt-cli` |
2015-03-05 14:57:47 -05:00
2015-12-07 10:35:27 -05:00
## Getting started
2015-03-13 12:47:44 -04:00
2016-08-22 10:30:46 -04:00
1. **Get the latest node modules **
2018-03-26 17:32:15 -04:00
- `npm install -g npm-check-updates`
- `npm-check-updates -u`
- `npm install`
2015-03-13 12:47:44 -04:00
2018-03-26 17:32:15 -04:00
BrowserSync will automatically inject, refresh and sync all your browsers.
2018-03-26 17:34:47 -04:00
2018-03-26 17:32:15 -04:00
2. **Set your project **
- `build/browserSync.js` update proxy
- `assets/scripts/utils/environment.js` update `APP_NAME`
2018-03-26 17:34:47 -04:00
3. **Run grunt, BrowserSync and start coding **
2018-03-26 17:32:15 -04:00
- `grunt sync`
2015-03-05 14:57:47 -05:00
2015-12-07 10:35:27 -05:00
### Grunt
2016-08-22 10:30:46 -04:00
2015-04-20 09:53:11 -04:00
Each Grunt task has it's own file in the `grunt_tasks` folder.
2015-12-07 10:35:27 -05:00
## CSS
2015-02-15 15:44:11 -05:00
2016-08-22 10:30:46 -04:00
- We use [Sass ](http://sass-lang.com ) for our CSS Preprocessor
- [itcss ](http://itcss.io ) CSS architecture
- More Minimal BEM like CSS Syntax: `.block_element -modifier`
- [More Transparent UI Code with Namespaces ](http://csswizardry.com/2015/03/more-transparent-ui-code-with-namespaces )
2015-12-07 10:35:27 -05:00
### Sass import order
2015-02-15 15:44:11 -05:00
2016-08-22 10:30:46 -04:00
* **Settings: ** Global variables, site-wide settings, config switches, etc.
* **Tools: ** Site-wide mixins and functions.
* **Generic: ** Low-specificity, far-reaching rulesets (e.g. resets).
* **Base: ** Unclassed HTML elements (e.g. `a {}` , `blockquote {}` , `address {}` ).
* **Objects: ** Objects, abstractions, and design patterns (e.g. `.o-media {}` ).
* **Components: ** Discrete, complete chunks of UI (e.g. `.c-carousel {}` ).
2018-03-26 17:32:15 -04:00
* **Utilities: ** High-specificity, very explicit selectors. Overrides and helper
2015-12-07 10:35:27 -05:00
classes (e.g. `.u-hidden {}` ).
2015-03-06 10:15:49 -05:00
### Grid
2018-03-26 17:32:15 -04:00
We use [inuitcss ](https://github.com/inuitcss/inuitcss/tree/6eb574fa604481ffa36272e6034e77467334ec50 ) layout and width system. We are using a inline-block grid system.
2015-03-06 10:15:49 -05:00
2018-03-26 17:32:15 -04:00
Insert a `.o-layout` block and add `.o-layout_item` elements inside it. By default `o-layout_item` made 100%.
You can define different fractions in `/tools/_widths.scss` (`$widths-fractions` )
2015-03-06 10:15:49 -05:00
2018-03-26 17:32:15 -04:00
If you want a 2 columns grid, just add `.u-1/2` on your 2 `.o-layout_item`
2015-03-06 10:15:49 -05:00
2018-03-26 17:32:15 -04:00
If you want to adapt columns by media queries, by example a 2 columns grid for 1000px + resolutions, and one columns in block under 1000px :
**HTML**
```
<div class="o-layout">
2018-03-26 17:34:47 -04:00
<div class="o-layout_item u-1/2@from -medium">
first colum
</div>
<div class="o-layout_item u-1/2@from -medium">
second colum
</div>
2018-03-26 17:32:15 -04:00
</div>
```
**CSS** (`/tools/_widths.scss` )
```
2018-03-26 17:34:47 -04:00
.u-1\/2\@from-medium {
@media (min-width: $from-medium) {
width: span(1/2);
2018-03-26 17:32:15 -04:00
}
2018-03-26 17:34:47 -04:00
}
2018-03-26 17:32:15 -04:00
```
2015-03-06 10:15:49 -05:00
2015-03-24 13:05:05 -04:00
### Form
We included some basic CSS styles and resets to the form elements so we can easily have custom style form elements that work on every browsers.
2016-08-22 10:30:46 -04:00
*[Demo][demo-form]*
2015-12-07 10:35:27 -05:00
## JavaScript
2016-08-22 10:30:46 -04:00
- We use HTML data attributes to init our JavaScript modules: `data-module`
- All DOM related JavaScript is hooked to `js-` prefixed HTML classes
- [jQuery ](https://jquery.com ) is globally included
[locomtl]: https://locomotive.ca
[demo-grid]: https://codepen.io/AntoineBoulanger/pen/EaLNxe
[demo-form]: https://codepen.io/AntoineBoulanger/pen/uBJmi
2018-03-26 17:32:15 -04:00
## Page transitions
We use [Pjax ](https://github.com/MoOx/pjax ) by MoOx.
### Setup
1. Create a wrapper : `.js-pjax-wrapper` and a container `.js-pjax-container` inside. When a transition is launched, the new container is put inside the wrapper, and the old one is remove.
2. Main settings are set inside `assets/scripts/transitions/TransitionManager.js`
3. `BaseTransition` is launched by default, to set a new transition (like `CustomTransition` ) :
- create a new class `TestTransition.js` witch extends `BaseTransition` in `assets/scripts/transitions/`
- add a line in `assets/scripts/transitions/transitions.js` to add your transition
- use it like : `<a href="/yourUrl" data-transition="TestTransition">My page</a>`
- Enjoy and made everything you want in your transition, check `BaseTransition.js` or `CustomTransition.js` like example
### Schema
Legend
- `[ ]` : listener
- `*` : trigger event
`[pjax:send]` -> (transition) launch()
`[pjax:switch]` (= new view is loaded) -> (BaseTransition) `hideView()` -> hide animations & `*readyToRemove`
`[readyToRemove]` -> `remove()` -> delete modules, remove oldView from the DOM, innerHTML newView, init modules, `display()`
`display()` -> (BaseTransition) `displayView()` -> display animations & `*readyToDestroy`
-> init new modules
`[readyToRemove]` -> reinit()