Skip to content

Commit 621e70d

Browse files
committed
tree refactoring
1 parent eebecbd commit 621e70d

File tree

8 files changed

+187
-20
lines changed

8 files changed

+187
-20
lines changed

build-js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2-
closure-compiler --js_output_file resources/public/js/reference.min.js --compilation_level SIMPLE `find ./js-src/ -name '*.js'`
2+
closure-compiler --js_output_file resources/public/js/reference.min.js --compilation_level SIMPLE --formatting PRETTY_PRINT `find ./js-src/ -name '*.js'`
3+
echo build

js-src/api/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $(function() {
1818
api.search.init();
1919

2020
api.tree.expand(location.pathname);
21-
api.breadcrumb.update(api.utils.getEntryFromUrl(location.pathname));
21+
api.breadcrumb.update(api.utils.getEntryFromURL(location.pathname));
2222

2323
api.tree.scrollToEntry(page, location.hash ? location.hash.substr(1) : null);
2424

js-src/api/pageScrolling.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ goog.require('api.tree');
66
* @private
77
* @type {boolean}
88
*/
9-
api.pageSrolling.isTopVisible_ = false;
9+
api.pageScrolling.isTopVisible_ = false;
1010

1111
/**
1212
* @private
1313
* @type {Array}
1414
*/
15-
api.pageSrolling.currentVisible_ = null;
15+
api.pageScrolling.currentVisible_ = null;
1616

1717
/**
1818
* @private
@@ -56,8 +56,8 @@ api.pageScrolling.getFirstVisible_ = function() {
5656
api.pageScrolling.onContentScroll_ = function() {
5757
api.pageScrolling.checkTopVisible_(this.mcs.top);
5858
var el = api.pageScrolling.getFirstVisible_();
59-
if (el && el != api.pageSrolling.currentVisible_) {
60-
api.pageSrolling.currentVisible_ = el;
59+
if (el && el != api.pageScrolling.currentVisible_) {
60+
api.pageScrolling.currentVisible_ = el;
6161
var link = "/" + version + "/" + page + "#" + el;
6262
api.tree.expand(page, el);
6363
api.page.highlight(el, false, false);

js-src/api/tree.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
goog.provide("api.tree");
22

33
goog.require("api.config");
4+
goog.require("api.utils");
45

56
/**
67
* @param {string} entry
@@ -43,10 +44,10 @@ api.tree.expand_ = function(entry, opt_hash) {
4344
* @param {string} path
4445
*/
4546
api.tree.expand = function(path) {
46-
path = cleanupPath(path);
47-
var entry = path.match("^/[^/]+/(.*)$")[1];
47+
path = api.utils.cleanupPath(path);
48+
var entry = path.match("^/[^/]+/(.*)$");
4849
if (entry)
49-
api.tree.expand_(entry);
50+
api.tree.expand_(entry[1]);
5051
};
5152

5253
/**

js-src/api/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ api.utils.cleanupPath = function(target) {
1717
* @return {string}
1818
*/
1919
api.utils.getEntryFromURL = function(path) {
20-
path = cleanupPath(path);
20+
path = api.utils.cleanupPath(path);
2121
return path.match("^/[^/]+/(.*)$")[1];
2222
};

resources/public/js/reference.min.js

Lines changed: 171 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,171 @@
1-
var api={config:{}};api.config.scrollSettings=function(){var a=80,b=100;navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)&&(a=2,b=15);return{scrollInertia:0,theme:"minimal-dark",mouseWheel:{enable:!0,scrollAmount:a},keyboard:{enable:!0,scrollAmount:b,scrollType:"stepless"}}}();api.links={};api.links.typeLinkClickWithScroll=function(a){};api.links.typeLinkClick=function(a){};api.page={};api.page.scrollToEntry=function(a){$(".method-block").removeClass("active");$("#"+a).addClass("active");window.setTimeout(function(){$("#content").css("min-height",$("#content").height());$("#content-wrapper").mCustomScrollbar("scrollTo",$("#"+a),{scrollInertia:700});$(".panel").on("hide.bs.collapse",function(a){var c=$(this).parent().parent();c.hasClass("selected")&&(a.preventDefault(),c.removeClass("selected"))})},200)};api.page.fixLinks=function(){$("#content a.type-link").click(api.links.typeLinkClickWithScroll)};
2-
api.page.fixListings=function(){prettyPrint()};api.page.highlight=function(a,b,c){b=void 0==b?!0:b;c=void 0==c?!0:c;$(".content-container .active").removeClass("active");b&&(b=getEntryFromUrl(location.pathname),doExpandInTree(b,a));c&&setTimeout(function(){$("#content-wrapper").mCustomScrollbar("scrollTo",$("#"+a),{scrollInertia:700})},100);$("#"+a).parent().addClass("active");location.hash=a};api.page.load=function(a,b,c){};api.resize={};api.resize.stopResize_=function(a){$("body").off("mouseup",api.resize.stopResize_);$("body").off("mousemove",api.resize.doResize_)};api.resize.doResize_=function(a){250<a.pageX&&a.pageX<window.innerWidth-300&&($("#menu-bar").css("width",a.pageX),$("#content-wrapper").css("margin-left",a.pageX).css("width",window.innerWidth-a.pageX),$(".breadcrumb").css("left",$("#menu-bar").width()));return!1};
3-
api.resize.startResize_=function(a){$("body").on("mouseup",api.resize.stopResize_);$("body").on("mousemove",api.resize.doResize_);return!1};api.resize.init=function(){$("#size-controller").on("mousedown",api.resize.startResize_)};api.search={};api.search.init=function(){};api.tree={};api.tree.scrollToEntry=function(a,b){var c=$("#tree li[x-data-name='"+(a+(b?"#"+b:""))+"']");window.setTimeout(function(){$("#tree-wrapper").mCustomScrollbar("scrollTo",c.offset().top-120,{scrollInertia:700})},200)};
4-
api.tree.expand_=function(a,b){$("#tree .active").removeClass("active");for(var c=a.split("."),e=0;e<c.length;e++){var d=c.slice(0,e+1).join("."),d=$("#tree li[x-data-name='"+d+"']");d.find(">ul").show();d.find(">a i").removeClass("fa-chevron-right").addClass("fa-chevron-down");d.addClass("active")}b&&(d=$("#tree li.item[x-data-name='"+a+"#"+b+"']"),d.addClass("active"))};api.tree.expand=function(a){a=cleanupPath(a);(a=a.match("^/[^/]+/(.*)$")[1])&&api.tree.expand_(a)};
5-
api.tree.init=function(){$("#tree-wrapper").mCustomScrollbar(api.config.scrollSettings);$("#tree li.group").each(function(){var a=$(this).find(">ul");$(this).find(">a").click(function(b){if(b.ctrlKey||b.metaKey)return!0;a.toggle();a.is(":visible")?$(this).find("i").addClass("fa-chevron-down").removeClass("fa-chevron-right"):$(this).find("i").addClass("fa-chevron-right").removeClass("fa-chevron-down");return api.page.load($(this).attr("href"))})});$("#tree li.item a").click(function(a){return a.ctrlKey||
6-
a.metaKey?!0:api.page.load($(this).attr("href"))})};api.pageScrolling={};api.pageSrolling.isTopVisible_=!1;api.pageSrolling.currentVisible_=null;api.pageScrolling.checkTopVisible_=function(a){0>a?api.pageScrolling.isTopVisible_||($("#top-page-content").fadeIn(),api.pageScrolling.isTopVisible_=!0):api.pageScrolling.isTopVisible_&&($("#top-page-content").fadeOut(),api.pageScrolling.isTopVisible_=!1)};
7-
api.pageScrolling.getFirstVisible_=function(){var a=Number.MAX_VALUE,b=null;$("div.content-block.methods h3").each(function(){var c=$(this),e=Math.abs(c.offset().top-100);e<a&&(a=e,b=c)});return b?b.attr("id"):null};api.pageScrolling.onContentScroll_=function(){api.pageScrolling.checkTopVisible_(this.mcs.top);var a=api.pageScrolling.getFirstVisible_();a&&a!=api.pageSrolling.currentVisible_&&(api.pageSrolling.currentVisible_=a,api.tree.expand(page,a),api.page.highlight(a,!1,!1))};
8-
api.pageScrolling.update=function(){$("#top-page-content").hide();api.pageScrolling.isTopVisible_=!1;api.pageScrolling.currentVisible_=null;$("#content-wrapper").mCustomScrollbar($.extend(api.config.scrollSettings,{callbacks:{onScroll:api.pageScrolling.onContentScroll_}}))};api.pageScrolling.scrollTo=function(a){$("#content-wrapper").mCustomScrollbar("scrollTo",$(a))};api.utils={};api.utils.cleanupPath=function(a){-1!=a.indexOf("http")&&(a=a.substr(a.indexOf("/",a.indexOf("//")+2)));-1!=a.indexOf("#")&&(a=a.substr(0,a.indexOf("#")));return a};api.utils.getEntryFromURL=function(a){a=cleanupPath(a);return a.match("^/[^/]+/(.*)$")[1]};api.breadcrumb={};api.breadcrumb.update=function(a){a=api.utils.cleanupPath(a);$("ol.breadcrumb").html("");a=a.split(".");for(var b=0;b<a.length;b++){var c;b<a.length-1?(c=a.slice(0,b+1).join("."),c=$("<li><a href='/"+version+"/"+c+"'>"+a[b]+"</a></li>"),c.find("a").click(api.links.typeLinkClickWithScroll)):c=$("<li class='active'>"+a[b]+"</li>");$("ol.breadcrumb").append(c)}};api.versions={};api.versions.init=function(){$(".versionselect").on("change",function(){location.href="/"+$(this).find("option:selected").val()+"/try/"+api.utils.getEntryFromUrl(location.pathname)})};api.core={};$(function(){api.versions.init();api.resize.init();api.page.fixLinks();api.page.fixListings();api.tree.init();api.pageScrolling.update();api.search.init();api.tree.expand(location.pathname);api.breadcrumb.update(api.utils.getEntryFromUrl(location.pathname));api.tree.scrollToEntry(page,location.hash?location.hash.substr(1):null);location.hash&&api.pageScrolling.scrollTo(location.hash)});
1+
var api = {config:{}};
2+
api.config.scrollSettings = function() {
3+
var a = 80, b = 100;
4+
navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) && (a = 2, b = 15);
5+
return {scrollInertia:0, theme:"minimal-dark", mouseWheel:{enable:!0, scrollAmount:a}, keyboard:{enable:!0, scrollAmount:b, scrollType:"stepless"}};
6+
}();
7+
api.links = {};
8+
api.links.typeLinkClickWithScroll = function(a) {
9+
};
10+
api.links.typeLinkClick = function(a) {
11+
};
12+
api.page = {};
13+
api.page.scrollToEntry = function(a) {
14+
$(".method-block").removeClass("active");
15+
$("#" + a).addClass("active");
16+
window.setTimeout(function() {
17+
$("#content").css("min-height", $("#content").height());
18+
$("#content-wrapper").mCustomScrollbar("scrollTo", $("#" + a), {scrollInertia:700});
19+
$(".panel").on("hide.bs.collapse", function(a) {
20+
var c = $(this).parent().parent();
21+
c.hasClass("selected") && (a.preventDefault(), c.removeClass("selected"));
22+
});
23+
}, 200);
24+
};
25+
api.page.fixLinks = function() {
26+
$("#content a.type-link").click(api.links.typeLinkClickWithScroll);
27+
};
28+
api.page.fixListings = function() {
29+
prettyPrint();
30+
};
31+
api.page.highlight = function(a, b, c) {
32+
b = void 0 == b ? !0 : b;
33+
c = void 0 == c ? !0 : c;
34+
$(".content-container .active").removeClass("active");
35+
b && (b = getEntryFromUrl(location.pathname), doExpandInTree(b, a));
36+
c && setTimeout(function() {
37+
$("#content-wrapper").mCustomScrollbar("scrollTo", $("#" + a), {scrollInertia:700});
38+
}, 100);
39+
$("#" + a).parent().addClass("active");
40+
location.hash = a;
41+
};
42+
api.page.load = function(a, b, c) {
43+
};
44+
api.resize = {};
45+
api.resize.stopResize_ = function(a) {
46+
$("body").off("mouseup", api.resize.stopResize_);
47+
$("body").off("mousemove", api.resize.doResize_);
48+
};
49+
api.resize.doResize_ = function(a) {
50+
250 < a.pageX && a.pageX < window.innerWidth - 300 && ($("#menu-bar").css("width", a.pageX), $("#content-wrapper").css("margin-left", a.pageX).css("width", window.innerWidth - a.pageX), $(".breadcrumb").css("left", $("#menu-bar").width()));
51+
return !1;
52+
};
53+
api.resize.startResize_ = function(a) {
54+
$("body").on("mouseup", api.resize.stopResize_);
55+
$("body").on("mousemove", api.resize.doResize_);
56+
return !1;
57+
};
58+
api.resize.init = function() {
59+
$("#size-controller").on("mousedown", api.resize.startResize_);
60+
};
61+
api.search = {};
62+
api.search.init = function() {
63+
};
64+
api.utils = {};
65+
api.utils.cleanupPath = function(a) {
66+
-1 != a.indexOf("http") && (a = a.substr(a.indexOf("/", a.indexOf("//") + 2)));
67+
-1 != a.indexOf("#") && (a = a.substr(0, a.indexOf("#")));
68+
return a;
69+
};
70+
api.utils.getEntryFromURL = function(a) {
71+
a = api.utils.cleanupPath(a);
72+
return a.match("^/[^/]+/(.*)$")[1];
73+
};
74+
api.breadcrumb = {};
75+
api.breadcrumb.update = function(a) {
76+
a = api.utils.cleanupPath(a);
77+
$("ol.breadcrumb").html("");
78+
a = a.split(".");
79+
for (var b = 0;b < a.length;b++) {
80+
var c;
81+
b < a.length - 1 ? (c = a.slice(0, b + 1).join("."), c = $("<li><a href='/" + version + "/" + c + "'>" + a[b] + "</a></li>"), c.find("a").click(api.links.typeLinkClickWithScroll)) : c = $("<li class='active'>" + a[b] + "</li>");
82+
$("ol.breadcrumb").append(c);
83+
}
84+
};
85+
api.tree = {};
86+
api.tree.scrollToEntry = function(a, b) {
87+
var c = $("#tree li[x-data-name='" + (a + (b ? "#" + b : "")) + "']");
88+
window.setTimeout(function() {
89+
$("#tree-wrapper").mCustomScrollbar("scrollTo", c.offset().top - 120, {scrollInertia:700});
90+
}, 200);
91+
};
92+
api.tree.expand_ = function(a, b) {
93+
$("#tree .active").removeClass("active");
94+
for (var c = a.split("."), e = 0;e < c.length;e++) {
95+
var d = c.slice(0, e + 1).join("."), d = $("#tree li[x-data-name='" + d + "']");
96+
d.find(">ul").show();
97+
d.find(">a i").removeClass("fa-chevron-right").addClass("fa-chevron-down");
98+
d.addClass("active");
99+
}
100+
b && (d = $("#tree li.item[x-data-name='" + a + "#" + b + "']"), d.addClass("active"));
101+
};
102+
api.tree.expand = function(a) {
103+
a = api.utils.cleanupPath(a);
104+
(a = a.match("^/[^/]+/(.*)$")) && api.tree.expand_(a[1]);
105+
};
106+
api.tree.init = function() {
107+
$("#tree-wrapper").mCustomScrollbar(api.config.scrollSettings);
108+
$("#tree li.group").each(function() {
109+
var a = $(this).find(">ul");
110+
$(this).find(">a").click(function(b) {
111+
if (b.ctrlKey || b.metaKey) {
112+
return !0;
113+
}
114+
a.toggle();
115+
a.is(":visible") ? $(this).find("i").addClass("fa-chevron-down").removeClass("fa-chevron-right") : $(this).find("i").addClass("fa-chevron-right").removeClass("fa-chevron-down");
116+
return api.page.load($(this).attr("href"));
117+
});
118+
});
119+
$("#tree li.item a").click(function(a) {
120+
return a.ctrlKey || a.metaKey ? !0 : api.page.load($(this).attr("href"));
121+
});
122+
};
123+
api.pageScrolling = {};
124+
api.pageScrolling.isTopVisible_ = !1;
125+
api.pageScrolling.currentVisible_ = null;
126+
api.pageScrolling.checkTopVisible_ = function(a) {
127+
0 > a ? api.pageScrolling.isTopVisible_ || ($("#top-page-content").fadeIn(), api.pageScrolling.isTopVisible_ = !0) : api.pageScrolling.isTopVisible_ && ($("#top-page-content").fadeOut(), api.pageScrolling.isTopVisible_ = !1);
128+
};
129+
api.pageScrolling.getFirstVisible_ = function() {
130+
var a = Number.MAX_VALUE, b = null;
131+
$("div.content-block.methods h3").each(function() {
132+
var c = $(this), e = Math.abs(c.offset().top - 100);
133+
e < a && (a = e, b = c);
134+
});
135+
return b ? b.attr("id") : null;
136+
};
137+
api.pageScrolling.onContentScroll_ = function() {
138+
api.pageScrolling.checkTopVisible_(this.mcs.top);
139+
var a = api.pageScrolling.getFirstVisible_();
140+
a && a != api.pageScrolling.currentVisible_ && (api.pageScrolling.currentVisible_ = a, api.tree.expand(page, a), api.page.highlight(a, !1, !1));
141+
};
142+
api.pageScrolling.update = function() {
143+
$("#top-page-content").hide();
144+
api.pageScrolling.isTopVisible_ = !1;
145+
api.pageScrolling.currentVisible_ = null;
146+
$("#content-wrapper").mCustomScrollbar($.extend(api.config.scrollSettings, {callbacks:{onScroll:api.pageScrolling.onContentScroll_}}));
147+
};
148+
api.pageScrolling.scrollTo = function(a) {
149+
$("#content-wrapper").mCustomScrollbar("scrollTo", $(a));
150+
};
151+
api.versions = {};
152+
api.versions.init = function() {
153+
$(".versionselect").on("change", function() {
154+
location.href = "/" + $(this).find("option:selected").val() + "/try/" + api.utils.getEntryFromUrl(location.pathname);
155+
});
156+
};
157+
api.core = {};
158+
$(function() {
159+
api.versions.init();
160+
api.resize.init();
161+
api.page.fixLinks();
162+
api.page.fixListings();
163+
api.tree.init();
164+
api.pageScrolling.update();
165+
api.search.init();
166+
api.tree.expand(location.pathname);
167+
api.breadcrumb.update(api.utils.getEntryFromURL(location.pathname));
168+
api.tree.scrollToEntry(page, location.hash ? location.hash.substr(1) : null);
169+
location.hash && api.pageScrolling.scrollTo(location.hash);
170+
});
171+

src/templates/app.selmer

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div id="search-results-new" style="display:none">
2121
</div>
2222
<div id="header">
23-
<a class="navbar-brand" href="http://anychart.com/">
23+
<a class="navbar-brand" href="//anychart.com/">
2424
<img src="/i/AnyChart-light-empty.png" width="300" height="72" alt="AnyChart">
2525
<div class="chart-row">
2626
<span class="chart-col green"></span>
@@ -103,5 +103,5 @@
103103
<script src="/lib/bootstrap-select.js"></script>
104104
<script src="/lib/bootstrap3-typeahead.min.js"></script>
105105
<script src="/lib/prettiffy/prettify.js" type="text/javascript" charset="utf-8"></script>
106-
<script src="/js/main.js"></script>
106+
<script src="/js/reference.min.js"></script>
107107
</html>

watch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
fswatch -o -r js-src | xargs -n1 -I{} ./build-js

0 commit comments

Comments
 (0)