components_scrollspy.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Scrollspy
  4. *
  5. * Demo JS code for components_scrollspy.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var Scrollspy = function () {
  11. //
  12. // Setup module components
  13. //
  14. // Sticky
  15. var _componentSticky = function() {
  16. if (!$().stick_in_parent) {
  17. console.warn('Warning - sticky.min.js is not loaded.');
  18. return;
  19. }
  20. // Initialize
  21. $('.sidebar-sticky .sidebar').stick_in_parent({
  22. offset_top: 20,
  23. parent: '.content'
  24. });
  25. // Detach on mobiles
  26. $('.sidebar-mobile-component-toggle').on('click', function() {
  27. $('.sidebar-sticky .sidebar').trigger("sticky_kit:detach");
  28. });
  29. };
  30. //
  31. // Return objects assigned to module
  32. //
  33. return {
  34. initComponents: function() {
  35. _componentSticky();
  36. }
  37. }
  38. }();
  39. // Initialize module
  40. // ------------------------------
  41. document.addEventListener('DOMContentLoaded', function() {
  42. Scrollspy.initComponents();
  43. });