1window.click_ready = true; 2ko.observableArray.fn.withIndex = function (keyName, useName) { 3 /// keyName == the name of the property used as the index 4 /// value. 5 /// useName == when false, a function named findByKey 6 /// is added to the observableArray. 7 /// when true, the function is named based 8 /// on the name of the index property & 9 /// capitalized (like id becomes findById) 10 var index = ko.computed(function () { 11 var list = this() || []; // the internal array 12 var keys = {}; // a place for key/value 13 ko.utils.arrayForEach(list, function (v) { 14 if (keyName) { // if there is a key 15 keys[v[keyName]] = v; // use it 16 } else { 17 keys[v] = v; 18 } 19 }); 20 return keys; 21 }, this); 22 23 var fnName = ""; 24 if (useName && keyName) { 25 var cap = keyName.substr(0, 1).toUpperCase(); 26 if (keyName.length > 1) { 27 fnName = cap + keyName.substring(1); 28 } else { 29 fnName = cap; 30 } 31 } else { 32 fnName = "Key"; 33 } 34 35 var fnName = "findBy" + fnName; 36 this[fnName] = function (key) { 37 return index()[key]; 38 }; 39 40 return this; 41}; 42 43 44 45 46 47 48function Result(data) { 49 var self = this; 50 51 this.tld = ko.observable("."+data.tld); 52 this.domain = ko.observable(data.domain); 53 this.domain_base = ko.observable(data.domain_base); 54 this.base = ko.observable(data.base); 55 this.fees = ko.observable(data.extra_fees); 56 this.avail = ko.observable(data.result); 57 this.in_cart = ko.observable(false); 58 controller.status('results'); 59 60 61 this.price = ko.computed(function(){ 62 if(self.in_cart() == true) return 'Added'; 63 return "$"+(parseFloat(self.base()) + parseFloat(self.fees())).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ","); 64 }); 65 66 this.status = ko.computed(function(){ 67 if(self.in_cart() === true) return "Added"; 68 else if(self.avail() == 1) return "Add"; 69 else if(self.avail() == 0) return "Taken"; 70 else return "Error"; 71 }); 72 73 $(".cart").show(); 74 75 this.process_action = function(){ 76 77 console.log("in process action"); 78 79 if(self.in_cart() !== true){ 80 $.post('/search/add_to_cart/'+self.domain(), function(data, elem){ 81 if(data.payload.success){ 82 self.in_cart(true); 83 console.log(self.tld()); 84 } 85 }, 'json').done(function(data){ 86 cart.refresh(); 87 }); 88 89 } else { 90 91 $.post('/search/remove_from_cart/'+self.domain(), function(data, elem){ 92 if(data.payload.success){ 93 self.in_cart(false); 94 console.log(self.tld()); 95 } 96 }, 'json').done(function(data){ 97 cart.refresh(); 98 }); 99 100 } 101 console.log("firing cart refresh from process action"); 102 103 //return true; 104 } 105} 106 107 108 109 110 111 112function TLD(tld){ 113 self = this; 114 115 this.selected = ko.observable(false); 116 this.tld = ko.observable(tld); 117 118 this.toggle = function(tld){ 119 if( typeof tld == 'undefined' ) tld = self; 120 121 if(tld.selected() == true){ 122 tld.selected(false); 123 } else { 124 tld.selected(true); 125 } 126 } 127} 128 129 130 131 132 133 134 135 136 137function Category(category){ 138 var self = this; 139 this.category = ko.observable(category); 140 this.tlds = ko.observableArray([]); 141 142 this.set_selected = function(){ 143 controller.set_selected(self); 144 } 145 146} 147 148 149 150function SearchViewModel() { 151 var self = this; 152 this.domain_bases = ko.observable(); 153 this.results = ko.observableArray([]); 154 this.not_avail = ko.observableArray([]); 155 this.status = ko.observable('waiting'); 156 //this.cart_domains = ko.observableArray([]); 157 this.prices = ko.observableArray([]).withIndex('tld', true); 158 this.categories = ko.observableArray([]); 159 this.tlds = ko.observableArray([]).withIndex('tld', true);; 160 this.selected_cat = ko.observable(new Category('')); 161 this.tlds_selected = ko.observableArray([]); 162 163 164 this.prompt = ko.computed(function(){ 165 if(self.results().length > 0){ 166 return "Checkout Now"; 167 } else { 168 return "Search Domains"; 169 } 170 }); 171 172 this.clear = function(){ 173 $(".tlds").show(); 174 $(".arrow_container").show(); 175 $("#tldCategories").show(); 176 $(".search_domains").show(); 177 self.not_avail.removeAll(); 178 179 self.results([]); 180 181 ko.utils.arrayForEach(self.tlds(), function (tlditem) { 182 tlditem.data.selected(false); 183 }); 184 185 self.tlds_selected([]); 186 187 188 self.set_selected(self.categories()[0]); 189 self.status('ready'); 190 } 191 192 this.set_selected = function(cat){ 193 self.selected_cat(cat); 194 self.status('searching'); 195 } 196 197 this.show_results = function(){ 198 self.status('results'); 199 self.selected_cat(new Category('')); 200 } 201 202 203 204 205 206this.all_results_checked = function(){ 207 208 var results = self.results(); 209 var d = []; 210 var r = []; 211 ko.utils.arrayForEach(results, function (res) { 212 213 if(res.in_cart() == false ){ 214 console.log(res.domain()); 215 d.push(res.domain()); 216 res.in_cart(true); 217 }else{ 218 r.push(res.domain()); 219 res.in_cart(false); 220 } 221 222 }); 223 224 if(d.length){ 225 $.post('/search/bulk_add/',{'domains': d}, function(data, elem){ 226 227 if(data.payload.success){ 228 console.log("bulk add success"); 229 } 230 }, 'json').done(function(data){ 231 cart.refresh(); 232 }); 233 } 234 235 if(r.length){ 236 $.post('/search/bulk_remove/',{'domains': r}, function(data, elem){ 237 238 if(data.payload.success){ 239 console.log("bulk add success"); 240 } 241 }, 'json').done(function(data){ 242 cart.refresh(); 243 }); 244 } 245 246 247} 248 249 250 this.add_result = function(data){ 251 if(data.result == 1){ 252 253 var parts = data.domain.split("."); 254 var domain_base = parts.shift(); 255 256 data.tld = parts.join(".").toLowerCase(); 257 self.results.push(new Result(data)); 258 259 } 260 261 if(data.result == 0){ 262 var parts = data.domain.split("."); 263 var domain_base = parts.shift(); 264 265 data.tld = parts.join(".").toLowerCase(); 266 self.not_avail.push(new Result(data)); 267 268 } 269 270 271 } 272 273 this.init = function(){ 274 self.load_categories(); 275 self.load_prices(); 276 277 //self.cart_domains(JSON.parse(window.cart_domains)); 278 } 279 280 this.load_categories = function(){ 281 var c = JSON.parse(window.categories); 282 for(var cat in c){ 283 var ct = new Category(cat); 284 for(tld in c[cat]){ 285 var t = self.tlds.findByTld(c[cat][tld]); 286 if(t == undefined || typeof t == 'function'){ 287 var t = {}; 288 t.tld = c[cat][tld]; 289 t.data = new TLD(c[cat][tld]); 290 self.tlds.push(t); 291 } 292 293 ct.tlds.push(t.data); 294 } 295 296 self.categories.push(ct); 297 } 298 299 self.selected_cat(self.categories()[0]); 300 self.status('ready'); 301 } 302 303 304 305 this.checkedCBs = ko.computed(function() { 306 307 return ko.utils.arrayFilter(self.tlds(), function(tld) { 308 309 if(tld.data.selected()==true && $.inArray(tld.tld, controller.tlds_selected()) === -1 ){ 310 311 312 var tld_name = tld.tld; 313 314 controller.tlds_selected.push(tld_name); 315 316 } 317 318 return controller.tlds_selected; 319 }); 320 }); 321 322 323 this.load_prices = function(){ 324 var p = JSON.parse(window.prices); 325 326 for(t in p){ 327 self.prices.push({tld: t, price: p[t]}); 328 } 329 } 330 331 332 333 334 335} 336 337controller = new SearchViewModel(); 338controller.init(); 339ko.applyBindings(controller); 340 341function http_push_add_result(data, id, channel){ 342 //console.log(data.payload.data); 343 controller.add_result(data.payload.data, true); 344}
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.