Skip to content

Commit f78f220

Browse files
committed
Work in progress menu and restructure
1 parent cf44202 commit f78f220

File tree

15 files changed

+1444
-59
lines changed

15 files changed

+1444
-59
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"tv4": "~1.0.15",
4545
"angular-sanitize": ">= 1.2",
4646
"objectpath": "~1.1.0",
47-
"moment": "~2.9.0"
47+
"moment": "~2.9.0",
48+
"angular-scroll": "~0.7.0"
4849
},
4950
"devDependencies": {
5051
"angular-ui-ace": "bower",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "angular-scroll",
3+
"version": "0.7.0",
4+
"main": "angular-scroll.js",
5+
"ignore": [
6+
"**/.*",
7+
"node_modules",
8+
"bower_components",
9+
"test",
10+
"tests",
11+
"package.json",
12+
"src",
13+
"Gruntfile.js"
14+
],
15+
"dependencies": {
16+
"angular": "^1.2.16"
17+
},
18+
"devDependencies": {
19+
"angular-mocks": "^1.2.16"
20+
},
21+
"resolutions": {
22+
"angular": "^1.2.16"
23+
},
24+
"homepage": "https://github.com/oblador/angular-scroll",
25+
"_release": "0.7.0",
26+
"_resolution": {
27+
"type": "version",
28+
"tag": "v0.7.0",
29+
"commit": "cccd872652502bb169f468e19bb6cc20a469e4cd"
30+
},
31+
"_source": "git://github.com/oblador/angular-scroll.git",
32+
"_target": "~0.7.0",
33+
"_originalSource": "angular-scroll",
34+
"_direct": true
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Issues
2+
------
3+
4+
**Please provide clear steps to reproduce your issue**. This is preferably done in a [plunker](http://plnkr.co/), a video or just a link to your project.
5+
6+
Also nice to include info about your browser environment, version of angular/angular-scroll you are using and other libraries (such as jQuery etc).
7+
8+
9+
Pull Requests
10+
-------------
11+
12+
* Don't include the compiled assets (`angular-scroll.*`) in your PR.
13+
* Only edit the source files (ie not the `angular-scroll.*` files).
14+
* Tests are welcome and don't forget to run existing via `npm run test-single-run` and `npm run protractor` before comitting.
15+
* Lint your code by running `gulp lint` before comitting.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Durated
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
angular-scroll
2+
==============
3+
4+
Angular is only dependency (no jQuery). 8K minified or 2K gzipped.
5+
6+
Example
7+
-------
8+
Check out [the live demo](http://oblador.github.io/angular-scroll/) or the [source code](https://github.com/oblador/angular-scroll/blob/master/example/index.html).
9+
10+
Install
11+
-------
12+
13+
#### With bower:
14+
15+
$ bower install angular-scroll
16+
17+
#### With npm (for use with browserify):
18+
19+
$ npm install angular-scroll
20+
21+
You can also download the [production version](https://raw.github.com/oblador/angular-scroll/master/angular-scroll.min.js)or the [development version](https://raw.github.com/oblador/angular-scroll/master/angular-scroll.js).
22+
23+
If you prefer a CDN hosted version (which might speed up your load times), check out [cdnjs.com/libraries/angular-scroll](https://cdnjs.com/libraries/angular-scroll).
24+
25+
26+
Don't forget to add `duScroll` to your module dependencies.
27+
28+
`angular.element` Scroll API
29+
----------------------------
30+
31+
This module extends the `angular.element` object with a few jQuery like functions. Note that `$document` is an `angular.element`, for usage example see below. In case of name collisions existing jQuery or jqlite functions will be preserved, just use the prefixed version: ie `.duScrollTo()` instead of `.scrollTo()`.
32+
33+
#### `.scrollTo( left, top [, duration [, easing ] ] )`
34+
Scrolls the element/window to the specified left/top position. If `duration` is specified the scrolling is animated for n milliseconds. If `easing` is ommited the animation will default to the `duScrollEasing` function.
35+
36+
#### `.scrollTo( element [, offset, [, duration [, easing ] ] ] )`
37+
Alias of `.scrollToElement`.
38+
39+
#### `.scrollToElement( element [, offset, [, duration [, easing ] ] ] )`
40+
Scrolls to the specified element, if `offset` is passed it will be subtracted from the elements position which is good if one uses floating menus.
41+
42+
#### `.scrollToElementAnimated( element [, offset, [, duration [, easing ] ] ] )`
43+
Convenience function. Works exactly the same as `scrollToElement` but uses the default values from `duScrollOffset`, `duScrollDuration` and `duScrollEasing` unless otherwise specified.
44+
45+
#### `.scrollTop|scrollLeft( )`
46+
Returns current scroll position.
47+
48+
#### `.scrollTop|scrollLeft( top [, duration [, easing ] ] )`
49+
Scrolls to specified position in either axis, with optional animation.
50+
51+
#### `.scrollTopAnimated|scrollLeftAnimated( top [, duration [, easing ] ] )`
52+
Convenience function like `scrollToElementAnimated` but for `scrollTop`/`scrollLeft`.
53+
54+
#### Promises
55+
Animated scrolling returns a `$q` promise, it will resolve when the scrolling has finished or be rejected if cancelled (by starting another scroll animation before it finished).
56+
57+
#### Example
58+
```js
59+
angular.module('myApp', ['duScroll']).
60+
controller('myCtrl', function($scope, $document) {
61+
var top = 400;
62+
var duration = 2000; //milliseconds
63+
64+
//Scroll to the exact position
65+
$document.scrollTop(top, duration).then(function() {
66+
console && console.log('You just scrolled to the top!');
67+
});
68+
69+
var offset = 30; //pixels; adjust for floating menu, context etc
70+
//Scroll to #some-id with 30 px "padding"
71+
//Note: Use this in a directive, not with document.getElementById
72+
var someElement = angular.element(document.getElementById('some-id'));
73+
$document.scrollToElement(someElement, offset, duration);
74+
}
75+
);
76+
```
77+
78+
The above example can be achieved by configuration instead of arguments:
79+
80+
```js
81+
angular.module('myApp', ['duScroll'])
82+
.value('duScrollDuration', 2000)
83+
.value('duScrollOffset', 30)
84+
.controller('myCtrl', function($scope, $document) {
85+
$document.scrollTopAnimated(400).then(function() {
86+
console && console.log('You just scrolled to the top!');
87+
});
88+
89+
var someElement = angular.element(document.getElementById('some-id'));
90+
$document.scrollToElementAnimated(someElement);
91+
}
92+
);
93+
```
94+
95+
96+
Directives
97+
----------
98+
99+
### `du-smooth-scroll`
100+
Provides smooth anchor scrolling.
101+
```html
102+
<a href="#anchor" du-smooth-scroll>Scroll it!</a>
103+
```
104+
105+
### `du-scrollspy`
106+
Observes whether the target element is at the top of the viewport (or container) and adds an `active` class if so. Takes optional `offset` and `duration` attributes which is passed on to `.scrollTo`,
107+
108+
```html
109+
<a href="#anchor" du-scrollspy>Am i active?</a>
110+
```
111+
112+
or together with Bootstrap
113+
114+
```html
115+
<ul class="nav navbar-nav">
116+
<li du-scrollspy="anchor"><a href="#anchor">Link</a></li>
117+
</ul>
118+
```
119+
120+
### `du-spy-context`
121+
Enables multiple sets of spies on the same target element. Takes optional `offset` attribute to
122+
123+
```html
124+
<ul du-spy-context class="nav navbar-nav">
125+
<li du-scrollspy="anchor"><a href="#anchor">Link</a></li>
126+
</ul>
127+
<ul du-spy-context class="nav navbar-nav">
128+
<li du-scrollspy="anchor"><a href="#anchor">Link</a></li>
129+
</ul>
130+
```
131+
### `du-scroll-container`
132+
Modifies behavior of `du-scrollspy` and `du-smooth-scroll` to observe/scroll within and element instead of the window/document. Good for modals/elements with `overflow: auto/scroll`.
133+
134+
```html
135+
<div du-scroll-container>
136+
<p id="top">This is the top</p>
137+
<p id="anchor">Scroll to me, or <a href="#top" du-smooth-scroll>the top</a></p>
138+
</div>
139+
```
140+
141+
If your links lie outside of the scrollable element, wrap them with the `du-scroll-container` directive and send the element id as argument:
142+
143+
```html
144+
<ul du-scroll-container="scroll-container">
145+
<li><a href="#anchor" du-smooth-scroll>Link</a></li>
146+
</ul>
147+
<div id="scroll-container">
148+
[...]
149+
</div>
150+
```
151+
152+
### [All in together now](http://www.youtube.com/watch?v=cx4KtTezEFg&feature=kp)
153+
The directives play well together, try [the demo](http://oblador.github.io/angular-scroll/container.html) or inspect its [source code](https://github.com/oblador/angular-scroll/blob/master/example/container.html).
154+
155+
```html
156+
<ul du-spy-context du-scroll-container="scroll-container">
157+
<li><a href="#anchor" offset="30" du-smooth-scroll du-scrollspy>Link</a></li>
158+
</ul>
159+
<ul du-spy-context du-scroll-container="scroll-container">
160+
<li><a href="#anchor" offset="30" du-smooth-scroll du-scrollspy>Link</a></li>
161+
</ul>
162+
<div id="scroll-container">
163+
[...]
164+
</div>
165+
```
166+
167+
Observing Scroll Position
168+
-------------------------
169+
170+
**NOTE:** the `$duScrollChanged` event and the `scrollPosition` service are deprecated. Use `angular.element().on()` together with `.scrollTop()` instead.
171+
172+
```js
173+
angular.module('myApp', ['duScroll']).
174+
controller('MyCtrl', function($scope, $document){
175+
$document.on('scroll', function() {
176+
console.log('Document scrolled to ', $document.scrollLeft(), $document.scrollTop());
177+
});
178+
var container = angular.element(document.getElementById('container'));
179+
container.on('scroll', function() {
180+
console.log('Container scrolled to ', container.scrollLeft(), container.scrollTop());
181+
});
182+
}
183+
);
184+
```
185+
186+
Configuration
187+
-------------
188+
189+
### Scroll speed
190+
Duration is defined in milliseconds.
191+
192+
To set a scroll duration on a single anchor:
193+
```html
194+
<a href="#anchor" du-smooth-scroll duration="5000">Scroll it!</a>
195+
```
196+
197+
To change the default duration:
198+
```js
199+
angular.module('myApp', ['duScroll']).value('duScrollDuration', 5000);
200+
```
201+
202+
### Scroll easing
203+
Set the `duScrollEasing` value to a function that takes and returns a value between 0 to 1. Here's [a few examples](https://gist.github.com/gre/1650294) to choose from.
204+
205+
```js
206+
function invertedEasingFunction(x) {
207+
return 1-x;
208+
}
209+
angular.module('myApp', ['duScroll']).value('duScrollEasing', invertedEasingFunction);
210+
```
211+
212+
You can also pass a custom easing function as the fourth argument in `scrollTo`.
213+
214+
### Greedy option
215+
Set the `duScrollGreedy` value to `true` if the elements you are observing are not wrapping the whole section you want to observe, but merely the first one in the section (such as headlines).
216+
217+
```js
218+
angular.module('myApp', ['duScroll']).value('duScrollGreedy', true);
219+
```
220+
221+
### Offset
222+
To change default offset (in pixels) for the `du-smooth-scroll` directive:
223+
224+
```js
225+
angular.module('myApp', ['duScroll']).value('duScrollOffset', 30);
226+
```
227+
228+
### Bottom spy
229+
To make the last `du-scrollspy` link active when scroll reaches page/container bottom:
230+
231+
```js
232+
angular.module('myApp', ['duScroll']).value('duScrollBottomSpy', true);
233+
```
234+
235+
Events
236+
------
237+
238+
The `duScrollspy` directive fires the global events `duScrollspy:becameActive` and `duScrollspy:becameInactive` with an angular.element wrapped element as first argument. This is nice to have if you want the URL bar to reflect where on the page the visitor are, like this:
239+
240+
```js
241+
angular.module('myApp', ['duScroll']).
242+
config(function($locationProvider) {
243+
$locationProvider.html5Mode(true);
244+
}).
245+
run(function($rootScope, $location){
246+
$rootScope.$on('duScrollspy:becameActive', function($event, $element){
247+
//Automaticly update location
248+
var hash = $element.prop('hash');
249+
if(hash) {
250+
$location.hash(hash.substr(1)).replace();
251+
$rootScope.$apply();
252+
}
253+
});
254+
});
255+
```
256+
257+
258+
Building
259+
--------
260+
261+
$ gulp
262+
263+
Tests
264+
-----
265+
266+
### Unit tests
267+
268+
$ npm test
269+
270+
### End to end tests
271+
272+
$ npm run update-webdriver
273+
$ npm run protractor

0 commit comments

Comments
 (0)