From e716b76e9a02c43e60bd368674ac0d3952767ae1 Mon Sep 17 00:00:00 2001 From: Artem Fitiskin Date: Wed, 27 May 2015 00:55:07 +0300 Subject: [PATCH] modal stack single option --- app/js/services.js | 3 +- .../ui-bootstrap-custom-tpls-0.12.0.js | 45 ++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/js/services.js b/app/js/services.js index 45263c2a..c714e14f 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -271,7 +271,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) templateUrl: templateUrl('user_modal'), controller: 'UserModalController', scope: scope, - windowClass: 'user_modal_window mobile_modal' + windowClass: 'user_modal_window mobile_modal', + backdrop: 'single' }); }; diff --git a/app/vendor/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.js b/app/vendor/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.js index ff683309..de1ff96c 100644 --- a/app/vendor/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.js +++ b/app/vendor/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.js @@ -787,6 +787,10 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) element.addClass(attrs.windowClass || ''); scope.size = attrs.size; + $modalStack.registerObserverCallback(function(hiddenBySingle) { + scope.hiddenBySingle = hiddenBySingle || false; + }); + $timeout(function () { // trigger CSS transitions scope.animate = true; @@ -835,6 +839,25 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) var backdropDomEl, backdropScope; var openedWindows = $$stackedMap.createNew(); var $modalStack = {}; + var observerCallbacks = []; + + function notifyObservers() { + angular.forEach(observerCallbacks, function(callback, index) { + var hasSingleParent = false, + opened = openedWindows.keys(); + + for (var i = 0; i < opened.length; i++) { + var item = openedWindows.get(opened[i]).value; + + if (item.backdrop == 'single' && item.index > index) { + hasSingleParent = true; + break; + } + } + + callback(hasSingleParent); + }); + }; function backdropIndex() { var topBackdropIndex = -1; @@ -854,13 +877,15 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) }); function removeModalWindow(modalInstance) { - var body = $document.find('body').eq(0); var modalWindow = openedWindows.get(modalInstance).value; //clean up the stack openedWindows.remove(modalInstance); + //clean up the observer + observerCallbacks.splice(modalWindow.index, 1); + //remove window DOM element removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, 0, function() { modalWindow.modalScope.$destroy(); @@ -879,6 +904,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) }); backdropDomEl = undefined; backdropScope = undefined; + } else { + notifyObservers(); } } @@ -928,8 +955,11 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) } }); - $modalStack.open = function (modalInstance, modal) { + $modalStack.registerObserverCallback = function(callback){ + observerCallbacks.push(callback); + }; + $modalStack.open = function (modalInstance, modal) { openedWindows.add(modalInstance, { deferred: modal.deferred, modalScope: modal.scope, @@ -949,19 +979,24 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition']) body.append(backdropDomEl); } - var angularDomEl = angular.element('
'); + var angularDomEl = angular.element('
'), + index = openedWindows.length() - 1; + angularDomEl.attr({ 'template-url': modal.windowTemplateUrl, 'window-class': modal.windowClass, 'size': modal.size, - 'index': openedWindows.length() - 1, + 'index': index, 'animate': 'animate' }).html(modal.content); var modalDomEl = $compile(angularDomEl)(modal.scope); openedWindows.top().value.modalDomEl = modalDomEl; + openedWindows.top().value.index = index; body.append(modalDomEl); body.addClass(OPENED_MODAL_CLASS); + + notifyObservers(); }; $modalStack.close = function (modalInstance, result) { @@ -1222,7 +1257,7 @@ angular.module("template/modal/backdrop.html", []).run(["$templateCache", functi angular.module("template/modal/window.html", []).run(["$templateCache", function($templateCache) { $templateCache.put("template/modal/window.html", - "
\n" + + "
\n" + "
\n" + "
\n" + "
\n" +