details.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!-- Details -->
  2. <style>
  3. .details h2 {
  4. margin-bottom: .5em;
  5. margin-top: 0px;
  6. }
  7. .details {
  8. position: relative;
  9. }
  10. .details table {
  11. margin-bottom: .5em;
  12. margin-top: .5em;
  13. border-collapse: collapse;
  14. margin: auto;
  15. }
  16. .details table td, .details table th {
  17. border: 1px solid var(--chrome-border);
  18. padding: .25em;
  19. text-align: center;
  20. }
  21. .details .view {
  22. display: none;
  23. }
  24. .details.has-selection .view {
  25. display: block;
  26. }
  27. .details.has-selection .instructions{
  28. display: none;
  29. }
  30. .details .hbox h2 {
  31. display: inline;
  32. margin: 0px;
  33. margin-right: auto;
  34. }
  35. .details .hbox > * + * {
  36. margin-left: .5em;
  37. }
  38. .details .hbox {
  39. display: flex;
  40. flex-wrap: wrap;
  41. align-items: center;
  42. margin-bottom: 1em;
  43. height: 2em;
  44. }
  45. .details label {
  46. font-weight: bold;
  47. }
  48. td.highlight {
  49. background: var(--accent);
  50. color: white;
  51. color: var(--accent-text);
  52. }
  53. .details details {
  54. margin-top: .5em;
  55. }
  56. .details summary {
  57. margin-bottom: .5em;
  58. }
  59. #delete-confirm.hidden {
  60. display: inline-block;
  61. overflow: hidden;
  62. opacity: 0;
  63. width: 1ch;
  64. height: 1ch;
  65. visibility: hidden;
  66. }
  67. #delete-confirm {
  68. transition: .3s all;
  69. }
  70. </style>
  71. <section class="details">
  72. <h2 class='instructions'>Clip Details</h2>
  73. <div class='instructions'>
  74. When you select a clip/point from the graph it will be displayed here.
  75. If you just loaded the page and are seeing this,
  76. your browser is downloading the examples
  77. and they will display as they arrive.
  78. If you are on a slow connection,
  79. you may wish to start by reading the instructions in the help tab
  80. while you wait.
  81. </div>
  82. <div class='view'>
  83. <div class="hbox">
  84. <h2 id="preview-title"></h2>
  85. <span class='buttons'>
  86. <span id='delete-confirm' class='hidden'>Press again to delete</span>
  87. <button class='delete' title='Delete Clip'>{% include 'trash.svg' %}</button>
  88. <button class='download' title='Download Clip'>{% include 'download.svg' %}</button>
  89. </span>
  90. </div>
  91. <table>
  92. <tr>
  93. <th></th>
  94. <th>Mean</th>
  95. <th>Median</th>
  96. <th>St. dev.</th>
  97. </tr>
  98. <tr>
  99. <th>Pitch</th>
  100. <td id='preview-mean-pitch'>--</td>
  101. <td id='preview-median-pitch'>--</td>
  102. <td class='highlight'><span id='preview-stdev-pitch'></span>*</td>
  103. </tr>
  104. <tr>
  105. <th>Resonance</th>
  106. <td id='preview-mean-resonance'>--</td>
  107. <td id='preview-median-resonance'>--</td>
  108. <td id='preview-stdev-resonance'>--</td>
  109. </tr>
  110. </table>
  111. <br>
  112. <div>
  113. <label for="preview-transcript">Transcript</label>:
  114. <span id='preview-transcript'></span>
  115. </div>
  116. <details>
  117. <summary>Advanced</summary>
  118. <button id='dl-json'>Download JSON</button>
  119. </details>
  120. <hr>
  121. <div>
  122. <small>* In many contexts, greater variation in pitch (standard deviation) is
  123. associated with women's speech, whereas monotone is associated with men's speech.
  124. </small>
  125. </div>
  126. </div>
  127. </section>
  128. <script>
  129. globalState.render(['previewClip'], current => {
  130. if (current.previewClip) {
  131. $('.details').classList.add('has-selection');
  132. $('#preview-title').innerHTML = current.previewClip.title || '';
  133. if (current.previewClip.meanPitch) {
  134. $('#preview-mean-pitch').innerHTML = Math.round(current.previewClip.meanPitch) + 'Hz';
  135. $('#preview-mean-resonance').innerHTML = Math.round(current.previewClip.meanResonance * 100) + '%';
  136. $('#preview-stdev-pitch').innerHTML = Math.round(current.previewClip.stdevPitch) + 'Hz';
  137. $('#preview-stdev-resonance').innerHTML = Math.round(current.previewClip.stdevResonance * 100) + '%';
  138. $('#preview-median-pitch').innerHTML = Math.round(current.previewClip.medianPitch) + 'Hz';
  139. $('#preview-median-resonance').innerHTML = Math.round(current.previewClip.medianResonance * 100) + '%';
  140. }
  141. if (current.previewClip.transcript) {
  142. $('#preview-transcript').innerHTML = current.previewClip.transcript;
  143. }
  144. } else {
  145. $('.details').classList.remove('has-selection');
  146. }
  147. })
  148. $('section.details button.download').addEventListener('click', evt => {
  149. let previewClip = globalState.get('previewClip');
  150. downloadFile(previewClip.audio, previewClip.title);
  151. });
  152. let lastDeletePress = 0;
  153. $('section.details button.delete').addEventListener('click', evt => {
  154. if (Date.now() - lastDeletePress > 4000) {
  155. $('#delete-confirm').classList.remove('hidden');
  156. lastDeletePress = Date.now();
  157. window.setTimeout(() => {
  158. $('#delete-confirm').classList.add('hidden');
  159. }, 4000)
  160. } else {
  161. let previewClip = globalState.get('previewClip');
  162. globalState.mutate('clips', clips => {
  163. let index = clips.indexOf(previewClip);
  164. clips.splice(index, 1);
  165. })
  166. globalState.set('previewClip', null);
  167. }
  168. });
  169. $('#dl-json').addEventListener('click', evt => {
  170. let previewClip = globalState.get('previewClip');
  171. let cloneClip = JSON.parse(JSON.stringify(previewClip));
  172. delete cloneClip.marker;
  173. downloadFile(
  174. 'data:text/json;charset=utf-8,'
  175. + encodeURIComponent(JSON.stringify(cloneClip)),
  176. previewClip.title + '.json'
  177. );
  178. })
  179. </script>