timeline.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function () {
  2. 'use strict';
  3. var Timeline = function (options) {
  4. this.options = options;
  5. var self = this;
  6. this.init = function () {
  7. if (this.options.$focus) {
  8. this.options.$focus.focus();
  9. delete this.options.$focus;
  10. }
  11. self.options.$timeline.find('.debug-timeline-panel__item a').tooltip();
  12. return self;
  13. };
  14. this.setFocus = function ($elem) {
  15. this.options.$focus = $elem;
  16. return $elem;
  17. };
  18. this.affixTop = function (refresh) {
  19. if (!this.options.affixTop || refresh) {
  20. this.options.affixTop = self.options.$header.offset().top;
  21. }
  22. return this.options.affixTop;
  23. };
  24. $(document).on('pjax:success', function () {
  25. self.init()
  26. });
  27. $(window).on('resize', function () {
  28. self.affixTop(true);
  29. });
  30. self.options.$header
  31. .on('dblclick', function () {
  32. self.options.$timeline.toggleClass('inline');
  33. })
  34. .on('click', 'button', function () {
  35. self.options.$timeline.toggleClass('inline');
  36. });
  37. self.options.$search.on('change', function () {
  38. self.setFocus($(this)).submit();
  39. });
  40. self.options.$timeline.affix({
  41. offset: {
  42. top: function () {
  43. return self.affixTop()
  44. }
  45. }
  46. });
  47. this.init();
  48. };
  49. (new Timeline({
  50. '$timeline': $('.debug-timeline-panel'),
  51. '$header': $('.debug-timeline-panel__header'),
  52. '$search': $('.debug-timeline-panel__search input')
  53. }));
  54. })();