├── .gitattributes
├── .gitignore
├── LICENSE
├── LICENSE-ng
├── README.md
├── nuget
├── build.ps1
├── publish.ps1
└── src
│ ├── AngularJS.Intellisense.nuspec
│ └── content
│ └── scripts
│ └── _references.js
└── src
├── AngularJS-VisualStudio-Intellisense.csproj
├── AngularJS-VisualStudio-Intellisense.sln
├── Scripts
├── _references.js
├── angular-animate.js
├── angular-route.js
├── angular.intellisense.js
├── angular.js
└── tests
│ ├── basic-tests.js
│ ├── multi-file-test
│ ├── multi-file-test1.js
│ └── multi-file-test2.js
│ └── test-ngModuleIncludedByDefault.js
└── packages.config
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 |
18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19 | !packages/*/build/
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 |
98 | # NuGet Packages Directory
99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
100 | #packages/
101 |
102 | # Windows Azure Build Output
103 | csx
104 | *.build.csdef
105 |
106 | # Windows Store app package directory
107 | AppPackages/
108 |
109 | # Others
110 | sql/
111 | *.Cache
112 | ClientBin/
113 | [Ss]tyle[Cc]op.*
114 | ~$*
115 | *~
116 | *.dbmdl
117 | *.[Pp]ublish.xml
118 | *.pfx
119 | *.publishsettings
120 |
121 | # RIA/Silverlight projects
122 | Generated_Code/
123 |
124 | # Backup & report files from converting an old project file to a newer
125 | # Visual Studio version. Backup files are not needed, because we have git ;-)
126 | _UpgradeReport_Files/
127 | Backup*/
128 | UpgradeLog*.XML
129 | UpgradeLog*.htm
130 |
131 | # SQL Server files
132 | App_Data/*.mdf
133 | App_Data/*.ldf
134 |
135 |
136 | #LightSwitch generated files
137 | GeneratedArtifacts/
138 | _Pvt_Extensions/
139 | ModelManifest.xml
140 |
141 | # =========================
142 | # Windows detritus
143 | # =========================
144 |
145 | # Windows image file caches
146 | Thumbs.db
147 | ehthumbs.db
148 |
149 | # Folder config file
150 | Desktop.ini
151 |
152 | # Recycle Bin used on file shares
153 | $RECYCLE.BIN/
154 |
155 | # Mac desktop service store files
156 | .DS_Store
157 |
158 |
159 | # Nuget Building stuff
160 | nuget/src/content/scripts/angular.intellisense.js
161 | nuget/nuget.exe
162 | nuget/AngularJS.Intellisense.1.0.0.nupkg
163 | nuget/src/content/scripts/angular.intellisense.js
164 | nuget/nuget.exe
165 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 John Bledsoe
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, 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,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/LICENSE-ng:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all 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,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | JavaScript IntelliSense for AngularJS Components in Visual Studio
2 | ===================================
3 |
4 | This project provides intellisense in JavaScript files for injected AngularJS components in Visual Studio.
5 |
6 | Visual Studio 2013 provides intellisense for AngularJS directives within HTML pages, but doesn't include support for intellisense on custom AngularJS components in your project. This extension is designed to provide this support, so that you can have full member listing and statement completion on AngularJS services, factories and providers that you develop.
7 |
8 | >**Note:** This extension is now included by default in Visual Studio 2015. If you want to modify the default behavior, this extension is installed by default in the %PROGRAMFILES%\Microsoft Visual Studio 14.0\JavaScript\References folder. %PROGRAMFILES% is the location of your program files folder, usually under C:\Program Files or C:\Program Files (x86). You can overwrite this file with a new copy from this repository, but do so at your own risk.
9 |
10 | ## Usage
11 |
12 | Enabling intellisense for your custom AngularJS components is simple and can be accomplished with a few simple steps:
13 |
14 | ### Prerequisites
15 |
16 | In order for AngularJS Intellisense to function properly, your project needs a correctly-constructed _references.js file. See the following articles for guidance on creating a _references.js file:
17 |
18 | - http://madskristensen.net/post/the-story-behind-_referencesjs
19 | - http://blogs.msdn.com/b/webdev/archive/2014/10/10/references-js-file-s-auto-sync-feature.aspx
20 |
21 | ### Enabling Intellisense in a Single Project
22 |
23 | Add the [angular.intellisense.js](https://raw.github.com/jmbledsoe/angularjs-visualstudio-intellisense/master/src/Scripts/angular.intellisense.js) file to the same folder in your project that contains angular.js or angular.min.js.
24 |
25 | That's it! All of your AngularJS components should now be fully available via intellisense.
26 |
27 | ### Enabling Intellisense in Multiple Projects
28 |
29 | If you prefer to enable AngularJS intellisene for all of your web projects, simply save the [angular.intellisense.js](https://raw.github.com/jmbledsoe/angularjs-visualstudio-intellisense/master/src/Scripts/angular.intellisense.js) file to your %PROGRAMFILES%\Microsoft Visual Studio 12.0\JavaScript\References folder. %PROGRAMFILES% is the location of your program files folder, usually under C:\Program Files or C:\Program Files (x86).
30 |
31 | ## Tips & Tricks
32 |
33 | 1. Intellisense doesn't yet work for private JavaScript functions inside AngularJS components, but this feature will be added in a future version. **Update:** The latest revision of the _intellisense.js file added support for some private functions along some code paths. Basically, the Visual Studio JavaScript intellisense engine works by calling the JavaScript methods in a code file. The latest update calls many more methods, but still misses methods that are only called in "non-default" code paths. I'm hoping that I can gain some insight into this engine and fix this issue.
34 |
35 | ## Project Status
36 |
37 | This project is still early in its life and so may still have issues, but it is stable enough for use as-is. It provides intellisense for AngularJS components in most of the cases I have tested, although there are some code structures that it cannot figure out yet. If you encounter any issues or any scenarios in which the project isn't providing proper intellisense, please submit an issue.
38 |
39 | **Update: 3/27/2015**
40 |
41 | NuGet Package Created: [AngularJS.Intellisense](https://www.nuget.org/packages/AngularJS.Intellisense/)
42 |
43 | ~~~
44 | PM> Install-Package AngularJS.Intellisense
45 |
46 | ~~~
47 |
48 |
49 |
50 | **Update: 11/10/2014**
51 |
52 | Refactored the extension so that it works with the Visual Studio JavaScript editor's native extensibility model - renaming the extension to angular.intellisense.js. Now, if the file is placed next to angular.js in the project, it will automatically be loaded right after Angular library.
53 |
54 | Other bug fixes made:
55 |
56 | 1. Modules no longer need to be exported to global
57 | 2. The implicit "ng" module is now required by default for all modules - the same as Angular's runtime behavior
58 | 3. Required modules are respected correctly when editing the first file in which a module is defined
59 | 4. Expanded test cases
60 |
61 | **Update: 10/23/2014**
62 |
63 | I've made some significant changes to the _intellisense.js file, which should enable intellisense in far more parts of code. Specifically, I've added code to enable intellisense for:
64 |
65 | 1. Promise callbacks
66 | 2. Scope event listeners
67 | 3. HTTP service callbacks
68 | 4. Functions exposed as members of services
69 |
70 | There are definitely still issues to work out, and I appreciate any issue reports that I receive. Feel free to submit pull requests as well to solve any issues that you encounter, as I don't have a ton of time to devote to this project.
71 |
--------------------------------------------------------------------------------
/nuget/build.ps1:
--------------------------------------------------------------------------------
1 | Copy-Item '..\src\scripts\angular.intellisense.js' -Destination '.\src\content\scripts' -Force
2 |
3 | wget http://nuget.org/nuget.exe -OutFile nuget.exe -ErrorAction Continue
4 |
5 | if (Test-Path '.\nuget.exe'){
6 | $buildCmd = {.\nuget pack src\AngularJS.Intellisense.nuspec -BasePath src -OutputDirectory .}
7 | Invoke-Command $buildCmd
8 | }
9 | else {
10 | Write-Error "Nuget.exe not found"
11 | }
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/nuget/publish.ps1:
--------------------------------------------------------------------------------
1 | [CmdletBinding()]
2 | Param(
3 | [Parameter(Mandatory=$True)]
4 | [string]$apiKey,
5 | [Parameter(Mandatory=$True)]
6 | [string]$packageFile
7 | )
8 |
9 | #$apiKey = Read-Host -Prompt "What is your API Key?"
10 |
11 | wget http://nuget.org/nuget.exe -OutFile nuget.exe -ErrorAction Continue
12 |
13 |
14 | if (Test-Path '.\nuget.exe'){
15 | $pubCmd = {.\nuget.exe push $packageFile -ApiKey $apiKey}
16 | Invoke-Command $pubCmd
17 | }
18 | else {
19 | Write-Error "Nuget.exe not found"
20 | }
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/nuget/src/AngularJS.Intellisense.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | AngularJS.Intellisense
5 | 1.0.3
6 | AngularJS Intellilsense add on
7 | Shawn Cicoria, John Bledsoe
8 | Shawn Cicoria, John Bledsoe
9 | https://raw.githubusercontent.com/cicorias/angularjs-visualstudio-intellisense/master/LICENSE-ng
10 | https://angularjs.org/
11 | https://secure.gravatar.com/avatar/6e1b5ab3ef1593413f1bee4e5a6e6ae7?s=140&d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png
12 | false
13 | This will inject the angularJs intellisense file to your project, along with adding a _references.js file that allows for auto-update of references to drive intellisense.
14 |
15 | For the auto-update of _references.js you can disable by setting the flag to 'false'
16 | Provides project level support for AngularJS intellisence using an intellisense file from John Bledsoe (jmbledsoe) - https://github.com/jmbledsoe/angularjs-visualstudio-intellisense.
17 |
18 | 1.0.3 - set min ref to 1.3 and less than 1.4
19 | 1.0.1 - minor fix - polluted _references.js file
20 | 1.0.0 - initial release
21 | DISCLAIMER: This package is maintained by Shawn Cicoria, but is based upon the hard word of John Beldsoe who created the Intellisense support for AngularJS in Visual Studio. See his GitHub repository
22 | 2015
23 | angularjs, javascript, intellisense
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/nuget/src/content/scripts/_references.js:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/src/AngularJS-VisualStudio-Intellisense.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 |
8 |
9 | 2.0
10 | {9FD86549-6793-45BB-A421-B52A527EDBED}
11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
12 | Library
13 | Properties
14 | AngularJS_VisualStudio_Intellisense
15 | AngularJS-VisualStudio-Intellisense
16 | v4.5
17 | true
18 |
19 |
20 |
21 |
22 |
23 |
24 | true
25 | full
26 | false
27 | bin\
28 | DEBUG;TRACE
29 | prompt
30 | 4
31 |
32 |
33 | pdbonly
34 | true
35 | bin\
36 | TRACE
37 | prompt
38 | 4
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | 10.0
76 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | True
86 | True
87 | 1591
88 | /
89 | http://localhost:1591/
90 | False
91 | False
92 |
93 |
94 | False
95 |
96 |
97 |
98 |
99 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/src/AngularJS-VisualStudio-Intellisense.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30110.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AngularJS-VisualStudio-Intellisense", "AngularJS-VisualStudio-Intellisense.csproj", "{9FD86549-6793-45BB-A421-B52A527EDBED}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {9FD86549-6793-45BB-A421-B52A527EDBED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {9FD86549-6793-45BB-A421-B52A527EDBED}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {9FD86549-6793-45BB-A421-B52A527EDBED}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {9FD86549-6793-45BB-A421-B52A527EDBED}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/src/Scripts/_references.js:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 |
--------------------------------------------------------------------------------
/src/Scripts/angular-animate.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @license AngularJS v1.2.26
3 | * (c) 2010-2014 Google, Inc. http://angularjs.org
4 | * License: MIT
5 | */
6 | (function(window, angular, undefined) {'use strict';
7 |
8 | /* jshint maxlen: false */
9 |
10 | /**
11 | * @ngdoc module
12 | * @name ngAnimate
13 | * @description
14 | *
15 | * # ngAnimate
16 | *
17 | * The `ngAnimate` module provides support for JavaScript, CSS3 transition and CSS3 keyframe animation hooks within existing core and custom directives.
18 | *
19 | *
20 | *
21 | *
22 | * # Usage
23 | *
24 | * To see animations in action, all that is required is to define the appropriate CSS classes
25 | * or to register a JavaScript animation via the myModule.animation() function. The directives that support animation automatically are:
26 | * `ngRepeat`, `ngInclude`, `ngIf`, `ngSwitch`, `ngShow`, `ngHide`, `ngView` and `ngClass`. Custom directives can take advantage of animation
27 | * by using the `$animate` service.
28 | *
29 | * Below is a more detailed breakdown of the supported animation events provided by pre-existing ng directives:
30 | *
31 | * | Directive | Supported Animations |
32 | * |---------------------------------------------------------- |----------------------------------------------------|
33 | * | {@link ng.directive:ngRepeat#usage_animations ngRepeat} | enter, leave and move |
34 | * | {@link ngRoute.directive:ngView#usage_animations ngView} | enter and leave |
35 | * | {@link ng.directive:ngInclude#usage_animations ngInclude} | enter and leave |
36 | * | {@link ng.directive:ngSwitch#usage_animations ngSwitch} | enter and leave |
37 | * | {@link ng.directive:ngIf#usage_animations ngIf} | enter and leave |
38 | * | {@link ng.directive:ngClass#usage_animations ngClass} | add and remove |
39 | * | {@link ng.directive:ngShow#usage_animations ngShow & ngHide} | add and remove (the ng-hide class value) |
40 | * | {@link ng.directive:form#usage_animations form} | add and remove (dirty, pristine, valid, invalid & all other validations) |
41 | * | {@link ng.directive:ngModel#usage_animations ngModel} | add and remove (dirty, pristine, valid, invalid & all other validations) |
42 | *
43 | * You can find out more information about animations upon visiting each directive page.
44 | *
45 | * Below is an example of how to apply animations to a directive that supports animation hooks:
46 | *
47 | * ```html
48 | *
59 | *
60 | *
64 | *
65 | * ```
66 | *
67 | * Keep in mind that, by default, if an animation is running, any child elements cannot be animated
68 | * until the parent element's animation has completed. This blocking feature can be overridden by
69 | * placing the `ng-animate-children` attribute on a parent container tag.
70 | *
71 | * ```html
72 | *
73 | *
74 | *
75 | * ...
76 | *
77 | *
78 | *
79 | * ```
80 | *
81 | * When the `on` expression value changes and an animation is triggered then each of the elements within
82 | * will all animate without the block being applied to child elements.
83 | *
84 | *
CSS-defined Animations
85 | * The animate service will automatically apply two CSS classes to the animated element and these two CSS classes
86 | * are designed to contain the start and end CSS styling. Both CSS transitions and keyframe animations are supported
87 | * and can be used to play along with this naming structure.
88 | *
89 | * The following code below demonstrates how to perform animations using **CSS transitions** with Angular:
90 | *
91 | * ```html
92 | *
115 | *
116 | *
117 | *
118 | *
119 | * ```
120 | *
121 | * The following code below demonstrates how to perform animations using **CSS animations** with Angular:
122 | *
123 | * ```html
124 | *
138 | *
139 | *
140 | *
141 | *
142 | * ```
143 | *
144 | * Both CSS3 animations and transitions can be used together and the animate service will figure out the correct duration and delay timing.
145 | *
146 | * Upon DOM mutation, the event class is added first (something like `ng-enter`), then the browser prepares itself to add
147 | * the active class (in this case `ng-enter-active`) which then triggers the animation. The animation module will automatically
148 | * detect the CSS code to determine when the animation ends. Once the animation is over then both CSS classes will be
149 | * removed from the DOM. If a browser does not support CSS transitions or CSS animations then the animation will start and end
150 | * immediately resulting in a DOM element that is at its final state. This final state is when the DOM element
151 | * has no CSS transition/animation classes applied to it.
152 | *
153 | *
CSS Staggering Animations
154 | * A Staggering animation is a collection of animations that are issued with a slight delay in between each successive operation resulting in a
155 | * curtain-like effect. The ngAnimate module, as of 1.2.0, supports staggering animations and the stagger effect can be
156 | * performed by creating a **ng-EVENT-stagger** CSS class and attaching that class to the base CSS class used for
157 | * the animation. The style property expected within the stagger class can either be a **transition-delay** or an
158 | * **animation-delay** property (or both if your animation contains both transitions and keyframe animations).
159 | *
160 | * ```css
161 | * .my-animation.ng-enter {
162 | * /* standard transition code */
163 | * -webkit-transition: 1s linear all;
164 | * transition: 1s linear all;
165 | * opacity:0;
166 | * }
167 | * .my-animation.ng-enter-stagger {
168 | * /* this will have a 100ms delay between each successive leave animation */
169 | * -webkit-transition-delay: 0.1s;
170 | * transition-delay: 0.1s;
171 | *
172 | * /* in case the stagger doesn't work then these two values
173 | * must be set to 0 to avoid an accidental CSS inheritance */
174 | * -webkit-transition-duration: 0s;
175 | * transition-duration: 0s;
176 | * }
177 | * .my-animation.ng-enter.ng-enter-active {
178 | * /* standard transition styles */
179 | * opacity:1;
180 | * }
181 | * ```
182 | *
183 | * Staggering animations work by default in ngRepeat (so long as the CSS class is defined). Outside of ngRepeat, to use staggering animations
184 | * on your own, they can be triggered by firing multiple calls to the same event on $animate. However, the restrictions surrounding this
185 | * are that each of the elements must have the same CSS className value as well as the same parent element. A stagger operation
186 | * will also be reset if more than 10ms has passed after the last animation has been fired.
187 | *
188 | * The following code will issue the **ng-leave-stagger** event on the element provided:
189 | *
190 | * ```js
191 | * var kids = parent.children();
192 | *
193 | * $animate.leave(kids[0]); //stagger index=0
194 | * $animate.leave(kids[1]); //stagger index=1
195 | * $animate.leave(kids[2]); //stagger index=2
196 | * $animate.leave(kids[3]); //stagger index=3
197 | * $animate.leave(kids[4]); //stagger index=4
198 | *
199 | * $timeout(function() {
200 | * //stagger has reset itself
201 | * $animate.leave(kids[5]); //stagger index=0
202 | * $animate.leave(kids[6]); //stagger index=1
203 | * }, 100, false);
204 | * ```
205 | *
206 | * Stagger animations are currently only supported within CSS-defined animations.
207 | *
208 | *
JavaScript-defined Animations
209 | * In the event that you do not want to use CSS3 transitions or CSS3 animations or if you wish to offer animations on browsers that do not
210 | * yet support CSS transitions/animations, then you can make use of JavaScript animations defined inside of your AngularJS module.
211 | *
212 | * ```js
213 | * //!annotate="YourApp" Your AngularJS Module|Replace this or ngModule with the module that you used to define your application.
214 | * var ngModule = angular.module('YourApp', ['ngAnimate']);
215 | * ngModule.animation('.my-crazy-animation', function() {
216 | * return {
217 | * enter: function(element, done) {
218 | * //run the animation here and call done when the animation is complete
219 | * return function(cancelled) {
220 | * //this (optional) function will be called when the animation
221 | * //completes or when the animation is cancelled (the cancelled
222 | * //flag will be set to true if cancelled).
223 | * };
224 | * },
225 | * leave: function(element, done) { },
226 | * move: function(element, done) { },
227 | *
228 | * //animation that can be triggered before the class is added
229 | * beforeAddClass: function(element, className, done) { },
230 | *
231 | * //animation that can be triggered after the class is added
232 | * addClass: function(element, className, done) { },
233 | *
234 | * //animation that can be triggered before the class is removed
235 | * beforeRemoveClass: function(element, className, done) { },
236 | *
237 | * //animation that can be triggered after the class is removed
238 | * removeClass: function(element, className, done) { }
239 | * };
240 | * });
241 | * ```
242 | *
243 | * JavaScript-defined animations are created with a CSS-like class selector and a collection of events which are set to run
244 | * a javascript callback function. When an animation is triggered, $animate will look for a matching animation which fits
245 | * the element's CSS class attribute value and then run the matching animation event function (if found).
246 | * In other words, if the CSS classes present on the animated element match any of the JavaScript animations then the callback function will
247 | * be executed. It should be also noted that only simple, single class selectors are allowed (compound class selectors are not supported).
248 | *
249 | * Within a JavaScript animation, an object containing various event callback animation functions is expected to be returned.
250 | * As explained above, these callbacks are triggered based on the animation event. Therefore if an enter animation is run,
251 | * and the JavaScript animation is found, then the enter callback will handle that animation (in addition to the CSS keyframe animation
252 | * or transition code that is defined via a stylesheet).
253 | *
254 | */
255 |
256 | angular.module('ngAnimate', ['ng'])
257 |
258 | /**
259 | * @ngdoc provider
260 | * @name $animateProvider
261 | * @description
262 | *
263 | * The `$animateProvider` allows developers to register JavaScript animation event handlers directly inside of a module.
264 | * When an animation is triggered, the $animate service will query the $animate service to find any animations that match
265 | * the provided name value.
266 | *
267 | * Requires the {@link ngAnimate `ngAnimate`} module to be installed.
268 | *
269 | * Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
270 | *
271 | */
272 | .directive('ngAnimateChildren', function() {
273 | var NG_ANIMATE_CHILDREN = '$$ngAnimateChildren';
274 | return function(scope, element, attrs) {
275 | var val = attrs.ngAnimateChildren;
276 | if(angular.isString(val) && val.length === 0) { //empty attribute
277 | element.data(NG_ANIMATE_CHILDREN, true);
278 | } else {
279 | scope.$watch(val, function(value) {
280 | element.data(NG_ANIMATE_CHILDREN, !!value);
281 | });
282 | }
283 | };
284 | })
285 |
286 | //this private service is only used within CSS-enabled animations
287 | //IE8 + IE9 do not support rAF natively, but that is fine since they
288 | //also don't support transitions and keyframes which means that the code
289 | //below will never be used by the two browsers.
290 | .factory('$$animateReflow', ['$$rAF', '$document', function($$rAF, $document) {
291 | var bod = $document[0].body;
292 | return function(fn) {
293 | //the returned function acts as the cancellation function
294 | return $$rAF(function() {
295 | //the line below will force the browser to perform a repaint
296 | //so that all the animated elements within the animation frame
297 | //will be properly updated and drawn on screen. This is
298 | //required to perform multi-class CSS based animations with
299 | //Firefox. DO NOT REMOVE THIS LINE.
300 | var a = bod.offsetWidth + 1;
301 | fn();
302 | });
303 | };
304 | }])
305 |
306 | .config(['$provide', '$animateProvider', function($provide, $animateProvider) {
307 | var noop = angular.noop;
308 | var forEach = angular.forEach;
309 | var selectors = $animateProvider.$$selectors;
310 |
311 | var ELEMENT_NODE = 1;
312 | var NG_ANIMATE_STATE = '$$ngAnimateState';
313 | var NG_ANIMATE_CHILDREN = '$$ngAnimateChildren';
314 | var NG_ANIMATE_CLASS_NAME = 'ng-animate';
315 | var rootAnimateState = {running: true};
316 |
317 | function extractElementNode(element) {
318 | for(var i = 0; i < element.length; i++) {
319 | var elm = element[i];
320 | if(elm.nodeType == ELEMENT_NODE) {
321 | return elm;
322 | }
323 | }
324 | }
325 |
326 | function prepareElement(element) {
327 | return element && angular.element(element);
328 | }
329 |
330 | function stripCommentsFromElement(element) {
331 | return angular.element(extractElementNode(element));
332 | }
333 |
334 | function isMatchingElement(elm1, elm2) {
335 | return extractElementNode(elm1) == extractElementNode(elm2);
336 | }
337 |
338 | $provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement', '$$asyncCallback', '$rootScope', '$document',
339 | function($delegate, $injector, $sniffer, $rootElement, $$asyncCallback, $rootScope, $document) {
340 |
341 | var globalAnimationCounter = 0;
342 | $rootElement.data(NG_ANIMATE_STATE, rootAnimateState);
343 |
344 | // disable animations during bootstrap, but once we bootstrapped, wait again
345 | // for another digest until enabling animations. The reason why we digest twice
346 | // is because all structural animations (enter, leave and move) all perform a
347 | // post digest operation before animating. If we only wait for a single digest
348 | // to pass then the structural animation would render its animation on page load.
349 | // (which is what we're trying to avoid when the application first boots up.)
350 | $rootScope.$$postDigest(function() {
351 | $rootScope.$$postDigest(function() {
352 | rootAnimateState.running = false;
353 | });
354 | });
355 |
356 | var classNameFilter = $animateProvider.classNameFilter();
357 | var isAnimatableClassName = !classNameFilter
358 | ? function() { return true; }
359 | : function(className) {
360 | return classNameFilter.test(className);
361 | };
362 |
363 | function blockElementAnimations(element) {
364 | var data = element.data(NG_ANIMATE_STATE) || {};
365 | data.running = true;
366 | element.data(NG_ANIMATE_STATE, data);
367 | }
368 |
369 | function lookup(name) {
370 | if (name) {
371 | var matches = [],
372 | flagMap = {},
373 | classes = name.substr(1).split('.');
374 |
375 | //the empty string value is the default animation
376 | //operation which performs CSS transition and keyframe
377 | //animations sniffing. This is always included for each
378 | //element animation procedure if the browser supports
379 | //transitions and/or keyframe animations. The default
380 | //animation is added to the top of the list to prevent
381 | //any previous animations from affecting the element styling
382 | //prior to the element being animated.
383 | if ($sniffer.transitions || $sniffer.animations) {
384 | matches.push($injector.get(selectors['']));
385 | }
386 |
387 | for(var i=0; i < classes.length; i++) {
388 | var klass = classes[i],
389 | selectorFactoryName = selectors[klass];
390 | if(selectorFactoryName && !flagMap[klass]) {
391 | matches.push($injector.get(selectorFactoryName));
392 | flagMap[klass] = true;
393 | }
394 | }
395 | return matches;
396 | }
397 | }
398 |
399 | function animationRunner(element, animationEvent, className) {
400 | //transcluded directives may sometimes fire an animation using only comment nodes
401 | //best to catch this early on to prevent any animation operations from occurring
402 | var node = element[0];
403 | if(!node) {
404 | return;
405 | }
406 |
407 | var isSetClassOperation = animationEvent == 'setClass';
408 | var isClassBased = isSetClassOperation ||
409 | animationEvent == 'addClass' ||
410 | animationEvent == 'removeClass';
411 |
412 | var classNameAdd, classNameRemove;
413 | if(angular.isArray(className)) {
414 | classNameAdd = className[0];
415 | classNameRemove = className[1];
416 | className = classNameAdd + ' ' + classNameRemove;
417 | }
418 |
419 | var currentClassName = element.attr('class');
420 | var classes = currentClassName + ' ' + className;
421 | if(!isAnimatableClassName(classes)) {
422 | return;
423 | }
424 |
425 | var beforeComplete = noop,
426 | beforeCancel = [],
427 | before = [],
428 | afterComplete = noop,
429 | afterCancel = [],
430 | after = [];
431 |
432 | var animationLookup = (' ' + classes).replace(/\s+/g,'.');
433 | forEach(lookup(animationLookup), function(animationFactory) {
434 | var created = registerAnimation(animationFactory, animationEvent);
435 | if(!created && isSetClassOperation) {
436 | registerAnimation(animationFactory, 'addClass');
437 | registerAnimation(animationFactory, 'removeClass');
438 | }
439 | });
440 |
441 | function registerAnimation(animationFactory, event) {
442 | var afterFn = animationFactory[event];
443 | var beforeFn = animationFactory['before' + event.charAt(0).toUpperCase() + event.substr(1)];
444 | if(afterFn || beforeFn) {
445 | if(event == 'leave') {
446 | beforeFn = afterFn;
447 | //when set as null then animation knows to skip this phase
448 | afterFn = null;
449 | }
450 | after.push({
451 | event : event, fn : afterFn
452 | });
453 | before.push({
454 | event : event, fn : beforeFn
455 | });
456 | return true;
457 | }
458 | }
459 |
460 | function run(fns, cancellations, allCompleteFn) {
461 | var animations = [];
462 | forEach(fns, function(animation) {
463 | animation.fn && animations.push(animation);
464 | });
465 |
466 | var count = 0;
467 | function afterAnimationComplete(index) {
468 | if(cancellations) {
469 | (cancellations[index] || noop)();
470 | if(++count < animations.length) return;
471 | cancellations = null;
472 | }
473 | allCompleteFn();
474 | }
475 |
476 | //The code below adds directly to the array in order to work with
477 | //both sync and async animations. Sync animations are when the done()
478 | //operation is called right away. DO NOT REFACTOR!
479 | forEach(animations, function(animation, index) {
480 | var progress = function() {
481 | afterAnimationComplete(index);
482 | };
483 | switch(animation.event) {
484 | case 'setClass':
485 | cancellations.push(animation.fn(element, classNameAdd, classNameRemove, progress));
486 | break;
487 | case 'addClass':
488 | cancellations.push(animation.fn(element, classNameAdd || className, progress));
489 | break;
490 | case 'removeClass':
491 | cancellations.push(animation.fn(element, classNameRemove || className, progress));
492 | break;
493 | default:
494 | cancellations.push(animation.fn(element, progress));
495 | break;
496 | }
497 | });
498 |
499 | if(cancellations && cancellations.length === 0) {
500 | allCompleteFn();
501 | }
502 | }
503 |
504 | return {
505 | node : node,
506 | event : animationEvent,
507 | className : className,
508 | isClassBased : isClassBased,
509 | isSetClassOperation : isSetClassOperation,
510 | before : function(allCompleteFn) {
511 | beforeComplete = allCompleteFn;
512 | run(before, beforeCancel, function() {
513 | beforeComplete = noop;
514 | allCompleteFn();
515 | });
516 | },
517 | after : function(allCompleteFn) {
518 | afterComplete = allCompleteFn;
519 | run(after, afterCancel, function() {
520 | afterComplete = noop;
521 | allCompleteFn();
522 | });
523 | },
524 | cancel : function() {
525 | if(beforeCancel) {
526 | forEach(beforeCancel, function(cancelFn) {
527 | (cancelFn || noop)(true);
528 | });
529 | beforeComplete(true);
530 | }
531 | if(afterCancel) {
532 | forEach(afterCancel, function(cancelFn) {
533 | (cancelFn || noop)(true);
534 | });
535 | afterComplete(true);
536 | }
537 | }
538 | };
539 | }
540 |
541 | /**
542 | * @ngdoc service
543 | * @name $animate
544 | * @kind function
545 | *
546 | * @description
547 | * The `$animate` service provides animation detection support while performing DOM operations (enter, leave and move) as well as during addClass and removeClass operations.
548 | * When any of these operations are run, the $animate service
549 | * will examine any JavaScript-defined animations (which are defined by using the $animateProvider provider object)
550 | * as well as any CSS-defined animations against the CSS classes present on the element once the DOM operation is run.
551 | *
552 | * The `$animate` service is used behind the scenes with pre-existing directives and animation with these directives
553 | * will work out of the box without any extra configuration.
554 | *
555 | * Requires the {@link ngAnimate `ngAnimate`} module to be installed.
556 | *
557 | * Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
558 | *
559 | */
560 | return {
561 | /**
562 | * @ngdoc method
563 | * @name $animate#enter
564 | * @kind function
565 | *
566 | * @description
567 | * Appends the element to the parentElement element that resides in the document and then runs the enter animation. Once
568 | * the animation is started, the following CSS classes will be present on the element for the duration of the animation:
569 | *
570 | * Below is a breakdown of each step that occurs during enter animation:
571 | *
572 | * | Animation Step | What the element class attribute looks like |
573 | * |----------------------------------------------------------------------------------------------|---------------------------------------------|
574 | * | 1. $animate.enter(...) is called | class="my-animation" |
575 | * | 2. element is inserted into the parentElement element or beside the afterElement element | class="my-animation" |
576 | * | 3. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
577 | * | 4. the .ng-enter class is added to the element | class="my-animation ng-animate ng-enter" |
578 | * | 5. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate ng-enter" |
579 | * | 6. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate ng-enter" |
580 | * | 7. the .ng-enter-active and .ng-animate-active classes are added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-enter ng-enter-active" |
581 | * | 8. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active ng-enter ng-enter-active" |
582 | * | 9. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
583 | * | 10. The doneCallback() callback is fired (if provided) | class="my-animation" |
584 | *
585 | * @param {DOMElement} element the element that will be the focus of the enter animation
586 | * @param {DOMElement} parentElement the parent element of the element that will be the focus of the enter animation
587 | * @param {DOMElement} afterElement the sibling element (which is the previous element) of the element that will be the focus of the enter animation
588 | * @param {function()=} doneCallback the callback function that will be called once the animation is complete
589 | */
590 | enter : function(element, parentElement, afterElement, doneCallback) {
591 | element = angular.element(element);
592 | parentElement = prepareElement(parentElement);
593 | afterElement = prepareElement(afterElement);
594 |
595 | blockElementAnimations(element);
596 | $delegate.enter(element, parentElement, afterElement);
597 | $rootScope.$$postDigest(function() {
598 | element = stripCommentsFromElement(element);
599 | performAnimation('enter', 'ng-enter', element, parentElement, afterElement, noop, doneCallback);
600 | });
601 | },
602 |
603 | /**
604 | * @ngdoc method
605 | * @name $animate#leave
606 | * @kind function
607 | *
608 | * @description
609 | * Runs the leave animation operation and, upon completion, removes the element from the DOM. Once
610 | * the animation is started, the following CSS classes will be added for the duration of the animation:
611 | *
612 | * Below is a breakdown of each step that occurs during leave animation:
613 | *
614 | * | Animation Step | What the element class attribute looks like |
615 | * |----------------------------------------------------------------------------------------------|---------------------------------------------|
616 | * | 1. $animate.leave(...) is called | class="my-animation" |
617 | * | 2. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
618 | * | 3. the .ng-leave class is added to the element | class="my-animation ng-animate ng-leave" |
619 | * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate ng-leave" |
620 | * | 5. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate ng-leave" |
621 | * | 6. the .ng-leave-active and .ng-animate-active classes is added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-leave ng-leave-active" |
622 | * | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active ng-leave ng-leave-active" |
623 | * | 8. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
624 | * | 9. The element is removed from the DOM | ... |
625 | * | 10. The doneCallback() callback is fired (if provided) | ... |
626 | *
627 | * @param {DOMElement} element the element that will be the focus of the leave animation
628 | * @param {function()=} doneCallback the callback function that will be called once the animation is complete
629 | */
630 | leave : function(element, doneCallback) {
631 | element = angular.element(element);
632 | cancelChildAnimations(element);
633 | blockElementAnimations(element);
634 | $rootScope.$$postDigest(function() {
635 | performAnimation('leave', 'ng-leave', stripCommentsFromElement(element), null, null, function() {
636 | $delegate.leave(element);
637 | }, doneCallback);
638 | });
639 | },
640 |
641 | /**
642 | * @ngdoc method
643 | * @name $animate#move
644 | * @kind function
645 | *
646 | * @description
647 | * Fires the move DOM operation. Just before the animation starts, the animate service will either append it into the parentElement container or
648 | * add the element directly after the afterElement element if present. Then the move animation will be run. Once
649 | * the animation is started, the following CSS classes will be added for the duration of the animation:
650 | *
651 | * Below is a breakdown of each step that occurs during move animation:
652 | *
653 | * | Animation Step | What the element class attribute looks like |
654 | * |----------------------------------------------------------------------------------------------|---------------------------------------------|
655 | * | 1. $animate.move(...) is called | class="my-animation" |
656 | * | 2. element is moved into the parentElement element or beside the afterElement element | class="my-animation" |
657 | * | 3. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
658 | * | 4. the .ng-move class is added to the element | class="my-animation ng-animate ng-move" |
659 | * | 5. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate ng-move" |
660 | * | 6. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate ng-move" |
661 | * | 7. the .ng-move-active and .ng-animate-active classes is added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-move ng-move-active" |
662 | * | 8. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active ng-move ng-move-active" |
663 | * | 9. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
664 | * | 10. The doneCallback() callback is fired (if provided) | class="my-animation" |
665 | *
666 | * @param {DOMElement} element the element that will be the focus of the move animation
667 | * @param {DOMElement} parentElement the parentElement element of the element that will be the focus of the move animation
668 | * @param {DOMElement} afterElement the sibling element (which is the previous element) of the element that will be the focus of the move animation
669 | * @param {function()=} doneCallback the callback function that will be called once the animation is complete
670 | */
671 | move : function(element, parentElement, afterElement, doneCallback) {
672 | element = angular.element(element);
673 | parentElement = prepareElement(parentElement);
674 | afterElement = prepareElement(afterElement);
675 |
676 | cancelChildAnimations(element);
677 | blockElementAnimations(element);
678 | $delegate.move(element, parentElement, afterElement);
679 | $rootScope.$$postDigest(function() {
680 | element = stripCommentsFromElement(element);
681 | performAnimation('move', 'ng-move', element, parentElement, afterElement, noop, doneCallback);
682 | });
683 | },
684 |
685 | /**
686 | * @ngdoc method
687 | * @name $animate#addClass
688 | *
689 | * @description
690 | * Triggers a custom animation event based off the className variable and then attaches the className value to the element as a CSS class.
691 | * Unlike the other animation methods, the animate service will suffix the className value with {@type -add} in order to provide
692 | * the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if no CSS transitions
693 | * or keyframes are defined on the -add or base CSS class).
694 | *
695 | * Below is a breakdown of each step that occurs during addClass animation:
696 | *
697 | * | Animation Step | What the element class attribute looks like |
698 | * |------------------------------------------------------------------------------------------------|---------------------------------------------|
699 | * | 1. $animate.addClass(element, 'super') is called | class="my-animation" |
700 | * | 2. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
701 | * | 3. the .super-add class are added to the element | class="my-animation ng-animate super-add" |
702 | * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate super-add" |
703 | * | 5. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate super-add" |
704 | * | 6. the .super, .super-add-active and .ng-animate-active classes are added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active super super-add super-add-active" |
705 | * | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation super super-add super-add-active" |
706 | * | 8. The animation ends and all generated CSS classes are removed from the element | class="my-animation super" |
707 | * | 9. The super class is kept on the element | class="my-animation super" |
708 | * | 10. The doneCallback() callback is fired (if provided) | class="my-animation super" |
709 | *
710 | * @param {DOMElement} element the element that will be animated
711 | * @param {string} className the CSS class that will be added to the element and then animated
712 | * @param {function()=} doneCallback the callback function that will be called once the animation is complete
713 | */
714 | addClass : function(element, className, doneCallback) {
715 | element = angular.element(element);
716 | element = stripCommentsFromElement(element);
717 | performAnimation('addClass', className, element, null, null, function() {
718 | $delegate.addClass(element, className);
719 | }, doneCallback);
720 | },
721 |
722 | /**
723 | * @ngdoc method
724 | * @name $animate#removeClass
725 | *
726 | * @description
727 | * Triggers a custom animation event based off the className variable and then removes the CSS class provided by the className value
728 | * from the element. Unlike the other animation methods, the animate service will suffix the className value with {@type -remove} in
729 | * order to provide the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if
730 | * no CSS transitions or keyframes are defined on the -remove or base CSS classes).
731 | *
732 | * Below is a breakdown of each step that occurs during removeClass animation:
733 | *
734 | * | Animation Step | What the element class attribute looks like |
735 | * |-----------------------------------------------------------------------------------------------|---------------------------------------------|
736 | * | 1. $animate.removeClass(element, 'super') is called | class="my-animation super" |
737 | * | 2. $animate runs any JavaScript-defined animations on the element | class="my-animation super ng-animate" |
738 | * | 3. the .super-remove class are added to the element | class="my-animation super ng-animate super-remove"|
739 | * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation super ng-animate super-remove" |
740 | * | 5. $animate waits for 10ms (this performs a reflow) | class="my-animation super ng-animate super-remove" |
741 | * | 6. the .super-remove-active and .ng-animate-active classes are added and .super is removed (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active super-remove super-remove-active" |
742 | * | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active super-remove super-remove-active" |
743 | * | 8. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
744 | * | 9. The doneCallback() callback is fired (if provided) | class="my-animation" |
745 | *
746 | *
747 | * @param {DOMElement} element the element that will be animated
748 | * @param {string} className the CSS class that will be animated and then removed from the element
749 | * @param {function()=} doneCallback the callback function that will be called once the animation is complete
750 | */
751 | removeClass : function(element, className, doneCallback) {
752 | element = angular.element(element);
753 | element = stripCommentsFromElement(element);
754 | performAnimation('removeClass', className, element, null, null, function() {
755 | $delegate.removeClass(element, className);
756 | }, doneCallback);
757 | },
758 |
759 | /**
760 | *
761 | * @ngdoc function
762 | * @name $animate#setClass
763 | * @function
764 | * @description Adds and/or removes the given CSS classes to and from the element.
765 | * Once complete, the done() callback will be fired (if provided).
766 | * @param {DOMElement} element the element which will its CSS classes changed
767 | * removed from it
768 | * @param {string} add the CSS classes which will be added to the element
769 | * @param {string} remove the CSS class which will be removed from the element
770 | * @param {Function=} done the callback function (if provided) that will be fired after the
771 | * CSS classes have been set on the element
772 | */
773 | setClass : function(element, add, remove, doneCallback) {
774 | element = angular.element(element);
775 | element = stripCommentsFromElement(element);
776 | performAnimation('setClass', [add, remove], element, null, null, function() {
777 | $delegate.setClass(element, add, remove);
778 | }, doneCallback);
779 | },
780 |
781 | /**
782 | * @ngdoc method
783 | * @name $animate#enabled
784 | * @kind function
785 | *
786 | * @param {boolean=} value If provided then set the animation on or off.
787 | * @param {DOMElement=} element If provided then the element will be used to represent the enable/disable operation
788 | * @return {boolean} Current animation state.
789 | *
790 | * @description
791 | * Globally enables/disables animations.
792 | *
793 | */
794 | enabled : function(value, element) {
795 | switch(arguments.length) {
796 | case 2:
797 | if(value) {
798 | cleanup(element);
799 | } else {
800 | var data = element.data(NG_ANIMATE_STATE) || {};
801 | data.disabled = true;
802 | element.data(NG_ANIMATE_STATE, data);
803 | }
804 | break;
805 |
806 | case 1:
807 | rootAnimateState.disabled = !value;
808 | break;
809 |
810 | default:
811 | value = !rootAnimateState.disabled;
812 | break;
813 | }
814 | return !!value;
815 | }
816 | };
817 |
818 | /*
819 | all animations call this shared animation triggering function internally.
820 | The animationEvent variable refers to the JavaScript animation event that will be triggered
821 | and the className value is the name of the animation that will be applied within the
822 | CSS code. Element, parentElement and afterElement are provided DOM elements for the animation
823 | and the onComplete callback will be fired once the animation is fully complete.
824 | */
825 | function performAnimation(animationEvent, className, element, parentElement, afterElement, domOperation, doneCallback) {
826 |
827 | var runner = animationRunner(element, animationEvent, className);
828 | if(!runner) {
829 | fireDOMOperation();
830 | fireBeforeCallbackAsync();
831 | fireAfterCallbackAsync();
832 | closeAnimation();
833 | return;
834 | }
835 |
836 | className = runner.className;
837 | var elementEvents = angular.element._data(runner.node);
838 | elementEvents = elementEvents && elementEvents.events;
839 |
840 | if (!parentElement) {
841 | parentElement = afterElement ? afterElement.parent() : element.parent();
842 | }
843 |
844 | var ngAnimateState = element.data(NG_ANIMATE_STATE) || {};
845 | var runningAnimations = ngAnimateState.active || {};
846 | var totalActiveAnimations = ngAnimateState.totalActive || 0;
847 | var lastAnimation = ngAnimateState.last;
848 |
849 | //only allow animations if the currently running animation is not structural
850 | //or if there is no animation running at all
851 | var skipAnimations;
852 | if (runner.isClassBased) {
853 | skipAnimations = ngAnimateState.running ||
854 | ngAnimateState.disabled ||
855 | (lastAnimation && !lastAnimation.isClassBased);
856 | }
857 |
858 | //skip the animation if animations are disabled, a parent is already being animated,
859 | //the element is not currently attached to the document body or then completely close
860 | //the animation if any matching animations are not found at all.
861 | //NOTE: IE8 + IE9 should close properly (run closeAnimation()) in case an animation was found.
862 | if (skipAnimations || animationsDisabled(element, parentElement)) {
863 | fireDOMOperation();
864 | fireBeforeCallbackAsync();
865 | fireAfterCallbackAsync();
866 | closeAnimation();
867 | return;
868 | }
869 |
870 | var skipAnimation = false;
871 | if(totalActiveAnimations > 0) {
872 | var animationsToCancel = [];
873 | if(!runner.isClassBased) {
874 | if(animationEvent == 'leave' && runningAnimations['ng-leave']) {
875 | skipAnimation = true;
876 | } else {
877 | //cancel all animations when a structural animation takes place
878 | for(var klass in runningAnimations) {
879 | animationsToCancel.push(runningAnimations[klass]);
880 | cleanup(element, klass);
881 | }
882 | runningAnimations = {};
883 | totalActiveAnimations = 0;
884 | }
885 | } else if(lastAnimation.event == 'setClass') {
886 | animationsToCancel.push(lastAnimation);
887 | cleanup(element, className);
888 | }
889 | else if(runningAnimations[className]) {
890 | var current = runningAnimations[className];
891 | if(current.event == animationEvent) {
892 | skipAnimation = true;
893 | } else {
894 | animationsToCancel.push(current);
895 | cleanup(element, className);
896 | }
897 | }
898 |
899 | if(animationsToCancel.length > 0) {
900 | forEach(animationsToCancel, function(operation) {
901 | operation.cancel();
902 | });
903 | }
904 | }
905 |
906 | if(runner.isClassBased && !runner.isSetClassOperation && !skipAnimation) {
907 | skipAnimation = (animationEvent == 'addClass') == element.hasClass(className); //opposite of XOR
908 | }
909 |
910 | if(skipAnimation) {
911 | fireDOMOperation();
912 | fireBeforeCallbackAsync();
913 | fireAfterCallbackAsync();
914 | fireDoneCallbackAsync();
915 | return;
916 | }
917 |
918 | if(animationEvent == 'leave') {
919 | //there's no need to ever remove the listener since the element
920 | //will be removed (destroyed) after the leave animation ends or
921 | //is cancelled midway
922 | element.one('$destroy', function(e) {
923 | var element = angular.element(this);
924 | var state = element.data(NG_ANIMATE_STATE);
925 | if(state) {
926 | var activeLeaveAnimation = state.active['ng-leave'];
927 | if(activeLeaveAnimation) {
928 | activeLeaveAnimation.cancel();
929 | cleanup(element, 'ng-leave');
930 | }
931 | }
932 | });
933 | }
934 |
935 | //the ng-animate class does nothing, but it's here to allow for
936 | //parent animations to find and cancel child animations when needed
937 | element.addClass(NG_ANIMATE_CLASS_NAME);
938 |
939 | var localAnimationCount = globalAnimationCounter++;
940 | totalActiveAnimations++;
941 | runningAnimations[className] = runner;
942 |
943 | element.data(NG_ANIMATE_STATE, {
944 | last : runner,
945 | active : runningAnimations,
946 | index : localAnimationCount,
947 | totalActive : totalActiveAnimations
948 | });
949 |
950 | //first we run the before animations and when all of those are complete
951 | //then we perform the DOM operation and run the next set of animations
952 | fireBeforeCallbackAsync();
953 | runner.before(function(cancelled) {
954 | var data = element.data(NG_ANIMATE_STATE);
955 | cancelled = cancelled ||
956 | !data || !data.active[className] ||
957 | (runner.isClassBased && data.active[className].event != animationEvent);
958 |
959 | fireDOMOperation();
960 | if(cancelled === true) {
961 | closeAnimation();
962 | } else {
963 | fireAfterCallbackAsync();
964 | runner.after(closeAnimation);
965 | }
966 | });
967 |
968 | function fireDOMCallback(animationPhase) {
969 | var eventName = '$animate:' + animationPhase;
970 | if(elementEvents && elementEvents[eventName] && elementEvents[eventName].length > 0) {
971 | $$asyncCallback(function() {
972 | element.triggerHandler(eventName, {
973 | event : animationEvent,
974 | className : className
975 | });
976 | });
977 | }
978 | }
979 |
980 | function fireBeforeCallbackAsync() {
981 | fireDOMCallback('before');
982 | }
983 |
984 | function fireAfterCallbackAsync() {
985 | fireDOMCallback('after');
986 | }
987 |
988 | function fireDoneCallbackAsync() {
989 | fireDOMCallback('close');
990 | if(doneCallback) {
991 | $$asyncCallback(function() {
992 | doneCallback();
993 | });
994 | }
995 | }
996 |
997 | //it is less complicated to use a flag than managing and canceling
998 | //timeouts containing multiple callbacks.
999 | function fireDOMOperation() {
1000 | if(!fireDOMOperation.hasBeenRun) {
1001 | fireDOMOperation.hasBeenRun = true;
1002 | domOperation();
1003 | }
1004 | }
1005 |
1006 | function closeAnimation() {
1007 | if(!closeAnimation.hasBeenRun) {
1008 | closeAnimation.hasBeenRun = true;
1009 | var data = element.data(NG_ANIMATE_STATE);
1010 | if(data) {
1011 | /* only structural animations wait for reflow before removing an
1012 | animation, but class-based animations don't. An example of this
1013 | failing would be when a parent HTML tag has a ng-class attribute
1014 | causing ALL directives below to skip animations during the digest */
1015 | if(runner && runner.isClassBased) {
1016 | cleanup(element, className);
1017 | } else {
1018 | $$asyncCallback(function() {
1019 | var data = element.data(NG_ANIMATE_STATE) || {};
1020 | if(localAnimationCount == data.index) {
1021 | cleanup(element, className, animationEvent);
1022 | }
1023 | });
1024 | element.data(NG_ANIMATE_STATE, data);
1025 | }
1026 | }
1027 | fireDoneCallbackAsync();
1028 | }
1029 | }
1030 | }
1031 |
1032 | function cancelChildAnimations(element) {
1033 | var node = extractElementNode(element);
1034 | if (node) {
1035 | var nodes = angular.isFunction(node.getElementsByClassName) ?
1036 | node.getElementsByClassName(NG_ANIMATE_CLASS_NAME) :
1037 | node.querySelectorAll('.' + NG_ANIMATE_CLASS_NAME);
1038 | forEach(nodes, function(element) {
1039 | element = angular.element(element);
1040 | var data = element.data(NG_ANIMATE_STATE);
1041 | if(data && data.active) {
1042 | forEach(data.active, function(runner) {
1043 | runner.cancel();
1044 | });
1045 | }
1046 | });
1047 | }
1048 | }
1049 |
1050 | function cleanup(element, className) {
1051 | if(isMatchingElement(element, $rootElement)) {
1052 | if(!rootAnimateState.disabled) {
1053 | rootAnimateState.running = false;
1054 | rootAnimateState.structural = false;
1055 | }
1056 | } else if(className) {
1057 | var data = element.data(NG_ANIMATE_STATE) || {};
1058 |
1059 | var removeAnimations = className === true;
1060 | if(!removeAnimations && data.active && data.active[className]) {
1061 | data.totalActive--;
1062 | delete data.active[className];
1063 | }
1064 |
1065 | if(removeAnimations || !data.totalActive) {
1066 | element.removeClass(NG_ANIMATE_CLASS_NAME);
1067 | element.removeData(NG_ANIMATE_STATE);
1068 | }
1069 | }
1070 | }
1071 |
1072 | function animationsDisabled(element, parentElement) {
1073 | if (rootAnimateState.disabled) {
1074 | return true;
1075 | }
1076 |
1077 | if (isMatchingElement(element, $rootElement)) {
1078 | return rootAnimateState.running;
1079 | }
1080 |
1081 | var allowChildAnimations, parentRunningAnimation, hasParent;
1082 | do {
1083 | //the element did not reach the root element which means that it
1084 | //is not apart of the DOM. Therefore there is no reason to do
1085 | //any animations on it
1086 | if (parentElement.length === 0) break;
1087 |
1088 | var isRoot = isMatchingElement(parentElement, $rootElement);
1089 | var state = isRoot ? rootAnimateState : (parentElement.data(NG_ANIMATE_STATE) || {});
1090 | if (state.disabled) {
1091 | return true;
1092 | }
1093 |
1094 | //no matter what, for an animation to work it must reach the root element
1095 | //this implies that the element is attached to the DOM when the animation is run
1096 | if (isRoot) {
1097 | hasParent = true;
1098 | }
1099 |
1100 | //once a flag is found that is strictly false then everything before
1101 | //it will be discarded and all child animations will be restricted
1102 | if (allowChildAnimations !== false) {
1103 | var animateChildrenFlag = parentElement.data(NG_ANIMATE_CHILDREN);
1104 | if(angular.isDefined(animateChildrenFlag)) {
1105 | allowChildAnimations = animateChildrenFlag;
1106 | }
1107 | }
1108 |
1109 | parentRunningAnimation = parentRunningAnimation ||
1110 | state.running ||
1111 | (state.last && !state.last.isClassBased);
1112 | }
1113 | while(parentElement = parentElement.parent());
1114 |
1115 | return !hasParent || (!allowChildAnimations && parentRunningAnimation);
1116 | }
1117 | }]);
1118 |
1119 | $animateProvider.register('', ['$window', '$sniffer', '$timeout', '$$animateReflow',
1120 | function($window, $sniffer, $timeout, $$animateReflow) {
1121 | // Detect proper transitionend/animationend event names.
1122 | var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMATIONEND_EVENT;
1123 |
1124 | // If unprefixed events are not supported but webkit-prefixed are, use the latter.
1125 | // Otherwise, just use W3C names, browsers not supporting them at all will just ignore them.
1126 | // Note: Chrome implements `window.onwebkitanimationend` and doesn't implement `window.onanimationend`
1127 | // but at the same time dispatches the `animationend` event and not `webkitAnimationEnd`.
1128 | // Register both events in case `window.onanimationend` is not supported because of that,
1129 | // do the same for `transitionend` as Safari is likely to exhibit similar behavior.
1130 | // Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit
1131 | // therefore there is no reason to test anymore for other vendor prefixes: http://caniuse.com/#search=transition
1132 | if (window.ontransitionend === undefined && window.onwebkittransitionend !== undefined) {
1133 | CSS_PREFIX = '-webkit-';
1134 | TRANSITION_PROP = 'WebkitTransition';
1135 | TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
1136 | } else {
1137 | TRANSITION_PROP = 'transition';
1138 | TRANSITIONEND_EVENT = 'transitionend';
1139 | }
1140 |
1141 | if (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) {
1142 | CSS_PREFIX = '-webkit-';
1143 | ANIMATION_PROP = 'WebkitAnimation';
1144 | ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
1145 | } else {
1146 | ANIMATION_PROP = 'animation';
1147 | ANIMATIONEND_EVENT = 'animationend';
1148 | }
1149 |
1150 | var DURATION_KEY = 'Duration';
1151 | var PROPERTY_KEY = 'Property';
1152 | var DELAY_KEY = 'Delay';
1153 | var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount';
1154 | var NG_ANIMATE_PARENT_KEY = '$$ngAnimateKey';
1155 | var NG_ANIMATE_CSS_DATA_KEY = '$$ngAnimateCSS3Data';
1156 | var NG_ANIMATE_BLOCK_CLASS_NAME = 'ng-animate-block-transitions';
1157 | var ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
1158 | var CLOSING_TIME_BUFFER = 1.5;
1159 | var ONE_SECOND = 1000;
1160 |
1161 | var lookupCache = {};
1162 | var parentCounter = 0;
1163 | var animationReflowQueue = [];
1164 | var cancelAnimationReflow;
1165 | function afterReflow(element, callback) {
1166 | if(cancelAnimationReflow) {
1167 | cancelAnimationReflow();
1168 | }
1169 | animationReflowQueue.push(callback);
1170 | cancelAnimationReflow = $$animateReflow(function() {
1171 | forEach(animationReflowQueue, function(fn) {
1172 | fn();
1173 | });
1174 |
1175 | animationReflowQueue = [];
1176 | cancelAnimationReflow = null;
1177 | lookupCache = {};
1178 | });
1179 | }
1180 |
1181 | var closingTimer = null;
1182 | var closingTimestamp = 0;
1183 | var animationElementQueue = [];
1184 | function animationCloseHandler(element, totalTime) {
1185 | var node = extractElementNode(element);
1186 | element = angular.element(node);
1187 |
1188 | //this item will be garbage collected by the closing
1189 | //animation timeout
1190 | animationElementQueue.push(element);
1191 |
1192 | //but it may not need to cancel out the existing timeout
1193 | //if the timestamp is less than the previous one
1194 | var futureTimestamp = Date.now() + totalTime;
1195 | if(futureTimestamp <= closingTimestamp) {
1196 | return;
1197 | }
1198 |
1199 | $timeout.cancel(closingTimer);
1200 |
1201 | closingTimestamp = futureTimestamp;
1202 | closingTimer = $timeout(function() {
1203 | closeAllAnimations(animationElementQueue);
1204 | animationElementQueue = [];
1205 | }, totalTime, false);
1206 | }
1207 |
1208 | function closeAllAnimations(elements) {
1209 | forEach(elements, function(element) {
1210 | var elementData = element.data(NG_ANIMATE_CSS_DATA_KEY);
1211 | if(elementData) {
1212 | (elementData.closeAnimationFn || noop)();
1213 | }
1214 | });
1215 | }
1216 |
1217 | function getElementAnimationDetails(element, cacheKey) {
1218 | var data = cacheKey ? lookupCache[cacheKey] : null;
1219 | if(!data) {
1220 | var transitionDuration = 0;
1221 | var transitionDelay = 0;
1222 | var animationDuration = 0;
1223 | var animationDelay = 0;
1224 | var transitionDelayStyle;
1225 | var animationDelayStyle;
1226 | var transitionDurationStyle;
1227 | var transitionPropertyStyle;
1228 |
1229 | //we want all the styles defined before and after
1230 | forEach(element, function(element) {
1231 | if (element.nodeType == ELEMENT_NODE) {
1232 | var elementStyles = $window.getComputedStyle(element) || {};
1233 |
1234 | transitionDurationStyle = elementStyles[TRANSITION_PROP + DURATION_KEY];
1235 |
1236 | transitionDuration = Math.max(parseMaxTime(transitionDurationStyle), transitionDuration);
1237 |
1238 | transitionPropertyStyle = elementStyles[TRANSITION_PROP + PROPERTY_KEY];
1239 |
1240 | transitionDelayStyle = elementStyles[TRANSITION_PROP + DELAY_KEY];
1241 |
1242 | transitionDelay = Math.max(parseMaxTime(transitionDelayStyle), transitionDelay);
1243 |
1244 | animationDelayStyle = elementStyles[ANIMATION_PROP + DELAY_KEY];
1245 |
1246 | animationDelay = Math.max(parseMaxTime(animationDelayStyle), animationDelay);
1247 |
1248 | var aDuration = parseMaxTime(elementStyles[ANIMATION_PROP + DURATION_KEY]);
1249 |
1250 | if(aDuration > 0) {
1251 | aDuration *= parseInt(elementStyles[ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY], 10) || 1;
1252 | }
1253 |
1254 | animationDuration = Math.max(aDuration, animationDuration);
1255 | }
1256 | });
1257 | data = {
1258 | total : 0,
1259 | transitionPropertyStyle: transitionPropertyStyle,
1260 | transitionDurationStyle: transitionDurationStyle,
1261 | transitionDelayStyle: transitionDelayStyle,
1262 | transitionDelay: transitionDelay,
1263 | transitionDuration: transitionDuration,
1264 | animationDelayStyle: animationDelayStyle,
1265 | animationDelay: animationDelay,
1266 | animationDuration: animationDuration
1267 | };
1268 | if(cacheKey) {
1269 | lookupCache[cacheKey] = data;
1270 | }
1271 | }
1272 | return data;
1273 | }
1274 |
1275 | function parseMaxTime(str) {
1276 | var maxValue = 0;
1277 | var values = angular.isString(str) ?
1278 | str.split(/\s*,\s*/) :
1279 | [];
1280 | forEach(values, function(value) {
1281 | maxValue = Math.max(parseFloat(value) || 0, maxValue);
1282 | });
1283 | return maxValue;
1284 | }
1285 |
1286 | function getCacheKey(element) {
1287 | var parentElement = element.parent();
1288 | var parentID = parentElement.data(NG_ANIMATE_PARENT_KEY);
1289 | if(!parentID) {
1290 | parentElement.data(NG_ANIMATE_PARENT_KEY, ++parentCounter);
1291 | parentID = parentCounter;
1292 | }
1293 | return parentID + '-' + extractElementNode(element).getAttribute('class');
1294 | }
1295 |
1296 | function animateSetup(animationEvent, element, className, calculationDecorator) {
1297 | var cacheKey = getCacheKey(element);
1298 | var eventCacheKey = cacheKey + ' ' + className;
1299 | var itemIndex = lookupCache[eventCacheKey] ? ++lookupCache[eventCacheKey].total : 0;
1300 |
1301 | var stagger = {};
1302 | if(itemIndex > 0) {
1303 | var staggerClassName = className + '-stagger';
1304 | var staggerCacheKey = cacheKey + ' ' + staggerClassName;
1305 | var applyClasses = !lookupCache[staggerCacheKey];
1306 |
1307 | applyClasses && element.addClass(staggerClassName);
1308 |
1309 | stagger = getElementAnimationDetails(element, staggerCacheKey);
1310 |
1311 | applyClasses && element.removeClass(staggerClassName);
1312 | }
1313 |
1314 | /* the animation itself may need to add/remove special CSS classes
1315 | * before calculating the anmation styles */
1316 | calculationDecorator = calculationDecorator ||
1317 | function(fn) { return fn(); };
1318 |
1319 | element.addClass(className);
1320 |
1321 | var formerData = element.data(NG_ANIMATE_CSS_DATA_KEY) || {};
1322 |
1323 | var timings = calculationDecorator(function() {
1324 | return getElementAnimationDetails(element, eventCacheKey);
1325 | });
1326 |
1327 | var transitionDuration = timings.transitionDuration;
1328 | var animationDuration = timings.animationDuration;
1329 | if(transitionDuration === 0 && animationDuration === 0) {
1330 | element.removeClass(className);
1331 | return false;
1332 | }
1333 |
1334 | element.data(NG_ANIMATE_CSS_DATA_KEY, {
1335 | running : formerData.running || 0,
1336 | itemIndex : itemIndex,
1337 | stagger : stagger,
1338 | timings : timings,
1339 | closeAnimationFn : noop
1340 | });
1341 |
1342 | //temporarily disable the transition so that the enter styles
1343 | //don't animate twice (this is here to avoid a bug in Chrome/FF).
1344 | var isCurrentlyAnimating = formerData.running > 0 || animationEvent == 'setClass';
1345 | if(transitionDuration > 0) {
1346 | blockTransitions(element, className, isCurrentlyAnimating);
1347 | }
1348 |
1349 | //staggering keyframe animations work by adjusting the `animation-delay` CSS property
1350 | //on the given element, however, the delay value can only calculated after the reflow
1351 | //since by that time $animate knows how many elements are being animated. Therefore,
1352 | //until the reflow occurs the element needs to be blocked (where the keyframe animation
1353 | //is set to `none 0s`). This blocking mechanism should only be set for when a stagger
1354 | //animation is detected and when the element item index is greater than 0.
1355 | if(animationDuration > 0 && stagger.animationDelay > 0 && stagger.animationDuration === 0) {
1356 | blockKeyframeAnimations(element);
1357 | }
1358 |
1359 | return true;
1360 | }
1361 |
1362 | function isStructuralAnimation(className) {
1363 | return className == 'ng-enter' || className == 'ng-move' || className == 'ng-leave';
1364 | }
1365 |
1366 | function blockTransitions(element, className, isAnimating) {
1367 | if(isStructuralAnimation(className) || !isAnimating) {
1368 | extractElementNode(element).style[TRANSITION_PROP + PROPERTY_KEY] = 'none';
1369 | } else {
1370 | element.addClass(NG_ANIMATE_BLOCK_CLASS_NAME);
1371 | }
1372 | }
1373 |
1374 | function blockKeyframeAnimations(element) {
1375 | extractElementNode(element).style[ANIMATION_PROP] = 'none 0s';
1376 | }
1377 |
1378 | function unblockTransitions(element, className) {
1379 | var prop = TRANSITION_PROP + PROPERTY_KEY;
1380 | var node = extractElementNode(element);
1381 | if(node.style[prop] && node.style[prop].length > 0) {
1382 | node.style[prop] = '';
1383 | }
1384 | element.removeClass(NG_ANIMATE_BLOCK_CLASS_NAME);
1385 | }
1386 |
1387 | function unblockKeyframeAnimations(element) {
1388 | var prop = ANIMATION_PROP;
1389 | var node = extractElementNode(element);
1390 | if(node.style[prop] && node.style[prop].length > 0) {
1391 | node.style[prop] = '';
1392 | }
1393 | }
1394 |
1395 | function animateRun(animationEvent, element, className, activeAnimationComplete) {
1396 | var node = extractElementNode(element);
1397 | var elementData = element.data(NG_ANIMATE_CSS_DATA_KEY);
1398 | if(node.getAttribute('class').indexOf(className) == -1 || !elementData) {
1399 | activeAnimationComplete();
1400 | return;
1401 | }
1402 |
1403 | var activeClassName = '';
1404 | forEach(className.split(' '), function(klass, i) {
1405 | activeClassName += (i > 0 ? ' ' : '') + klass + '-active';
1406 | });
1407 |
1408 | var stagger = elementData.stagger;
1409 | var timings = elementData.timings;
1410 | var itemIndex = elementData.itemIndex;
1411 | var maxDuration = Math.max(timings.transitionDuration, timings.animationDuration);
1412 | var maxDelay = Math.max(timings.transitionDelay, timings.animationDelay);
1413 | var maxDelayTime = maxDelay * ONE_SECOND;
1414 |
1415 | var startTime = Date.now();
1416 | var css3AnimationEvents = ANIMATIONEND_EVENT + ' ' + TRANSITIONEND_EVENT;
1417 |
1418 | var style = '', appliedStyles = [];
1419 | if(timings.transitionDuration > 0) {
1420 | var propertyStyle = timings.transitionPropertyStyle;
1421 | if(propertyStyle.indexOf('all') == -1) {
1422 | style += CSS_PREFIX + 'transition-property: ' + propertyStyle + ';';
1423 | style += CSS_PREFIX + 'transition-duration: ' + timings.transitionDurationStyle + ';';
1424 | appliedStyles.push(CSS_PREFIX + 'transition-property');
1425 | appliedStyles.push(CSS_PREFIX + 'transition-duration');
1426 | }
1427 | }
1428 |
1429 | if(itemIndex > 0) {
1430 | if(stagger.transitionDelay > 0 && stagger.transitionDuration === 0) {
1431 | var delayStyle = timings.transitionDelayStyle;
1432 | style += CSS_PREFIX + 'transition-delay: ' +
1433 | prepareStaggerDelay(delayStyle, stagger.transitionDelay, itemIndex) + '; ';
1434 | appliedStyles.push(CSS_PREFIX + 'transition-delay');
1435 | }
1436 |
1437 | if(stagger.animationDelay > 0 && stagger.animationDuration === 0) {
1438 | style += CSS_PREFIX + 'animation-delay: ' +
1439 | prepareStaggerDelay(timings.animationDelayStyle, stagger.animationDelay, itemIndex) + '; ';
1440 | appliedStyles.push(CSS_PREFIX + 'animation-delay');
1441 | }
1442 | }
1443 |
1444 | if(appliedStyles.length > 0) {
1445 | //the element being animated may sometimes contain comment nodes in
1446 | //the jqLite object, so we're safe to use a single variable to house
1447 | //the styles since there is always only one element being animated
1448 | var oldStyle = node.getAttribute('style') || '';
1449 | node.setAttribute('style', oldStyle + '; ' + style);
1450 | }
1451 |
1452 | element.on(css3AnimationEvents, onAnimationProgress);
1453 | element.addClass(activeClassName);
1454 | elementData.closeAnimationFn = function() {
1455 | onEnd();
1456 | activeAnimationComplete();
1457 | };
1458 |
1459 | var staggerTime = itemIndex * (Math.max(stagger.animationDelay, stagger.transitionDelay) || 0);
1460 | var animationTime = (maxDelay + maxDuration) * CLOSING_TIME_BUFFER;
1461 | var totalTime = (staggerTime + animationTime) * ONE_SECOND;
1462 |
1463 | elementData.running++;
1464 | animationCloseHandler(element, totalTime);
1465 | return onEnd;
1466 |
1467 | // This will automatically be called by $animate so
1468 | // there is no need to attach this internally to the
1469 | // timeout done method.
1470 | function onEnd(cancelled) {
1471 | element.off(css3AnimationEvents, onAnimationProgress);
1472 | element.removeClass(activeClassName);
1473 | animateClose(element, className);
1474 | var node = extractElementNode(element);
1475 | for (var i in appliedStyles) {
1476 | node.style.removeProperty(appliedStyles[i]);
1477 | }
1478 | }
1479 |
1480 | function onAnimationProgress(event) {
1481 | event.stopPropagation();
1482 | var ev = event.originalEvent || event;
1483 | var timeStamp = ev.$manualTimeStamp || ev.timeStamp || Date.now();
1484 |
1485 | /* Firefox (or possibly just Gecko) likes to not round values up
1486 | * when a ms measurement is used for the animation */
1487 | var elapsedTime = parseFloat(ev.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES));
1488 |
1489 | /* $manualTimeStamp is a mocked timeStamp value which is set
1490 | * within browserTrigger(). This is only here so that tests can
1491 | * mock animations properly. Real events fallback to event.timeStamp,
1492 | * or, if they don't, then a timeStamp is automatically created for them.
1493 | * We're checking to see if the timeStamp surpasses the expected delay,
1494 | * but we're using elapsedTime instead of the timeStamp on the 2nd
1495 | * pre-condition since animations sometimes close off early */
1496 | if(Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
1497 | activeAnimationComplete();
1498 | }
1499 | }
1500 | }
1501 |
1502 | function prepareStaggerDelay(delayStyle, staggerDelay, index) {
1503 | var style = '';
1504 | forEach(delayStyle.split(','), function(val, i) {
1505 | style += (i > 0 ? ',' : '') +
1506 | (index * staggerDelay + parseInt(val, 10)) + 's';
1507 | });
1508 | return style;
1509 | }
1510 |
1511 | function animateBefore(animationEvent, element, className, calculationDecorator) {
1512 | if(animateSetup(animationEvent, element, className, calculationDecorator)) {
1513 | return function(cancelled) {
1514 | cancelled && animateClose(element, className);
1515 | };
1516 | }
1517 | }
1518 |
1519 | function animateAfter(animationEvent, element, className, afterAnimationComplete) {
1520 | if(element.data(NG_ANIMATE_CSS_DATA_KEY)) {
1521 | return animateRun(animationEvent, element, className, afterAnimationComplete);
1522 | } else {
1523 | animateClose(element, className);
1524 | afterAnimationComplete();
1525 | }
1526 | }
1527 |
1528 | function animate(animationEvent, element, className, animationComplete) {
1529 | //If the animateSetup function doesn't bother returning a
1530 | //cancellation function then it means that there is no animation
1531 | //to perform at all
1532 | var preReflowCancellation = animateBefore(animationEvent, element, className);
1533 | if(!preReflowCancellation) {
1534 | animationComplete();
1535 | return;
1536 | }
1537 |
1538 | //There are two cancellation functions: one is before the first
1539 | //reflow animation and the second is during the active state
1540 | //animation. The first function will take care of removing the
1541 | //data from the element which will not make the 2nd animation
1542 | //happen in the first place
1543 | var cancel = preReflowCancellation;
1544 | afterReflow(element, function() {
1545 | unblockTransitions(element, className);
1546 | unblockKeyframeAnimations(element);
1547 | //once the reflow is complete then we point cancel to
1548 | //the new cancellation function which will remove all of the
1549 | //animation properties from the active animation
1550 | cancel = animateAfter(animationEvent, element, className, animationComplete);
1551 | });
1552 |
1553 | return function(cancelled) {
1554 | (cancel || noop)(cancelled);
1555 | };
1556 | }
1557 |
1558 | function animateClose(element, className) {
1559 | element.removeClass(className);
1560 | var data = element.data(NG_ANIMATE_CSS_DATA_KEY);
1561 | if(data) {
1562 | if(data.running) {
1563 | data.running--;
1564 | }
1565 | if(!data.running || data.running === 0) {
1566 | element.removeData(NG_ANIMATE_CSS_DATA_KEY);
1567 | }
1568 | }
1569 | }
1570 |
1571 | return {
1572 | enter : function(element, animationCompleted) {
1573 | return animate('enter', element, 'ng-enter', animationCompleted);
1574 | },
1575 |
1576 | leave : function(element, animationCompleted) {
1577 | return animate('leave', element, 'ng-leave', animationCompleted);
1578 | },
1579 |
1580 | move : function(element, animationCompleted) {
1581 | return animate('move', element, 'ng-move', animationCompleted);
1582 | },
1583 |
1584 | beforeSetClass : function(element, add, remove, animationCompleted) {
1585 | var className = suffixClasses(remove, '-remove') + ' ' +
1586 | suffixClasses(add, '-add');
1587 | var cancellationMethod = animateBefore('setClass', element, className, function(fn) {
1588 | /* when classes are removed from an element then the transition style
1589 | * that is applied is the transition defined on the element without the
1590 | * CSS class being there. This is how CSS3 functions outside of ngAnimate.
1591 | * http://plnkr.co/edit/j8OzgTNxHTb4n3zLyjGW?p=preview */
1592 | var klass = element.attr('class');
1593 | element.removeClass(remove);
1594 | element.addClass(add);
1595 | var timings = fn();
1596 | element.attr('class', klass);
1597 | return timings;
1598 | });
1599 |
1600 | if(cancellationMethod) {
1601 | afterReflow(element, function() {
1602 | unblockTransitions(element, className);
1603 | unblockKeyframeAnimations(element);
1604 | animationCompleted();
1605 | });
1606 | return cancellationMethod;
1607 | }
1608 | animationCompleted();
1609 | },
1610 |
1611 | beforeAddClass : function(element, className, animationCompleted) {
1612 | var cancellationMethod = animateBefore('addClass', element, suffixClasses(className, '-add'), function(fn) {
1613 |
1614 | /* when a CSS class is added to an element then the transition style that
1615 | * is applied is the transition defined on the element when the CSS class
1616 | * is added at the time of the animation. This is how CSS3 functions
1617 | * outside of ngAnimate. */
1618 | element.addClass(className);
1619 | var timings = fn();
1620 | element.removeClass(className);
1621 | return timings;
1622 | });
1623 |
1624 | if(cancellationMethod) {
1625 | afterReflow(element, function() {
1626 | unblockTransitions(element, className);
1627 | unblockKeyframeAnimations(element);
1628 | animationCompleted();
1629 | });
1630 | return cancellationMethod;
1631 | }
1632 | animationCompleted();
1633 | },
1634 |
1635 | setClass : function(element, add, remove, animationCompleted) {
1636 | remove = suffixClasses(remove, '-remove');
1637 | add = suffixClasses(add, '-add');
1638 | var className = remove + ' ' + add;
1639 | return animateAfter('setClass', element, className, animationCompleted);
1640 | },
1641 |
1642 | addClass : function(element, className, animationCompleted) {
1643 | return animateAfter('addClass', element, suffixClasses(className, '-add'), animationCompleted);
1644 | },
1645 |
1646 | beforeRemoveClass : function(element, className, animationCompleted) {
1647 | var cancellationMethod = animateBefore('removeClass', element, suffixClasses(className, '-remove'), function(fn) {
1648 | /* when classes are removed from an element then the transition style
1649 | * that is applied is the transition defined on the element without the
1650 | * CSS class being there. This is how CSS3 functions outside of ngAnimate.
1651 | * http://plnkr.co/edit/j8OzgTNxHTb4n3zLyjGW?p=preview */
1652 | var klass = element.attr('class');
1653 | element.removeClass(className);
1654 | var timings = fn();
1655 | element.attr('class', klass);
1656 | return timings;
1657 | });
1658 |
1659 | if(cancellationMethod) {
1660 | afterReflow(element, function() {
1661 | unblockTransitions(element, className);
1662 | unblockKeyframeAnimations(element);
1663 | animationCompleted();
1664 | });
1665 | return cancellationMethod;
1666 | }
1667 | animationCompleted();
1668 | },
1669 |
1670 | removeClass : function(element, className, animationCompleted) {
1671 | return animateAfter('removeClass', element, suffixClasses(className, '-remove'), animationCompleted);
1672 | }
1673 | };
1674 |
1675 | function suffixClasses(classes, suffix) {
1676 | var className = '';
1677 | classes = angular.isArray(classes) ? classes : classes.split(/\s+/);
1678 | forEach(classes, function(klass, i) {
1679 | if(klass && klass.length > 0) {
1680 | className += (i > 0 ? ' ' : '') + klass + suffix;
1681 | }
1682 | });
1683 | return className;
1684 | }
1685 | }]);
1686 | }]);
1687 |
1688 |
1689 | })(window, window.angular);
1690 |
--------------------------------------------------------------------------------
/src/Scripts/angular-route.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @license AngularJS v1.2.26
3 | * (c) 2010-2014 Google, Inc. http://angularjs.org
4 | * License: MIT
5 | */
6 | (function(window, angular, undefined) {'use strict';
7 |
8 | /**
9 | * @ngdoc module
10 | * @name ngRoute
11 | * @description
12 | *
13 | * # ngRoute
14 | *
15 | * The `ngRoute` module provides routing and deeplinking services and directives for angular apps.
16 | *
17 | * ## Example
18 | * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`.
19 | *
20 | *
21 | *
22 | */
23 | /* global -ngRouteModule */
24 | var ngRouteModule = angular.module('ngRoute', ['ng']).
25 | provider('$route', $RouteProvider);
26 |
27 | /**
28 | * @ngdoc provider
29 | * @name $routeProvider
30 | * @kind function
31 | *
32 | * @description
33 | *
34 | * Used for configuring routes.
35 | *
36 | * ## Example
37 | * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`.
38 | *
39 | * ## Dependencies
40 | * Requires the {@link ngRoute `ngRoute`} module to be installed.
41 | */
42 | function $RouteProvider(){
43 | function inherit(parent, extra) {
44 | return angular.extend(new (angular.extend(function() {}, {prototype:parent}))(), extra);
45 | }
46 |
47 | var routes = {};
48 |
49 | /**
50 | * @ngdoc method
51 | * @name $routeProvider#when
52 | *
53 | * @param {string} path Route path (matched against `$location.path`). If `$location.path`
54 | * contains redundant trailing slash or is missing one, the route will still match and the
55 | * `$location.path` will be updated to add or drop the trailing slash to exactly match the
56 | * route definition.
57 | *
58 | * * `path` can contain named groups starting with a colon: e.g. `:name`. All characters up
59 | * to the next slash are matched and stored in `$routeParams` under the given `name`
60 | * when the route matches.
61 | * * `path` can contain named groups starting with a colon and ending with a star:
62 | * e.g.`:name*`. All characters are eagerly stored in `$routeParams` under the given `name`
63 | * when the route matches.
64 | * * `path` can contain optional named groups with a question mark: e.g.`:name?`.
65 | *
66 | * For example, routes like `/color/:color/largecode/:largecode*\/edit` will match
67 | * `/color/brown/largecode/code/with/slashes/edit` and extract:
68 | *
69 | * * `color: brown`
70 | * * `largecode: code/with/slashes`.
71 | *
72 | *
73 | * @param {Object} route Mapping information to be assigned to `$route.current` on route
74 | * match.
75 | *
76 | * Object properties:
77 | *
78 | * - `controller` – `{(string|function()=}` – Controller fn that should be associated with
79 | * newly created scope or the name of a {@link angular.Module#controller registered
80 | * controller} if passed as a string.
81 | * - `controllerAs` – `{string=}` – A controller alias name. If present the controller will be
82 | * published to scope under the `controllerAs` name.
83 | * - `template` – `{string=|function()=}` – html template as a string or a function that
84 | * returns an html template as a string which should be used by {@link
85 | * ngRoute.directive:ngView ngView} or {@link ng.directive:ngInclude ngInclude} directives.
86 | * This property takes precedence over `templateUrl`.
87 | *
88 | * If `template` is a function, it will be called with the following parameters:
89 | *
90 | * - `{Array.