Created
June 28, 2013 19:50
-
-
Save marshall007/5887542 to your computer and use it in GitHub Desktop.
AngularJS loading indicator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ACTIVE_CLASS = 'active' | |
| ERROR_CLASS = 'ng-error' | |
| SUCCESS_CLASS = 'ng-ok' | |
| angular.module('app') | |
| .config([ '$httpProvider', ($httpProvider) -> | |
| $el = angular.element document.getElementById 'loading' | |
| $httpProvider.responseInterceptors.push 'LoadingIndicator' | |
| $httpProvider.defaults.transformRequest.push (data, headersGetter) -> | |
| $el.removeClass "#{SUCCESS_CLASS} #{ERROR_CLASS}" | |
| $el.addClass ACTIVE_CLASS | |
| return data | |
| ]) | |
| .factory 'LoadingIndicator', [ '$q', ($q) -> | |
| $el = angular.element document.getElementById 'loading' | |
| return (promise) -> | |
| promise.then (response) -> | |
| $el.addClass SUCCESS_CLASS | |
| $el.removeClass ACTIVE_CLASS | |
| return response | |
| , (response) -> | |
| $el.addClass ERROR_CLASS | |
| $el.removeClass ACTIVE_CLASS | |
| return $q.reject response | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $base3 = #fdf6e3 | |
| $yellow = #b58900 | |
| $red = #dc322f | |
| $green = #859900 | |
| #loading | |
| background $yellow | |
| color $base3 | |
| font-weight bold | |
| left 50% | |
| line-height 22px | |
| margin-left 30px | |
| position fixed | |
| text-align center | |
| top -22px | |
| width 100px | |
| transition-property top | |
| transition-delay .5s | |
| transition-duration .5s | |
| &.active | |
| top 0px | |
| transition-delay 0s | |
| &.ng-error | |
| background $red | |
| &.ng-ok | |
| background $green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment