|
1 | 1 | //uglifyjs unbxdSearch.js -o unbxdSearch.min.js && gzip -c unbxdSearch.min.js > unbxdSearch.min.js.gz && aws s3 cp unbxdSearch.min.js.gz s3://unbxd/unbxdSearch.js --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-encoding gzip --cache-control max-age=3600
|
2 |
| -var unbxdSearchInit = function(jQuery, Handlebars){ |
| 2 | +var unbxdSearchInit = function(jQuery, Handlebars){ |
3 | 3 | window.Unbxd = window.Unbxd || {};
|
4 |
| - Unbxd.jsSdkVersion = "1.0.2"; |
| 4 | + Unbxd.jsSdkVersion = "1.0.3"; |
5 | 5 |
|
6 | 6 | // Production steps of ECMA-262, Edition 5, 15.4.4.14
|
7 | 7 | // Reference: http://es5.github.io/#x15.4.4.14
|
@@ -519,109 +519,65 @@ var unbxdSearchInit = function(jQuery, Handlebars){
|
519 | 519 | ,hashChangeInterval : null
|
520 | 520 | ,ajaxCall : null
|
521 | 521 | ,init : function(){
|
522 |
| - this.isHashChange = !!("onhashchange" in window.document.body); |
523 |
| - this.$input = jQuery(this.options.inputSelector); |
524 |
| - this.$input.val(''); |
525 |
| - this.input = this.$input[0]; |
526 |
| - this.setEvents(); |
527 |
| - this.reset(); |
528 |
| - this.params.categoryId = this.options.type == "browse" && typeof this.options.getCategoryId == "function" ? this.options.getCategoryId() : ""; |
529 |
| - if(this.params.categoryId.length > 0){ |
530 |
| - if(this.getQueryParams()["category-id"] == this.params.categoryId){ |
531 |
| - var cur_url = this.getUrlSubstring() |
532 |
| - , urlqueryparams = this.getQueryParams(cur_url) |
533 |
| - , decodedParams = !/[^A-Za-z0-9\+\/\=]/g.test(cur_url) ? this.getQueryParams(this.decode(cur_url)) : {} |
534 |
| - , queryparamcount = Object.keys(urlqueryparams).length |
535 |
| - , decodedParamscount = Object.keys(decodedParams).length |
536 |
| - , finalParams = null ; |
537 |
| - if (!this.options.noEncoding && decodedParamscount > 0) { |
538 |
| - finalParams = this._processURL(decodedParams) |
539 |
| - } else { |
540 |
| - finalParams = this._processURL(urlqueryparams) |
541 |
| - } |
542 |
| - this.params = finalParams; |
543 |
| - this.setPage("page" in finalParams.extra ? finalParams.extra.page : 1).setPageSize("rows" in finalParams.extra ? finalParams.extra.rows : this.options.pageSize); |
544 |
| - if (typeof this.options.setDefaultFilters == "function") |
545 |
| - this.setDefaultParams(this.params); |
546 |
| - this.callResults(this.paintResultSet) |
547 |
| - }else{ |
548 |
| - if (typeof this.options.setDefaultFilters == "function") |
549 |
| - this.setDefaultParams(this.params); |
550 |
| - this.setPage(1).setPageSize(this.options.pageSize); |
551 |
| - this.callResults(this.paintResultSet) |
552 |
| - } |
553 |
| - }else if(this.options.type == "search" && this.input.value.trim().length){ |
554 |
| - if(typeof this.options.setDefaultFilters == "function") |
555 |
| - this.setDefaultParams(this.params); |
| 522 | + this.isHashChange = !!("onhashchange" in window.document.body); |
556 | 523 |
|
557 |
| - this.params.query = this.$input.val().trim(); |
| 524 | + this.$input = jQuery(this.options.inputSelector); |
| 525 | + this.$input.val(''); |
| 526 | + this.input = this.$input[0]; |
558 | 527 |
|
559 |
| - if(this.options.deferInitRender.indexOf('search') === -1) |
560 |
| - jQuery(this.options.searchResultContainer).html(''); |
561 |
| - |
562 |
| - this.setPage(1) |
563 |
| - .setPageSize(this.options.pageSize); |
564 |
| - |
565 |
| - this.callResults(this.paintResultSet); |
566 |
| - }else{ |
567 |
| - var cur_url = this.getUrlSubstring() |
568 |
| - ,urlqueryparams = this.getQueryParams(cur_url) |
569 |
| - // add test to check if the url is encoded, |
570 |
| - // decode the query parameters only if url is encoded |
571 |
| - // fixes SKU searches like writ0035/WRIT0035 & HSWD0015 |
572 |
| - ,decodedParams = !(/[^A-Za-z0-9\+\/\=]/g.test(cur_url)) ? this.getQueryParams(this.decode(cur_url)) : {} |
573 |
| - ,queryparamcount = Object.keys(urlqueryparams).length |
574 |
| - ,decodedParamscount = Object.keys(decodedParams).length |
575 |
| - ,finalParams = null; |
576 |
| - |
577 |
| - if(!this.options.noEncoding && decodedParamscount > 0){ |
578 |
| - finalParams = this._processURL(decodedParams); |
579 |
| - }else{ |
580 |
| - finalParams = this._processURL(urlqueryparams); |
581 |
| - } |
| 528 | + this.setEvents(); |
582 | 529 |
|
583 |
| - if(this.options.deferInitRender.indexOf('search') > -1 |
584 |
| - && !this.isUsingPagination() |
585 |
| - && finalParams.extra.hasOwnProperty('page') |
586 |
| - && finalParams.extra.page >= 1) |
587 |
| - finalParams.extra.page = finalParams.extra.page + 1; |
| 530 | + this.reset(); |
588 | 531 |
|
| 532 | + this.params.categoryId = this.options.type == "browse" && typeof this.options.getCategoryId == "function" ? this.options.getCategoryId() : ""; |
| 533 | + var cur_url = this.getUrlSubstring() |
| 534 | + ,urlqueryparams = this.getQueryParams(cur_url) |
| 535 | + // add test to check if the url is encoded, |
| 536 | + // decode the query parameters only if url is encoded |
| 537 | + // fixes SKU searches like writ0035/WRIT0035 & HSWD0015 |
| 538 | + ,decodedParams = !(/[^A-Za-z0-9\+\/\=]/g.test(cur_url)) ? this.getQueryParams(this.decode(cur_url)) : {} |
| 539 | + ,queryparamcount = Object.keys(urlqueryparams).length |
| 540 | + ,decodedParamscount = Object.keys(decodedParams).length |
| 541 | + ,finalParams = null; |
589 | 542 |
|
590 |
| - if(this.options.type == "search"){ |
591 |
| - this.params = finalParams; |
592 |
| - |
593 |
| - if(typeof this.options.setDefaultFilters == "function") |
594 |
| - this.setDefaultParams(this.params); |
| 543 | + if(!this.options.noEncoding && decodedParamscount > 0){ |
| 544 | + finalParams = this._processURL(decodedParams); |
| 545 | + }else{ |
| 546 | + finalParams = this._processURL(urlqueryparams); |
| 547 | + } |
595 | 548 |
|
| 549 | + if(this.options.deferInitRender.indexOf('search') > -1 |
| 550 | + && !this.isUsingPagination() |
| 551 | + && finalParams.extra.hasOwnProperty('page') |
| 552 | + && finalParams.extra.page >= 1) |
| 553 | + finalParams.extra.page = finalParams.extra.page + 1; |
596 | 554 |
|
597 |
| - if(!("query" in this.params) || (this.params.query + "").trim().length == 0) |
598 |
| - this.params.query = "*"; |
| 555 | + this.params = finalParams; |
599 | 556 |
|
600 |
| - this.params.query = this.options.sanitizeQueryString.call(this,this.params.query); |
| 557 | + this.setPage("page" in finalParams.extra ? finalParams.extra.page : 1) |
| 558 | + .setPageSize("rows" in finalParams.extra ? finalParams.extra.rows : this.options.pageSize); |
601 | 559 |
|
602 |
| - this.$input.val(this.params.query != "*" ? this.params.query : ""); |
| 560 | + if(this.options.type == "search"){ |
| 561 | + if(this.input.value.trim().length) |
| 562 | + this.params.query = this.$input.val().trim(); |
| 563 | + else if(!("query" in this.params) || (this.params.query + "").trim().length == 0) |
| 564 | + this.params.query = "*"; |
603 | 565 |
|
604 |
| - if(this.options.deferInitRender.indexOf('search') === -1) |
605 |
| - jQuery(this.options.searchResultContainer).html(''); |
| 566 | + this.params.query = this.options.sanitizeQueryString.call(this,this.params.query); |
606 | 567 |
|
607 |
| - this.setPage("page" in finalParams.extra ? finalParams.extra.page : 1) |
608 |
| - .setPageSize("rows" in finalParams.extra ? finalParams.extra.rows : this.options.pageSize); |
| 568 | + this.$input.val(this.params.query != "*" ? this.params.query : ""); |
609 | 569 |
|
610 |
| - if(this.params.query){ |
611 |
| - this.callResults(this.paintResultSet); |
612 |
| - } |
613 |
| - }else if(this.options.type == "browse" && "categoryId" in finalParams && finalParams["categoryId"].trim().length > 0){ |
614 |
| - this.params = finalParams; |
| 570 | + if(this.options.deferInitRender.indexOf('search') === -1) |
| 571 | + jQuery(this.options.searchResultContainer).html(''); |
615 | 572 |
|
616 |
| - if(typeof this.options.setDefaultFilters == "function") |
617 |
| - this.setDefaultParams(this.params); |
| 573 | + } |
618 | 574 |
|
619 |
| - this.setPage("page" in finalParams.extra ? finalParams.extra.page : 1) |
620 |
| - .setPageSize("rows" in finalParams.extra ? finalParams.extra.rows : this.options.pageSize); |
| 575 | + if(typeof this.options.setDefaultFilters == "function") |
| 576 | + this.setDefaultParams(this.params); |
621 | 577 |
|
622 |
| - this.callResults(this.paintResultSet); |
623 |
| - } |
624 |
| - } |
| 578 | + if((this.options.type == "search" && "query" in this.params && this.params["query"].trim().length > 0) || |
| 579 | + (this.options.type == "browse" && "categoryId" in this.params && this.params["categoryId"].trim().length > 0)) |
| 580 | + this.callResults(this.paintResultSet); |
625 | 581 | }
|
626 | 582 | ,getClass : function(object){
|
627 | 583 | return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
|
@@ -680,63 +636,57 @@ var unbxdSearchInit = function(jQuery, Handlebars){
|
680 | 636 | if(this.options.type == "search"){
|
681 | 637 | if("form" in this.input && this.input.form){
|
682 | 638 | jQuery(this.input.form).bind("submit",function(e){
|
683 |
| - e.preventDefault(); |
| 639 | + e.preventDefault(); |
684 | 640 |
|
685 |
| - self.reset(); |
| 641 | + self.reset(); |
686 | 642 |
|
687 |
| - self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
| 643 | + self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
688 | 644 |
|
689 | 645 | if(self.options.deferInitRender.indexOf('search') === -1)
|
690 | 646 | jQuery(self.options.searchResultContainer).html('');
|
691 | 647 |
|
692 |
| - if(typeof self.options.setDefaultFilters == "function") |
693 |
| - self.setDefaultParams(self.params); |
694 |
| - |
695 |
| - self.setPage(1) |
696 |
| - .setPageSize(self.options.pageSize) |
| 648 | + self.setPage(1) |
| 649 | + .setPageSize(self.options.pageSize) |
697 | 650 |
|
698 |
| - if(self.params.query) |
699 |
| - self.callResults(self.paintResultSet,true); |
| 651 | + if(self.params.query) |
| 652 | + self.callResults(self.paintResultSet,true); |
700 | 653 | });
|
701 | 654 | }else{
|
702 | 655 | this.$input.bind('keydown',function(e){
|
703 | 656 | if(e.which == 13){
|
704 |
| - e.preventDefault(); |
| 657 | + e.preventDefault(); |
705 | 658 |
|
706 |
| - self.reset(); |
| 659 | + self.reset(); |
707 | 660 |
|
708 |
| - self.params.query = self.options.sanitizeQueryString.call(self, this.value ); |
| 661 | + self.params.query = self.options.sanitizeQueryString.call(self, this.value ); |
709 | 662 |
|
710 | 663 | if(self.options.deferInitRender.indexOf('search') === -1)
|
711 | 664 | jQuery(self.options.searchResultContainer).html('');
|
712 | 665 |
|
713 |
| - if(typeof self.options.setDefaultFilters == "function") |
714 |
| - self.setDefaultParams(self.params); |
715 |
| - |
716 |
| - self.clearFilters(true).setPage(1) |
717 |
| - .setPageSize(self.options.pageSize) |
| 666 | + self.clearFilters(true).setPage(1) |
| 667 | + .setPageSize(self.options.pageSize) |
718 | 668 |
|
719 |
| - if(self.params.query) |
720 |
| - self.callResults(self.paintResultSet,true); |
| 669 | + if(self.params.query) |
| 670 | + self.callResults(self.paintResultSet,true); |
721 | 671 | }
|
722 | 672 | });
|
723 | 673 |
|
724 | 674 | if(this.options.searchButtonSelector.length){
|
725 | 675 | jQuery(this.options.searchButtonSelector).bind("click",function(e){
|
726 |
| - e.preventDefault(); |
| 676 | + e.preventDefault(); |
727 | 677 |
|
728 |
| - self.reset(); |
| 678 | + self.reset(); |
729 | 679 |
|
730 |
| - self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
| 680 | + self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
731 | 681 |
|
732 | 682 | if(self.options.deferInitRender.indexOf('search') === -1)
|
733 | 683 | jQuery(self.options.searchResultContainer).html('');
|
734 | 684 |
|
735 |
| - self.clearFilters(true).setPage(1) |
736 |
| - .setPageSize(self.options.pageSize) |
| 685 | + self.clearFilters(true).setPage(1) |
| 686 | + .setPageSize(self.options.pageSize) |
737 | 687 |
|
738 |
| - if(self.params.query) |
739 |
| - self.callResults(self.paintResultSet,true); |
| 688 | + if(self.params.query) |
| 689 | + self.callResults(self.paintResultSet,true); |
740 | 690 | });
|
741 | 691 | }
|
742 | 692 | }
|
@@ -1058,7 +1008,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
|
1058 | 1008 | var nonhistoryPath = "";
|
1059 | 1009 |
|
1060 | 1010 | if(this.options.type == "search" && this.params['query'] != undefined){
|
1061 |
| - url += '&'+ this.options.searchQueryParam +'='+ encodeURIComponent(this.params.query); |
| 1011 | + url += '&'+ this.options.searchQueryParam +'='+ encodeURIComponent(this.params.query); |
1062 | 1012 | }else if(this.options.type == "browse" && this.params['categoryId'] != undefined){
|
1063 | 1013 | url += '&category-id=' + encodeURIComponent(this.params.categoryId);
|
1064 | 1014 | }
|
@@ -1218,36 +1168,42 @@ var unbxdSearchInit = function(jQuery, Handlebars){
|
1218 | 1168 |
|
1219 | 1169 | jQuery(this.options.facetContainerSelector).empty();
|
1220 | 1170 |
|
1221 |
| - this.options.selectedFacetHolderSelector && jQuery(this.options.selectedFacetHolderSelector).hide(); |
| 1171 | + this.options.selectedFacetHolderSelector && jQuery(this.options.selectedFacetHolderSelector).hide(); |
1222 | 1172 |
|
1223 |
| - this.options.loaderSelector.length > 0 && jQuery(this.options.loaderSelector).hide(); |
| 1173 | + this.options.loaderSelector.length > 0 && jQuery(this.options.loaderSelector).hide(); |
1224 | 1174 |
|
1225 |
| - this.params = { |
1226 |
| - query : '*' |
1227 |
| - ,filters : {} |
1228 |
| - ,sort : {} |
1229 |
| - ,ranges : {} |
1230 |
| - ,categoryId : "" |
1231 |
| - ,extra : { |
1232 |
| - format: "json" |
1233 |
| - ,page: 1 |
1234 |
| - ,rows: 12 |
1235 |
| - } |
1236 |
| - }; |
| 1175 | + this.params = { |
| 1176 | + query : '*' |
| 1177 | + ,filters : {} |
| 1178 | + ,sort : {} |
| 1179 | + ,ranges : {} |
| 1180 | + ,categoryId : "" |
| 1181 | + ,extra : { |
| 1182 | + format: "json" |
| 1183 | + ,page: 1 |
| 1184 | + ,rows: 12 |
| 1185 | + } |
| 1186 | + }; |
1237 | 1187 |
|
1238 | 1188 | if( this.options.viewTypes && this.options.viewTypes.length > 0)
|
1239 | 1189 | this.params.extra.view = this.options.viewTypes[0];
|
1240 | 1190 |
|
1241 | 1191 | if(typeof this.options.customReset == "function")
|
1242 | 1192 | this.options.customReset.call(this);
|
1243 | 1193 |
|
| 1194 | + if(typeof this.options.setDefaultFilters == "function") |
| 1195 | + this.setDefaultParams(this.params); |
| 1196 | + |
1244 | 1197 | return this;
|
1245 | 1198 | }
|
1246 | 1199 | ,setDefaultParams: function(params){
|
| 1200 | + var newparams, diff; |
| 1201 | + var oldparams = JSON.stringify(params); |
1247 | 1202 | this.options.setDefaultFilters.call(this);
|
1248 |
| - |
| 1203 | + newparams = JSON.stringify(this.params); |
| 1204 | + |
1249 | 1205 | if(Object.keys(this.defaultParams).length === 0)
|
1250 |
| - this.defaultParams = jQuery.extend(true, {}, this.params); |
| 1206 | + this.defaultParams = JSON.parse(newparams); |
1251 | 1207 | }
|
1252 | 1208 | ,_processURL: function(url){
|
1253 | 1209 | var obj = typeof url == "string" ? this.getQueryParams(url) : url
|
|
0 commit comments