SnapIndicatorView.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Storytelling
  5. * (C) Copyright IBM Corp. 2014, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['baglass/core-client/js/core-client/ui/core/View', 'jquery'], function (View, $) {
  9. var SnapIndicatorView = View.extend({
  10. id: null,
  11. snapIndicatorRefreshInverval: 100,
  12. snapIndicatorTimer: null,
  13. events: {},
  14. init: function init(options) {
  15. SnapIndicatorView.inherited('init', this, arguments);
  16. this.$slidersHolder = options.$slidersHolder;
  17. this.id = options.id;
  18. this.controller = options.controller;
  19. this.scaleManager = options.scaleManager;
  20. this.$snapIndicator = $(document.createElement('div')).addClass('guideline').css({
  21. position: 'absolute',
  22. height: '100%',
  23. zIndex: 1066,
  24. top: 0,
  25. display: 'block'
  26. });
  27. },
  28. /**
  29. * Renders the timeline
  30. *
  31. * @returns
  32. */
  33. render: function render() {
  34. return this;
  35. },
  36. refreshSnapIndicator: function refreshSnapIndicator(getDragValue, getDraggingElement) {
  37. this.$snapIndicator.css('height', Math.max(this.controller.getTimelineEpisodeCount() * $('.sliderContent').height() + 50, this.$slidersHolder.height() + 50));
  38. this.isDragging = true;
  39. this.$snapIndicator.remove();
  40. var dragValue = getDragValue();
  41. if (dragValue) {
  42. var startTime = dragValue[0] * 1000;
  43. var endTime = dragValue[1] * 1000;
  44. var snapIndicatorTime = this.controller.getSnapIndicatorTime([startTime, endTime], getDraggingElement());
  45. if (snapIndicatorTime.changed === 'start') {
  46. this.$snapIndicator.css('left', this.scaleManager.convertTimeToPosition(snapIndicatorTime.timeRange[0]));
  47. this.$slidersHolder.append(this.$snapIndicator);
  48. } else if (snapIndicatorTime.changed === 'end') {
  49. this.$snapIndicator.css('left', this.scaleManager.convertTimeToPosition(snapIndicatorTime.timeRange[1]));
  50. this.$slidersHolder.append(this.$snapIndicator);
  51. }
  52. }
  53. },
  54. showIndicator: function showIndicator(getDragValue, getDraggingElement) {
  55. this.snapIndicatorTimer = setInterval(this.refreshSnapIndicator.bind(this, getDragValue, getDraggingElement), this.snapIndicatorRefreshInverval);
  56. },
  57. removeIndicator: function removeIndicator() {
  58. if (this.snapIndicatorTimer) {
  59. clearInterval(this.snapIndicatorTimer);
  60. }
  61. this.snapIndicatorTimer = null;
  62. this.$snapIndicator.remove();
  63. }
  64. });
  65. return SnapIndicatorView;
  66. });
  67. //# sourceMappingURL=SnapIndicatorView.js.map