UNPKG

6.93 kBHTMLView Raw
1<!doctype html>
2<html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta http-equiv="X-UA-Compatible" content="chrome=1">
6 <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
7 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css">
8 <link rel="stylesheet" href="../css/ol.css" type="text/css">
9 <link rel="stylesheet" href="./resources/layout.css" type="text/css">
10 <style>
11 body {
12 padding-top: 70px;
13 }
14 input.search-query {
15 color: #333;
16 }
17 .example {
18 display: block;
19 padding: 10px;
20 background-color: #F5F5F5;
21 height: 140px;
22 margin: 10px 0;
23 overflow: auto;
24 }
25 .example p.description {
26 font-size: smaller;
27 margin: 5px 0;
28 }
29 .example:hover {
30 background-color: #ddd;
31 }
32
33 ::-webkit-scrollbar {
34 width: 8px;
35 }
36
37 ::-webkit-scrollbar-button {
38 width: 0;
39 height: 0;
40 display: none;
41 }
42
43 ::-webkit-scrollbar-thumb {
44 background-color: rgba(0, 0, 0, 0.2);
45 -webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.10),inset 0 -1px 0 rgba(0, 0, 0, 0.07);
46 }
47
48 ::-webkit-scrollbar-thumb:hover {
49 background-color: rgba(0, 0, 0, 0.4);
50 }
51
52 ::-webkit-scrollbar-corner {
53 background-color: transparent;
54 }
55 </style>
56 <script type="text/javascript" src="Jugl.js"></script>
57 <script type="text/javascript" src="index.js"></script>
58 <script type="text/javascript">
59 var template, target;
60
61 function listExamples(examples) {
62 target.innerHTML = "";
63 var node = template.process({
64 context: {examples: examples},
65 clone: true,
66 parent: target
67 });
68 document.getElementById("count").innerHTML = "(" + examples.length + ")";
69 }
70
71 var timerId;
72 function inputChange() {
73 if (timerId) {
74 window.clearTimeout(timerId);
75 }
76 var text = this.value;
77 timerId = window.setTimeout(function() {
78 filterList(text);
79 }, 500);
80 }
81
82 function filterList(text) {
83 var examples;
84 if (text.length < 2) {
85 examples = info.examples;
86 } else {
87 var words = text.split(/\W+/);
88 var scores = {};
89 for(var i=0; i<words.length; ++i) {
90 var word = words[i].toLowerCase();
91 var dict = info.index[word];
92 var updateScores = function() {
93 for(exIndex in dict) {
94 var count = dict[exIndex];
95 if(scores[exIndex]) {
96 if(scores[exIndex][word]) {
97 scores[exIndex][word] += count;
98 } else {
99 scores[exIndex][word] = count;
100 }
101 } else {
102 scores[exIndex] = {};
103 scores[exIndex][word] = count;
104 }
105 }
106 };
107 if (dict) {
108 updateScores();
109 } else {
110 var r;
111 for (idx in info.index) {
112 r = new RegExp(word);
113 if (r.test(idx)) {
114 dict = info.index[idx];
115 updateScores();
116 }
117 }
118 }
119 }
120 examples = [];
121 for (var j in scores) {
122 var ex = info.examples[j];
123 ex.score = scores[j];
124 examples.push(ex);
125 }
126 // sort examples by first by number of words matched, then
127 // by word frequency
128 examples.sort(function(a, b) {
129 var cmp;
130 var aWords = 0, bWords = 0;
131 var aScore = 0, bScore = 0;
132 for (var i in a.score) {
133 aScore += a.score[i];
134 aWords += 1;
135 }
136 for (var j in b.score) {
137 bScore += b.score[j];
138 bWords += 1;
139 }
140 if (aWords == bWords) {
141 cmp = bScore - aScore;
142 } else {
143 cmp = bWords - aWords;
144 }
145 return cmp;
146 });
147 }
148 listExamples(examples);
149 }
150
151 function parseQuery() {
152 var params = {};
153 var list = window.location.search.substring(1).split("&");
154 for (var i = 0; i < list.length; ++i) {
155 var pair = list[i].split("=");
156 if (pair.length == 2) {
157 params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
158 }
159 }
160 if (params["q"]) {
161 var input = document.getElementById("keywords");
162 input.value = params["q"];
163 inputChange.call(input);
164 }
165 }
166
167 window.onload = function() {
168 for (var i = 0; i < info.examples.length; ++i) {
169 info.examples[i].link += window.location.search;
170 }
171 template = new jugl.Template("template");
172 target = document.getElementById("examples");
173 listExamples(info.examples);
174 document.getElementById("keywords").onkeyup = inputChange;
175 parseQuery();
176 };
177
178 </script>
179
180 <title>OpenLayers Examples</title>
181 </head>
182 <body>
183
184 <header class="navbar navbar-fixed-top" role="navigation">
185 <div class="container">
186 <div class="display-table pull-left">
187 <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png">&nbsp;OpenLayers Examples</a>
188 <form class="navbar-form" role="search">
189 <input name="q" type="text" id="keywords" class="search-query" placeholder="Search" autofocus>
190 <span id="count"></span>
191 </form>
192 </div>
193 <!-- menu items that get hidden below 768px width -->
194 <nav class='collapse navbar-collapse navbar-responsive-collapse'>
195 <ul class="nav navbar-nav pull-right">
196 <li><a href="../doc">Docs</a></li>
197 <li><a class="active" href="index.html">Examples</a></li>
198 <li><a href="../apidoc">API</a></li>
199 <li><a href="https://github.com/openlayers/openlayers">Code</a></li>
200 </ul>
201 </nav>
202 </div>
203 </header>
204
205 <div class="container-fluid">
206 <div id="examples"></div>
207 <div style="display: none;">
208 <div id="template" class="row">
209 <div class="col-md-4 col-sm-4" jugl:repeat="example examples">
210 <a jugl:attributes="href example.link" class="example">
211 <span class="mainlink">
212 <strong><span jugl:replace="example.title">title</span></strong><br>
213 <small jugl:content="'(' + example.example + ')'"></small>
214 </span>
215 <p class="description" jugl:content="example.shortdesc"></p>
216 </a>
217 </div>
218 </div>
219 </div>
220 </div>
221 </body>
222</html>