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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. // Default to empty if not used
  50. //options.innerHTML = options.innerHTML || "";
  51. contentDiv.innerHTML = "<strong>" + options.name + ":</strong>" + options.message;
  52. return {
  53. start: function( event, options ) {
  54. contentDiv.style.display = "block";
  55. if ($("#exposechat").is(':checked')) {
  56. contentDiv.setAttribute('aria-hidden', false);
  57. }
  58. if( options.direction === "down" ) {
  59. target.scrollTop = target.scrollHeight;
  60. }
  61. if ($("#accEnabled").is(':checked'))
  62. addTime(7);
  63. },
  64. end: function( event, options ) {
  65. contentDiv.style.display = "none";
  66. contentDiv.setAttribute('aria-hidden', true);
  67. },
  68. _teardown: function( options ) {
  69. ( target && contentDiv ) && target.removeChild( contentDiv ) && !target.firstChild
  70. }
  71. };
  72. },
  73. {
  74. options: {
  75. start: {
  76. elem: "input",
  77. type: "number",
  78. label: "Start"
  79. },
  80. end: {
  81. elem: "input",
  82. type: "number",
  83. label: "End"
  84. },
  85. target: "feed-container",
  86. name: {
  87. elem: "input",
  88. type: "text",
  89. label: "Name"
  90. },
  91. message: {
  92. elem: "input",
  93. type: "text",
  94. label: "Message"
  95. },
  96. direction: {
  97. elem: "select",
  98. options: [ "DOWN", "UP" ],
  99. label: "Direction",
  100. optional: true
  101. }
  102. }
  103. });
  104. })( Popcorn );