Files
openlayers/examples/example-list.html
Tim Schaub 92c092c598 keep filter at top, parse query
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7125 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2008-05-09 15:02:31 +00:00

232 lines
8.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
<title>OpenLayers Examples</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<style type="text/css">
html, body {
height: 100%;
overflow: hidden;
margin: 0;
padding: 0;
line-height: 1.25em;
}
.ex_container{
border-bottom: 1px solid #cccccc;
}
.ex_container a {
text-decoration: none;
padding: 5px 1em;
display: block;
}
.ex_container a:hover {
background-color: #eeeeee;
}
.ex_title{
display: inline;
font-weight: bold;
color: #333;
}
.ex_filename {
font-weight: normal;
font-size: 0.8em;
color: #ccc
}
.ex_description{
color: #222;
padding: 3px;
}
.ex_classes{
font-size: .7em;
color: grey;
display: none;
}
#toc {
width: 30%;
height: 100%;
}
#filter {
top: 0px;
height: 50px;
padding: 10px 1em 10px 1em;
}
#examples {
border-top: 1px solid #cccccc;
position: absolute;
width: 30%;
top: 70px;
bottom: 0px;
overflow: auto;
list-style: none;
margin: 0;
padding: 0;
}
#examples ul {
list-style: none;
margin: 0;
padding: 0;
}
#examples ul li {
display: block;
margin: 0;
padding: 0;
}
#exwin {
position: absolute;
top: 0;
left: 30%;
width: 70%;
height: 100%;
border: none;
border-left: 1px solid #cccccc;
margin: 0;
}
</style>
<script type="text/javascript" src="Jugl.js"></script>
<script type="text/javascript" src="example-list.js"></script>
<script type="text/javascript">
// import
var Jugl = window["http://jugl.tschaub.net/trunk/lib/Jugl.js"];
var template, target;
function listExamples(examples) {
target.innerHTML = "";
var node = template.process({
context: {examples: examples},
clone: true,
parent: target
});
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]) {
if(scores[exIndex][word]) {
scores[exIndex][word] += count;
} else {
scores[exIndex][word] = count;
}
} else {
scores[exIndex] = {};
scores[exIndex][word] = count;
}
}
}
}
examples = [];
for(var j in scores) {
var ex = info.examples[j];
ex.score = scores[j];
examples.push(ex);
}
// sort examples by first by number of words matched, then
// by word frequency
examples.sort(function(a, b) {
var cmp;
var aWords = 0, bWords = 0;
var aScore = 0, bScore = 0;
for(var i in a.score) {
aScore += a.score[i];
aWords += 1;
}
for(var j in b.score) {
bScore += b.score[j];
bWords += 1;
}
if(aWords == bWords) {
cmp = bScore - aScore;
} else {
cmp = bWords - aWords;
}
return cmp;
});
}
listExamples(examples);
}
function showAll() {
document.getElementById("keywords").value = "";
listExamples(info.examples);
}
function parseQuery() {
var params = {};
var list = window.location.search.substring(1).split("&");
for(var i=0; i<list.length; ++i) {
var pair = list[i].split("=");
if(pair.length == 2) {
params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
}
if(params["q"]) {
var input = document.getElementById("keywords");
input.value = params["q"];
inputChange.call(input);
}
}
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
parseQuery();
};
</script>
</head>
<body>
<div id="toc">
<div id="filter">
<p>
<label for="keywords">Filter by keywords</label><br />
<input type="text" id="keywords" />
<span id="count"></span><br />
<a href="javascript:void showAll();">show all</a>
</p>
</div>
<div id="examples"></div>
</div>
<iframe id="exwin" name="exwin" frameborder="0"></iframe>
<div style="display: none;">
<ul id="template">
<li class="ex_container" jugl:repeat="example examples">
<a jugl:attributes="href example.link" target="exwin">
<h5 class="ex_title">
<span jugl:replace="example.title">title</span><br />
<span class="ex_filename" jugl:content="'(' + example.example + ')'">filename</span>
</h5>
<div class="ex_description" jugl:content="example.shortdesc">
Short Description goes here
</div>
<p class="ex_classes" jugl:content="example.classes">
Related Classes go here
</p>
</a>
</li>
</ul>
</div>
</body>
</html>