You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

popcorn.chattimeline.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // PLUGIN: Timeline
  2. (function ( Popcorn ) {
  3. /**
  4. * chat-timeline popcorn plug-in
  5. * Adds data associated with a certain time in the video, which creates a scrolling view of each item as the video progresses
  6. * Options parameter will need a start, target, title, and text
  7. * -Start is the time that you want this plug-in to execute
  8. * -End is the time that you want this plug-in to stop executing, tho for this plugin an end time may not be needed ( optional )
  9. * -Target is the id of the DOM element that you want the timeline to appear in. This element must be in the DOM
  10. * -Name is the name of the current chat message sender
  11. * -Text is text is simply related text that will be displayed
  12. * -direction specifies whether the timeline will grow from the top or the bottom, receives input as "UP" or "DOWN"
  13. * @param {Object} options
  14. *
  15. * Example:
  16. var p = Popcorn("#video")
  17. .timeline( {
  18. start: 5, // seconds
  19. target: "timeline",
  20. name: "Seneca",
  21. text: "Welcome to seneca",
  22. } )
  23. *
  24. */
  25. var i = 1;
  26. Popcorn.plugin( "chattimeline" , function( options ) {
  27. var target = document.getElementById( options.target ),
  28. contentDiv = document.createElement( "div" ),
  29. goingUp = true;
  30. contentDiv.style.display = "none";
  31. contentDiv.setAttribute('aria-hidden', true);
  32. contentDiv.id = "timelineDiv" + i;
  33. // Default to up if options.direction is non-existant or not up or down
  34. options.direction = options.direction || "up";
  35. if ( options.direction.toLowerCase() === "down" ) {
  36. goingUp = false;
  37. }
  38. if ( target ) {
  39. // if this isnt the first div added to the target div
  40. if( goingUp ){
  41. // insert the current div before the previous div inserted
  42. target.insertBefore( contentDiv, target.firstChild );
  43. }
  44. else {
  45. target.appendChild( contentDiv );
  46. }
  47. }
  48. i++;
  49. contentDiv.innerHTML = "<strong>" + options.name + ":</strong>" + options.message;
  50. //If chat message contains a link, we add to it a target attribute
  51. //So when the user clicks on it, it opens in a new tab
  52. $(contentDiv).find('a').attr('target', '_blank');
  53. return {
  54. start: function( event, options ) {
  55. contentDiv.style.display = "block";
  56. if ($("#exposechat").is(':checked')) {
  57. contentDiv.setAttribute('aria-hidden', false);
  58. }
  59. if( options.direction === "down" ) {
  60. target.scrollTop = target.scrollHeight;
  61. }
  62. if ($("#accEnabled").is(':checked'))
  63. addTime(7);
  64. },
  65. end: function( event, options ) {
  66. contentDiv.style.display = "none";
  67. contentDiv.setAttribute('aria-hidden', true);
  68. },
  69. _teardown: function( options ) {
  70. ( target && contentDiv ) && target.removeChild( contentDiv ) && !target.firstChild
  71. }
  72. };
  73. },
  74. {
  75. options: {
  76. start: {
  77. elem: "input",
  78. type: "number",
  79. label: "Start"
  80. },
  81. end: {
  82. elem: "input",
  83. type: "number",
  84. label: "End"
  85. },
  86. target: "feed-container",
  87. name: {
  88. elem: "input",
  89. type: "text",
  90. label: "Name"
  91. },
  92. message: {
  93. elem: "input",
  94. type: "text",
  95. label: "Message"
  96. },
  97. direction: {
  98. elem: "select",
  99. options: [ "DOWN", "UP" ],
  100. label: "Direction",
  101. optional: true
  102. }
  103. }
  104. });
  105. })( Popcorn );