No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

232 líneas
6.6 KiB

  1. // jump modal
  2. $(function() {
  3. var all;
  4. var visible;
  5. var active = -1;
  6. var lastFilter = '';
  7. var $body = $('#x-jump-body');
  8. var $list = $('#x-jump-list');
  9. var $filter = $('#x-jump-filter');
  10. var $modal = $('#x-jump');
  11. var update = function(filter) {
  12. lastFilter = filter;
  13. if (active >= 0) {
  14. visible[active].e.removeClass('active');
  15. active = -1;
  16. }
  17. visible = []
  18. var re = new RegExp(filter.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), "gi");
  19. all.forEach(function (id) {
  20. id.e.detach();
  21. var text = id.text;
  22. if (filter) {
  23. text = id.text.replace(re, function (s) { return '<b>' + s + '</b>'; });
  24. if (text == id.text) {
  25. return
  26. }
  27. }
  28. id.e.html(text + ' ' + '<i>' + id.kind + '</i>');
  29. visible.push(id);
  30. });
  31. $body.scrollTop(0);
  32. if (visible.length > 0) {
  33. active = 0;
  34. visible[active].e.addClass('active');
  35. }
  36. $list.append($.map(visible, function(identifier) { return identifier.e; }));
  37. }
  38. var incrActive = function(delta) {
  39. if (visible.length == 0) {
  40. return
  41. }
  42. visible[active].e.removeClass('active');
  43. active += delta;
  44. if (active < 0) {
  45. active = 0;
  46. $body.scrollTop(0);
  47. } else if (active >= visible.length) {
  48. active = visible.length - 1;
  49. $body.scrollTop($body[0].scrollHeight - $body[0].clientHeight);
  50. } else {
  51. var $e = visible[active].e;
  52. var t = $e.position().top;
  53. var b = t + $e.outerHeight(false);
  54. if (t <= 0) {
  55. $body.scrollTop($body.scrollTop() + t);
  56. } else if (b >= $body.outerHeight(false)) {
  57. $body.scrollTop($body.scrollTop() + b - $body.outerHeight(false));
  58. }
  59. }
  60. visible[active].e.addClass('active');
  61. }
  62. $modal.on('show.bs.modal', function() {
  63. if (!all) {
  64. all = []
  65. var kinds = {'c': 'constant', 'v': 'variable', 'f': 'function', 't': 'type', 'd': 'field', 'm': 'method'}
  66. $('*[id]').each(function() {
  67. var e = $(this);
  68. var id = e.attr('id');
  69. if (/^[^_][^-]*$/.test(id)) {
  70. all.push({
  71. text: id,
  72. ltext: id.toLowerCase(),
  73. kind: kinds[e.closest('[data-kind]').attr('data-kind')],
  74. e: $('<a/>', {href: '#' + id, 'class': 'list-group-item', tabindex: '-1'})
  75. });
  76. }
  77. });
  78. all.sort(function (a, b) {
  79. if (a.ltext > b.ltext) { return 1; }
  80. if (a.ltext < b.ltext) { return -1; }
  81. return 0
  82. });
  83. }
  84. }).on('shown.bs.modal', function() {
  85. update('');
  86. $filter.val('').focus();
  87. }).on('hide.bs.modal', function() {
  88. $filter.blur();
  89. }).on('click', '.list-group-item', function() {
  90. $modal.modal('hide');
  91. });
  92. $filter.on('change keyup', function() {
  93. var filter = $filter.val();
  94. if (filter.toUpperCase() != lastFilter.toUpperCase()) {
  95. update(filter);
  96. }
  97. }).on('keydown', function(e) {
  98. switch(e.which) {
  99. case 38: // up
  100. incrActive(-1);
  101. e.preventDefault();
  102. break;
  103. case 40: // down
  104. incrActive(1);
  105. e.preventDefault();
  106. break;
  107. case 13: // enter
  108. if (active >= 0) {
  109. visible[active].e[0].click();
  110. }
  111. break
  112. }
  113. });
  114. });
  115. $(function() {
  116. if ("onhashchange" in window) {
  117. var highlightedSel = "";
  118. window.onhashchange = function() {
  119. if (highlightedSel) {
  120. $(highlightedSel).removeClass("highlighted");
  121. }
  122. highlightedSel = window.location.hash.replace( /(:|\.|\[|\]|,)/g, "\\$1" );
  123. if (highlightedSel && (highlightedSel.indexOf("example-") == -1)) {
  124. $(highlightedSel).addClass("highlighted");
  125. }
  126. };
  127. window.onhashchange();
  128. }
  129. });
  130. // keyboard shortcuts
  131. $(function() {
  132. var prevCh = null, prevTime = 0, modal = false;
  133. $('.modal').on({
  134. show: function() { modal = true; },
  135. hidden: function() { modal = false; }
  136. });
  137. $(document).on('keypress', function(e) {
  138. var combo = e.timeStamp - prevTime <= 1000;
  139. prevTime = 0;
  140. if (modal) {
  141. return true;
  142. }
  143. var t = e.target.tagName
  144. if (t == 'INPUT' ||
  145. t == 'SELECT' ||
  146. t == 'TEXTAREA' ) {
  147. return true;
  148. }
  149. if (e.target.contentEditable && e.target.contentEditable == 'true') {
  150. return true;
  151. }
  152. if (e.metaKey || e.ctrlKey) {
  153. return true;
  154. }
  155. var ch = String.fromCharCode(e.which);
  156. if (combo) {
  157. switch (prevCh + ch) {
  158. case "gg":
  159. $('html,body').animate({scrollTop: 0},'fast');
  160. return false;
  161. case "gb":
  162. $('html,body').animate({scrollTop: $(document).height()},'fast');
  163. return false;
  164. case "gi":
  165. if ($('#pkg-index').length > 0) {
  166. $('html,body').animate({scrollTop: $("#pkg-index").offset().top},'fast');
  167. return false;
  168. }
  169. case "ge":
  170. if ($('#pkg-examples').length > 0) {
  171. $('html,body').animate({scrollTop: $("#pkg-examples").offset().top},'fast');
  172. return false;
  173. }
  174. }
  175. }
  176. switch (ch) {
  177. case "/":
  178. $('#x-search-query').focus();
  179. return false;
  180. case "?":
  181. $('#x-shortcuts').modal();
  182. return false;
  183. case "f":
  184. if ($('#x-jump').length > 0) {
  185. $('#x-jump').modal();
  186. return false;
  187. }
  188. }
  189. prevCh = ch
  190. prevTime = e.timeStamp
  191. return true;
  192. });
  193. });
  194. // misc
  195. $(function() {
  196. $('span.timeago').timeago();
  197. if (window.location.hash.substring(0, 9) == '#example-') {
  198. var id = '#ex-' + window.location.hash.substring(9);
  199. $(id).addClass('in').removeClass('collapse').height('auto');
  200. }
  201. $(document).on("click", "input.click-select", function(e) {
  202. $(e.target).select();
  203. });
  204. $('body').scrollspy({
  205. target: '.gddo-sidebar',
  206. offset: 10
  207. });
  208. });