summaryrefslogtreecommitdiff
path: root/misc/openlayers/examples/example-list.html
blob: 3ac9120b4fa34f95a4c1deaef7a848c683c0ca7e (plain)
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
298
299
300
301
302
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <!-- This is the example list source: if you are trying to look at the 
        source of an example, YOU ARE IN THE WRONG PLACE. If you want to view
        the source of just one example, you can typically choose 
        "This Frame -> View source" when right clicking on the exmaple. If not,
        choose to open the example in a new window (via the context menu 
        click on the link), and view source from there. -->  
        <title>OpenLayers Examples</title>
        <link rel="alternate" href="example-list.xml" type="application/atom+xml" />
        <link rel="stylesheet" href="style.css" type="text/css">
        <style type="text/css">
            html, body {
                margin: 0;
                padding: 0;
                line-height: 1.25em;
            }
            #logo {
                text-shadow: 2px 2px 3px gray;
                color: white;
                vertical-align: middle;
                position: absolute;
                top: 5px;
                left: 5px;
                font-size: 34px;
                font-family: "Trebuchet MS",Helvetica,Arial,sans-serif;
            }
            #logo img {
                vertical-align: middle;
            }
            .ex_container{
            }
            .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_tags{
                display: inline;
                font-size: smaller;
                font-style: italic;
                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: gray;
                display: none;
            }
            #toc {
                width: 100%;
                height: 100%;
            }
            #filter {
                position: fixed;
                text-align: center;
                top: 0px;
                background: #9D9FA1;
                width: 100%;
                padding: 1.3em 0;
            }
            #examples {
                overflow: auto;
                list-style: none;
                margin: 0;
                padding: 0;
            }
            #examples ul {
                list-style: none;
                margin: 0;
                padding: 0;
                margin-top: 4em;
            }
            #examples ul li {
                display: inline;
                float: left;
                width: 350px;
                margin: 10px 0 0 10px;
                padding: 0;
                border: 1px solid #ddd;
                border-radius: 3px;
            }
            #examples .mainlink {
                height: 8em;
                overflow: auto;
            }
            #exwin {
                position: absolute;
                top: 0;
                left: 30%;
                width: 70%;
                height: 100%;
                border: none;
                border-left: 1px solid #cccccc;
                margin: 0;
            }
            @media only screen and (max-width: 600px) {
                #examples ul {
                    margin-top: 100px;
                }
                #filter {
                    padding-top: 50px;
                }
                #examples ul li {
                    margin-left: 0;
                    border-radius: 0;
                    border-width: 1px 0;
                    width: 100%;
                }
                #examples .mainlink {
                    height: auto;
                }
                #examples .ex_tags, #examples .ex_filename {
                    display: none;
                }
            }
        </style>
        <script type="text/javascript" src="Jugl.js"></script>
        <script type="text/javascript" src="example-list.js"></script>
        <script type="text/javascript">
            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];
                        var updateScores = function() {
                            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;
                                }
                            }
                        };
                        if(dict) {
                            updateScores();
                        } else {
                            var r;
                            for (idx in info.index) {
                               r = new RegExp(word);
                               if (r.test(idx)) {
                                    dict = info.index[idx];
                                    updateScores();
                               }
                            }
                        }
                    }
                    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() {
                //document.getElementById('keywords').focus();
                template = new jugl.Template("template");
                target = document.getElementById("examples");
                listExamples(info.examples);
                document.getElementById("keywords").onkeyup = inputChange;
                parseQuery();
            };
        </script>
    </head>
    <body>
        <div id="toc">
            <div id="filter">
                <div id="logo">
                <img src="http://www.openlayers.org/images/OpenLayers.trac.png"
                 />
                 OpenLayers
             </div>
                <p>
                    <input autofocus placeholder="filter by keywords..." type="text" id="keywords" />
                    <span id="count"></span>
                    <a href="javascript:void showAll();">show all</a>
                </p>
            </div>
            <div id="examples"></div>
        </div>
        <div style="display: none;">
            <ul id="template">
                <li class="ex_container" jugl:repeat="example examples">
                <a jugl:attributes="href example.link" class="mainlink"
                    target="_blank">
                        <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>
                        <div class="ex_tags" jugl:content="'...tagged with ' + example.tags">
                            
                        </div>
                    </a>
                </li>
            </ul>
        </div>
    </body>
</html>