Guest User

Untitled

a guest
Feb 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. /**
  2. * For the day job, pay it no mind
  3. */
  4. (function () {
  5. if (document.getElementById('quicktabs-5')) {
  6.  
  7. var faculty = $('.faculty-name'),
  8. rootBlock = $('#block-block-12'),
  9. nameOuter = rootBlock.find('> div > div').eq(0),
  10. letters = {}, alpha = '', listItems = '', node,
  11. navList = document.createElement('ul');
  12.  
  13. nameOuter.parent()[0].style.position = 'relative';
  14.  
  15. // change id to whatever matches your naming scheme and style as needed
  16. navList.id = 'faculty-alpha-nav';
  17.  
  18. /* --------------------------------------------------------------
  19. * -- START TEST-ONLY SECTION
  20. * -- All style stuff that follows should be in CSS, not here */
  21.  
  22. // this was just a quick way to demonstration/dev in the console
  23. var style = document.createElement('style');
  24. style.type = 'text/css';
  25.  
  26. /* TESTING
  27. * SET THESE PROPERTIES IN CSS IN PLACE OF CURRENT DISPLAY:NONE
  28. * I don't understand what is going on with this, and don't
  29. * and don't have time to work it out, but would suggest there
  30. * is almost certainly a better solution to whatever problem
  31. * this was meant to solve. It is very odd.
  32. */
  33. style.innerHTML = '.page-patient-care-faculty-staff #content-area { position: absolute; left: -99999em; display: block }\n ';
  34.  
  35. // these styles are for testing only, standard drupal search pager
  36. // styling would be better for the real thing
  37. style.innerHTML += '#faculty-alpha-nav { padding:0 !important;list-style:none;float:left;clear:right } #faculty-alpha-nav li { width: 1.2em; margin-left:2px;height:1em;float:left;cursor:pointer;border:1px solid #444;text-align:center;padding-bottom:3px } #faculty-alpha-nav li:hover { color:#aaa;background:#000 } #faculty-alpha-nav + div { clear:both !important }';
  38.  
  39. document.getElementsByTagName('head')[0].appendChild(style);
  40. /* --------------------------------------------------------------
  41. * -- END TEST-ONLY SECTION
  42. * -- everything below this line is required
  43. */
  44.  
  45. // we need to build a hash of jQuery objects that each contain a reference
  46. // to the outer most div that surrounds a single faculty name, in each case
  47. // it will be the first name to begin with that letter, A-Z
  48. faculty.each(function() {
  49. var alpha = $(this).text().charAt(0);
  50. if (!letters[alpha]) {
  51. node = $(this.parentNode.parentNode.parentNode.parentNode);
  52. node.buttonEl = $(this.parentNode.parentNode.parentNode); // store a reference to the node that the event listeners appear to be attached to for the ajax stuff, unfortunately, synthetic events don't bubble in jQuery before 1.3, or we could just store $(this). We'll trigger a click on this after scrolling to it
  53. if (node.parent().css('display') != 'none')
  54. letters[alpha] = node;
  55. }
  56. });
  57.  
  58. // next we create a list item for each letter that exists
  59. for (prop in letters) {
  60. if (Object.prototype.hasOwnProperty.call(letters, prop)) {
  61. listItems += '<li>' + prop + '</li>';
  62. }
  63. }
  64.  
  65. navList.innerHTML = listItems;
  66. // overwrite the reference to the UL node with a jQuery object containing it
  67. navList = $(navList);
  68. // and insert it into the DOM after the block title
  69. rootBlock.find('h2').eq(0).css('float', 'left').after(navList);
  70.  
  71. // we need a function to do the scrolling
  72. function scrollTo(container, stopAt) {
  73. if (!!stopAt[0].offsetParent) {
  74. container.animate({scrollTop: stopAt.position().top}, 333);
  75. // the same event should trigger adding and removing the button active
  76. // class. It doesn't at the moment, but this would be an easy fix.
  77. return stopAt.buttonEl.trigger('click');
  78. }
  79. }
  80.  
  81. // there's no event delegation in the version of jQuery that ships with Drupal,
  82. // but for clicks it is very simple to do
  83. navList.bind('click', function(e) {
  84. if (e.target.nodeName.toLowerCase() == 'li')
  85. return scrollTo(nameOuter, letters[e.target.innerHTML])
  86. });
  87. }
  88. }());
Add Comment
Please, Sign In to add comment