Browse Source

Adds several fixes for theming for search

pull/1243/head
jlukic 10 years ago
parent
commit
110ebc28cc
4 changed files with 197 additions and 98 deletions
  1. 6
      src/definitions/behaviors/api.js
  2. 81
      src/definitions/modules/search.js
  3. 146
      src/definitions/modules/search.less
  4. 62
      src/themes/default/modules/search.variables

6
src/definitions/behaviors/api.js

@ -466,17 +466,17 @@ $.api = $.fn.api = function(parameters) {
if(runSettings) { if(runSettings) {
if(runSettings.success !== undefined) { if(runSettings.success !== undefined) {
module.debug('Legacy success callback detected', runSettings); module.debug('Legacy success callback detected', runSettings);
module.error(error.legacyParameters);
module.error(error.legacyParameters, runSettings.success);
runSettings.onSuccess = runSettings.success; runSettings.onSuccess = runSettings.success;
} }
if(runSettings.failure !== undefined) { if(runSettings.failure !== undefined) {
module.debug('Legacy failure callback detected', runSettings); module.debug('Legacy failure callback detected', runSettings);
module.error(error.legacyParameters);
module.error(error.legacyParameters, runSettings.failure);
runSettings.onFailure = runSettings.failure; runSettings.onFailure = runSettings.failure;
} }
if(runSettings.complete !== undefined) { if(runSettings.complete !== undefined) {
module.debug('Legacy complete callback detected', runSettings); module.debug('Legacy complete callback detected', runSettings);
module.error(error.legacyParameters);
module.error(error.legacyParameters, runSettings.complete);
runSettings.onComplete = runSettings.complete; runSettings.onComplete = runSettings.complete;
} }
} }

81
src/definitions/modules/search.js

@ -70,7 +70,6 @@ $.fn.search = function(parameters) {
.on('keydown' + eventNamespace, module.handleKeyboard) .on('keydown' + eventNamespace, module.handleKeyboard)
; ;
if(settings.automatic) { if(settings.automatic) {
console.log($prompt);
$prompt $prompt
.on(inputEvent + eventNamespace, module.search.throttle) .on(inputEvent + eventNamespace, module.search.throttle)
; ;
@ -112,7 +111,9 @@ $.fn.search = function(parameters) {
; ;
clearTimeout(module.timer); clearTimeout(module.timer);
module.search.throttle(); module.search.throttle();
module.results.show();
if(module.has.minimum()) {
module.results.show();
}
}, },
blur: function() { blur: function() {
module.search.cancel(); module.search.cancel();
@ -212,6 +213,15 @@ $.fn.search = function(parameters) {
} }
} }
}, },
has: {
minimum: function() {
var
searchTerm = $prompt.val(),
numCharacters = searchTerm.length
;
return (numCharacters >= settings.minCharacters);
}
},
search: { search: {
cancel: function() { cancel: function() {
var var
@ -223,12 +233,8 @@ $.fn.search = function(parameters) {
} }
}, },
throttle: function() { throttle: function() {
var
searchTerm = $prompt.val(),
numCharacters = searchTerm.length
;
clearTimeout(module.timer); clearTimeout(module.timer);
if(numCharacters >= settings.minCharacters) {
if(module.has.minimum()) {
module.timer = setTimeout(module.search.query, settings.searchDelay); module.timer = setTimeout(module.search.query, settings.searchDelay);
} }
else { else {
@ -308,8 +314,8 @@ $.fn.search = function(parameters) {
remote: function(searchTerm) { remote: function(searchTerm) {
var var
apiSettings = { apiSettings = {
stateContext : $module,
urlData: {
stateContext : $module,
urlData : {
query: searchTerm query: searchTerm
}, },
onSuccess : function(response) { onSuccess : function(response) {
@ -317,7 +323,7 @@ $.fn.search = function(parameters) {
module.search.cache.write(searchTerm, searchHTML); module.search.cache.write(searchTerm, searchHTML);
module.results.add(searchHTML); module.results.add(searchHTML);
}, },
failure : module.error
onFailure : module.error
}, },
searchHTML searchHTML
; ;
@ -360,7 +366,10 @@ $.fn.search = function(parameters) {
; ;
if(($.isPlainObject(response.results) && !$.isEmptyObject(response.results)) || ($.isArray(response.results) && response.results.length > 0) ) { if(($.isPlainObject(response.results) && !$.isEmptyObject(response.results)) || ($.isArray(response.results) && response.results.length > 0) ) {
if(settings.maxResults > 0) { if(settings.maxResults > 0) {
response.results = $.makeArray(response.results).slice(0, settings.maxResults);
response.results = $.isArray(response.results)
? response.results.slice(0, settings.maxResults)
: response.results
;
} }
if($.isFunction(template)) { if($.isFunction(template)) {
html = template(response); html = template(response);
@ -385,10 +394,14 @@ $.fn.search = function(parameters) {
}, },
show: function() { show: function() {
if( ($results.filter(':visible').size() === 0) && ($prompt.filter(':focus').size() > 0) && $results.html() !== '') { if( ($results.filter(':visible').size() === 0) && ($prompt.filter(':focus').size() > 0) && $results.html() !== '') {
if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported') && !$results.transition('is inward')) {
module.debug('Showing results with css animations'); module.debug('Showing results with css animations');
$results $results
.transition(settings.transition + ' in', settings.duration)
.transition({
animation : settings.transition + ' in',
duration : settings.duration,
queue : true
})
; ;
} }
else { else {
@ -403,10 +416,14 @@ $.fn.search = function(parameters) {
}, },
hide: function() { hide: function() {
if($results.filter(':visible').size() > 0) { if($results.filter(':visible').size() > 0) {
if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported') && !$results.transition('is outward')) {
module.debug('Hiding results with css animations'); module.debug('Hiding results with css animations');
$results $results
.transition(settings.transition + ' out', settings.duration)
.transition({
animation : settings.transition + ' out',
duration : settings.duration,
queue : true
})
; ;
} }
else { else {
@ -429,10 +446,17 @@ $.fn.search = function(parameters) {
if(settings.onSelect == 'default' || $.proxy(settings.onSelect, this)(event) == 'default') { if(settings.onSelect == 'default' || $.proxy(settings.onSelect, this)(event) == 'default') {
var var
$link = $result.find('a[href]').eq(0), $link = $result.find('a[href]').eq(0),
$title = $result.find(selector.title).eq(0),
href = $link.attr('href') || false, href = $link.attr('href') || false,
target = $link.attr('target') || false
target = $link.attr('target') || false,
name = ($title.size() > 0)
? $title.text()
: false
; ;
module.results.hide(); module.results.hide();
if(name) {
$prompt.val(name);
}
if(href) { if(href) {
if(target == '_blank' || event.ctrlKey) { if(target == '_blank' || event.ctrlKey) {
window.open(href); window.open(href);
@ -642,7 +666,7 @@ $.fn.search.settings = {
// api config // api config
apiSettings : false, apiSettings : false,
type : 'simple', type : 'simple',
minCharacters : 2,
minCharacters : 1,
source : false, source : false,
searchFields : [ searchFields : [
@ -651,7 +675,7 @@ $.fn.search.settings = {
], ],
automatic : 'true', automatic : 'true',
hideDelay : 300,
hideDelay : 0,
searchDelay : 300, searchDelay : 300,
maxResults : 7, maxResults : 7,
cache : true, cache : true,
@ -693,7 +717,8 @@ $.fn.search.settings = {
searchButton : '.search.button', searchButton : '.search.button',
results : '.results', results : '.results',
category : '.category', category : '.category',
result : '.result'
result : '.result',
title : '.title, .name'
}, },
templates: { templates: {
@ -756,7 +781,9 @@ $.fn.search.settings = {
// each item inside category // each item inside category
$.each(category.results, function(index, result) { $.each(category.results, function(index, result) {
html += '<div class="result">'; html += '<div class="result">';
html += '<a href="' + result.url + '"></a>';
if(result.url) {
html += '<a href="' + result.url + '"></a>';
}
if(result.image !== undefined) { if(result.image !== undefined) {
result.image = escape(result.image); result.image = escape(result.image);
html += '' html += ''
@ -787,10 +814,10 @@ $.fn.search.settings = {
; ;
} }
}); });
if(response.resultPage) {
if(response.action) {
html += '' html += ''
+ '<a href="' + response.resultPage.url + '" class="all">'
+ response.resultPage.text
+ '<a href="' + response.action.url + '" class="action">'
+ response.action.text
+ '</a>'; + '</a>';
} }
return html; return html;
@ -805,7 +832,9 @@ $.fn.search.settings = {
// each result // each result
$.each(response.results, function(index, result) { $.each(response.results, function(index, result) {
html += '<a class="result" href="' + result.url + '">';
if(result.url) {
html += '<a class="result" href="' + result.url + '">';
}
if(result.image !== undefined) { if(result.image !== undefined) {
html += '' html += ''
+ '<div class="image">' + '<div class="image">'
@ -825,8 +854,10 @@ $.fn.search.settings = {
} }
html += '' html += ''
+ '</div>' + '</div>'
+ '</a>'
; ;
if(results.url) {
html += '</a>';
}
}); });
if(response.resultPage) { if(response.resultPage) {

146
src/definitions/modules/search.less

@ -44,7 +44,6 @@
border: @promptBorder; border: @promptBorder;
color: @promptColor; color: @promptColor;
box-shadow: @promptBoxShadow; box-shadow: @promptBoxShadow;
box-sizing: border-box;
transition: @promptTransition; transition: @promptTransition;
} }
@ -65,7 +64,7 @@
Results Results
---------------*/ ---------------*/
.ui.search .results {
.ui.search > .results {
display: none; display: none;
position: absolute; position: absolute;
@ -87,7 +86,7 @@
Result Result
---------------*/ ---------------*/
.ui.search .result {
.ui.search > .results .result {
font-family: @pageFont; font-family: @pageFont;
cursor: pointer; cursor: pointer;
overflow: hidden; overflow: hidden;
@ -96,12 +95,12 @@
color: @resultTextColor; color: @resultTextColor;
line-height: @resultLineHeight; line-height: @resultLineHeight;
} }
.ui.search .result:first-child {
.ui.search > .results .result:first-child {
border-top: none; border-top: none;
} }
/* Image */ /* Image */
.ui.search .result .image {
.ui.search > .results .result .image {
float: @resultImageFloat; float: @resultImageFloat;
overflow: hidden; overflow: hidden;
background: @resultImageBackground; background: @resultImageBackground;
@ -109,7 +108,7 @@
height: @resultImageHeight; height: @resultImageHeight;
border-radius: @resultImageBorderRadius; border-radius: @resultImageBorderRadius;
} }
.ui.search .result .image img {
.ui.search > .results .result .image img {
display: block; display: block;
width: auto; width: auto;
height: 100%; height: 100%;
@ -119,19 +118,21 @@
Info Info
---------------*/ ---------------*/
.ui.search .result .image + .content {
.ui.search > .results .result .image + .content {
margin: @resultImageMargin; margin: @resultImageMargin;
} }
.ui.search .result .title {
.ui.search > .results .result .title {
font-family: @resultTitleFont; font-family: @resultTitleFont;
font-weight: @resultTitleFontWeight; font-weight: @resultTitleFontWeight;
font-size: @resultTitleFontSize;
color: @resultTitleColor; color: @resultTitleColor;
} }
.ui.search .result .description {
.ui.search > .results .result .description {
margin-top: @resultDescriptionDistance;
color: @resultDescriptionColor; color: @resultDescriptionColor;
} }
.ui.search .result .price {
.ui.search > .results .result .price {
float: @resultPriceFloat; float: @resultPriceFloat;
color: @resultPriceColor; color: @resultPriceColor;
} }
@ -140,31 +141,31 @@
Message Message
---------------*/ ---------------*/
.ui.search .message {
.ui.search > .results > .message {
padding: @messageVerticalPadding @messageHorizontalPadding; padding: @messageVerticalPadding @messageHorizontalPadding;
} }
.ui.search .message .header {
.ui.search > .results > .message .header {
font-family: @headerFont; font-family: @headerFont;
font-size: @messageHeaderFontSize; font-size: @messageHeaderFontSize;
font-weight: @messageHeaderFontWeight; font-weight: @messageHeaderFontWeight;
color: @messageHeaderColor; color: @messageHeaderColor;
} }
.ui.search .message .description {
.ui.search > .results > .message .description {
margin-top: @messageDescriptionDistance; margin-top: @messageDescriptionDistance;
font-size: @messageDescriptionFontSize; font-size: @messageDescriptionFontSize;
color: @messageDescriptionColor; color: @messageDescriptionColor;
} }
/* View All Results */ /* View All Results */
.ui.search .all {
.ui.search > .results > .action {
display: block; display: block;
border-top: @allResultsBorder;
background-color: @allResultsBackground;
height: @allResultsHeight;
line-height: @allResultsHeight;
color: @allResultsColor;
font-weight: @allResultsFontWeight;
text-align: @allResultsAlign;
border-top: @actionBorder;
background: @actionBackground;
height: @actionHeight;
line-height: @actionHeight;
color: @actionColor;
font-weight: @actionFontWeight;
text-align: @actionAlign;
} }
@ -173,39 +174,80 @@
States States
*******************************/ *******************************/
/*--------------------
Loading
---------------------*/
.ui.loading.search .input > .icon:before {
position: absolute;
content: '';
top: 50%;
left: 50%;
margin: @loaderMargin;
width: @loaderSize;
height: @loaderSize;
border-radius: @circularRadius;
border: @loaderLineWidth solid @loaderFillColor;
}
.ui.loading.search .input > .icon:after {
position: absolute;
content: '';
top: 50%;
left: 50%;
margin: @loaderMargin;
width: @loaderSize;
height: @loaderSize;
animation: button-spin @loaderSpeed linear;
animation-iteration-count: infinite;
border-radius: @circularRadius;
border-color: @loaderLineColor transparent transparent;
border-style: solid;
border-width: @loaderLineWidth;
box-shadow: 0px 0px 0px 1px transparent;
}
/*-------------- /*--------------
Hover Hover
---------------*/ ---------------*/
.ui.search .result:hover,
.ui.search .results .category .result:hover {
.ui.search > .results .result:hover,
.ui.search > .results .category .result:hover {
background: @resultHoverBackground; background: @resultHoverBackground;
} }
.ui.search .all:hover { .ui.search .all:hover {
background: @allResultsHoverBackground;
background: @actionHoverBackground;
} }
/*-------------- /*--------------
Active Active
---------------*/ ---------------*/
.ui.search .results .category.active {
background-color: @categoryActiveBackground;
.ui.search > .results .category.active {
background: @categoryActiveBackground;
} }
.ui.search .results .category.active > .name {
.ui.search > .results .category.active > .name {
color: @categoryNameActiveColor; color: @categoryNameActiveColor;
} }
.ui.search .result.active,
.ui.search .results .category .result.active {
.ui.search > .results .result.active,
.ui.search > .results .category .result.active {
position: relative;
border-left-color: @resultActiveBorderLeft; border-left-color: @resultActiveBorderLeft;
background-color: @resultActiveBackground;
background: @resultActiveBackground;
box-shadow: @resultActiveBoxShadow; box-shadow: @resultActiveBoxShadow;
} }
.ui.search .result.active .title {
.ui.search > .results .result.active .title {
color: @resultActiveTitleColor; color: @resultActiveTitleColor;
} }
.ui.search .result.active .description {
.ui.search > .results .result.active .description {
color: @resultActiveDescriptionColor; color: @resultActiveDescriptionColor;
} }
@ -218,7 +260,11 @@
Left / Right Left / Right
--------------------*/ --------------------*/
.ui.right.aligned.search .results {
.ui[class*="left aligned"].search > .results {
right: auto;
left: 0%;
}
.ui[class*="right aligned"].search > .results {
right: 0%; right: 0%;
left: auto; left: auto;
} }
@ -227,34 +273,40 @@
Categories Categories
---------------*/ ---------------*/
.ui.search .results .category {
/* Category */
.ui.search > .results .category {
background: @categoryBackground; background: @categoryBackground;
box-shadow: @categoryBoxShadow; box-shadow: @categoryBoxShadow;
border-bottom: @categoryDivider;
transition: @categoryTransition;
} }
.ui.search .results .category,
.ui.search .results .category .result {
position: relative;
.ui.search > .results .category:last-child {
border-bottom: none;
}
/* Category Result */
.ui.search > .results .category .result {
background: @categoryResultBackground;
margin-left: @categoryNameWidth;
border-left: @categoryResultLeftBorder;
border-bottom: @categoryResultDivider;
transition: @categoryResultTransition; transition: @categoryResultTransition;
} }
.ui.search .results .category:first-child {
box-shadow: none;
.ui.search > .results .category .result:last-child {
border-bottom: @categoryResultLastDivider;
} }
.ui.search .results .category > .name {
/* Category Result Name */
.ui.search > .results .category > .name {
background: @categoryNameBackground;
font-family: @categoryNameFont; font-family: @categoryNameFont;
width: @categoryNameWidth;
float: @categoryNameFontSize; float: @categoryNameFontSize;
float: @categoryNameFloat; float: @categoryNameFloat;
padding: @categoryNamePadding; padding: @categoryNamePadding;
font-weight: @categoryNameFontWeight; font-weight: @categoryNameFontWeight;
color: @categoryNameColor; color: @categoryNameColor;
} }
.ui.search .results .category .result {
background-color: @categoryResultBackground;
margin-left: @categoryNameWidth;
border-left: @categoryResultLeftBorder;
border-bottom: @categoryResultTopBorder;
}
/******************************* /*******************************
Variations Variations

62
src/themes/default/modules/search.variables

@ -28,7 +28,7 @@
@resultsBoxShadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.2); @resultsBoxShadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.2);
/* Result */ /* Result */
@resultFontSize: 0.9em;
@resultFontSize: 0.9285em;
@resultVerticalPadding: 0.5em; @resultVerticalPadding: 0.5em;
@resultHorizontalPadding: 1em; @resultHorizontalPadding: 1em;
@resultTextColor: @textColor; @resultTextColor: @textColor;
@ -44,9 +44,15 @@
/* Result Content */ /* Result Content */
@resultTitleFont: @headerFont; @resultTitleFont: @headerFont;
@resultTitleFontWeight: normal;
@resultTitleFontWeight: bold;
@resultTitleFontSize: 1.1em;
@resultTitleColor: @darkTextColor; @resultTitleColor: @darkTextColor;
@resultDescriptionColor: @textColor;
/* Description */
@resultDescriptionDistance: 0.25em;
@resultDescriptionColor: @lightTextColor;
/* Price */
@resultPriceFloat: right; @resultPriceFloat: right;
@resultPriceColor: @green; @resultPriceColor: @green;
@ -61,12 +67,12 @@
@messageDescriptionColor: @textColor; @messageDescriptionColor: @textColor;
/* All Results Link */ /* All Results Link */
@allResultsBorder: 1px solid rgba(0, 0, 0, 0.1);
@allResultsBackground: #F0F0F0;
@allResultsHeight: 2em;
@allResultsColor: @textColor;
@allResultsFontWeight: bold;
@allResultsAlign: center;
@actionBorder: 1px solid @borderColor;
@actionBackground: #F0F0F0;
@actionHeight: 2em;
@actionColor: @textColor;
@actionFontWeight: bold;
@actionAlign: center;
/******************************* /*******************************
@ -74,20 +80,23 @@
*******************************/ *******************************/
/* Hover */ /* Hover */
@resultHoverBackground: #FAFAFA;
@allResultsHoverBackground: #FAFAFA;
@resultHoverBackground: @offWhite;
@actionHoverBackground: @offWhite;
/* Loading */ /* Loading */
@loaderPath: "@{imagePath}/loader-mini.gif";
@loaderSize: 1.2857em;
@loaderOffset: -(@loaderSize / 2);
@loaderMargin: @loaderOffset 0em 0em @loaderOffset;
@invertedLoaderFillColor: rgba(0, 0, 0, 0.15);
/* Active Category */ /* Active Category */
@categoryActiveBackground: #F1F1F1;
@categoryActiveBackground: @darkWhite;
@categoryNameActiveColor: @textColor; @categoryNameActiveColor: @textColor;
/* Active Result */ /* Active Result */
@resultActiveBorderLeft: transparent; @resultActiveBorderLeft: transparent;
@resultActiveBackground: #F0F0F0;
@resultActiveBoxShadow: 2px 0px 2px 0px rgba(0, 0, 0, 0.2);
@resultActiveBackground: @darkWhite;
@resultActiveBoxShadow: 3px 0px 3px 0px @borderColor;
@resultActiveTitleColor: @darkTextColor; @resultActiveTitleColor: @darkTextColor;
@resultActiveDescriptionColor: @darkTextColor; @resultActiveDescriptionColor: @darkTextColor;
@ -97,21 +106,28 @@
*******************************/ *******************************/
/* Category */ /* Category */
@categoryBackground: #F0F0F0;
@categoryBoxShadow: 0px -1px 0px 0px rgba(0, 0, 0, 0.1);
@categoryResultTransition: background 0.2s ease, border-color 0.2s ease;
@categoryBackground: @darkWhite;
@categoryBoxShadow: none;
@categoryDivider: 1px solid @borderColor;
@categoryTransition:
background 0.2s ease,
border-color 0.2s ease
;
@categoryResultBackground: @white;
@categoryResultLeftBorder: 1px solid @borderColor;
@categoryResultDivider: 1px solid @borderColor;
@categoryResultLastDivider: none;
@categoryResultTransition: @categoryTransition;
@categoryNameBackground: @darkWhite;
@categoryNameFont: @pageFont; @categoryNameFont: @pageFont;
@categoryNameFontSize: 0.9em; @categoryNameFontSize: 0.9em;
@categoryNameFloat: left; @categoryNameFloat: left;
@categoryNamePadding: 0.4em 0em 0em 1em;
@categoryNamePadding: 0.4em 1em;
@categoryNameFontWeight: bold; @categoryNameFontWeight: bold;
@categoryNameColor: @lightTextColor; @categoryNameColor: @lightTextColor;
@categoryResultBackground: #FFFFFF;
@categoryNameWidth: 100px; @categoryNameWidth: 100px;
@categoryResultLeftBorder: 1px solid rgba(0, 0, 0, 0.1);
@categoryResultTopBorder: 1px solid rgba(0, 0, 0, 0.1);
/* Sizes */ /* Sizes */
@medium: 1em; @medium: 1em;

Loading…
Cancel
Save