Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
feature(macModal): Use $animate to show and hide mac-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlee44 committed Nov 13, 2013
1 parent 771ddcb commit 6a7373d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
10 changes: 8 additions & 2 deletions src/css/modal.styl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
bottom 0
opacity 0
visibility hidden
transition all 0.2s ease-out
overflow-y auto
z-index 3

&.visible
&.visible, &.visible-add-active
visibility visible
opacity 1.0

.modal
top 50%

&.visible-add, &.visible-remove
transition 0.2s ease-out all

&.visible-remove-active
visibility hidden
opacity 0

.modal
position absolute
top 0
Expand Down
27 changes: 11 additions & 16 deletions src/services/modal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ There are multiple components used by modal.
angular.module("Mac").service("modal", [
"$rootScope"
"$animate"
"$timeout"
"$templateCache"
"$compile"
"$http"
"$controller"
"modalViews"
"keys"
($rootScope, $animate, $timeout, $templateCache, $compile, $http, $controller, modalViews, keys) ->
($rootScope, $animate, $templateCache, $compile, $http, $controller, modalViews, keys) ->
# Dictionary of registered modal
registered: modalViews.registered

Expand Down Expand Up @@ -74,18 +73,18 @@ angular.module("Mac").service("modal", [
angular.extend options, triggerOptions

showModal = (element) =>
$animate.removeClass element, "hide", ->
$animate.addClass element, "visible"
$animate.removeClass element, "hide", =>
$animate.addClass element, "visible", =>

# Update opened modal object
@opened = {id, element, options}
@resize @opened
@bindingEvents()
# Update opened modal object
@opened = {id, element, options}
@resize @opened
@bindingEvents()

options.callback?()
options.callback?()

$rootScope.$broadcast "modalWasShown", id
@clearWaiting()
$rootScope.$broadcast "modalWasShown", id
@clearWaiting()

# if modal is created thru module method "modal"
if options.moduleMethod?
Expand Down Expand Up @@ -172,10 +171,7 @@ angular.module("Mac").service("modal", [

{id, options, element} = @opened

$animate.removeClass element, "visible"

# 250ms timeout is added to account for the hide modal animation
$timeout =>
$animate.removeClass element, "visible", =>
@bindingEvents "unbind"
@opened = null

Expand All @@ -188,7 +184,6 @@ angular.module("Mac").service("modal", [
$rootScope.$broadcast "modalWasHidden", id

callback && callback()
, 250

bindingEvents: (action = "bind") ->
return unless action in ["bind", "unbind"] and @opened?
Expand Down
9 changes: 7 additions & 2 deletions test/unit/modal.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe "Mac modal", ->

modal.register "test-modal", element, {}, angular.noop
modal.show "test-modal"
$timeout.flush()

modalElement = $(".modal", element)
expect(modalElement.attr("style")).toBeDefined()
Expand Down Expand Up @@ -156,6 +157,7 @@ describe "Mac modal", ->
$rootScope.$digest()

element.click()
$timeout.flush()
expect(modal.opened.id).toBe "test-modal"

it "should bind data to opened modal", ->
Expand All @@ -166,6 +168,7 @@ describe "Mac modal", ->
$rootScope.$digest()

element.click()
$timeout.flush()
expect(modal.opened.options.data.text).toBe "hello"

describe "modal method", ->
Expand Down Expand Up @@ -216,7 +219,9 @@ describe "Mac modal", ->
modal.show "testing"
$timeout.flush()

modal.hide()
callback = jasmine.createSpy "select"

modal.hide(callback)
$timeout.flush()

expect(angular.element(".modal-content-wrapper").length).toBe 0
expect(callback).toHaveBeenCalled()

0 comments on commit 6a7373d

Please sign in to comment.