Changeset 7097
- Timestamp:
- 05/08/08 04:27:54 (2 months ago)
- Files:
-
- trunk/openlayers/doc/examples.html (modified) (5 diffs)
- trunk/openlayers/tools/exampleparser.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/doc/examples.html
r7092 r7097 2 2 <html> 3 3 <head> 4 <title>OL Docs</title> 4 <title>OpenLayers Examples</title> 5 <link rel="stylesheet" href="../examples/style.css" type="text/css" /> 5 6 <style type="text/css"> 6 7 html, body { … … 9 10 margin: 0; 10 11 padding: 0; 11 font: 0.9em Verdana, Arial, sans serif;12 line-height: 1.25em; 12 13 } 13 14 .ex_container{ … … 15 16 } 16 17 .ex_container a { 18 text-decoration: none; 17 19 padding: 5px 1em; 18 20 display: block; … … 25 27 font-weight: bold; 26 28 color: #333; 29 } 30 .ex_filename { 31 font-weight: normal; 32 font-size: 0.8em; 33 color: #ccc 27 34 } 28 35 .ex_description{ … … 57 64 <script type="text/javascript"> 58 65 // import 59 var uri = "http://jugl.tschaub.net/trunk/lib/Jugl.js"; 60 var Jugl = window[uri]; 61 // this part does the actual template processing 66 var Jugl = window["http://jugl.tschaub.net/trunk/lib/Jugl.js"]; 67 var template, target; 68 69 function listExamples(examples) { 70 var node = template.process({examples: examples}, true); 71 target.innerHTML = ""; 72 target.appendChild(node); 73 document.getElementById("count").innerHTML = "(" + examples.length + ")"; 74 } 75 76 var timerId; 77 function inputChange() { 78 if(timerId) { 79 window.clearTimeout(timerId); 80 } 81 var text = this.value; 82 timerId = window.setTimeout(function() { 83 filterList(text); 84 }, 500); 85 } 86 87 function filterList(text) { 88 var examples; 89 if(text.length < 2) { 90 examples = info.examples; 91 } else { 92 var words = text.split(/\W+/); 93 var scores = {}; 94 for(var i=0; i<words.length; ++i) { 95 var word = words[i].toLowerCase() 96 var dict = info.index[word]; 97 if(dict) { 98 for(exIndex in dict) { 99 var count = dict[exIndex]; 100 if(scores[exIndex]) { 101 scores[exIndex] += count; 102 } else { 103 scores[exIndex] = count; 104 } 105 } 106 } 107 } 108 examples = []; 109 for(var j in scores) { 110 var ex = info.examples[j]; 111 ex.score = scores[j]; 112 examples.push(ex); 113 } 114 // sort examples by descending score 115 examples.sort(function(a, b) { 116 return (b.score - a.score); 117 }); 118 } 119 listExamples(examples); 120 } 121 122 function showAll() { 123 document.getElementById("keywords").value = ""; 124 listExamples(info.examples); 125 } 62 126 window.onload = function() { 63 vartemplate = new Jugl.Template("template");64 var node = template.process(null, true);65 document.getElementById("examples").appendChild(node);127 template = new Jugl.Template("template"); 128 target = document.getElementById("examples"); 129 listExamples(info.examples); 66 130 document.getElementById("exwin").src = "../examples/example.html"; 67 } 131 document.getElementById("keywords").onkeyup = inputChange 132 }; 68 133 </script> 69 134 </head> 70 135 <body> 71 136 <div id="toc"> 72 <p id="instructions">Click an example link below to view on the right.</p> 137 <p id="instructions"> 138 <label for="keywords">Filter by keywords</label> 139 <input type="text" id="keywords" /><br /> 140 <span id="count"></span> 141 <a href="javascript:void showAll();">show all</a> 142 </p> 73 143 <div id="examples"></div> 74 144 </div> 75 <iframe id="exwin" name="exwin"></iframe> 76 145 <iframe id="exwin" name="exwin"></iframe> 77 146 <div style="display: none;"> 78 147 <div id="template"> 79 148 <div class="ex_container" jugl:repeat="example examples"> 80 149 <a jugl:attributes="href example.link" target="exwin"> 81 <h 3class="ex_title">150 <h5 class="ex_title"> 82 151 <span jugl:replace="example.title">title</span><br /> 83 <span class="ex ampleName" jugl:content="'(' + example.example + ')'">filename</span>84 </h 3>152 <span class="ex_filename" jugl:content="'(' + example.example + ')'">filename</span> 153 </h5> 85 154 <div class="ex_description" jugl:content="example.shortdesc"> 86 155 Short Description goes here trunk/openlayers/tools/exampleparser.py
r5362 r7097 82 82 return d 83 83 84 84 def wordIndex(examples): 85 """ 86 Create an inverted index based on words in title and shortdesc. Keys are 87 lower cased words. Values are dictionaries with example index keys and 88 count values. 89 """ 90 index = {} 91 unword = re.compile("\\W+") 92 keys = ["shortdesc", "title"] 93 for i in range(len(examples)): 94 for key in keys: 95 text = examples[i][key] 96 if text: 97 words = unword.split(text) 98 for word in words: 99 if word: 100 word = word.lower() 101 if index.has_key(word): 102 if index[word].has_key(i): 103 index[word][i] += 1 104 else: 105 index[word][i] = 1 106 else: 107 index[word] = {i: 1} 108 return index 109 85 110 if __name__ == "__main__": 86 111 … … 115 140 116 141 exampleList.sort(key=lambda x:x['example'].lower()) 117 json = simplejson.dumps(exampleList) 142 143 index = wordIndex(exampleList) 144 145 json = simplejson.dumps({"examples": exampleList, "index": index}) 118 146 #give the json a global variable we can use in our js. This should be replaced or made optional. 119 json = 'var examples=' + json147 json = 'var info=' + json 120 148 outFile.write(json) 121 149 outFile.close()
