forked from PDLPorters/pdlporters.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
297 lines (269 loc) · 9.06 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Perl Data Language</title>
<link rel="shortcut icon" href="images/favicon.ico" type="image/vnd.microsoft.icon" />
<link rel="stylesheet" type="text/css" href="google-search.css" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="pdl.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>
<script type="text/javascript" src="js/jquery.autocomplete.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.2.custom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rivets/0.7.1/rivets.bundled.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.3/vue.min.js"></script>
<script type="text/javascript" src="js/URI.min.js"></script>
<script type="text/javascript" src="js/jquery.URI.min.js"></script>
<script type="text/javascript" src="js/pdl-www.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17388934-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<!-- BANNER -->
<div class="banner">
<a href="/">
<img src="images/icons/pdl.png" alt="PDL" height="79px" width="146px"/>
</a>
<div id="banner-images"></div>
<form action="">
<input type="hidden" name="size" id="search-size" value="20">
<div class="form-group" style="position: absolute; top: 20px; left: 700px">
<input type="text" name="search" size="41" autofocus="autofocus" autocorrect="off" autocapitalize="off" spellcheck="false" id="search-input" class="form-control home-search-input" placeholder="MetaCPAN Search">
<button type="submit" class="btn search-btn">Search MetaCPAN</button>
</div>
</form>
</div>
<!-- END BANNER -->
<!-- SIDE BAR -->
<div class="sidebar-container">
<div class="sidebar" id="sidebar">
<div rv-each-section="sections">
<h3 rv-text="section.title"></h3>
<ul>
<li rv-each-page="section.pages" rv-class-selected="page.selected">
<a rv-href="page.href" rv-text="page.title"></a>
</li>
</ul>
</div>
</div>
</div>
<!-- END SIDE BAR -->
<!-- MAIN CONTENT -->
<div class="main" id="main">
<app-body :params="params"></app-body>
</div>
<!-- END CONTENT -->
<!-- APPLICATION -->
<template id="search-results-template">
<div id="search" v-if="results.total">
<h2>Search provided by <a href="https://metacpan.org">MetaCPAN</a></h2>
<p>Found {{ results.total }} hits</p><hr>
<p v-for="result in results.records">
<a :href="result.href">{{ result.name }}</a> - {{ result.abstract }}
</p>
</div>
</template>
<script>
Vue.component('search-results', {
template: '#search-results-template',
props: {
query: {
type: String,
required: false,
},
},
data: function() {
return {
raw_results: {},
};
},
computed: {
results: function() {
var ret = {
total: 0,
records: [],
};
var data = this.raw_results;
if ('results' in data) {
ret.total = data.total;
$.each( data.results, function (index, outer) {
var item = outer.hits[0];
if ( !item ) return;
var name = item.documentation || item.module[0].name;
var out = {
name: name,
href: '?docs=' + name,
abstract: item.abstract,
};
ret.records.push(out);
});
}
return ret;
},
},
methods: {
search: function(query) {
var self = this;
self.raw_results = {};
query = query || this.query;
if (!query) return;
$.ajax({
type : "GET",
url : 'https://fastapi.metacpan.org/v1/search/web',
data : {q: query, size: 20, collapsed: 0},
success : function(data) {
self.raw_results = data;
},
}).error( function() { console.log("Error attempting to search metacpan") } );
}
},
mounted: function() { this.search() },
watch: { query: 'search' },
});
</script>
<template id="pod-viewer-template">
<div id="pod-viewer">
<b>See also:</b> <a href="?page=function-ref">How do I search for a function?</a>
<h1 class="title">{{ display_title }}</h1>
<div class="pod" v-html="display_html"></div>
<h2>Thanks</h2>
<p>This documentation was obtained via <a href="https://metacpan.org">MetaCPAN</a></p>
</div>
</template>
<script>
Vue.component('pod-viewer', {
template: '#pod-viewer-template',
props: {
title: {
type: String,
default: '',
},
module: {
type: String,
default: '',
},
},
data: function() {
return {
current_module: '',
pod: '',
};
},
computed: {
display_title: function() {
return this.title || this.current_module;
},
display_html: function () {
var input = this.pod;
if (!input) return '';
var pod = $($.parseHTML(input));
// change pod links
pod.find('a:uri(domain = metacpan.org):uri(directory *= /pod/)').each(function(index){
var url = $(this).uri();
var target = new URI();
target.fragment(''); // clear any existing fragment
var name = url.filename();
target.query({docs:name, title:name});
var frag = url.fragment();
if ( frag ) {
target.fragment(frag);
}
$(this).uri(target);
});
return pod.prop('outerHTML');
},
},
methods: {
load_pod_for_module: function (module) {
module = module || this.module || this.current_module;
if (module.indexOf('PDL::') != 0) module = 'PDL::' + module;
this.current_module = module;
var self = this;
$.get('https://fastapi.metacpan.org/v1/pod/' + module + '?content-type=text/html', function (data) {
self.pod = '<div>' + data + '</div>';
self.render_math();
});
},
render_math: function () {
if ('MathJax' in window) {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
return;
}
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
},
},
mounted: function() { this.load_pod_for_module() },
watch: { module: 'load_pod_for_module' },
});
Vue.component('page-container', {
template: '<div id="page"></div>',
props: {
page: {
type: String,
required: true,
},
},
methods: {
load: function () {
// this cheats because it has to evaluate scripts in the loaded file
$('#page').load('content/' + this.page + '.html');
},
},
mounted: function() { this.load() },
watch: { page: 'load' },
});
Vue.component('app-body', {
props: {
params: {
type: Object,
required: true,
},
},
computed: {
// the "router"
page_type: function() {
if (this.params.search) return 'search';
if (this.params.docs) return 'docs';
if (!this.params.page) this.params.page = 'home';
return 'page';
},
},
render: function (h) {
// render the "route"
if (this.page_type == 'search') {
return h('search-results', { props: { query: this.params.search } });
} else if (this.page_type == 'docs') {
return h('pod-viewer', { props: {
module: this.params.docs,
title: this.params.title || '',
}});
} else if (this.page_type == 'page') {
return h('page-container', { props: { page: this.params.page } });
}
return h('p', 'Page not understood');
},
});
var vm = new Vue({
el: '#main',
data: {
params: (new URI).query(true),
},
});
</script>
</body>
</html>