docs: add animations into docs and directive examples

This commit is contained in:
Matias Niemelä 2013-04-02 19:41:16 -04:00 committed by Igor Minar
parent 303df9dafe
commit 19f1801379
10 changed files with 496 additions and 97 deletions

View file

@ -57,12 +57,27 @@ exports.Example.prototype.addSource = function(name, content) {
}
};
exports.Example.prototype.enableAnimations = function() {
this.animations = true;
};
exports.Example.prototype.disableAnimations = function() {
this.animations = false;
};
exports.Example.prototype.toHtml = function() {
return '<h2>Source</h2>\n' +
this.toHtmlEdit() +
this.toHtmlTabs() +
'<h2>Demo</h2>\n' +
this.toHtmlEmbed();
var html = "<h2>Source</h2>\n";
html += this.toHtmlEdit();
html += this.toHtmlTabs();
if(this.animations) {
html += '<div class="pull-right">';
html += ' <button class="btn btn-primary" ng-click="animationsOff=true" ng-hide="animationsOff">Animations on</button>';
html += ' <button class="btn btn-primary disabled" ng-click="animationsOff=false" ng-show="animationsOff">Animations off</button>';
html += '</div>';
}
html += "<h2>Demo</h2>\n";
html += this.toHtmlEmbed();
return html;
};
@ -116,7 +131,10 @@ exports.Example.prototype.toHtmlTabs = function() {
exports.Example.prototype.toHtmlEmbed = function() {
var out = [];
out.push('<div class="well doc-example-live"');
out.push('<div class="well doc-example-live animator-container"');
if(this.animations) {
out.push(" ng-class=\"{'animations-off':animationsOff == true}\"");
}
out.push(' ng-embed-app="' + this.module + '"');
out.push(' ng-set-html="' + this.html[0].id + '"');
out.push(' ng-eval-javascript="' + ids(this.js) + '">');

View file

@ -130,8 +130,13 @@ Doc.prototype = {
parts.forEach(function(text, i) {
parts[i] = (text || '').
replace(/<example(?:\s+module="([^"]*)")?(?:\s+deps="([^"]*)")?>([\s\S]*?)<\/example>/gmi, function(_, module, deps, content) {
replace(/<example(?:\s+module="([^"]*)")?(?:\s+deps="([^"]*)")?(\s+animations="true")?>([\s\S]*?)<\/example>/gmi,
function(_, module, deps, animations, content) {
var example = new Example(self.scenarios);
if(animations) {
example.enableAnimations();
}
example.setModule(module);
example.addDeps(deps);
@ -437,9 +442,11 @@ Doc.prototype = {
var restrict = self.restrict || 'AC';
if (restrict.match(/E/)) {
dom.html('<p>');
dom.text('This directive can be used as custom element, but we aware of ');
dom.tag('a', {href:'guide/ie'}, 'IE restrictions');
dom.text('.');
dom.html('</p>');
}
if (self.usage) {

View file

@ -0,0 +1,73 @@
.reveal-setup {
-webkit-transition:1s linear all;
-moz-transition:1s linear all;
-ms-transition:1s linear all;
-o-transition:1s linear all;
transition:1s linear all;
opacity:0;
}
.reveal-setup.reveal-start {
opacity:1;
}
.slide-reveal-setup {
-webkit-transition:0.5s linear all;
-moz-transition:0.5s linear all;
-ms-transition:0.5s linear all;
-o-transition:0.5s linear all;
transition:0.5s linear all;
opacity:0.5;
}
.slide-reveal-setup.slide-reveal-start {
opacity:1;
}
.slide-enter-setup {
-webkit-transition:0.5s linear all;
-moz-transition:0.5s linear all;
-ms-transition:0.5s linear all;
-o-transition:0.5s linear all;
transition:0.5s linear all;
position:relative;
left:10px;
opacity:0;
}
.slide-enter-setup.slide-enter-start {
left:0;
opacity:1;
}
.slide-leave-setup {
-webkit-transition:0.5s linear all;
-moz-transition:0.5s linear all;
-ms-transition:0.5s linear all;
-o-transition:0.5s linear all;
transition:0.5s linear all;
opacity:1;
}
.slide-leave-setup.slide-leave-start {
opacity:0;
}
.example-animate-container {
position:relative;
background:white;
border:1px solid black;
height:40px;
overflow:hidden;
}
.example-animate-container > div {
padding:1em;
}
.animator-container.animations-off * {
-webkit-transition: none;
-moz-transition: none;
-ms-transition: none;
-o-transition: color 0 ease-in; /* opera is special :) */
transition: none;
}

View file

@ -3,6 +3,15 @@ img.AngularJS-small {
height: 25px;
}
/* this is here to avoid the display=block shuffling of ngShow */
.breadcrumb li > * {
float:left;
margin:0 2px 0 0;
}
.breadcrumb {
padding-bottom:2px;
}
.clear-navbar {
margin-top: 60px;

View file

@ -34,6 +34,7 @@
addTag('link', {rel: 'stylesheet', href: 'css/bootstrap.min.css', type: 'text/css'});
addTag('link', {rel: 'stylesheet', href: 'css/font-awesome.css', type: 'text/css'});
addTag('link', {rel: 'stylesheet', href: 'css/docs.css', type: 'text/css'});
addTag('link', {rel: 'stylesheet', href: 'css/animations.css', type: 'text/css'});
if (jQuery) addTag('script', {src: debug ? 'js/jquery.js' : 'js/jquery.min.js'});
addTag('script', {src: path('angular.js')}, sync);
addTag('script', {src: path('angular-resource.js') }, sync);
@ -231,21 +232,21 @@
<li class="nav-header section" ng-show="module.directives">
<a href="{{URL.directive}}" class="guide">directive</a>
</li>
<li ng-repeat="page in module.directives" ng-class="navClass(page)">
<li ng-repeat="page in module.directives" ng-class="navClass(page)" ng-animate="'slide'">
<a href="{{page.url}}" tabindex="2">{{page.shortName}}</a>
</li>
<li class="nav-header section" ng-show="module.filters">
<a href="{{URL.filter}}" class="guide">filter</a>
</li>
<li ng-repeat="page in module.filters" ng-class="navClass(page)">
<li ng-repeat="page in module.filters" ng-class="navClass(page)" ng-animate="'slide'">
<a href="{{page.url}}" tabindex="2">{{page.shortName}}</a>
</li>
<li class="nav-header section" ng-show="module.services">
<a href="{{URL.service}}" class="guide">service</a>
</li>
<li ng-repeat="service in module.services" ng-class="navClass(service.instance, service.provider)">
<li ng-repeat="service in module.services" ng-animate="'slide'" ng-class="navClass(service.instance, service.provider)">
<a ng-show="service.provider" class="pull-right" href="{{service.provider.url}}" tabindex="2"><i class="icon-cog"></i></a>
<a href="{{service.instance.url}}" tabindex="2">{{service.name}}</a>
</li>
@ -253,7 +254,7 @@
<li class="nav-header section" ng-show="module.types">
<a href="{{URL.type}}" class="guide">Types</a>
</li>
<li ng-repeat="page in module.types" ng-class="navClass(page)">
<li ng-repeat="page in module.types" ng-class="navClass(page)" ng-animate="'slide'">
<a href="{{page.url}}" tabindex="2">{{page.shortName}}</a>
</li>
@ -281,7 +282,7 @@
<div id="loading" ng-show="loading">Loading...</div>
<div ng-hide="loading" ng-include src="currentPage.partialUrl" onload="afterPartialLoaded()" autoscroll class="content"></div>
<div ng-hide="loading" ng-include src="currentPage.partialUrl" onload="afterPartialLoaded()" autoscroll class="content" ng-animate="{enter: 'slide-reveal'}" ></div>
<div id="disqus" class="disqus">
<h2>Discussion</h2>

View file

@ -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() {

View file

@ -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 '" +

View file

@ -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) {

View file

@ -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 {

View file

@ -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">