| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class PopupHandler { | |
| 6 // references to CSS classes for fade in and fade out transitions | |
| 7 static final String _fadeInClass = "fadeIn"; | |
| 8 static final String _fadeOutClass = "fadeOut"; | |
| 9 static PopupHandler _instance; // singleton | |
| 10 | |
| 11 Element _activePopup; | |
| 12 | |
| 13 factory PopupHandler(Document doc) { | |
| 14 if (_instance == null) { | |
| 15 _instance = new PopupHandler._internal(doc); | |
| 16 } | |
| 17 return _instance; | |
| 18 } | |
| 19 | |
| 20 PopupHandler._internal(Document doc) { | |
| 21 Element body = doc.body; | |
| 22 | |
| 23 body.on.click.add((Event e) { | |
| 24 if (_activePopup == null) { | |
| 25 return; | |
| 26 } | |
| 27 Element target = e.target; | |
| 28 while (target != null && target != body && target != _activePopup) { | |
| 29 target = target.parent; | |
| 30 } | |
| 31 if (target != _activePopup) { | |
| 32 deactivatePopup(); | |
| 33 } | |
| 34 }, true); | |
| 35 } | |
| 36 | |
| 37 void activatePopup(Element popup, int x, int y) { | |
| 38 if (_activePopup != null) { | |
| 39 deactivatePopup(); | |
| 40 } | |
| 41 | |
| 42 _activePopup = popup; | |
| 43 _activePopup.style.setProperty("left", HtmlUtils.toPx(x)); | |
| 44 _activePopup.style.setProperty("top", HtmlUtils.toPx(y)); | |
| 45 | |
| 46 Set<String> classes = _activePopup.classes; | |
| 47 classes.remove(_fadeOutClass); | |
| 48 classes.add(_fadeInClass); | |
| 49 } | |
| 50 | |
| 51 void deactivatePopup() { | |
| 52 if (_activePopup == null) { | |
| 53 return; | |
| 54 } | |
| 55 Set<String> classes = _activePopup.classes; | |
| 56 classes.remove(_fadeInClass); | |
| 57 classes.add(_fadeOutClass); | |
| 58 _activePopup = null; | |
| 59 } | |
| 60 } | |
| OLD | NEW |