1;(function ($) { 2 var publicMethods = {}, 3 pluginName = "citySelector"; 4 5 function CitySelector(element, options) { 6 var self = this; 7 8 this.$scope = $(element); 9 this.$countries = $("button[type='button']"); 10 this.$resultContainer = this.$scope.find(".choose-city"); 11 this.$input = $("#city-query"); 12 13 this.updateTimer = null; 14 this.options = $.extend({}, $.fn.citySelector.defaults, options); 15 this.lastQuery = null; 16 17 this.$scope.on("click", "span.found", function (e) { 18 var $a = $(e.target).parent("a"); 19 20 if ($a.length) { 21 window.location = $a.attr("href"); 22 } 23 }); 24 25 this.$scope.on("click", "button[type='button']", function (e) { 26 self.$countries.removeClass("active"); 27 $(this).addClass("active"); 28 29 self.$resultContainer.html(""); 30 31 // $("#loading-icon") 32 // .clone() 33 // .appendTo(self.$resultContainer) 34 // .show(); 35 36 $.ajax(Routing.generate('ajax_geolocation_set_country_cookie'), { 37 type: "get", 38 data: { 39 name: $(this).attr("data-country") 40 } 41 }).fail(function () { 42 throw new Error("Unable to set a country"); 43 }).success(function (json) { 44 var index, $block = self.$scope.find("p.popular>span.i-links"); 45 46 $block.html(""); 47 window.location.reload(); 48 49 // if ("undefined" != typeof json.cities) { 50 // for (index = 0; index < json.cities.length; index++) { 51 // $("<a>") 52 // .attr("href", json.cities[index].url) 53 // .text(json.cities[index].title + (index != json.cities.length - 1 ? ", " : "")) 54 // .appendTo($block) 55 // ; 56 // } 57 // } 58 59 // self.search(); 60 }); 61 }); 62 63 if (typeof window.country != "undefined") { 64 $("button[type='button']:contains('" + window.country + "')").addClass("active"); 65 } 66 67 // this.$input.on("keyup", function () { 68 // if (self.updateTimer !== null) { 69 // clearTimeout(self.updateTimer); 70 // } 71 // 72 // self.updateTimer = setTimeout(function () { 73 // self.search(); 74 // }, 500); 75 // }); 76 77 // this.search(); 78 } 79 80 CitySelector.prototype.search = function () { 81 var self = this; 82 83 this.lastQuery = this.$input.val(); 84 85 $.ajax(Routing.generate('ajax_geolocation_get_country_cities'), { 86 type: "get", 87 data: { 88 q: this.lastQuery 89 } 90 }) 91 .fail(function () { 92 throw new Error("Unable to search against cities"); 93 }) 94 .done(function (html) { 95 self.update(html); 96 }); 97 }; 98 99 CitySelector.prototype.update = function (html) { 100 this.$resultContainer.html(html); 101 }; 102 103 $.fn.citySelector = function (options, args) { 104 var instance, method = typeof options == "string" ? options : null; 105 106 return this.each(function () { 107 instance = $.data(this, "plugin_" + pluginName); 108 109 if (!instance) { 110 instance = new CitySelector(this, options); 111 $.data(this, "plugin_" + pluginName, instance); 112 } 113 114 if (typeof publicMethods[method] !== "undefined") { 115 publicMethods[method].apply(instance, $.isArray(args) ? args : [args]); 116 } 117 }); 118 }; 119 120 $.fn.citySelector.defaults = {}; 121}(jQuery));
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.