Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
875 lars 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
 
34
		var to1 = false;
35
		$(window).resize(function () {
36
			if(to1) { clearTimeout(to1); }
37
			to1 = setTimeout(function () {
38
				$('.page').css('minHeight','0px').css('minHeight', ($(document).height() - $('#head').outerHeight()) + 'px');
39
			},50);
40
		});
41
 
42
		$('.tab-content').children().hide().eq(0).show();
43
		$('.nav a').on('click', function () { $(this).blur(); });
44
 
45
		$.address
46
			//.state(window.location.protocol + '//' + window.location.host + window.location.pathname.replace(/^(.*?\/docs\/).*$/ig, '$1'))
47
			.init(function(e) {
48
				$('a:not([href^=http])').not($('.demo a')).address().on('click', function () { if($.address.pathNames().length < 2 && !$.address.parameter('f')) { $(document).scrollTop(0); } });
49
			})
50
			.change(function(e) {
51
				var page, elem, cont, srch;
52
				if(!e.pathNames.length || !$('#content').children('#' + e.pathNames[0]).length) {
53
					$('#menu a').eq(0).click();
54
					return;
55
				}
56
				page = e.pathNames[0];
57
 
58
				$('#menu').find('a[href$="'+page+'"]').blur().parent().addClass('active').siblings().removeClass('active');
59
				cont = $('#content').children('#' + page).show().siblings().hide().end();
60
				if(page === 'api') {
61
					search($.address.parameter('q') ? decodeURIComponent($.address.parameter('q')) : '');
62
					filter($.address.parameter('f') ? decodeURIComponent($.address.parameter('f')) : '');
63
				}
64
				else {
65
					$('#srch').val('');
66
					cont.find('.item').show();
67
					elem = e.pathNames[1] ? cont.find('#' + e.pathNames[1]) : [];
68
					if(elem.length) {
69
						if(elem.hasClass('tab-content-item')) {
70
							elem.siblings().hide().end().show().parent().prev().children().removeClass('active').eq(elem.index()).addClass('active');
71
						}
72
						else {
73
							elem[0].scrollIntoView();
74
						}
75
					}
76
					//else {
77
					//	document.documentElement.scrollTop = 0;
78
					//}
79
				}
80
				$(window).resize();
81
			});
82
 
83
		var to2 = false;
84
		$('#srch').on('keyup', function () {
85
			if(to2) { clearTimeout(to2); }
86
			to2 = setTimeout(function () {
87
				var f = $.address.parameter('f'),
88
					q = $('#srch').val(),
89
					d = [];
90
				if(q && q.length) {
91
					d.push('q=' + q);
92
				}
93
				if(f && f.length && false) {
94
					d.push('f=' + f);
95
				}
96
				$.address.value('/api/' + (d.length ? '?' + d.join('&') : ''));
97
			}, 250);
98
		});
99
 
100
		var container = $('#api_inner'), str;
101
		$.getJSON('./jstree.json', function (data) {
102
			//return;
103
			$.each(data, function (ii, v) {
104
				if(v.description.full.indexOf('<p>lobals') === 0) { return true; }
105
				if(v.ignore) { return true; }
106
				var str = '', name, plugin, internal, params = [], retrn, priv = false, evnt = false, trig, i, j;
107
				for(i = 0, j = v.tags.length; i < j; i++) {
108
					switch(v.tags[i].type) {
109
						case "name":
110
							name = v.tags[i].string;
111
							break;
112
						case "private":
113
							priv = true;
114
							break;
115
						case "event":
116
							evnt = true;
117
							break;
118
						case "trigger":
119
							trig = v.tags[i].string;
120
							break;
121
						case 'plugin':
122
							plugin = v.tags[i].string;
123
							break;
124
						case 'return':
125
							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>';
126
 
127
							break;
128
						case 'param':
129
							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>');
130
							break;
131
					}
132
				}
133
				str += '<div class="item '+(priv?'private':'')+'" rel="'+(name?name.replace('"',''):'')+'">';
134
				if(name) {
135
					if(name.indexOf('(') !== -1 && name.indexOf('$(') === -1) {
136
						name = name.split('(');
137
						name = '<strong>' + name[0] + '</strong> (' + name[1];
138
					}
139
					str += '<h4><code class="'+(name.indexOf('(') === -1 ? (evnt ? 'evnt' : 'prop') : 'func')+'">'+name+(evnt?' Event <i class="glyphicon glyphicon-flash"></i>' : '')+'</code>';
140
					if(plugin) { str += '<code class="meta plugin"><i class="glyphicon glyphicon-leaf"></i> '+plugin+' plugin</code> '; }
141
					if(priv) { str += '<code class="meta">private</code> '; }
142
					str += '</h4>';
143
				}
144
				str += '<div class="' + (name ? "item-inner" : "" ) + '">';
145
				str += '<div>'+ v.description.full +'</div>';
146
				if(params.length) {
147
					str += '<ul class="params list-unstyled">';
148
					for(var k = 0, l = params.length; k < l; k++) {
149
						str += '<li>' + params[k] + '</li>';
150
					}
151
					str += '</ul>';
152
				}
153
				if(retrn) {
154
					str += retrn;
155
				}
156
				if(trig) {
157
					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>';
158
				}
159
				str += '</div>';
160
				str += '</div>';
161
				container.append(str);
162
			});
163
 
164
			$('#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');
165
 
166
			$('.item > h4').on('click', function () {
167
				var r = $(this).parent().attr('rel');
168
				if(r && r.length) {
169
					var q = $.address.parameter('q');
170
					if($.address.parameter('f') === r) {
171
						$.address.value($.address.pathNames()[0] + '/' + (q ? '?q=' + q : ''));
172
					}
173
					else {
174
						$.address.value($.address.pathNames()[0] + '/?' + (q ? 'q=' + q + '&' : '') + 'f=' +  r);
175
					}
176
				}
177
				//$(this).next().slideToggle();
178
			});
179
			//$('.item > h4 > code').on('click', function () { $('#srch').val($(this).text().replace(' Event','')).keyup(); });
180
 
181
			container.find('pre').each(function () {
182
				var d = $('<div>'),
183
					p = $(this).closest('.item').find('.item-inner');
184
				$(this).prev().appendTo(d);
185
				$(this).appendTo(d);
186
				p.append(d);
187
			});
188
 
189
			if($('#srch').val().length) {
190
				search(decodeURIComponent($.address.parameter('q')));
191
			}
192
			filter(decodeURIComponent($.address.parameter('f')));
193
		});
194
	});
195
}(jQuery));