You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

92 lines
2.9 KiB

  1. /**
  2. * Sets up the behaviour of the meta box
  3. *
  4. * @author Andreas Gohr <gohr@cosmocode.de>
  5. * @author Jana Deutschlaender <deutschlaender@cosmocode.de>
  6. */
  7. (function($) {
  8. /**
  9. * Register the click handler for the tabs
  10. *
  11. * Tabs can be added dynamically later on and this handler will still
  12. * provide the open/close functionality
  13. */
  14. var registerClickForTabsInMetaBox = function($metaBox) {
  15. $metaBox.on('click', '.meta-tabs a', function (e) {
  16. e.preventDefault();
  17. var $tab = $(this),
  18. isopen = $tab.attr('aria-expanded') === 'true';
  19. // disable all existing tabs
  20. disableExistingTabs($metaBox);
  21. if (isopen) return; // tab was open, we closed it. we're done
  22. // enable current tab
  23. $tab
  24. .attr('aria-expanded', 'true')
  25. .closest('li')
  26. .addClass('active');
  27. $metaBox.find($tab.attr('href'))
  28. .addClass('active')
  29. .attr('aria-hidden', 'false');
  30. }).find('.meta-content').on('click', 'a[href*="#"]', function (e) {
  31. disableExistingTabs($metaBox);
  32. /* uses custome event handler hide see spc.js */
  33. }).find('#tagging__edit').on('hide', function(e){
  34. disableExistingTabs($metaBox);
  35. });
  36. /**
  37. * in admin templates show toc tab, if available
  38. */
  39. if($('body').hasClass('do-admin')) {
  40. var $tocLink = $metaBox.find('a[href="#spr__tab-toc"]');
  41. if($tocLink.length === 1) {
  42. $tocLink.trigger('click');
  43. }
  44. }
  45. },
  46. disableExistingTabs = function($metaBox) {
  47. $metaBox.find('.meta-tabs li')
  48. .removeClass('active')
  49. .find('a')
  50. .attr('aria-expanded', 'false');
  51. $metaBox.find('.meta-content .tab-pane')
  52. .removeClass('active')
  53. .attr('aria-hidden', 'false');
  54. };
  55. var stickyBox = function ($metaBox, topOffset, leftOffset) {
  56. if (window.pageYOffset >= topOffset) {
  57. $metaBox.addClass("sticky").attr("style", "left: " + leftOffset + "px");
  58. } else {
  59. $metaBox.removeClass("sticky").removeAttr("style");
  60. }
  61. };
  62. $(function(){
  63. var $metaBox = $('#spr__meta-box');
  64. if (!$metaBox.length) return;
  65. registerClickForTabsInMetaBox($metaBox);
  66. var topOffset = $metaBox.offset().top;
  67. window.onscroll = function () {
  68. // check while scrolling, or window resizing will break horizontal positioning
  69. var leftOffset = $metaBox.offset().left;
  70. stickyBox($metaBox, topOffset, leftOffset)
  71. };
  72. });
  73. })(jQuery);