_header_js_custom.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <script language="javascript">
  2. $(document).ready(function () {
  3. bx_activate_anim_icons('#283C50');
  4. var aSidebars = ['site', 'account'];
  5. for(var i in aSidebars) {
  6. if(typeof(aSidebars[i]) != 'string')
  7. continue;
  8. var oSidebar = bx_sidebar_get(aSidebars[i]);
  9. $('.bx-sidebar-' + aSidebars[i] + '-trigger').on('click', function(event) {
  10. event.preventDefault();
  11. var aMatches = $(this).attr('class').match(/bx-sidebar-(.*)-trigger/);
  12. if(!aMatches || aMatches.length != 2)
  13. return;
  14. bx_sidebar_toggle(aMatches[1]);
  15. });
  16. $('.bx-sidebar .bx-sidebar-' + aSidebars[i] + '-bg').on('click', function(event){
  17. event.preventDefault();
  18. var aMatches = $(this).attr('class').match(/bx-sidebar-(.*)-bg/);
  19. if(!aMatches || aMatches.length != 2)
  20. return;
  21. bx_sidebar_toggle(aMatches[1]);
  22. });
  23. $('.bx-sidebar .bx-sidebar-' + aSidebars[i] + '-close').on('click', function(event){
  24. event.preventDefault();
  25. var aMatches = $(this).attr('class').match(/bx-sidebar-(.*)-close/);
  26. if(!aMatches || aMatches.length != 2)
  27. return;
  28. bx_sidebar_toggle(aMatches[1]);
  29. });
  30. $('.bx-sidebar.bx-sidebar-' + aSidebars[i] + ' .bx-focus-trap').bind('focus', function() {
  31. var aFocusable = bx_get_focusable(oSidebar.get(0));
  32. if(aFocusable && aFocusable.length > 0)
  33. $(aFocusable[0]).focus();
  34. });
  35. }
  36. //--- Escape closes whichever sidebar is open; bx_sidebar_toggle returns focus to its trigger.
  37. $(document).on('keydown.bx-sidebar', function(event) {
  38. if(event.which != 27 && event.key != 'Escape')
  39. return;
  40. for(var j in aSidebars) {
  41. if(typeof(aSidebars[j]) != 'string' || !bx_sidebar_active(aSidebars[j]))
  42. continue;
  43. event.preventDefault();
  44. bx_sidebar_toggle(aSidebars[j]);
  45. }
  46. });
  47. });
  48. function bx_sidebar_get(sType) {
  49. return $('.bx-sidebar.bx-sidebar-' + sType);
  50. }
  51. function bx_sidebar_active(sType) {
  52. var oSidebar = bx_sidebar_get(sType);
  53. if(!oSidebar || oSidebar.length == 0)
  54. return false;
  55. return oSidebar.hasClass('bx-sidebar-active');
  56. }
  57. function bx_sidebar_toggle(sType) {
  58. var oSidebar = bx_sidebar_get(sType);
  59. var bSidebarActive = bx_sidebar_active(sType);
  60. // A drawer opening or closing (interface sounds, see bx_sound).
  61. if(typeof(bx_sound) == 'function')
  62. bx_sound(bSidebarActive ? 'close' : 'open');
  63. oSidebar.toggleClass('bx-sidebar-active', !bSidebarActive);
  64. var oTrigger = $('.bx-sidebar-' + sType + '-trigger');
  65. oTrigger.attr('aria-expanded', !bSidebarActive ? 'true' : 'false');
  66. if(!bSidebarActive) {
  67. var aFocusable = bx_get_focusable(oSidebar.get(0));
  68. if(aFocusable && aFocusable.length > 0)
  69. $(aFocusable[0]).focus();
  70. }
  71. else {
  72. var oReturnTo = bx_clicked_stack_pop();
  73. $(oReturnTo || oTrigger.filter(':visible').get(0)).focus();
  74. }
  75. }
  76. function bx_sidebar_dropdown_toggle(oLink) {
  77. var oItem = $(oLink).parents('.bx-sidebar-item:first');
  78. oItem.toggleClass('bx-si-dropdown-open').find('.bx-si-dropdown-icon').toggleClass('rotate-0 rotate-90');
  79. $(oLink).attr('aria-expanded', oItem.hasClass('bx-si-dropdown-open') ? 'true' : 'false');
  80. return false;
  81. }
  82. /**
  83. * The 'search' item of the member toolbar opens the floating search bar (#bx-ti-search-box), which takes the item's place until a click outside or Escape.
  84. */
  85. function bx_site_search_show(oLink) {
  86. var oBox = $('#bx-ti-search-box');
  87. if(!oBox.length)
  88. return;
  89. $(oLink).attr('aria-expanded', 'true').parents('.bx-menu-toolbar-item:first').addClass('bx-tis-button-hidden');
  90. oBox.addClass('bx-tis-box-shown');
  91. oBox.find('.bx-form-input-text').focus();
  92. setTimeout(function () {
  93. $(document).on('click.bx-site-search-box touchend.bx-site-search-box', function (event) {
  94. if(!$(event.target).closest('.sys-search-results-quick,.bx-ti-search-box').length)
  95. bx_site_search_hide();
  96. });
  97. }, 10);
  98. }
  99. function bx_site_search_hide() {
  100. var oBox = $('#bx-ti-search-box');
  101. if(!oBox.hasClass('bx-tis-box-shown'))
  102. return;
  103. $(document).off('.bx-site-search-box');
  104. bx_site_search_close_all_opened();
  105. oBox.removeClass('bx-tis-box-shown');
  106. $('.bx-tis-button-hidden').removeClass('bx-tis-button-hidden').find('a[aria-controls="bx-ti-search-box"]').attr('aria-expanded', 'false').focus();
  107. }
  108. function bx_site_search_complete(oContainer, oData) {
  109. if(!oData) {
  110. if(oContainer.is(':visible'))
  111. oContainer.hide();
  112. return;
  113. }
  114. oContainer.show();
  115. setTimeout(function () {
  116. var iWidthPrev = $(window).width();
  117. $(window).on('resize.bx-site-search', function () {
  118. if($(this).width() == iWidthPrev)
  119. return;
  120. iWidthPrev = $(this).width();
  121. bx_site_search_close_all_opened();
  122. });
  123. $(document).on('click.bx-site-search touchend.bx-site-search', function (event) {
  124. if ($(event.target).parents('.sys-search-results-quick').length || $(event.target).filter('.sys-search-results-quick').length || e === event.target)
  125. event.stopPropagation();
  126. else
  127. bx_site_search_close_all_opened();
  128. });
  129. }, 10);
  130. }
  131. function bx_site_search_cancel(oForm)
  132. {
  133. if($(oForm).parents('#bx-ti-search-box').length)
  134. bx_site_search_hide();
  135. }
  136. function bx_site_search_close_all_opened() {
  137. $('.sys-search-results-quick:visible').each(function () {
  138. $(this).hide();
  139. });
  140. }
  141. </script>