submenu.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview A class representing menu items that open a submenu.
  16. * @see goog.ui.Menu
  17. *
  18. * @see ../demos/submenus.html
  19. * @see ../demos/submenus2.html
  20. */
  21. goog.provide('goog.ui.SubMenu');
  22. goog.require('goog.Timer');
  23. goog.require('goog.asserts');
  24. goog.require('goog.dom');
  25. goog.require('goog.dom.classlist');
  26. goog.require('goog.events.KeyCodes');
  27. goog.require('goog.positioning.AnchoredViewportPosition');
  28. goog.require('goog.positioning.Corner');
  29. goog.require('goog.style');
  30. goog.require('goog.ui.Component');
  31. goog.require('goog.ui.Menu');
  32. goog.require('goog.ui.MenuItem');
  33. goog.require('goog.ui.SubMenuRenderer');
  34. goog.require('goog.ui.registry');
  35. /**
  36. * Class representing a submenu that can be added as an item to other menus.
  37. *
  38. * @param {goog.ui.ControlContent} content Text caption or DOM structure to
  39. * display as the content of the submenu (use to add icons or styling to
  40. * menus).
  41. * @param {*=} opt_model Data/model associated with the menu item.
  42. * @param {goog.dom.DomHelper=} opt_domHelper Optional dom helper used for dom
  43. * interactions.
  44. * @param {goog.ui.MenuItemRenderer=} opt_renderer Renderer used to render or
  45. * decorate the component; defaults to {@link goog.ui.SubMenuRenderer}.
  46. * @constructor
  47. * @extends {goog.ui.MenuItem}
  48. */
  49. goog.ui.SubMenu = function(content, opt_model, opt_domHelper, opt_renderer) {
  50. goog.ui.MenuItem.call(
  51. this, content, opt_model, opt_domHelper,
  52. opt_renderer || goog.ui.SubMenuRenderer.getInstance());
  53. };
  54. goog.inherits(goog.ui.SubMenu, goog.ui.MenuItem);
  55. goog.tagUnsealableClass(goog.ui.SubMenu);
  56. /**
  57. * The delay before opening the sub menu in milliseconds.
  58. * @type {number}
  59. */
  60. goog.ui.SubMenu.MENU_DELAY_MS = 218;
  61. /**
  62. * Timer used to dismiss the submenu when the item becomes unhighlighted.
  63. * @type {?number}
  64. * @private
  65. */
  66. goog.ui.SubMenu.prototype.dismissTimer_ = null;
  67. /**
  68. * Timer used to show the submenu on mouseover.
  69. * @type {?number}
  70. * @private
  71. */
  72. goog.ui.SubMenu.prototype.showTimer_ = null;
  73. /**
  74. * Whether the submenu believes the menu is visible.
  75. * @type {boolean}
  76. * @private
  77. */
  78. goog.ui.SubMenu.prototype.menuIsVisible_ = false;
  79. /**
  80. * The lazily created sub menu.
  81. * @type {goog.ui.Menu?}
  82. * @private
  83. */
  84. goog.ui.SubMenu.prototype.subMenu_ = null;
  85. /**
  86. * Whether or not the sub-menu was set explicitly.
  87. * @type {boolean}
  88. * @private
  89. */
  90. goog.ui.SubMenu.prototype.externalSubMenu_ = false;
  91. /**
  92. * Whether or not to align the submenu at the end of the parent menu.
  93. * If true, the menu expands to the right in LTR languages and to the left
  94. * in RTL langauges.
  95. * @type {boolean}
  96. * @private
  97. */
  98. goog.ui.SubMenu.prototype.alignToEnd_ = true;
  99. /**
  100. * Whether the position of this submenu may be adjusted to fit
  101. * the visible area, as in {@link goog.ui.Popup.positionAtCoordinate}.
  102. * @type {boolean}
  103. * @private
  104. */
  105. goog.ui.SubMenu.prototype.isPositionAdjustable_ = false;
  106. /** @override */
  107. goog.ui.SubMenu.prototype.enterDocument = function() {
  108. goog.ui.SubMenu.superClass_.enterDocument.call(this);
  109. this.getHandler().listen(
  110. this.getParent(), goog.ui.Component.EventType.HIDE, this.onParentHidden_);
  111. if (this.subMenu_) {
  112. this.setMenuListenersEnabled_(this.subMenu_, true);
  113. }
  114. };
  115. /** @override */
  116. goog.ui.SubMenu.prototype.exitDocument = function() {
  117. this.getHandler().unlisten(
  118. this.getParent(), goog.ui.Component.EventType.HIDE, this.onParentHidden_);
  119. if (this.subMenu_) {
  120. this.setMenuListenersEnabled_(this.subMenu_, false);
  121. if (!this.externalSubMenu_) {
  122. this.subMenu_.exitDocument();
  123. goog.dom.removeNode(this.subMenu_.getElement());
  124. }
  125. }
  126. goog.ui.SubMenu.superClass_.exitDocument.call(this);
  127. };
  128. /** @override */
  129. goog.ui.SubMenu.prototype.disposeInternal = function() {
  130. if (this.subMenu_ && !this.externalSubMenu_) {
  131. this.subMenu_.dispose();
  132. }
  133. this.subMenu_ = null;
  134. goog.ui.SubMenu.superClass_.disposeInternal.call(this);
  135. };
  136. /**
  137. * @override
  138. * Dismisses the submenu on a delay, with the result that the user needs less
  139. * accuracy when moving to submenus. Alternate implementations could use
  140. * geometry instead of a timer.
  141. * @param {boolean} highlight Whether item should be highlighted.
  142. * @param {boolean=} opt_btnPressed Whether the mouse button is held down.
  143. */
  144. goog.ui.SubMenu.prototype.setHighlighted = function(highlight, opt_btnPressed) {
  145. goog.ui.SubMenu.superClass_.setHighlighted.call(this, highlight);
  146. if (opt_btnPressed) {
  147. this.getMenu().setMouseButtonPressed(true);
  148. }
  149. if (!highlight) {
  150. if (this.dismissTimer_) {
  151. goog.Timer.clear(this.dismissTimer_);
  152. }
  153. this.dismissTimer_ = goog.Timer.callOnce(
  154. this.dismissSubMenu, goog.ui.SubMenu.MENU_DELAY_MS, this);
  155. }
  156. };
  157. /**
  158. * Show the submenu and ensure that all siblings are hidden.
  159. */
  160. goog.ui.SubMenu.prototype.showSubMenu = function() {
  161. // Only show the menu if this item is still selected. This is called on a
  162. // timeout, so make sure our parent still exists.
  163. var parent = this.getParent();
  164. if (parent && parent.getHighlighted() == this) {
  165. this.setSubMenuVisible_(true);
  166. this.dismissSiblings_();
  167. }
  168. };
  169. /**
  170. * Dismisses the menu and all further submenus.
  171. */
  172. goog.ui.SubMenu.prototype.dismissSubMenu = function() {
  173. // Because setHighlighted calls this function on a timeout, we need to make
  174. // sure that the sub menu hasn't been disposed when we come back.
  175. var subMenu = this.subMenu_;
  176. if (subMenu && subMenu.getParent() == this) {
  177. this.setSubMenuVisible_(false);
  178. subMenu.forEachChild(function(child) {
  179. if (typeof child.dismissSubMenu == 'function') {
  180. child.dismissSubMenu();
  181. }
  182. });
  183. }
  184. };
  185. /**
  186. * Clears the show and hide timers for the sub menu.
  187. */
  188. goog.ui.SubMenu.prototype.clearTimers = function() {
  189. if (this.dismissTimer_) {
  190. goog.Timer.clear(this.dismissTimer_);
  191. }
  192. if (this.showTimer_) {
  193. goog.Timer.clear(this.showTimer_);
  194. }
  195. };
  196. /**
  197. * Sets the menu item to be visible or invisible.
  198. * @param {boolean} visible Whether to show or hide the component.
  199. * @param {boolean=} opt_force If true, doesn't check whether the component
  200. * already has the requested visibility, and doesn't dispatch any events.
  201. * @return {boolean} Whether the visibility was changed.
  202. * @override
  203. */
  204. goog.ui.SubMenu.prototype.setVisible = function(visible, opt_force) {
  205. var visibilityChanged =
  206. goog.ui.SubMenu.superClass_.setVisible.call(this, visible, opt_force);
  207. // For menus that allow menu items to be hidden (i.e. ComboBox) ensure that
  208. // the submenu is hidden.
  209. if (visibilityChanged && !this.isVisible()) {
  210. this.dismissSubMenu();
  211. }
  212. return visibilityChanged;
  213. };
  214. /**
  215. * Dismiss all the sub menus of sibling menu items.
  216. * @private
  217. */
  218. goog.ui.SubMenu.prototype.dismissSiblings_ = function() {
  219. this.getParent().forEachChild(function(child) {
  220. if (child != this && typeof child.dismissSubMenu == 'function') {
  221. child.dismissSubMenu();
  222. child.clearTimers();
  223. }
  224. }, this);
  225. };
  226. /**
  227. * Handles a key event that is passed to the menu item from its parent because
  228. * it is highlighted. If the right key is pressed the sub menu takes control
  229. * and delegates further key events to its menu until it is dismissed OR the
  230. * left key is pressed.
  231. * @param {goog.events.KeyEvent} e A key event.
  232. * @return {boolean} Whether the event was handled.
  233. * @override
  234. */
  235. goog.ui.SubMenu.prototype.handleKeyEvent = function(e) {
  236. var keyCode = e.keyCode;
  237. var openKeyCode = this.isRightToLeft() ? goog.events.KeyCodes.LEFT :
  238. goog.events.KeyCodes.RIGHT;
  239. var closeKeyCode = this.isRightToLeft() ? goog.events.KeyCodes.RIGHT :
  240. goog.events.KeyCodes.LEFT;
  241. if (!this.menuIsVisible_) {
  242. // Menu item doesn't have keyboard control and the right key was pressed.
  243. // So open take keyboard control and open the sub menu.
  244. if (this.isEnabled() &&
  245. (keyCode == openKeyCode || keyCode == this.getMnemonic())) {
  246. this.showSubMenu();
  247. this.getMenu().highlightFirst();
  248. this.clearTimers();
  249. // The menu item doesn't currently care about the key events so let the
  250. // parent menu handle them accordingly .
  251. } else {
  252. return false;
  253. }
  254. // Menu item has control, so let its menu try to handle the keys (this may
  255. // in turn be handled by sub-sub menus).
  256. } else if (this.getMenu().handleKeyEvent(e)) {
  257. // Nothing to do
  258. // The menu has control and the key hasn't yet been handled, on left arrow
  259. // we turn off key control.
  260. } else if (keyCode == closeKeyCode) {
  261. this.dismissSubMenu();
  262. } else {
  263. // Submenu didn't handle the key so let the parent decide what to do.
  264. return false;
  265. }
  266. e.preventDefault();
  267. return true;
  268. };
  269. /**
  270. * Listens to the sub menus items and ensures that this menu item is selected
  271. * while dismissing the others. This handles the case when the user mouses
  272. * over other items on their way to the sub menu.
  273. * @param {goog.events.Event} e Enter event to handle.
  274. * @private
  275. */
  276. goog.ui.SubMenu.prototype.onChildEnter_ = function(e) {
  277. if (this.subMenu_.getParent() == this) {
  278. this.clearTimers();
  279. this.getParentEventTarget().setHighlighted(this);
  280. this.dismissSiblings_();
  281. }
  282. };
  283. /**
  284. * Listens to the parent menu's hide event and ensures that all submenus are
  285. * hidden at the same time.
  286. * @param {goog.events.Event} e The event.
  287. * @private
  288. */
  289. goog.ui.SubMenu.prototype.onParentHidden_ = function(e) {
  290. // Ignore propagated events
  291. if (e.target == this.getParentEventTarget()) {
  292. // TODO(user): Using an event for this is expensive. Consider having a
  293. // generalized interface that the parent menu calls on its children when
  294. // it is hidden.
  295. this.dismissSubMenu();
  296. this.clearTimers();
  297. }
  298. };
  299. /**
  300. * @override
  301. * Sets a timer to show the submenu and then dispatches an ENTER event to the
  302. * parent menu.
  303. * @param {goog.events.BrowserEvent} e Mouse event to handle.
  304. * @protected
  305. */
  306. goog.ui.SubMenu.prototype.handleMouseOver = function(e) {
  307. if (this.isEnabled()) {
  308. this.clearTimers();
  309. this.showTimer_ = goog.Timer.callOnce(
  310. this.showSubMenu, goog.ui.SubMenu.MENU_DELAY_MS, this);
  311. }
  312. goog.ui.SubMenu.superClass_.handleMouseOver.call(this, e);
  313. };
  314. /**
  315. * Overrides the default mouseup event handler, so that the ACTION isn't
  316. * dispatched for the submenu itself, instead the submenu is shown instantly.
  317. * @param {goog.events.Event} e The browser event.
  318. * @return {boolean} True if the action was allowed to proceed, false otherwise.
  319. * @override
  320. */
  321. goog.ui.SubMenu.prototype.performActionInternal = function(e) {
  322. this.clearTimers();
  323. var shouldHandleClick =
  324. this.isSupportedState(goog.ui.Component.State.SELECTED) ||
  325. this.isSupportedState(goog.ui.Component.State.CHECKED);
  326. if (shouldHandleClick) {
  327. return goog.ui.SubMenu.superClass_.performActionInternal.call(this, e);
  328. } else {
  329. this.showSubMenu();
  330. return true;
  331. }
  332. };
  333. /**
  334. * Sets the visiblility of the sub menu.
  335. * @param {boolean} visible Whether to show menu.
  336. * @private
  337. */
  338. goog.ui.SubMenu.prototype.setSubMenuVisible_ = function(visible) {
  339. // Unhighlighting the menuitems if closing the menu so the event handlers can
  340. // determine the correct state.
  341. if (!visible && this.getMenu()) {
  342. this.getMenu().setHighlightedIndex(-1);
  343. }
  344. // Dispatch OPEN event before calling getMenu(), so we can create the menu
  345. // lazily on first access.
  346. this.dispatchEvent(
  347. goog.ui.Component.getStateTransitionEvent(
  348. goog.ui.Component.State.OPENED, visible));
  349. var subMenu = this.getMenu();
  350. if (visible != this.menuIsVisible_) {
  351. goog.dom.classlist.enable(
  352. goog.asserts.assert(this.getElement()),
  353. goog.getCssName('goog-submenu-open'), visible);
  354. }
  355. if (visible != subMenu.isVisible()) {
  356. if (visible) {
  357. // Lazy-render menu when first shown, if needed.
  358. if (!subMenu.isInDocument()) {
  359. subMenu.render();
  360. }
  361. subMenu.setHighlightedIndex(-1);
  362. }
  363. subMenu.setVisible(visible);
  364. // We must position after the menu is visible, otherwise positioning logic
  365. // breaks in RTL.
  366. if (visible) {
  367. this.positionSubMenu();
  368. }
  369. }
  370. this.menuIsVisible_ = visible;
  371. };
  372. /**
  373. * Attaches or detaches menu event listeners to/from the given menu. Called
  374. * each time a menu is attached to or detached from the submenu.
  375. * @param {goog.ui.Menu} menu Menu on which to listen for events.
  376. * @param {boolean} attach Whether to attach or detach event listeners.
  377. * @private
  378. */
  379. goog.ui.SubMenu.prototype.setMenuListenersEnabled_ = function(menu, attach) {
  380. var handler = this.getHandler();
  381. var method = attach ? handler.listen : handler.unlisten;
  382. method.call(
  383. handler, menu, goog.ui.Component.EventType.ENTER, this.onChildEnter_);
  384. };
  385. /**
  386. * Sets whether the submenu is aligned at the end of the parent menu.
  387. * @param {boolean} alignToEnd True to align to end, false to align to start.
  388. */
  389. goog.ui.SubMenu.prototype.setAlignToEnd = function(alignToEnd) {
  390. if (alignToEnd != this.alignToEnd_) {
  391. this.alignToEnd_ = alignToEnd;
  392. if (this.isInDocument()) {
  393. // Completely re-render the widget.
  394. var oldElement = this.getElement();
  395. this.exitDocument();
  396. if (oldElement.nextSibling) {
  397. this.renderBefore(/** @type {!Element} */ (oldElement.nextSibling));
  398. } else {
  399. this.render(/** @type {Element} */ (oldElement.parentNode));
  400. }
  401. }
  402. }
  403. };
  404. /**
  405. * Determines whether the submenu is aligned at the end of the parent menu.
  406. * @return {boolean} True if aligned to the end (the default), false if
  407. * aligned to the start.
  408. */
  409. goog.ui.SubMenu.prototype.isAlignedToEnd = function() {
  410. return this.alignToEnd_;
  411. };
  412. /**
  413. * Positions the submenu. This method should be called if the sub menu is
  414. * opened and the menu element's size changes (e.g., when adding/removing items
  415. * to an opened sub menu).
  416. */
  417. goog.ui.SubMenu.prototype.positionSubMenu = function() {
  418. var position = new goog.positioning.AnchoredViewportPosition(
  419. this.getElement(),
  420. this.isAlignedToEnd() ? goog.positioning.Corner.TOP_END :
  421. goog.positioning.Corner.TOP_START,
  422. this.isPositionAdjustable_);
  423. // TODO(user): Clean up popup code and have this be a one line call
  424. var subMenu = this.getMenu();
  425. var el = subMenu.getElement();
  426. if (!subMenu.isVisible()) {
  427. el.style.visibility = 'hidden';
  428. goog.style.setElementShown(el, true);
  429. }
  430. position.reposition(
  431. el, this.isAlignedToEnd() ? goog.positioning.Corner.TOP_START :
  432. goog.positioning.Corner.TOP_END);
  433. if (!subMenu.isVisible()) {
  434. goog.style.setElementShown(el, false);
  435. el.style.visibility = 'visible';
  436. }
  437. };
  438. // Methods delegated to sub-menu but accessible here for convinience
  439. /**
  440. * Adds a new menu item at the end of the menu.
  441. * @param {goog.ui.MenuHeader|goog.ui.MenuItem|goog.ui.MenuSeparator} item Menu
  442. * item to add to the menu.
  443. */
  444. goog.ui.SubMenu.prototype.addItem = function(item) {
  445. this.getMenu().addChild(item, true);
  446. };
  447. /**
  448. * Adds a new menu item at a specific index in the menu.
  449. * @param {goog.ui.MenuHeader|goog.ui.MenuItem|goog.ui.MenuSeparator} item Menu
  450. * item to add to the menu.
  451. * @param {number} n Index at which to insert the menu item.
  452. */
  453. goog.ui.SubMenu.prototype.addItemAt = function(item, n) {
  454. this.getMenu().addChildAt(item, n, true);
  455. };
  456. /**
  457. * Removes an item from the menu and disposes it.
  458. * @param {goog.ui.MenuItem} item The menu item to remove.
  459. */
  460. goog.ui.SubMenu.prototype.removeItem = function(item) {
  461. var child = this.getMenu().removeChild(item, true);
  462. if (child) {
  463. child.dispose();
  464. }
  465. };
  466. /**
  467. * Removes a menu item at a given index in the menu and disposes it.
  468. * @param {number} n Index of item.
  469. */
  470. goog.ui.SubMenu.prototype.removeItemAt = function(n) {
  471. var child = this.getMenu().removeChildAt(n, true);
  472. if (child) {
  473. child.dispose();
  474. }
  475. };
  476. /**
  477. * Returns a reference to the menu item at a given index.
  478. * @param {number} n Index of menu item.
  479. * @return {goog.ui.Component} Reference to the menu item.
  480. */
  481. goog.ui.SubMenu.prototype.getItemAt = function(n) {
  482. return this.getMenu().getChildAt(n);
  483. };
  484. /**
  485. * Returns the number of items in the sub menu (including separators).
  486. * @return {number} The number of items in the menu.
  487. */
  488. goog.ui.SubMenu.prototype.getItemCount = function() {
  489. return this.getMenu().getChildCount();
  490. };
  491. /**
  492. * Returns the menu items contained in the sub menu.
  493. * @return {!Array<!goog.ui.MenuItem>} An array of menu items.
  494. * @deprecated Use getItemAt/getItemCount instead.
  495. */
  496. goog.ui.SubMenu.prototype.getItems = function() {
  497. return this.getMenu().getItems();
  498. };
  499. /**
  500. * Gets a reference to the submenu's actual menu.
  501. * @return {!goog.ui.Menu} Reference to the object representing the sub menu.
  502. */
  503. goog.ui.SubMenu.prototype.getMenu = function() {
  504. if (!this.subMenu_) {
  505. this.setMenu(
  506. new goog.ui.Menu(this.getDomHelper()), /* opt_internal */ true);
  507. } else if (this.externalSubMenu_ && this.subMenu_.getParent() != this) {
  508. // Since it is possible for the same popup menu to be attached to multiple
  509. // submenus, we need to ensure that it has the correct parent event target.
  510. this.subMenu_.setParent(this);
  511. }
  512. // Always create the menu DOM, for backward compatibility.
  513. if (!this.subMenu_.getElement()) {
  514. this.subMenu_.createDom();
  515. }
  516. return this.subMenu_;
  517. };
  518. /**
  519. * Sets the submenu to a specific menu.
  520. * @param {goog.ui.Menu} menu The menu to show when this item is selected.
  521. * @param {boolean=} opt_internal Whether this menu is an "internal" menu, and
  522. * should be disposed of when this object is disposed of.
  523. */
  524. goog.ui.SubMenu.prototype.setMenu = function(menu, opt_internal) {
  525. var oldMenu = this.subMenu_;
  526. if (menu != oldMenu) {
  527. if (oldMenu) {
  528. this.dismissSubMenu();
  529. if (this.isInDocument()) {
  530. this.setMenuListenersEnabled_(oldMenu, false);
  531. }
  532. }
  533. this.subMenu_ = menu;
  534. this.externalSubMenu_ = !opt_internal;
  535. if (menu) {
  536. menu.setParent(this);
  537. // There's no need to dispatch a HIDE event during submenu construction.
  538. menu.setVisible(false, /* opt_force */ true);
  539. menu.setAllowAutoFocus(false);
  540. menu.setFocusable(false);
  541. if (this.isInDocument()) {
  542. this.setMenuListenersEnabled_(menu, true);
  543. }
  544. }
  545. }
  546. };
  547. /**
  548. * Returns true if the provided element is to be considered inside the menu for
  549. * purposes such as dismissing the menu on an event. This is so submenus can
  550. * make use of elements outside their own DOM.
  551. * @param {Element} element The element to test for.
  552. * @return {boolean} Whether or not the provided element is contained.
  553. */
  554. goog.ui.SubMenu.prototype.containsElement = function(element) {
  555. return this.getMenu().containsElement(element);
  556. };
  557. /**
  558. * @param {boolean} isAdjustable Whether this submenu is adjustable.
  559. */
  560. goog.ui.SubMenu.prototype.setPositionAdjustable = function(isAdjustable) {
  561. this.isPositionAdjustable_ = !!isAdjustable;
  562. };
  563. /**
  564. * @return {boolean} Whether this submenu is adjustable.
  565. */
  566. goog.ui.SubMenu.prototype.isPositionAdjustable = function() {
  567. return this.isPositionAdjustable_;
  568. };
  569. // Register a decorator factory function for goog.ui.SubMenus.
  570. goog.ui.registry.setDecoratorByClassName(
  571. goog.getCssName('goog-submenu'),
  572. function() { return new goog.ui.SubMenu(null); });