create word index from examples and use it to filter example list
git-svn-id: http://svn.openlayers.org/trunk/openlayers/doc@7097 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+84
-15
@@ -1,19 +1,21 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>OL Docs</title>
|
<title>OpenLayers Examples</title>
|
||||||
|
<link rel="stylesheet" href="../examples/style.css" type="text/css" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
html, body {
|
html, body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
font: 0.9em Verdana, Arial, sans serif;
|
line-height: 1.25em;
|
||||||
}
|
}
|
||||||
.ex_container{
|
.ex_container{
|
||||||
border-bottom: 1px solid grey;
|
border-bottom: 1px solid grey;
|
||||||
}
|
}
|
||||||
.ex_container a {
|
.ex_container a {
|
||||||
|
text-decoration: none;
|
||||||
padding: 5px 1em;
|
padding: 5px 1em;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
@@ -25,6 +27,11 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
.ex_filename {
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 0.8em;
|
||||||
|
color: #ccc
|
||||||
|
}
|
||||||
.ex_description{
|
.ex_description{
|
||||||
color: #222;
|
color: #222;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
@@ -56,32 +63,94 @@
|
|||||||
<script type="text/javascript" src="examples.js"></script>
|
<script type="text/javascript" src="examples.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// import
|
// import
|
||||||
var uri = "http://jugl.tschaub.net/trunk/lib/Jugl.js";
|
var Jugl = window["http://jugl.tschaub.net/trunk/lib/Jugl.js"];
|
||||||
var Jugl = window[uri];
|
var template, target;
|
||||||
// this part does the actual template processing
|
|
||||||
window.onload = function() {
|
function listExamples(examples) {
|
||||||
var template = new Jugl.Template("template");
|
var node = template.process({examples: examples}, true);
|
||||||
var node = template.process(null, true);
|
target.innerHTML = "";
|
||||||
document.getElementById("examples").appendChild(node);
|
target.appendChild(node);
|
||||||
document.getElementById("exwin").src = "../examples/example.html";
|
document.getElementById("count").innerHTML = "(" + examples.length + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var timerId;
|
||||||
|
function inputChange() {
|
||||||
|
if(timerId) {
|
||||||
|
window.clearTimeout(timerId);
|
||||||
|
}
|
||||||
|
var text = this.value;
|
||||||
|
timerId = window.setTimeout(function() {
|
||||||
|
filterList(text);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterList(text) {
|
||||||
|
var examples;
|
||||||
|
if(text.length < 2) {
|
||||||
|
examples = info.examples;
|
||||||
|
} else {
|
||||||
|
var words = text.split(/\W+/);
|
||||||
|
var scores = {};
|
||||||
|
for(var i=0; i<words.length; ++i) {
|
||||||
|
var word = words[i].toLowerCase()
|
||||||
|
var dict = info.index[word];
|
||||||
|
if(dict) {
|
||||||
|
for(exIndex in dict) {
|
||||||
|
var count = dict[exIndex];
|
||||||
|
if(scores[exIndex]) {
|
||||||
|
scores[exIndex] += count;
|
||||||
|
} else {
|
||||||
|
scores[exIndex] = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
examples = [];
|
||||||
|
for(var j in scores) {
|
||||||
|
var ex = info.examples[j];
|
||||||
|
ex.score = scores[j];
|
||||||
|
examples.push(ex);
|
||||||
|
}
|
||||||
|
// sort examples by descending score
|
||||||
|
examples.sort(function(a, b) {
|
||||||
|
return (b.score - a.score);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
listExamples(examples);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAll() {
|
||||||
|
document.getElementById("keywords").value = "";
|
||||||
|
listExamples(info.examples);
|
||||||
|
}
|
||||||
|
window.onload = function() {
|
||||||
|
template = new Jugl.Template("template");
|
||||||
|
target = document.getElementById("examples");
|
||||||
|
listExamples(info.examples);
|
||||||
|
document.getElementById("exwin").src = "../examples/example.html";
|
||||||
|
document.getElementById("keywords").onkeyup = inputChange
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="toc">
|
<div id="toc">
|
||||||
<p id="instructions">Click an example link below to view on the right.</p>
|
<p id="instructions">
|
||||||
|
<label for="keywords">Filter by keywords</label>
|
||||||
|
<input type="text" id="keywords" /><br />
|
||||||
|
<span id="count"></span>
|
||||||
|
<a href="javascript:void showAll();">show all</a>
|
||||||
|
</p>
|
||||||
<div id="examples"></div>
|
<div id="examples"></div>
|
||||||
</div>
|
</div>
|
||||||
<iframe id="exwin" name="exwin"></iframe>
|
<iframe id="exwin" name="exwin"></iframe>
|
||||||
|
|
||||||
<div style="display: none;">
|
<div style="display: none;">
|
||||||
<div id="template">
|
<div id="template">
|
||||||
<div class="ex_container" jugl:repeat="example examples">
|
<div class="ex_container" jugl:repeat="example examples">
|
||||||
<a jugl:attributes="href example.link" target="exwin">
|
<a jugl:attributes="href example.link" target="exwin">
|
||||||
<h3 class="ex_title">
|
<h5 class="ex_title">
|
||||||
<span jugl:replace="example.title">title</span><br />
|
<span jugl:replace="example.title">title</span><br />
|
||||||
<span class="exampleName" jugl:content="'(' + example.example + ')'">filename</span>
|
<span class="ex_filename" jugl:content="'(' + example.example + ')'">filename</span>
|
||||||
</h3>
|
</h5>
|
||||||
<div class="ex_description" jugl:content="example.shortdesc">
|
<div class="ex_description" jugl:content="example.shortdesc">
|
||||||
Short Description goes here
|
Short Description goes here
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user