1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <title>Wikipedia Data Store</title> |
---|
5 | <style type="text/css"> |
---|
6 | @import "../../../dojo/resources/dojo.css"; |
---|
7 | @import "../../../dijit/themes/tundra/tundra.css"; |
---|
8 | h1 { margin-bottom: 1em; } |
---|
9 | </style> |
---|
10 | <script type="text/javascript"> |
---|
11 | //<![CDATA[ |
---|
12 | djConfig = { isDebug: true }; |
---|
13 | //]]> |
---|
14 | </script> |
---|
15 | <script type="text/javascript" src="../../../dojo/dojo.js"></script> |
---|
16 | <script type="text/javascript"> |
---|
17 | //<![CDATA[ |
---|
18 | dojo.require("dojox.data.WikipediaStore"); |
---|
19 | var store = new dojox.data.WikipediaStore(); |
---|
20 | |
---|
21 | function doSearch(){ |
---|
22 | var outNode = dojo.byId("output"); |
---|
23 | outNode.innerHTML = "Searching..."; |
---|
24 | |
---|
25 | function loadArticle(article){ |
---|
26 | var request = { |
---|
27 | query: { |
---|
28 | title: article |
---|
29 | }, |
---|
30 | onItem: function(item, req){ |
---|
31 | var title = store.getValue(item, "title"); |
---|
32 | var text = store.getValue(item, "text")["*"]; |
---|
33 | outNode.innerHTML = "<h1>" + title + "</h1>" + text; |
---|
34 | } |
---|
35 | }; |
---|
36 | console.log("Article request: ", request); |
---|
37 | store.fetch(request); |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | var request = { |
---|
42 | query: { |
---|
43 | action: "query", |
---|
44 | text: dojo.byId("searchText").value |
---|
45 | }, |
---|
46 | count: dojo.byId("count").value, |
---|
47 | onBegin: function(count){ |
---|
48 | outNode.innerHTML += " found " + count + " results.<br>Click one to load the article."; |
---|
49 | }, |
---|
50 | onItem: function(item, req){ |
---|
51 | console.debug(item); |
---|
52 | var node = document.createElement("a"); |
---|
53 | node.href = "#"; |
---|
54 | node.onclick = function(){ |
---|
55 | console.log("clicked ", this.innerHTML); |
---|
56 | loadArticle(this.innerHTML); |
---|
57 | }; |
---|
58 | node.style.padding = "6px"; |
---|
59 | node.style.display = "block"; |
---|
60 | node.innerHTML = store.getValue(item, "title"); |
---|
61 | outNode.appendChild(node); |
---|
62 | } |
---|
63 | }; |
---|
64 | console.log("Request: ", request); |
---|
65 | store.fetch(request); |
---|
66 | } |
---|
67 | //]]> |
---|
68 | </script> |
---|
69 | </head> |
---|
70 | <body class="tundra" style="margin:20px;"> |
---|
71 | <form action="#"> |
---|
72 | <p> |
---|
73 | Text: <input id="searchText" type="text" value="dojo toolkit"> |
---|
74 | Count: <input id="count" type="text" value="8" size="3"> |
---|
75 | <input id="searchButton" type="button" value="store.fetch()" onclick="doSearch()"> |
---|
76 | </p> |
---|
77 | |
---|
78 | <div id="output" style="padding:0 20px;"> |
---|
79 | </div> |
---|
80 | </form> |
---|
81 | </body> |
---|
82 | </html> |
---|