toolbar.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal, drupalSettings) {
  8. var options = $.extend({
  9. breakpoints: {
  10. 'toolbar.narrow': '',
  11. 'toolbar.standard': '',
  12. 'toolbar.wide': ''
  13. }
  14. }, drupalSettings.toolbar, {
  15. strings: {
  16. horizontal: Drupal.t('Horizontal orientation'),
  17. vertical: Drupal.t('Vertical orientation')
  18. }
  19. });
  20. Drupal.behaviors.toolbar = {
  21. attach: function attach(context) {
  22. if (!window.matchMedia('only screen').matches) {
  23. return;
  24. }
  25. $(context).find('#toolbar-administration').once('toolbar').each(function () {
  26. var model = Drupal.toolbar.models.toolbarModel = new Drupal.toolbar.ToolbarModel({
  27. locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')),
  28. activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))),
  29. height: $('#toolbar-administration').outerHeight()
  30. });
  31. for (var label in options.breakpoints) {
  32. if (options.breakpoints.hasOwnProperty(label)) {
  33. var mq = options.breakpoints[label];
  34. var mql = Drupal.toolbar.mql[label] = window.matchMedia(mq);
  35. mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
  36. Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql);
  37. }
  38. }
  39. Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({
  40. el: this,
  41. model: model,
  42. strings: options.strings
  43. });
  44. Drupal.toolbar.views.toolbarAuralView = new Drupal.toolbar.ToolbarAuralView({
  45. el: this,
  46. model: model,
  47. strings: options.strings
  48. });
  49. Drupal.toolbar.views.bodyVisualView = new Drupal.toolbar.BodyVisualView({
  50. el: this,
  51. model: model
  52. });
  53. model.trigger('change:isFixed', model, model.get('isFixed'));
  54. model.trigger('change:activeTray', model, model.get('activeTray'));
  55. var menuModel = Drupal.toolbar.models.menuModel = new Drupal.toolbar.MenuModel();
  56. Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({
  57. el: $(this).find('.toolbar-menu-administration').get(0),
  58. model: menuModel,
  59. strings: options.strings
  60. });
  61. Drupal.toolbar.setSubtrees.done(function (subtrees) {
  62. menuModel.set('subtrees', subtrees);
  63. var theme = drupalSettings.ajaxPageState.theme;
  64. localStorage.setItem('Drupal.toolbar.subtrees.' + theme, JSON.stringify(subtrees));
  65. model.set('areSubtreesLoaded', true);
  66. });
  67. Drupal.toolbar.views.toolbarVisualView.loadSubtrees();
  68. $(document).on('drupalViewportOffsetChange.toolbar', function (event, offsets) {
  69. model.set('offsets', offsets);
  70. });
  71. model.on('change:orientation', function (model, orientation) {
  72. $(document).trigger('drupalToolbarOrientationChange', orientation);
  73. }).on('change:activeTab', function (model, tab) {
  74. $(document).trigger('drupalToolbarTabChange', tab);
  75. }).on('change:activeTray', function (model, tray) {
  76. $(document).trigger('drupalToolbarTrayChange', tray);
  77. });
  78. if (Drupal.toolbar.models.toolbarModel.get('orientation') === 'horizontal' && Drupal.toolbar.models.toolbarModel.get('activeTab') === null) {
  79. Drupal.toolbar.models.toolbarModel.set({
  80. activeTab: $('.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a').get(0)
  81. });
  82. }
  83. });
  84. }
  85. };
  86. Drupal.toolbar = {
  87. views: {},
  88. models: {},
  89. mql: {},
  90. setSubtrees: new $.Deferred(),
  91. mediaQueryChangeHandler: function mediaQueryChangeHandler(model, label, mql) {
  92. switch (label) {
  93. case 'toolbar.narrow':
  94. model.set({
  95. isOriented: mql.matches,
  96. isTrayToggleVisible: false
  97. });
  98. if (!mql.matches || !model.get('orientation')) {
  99. model.set({ orientation: 'vertical' }, { validate: true });
  100. }
  101. break;
  102. case 'toolbar.standard':
  103. model.set({
  104. isFixed: mql.matches
  105. });
  106. break;
  107. case 'toolbar.wide':
  108. model.set({
  109. orientation: mql.matches && !model.get('locked') ? 'horizontal' : 'vertical'
  110. }, { validate: true });
  111. model.set({
  112. isTrayToggleVisible: mql.matches
  113. });
  114. break;
  115. default:
  116. break;
  117. }
  118. }
  119. };
  120. Drupal.theme.toolbarOrientationToggle = function () {
  121. return '<div class="toolbar-toggle-orientation"><div class="toolbar-lining">' + '<button class="toolbar-icon" type="button"></button>' + '</div></div>';
  122. };
  123. Drupal.AjaxCommands.prototype.setToolbarSubtrees = function (ajax, response, status) {
  124. Drupal.toolbar.setSubtrees.resolve(response.subtrees);
  125. };
  126. })(jQuery, Drupal, drupalSettings);