22 * angular-mm-foundation
33 * http://pineconellc.github.io/angular-foundation/
44
5- * Version: 0.7 .0 - 2015-09-25
5+ * Version: 0.8 .0 - 2015-10-13
66 * License: MIT
77 * (c) Pinecone, LLC
88 */
@@ -439,6 +439,8 @@ angular.module('mm.foundation.dropdownToggle', [ 'mm.foundation.position', 'mm.f
439439
440440 if ( ! elementWasOpen && ! element . hasClass ( 'disabled' ) && ! element . prop ( 'disabled' ) ) {
441441 dropdown . css ( 'display' , 'block' ) ; // We display the element so that offsetParent is populated
442+ dropdown . addClass ( 'f-open-dropdown' ) ;
443+
442444 var offset = $position . offset ( element ) ;
443445 var parentOffset = $position . offset ( angular . element ( dropdown [ 0 ] . offsetParent ) ) ;
444446 var dropdownWidth = dropdown . prop ( 'offsetWidth' ) ;
@@ -476,6 +478,7 @@ angular.module('mm.foundation.dropdownToggle', [ 'mm.foundation.position', 'mm.f
476478 closeMenu = function ( event ) {
477479 $document . off ( 'click' , closeMenu ) ;
478480 dropdown . css ( 'display' , 'none' ) ;
481+ dropdown . removeClass ( 'f-open-dropdown' ) ;
479482 element . removeClass ( 'expanded' ) ;
480483 closeMenu = angular . noop ;
481484 openElement = null ;
@@ -985,7 +988,7 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
985988
986989 var OPENED_MODAL_CLASS = 'modal-open' ;
987990
988- var backdropDomEl , backdropScope ;
991+ var backdropDomEl , backdropScope , cssTop ;
989992 var openedWindows = $$stackedMap . createNew ( ) ;
990993 var $modalStack = { } ;
991994
@@ -1007,7 +1010,7 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
10071010 } ) ;
10081011
10091012 function removeModalWindow ( modalInstance ) {
1010- var body = $document . find ( 'body' ) . eq ( 0 ) ;
1013+ var parent = $document . find ( modalInstance . options . parent ) . eq ( 0 ) ;
10111014 var modalWindow = openedWindows . get ( modalInstance ) . value ;
10121015
10131016 //clean up the stack
@@ -1016,7 +1019,7 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
10161019 //remove window DOM element
10171020 removeAfterAnimate ( modalWindow . modalDomEl , modalWindow . modalScope , 300 , function ( ) {
10181021 modalWindow . modalScope . $destroy ( ) ;
1019- body . toggleClass ( OPENED_MODAL_CLASS , openedWindows . length ( ) > 0 ) ;
1022+ parent . toggleClass ( OPENED_MODAL_CLASS , openedWindows . length ( ) > 0 ) ;
10201023 checkRemoveBackdrop ( ) ;
10211024 } ) ;
10221025 }
@@ -1066,6 +1069,14 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
10661069 }
10671070 }
10681071
1072+ function calculateModalTop ( modalElement , offset ) {
1073+ if ( angular . isUndefined ( offset ) ) {
1074+ offset = 0 ;
1075+ }
1076+ var scrollY = $window . pageYOffset || 0 ;
1077+ return offset + scrollY ;
1078+ }
1079+
10691080 $document . bind ( 'keydown' , function ( evt ) {
10701081 var modal ;
10711082
@@ -1080,35 +1091,33 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
10801091 } ) ;
10811092
10821093 $modalStack . open = function ( modalInstance , modal ) {
1083-
1084- openedWindows . add ( modalInstance , {
1094+ modalInstance . options = {
10851095 deferred : modal . deferred ,
10861096 modalScope : modal . scope ,
10871097 backdrop : modal . backdrop ,
1088- keyboard : modal . keyboard
1089- } ) ;
1098+ keyboard : modal . keyboard ,
1099+ parent : modal . parent
1100+ } ;
1101+ openedWindows . add ( modalInstance , modalInstance . options ) ;
10901102
1091- var body = $document . find ( 'body' ) . eq ( 0 ) ,
1103+ var parent = $document . find ( modal . parent ) . eq ( 0 ) ,
10921104 currBackdropIndex = backdropIndex ( ) ;
10931105
10941106 if ( currBackdropIndex >= 0 && ! backdropDomEl ) {
10951107 backdropScope = $rootScope . $new ( true ) ;
10961108 backdropScope . index = currBackdropIndex ;
10971109 backdropDomEl = $compile ( '<div modal-backdrop></div>' ) ( backdropScope ) ;
1098- body . append ( backdropDomEl ) ;
1110+ parent . append ( backdropDomEl ) ;
10991111 }
11001112
11011113 // Create a faux modal div just to measure its
11021114 // distance to top
11031115 var faux = angular . element ( '<div class="reveal-modal" style="z-index:-1""></div>' ) ;
1104- body . append ( faux [ 0 ] ) ;
1105- var marginTop = parseInt ( getComputedStyle ( faux [ 0 ] ) . top ) || 0 ;
1116+ parent . append ( faux [ 0 ] ) ;
1117+ cssTop = parseInt ( $window . getComputedStyle ( faux [ 0 ] ) . top ) || 0 ;
1118+ var openAt = calculateModalTop ( faux , cssTop ) ;
11061119 faux . remove ( ) ;
11071120
1108- // Using pageYOffset instead of scrollY to ensure compatibility with IE
1109- var scrollY = $window . pageYOffset || 0 ;
1110- var openAt = scrollY + marginTop ;
1111-
11121121 var angularDomEl = angular . element ( '<div modal-window style="visibility: visible; top:' + openAt + 'px;"></div>' )
11131122 . attr ( {
11141123 'window-class' : modal . windowClass ,
@@ -1119,22 +1128,31 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
11191128
11201129 var modalDomEl = $compile ( angularDomEl ) ( modal . scope ) ;
11211130 openedWindows . top ( ) . value . modalDomEl = modalDomEl ;
1122- body . append ( modalDomEl ) ;
1123- body . addClass ( OPENED_MODAL_CLASS ) ;
1131+ parent . append ( modalDomEl ) ;
1132+ parent . addClass ( OPENED_MODAL_CLASS ) ;
11241133 } ;
11251134
1126- $modalStack . close = function ( modalInstance , result ) {
1135+ $modalStack . reposition = function ( modalInstance ) {
11271136 var modalWindow = openedWindows . get ( modalInstance ) . value ;
11281137 if ( modalWindow ) {
1129- modalWindow . deferred . resolve ( result ) ;
1138+ var modalDomEl = modalWindow . modalDomEl ;
1139+ var top = calculateModalTop ( modalDomEl , cssTop ) ;
1140+ modalDomEl . css ( 'top' , top + "px" ) ;
1141+ }
1142+ } ;
1143+
1144+ $modalStack . close = function ( modalInstance , result ) {
1145+ var modalWindow = openedWindows . get ( modalInstance ) ;
1146+ if ( modalWindow ) {
1147+ modalWindow . value . deferred . resolve ( result ) ;
11301148 removeModalWindow ( modalInstance ) ;
11311149 }
11321150 } ;
11331151
11341152 $modalStack . dismiss = function ( modalInstance , reason ) {
1135- var modalWindow = openedWindows . get ( modalInstance ) . value ;
1153+ var modalWindow = openedWindows . get ( modalInstance ) ;
11361154 if ( modalWindow ) {
1137- modalWindow . deferred . reject ( reason ) ;
1155+ modalWindow . value . deferred . reject ( reason ) ;
11381156 removeModalWindow ( modalInstance ) ;
11391157 }
11401158 } ;
@@ -1197,6 +1215,9 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
11971215 } ,
11981216 dismiss : function ( reason ) {
11991217 $modalStack . dismiss ( modalInstance , reason ) ;
1218+ } ,
1219+ reposition : function ( ) {
1220+ $modalStack . reposition ( modalInstance ) ;
12001221 }
12011222 } ;
12021223
@@ -1242,7 +1263,8 @@ angular.module('mm.foundation.modal', ['mm.foundation.transition'])
12421263 content : tplAndVars [ 0 ] ,
12431264 backdrop : modalOptions . backdrop ,
12441265 keyboard : modalOptions . keyboard ,
1245- windowClass : modalOptions . windowClass
1266+ windowClass : modalOptions . windowClass ,
1267+ parent : modalOptions . parent || 'body'
12461268 } ) ;
12471269
12481270 } , function resolveError ( reason ) {
0 commit comments