diff options
| author | Matias Niemelä | 2013-04-02 19:41:16 -0400 |
|---|---|---|
| committer | Igor Minar | 2013-04-03 17:40:15 -0700 |
| commit | 19f1801379104bc1f74fbb9d288f71034ba829c9 (patch) | |
| tree | eaf2d28c5056b80669b33478c808df88431d6a4e /src/ng/directive | |
| parent | 303df9dafee4314e5cfbc805f3321f4f4297a41a (diff) | |
| download | angular.js-19f1801379104bc1f74fbb9d288f71034ba829c9.tar.bz2 | |
docs: add animations into docs and directive examples
Diffstat (limited to 'src/ng/directive')
| -rw-r--r-- | src/ng/directive/ngInclude.js | 43 | ||||
| -rw-r--r-- | src/ng/directive/ngRepeat.js | 102 | ||||
| -rw-r--r-- | src/ng/directive/ngShowHide.js | 154 | ||||
| -rw-r--r-- | src/ng/directive/ngSwitch.js | 101 | ||||
| -rw-r--r-- | src/ng/directive/ngView.js | 61 |
5 files changed, 376 insertions, 85 deletions
diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js index a385d00b..45800e75 100644 --- a/src/ng/directive/ngInclude.js +++ b/src/ng/directive/ngInclude.js @@ -41,7 +41,9 @@ </select> url of the template: <tt>{{template.url}}</tt> <hr/> - <div ng-include src="template.url"></div> + <div class="example-animate-container" + ng-include="template.url" + ng-animate="{enter: 'example-enter', leave: 'example-leave'}"></div> </div> </file> <file name="script.js"> @@ -53,10 +55,45 @@ } </file> <file name="template1.html"> - Content of template1.html + <div>Content of template1.html</div> </file> <file name="template2.html"> - Content of template2.html + <div>Content of template2.html</div> + </file> + <file name="animations.css"> + .example-leave-setup, + .example-enter-setup { + -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + -ms-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + + position:absolute; + top:0; + left:0; + right:0; + bottom:0; + } + + .example-animate-container > * { + display:block; + padding:10px; + } + + .example-enter-setup { + top:-50px; + } + .example-enter-setup.example-enter-start { + top:0; + } + + .example-leave-setup { + top:0; + } + .example-leave-setup.example-leave-start { + top:50px; + } </file> <file name="scenario.js"> it('should load template1.html', function() { diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index fada0696..060f3392 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -61,26 +61,86 @@ * @example * This example initializes the scope to a list of names and * then uses `ngRepeat` to display every person: - <doc:example> - <doc:source> - <div ng-init="friends = [{name:'John', age:25}, {name:'Mary', age:28}]"> - I have {{friends.length}} friends. They are: - <ul> - <li ng-repeat="friend in friends"> - [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old. - </li> - </ul> - </div> - </doc:source> - <doc:scenario> - it('should check ng-repeat', function() { - var r = using('.doc-example-live').repeater('ul li'); - expect(r.count()).toBe(2); - expect(r.row(0)).toEqual(["1","John","25"]); - expect(r.row(1)).toEqual(["2","Mary","28"]); - }); - </doc:scenario> - </doc:example> + <example animations="true"> + <file name="index.html"> + <div ng-init="friends = [ + {name:'John', age:25, gender:'boy'}, + {name:'Jessie', age:30, gender:'girl'}, + {name:'Johanna', age:28, gender:'girl'}, + {name:'Joy', age:15, gender:'girl'}, + {name:'Mary', age:28, gender:'girl'}, + {name:'Peter', age:95, gender:'boy'}, + {name:'Sebastian', age:50, gender:'boy'}, + {name:'Erika', age:27, gender:'girl'}, + {name:'Patrick', age:40, gender:'boy'}, + {name:'Samantha', age:60, gender:'girl'} + ]"> + I have {{friends.length}} friends. They are: + <input type="search" ng-model="q" placeholder="filter friends..." /> + <ul> + <li ng-repeat="friend in friends | filter:q" + ng-animate="{enter: 'example-repeat-enter', + leave: 'example-repeat-leave', + move: 'example-repeat-move'}"> + [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old. + </li> + </ul> + </div> + </file> + <file name="animations.css"> + .example-repeat-enter-setup, + .example-repeat-leave-setup, + .example-repeat-move-setup { + -webkit-transition:all linear 0.5s; + -moz-transition:all linear 0.5s; + -ms-transition:all linear 0.5s; + -o-transition:all linear 0.5s; + transition:all linear 0.5s; + } + + .example-repeat-enter-setup { + line-height:0; + opacity:0; + } + .example-repeat-enter-setup.example-repeat-enter-start { + line-height:20px; + opacity:1; + } + + .example-repeat-leave-setup { + opacity:1; + line-height:20px; + } + .example-repeat-leave-setup.example-repeat-leave-start { + opacity:0; + line-height:0; + } + + .example-repeat-move-setup { } + .example-repeat-move-setup.example-repeat-move-start { } + </file> + <file name="scenario.js"> + it('should render initial data set', function() { + var r = using('.doc-example-live').repeater('ul li'); + expect(r.count()).toBe(10); + expect(r.row(0)).toEqual(["1","John","25"]); + expect(r.row(1)).toEqual(["2","Jessie","30"]); + expect(r.row(9)).toEqual(["10","Samantha","60"]); + expect(binding('friends.length')).toBe("10"); + }); + + it('should update repeater when filter predicate changes', function() { + var r = using('.doc-example-live').repeater('ul li'); + expect(r.count()).toBe(10); + + input('q').enter('ma'); + + expect(r.count()).toBe(2); + expect(r.row(0)).toEqual(["1","Mary","28"]); + expect(r.row(1)).toEqual(["2","Samantha","60"]); + }); + </file> + </example> */ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) { var NG_REMOVED = '$$NG_REMOVED'; @@ -119,7 +179,7 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) { return hashKey(value); } } - + match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/); if (!match) { throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '" + diff --git a/src/ng/directive/ngShowHide.js b/src/ng/directive/ngShowHide.js index 418a43ff..7ccc0aa0 100644 --- a/src/ng/directive/ngShowHide.js +++ b/src/ng/directive/ngShowHide.js @@ -24,13 +24,68 @@ * then the element is shown or hidden respectively. * * @example - <doc:example> - <doc:source> - Click me: <input type="checkbox" ng-model="checked"><br/> - Show: <span ng-show="checked">I show up when your checkbox is checked.</span> <br/> - Hide: <span ng-hide="checked">I hide when your checkbox is checked.</span> - </doc:source> - <doc:scenario> + <example animations="true"> + <file name="index.html"> + Click me: <input type="checkbox" ng-model="checked"><br/> + <div> + Show: + <span class="check-element" + ng-show="checked" + ng-animate="{show: 'example-show', hide: 'example-hide'}"> + <span class="icon-thumbs-up"></span> I show up when your checkbox is checked. + </span> + </div> + <div> + Hide: + <span class="check-element" + ng-hide="checked" + ng-animate="{show: 'example-show', hide: 'example-hide'}"> + <span class="icon-thumbs-down"></span> I hide when your checkbox is checked. + </span> + </div> + </file> + <file name="animations.css"> + .example-show-setup, .example-hide-setup { + -webkit-transition:all linear 0.5s; + -moz-transition:all linear 0.5s; + -ms-transition:all linear 0.5s; + -o-transition:all linear 0.5s; + transition:all linear 0.5s; + } + + .example-show-setup { + line-height:0; + opacity:0; + padding:0 10px; + } + .example-show-start.example-show-start { + line-height:20px; + opacity:1; + padding:10px; + border:1px solid black; + background:white; + } + + .example-hide-setup { + line-height:20px; + opacity:1; + padding:10px; + border:1px solid black; + background:white; + } + .example-hide-start.example-hide-start { + line-height:0; + opacity:0; + padding:0 10px; + } + + .check-element { + padding:10px; + border:1px solid black; + background:white; + } + </file> + <file name="scenario.js"> it('should check ng-show / ng-hide', function() { expect(element('.doc-example-live span:first:hidden').count()).toEqual(1); expect(element('.doc-example-live span:last:visible').count()).toEqual(1); @@ -40,8 +95,8 @@ expect(element('.doc-example-live span:first:visible').count()).toEqual(1); expect(element('.doc-example-live span:last:hidden').count()).toEqual(1); }); - </doc:scenario> - </doc:example> + </file> + </example> */ //TODO(misko): refactor to remove element from the DOM var ngShowDirective = ['$animator', function($animator) { @@ -78,24 +133,79 @@ var ngShowDirective = ['$animator', function($animator) { * the element is shown or hidden respectively. * * @example - <doc:example> - <doc:source> - Click me: <input type="checkbox" ng-model="checked"><br/> - Show: <span ng-show="checked">I show up when you checkbox is checked?</span> <br/> - Hide: <span ng-hide="checked">I hide when you checkbox is checked?</span> - </doc:source> - <doc:scenario> + <example animations="true"> + <file name="index.html"> + Click me: <input type="checkbox" ng-model="checked"><br/> + <div> + Show: + <span class="check-element" + ng-show="checked" + ng-animate="{show: 'example-show', hide: 'example-hide'}"> + <span class="icon-thumbs-up"></span> I show up when your checkbox is checked. + </span> + </div> + <div> + Hide: + <span class="check-element" + ng-hide="checked" + ng-animate="{show: 'example-show', hide: 'example-hide'}"> + <span class="icon-thumbs-down"></span> I hide when your checkbox is checked. + </span> + </div> + </file> + <file name="animations.css"> + .example-show-setup, .example-hide-setup { + -webkit-transition:all linear 0.5s; + -moz-transition:all linear 0.5s; + -ms-transition:all linear 0.5s; + -o-transition:all linear 0.5s; + transition:all linear 0.5s; + } + + .example-show-setup { + line-height:0; + opacity:0; + padding:0 10px; + } + .example-show-start.example-show-start { + line-height:20px; + opacity:1; + padding:10px; + border:1px solid black; + background:white; + } + + .example-hide-setup { + line-height:20px; + opacity:1; + padding:10px; + border:1px solid black; + background:white; + } + .example-hide-start.example-hide-start { + line-height:0; + opacity:0; + padding:0 10px; + } + + .check-element { + padding:10px; + border:1px solid black; + background:white; + } + </file> + <file name="scenario.js"> it('should check ng-show / ng-hide', function() { - expect(element('.doc-example-live span:first:hidden').count()).toEqual(1); - expect(element('.doc-example-live span:last:visible').count()).toEqual(1); + expect(element('.doc-example-live .check-element:first:hidden').count()).toEqual(1); + expect(element('.doc-example-live .check-element:last:visible').count()).toEqual(1); input('checked').check(); - expect(element('.doc-example-live span:first:visible').count()).toEqual(1); - expect(element('.doc-example-live span:last:hidden').count()).toEqual(1); + expect(element('.doc-example-live .check-element:first:visible').count()).toEqual(1); + expect(element('.doc-example-live .check-element:last:hidden').count()).toEqual(1); }); - </doc:scenario> - </doc:example> + </file> + </example> */ //TODO(misko): refactor to remove element from the DOM var ngHideDirective = ['$animator', function($animator) { diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 8b0dab31..8cf8945d 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -47,40 +47,77 @@ * * * @example - <doc:example> - <doc:source> - <script> - function Ctrl($scope) { - $scope.items = ['settings', 'home', 'other']; - $scope.selection = $scope.items[0]; - } - </script> - <div ng-controller="Ctrl"> - <select ng-model="selection" ng-options="item for item in items"> - </select> - <tt>selection={{selection}}</tt> - <hr/> - <div ng-switch on="selection" > + <example animations="true"> + <file name="index.html"> + <div ng-controller="Ctrl"> + <select ng-model="selection" ng-options="item for item in items"> + </select> + <tt>selection={{selection}}</tt> + <hr/> + <div + class="example-animate-container" + ng-switch on="selection" + ng-animate="{enter: 'example-enter', leave: 'example-leave'}"> <div ng-switch-when="settings">Settings Div</div> - <span ng-switch-when="home">Home Span</span> - <span ng-switch-default>default</span> - </div> + <div ng-switch-when="home">Home Span</div> + <div ng-switch-default>default</div> </div> - </doc:source> - <doc:scenario> - it('should start in settings', function() { - expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Settings Div/); - }); - it('should change to home', function() { - select('selection').option('home'); - expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Home Span/); - }); - it('should select default', function() { - select('selection').option('other'); - expect(element('.doc-example-live [ng-switch]').text()).toMatch(/default/); - }); - </doc:scenario> - </doc:example> + </div> + </file> + <file name="script.js"> + function Ctrl($scope) { + $scope.items = ['settings', 'home', 'other']; + $scope.selection = $scope.items[0]; + } + </file> + <file name="animations.css"> + .example-leave-setup, .example-enter-setup { + -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + -ms-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; + + position:absolute; + top:0; + left:0; + right:0; + bottom:0; + } + + .example-animate-container > * { + display:block; + padding:10px; + } + + .example-enter-setup { + top:-50px; + } + .example-enter-start.example-enter-start { + top:0; + } + + .example-leave-setup { + top:0; + } + .example-leave-start.example-leave-start { + top:50px; + } + </file> + <file name="scenario.js"> + it('should start in settings', function() { + expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Settings Div/); + }); + it('should change to home', function() { + select('selection').option('home'); + expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Home Span/); + }); + it('should select default', function() { + select('selection').option('other'); + expect(element('.doc-example-live [ng-switch]').text()).toMatch(/default/); + }); + </file> + </example> */ var ngSwitchDirective = ['$animator', function($animator) { return { diff --git a/src/ng/directive/ngView.js b/src/ng/directive/ngView.js index 2ffd64da..5b6d938b 100644 --- a/src/ng/directive/ngView.js +++ b/src/ng/directive/ngView.js @@ -21,7 +21,7 @@ * * @scope * @example - <example module="ngView"> + <example module="ngView" animations="true"> <file name="index.html"> <div ng-controller="MainCntl"> Choose: @@ -31,7 +31,10 @@ <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> | <a href="Book/Scarlet">Scarlet Letter</a><br/> - <div ng-view></div> + <div + ng-view + class="example-animate-container" + ng-animate="{enter: 'example-enter', leave: 'example-leave'}"></div> <hr /> <pre>$location.path() = {{$location.path()}}</pre> @@ -43,14 +46,58 @@ </file> <file name="book.html"> - controller: {{name}}<br /> - Book Id: {{params.bookId}}<br /> + <div> + controller: {{name}}<br /> + Book Id: {{params.bookId}}<br /> + </div> </file> <file name="chapter.html"> - controller: {{name}}<br /> - Book Id: {{params.bookId}}<br /> - Chapter Id: {{params.chapterId}} + <div> + controller: {{name}}<br /> + Book Id: {{params.bookId}}<br /> + Chapter Id: {{params.chapterId}} + </div> + </file> + + <file name="animations.css"> + .example-leave-setup, .example-enter-setup { + -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s; + -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s; + -ms-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s; + -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s; + transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s; + } + + .example-animate-container { + position:relative; + height:100px; + } + + .example-animate-container > * { + display:block; + width:100%; + border-left:1px solid black; + + position:absolute; + top:0; + left:0; + right:0; + bottom:0; + padding:10px; + } + + .example-enter-setup { + left:100%; + } + .example-enter-setup.example-enter-start { + left:0; + } + + .example-leave-setup { } + .example-leave-setup.example-leave-start { + left:-100%; + } </file> <file name="script.js"> |
