MenuWithTick.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['./Menu', 'underscore', 'text!../templates/Menu.html'], function (Menu, _, template) {
  8. var MenuWithTickItem = null;
  9. /**
  10. * Represents a drop down menu that can be added to an app bar
  11. */
  12. MenuWithTickItem = Menu.extend({
  13. templateString: template,
  14. /**
  15. * Creates a new menu item
  16. *
  17. * @param spec -
  18. * The menu item spec
  19. * @param root -
  20. * A reference to the root menu item, where items go if the app bar is collapsed horizontally
  21. */
  22. init: function init(spec) {
  23. _.extend(this, spec);
  24. MenuWithTickItem.inherited('init', this, arguments);
  25. },
  26. _templateParams: function _templateParams() {
  27. var params = MenuWithTickItem.inherited('_templateParams', this, arguments);
  28. params.showTick = true;
  29. return params;
  30. },
  31. /**
  32. * Updates checked mark and aria-checked attributes in given menuItem
  33. */
  34. updateMenuItemTick: function updateMenuItemTick($MenuItem, checked) {
  35. if ($MenuItem) {
  36. var link = $MenuItem.find('a');
  37. if (checked) {
  38. link.addClass('menuitem-toggled');
  39. } else {
  40. link.removeClass('menuitem-toggled');
  41. }
  42. $MenuItem.find('a')[0].setAttribute('aria-checked', checked ? 'true' : 'false');
  43. }
  44. }
  45. });
  46. return MenuWithTickItem;
  47. });