docs.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* global jQuery */
  2. (function ($) {
  3. "use strict";
  4. $(function () {
  5. var search = function (str) {
  6. var tmp = str && str.length ? $.vakata.search(str, true, { threshold : 0.2, fuzzy : true, caseSensitive : false }) : null,
  7. res = $('#api_inner')
  8. .find('.item').hide()
  9. .filter(function () {
  10. return tmp ? tmp.search($(this).find('>h4>code').text()).isMatch : true;
  11. }).show().length;
  12. $('#api_inner').find('#no_res')[ !tmp || res ? 'hide' : 'show' ]();
  13. $('#api_inner').find('#cl_src')[ tmp && res ? 'show' : 'hide' ]();
  14. if(!$('#srch').is(':focus')) {
  15. $('#srch').val(str);
  16. }
  17. $(window).resize();
  18. },
  19. filter = function (str) {
  20. $('.item-inner').hide();
  21. if(str) {
  22. var i = $('.item[rel="'+str+'"]');
  23. if(!i.length) { i = $('.item[rel^="'+str+'"]'); }
  24. if(i && i.length) {
  25. i = i.eq(0);
  26. i.children('.item-inner').show().end();
  27. if(i.offset().top < $(document).scrollTop() || i.offset().top + i.height() > $(document).scrollTop() + $(window).height()) {
  28. i[0].scrollIntoView();
  29. }
  30. }
  31. }
  32. };
  33. var to1 = false;
  34. $(window).resize(function () {
  35. if(to1) { clearTimeout(to1); }
  36. to1 = setTimeout(function () {
  37. $('.page').css('minHeight','0px').css('minHeight', ($(document).height() - $('#head').outerHeight()) + 'px');
  38. },50);
  39. });
  40. $('.tab-content').children().hide().eq(0).show();
  41. $('.nav a').on('click', function () { $(this).blur(); });
  42. $.address
  43. //.state(window.location.protocol + '//' + window.location.host + window.location.pathname.replace(/^(.*?\/docs\/).*$/ig, '$1'))
  44. .init(function(e) {
  45. $('a:not([href^=http])').not($('.demo a')).address().on('click', function () { if($.address.pathNames().length < 2 && !$.address.parameter('f')) { $(document).scrollTop(0); } });
  46. })
  47. .change(function(e) {
  48. var page, elem, cont, srch;
  49. if(!e.pathNames.length || !$('#content').children('#' + e.pathNames[0]).length) {
  50. $('#menu a').eq(0).click();
  51. return;
  52. }
  53. page = e.pathNames[0];
  54. $('#menu').find('a[href$="'+page+'"]').blur().parent().addClass('active').siblings().removeClass('active');
  55. cont = $('#content').children('#' + page).show().siblings().hide().end();
  56. if(page === 'api') {
  57. search($.address.parameter('q') ? decodeURIComponent($.address.parameter('q')) : '');
  58. filter($.address.parameter('f') ? decodeURIComponent($.address.parameter('f')) : '');
  59. }
  60. else {
  61. $('#srch').val('');
  62. cont.find('.item').show();
  63. elem = e.pathNames[1] ? cont.find('#' + e.pathNames[1]) : [];
  64. if(elem.length) {
  65. if(elem.hasClass('tab-content-item')) {
  66. elem.siblings().hide().end().show().parent().prev().children().removeClass('active').eq(elem.index()).addClass('active');
  67. }
  68. else {
  69. elem[0].scrollIntoView();
  70. }
  71. }
  72. //else {
  73. // document.documentElement.scrollTop = 0;
  74. //}
  75. }
  76. $(window).resize();
  77. });
  78. var to2 = false;
  79. $('#srch').on('keyup', function () {
  80. if(to2) { clearTimeout(to2); }
  81. to2 = setTimeout(function () {
  82. var f = $.address.parameter('f'),
  83. q = $('#srch').val(),
  84. d = [];
  85. if(q && q.length) {
  86. d.push('q=' + q);
  87. }
  88. if(f && f.length && false) {
  89. d.push('f=' + f);
  90. }
  91. $.address.value('/api/' + (d.length ? '?' + d.join('&') : ''));
  92. }, 250);
  93. });
  94. var container = $('#api_inner'), str;
  95. $.getJSON('./jstree.json', function (data) {
  96. //return;
  97. $.each(data, function (ii, v) {
  98. if(v.description.full.indexOf('<p>lobals') === 0) { return true; }
  99. if(v.ignore) { return true; }
  100. var str = '', name, plugin, internal, params = [], retrn, priv = false, evnt = false, trig, i, j;
  101. for(i = 0, j = v.tags.length; i < j; i++) {
  102. switch(v.tags[i].type) {
  103. case "name":
  104. name = v.tags[i].string;
  105. break;
  106. case "private":
  107. priv = true;
  108. break;
  109. case "event":
  110. evnt = true;
  111. break;
  112. case "trigger":
  113. trig = v.tags[i].string;
  114. break;
  115. case 'plugin':
  116. plugin = v.tags[i].string;
  117. break;
  118. case 'return':
  119. retrn = '<ul class="params list-unstyled"><li><code class="param return">Returns</code><p><code class="type">' + v.tags[i].types.join('</code> <code class="type">') + '</code> ' + v.tags[i].description + '</p></li></ul>';
  120. break;
  121. case 'param':
  122. params.push('<code class="param">' + v.tags[i].name + '</code><p><code class="type">' + v.tags[i].types.join('</code> <code class="type">') + '</code> ' + v.tags[i].description + '</p>');
  123. break;
  124. }
  125. }
  126. str += '<div class="item '+(priv?'private':'')+'" rel="'+(name?name.replace('"',''):'')+'">';
  127. if(name) {
  128. if(name.indexOf('(') !== -1 && name.indexOf('$(') === -1) {
  129. name = name.split('(');
  130. name = '<strong>' + name[0] + '</strong> (' + name[1];
  131. }
  132. str += '<h4><code class="'+(name.indexOf('(') === -1 ? (evnt ? 'evnt' : 'prop') : 'func')+'">'+name+(evnt?' Event <i class="glyphicon glyphicon-flash"></i>' : '')+'</code>';
  133. if(plugin) { str += '<code class="meta plugin"><i class="glyphicon glyphicon-leaf"></i> '+plugin+' plugin</code> '; }
  134. if(priv) { str += '<code class="meta">private</code> '; }
  135. str += '</h4>';
  136. }
  137. str += '<div class="' + (name ? "item-inner" : "" ) + '">';
  138. str += '<div>'+ v.description.full +'</div>';
  139. if(params.length) {
  140. str += '<ul class="params list-unstyled">';
  141. for(var k = 0, l = params.length; k < l; k++) {
  142. str += '<li>' + params[k] + '</li>';
  143. }
  144. str += '</ul>';
  145. }
  146. if(retrn) {
  147. str += retrn;
  148. }
  149. if(trig) {
  150. str += '<ul class="params list-unstyled"><li><code class="param trigger">Triggers</code><p><code class="evnt">'+ trig.split(',').join('</code> <code class="evnt">')+'</code></p></li></ul>';
  151. }
  152. str += '</div>';
  153. str += '</div>';
  154. container.append(str);
  155. });
  156. $('#api h3').prepend('<i class="glyphicon glyphicon-leaf"></i>&nbsp;').closest('.item').css({ 'background' : 'white', 'border' : '0', 'borderRadius' : '0', /*'borderBottom' : '1px solid #8b0000', 'textAlign' : 'center',*/ 'marginTop' : '0', 'paddingTop' : '0' }).prev().css('marginBottom', '3em');
  157. $('.item > h4').on('click', function () {
  158. var r = $(this).parent().attr('rel');
  159. if(r && r.length) {
  160. var q = $.address.parameter('q');
  161. if($.address.parameter('f') === r) {
  162. $.address.value($.address.pathNames()[0] + '/' + (q ? '?q=' + q : ''));
  163. }
  164. else {
  165. $.address.value($.address.pathNames()[0] + '/?' + (q ? 'q=' + q + '&' : '') + 'f=' + r);
  166. }
  167. }
  168. //$(this).next().slideToggle();
  169. });
  170. //$('.item > h4 > code').on('click', function () { $('#srch').val($(this).text().replace(' Event','')).keyup(); });
  171. container.find('pre').each(function () {
  172. var d = $('<div>'),
  173. p = $(this).closest('.item').find('.item-inner');
  174. $(this).prev().appendTo(d);
  175. $(this).appendTo(d);
  176. p.append(d);
  177. });
  178. if($('#srch').val().length) {
  179. search(decodeURIComponent($.address.parameter('q')));
  180. }
  181. filter(decodeURIComponent($.address.parameter('f')));
  182. });
  183. });
  184. }(jQuery));