JAVASCRIPT 12
Dialogue.js Guest on 6th April 2021 03:14:56 AM
  1. function Dialogue(container) {
  2.    
  3.     this.container = container;
  4.     this.timeToLines = [];
  5.  
  6.     _.each(this.container.children, function(c) {
  7.  
  8.         c.start = parseFloat(c.getAttribute('data-start'));
  9.         c.end = parseFloat(c.getAttribute('data-end'));
  10.         this.timeToLines.push(c);
  11.  
  12.     }, this);
  13.  
  14.     this.timeToLines.sort(function(a, b) {
  15.         return a.start - b.start;
  16.     });
  17.  
  18.  
  19. };
  20.  
  21. Dialogue.prototype.show = function(position) {
  22.  
  23. };
  24.  
  25. Dialogue.prototype.hide = function() {
  26.     if (this.lastLine) this.lastLine.classList.remove('showing');
  27. };
  28.  
  29. Dialogue.prototype.update = function(position) {
  30.  
  31.     var currentLine;
  32.  
  33.     _.each(this.timeToLines, function(line) {
  34.  
  35.         if (position >= line.start && position <= line.end) {
  36.             currentLine = line;
  37.         }
  38.  
  39.     });
  40.  
  41.  
  42.     if (currentLine != this.lastLine) {
  43.         if (currentLine) {
  44.             currentLine.classList.add('showing');
  45.         }
  46.         if (this.lastLine) {
  47.             this.lastLine.classList.remove('showing');
  48.         }
  49.     }
  50.  
  51.     this.lastLine = currentLine;
  52.  
  53. };

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.