Skip to content

Commit

Permalink
Fix search.js interferace with other forms
Browse files Browse the repository at this point in the history
- cc/ issue #194
  • Loading branch information
mmistakes committed Sep 11, 2016
1 parent 6b37a0b commit e3baabf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions assets/js/plugins/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
========================================================================== */

var q, jsonFeedUrl = "/search.json",
$searchForm = $(".simple-search"),
$searchForm = "[data-search-form]",
$searchInput = $("[data-search-input]"),
$resultTemplate = $("#search-result"),
$resultsPlaceholder = $("[data-search-results]"),
Expand All @@ -25,7 +25,7 @@ var q, jsonFeedUrl = "/search.json",


$(document).ready( function() {

// hide items found string
$foundContainer.hide();

Expand All @@ -39,7 +39,7 @@ $(document).ready( function() {
/* ==========================================================================
Search functions
========================================================================== */


/**
* Initiate search functionality.
Expand All @@ -66,7 +66,7 @@ function initSearch() {

/**
* Executes search
* @param {String} q
* @param {String} q
* @return null
*/
function execSearch(q) {
Expand All @@ -92,7 +92,7 @@ function toggleLoadingClass() {

/**
* Get Search results from JSON
* @param {Function} callbackFunction
* @param {Function} callbackFunction
* @return null
*/
function getSearchResults(callbackFunction) {
Expand All @@ -106,14 +106,14 @@ function getSearchResults(callbackFunction) {
*/
function processData() {
$results = [];

return function(data) {

var resultsCount = 0,
results = "";

$.each(data, function(index, item) {
// check if search term is in content or title
// check if search term is in content or title
if (item.excerpt.toLowerCase().indexOf(q.toLowerCase()) > -1 || item.title.toLowerCase().indexOf(q.toLowerCase()) > -1) {
var result = populateResultContent($resultTemplate.html(), item);
resultsCount++;
Expand Down Expand Up @@ -144,7 +144,7 @@ function showSearchResults(results) {

/**
* Add results content to item template
* @param {String} html
* @param {String} html
* @param {object} item
* @return {String} Populated HTML
*/
Expand All @@ -159,7 +159,7 @@ function populateResultContent(html, item) {

/**
* Populates results string
* @param {String} count
* @param {String} count
* @return null
*/
function populateResultsString(count) {
Expand All @@ -178,7 +178,7 @@ function populateResultsString(count) {

/**
* Gets query string parameter - taken from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
* @param {String} name
* @param {String} name
* @return {String} parameter value
*/
function getParameterByName(name) {
Expand All @@ -191,10 +191,10 @@ function getParameterByName(name) {
* Injects content into template using placeholder
* @param {String} originalContent
* @param {String} injection
* @param {String} placeholder
* @param {String} placeholder
* @return {String} injected content
*/
function injectContent(originalContent, injection, placeholder) {
var regex = new RegExp(placeholder, 'g');
return originalContent.replace(regex, injection);
}
}
Loading

0 comments on commit e3baabf

Please sign in to comment.