├── test.html └── CustomWidget.js /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 17 | 18 | -------------------------------------------------------------------------------- /CustomWidget.js: -------------------------------------------------------------------------------- 1 | var lstCities; 2 | var lstStyle; 3 | var itemStyle; 4 | class CustomWidget { 5 | constructor( insertDiv, textStyle, listStyle, citiesList, itmStyle) { 6 | this.textStyle = textStyle; 7 | lstStyle = listStyle; 8 | lstCities = citiesList; 9 | itemStyle = itmStyle; 10 | this.insertDiv = insertDiv; 11 | this.strElem = ''; 12 | document.getElementById( insertDiv).innerHTML = this.strElem; 13 | $("#AnswerInput").keyup(function(event){ 14 | $("p").remove(".city"); 15 | $("div").remove(".city"); 16 | var cityName = $("#AnswerInput").prop("value"); 17 | if(cityName == "") return; 18 | for( var i = 0; i < lstCities.length; i++){ 19 | var strCityName = lstCities[i].full; 20 | strCityName = strCityName.toUpperCase(); 21 | if( strCityName.indexOf(cityName.toUpperCase()) != -1 ){ 22 | $("#lstCity").append(''+ strCityName + '
'); 23 | } 24 | } 25 | $(".city").unbind("click").click(function(){ 26 | cityNameClicked($(this).html()); 27 | }); 28 | }); 29 | } 30 | } 31 | 32 | function cityNameClicked(__city_name){ 33 | var result = lstCities.filter(function(x){ return x.full.toUpperCase() == __city_name.toUpperCase();}); 34 | // var result = $.grep(lstCities, function(e){ return e.full == __city_name; }); 35 | // console.log(result); 36 | var a = result[0]; 37 | $("p").remove(".city"); 38 | for(var b='