1var VM; 2 3Date.prototype.getFormatDate = function () { 4 var monthNames = ["January", "February", "March", "April", "May", "June", 5 "July", "August", "September", "October", "November", "December" 6 ]; 7 return monthNames[this.getMonth()] + ' ' + this.getDate() + ', ' + this.getFullYear(); 8} 9 10$(function () { 11 12 13 var CustomSearchVM = function () { 14 var self = this; 15 16 self.Topic = ko.observable(); 17 self.Department = ko.observable(); 18 self.showPreloader = ko.observable(false); 19 self.searchResult = ko.observableArray([]); 20 self.pageSize = ko.observable(50); 21 self.page = ko.observable(1); 22 self.rowStart = 1; 23 self.totalItems = ko.observable(); 24 self.totalpages = ko.computed(function () { 25 return Math.ceil(parseInt(self.totalItems()) / self.pageSize()); 26 }); 27 28 self.setPage = function () { 29 self.page(self.page() + 1); 30 $('#savedpage').val(self.page()); 31 self.getCustomSearch(); 32 }; 33 34 self.getCustomSearch = function (innerbutton) { 35 self.showPreloader(true); 36 37 var uri = "/Data/Items/", 38 data = location.pathname.substr(location.pathname.lastIndexOf("/") + 1), 39 section = $('#section').val(); 40 41 $.getJSON(uri, { id: data, section: section, pageSize: self.pageSize(), page: self.page(), rowStart: self.rowStart }, function (data) { 42 if (data) { 43 self.totalItems(data.totalItems); 44 45 if (data.Items) { 46 self.setData(data.Items); 47 48 } 49 self.showPreloader(false); 50 51 } 52 }); 53 }; 54 self.setData = function (data) { 55 for (var i = 0; i < data.length; i++) { 56 var item = data[i]; 57 // in production code, item.htmlTitle should have the HTML entities escaped. 58 var iDate = new Date(item.Date).getFormatDate(); 59 self.searchResult.push(new model(item.Title, item.Link, item.Thumbnail, item.SubTitle, iDate, item.Author, item.ContentTypeID, item.Content)); 60 } 61 } 62 self.init = function () { 63 var pageLoaded = parseInt($('#savedpage').val()); 64 if (pageLoaded > 1) { 65 self.page(1); 66 self.rowStart = 11; 67 self.pageSize((pageLoaded - 1) * self.pageSize()); 68 self.getCustomSearch(); 69 self.page(self.page() + pageLoaded - 1); 70 self.pageSize(10); 71 self.rowStart = 1; 72 } 73 } 74 } 75 76 VM = new CustomSearchVM(); 77 ko.applyBindings(VM); 78 VM.init(); 79}); 80 81function model(title, link, image, snippet, date, author, contenttypeid, content) { 82 this.title = _.unescape(title); 83 this.contenttypeid = contenttypeid; 84 this.link = ko.computed(function () { 85 var url = ""; 86 if (!this.contenttypeid) 87 url = link; 88 else { 89 if (this.contenttypeid == 1 || this.contenttypeid == 2 || this.contenttypeid == 3) 90 url = "/news/article/" + link; 91 else if (this.contenttypeid == 8) 92 url = "/ce/" + link; 93 else 94 url = _.unescape(content); 95 } 96 97 return url; 98 }, this); 99 this.image = image; 100 this.snippet = _.unescape(snippet); 101 this.date = date; 102 this.author = author; 103 this.hasImage = ko.computed(function () { 104 return image || null; 105 }, this); 106 this.hasAuthor = ko.computed(function () { 107 return author || null; 108 }, this); 109 this.hasDate = ko.computed(function () { 110 return date != null; 111 }, this); 112 this.hasMeta = ko.computed(function () { 113 return this.hasDate() || this.hasAuthor(); 114 }, this); 115}
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.