Permalink
Browse files

bug: ForElement in MaterialMenu needs a delay during initialization (…

…SPA)
  • Loading branch information...
MikeMitterer committed Jun 10, 2015
1 parent e7a62ee commit 4c2e3a5cc4c14d7d6258e3ae893076a6cc6c2f70
Showing with 22 additions and 35 deletions.
  1. +22 −35 lib/src/components/MaterialMenu.dart
@@ -244,32 +244,6 @@ class MaterialMenu extends MdlComponent {
_outline = outline;
container.insertBefore(outline, element);
// // Find the "for" element and bind events to it.
// // Takes a while until elements are available
// new Future.delayed(new Duration(milliseconds: 50),() {
//
// final forElId = element.getAttribute('for');
// _logger.fine("forElId $forElId");
//
// dom.Element forEl = null;
// if (forElId != null) {
//
// // getElementById is OK here! element.querySelector not possible!
// forEl = dom.document.getElementById(forElId);
// _logger.fine("forEL $forEl #${forElId}");
//
// if (forEl != null) {
// _logger.info("$element has a for-ID: #$forElId pointing to $forEl");
// _forElement = forEl;
//
// // .addEventListener('click', -> .onClick.listen(<MouseEvent>);
// forEl.onClick.listen( _handleForClick );
// forEl.onKeyDown.listen( _handleForKeyboardEvent );
// }
// }
//
// });
_initForElement();
final List<dom.Element> items = element.querySelectorAll('.' + _cssClasses.ITEM );
@@ -339,24 +313,37 @@ class MaterialMenu extends MdlComponent {
}
}
/// searching the for-Element is a bit complex so it got it's own function.
void _initForElement() {
final forElId = element.getAttribute('for');
_logger.fine("forElId $forElId");
dom.Element forEl = null;
if (forElId != null) {
// getElementById is OK here! element.querySelector not possible!
forEl = dom.document.getElementById(forElId);
_logger.fine("forEL $forEl #${forElId}");
void _addEventListeners(final dom.HtmlElement forEl) {
_logger.fine("forEL $forEl #${forElId}");
if (forEl != null) {
_logger.fine("$element has a for-ID: #$forElId pointing to $forEl");
_forElement = forEl;
if (forEl != null) {
_logger.info("$element has a for-ID: #$forElId pointing to $forEl");
_forElement = forEl;
// .addEventListener('click', -> .onClick.listen(<MouseEvent>);
forEl.onClick.listen( _handleForClick );
forEl.onKeyDown.listen( _handleForKeyboardEvent );
}
}
// .addEventListener('click', -> .onClick.listen(<MouseEvent>);
forEl.onClick.listen( _handleForClick );
forEl.onKeyDown.listen( _handleForKeyboardEvent );
// getElementById is OK here! element.querySelector not possible!
forEl = dom.document.getElementById(forElId);
if(forEl != null) {
_addEventListeners(forEl);
} else {
// forEl was not found but maybe just because it takes a while for the DOM
// to recognize it... so we wait 50ms
new Future.delayed(new Duration(milliseconds: 50),() {
_addEventListeners(dom.document.getElementById(forElId));
});
}
}
}

0 comments on commit 4c2e3a5

Please sign in to comment.