]> git.0d.be Git - panikweb.git/blobdiff - panikweb_templates/static/js/specifics.js
add support for timestamps in description text
[panikweb.git] / panikweb_templates / static / js / specifics.js
index 4e44d159f46cedf21a0ea384e205c9ad09d4ed30..bce88e34d26f407a746d44495824b305dd003bc1 100644 (file)
@@ -521,6 +521,24 @@ $(function() {
                        return false;
                });
 
+               if ($('.sound + .content .text  ').length) {
+                       var text_content = $('.sound + .content .text')[0];
+                       text_content.innerHTML = text_content.innerHTML.replace(
+                               /[0-9][0-9]+:[0-9][0-9]/g,
+                               function(x) { return '<span class="timestamp">' + x + "</span>"; });
+                       $(text_content).find('span.timestamp').on('click', function() {
+                               var $waveform = $('div.waveform');
+                               var total_duration = parseFloat($waveform.data('duration'));
+                               var nb_ticks = $waveform.find('span').length;
+                               var timestamp = $(this).text().split(':');
+                               var timestamp_position = timestamp[0] * 60 + timestamp[1] * 1;
+                               var tick_idx = parseInt(nb_ticks * timestamp_position / total_duration);
+                               // twice to get play then set position
+                               $('span[data-tick-index=' + tick_idx + ']').trigger('click');
+                               $('span[data-tick-index=' + tick_idx + ']').trigger('click');
+                       });
+               }
+
                if (document.cookie.indexOf('panikdb=on') != -1) {
                        panikdb_path = null;
                        if (window.location.pathname.indexOf('/emissions/') == 0) {