mirror of
https://github.com/wezm/wezm.net.git
synced 2024-12-18 18:29:54 +00:00
Improve markup and styling of search results
This commit is contained in:
parent
fa5c2476f2
commit
4e3ea7f599
4 changed files with 63 additions and 40 deletions
|
@ -5,7 +5,7 @@
|
||||||
<link rel="stylesheet" href="/css/jsonSuggest.css" type="text/css" media="screen" charset="utf-8" />
|
<link rel="stylesheet" href="/css/jsonSuggest.css" type="text/css" media="screen" charset="utf-8" />
|
||||||
<script src="/js/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
|
<script src="/js/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="/js/jquery.ba-bbq.min.js" type="text/javascript" charset="utf-8"></script>
|
<script src="/js/jquery.ba-bbq.min.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="/js/jquery.jsonSuggest.js" type="text/javascript" charset="utf-8"></script>
|
<script src="/js/jquery.jsonSuggest-dev.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="/js/mojo.js" type="text/javascript" charset="utf-8"></script>
|
<script src="/js/mojo.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="/js/application.js" type="text/javascript" charset="utf-8"></script>
|
<script src="/js/application.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
|
|
@ -1,49 +1,60 @@
|
||||||
|
ul.jsonSuggestResults {
|
||||||
div.jsonSuggestResults {
|
|
||||||
position:absolute;
|
position:absolute;
|
||||||
border:1px solid #CCC;
|
border:1px solid #CCC;
|
||||||
padding:0px;
|
padding:0px;
|
||||||
margin:0px 2px;
|
margin:0px 2px;
|
||||||
z-index:1;
|
z-index:1;
|
||||||
|
-webkit-border-radius: 5px;
|
||||||
|
-moz-border-radius: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
list-style: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsonSuggestResults div.resultItem {
|
.jsonSuggestResults .resultItem {
|
||||||
margin:0px;
|
margin:0px;
|
||||||
padding:5px;
|
padding:5px;
|
||||||
position:relative;
|
position:relative;
|
||||||
height:auto;
|
height:auto;
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsonSuggestResults div.resultItem.odd {
|
.jsonSuggestResults .resultItem.odd {
|
||||||
background-color:#9ADFFE;
|
background-color:#EEE;
|
||||||
}
|
}
|
||||||
div.jsonSuggestResults div.resultItem.even {
|
.jsonSuggestResults .resultItem.even {
|
||||||
background-color:#FFFFFF;
|
background-color:#FFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsonSuggestResults div.resultItem.hover {
|
.jsonSuggestResults .resultItem.hover {
|
||||||
background-color:#3399FF;
|
background-color: rgb(188, 201, 224);
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsonSuggestResults div.resultItem img {
|
.jsonSuggestResults .resultItem img {
|
||||||
float:left;
|
float:left;
|
||||||
margin-right:10px;
|
margin-right:10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsonSuggestResults div.resultItem p {
|
.jsonSuggestResults .resultItem p {
|
||||||
margin:0px;
|
margin:0px;
|
||||||
padding:0px;
|
padding:0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsonSuggestResults div.resultItem p strong {
|
.jsonSuggestResults .resultItem strong {
|
||||||
font-weight:bold;
|
font-size: 18px;
|
||||||
text-decoration:underline;
|
font-family: "Helvetica Neue", Helvetica, "Liberation Sans", "Bitstream Vera Sans", Tahoma, Geneva, Arial, sans-serif;
|
||||||
|
font-weight: 200;
|
||||||
|
color: #111;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.jsonSuggestResults .resultItem strong em {
|
||||||
|
font-weight: 500;
|
||||||
|
font-style: normal;
|
||||||
|
text-decoration:underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsonSuggestResults div.resultItem p.extra {
|
.jsonSuggestResults .resultItem p.extra {
|
||||||
font-size: x-small !important;
|
font-size: small !important;
|
||||||
position:absolute;
|
font-family: Constantia, Georgia, "Bitstream Vera Serif", "Liberation Serif", serif;
|
||||||
bottom:3px;
|
|
||||||
right: 3px;
|
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ var WezM = {
|
||||||
$('#search').show();
|
$('#search').show();
|
||||||
$('#search input').jsonSuggest(this.articles, {
|
$('#search input').jsonSuggest(this.articles, {
|
||||||
onSelect: this._searchItemSelected,
|
onSelect: this._searchItemSelected,
|
||||||
width: 400
|
width: '400px'
|
||||||
});
|
});
|
||||||
if(navigator.userAgent.toLowerCase().indexOf('webkit') >= 0) {
|
if(navigator.userAgent.toLowerCase().indexOf('webkit') >= 0) {
|
||||||
$('#search input').css('paddingTop', 0);
|
$('#search input').css('paddingTop', 0);
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
|
|
||||||
var obj = $(this),
|
var obj = $(this),
|
||||||
wildCardPatt = new RegExp(regexEscape(settings.wildCard || ''),'g'),
|
wildCardPatt = new RegExp(regexEscape(settings.wildCard || ''),'g'),
|
||||||
results = $('<div />'),
|
results = $('<ul></ul>'),
|
||||||
currentSelection, pageX, pageY;
|
currentSelection, pageX, pageY;
|
||||||
|
|
||||||
// When an item has been selected then update the input box,
|
// When an item has been selected then update the input box,
|
||||||
|
@ -125,12 +125,21 @@
|
||||||
// current set of results and add it only to the given element. We also
|
// current set of results and add it only to the given element. We also
|
||||||
// need to set the current selection to the given element here.
|
// need to set the current selection to the given element here.
|
||||||
function setHoverClass(el) {
|
function setHoverClass(el) {
|
||||||
$('div.resultItem', results).removeClass('hover');
|
$('.resultItem', results).removeClass('hover');
|
||||||
$(el).addClass('hover');
|
$(el).addClass('hover');
|
||||||
|
|
||||||
currentSelection = el;
|
currentSelection = el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderResult(o) {
|
||||||
|
return '<li>\n\
|
||||||
|
<p>\n\
|
||||||
|
<strong></strong>\n\
|
||||||
|
' + (Mojo.escape(Mojo.normalize(o.summary))) + '\n\
|
||||||
|
</p>\n\
|
||||||
|
</li>';
|
||||||
|
}
|
||||||
|
|
||||||
// Build the results HTML based on an array of objects that matched
|
// Build the results HTML based on an array of objects that matched
|
||||||
// the search criteria, highlight the matches if feature is turned on in
|
// the search criteria, highlight the matches if feature is turned on in
|
||||||
// the settings.
|
// the settings.
|
||||||
|
@ -143,17 +152,15 @@
|
||||||
$(results).html('').hide();
|
$(results).html('').hide();
|
||||||
|
|
||||||
for (i = 0; i < resultObjects.length; i += 1) {
|
for (i = 0; i < resultObjects.length; i += 1) {
|
||||||
var item = $('<div />'),
|
var text = resultObjects[i].text;
|
||||||
text = resultObjects[i].text;
|
|
||||||
|
|
||||||
if (settings.highlightMatches === true) {
|
if (settings.highlightMatches === true) {
|
||||||
text = text.replace(filterPatt, "<strong>$1</strong>");
|
text = text.replace(filterPatt, "<em>$1</em>");
|
||||||
}
|
}
|
||||||
|
|
||||||
$(item).append('<p class="text">' + text + '</p>');
|
// $(item).append('<p class="text">' + text + '</p>');
|
||||||
|
|
||||||
if (typeof resultObjects[i].extra === 'string') {
|
if (typeof resultObjects[i].extra === 'string') {
|
||||||
$(item).append('<p class="extra">' + resultObjects[i].extra + '</p>');
|
// $(item).append('<p class="extra">' + resultObjects[i].extra + '</p>');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof resultObjects[i].image === 'string') {
|
if (typeof resultObjects[i].image === 'string') {
|
||||||
|
@ -161,16 +168,19 @@
|
||||||
append('<br style="clear:both;" />');
|
append('<br style="clear:both;" />');
|
||||||
}
|
}
|
||||||
|
|
||||||
$(item).addClass('resultItem').
|
var li = $(renderResult({ summary: resultObjects[i].extra }));
|
||||||
addClass((bOddRow) ? 'odd' : 'even').
|
$('strong', li).html(text);
|
||||||
click(function(n) { return function() {
|
|
||||||
selectResultItem(resultObjects[n]);
|
|
||||||
};}(i)).
|
|
||||||
mouseover(function(el) { return function() {
|
|
||||||
setHoverClass(el);
|
|
||||||
};}(item));
|
|
||||||
|
|
||||||
$(results).append(item);
|
li.addClass('resultItem').
|
||||||
|
addClass((bOddRow) ? 'odd' : 'even').
|
||||||
|
click(function(n) { return function() {
|
||||||
|
selectResultItem(resultObjects[n]);
|
||||||
|
};}(i)).
|
||||||
|
mouseover(function(el) { return function() {
|
||||||
|
setHoverClass(el);
|
||||||
|
};}(li));
|
||||||
|
|
||||||
|
$(results).append(li);
|
||||||
|
|
||||||
bOddRow = !bOddRow;
|
bOddRow = !bOddRow;
|
||||||
|
|
||||||
|
@ -180,7 +190,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($('div', results).length > 0) {
|
if ($('li', results).length > 0) {
|
||||||
currentSelection = undefined;
|
currentSelection = undefined;
|
||||||
$(results).show().css('height', 'auto');
|
$(results).show().css('height', 'auto');
|
||||||
|
|
||||||
|
@ -285,10 +295,12 @@
|
||||||
$(results).addClass('jsonSuggestResults').
|
$(results).addClass('jsonSuggestResults').
|
||||||
css({
|
css({
|
||||||
'top': (obj.position().top + obj.height() + 5) + 'px',
|
'top': (obj.position().top + obj.height() + 5) + 'px',
|
||||||
'left': obj.position().left + 'px',
|
'left': (obj.position().left - 10) + 'px',
|
||||||
'width': settings.width || ((obj.width() + 5) + 'px')
|
'width': settings.width || ((obj.width() + 5) + 'px')
|
||||||
}).hide();
|
}).hide();
|
||||||
|
|
||||||
|
console.log((obj.position().left - 15) + 'px');
|
||||||
|
|
||||||
obj.after(results).
|
obj.after(results).
|
||||||
keyup(keyListener).
|
keyup(keyListener).
|
||||||
blur(function(e) {
|
blur(function(e) {
|
||||||
|
@ -306,7 +318,7 @@
|
||||||
focus(function(e) {
|
focus(function(e) {
|
||||||
$(results).css({
|
$(results).css({
|
||||||
'top': (obj.position().top + obj.height() + 5) + 'px',
|
'top': (obj.position().top + obj.height() + 5) + 'px',
|
||||||
'left': obj.position().left + 'px'
|
'left': (obj.position().left - 15) + 'px'
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($('div', results).length > 0) {
|
if ($('div', results).length > 0) {
|
||||||
|
|
Loading…
Reference in a new issue