1XA.component.search.sort = (function ($, document) { 2 3 var api = {}, 4 initialized = false, 5 queryModel, 6 queryParameters, 7 getSignature; 8 9 var SortModel = Backbone.Model.extend({ 10 defaults: { 11 updateOrder: false, 12 sig: [] 13 } 14 }); 15 16 var SortView = XA.component.search.baseView.extend({ 17 initialize : function () { 18 var dataProperties = this.$el.data(); 19 20 if (this.model) { 21 this.model.set("sig", this.translateSignatures(dataProperties.properties.sig, "o")); 22 } 23 24 XA.component.search.vent.on("hashChanged", this.updateComponent.bind(this)); 25 }, 26 events : { 27 'click .sort-results-group a': 'sortSearchResultsLink', 28 'change select': 'sortSearchResultsSelect' 29 }, 30 sortSearchResultsLink: function (event) { 31 event.preventDefault(); 32 this.sortSearchResults($(event.currentTarget).parent()); 33 }, 34 sortSearchResultsSelect: function (event) { 35 this.sortSearchResults($(event.currentTarget[event.currentTarget.options.selectedIndex])); 36 }, 37 sortSearchResults: function (element) { 38 var attributes = element.data(), 39 sig = this.model.get("sig"), 40 attrString = attributes.facet + ',' + attributes.direction; 41 42 if (attributes.direction !== "") { 43 queryParameters.updateHash(this.updateSignaturesHash(sig, attrString, {})); 44 } else { 45 queryParameters.updateHash(this.updateSignaturesHash(sig, "", {})); 46 } 47 }, 48 updateComponent: function (hash) { 49 var optionToSelect, sortData, 50 sig = this.model.get("sig"), 51 i; 52 53 for (i = 0; i < sig.length; i++) { 54 if (hash.hasOwnProperty(sig[i])){ 55 sortData = hash[sig[i]].split(','); 56 optionToSelect = this.$el.find("[data-facet='" + sortData[0] + "'][data-direction='" + sortData[1] + "']"); 57 } else { 58 optionToSelect = this.$el.find("[data-facet][data-direction]:first"); 59 } 60 } 61 62 this.$el.find("[data-facet][data-direction]").removeAttr("selected"); 63 optionToSelect.attr("selected", "selected"); 64 } 65 }); 66 67 api.init = function () { 68 if ($("body").hasClass("on-page-editor") || initialized){ 69 return; 70 } 71 72 queryModel = XA.component.search.query; 73 queryParameters = XA.component.search.parameters; 74 75 var sort = $(".sort-results"); 76 _.each(sort, function (elem) { 77 var sortModel = new SortModel(), 78 view = new SortView({el: $(elem), model: sortModel}); 79 }); 80 81 initialzied = true; 82 }; 83 84 api.getFirstSortingOption = function(signature) { 85 var sortResults = $(".sort-results"), 86 firstSort, 87 attributes, 88 attrString, 89 thisSignatures, 90 data, 91 i, j; 92 93 for (i = 0; i < sortResults.length; i++) { 94 if (typeof(signature) !== "undefined") { 95 data = $(sortResults[i]).data(); 96 thisSignatures = data.properties.sig.split(','); 97 98 for (j = 0; j < thisSignatures.length; j++) { 99 if (thisSignatures[j] === signature) { 100 firstSort = $(sortResults[i]).find("[data-facet][data-direction]"); 101 attributes = firstSort.data(); 102 if (attributes.direction !== "") { 103 attrString = attributes.facet + ',' + attributes.direction; 104 return attrString; 105 } 106 } 107 } 108 } 109 } 110 111 return -1; 112 }; 113 114 return api; 115 116}(jQuery, document)); 117 118XA.register('searchSort', XA.component.search.sort);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.