-
Notifications
You must be signed in to change notification settings - Fork 14
/
SearchMarkUI.html
192 lines (159 loc) · 5.79 KB
/
SearchMarkUI.html
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search Bookmarked Pages</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script type="text/javascript" src="libs/jquery-1.4.4.min.js"></script>
<script language="Javascript">
// SearchMarkUI.html: SearchMark front-end
//
// Copyright (C) 2010 Candy Yiu, and Akshay Dua
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// About:
// Initialize communication channel between backend and UI.
// No UI code should be added here. Change only if ABSOLUTELY
// necessary.
//
$(document).ready(
function()
{
// Listen for search results from backend
chrome.extension.onConnect.addListener(function(port) {
if(port.name != "uiToBackend") {
console.log("Invalid port name: " + port.name);
return;
}
port.onMessage.addListener(function(result) {
processSearchResult(result);
});
});
localStorage['uivisits']++;
/* stop showing tip after 2 UI visits */
if(localStorage['uivisits'] < 4)
$('#welcomesearchbox').append(
'<div id="tiparea"><p><b>Tip:</b> Use the "*". ' +
'For example, to search for words beginning ' +
'with "mar", simply type "mar*".</div>');
if(localStorage['uivisits'] == 3)
$('#tiparea').delay(3000).fadeOut(
'slow',
function () {});
$('#searchbox').focus();
$('#searchbox').keyup(function(e) {
if(e.keyCode == 13) {
leavePage('#welcomepage');
}
});
});
// Send request to backend for displaying a cached bookmark page
function requestCachedPage(id) {
chrome.extension.sendRequest(
{method: 'cached', bookmarkid: id},
function() {});
}
var searchbtnid = "'#searchbutton'";
var searchbtneffect = "'searchbuttonpressed'";
var resultspagename = "'#resultspage'";
var results_page_top_html =
'<div id="topsearch">' +
'<table><tr>' +
'<th id = "thlogo"><img src="images/logotext-results.png"/></th>' +
'<!-- search box -->' +
'<th id = "thsearchbox"><input type="text" id="searchbox"' +
'class="searchbox"/>' +
'<!-- search button -->' +
'<button type="button" id="searchbutton" class="searchbutton"' +
'onmousedown="$(' + searchbtnid + ').addClass(' + searchbtneffect
+ ')"' +
'onmouseup="$(' + searchbtnid + ').removeClass('+
searchbtneffect + ');leavePage(' + resultspagename + ')">Search</button></th>' +
'</tr></table>' +
'</div>';
// Take keywords from text box and send to
// backend for searching.
function doSearch(searchwords) {
$('body').append('<div id = "resultspage"></div>');
$('#resultspage').append(results_page_top_html);
$('#resultspage').append(
'<div id="resultspagebtm"></div>');
chrome.extension.sendRequest(
{method: 'search', keywords: searchwords},
function() {});
}
function leavePage(pagename)
{
var searchwords = $('#searchbox').val();
$(pagename).remove();
$('body').css('cursor', 'wait');
doSearch(searchwords);
}
// Each search result will be delivered here.
// result object has fields,
// result.url: page URL
// result.text: formatted page text, or URL
// result.title: page title
// result.matchType: 'title', 'url', or 'page'
// If the title matched, then result.text will be
// empty. if URL matched, then result.text will be
// a formatted URL (keyword is in bold face), if
// page text matched, then result.text will contain
// textual context.
function processSearchResult(result) {
if(result.matchType == "DONE") {
$('body').css('cursor', 'auto');
// search error?
if(result.error) {
resultString = result.error;
} else {
resultString = " ";
}
$('#searchbox').focus();
$('#searchbox').keyup(function(e) {
if(e.keyCode == 13) {
leavePage('#resultspage');
}
});
} else {
if(result.img == "")
result.img = '<img src="" alt="No Image Available" ' +
'width=400 />';
else
result.img = '<img src="' + result.img +
'" width=400 />';
resultString =
'<a href="' + result.url + '" target="_blank">' + result.title +'</a>' +
'<br/>' + result.text + '<br/>' +
'<span class="resulturl">' + result.url + '</span> ' +
'<a href="#" class="resultactions" onclick="requestCachedPage(' + result.id +
');">(Offline Version)</a><br/>' + result.img + '<p><br/>';
}
$('#resultspagebtm').append(resultString);
}
</script>
</head>
<body>
<div id="welcomepage">
<div id="floater"></div>
<div id="welcomesearchbox">
<!-- search box -->
<input type="text" id="searchbox" class="searchbox"/>
<!-- search button -->
<button type="button" id="searchbutton" class="searchbutton"
onmousedown="$('#searchbutton').addClass('searchbuttonpressed')"
onmouseup="$('#searchbutton').removeClass('searchbuttonpressed');leavePage('#welcomepage')">
Search</button>
</div>
</div>
</body>
</html>