|
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,66 @@ 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 | + var cur_url = this.getUrlSubstring() |
| 533 | + ,urlqueryparams = this.getQueryParams(cur_url) |
| 534 | + // add test to check if the url is encoded, |
| 535 | + // decode the query parameters only if url is encoded |
| 536 | + // fixes SKU searches like writ0035/WRIT0035 & HSWD0015 |
| 537 | + ,decodedParams = !(/[^A-Za-z0-9\+\/\=]/g.test(cur_url)) ? this.getQueryParams(this.decode(cur_url)) : {} |
| 538 | + ,queryparamcount = Object.keys(urlqueryparams).length |
| 539 | + ,decodedParamscount = Object.keys(decodedParams).length |
| 540 | + ,finalParams = null; |
589 | 541 |
|
590 |
| - if(this.options.type == "search"){ |
591 |
| - this.params = finalParams; |
| 542 | + if(!this.options.noEncoding && decodedParamscount > 0){ |
| 543 | + finalParams = this._processURL(decodedParams); |
| 544 | + }else{ |
| 545 | + finalParams = this._processURL(urlqueryparams); |
| 546 | + } |
592 | 547 |
|
593 |
| - if(typeof this.options.setDefaultFilters == "function") |
594 |
| - this.setDefaultParams(this.params); |
| 548 | + if(this.options.deferInitRender.indexOf('search') > -1 |
| 549 | + && !this.isUsingPagination() |
| 550 | + && finalParams.extra.hasOwnProperty('page') |
| 551 | + && finalParams.extra.page >= 1) |
| 552 | + finalParams.extra.page = finalParams.extra.page + 1; |
595 | 553 |
|
| 554 | + this.params = finalParams; |
596 | 555 |
|
597 |
| - if(!("query" in this.params) || (this.params.query + "").trim().length == 0) |
598 |
| - this.params.query = "*"; |
| 556 | + this.params.categoryId = this.options.type == "browse" && typeof this.options.getCategoryId == "function" ? this.options.getCategoryId() : ""; |
599 | 557 |
|
600 |
| - this.params.query = this.options.sanitizeQueryString.call(this,this.params.query); |
| 558 | + this.setPage("page" in finalParams.extra ? finalParams.extra.page : 1) |
| 559 | + .setPageSize("rows" in finalParams.extra ? finalParams.extra.rows : this.options.pageSize); |
601 | 560 |
|
602 |
| - this.$input.val(this.params.query != "*" ? this.params.query : ""); |
| 561 | + if(this.options.type == "search"){ |
| 562 | + if(this.input.value.trim().length) |
| 563 | + this.params.query = this.$input.val().trim(); |
| 564 | + else if(!("query" in this.params) || (this.params.query + "").trim().length == 0) |
| 565 | + this.params.query = "*"; |
603 | 566 |
|
604 |
| - if(this.options.deferInitRender.indexOf('search') === -1) |
605 |
| - jQuery(this.options.searchResultContainer).html(''); |
| 567 | + this.params.query = this.options.sanitizeQueryString.call(this,this.params.query); |
606 | 568 |
|
607 |
| - this.setPage("page" in finalParams.extra ? finalParams.extra.page : 1) |
608 |
| - .setPageSize("rows" in finalParams.extra ? finalParams.extra.rows : this.options.pageSize); |
| 569 | + this.$input.val(this.params.query != "*" ? this.params.query : ""); |
609 | 570 |
|
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; |
| 571 | + if(this.options.deferInitRender.indexOf('search') === -1) |
| 572 | + jQuery(this.options.searchResultContainer).html(''); |
615 | 573 |
|
616 |
| - if(typeof this.options.setDefaultFilters == "function") |
617 |
| - this.setDefaultParams(this.params); |
| 574 | + } |
618 | 575 |
|
619 |
| - this.setPage("page" in finalParams.extra ? finalParams.extra.page : 1) |
620 |
| - .setPageSize("rows" in finalParams.extra ? finalParams.extra.rows : this.options.pageSize); |
| 576 | + if(typeof this.options.setDefaultFilters == "function") |
| 577 | + this.setDefaultParams(this.params); |
621 | 578 |
|
622 |
| - this.callResults(this.paintResultSet); |
623 |
| - } |
624 |
| - } |
| 579 | + if((this.options.type == "search" && "query" in this.params && this.params["query"].trim().length > 0) || |
| 580 | + (this.options.type == "browse" && "categoryId" in this.params && this.params["categoryId"].trim().length > 0)) |
| 581 | + this.callResults(this.paintResultSet); |
625 | 582 | }
|
626 | 583 | ,getClass : function(object){
|
627 | 584 | return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
|
@@ -680,63 +637,57 @@ var unbxdSearchInit = function(jQuery, Handlebars){
|
680 | 637 | if(this.options.type == "search"){
|
681 | 638 | if("form" in this.input && this.input.form){
|
682 | 639 | jQuery(this.input.form).bind("submit",function(e){
|
683 |
| - e.preventDefault(); |
| 640 | + e.preventDefault(); |
684 | 641 |
|
685 |
| - self.reset(); |
| 642 | + self.reset(); |
686 | 643 |
|
687 |
| - self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
| 644 | + self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
688 | 645 |
|
689 | 646 | if(self.options.deferInitRender.indexOf('search') === -1)
|
690 | 647 | jQuery(self.options.searchResultContainer).html('');
|
691 | 648 |
|
692 |
| - if(typeof self.options.setDefaultFilters == "function") |
693 |
| - self.setDefaultParams(self.params); |
694 |
| - |
695 |
| - self.setPage(1) |
696 |
| - .setPageSize(self.options.pageSize) |
| 649 | + self.setPage(1) |
| 650 | + .setPageSize(self.options.pageSize) |
697 | 651 |
|
698 |
| - if(self.params.query) |
699 |
| - self.callResults(self.paintResultSet,true); |
| 652 | + if(self.params.query) |
| 653 | + self.callResults(self.paintResultSet,true); |
700 | 654 | });
|
701 | 655 | }else{
|
702 | 656 | this.$input.bind('keydown',function(e){
|
703 | 657 | if(e.which == 13){
|
704 |
| - e.preventDefault(); |
| 658 | + e.preventDefault(); |
705 | 659 |
|
706 |
| - self.reset(); |
| 660 | + self.reset(); |
707 | 661 |
|
708 |
| - self.params.query = self.options.sanitizeQueryString.call(self, this.value ); |
| 662 | + self.params.query = self.options.sanitizeQueryString.call(self, this.value ); |
709 | 663 |
|
710 | 664 | if(self.options.deferInitRender.indexOf('search') === -1)
|
711 | 665 | jQuery(self.options.searchResultContainer).html('');
|
712 | 666 |
|
713 |
| - if(typeof self.options.setDefaultFilters == "function") |
714 |
| - self.setDefaultParams(self.params); |
715 |
| - |
716 |
| - self.clearFilters(true).setPage(1) |
717 |
| - .setPageSize(self.options.pageSize) |
| 667 | + self.clearFilters(true).setPage(1) |
| 668 | + .setPageSize(self.options.pageSize) |
718 | 669 |
|
719 |
| - if(self.params.query) |
720 |
| - self.callResults(self.paintResultSet,true); |
| 670 | + if(self.params.query) |
| 671 | + self.callResults(self.paintResultSet,true); |
721 | 672 | }
|
722 | 673 | });
|
723 | 674 |
|
724 | 675 | if(this.options.searchButtonSelector.length){
|
725 | 676 | jQuery(this.options.searchButtonSelector).bind("click",function(e){
|
726 |
| - e.preventDefault(); |
| 677 | + e.preventDefault(); |
727 | 678 |
|
728 |
| - self.reset(); |
| 679 | + self.reset(); |
729 | 680 |
|
730 |
| - self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
| 681 | + self.params.query = self.options.sanitizeQueryString.call(self, self.input.value); |
731 | 682 |
|
732 | 683 | if(self.options.deferInitRender.indexOf('search') === -1)
|
733 | 684 | jQuery(self.options.searchResultContainer).html('');
|
734 | 685 |
|
735 |
| - self.clearFilters(true).setPage(1) |
736 |
| - .setPageSize(self.options.pageSize) |
| 686 | + self.clearFilters(true).setPage(1) |
| 687 | + .setPageSize(self.options.pageSize) |
737 | 688 |
|
738 |
| - if(self.params.query) |
739 |
| - self.callResults(self.paintResultSet,true); |
| 689 | + if(self.params.query) |
| 690 | + self.callResults(self.paintResultSet,true); |
740 | 691 | });
|
741 | 692 | }
|
742 | 693 | }
|
@@ -1058,7 +1009,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
|
1058 | 1009 | var nonhistoryPath = "";
|
1059 | 1010 |
|
1060 | 1011 | if(this.options.type == "search" && this.params['query'] != undefined){
|
1061 |
| - url += '&'+ this.options.searchQueryParam +'='+ encodeURIComponent(this.params.query); |
| 1012 | + url += '&'+ this.options.searchQueryParam +'='+ encodeURIComponent(this.params.query); |
1062 | 1013 | }else if(this.options.type == "browse" && this.params['categoryId'] != undefined){
|
1063 | 1014 | url += '&category-id=' + encodeURIComponent(this.params.categoryId);
|
1064 | 1015 | }
|
@@ -1218,36 +1169,42 @@ var unbxdSearchInit = function(jQuery, Handlebars){
|
1218 | 1169 |
|
1219 | 1170 | jQuery(this.options.facetContainerSelector).empty();
|
1220 | 1171 |
|
1221 |
| - this.options.selectedFacetHolderSelector && jQuery(this.options.selectedFacetHolderSelector).hide(); |
| 1172 | + this.options.selectedFacetHolderSelector && jQuery(this.options.selectedFacetHolderSelector).hide(); |
1222 | 1173 |
|
1223 |
| - this.options.loaderSelector.length > 0 && jQuery(this.options.loaderSelector).hide(); |
| 1174 | + this.options.loaderSelector.length > 0 && jQuery(this.options.loaderSelector).hide(); |
1224 | 1175 |
|
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 |
| - }; |
| 1176 | + this.params = { |
| 1177 | + query : '*' |
| 1178 | + ,filters : {} |
| 1179 | + ,sort : {} |
| 1180 | + ,ranges : {} |
| 1181 | + ,categoryId : "" |
| 1182 | + ,extra : { |
| 1183 | + format: "json" |
| 1184 | + ,page: 1 |
| 1185 | + ,rows: 12 |
| 1186 | + } |
| 1187 | + }; |
1237 | 1188 |
|
1238 | 1189 | if( this.options.viewTypes && this.options.viewTypes.length > 0)
|
1239 | 1190 | this.params.extra.view = this.options.viewTypes[0];
|
1240 | 1191 |
|
1241 | 1192 | if(typeof this.options.customReset == "function")
|
1242 | 1193 | this.options.customReset.call(this);
|
1243 | 1194 |
|
| 1195 | + if(typeof this.options.setDefaultFilters == "function") |
| 1196 | + this.setDefaultParams(this.params); |
| 1197 | + |
1244 | 1198 | return this;
|
1245 | 1199 | }
|
1246 | 1200 | ,setDefaultParams: function(params){
|
| 1201 | + var newparams, diff; |
| 1202 | + var oldparams = JSON.stringify(params); |
1247 | 1203 | this.options.setDefaultFilters.call(this);
|
1248 |
| - |
| 1204 | + newparams = JSON.stringify(this.params); |
| 1205 | + |
1249 | 1206 | if(Object.keys(this.defaultParams).length === 0)
|
1250 |
| - this.defaultParams = jQuery.extend(true, {}, this.params); |
| 1207 | + this.defaultParams = JSON.parse(newparams); |
1251 | 1208 | }
|
1252 | 1209 | ,_processURL: function(url){
|
1253 | 1210 | var obj = typeof url == "string" ? this.getQueryParams(url) : url
|
|
0 commit comments