jqueryui_navigation.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # jQuery UI navigation components
  4. *
  5. * Demo JS code for jqueryui_navigation.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var JqueryUiNavigation = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Accordion
  15. var _componentUiAccordion = function() {
  16. if (!$().accordion) {
  17. console.warn('Warning - jQuery UI components are not loaded.');
  18. return;
  19. }
  20. // Basic accordion
  21. $('#jui-accordion-basic').accordion();
  22. // Collapsible accordion
  23. $('#jui-accordion-collapsible').accordion({
  24. collapsible: true
  25. });
  26. // Fill height
  27. $('#jui-accordion-fill').accordion({
  28. heightStyle: 'fill'
  29. });
  30. // Accordion on hover
  31. $('#jui-accordion-hover').accordion({
  32. event: 'mouseover'
  33. });
  34. // Animated accordion
  35. $('#jui-accordion-animate').accordion({
  36. animate: false
  37. });
  38. // Sortable accordion
  39. $('#jui-accordion-sortable').accordion({
  40. header: '> div > span'
  41. })
  42. .sortable({
  43. axis: 'y',
  44. handle: 'span',
  45. stop: function(event, ui) {
  46. ui.item.children('span').triggerHandler('focusout');
  47. // Refresh accordion to handle new order
  48. $(this).accordion('refresh');
  49. }
  50. });
  51. };
  52. // Menu
  53. var _componentUiMenu = function() {
  54. if (!$().menu) {
  55. console.warn('Warning - jQuery UI components are not loaded.');
  56. return;
  57. }
  58. // Basic example
  59. $('.jui-menu-basic').menu();
  60. // Disabled menu
  61. $('.jui-menu-disabled').menu({
  62. disabled: true
  63. }).find('a').on('click', function (e) {
  64. e.preventDefault();
  65. });
  66. // Menu with headers
  67. $('.jui-menu-header').menu({
  68. items: '> :not(.ui-menu-header)'
  69. });
  70. };
  71. // Tabs
  72. var _componentUiTabs = function() {
  73. if (!$().tabs) {
  74. console.warn('Warning - jQuery UI components are not loaded.');
  75. return;
  76. }
  77. // Basic example
  78. $('.jui-tabs-basic').tabs();
  79. // Collapsible tabs
  80. $('.jui-tabs-collapsible').tabs({
  81. collapsible: true
  82. });
  83. // Open tab on hover
  84. $('.jui-tabs-hover').tabs({
  85. event: 'mouseover'
  86. });
  87. //
  88. // Sortable tabs
  89. //
  90. // Initialize
  91. var tabs = $('.jui-tabs-sortable').tabs();
  92. // Add sortable functionality
  93. tabs.find('.ui-tabs-nav').sortable({
  94. containment: '#ui-tabs-sortable-container',
  95. stop: function() {
  96. tabs.tabs('refresh');
  97. }
  98. });
  99. };
  100. //
  101. // Return objects assigned to module
  102. //
  103. return {
  104. init: function() {
  105. _componentUiAccordion();
  106. _componentUiMenu();
  107. _componentUiTabs();
  108. }
  109. }
  110. }();
  111. // Initialize module
  112. // ------------------------------
  113. document.addEventListener('DOMContentLoaded', function() {
  114. JqueryUiNavigation.init();
  115. });