Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
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.

script.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. function initSideNav() {
  2. var leftNavToggle = document.getElementById('sidenav-left-toggle');
  3. var leftDrawer = document.querySelector('.sidebar-offcanvas-left');
  4. var overlay = document.getElementById('overlay-under-drawer');
  5. function toggleBoth() {
  6. if (leftDrawer) {
  7. leftDrawer.classList.toggle('active');
  8. }
  9. if (overlay) {
  10. overlay.classList.toggle('active');
  11. }
  12. }
  13. if (overlay) {
  14. overlay.addEventListener('click', function(e) {
  15. toggleBoth();
  16. });
  17. }
  18. if (leftNavToggle) {
  19. leftNavToggle.addEventListener('click', function(e) {
  20. toggleBoth();
  21. });
  22. }
  23. }
  24. function initSearch(name) {
  25. var searchIndex; // the JSON data
  26. var weights = {
  27. 'library' : 2,
  28. 'class' : 2,
  29. 'typedef' : 3,
  30. 'method' : 4,
  31. 'accessor' : 4,
  32. 'operator' : 4,
  33. 'property' : 4,
  34. 'constructor' : 4
  35. };
  36. function findMatches(q) {
  37. var allMatches = []; // list of matches
  38. function score(element, num) {
  39. num -= element.overriddenDepth * 10;
  40. var weightFactor = weights[element.type] || 4;
  41. return {e: element, score: (num / weightFactor) >> 0};
  42. }
  43. $.each(searchIndex, function(i, element) {
  44. // TODO: prefer matches in the current library
  45. // TODO: help prefer a named constructor
  46. var lowerName = element.name.toLowerCase();
  47. var lowerQualifiedName = element.qualifiedName.toLowerCase();
  48. var lowerQ = q.toLowerCase();
  49. var previousMatchCount = allMatches.length;
  50. if (element.name === q || element.qualifiedName === q) {
  51. // exact match, maximum score
  52. allMatches.push(score(element, 2000));
  53. } else if (element.name === 'dart:'+q) {
  54. // exact match for a dart: library
  55. allMatches.push(score(element, 2000));
  56. } else if (lowerName === 'dart:'+lowerQ) {
  57. // case-insensitive match for a dart: library
  58. allMatches.push(score(element, 1800));
  59. } else if (lowerName === lowerQ || lowerQualifiedName === lowerQ) {
  60. // case-insensitive exact match
  61. allMatches.push(score(element, 1700));
  62. }
  63. // only care about exact matches if length is 2 or less
  64. // and only continue if we didn't find a match above
  65. if (q.length <= 2 || previousMatchCount < allMatches.length) return;
  66. if (element.name.indexOf(q) === 0 || element.qualifiedName.indexOf(q) === 0) {
  67. // starts with
  68. allMatches.push(score(element, 750));
  69. } else if (lowerName.indexOf(lowerQ) === 0 || lowerQualifiedName.indexOf(lowerQ) === 0) {
  70. // case-insensitive starts with
  71. allMatches.push(score(element, 650));
  72. } else if (element.name.indexOf(q) >= 0 || element.qualifiedName.indexOf(q) >= 0) {
  73. // contains
  74. allMatches.push(score(element, 500));
  75. } else if (lowerName.indexOf(lowerQ) >= 0 || lowerQualifiedName.indexOf(lowerQ) >= 0) {
  76. // case insensitive contains
  77. allMatches.push(score(element, 400));
  78. }
  79. });
  80. allMatches.sort(function(a, b) {
  81. var x = b.score - a.score;
  82. if (x === 0) {
  83. // tie-breaker: shorter name wins
  84. return a.e.name.length - b.e.name.length;
  85. } else {
  86. return x;
  87. }
  88. });
  89. var sortedMatches = [];
  90. for (var i = 0; i < allMatches.length; i++) {
  91. sortedMatches.push(allMatches[i].e);
  92. }
  93. return sortedMatches;
  94. };
  95. function initTypeahead() {
  96. var search = new URI().query(true)["search"];
  97. if (search) {
  98. var matches = findMatches(search);
  99. if (matches.length != 0) {
  100. window.location = matches[0].href;
  101. return;
  102. }
  103. }
  104. $('#' + name).prop('disabled', false);
  105. $('#' + name).prop('placeholder', 'Search');
  106. $(document).keypress(function(event) {
  107. if (event.which == 47 /* / */) {
  108. event.preventDefault();
  109. $('#' + name).focus();
  110. }
  111. });
  112. $('#' + name + '.typeahead').typeahead({
  113. hint: true,
  114. highlight: true,
  115. minLength: 1
  116. },
  117. {
  118. name: 'elements',
  119. limit: 10,
  120. source: function(q, cb) { cb(findMatches(q)); },
  121. display: function(element) { return element.name; },
  122. templates: {
  123. suggestion: function(match) {
  124. return [
  125. '<div data-href="' + match.href + '">',
  126. match.name,
  127. ' ',
  128. match.type.toLowerCase(),
  129. (match.enclosedBy ? [
  130. '<div class="search-from-lib">from ',
  131. match.enclosedBy.name,
  132. '</div>'].join('') : ''),
  133. '</div>'
  134. ].join('');
  135. }
  136. }
  137. });
  138. var typeaheadElement = $('#' + name + '.typeahead');
  139. var typeaheadElementParent = typeaheadElement.parent();
  140. var selectedSuggestion;
  141. typeaheadElement.on("keydown", function (e) {
  142. if (e.keyCode === 13) { // Enter
  143. if (selectedSuggestion == null) {
  144. var suggestion = typeaheadElementParent.find(".tt-suggestion.tt-selectable:eq(0)");
  145. if (suggestion.length > 0) {
  146. var href = suggestion.data("href");
  147. if (href != null) {
  148. window.location = href;
  149. }
  150. }
  151. }
  152. }
  153. });
  154. typeaheadElement.bind('typeahead:select', function(ev, suggestion) {
  155. selectedSuggestion = suggestion;
  156. window.location = suggestion.href;
  157. });
  158. }
  159. var jsonReq = new XMLHttpRequest();
  160. jsonReq.open('GET', 'index.json', true);
  161. jsonReq.addEventListener('load', function() {
  162. searchIndex = JSON.parse(jsonReq.responseText);
  163. initTypeahead();
  164. });
  165. jsonReq.addEventListener('error', function() {
  166. $('#' + name).prop('placeholder', 'Error loading search index');
  167. });
  168. jsonReq.send();
  169. }
  170. document.addEventListener("DOMContentLoaded", function() {
  171. hljs.initHighlightingOnLoad();
  172. initSideNav();
  173. initSearch("search-box");
  174. initSearch("search-body");
  175. });