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
|
<!--
This file is a demo of the OpenSearchStore, a simple wrapper to any OpenSearch compliant
search engine.
Note, the simple proxy requires a curl-enabled PHP install
-->
<html>
<head>
<title>Demo of OpenSearchStore</title>
<style type="text/css">
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/tests/css/dijitTests.css";
@import "./openSearchDemo.css";
</style>
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dijit.form.CheckBox");
dojo.require("dijit.form.NumberSpinner");
dojo.require("dijit.Tree");
dojo.require("dojox.data.OpenSearchStore");
function init(){
var fViewWidgets = [];
//Set up an onComplete handler for OpenSearchData
function onComplete(items, request){
if(items.length > 0){
var ul = dojo.byId("searchResults");
var test;
var li;
for(var i=0; i<items.length; i++){
li = dojo.doc.createElement("li");
li.innerHTML = openSearchStore.getValue(items[i], "content");
ul.appendChild(li);
}
}
statusWidget.attr('value', "PROCESSING COMPLETE.");
}
//What to do if a search fails...
function onError(error, request){
statusWidget.attr('value', "PROCESSING ERROR.");
}
//Function to invoke the search of the openSearchStore
function invokeSearch(){
var tbody = dojo.byId("searchResults");
while(tbody.childNodes.length){
var node = tbody.childNodes.item(0);
node.parentNode.removeChild(node);
}
var request = {
query: {},
onComplete: onComplete,
onError: onError
};
if(searchTermsWidget){
var searchTerms = searchTermsWidget.attr('value');
if(searchTerms && searchTerms !== ""){
var searchTermsArray = searchTerms.split(" ");
searchTerms = "";
for(var i = 0; i < searchTermsArray.length; i++){
searchTerms = searchTerms + searchTermsArray[i];
if(i < (searchTermsArray.length - 1)){
searchTerms += ","
}
}
request.query.searchTerms = searchTerms;
}
}
if(countWidget){
request.count = countWidget.attr('value');
}
if(statusWidget){
statusWidget.attr('value', "PROCESSING REQUEST");
}
openSearchStore.fetch(request);
}
//Lastly, link up the search event.
dojo.connect(dijit.byId("searchButton"), 'onClick', invokeSearch);
var currentArgs = {url: 'http://intertwingly.net/search/'};
var oldProcess = null;
function setTransform(state){
if(state){
oldProcess = openSearchStore.processItem;
switch(currentArgs.url){
case 'http://intertwingly.net/search/':
openSearchStore.processItem = intertwinglyTransform;
break;
case 'http://www.shutterpoint.com/opensearch.xml':
openSearchStore.processItem = shutterpointTransform;
break;
case 'http://technorati.com/osd.xml':
openSearchStore.processItem = technoratiTransform;
break;
}
}else if(oldProcess !== null){
openSearchStore.processItem = oldProcess;
}
}
dojo.connect(dijit.byId('transformItem'), 'onChange', function(state){
setTransform(state);
});
dojo.connect(dijit.byId('urlSelector'), 'onChange', function(args){
currentArgs = dojo.fromJson(args);
currentArgs.url = 'openSearchProxy.php?osd=true&url='+currentArgs.url;
openSearchStore.close();
openSearchStore = new dojox.data.OpenSearchStore(currentArgs);
if(dijit.byId('transformItem').checked){
setTransform(true);
}
});
var intertwinglyTransform = function(item, attribute){
function removeAll(/*NodeList*/list){
while(list.length) {
var node = list.item(0);
node.parentNode.removeChild(node);
}
}
var content = item.node.getElementsByTagName("content").item(0);
// Remove all blockquote elements
removeAll(content.getElementsByTagName("blockquote"));
// Remove all pre-formatted elements
removeAll(content.getElementsByTagName("pre"));
return openSearchStore._getNodeXml(content, true);
};
var shutterpointTransform = function(item, attribute){
var description = item.node.getElementsByTagName("description").item(0);
var div = dojo.doc.createElement("div");
div.innerHTML = description.childNodes.item(0).nodeValue;
//Of the description children, remove the divs (to only leave the images)
for(var i=0; i<div.childNodes.length; i++){
var node = div.childNodes.item(i);
if(node.tagName.toLowerCase() === "div")
node.parentNode.removeChild(node);
}
return openSearchStore._getNodeXml(div, true);
};
var technoratiTransform = function(item, attribute){
function removeAll(/*NodeList*/list){
while(list.length) {
var node = list.item(0);
node.parentNode.removeChild(node);
}
}
removeAll(item.node.getElementsByTagName("blockquote"));
return item.innerHTML;
};
}
dojo.addOnLoad(init);
</script>
</head>
<body class="tundra">
<h1>DEMO: OpenSearchStore Search</h1>
<hr />
<h3>Description:</h3>
<p>
This simple demo shows how services, such as an OpenSearch compliant search service, can be wrapped by the datastore API. In this demo, you can search public search engines through a simple OpenSearchStore by specifying a series of search terms (separated by spaces) to search on. The results will be displayed below the search box.
</p>
<p>
<b>NOTE: This demo makes use of a simple PHP based proxy script. The proxy script requires cURL support in PHP. Without cURL support, the demo will throw errors.</b>
</p>
<label for="urlSelector">URL of OpenSearchDocument:</label>
<select dojoType="dijit.form.FilteringSelect"
id="urlSelector"
name="urlSelector"
autoComplete="true">
<option value="{url: 'http://intertwingly.net/search/'}">http://intertwingly.net/search/</option>
<option value="{url: 'http://www.shutterpoint.com/opensearch.xml'}">http://www.shutterpoint.com/opensearch.xml</option>
<option value="{url: 'http://technorati.com/osd.xml', itemPath: '.hentry'}">http://technorati.com/osd.xml</option>
</select>
<label for="transformItem">Apply transform function?</label>
<input dojoType="dijit.form.CheckBox"
type="checkbox"
id="transformItem"
name="transformItem">
</input>
<hr />
<label for="status">Status:</label>
<div dojoType="dijit.form.TextBox" maxLength="50" id="status" name="status" jsId="statusWidget" disabled="true"></div>
<label for="searchTerms">Search For:</label>
<div dojoType="dijit.form.TextBox" maxLength="50" id="searchTerms" name="searchTerms" jsId="searchTermsWidget" value="javascript"></div>
<label for="count">Number of Results:</label>
<div id="count"
name="count"
jsId="countWidget"
dojoType="dijit.form.NumberSpinner"
value="20"
constraints="{min:1,max:20}">
</div>
<div dojoType="dijit.form.Button" label="Search" id="searchButton" jsId="searchButtonWidget"></div>
<hr/>
<div dojoType="dojox.data.OpenSearchStore"
url="openSearchProxy.php?osd=true&url=http://intertwingly.net/search/"
jsId="openSearchStore">
</div>
<ul id="searchResults"></ul>
</body>
</html>
|