Skip to content

Commit

Permalink
Merge pull request #11 from bigcommerce/searcher
Browse files Browse the repository at this point in the history
Renderable AJAX
  • Loading branch information
hegrec committed May 4, 2015
2 parents 9266230 + d63cfe4 commit 7274617
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import AccountEvents from './account';
import CartEvents from './cart';
import CurrencySelectorEvents from './currency-selector';
import ProductEvents from './product';
import SearchEvents from './search';

export {
AccountEvents,
CartEvents,
CurrencySelectorEvents,
ProductEvents
ProductEvents,
SearchEvents
};
19 changes: 19 additions & 0 deletions src/events/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import BaseEvents from './base';

export default class SearchEvents extends BaseEvents {

/**
* @Constructor
* @param {object} options
*/
constructor(options) {
this.options = options || {};

this.dataMap = {
'[data-quick-search]': {
eventName: 'search-quick',
trigger: ['input']
}
};
}
}
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import {
AccountEvents,
CartEvents,
CurrencySelectorEvents,
ProductEvents
ProductEvents,
SearchEvents
} from './events/index';
import {
RemoteCountry,
RemoteProductAttributes
RemoteProduct,
RemoteProductAttributes,
Search
} from './remote/index';

let internals = {
Expand All @@ -17,7 +20,8 @@ internals.eventClasses = {
account: AccountEvents,
cart: CartEvents,
currencySelector: CurrencySelectorEvents,
product: ProductEvents
product: ProductEvents,
search: SearchEvents
};

internals.init = function (events) {
Expand Down Expand Up @@ -53,7 +57,9 @@ internals.events = function (eventTypes) {
internals.remote = function () {
return {
country: new RemoteCountry(),
productAttributes: new RemoteProductAttributes()
productAttributes: new RemoteProductAttributes(),
product: new RemoteProduct(),
search: new Search()
}
};

Expand Down
9 changes: 8 additions & 1 deletion src/remote/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import RemoteBC from './remote';
import RemoteCountry from './countries';
import RemoteProduct from './product';
import RemoteProductAttributes from './product-attributes';
import Search from './search';

export default RemoteBC;
export { RemoteCountry, RemoteProductAttributes };
export {
RemoteCountry,
RemoteProductAttributes,
RemoteProduct,
Search
};
33 changes: 33 additions & 0 deletions src/remote/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import RemoteBC from './remote';
import $ from 'jquery';

export default class RemoteProduct extends RemoteBC
{
/**
* @Constructor
*/
constructor() {
// call parent
super();

this.endPoint = '/product/';
}

/**
*
* @param productId
* @param params
* @param callback
*/
getById(productId, params, callback)
{
let url = this.endPoint + productId;

if (typeof params === 'function') {
callback = params;
params = {};
}

this.makeRequest(url, 'GET', params, callback);
}
}
28 changes: 28 additions & 0 deletions src/remote/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import RemoteBC from './remote';
import _ from 'lodash';

export default class Search extends RemoteBC
{
/**
* @Constructor
*/
constructor() {
// call parent
super();

// set up class variables
this.endPoint = '/search';
}

/**
* Get search results
* @param {String} query
* @param {Object} params
* @param {Function} callback
*/
search(query, params, callback) {
params.search_query = encodeURIComponent(query);

this.makeRequest(this.endPoint, 'GET', params, callback);
}
}

0 comments on commit 7274617

Please sign in to comment.