docker: fix build without submodule
[awesomized/ext-ion] / docs / v0.0 / index.js
1 "use strict";
2
3 $(function() {
4 var mdref = {
5 log: function log() {
6 console.log.apply(console, arguments);
7 },
8 is_constant: function is_constant(s) {
9 s = s.replace(/v\d+(_\d+)?$/, "");
10 if (s.length < 2) {
11 return false;
12 }
13 return s.toUpperCase(s) === s;
14 },
15 is_variable: function is_variable(s) {
16 return s.substring(0,1) === "$";
17 },
18 type: function type(s, nn) {
19 var i, j, t;
20 // mdref.log("type", s);
21 // nothing
22 if (!s.match(/[a-zA-Z]/)) {
23 return;
24 }
25
26 switch (s) {
27 // types
28 case "void":
29 case "bool":
30 case "int":
31 case "float":
32 case "string":
33 case "resource":
34 case "array":
35 case "object":
36 case "callable":
37 case "mixed":
38 // Zend/SPL
39 case "stdClass":
40 case "Exception":
41 case "ErrorException":
42 case "RuntimeException":
43 case "UnexpectedValueException":
44 case "DomainException":
45 case "InvalidArgumentException":
46 case "BadMethodCallException":
47 case "Closure":
48 case "Generator":
49 case "Countable":
50 case "Serializable":
51 case "Traversable":
52 case "Iterator":
53 case "IteratorAggregate":
54 case "RecursiveIterator":
55 case "ArrayAccess":
56 case "ArrayObject":
57 case "ArrayIterator":
58 case "RecursiveArrayIterator":
59 case "SeekableIterator":
60 case "SplObserver":
61 case "SplSubject":
62 case "SplObjectStorage":
63 case "JsonSerializable":
64 return "<code>";
65
66 // keywords
67 case "is":
68 if (nn !== "H1") {
69 return;
70 }
71 case "extends":
72 case "implements":
73 if (nn === "H1") {
74 return "<br>&nbsp;<em>";
75 }
76 case "class":
77 case "enum":
78 case "interface":
79 case "namespace":
80 case "public":
81 case "protected":
82 case "private":
83 case "static":
84 case "final":
85 case "abstract":
86 case "self":
87 case "parent":
88 // phrases
89 case "Optional":
90 case "optional":
91 return "<em>";
92 }
93
94 // class members
95 if (-1 !== (i = s.indexOf("::"))) {
96 t = s.substring(i+2);
97 if (!mdref.is_constant(t) && !mdref.is_variable(t)) {
98 // methods
99 return "<a href=\"" + s.replace(/::|\\/g, "/") + "\">";
100 }
101 }
102 if (-1 !== (j = s.lastIndexOf("\\")) && s.substr(j+1,1) !== "n") {
103 t = s.substring(j+1);
104 if (!mdref.is_constant(t) || s.match(/\\/g).length <= 1) {
105 return "<a href=\"" + s.replace(/\\/g, "/").replace(/::/, "#") + "\">";
106 }
107 return "<a href=\"" + s.substring(0,j).replace(/\\/g, "/") + "#" + t + "\">";
108 }
109
110 switch (s.toLowerCase()) {
111 // variables
112 default:
113 if (!mdref.is_variable(s)) {
114 break;
115 }
116 // special constants
117 case "null":
118 case "true":
119 case "false":
120 return "<span class=\"var\">";
121 }
122
123 // constants
124 if (mdref.is_constant(s)) {
125 return "<span class=\"constant\">";
126 }
127 },
128 wrap: function wrap(n, nn) {
129 var $n = $(n)
130 var a = [];
131
132 $n.text().split(/([^a-zA-Z0-9_\\\$:]+)/).forEach(function(v) {
133 var t;
134
135 if ((t = mdref.type(v.replace(/:$/, ""), nn))) {
136 a.push($(t).text(v));
137 } else if (a.length && a[a.length-1].nodeName === "#text") {
138 /* if we already have a text node and the next is also gonna be a text
139 * node, then join them, becuase chrome v30+ or something eats whitespace
140 * for breakfast, lunch and dinner!
141 */
142 a[a.length-1].textContent += v;
143 } else {
144 a.push(document.createTextNode(v));
145 }
146 });
147 $n.replaceWith(a);
148 },
149 walk: function walk(i, e) {
150 // mdref.log("walk", i, e);
151
152 switch (e.nodeName) {
153 case "H1":
154 case "H2":
155 case "H3":
156 case "H4":
157 case "H5":
158 case "H6":
159 if (e.id.length) {
160 var href = document.location.pathname;
161 var perm = $("<a class=\"permalink\" href=\""+href+"#\">#</a>");
162 if (e.nodeName === "H1") {
163 perm.prependTo(e);
164 } else {
165 perm.attr("href", function(i, href) {
166 return href + e.id;
167 });
168 perm.appendTo(e);
169 }
170 }
171 break;
172 }
173
174 $.each($.makeArray(e.childNodes), function(i, n) {
175 switch (n.nodeName) {
176 case "A":
177 case "BR":
178 case "HR":
179 case "EM":
180 case "CODE":
181 case "SPAN":
182 break;
183 case "#text":
184 mdref.wrap(n, e.nodeName);
185 break;
186 default:
187 mdref.walk(-1, n);
188 break;
189 }
190 });
191 },
192 blink: function blink(c) {
193 var $c = $(c);
194
195 $c.fadeOut("fast").queue(function(next) {
196 this.style.color = "red";
197 next();
198 }).fadeIn("fast").fadeOut("slow").queue(function(next) {
199 this.style.color = "";
200 next();
201 }).fadeIn("slow");
202 },
203 hashchange: function hashchange() {
204 if (location.hash.length > 1) {
205 var e;
206 if ((e = document.getElementById(location.hash.substring(1)))) {
207 mdref.blink(e);
208 } else {
209 var hash = location.hash.substring(1);
210 var name = mdref.is_variable(hash) ? ".var" : ".constant";
211 var scrolled = false;
212
213 $(name).each(hash.substring(hash.length-1) === "_" ? function(i, c) {
214 if (c.textContent.substring(0, hash.length) === hash) {
215 if (!scrolled) {
216 $(window).scrollTop($(c).offset().top - 100);
217 scrolled = true;
218 }
219 mdref.blink(c);
220 }
221 } : function(i, c) {
222 if (c.textContent === hash) {
223 $(window).scrollTop($(c).offset().top - 100);
224 mdref.blink(c);
225 return false;
226 }
227 });
228 }
229 }
230 }
231 };
232
233 $("h1,h2,h3,h4,h5,h6,p,li,code,td").each(mdref.walk);
234 $(window).on("hashchange", mdref.hashchange);
235 mdref.hashchange();
236
237 $("#disqus_activator").on("click", function() {
238 var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
239 dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
240 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
241 });
242 $.ajax("https://disqus.com/api/3.0/threads/details.json?thread:ident="+(disqus_identifier||"index")+"&forum=mdref&api_key=VmhVG4z5jjtY8SCaMstOjfUuwniMv43Xy9FCU9YfEzhsrl95dNz1epykXSJn8jt9"). then(function(json) {
243 if (json && json.response) {
244 $("#disqus_activator span").text(json.response.posts);
245 }
246 });
247 setTimeout(function() {
248 $("footer").addClass("hidden");
249 }, 1000);
250 });