function replaceAll(str,find,replace){ return str.replace(new RegExp(find,'g'),replace); }
Например, удалить проблемы во всех input в форме:
$("form input[type=text]").each(function(){ $(this).val(replaceAll($(this).val(),' ','')); });
Метка
Всего: 139 записей
function replaceAll(str,find,replace){ return str.replace(new RegExp(find,'g'),replace); }
Например, удалить проблемы во всех input в форме:
$("form input[type=text]").each(function(){ $(this).val(replaceAll($(this).val(),' ','')); });
JS:
$(".input_place").autocomplete({ source:"/?ajax_action=get_places", minLength:4, position:{my:"left top",at:"left bottom"}, select:function(event,ui){ var loc=$(this).closest('form').attr('action'); if(ui.item.country_id){ loc+='?country[]='+ui.item.country_id; $('#hidden_country').val(ui.item.country_id); } if(ui.item.district_id){ loc+='&district[]='+ui.item.district_id; $('#hidden_district').val(ui.item.district_id); } if(ui.item.city_id){ loc+='&city[]='+ui.item.city_id; $('#hidden_city').val(ui.item.city_id); } var selected=ui.item.country_name; if(ui.item.district_name!=''){ selected=ui.item.district_name; } if(ui.item.city_name!=''){ selected=ui.item.city_name; } $(this).val(selected); if($('#hidden_country').val()==undefined){ window.location.href=loc; } return false; } }).autocomplete("instance")._renderItem=function(ul,item){ var li=item.country_name; if(item.district_name!=''){ li+=' '+item.district_name; } if(item.city_name!=''){ li+=' '+item.city_name; } return $("<li>").append(li).appendTo(ul); };
if($_GET['ajax_action']=='get_places'){ $places=array(); $ajax_countries=get_from_base('*','countries',"shown=1 and (`name` LIKE '%".$_GET['term']."%' OR `id` IN (SELECT `parent` FROM `districts` WHERE`shown`=1 and (`name` LIKE '%".$_GET['term']."%' OR `id` IN (SELECT `parent` FROM `cities` WHERE`shown`=1 and `name` LIKE '%".$_GET['term']."%'))))",'pos'); if(count($ajax_countries)>0){ foreach($ajax_countries as $country){ $places[]=array('country_id'=>$country['id'],'country_name'=>$country['name'],'district_id'=>0,'district_name'=>'','city_id'=>0,'city_name'=>''); $ajax_districts=get_from_base('*','districts',"`parent`=".$country['id']." and `shown`=1 and (`name` LIKE '%".$_GET['term']."%' OR `id` IN (SELECT `parent` FROM `cities` WHERE`shown`=1 and `name` LIKE '%".$_GET['term']."%'))",'pos'); if(count($ajax_districts)>0){ foreach($ajax_districts as $district){ $places[]=array('country_id'=>$country['id'],'country_name'=>$country['name'],'district_id'=>$district['id'],'district_name'=>$district['name'],'city_id'=>0,'city_name'=>''); $ajax_cities=get_from_base('*','cities',"`parent`=".$district['id']." and `shown`=1 and `name` LIKE '%".$_GET['term']."%'",'pos'); if(count($ajax_cities)>0){ foreach($ajax_cities as $city){ $places[]=array('country_id'=>$country['id'],'country_name'=>$country['name'],'district_id'=>$district['id'],'district_name'=>$district['name'],'city_id'=>$city['id'],'city_name'=>$city['name']); } } } } } } header('Content-Type: application/json'); echo json_encode($places); exit(); }
https://jqueryui.com/autocomplete/#custom-data
Файлы для загрузки:
https://leafletjs.com/download.html https://github.com/Leaflet/Leaflet.markercluster
Подключение:
<script src="/assets/js/leaflet/leaflet.js"></script> <script src="/assets/js/leaflet/leaflet.markercluster.js"></script> <link href="/assets/js/leaflet/leaflet.css" rel="stylesheet" type="text/css"/> <link href="/assets/js/leaflet/MarkerCluster.css" rel="stylesheet" type="text/css"/> <link href="/assets/js/leaflet/MarkerCluster.Default.css" rel="stylesheet" type="text/css"/>
JS:
var map=L.map('map_search_leaflet').setView([59.939095,30.315868],2); L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}',{ attribution:'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>', minZoom:2, maxZoom:18, id:'mapbox.streets', accessToken:'--token--' }).addTo(map); map.scrollWheelZoom.disable(); map.setMaxBounds([ [90,-180], [-90,180] ]); var markers=L.markerClusterGroup({ maxClusterRadius:20 }); markers.addLayer(L.marker([60.171801, 24.956500]).bindPopup('<div class="popup_header"><a href="http://example.com/nedvizhimost/kupit/kafe-v-helsinki-art1.html">Кафе в Хельсинки</a></div><div class="popup_body"><div class="art">ID: art1</div><div class="price">248 000 €</div><div class="photo"><a href="http://example.com/nedvizhimost/kupit/kafe-v-helsinki-art1.html"><img src="http://example.com/resize/catalog/crop/270/210/c11.jpg" alt="Кафе в Хельсинки"/></a></div></div><div class="popup_footer"><div class="f_3">49 м2</div></div>')); markers.addLayer(L.marker([60.166892, 24.943673]).bindPopup('<div class="popup_header"><a href="http://example.com/nedvizhimost/kupit/restoran-v-helsinki-art2.html">Ресторан в Хельсинки</a></div><div class="popup_body"><div class="art">ID: art2</div><div class="price">350 000 €</div><div class="photo"><a href="http://example.com/nedvizhimost/kupit/restoran-v-helsinki-art2.html"><img src="http://example.com/resize/catalog/crop/270/210/c18.jpg" alt="Ресторан в Хельсинки"/></a></div></div><div class="popup_footer"><div class="f_3">130 м2</div></div>')); markers.addLayer(L.marker([60.166892, 24.943673]).bindPopup('<div class="popup_header"><a href="http://example.com/nedvizhimost/kupit/pomeshchenie-v-helsinki-art3.html">Помещение в Хельсинки</a></div><div class="popup_body"><div class="art">ID: art3</div><div class="price">198 000 €</div><div class="photo"><a href="http://example.com/nedvizhimost/kupit/pomeshchenie-v-helsinki-art3.html"><img src="http://example.com/resize/catalog/crop/270/210/c22.jpg" alt="Помещение в Хельсинки"/></a></div></div><div class="popup_footer"><div class="f_3">54 м2</div></div>')); map.addLayer(markers);
HTML:
<div id="map_search_leaflet"></div>CSS:
#map_search_leaflet{ height:570px; margin-bottom:20px; }
Модальное окно будет показано при наведении курсора на верхнюю часть документа. Высота в примере 20px. Модальное окно в примере открывается с использованием fancybox.
$(document).ready(function(){ var close_confirm=0; $(document).mousemove(function(e){ if(e.pageY<=20&&!close_confirm){ $("#close_confirm").fancybox().trigger('click'); close_confirm++; } }); });
<a href="/link.html" class="popup fancybox.ajax" id="close_confirm"></a>$(window).scroll(function(){ if($(window).scrollTop()>130){ $('header .top').addClass('fixed'); } else{ $('header .top').removeClass('fixed'); } });
header{ .top{ color:@color_white; background:@color_text; padding:10px 0; &.fixed{ position:fixed; top:0; left:0; width:100%; z-index:10000; } } }
Подключение плагинов:
https://github.com/jackocnr/intl-tel-input (https://intl-tel-input.com/)
https://github.com/digitalBush/jquery.maskedinput
Подключение js:
<script src="/assets/js/jquery.maskedinput.min.js"></script> <script src="/assets/js/intl-tel-input/js/intlTelInput-jquery.min.js"></script>
Подключение css:
@import '../js/intl-tel-input/css/intlTelInput.min.css';
JS:
function phone_mask(){ $.mask.definitions['9']=''; $.mask.definitions['d']='[0-9]'; $("input[name=phone],input.phone").mask("+7 ddd ddd-dd-dd"); $("input[name=phone],input.phone").intlTelInput({ autoHideDialCode:false, autoPlaceholder:"aggressive", placeholderNumberType:"MOBILE", preferredCountries:['ru','th'], separateDialCode:true, utilsScript:"/assets/js/intl-tel-input/js/utils.js", customPlaceholder:function(selectedCountryPlaceholder,selectedCountryData){ return '+'+selectedCountryData.dialCode+' '+selectedCountryPlaceholder.replace(/[0-9]/g,'_'); }, //allowDropdown:false, //dropdownContainer:document.body, //excludeCountries:["us"], //formatOnDisplay:false, //geoIpLookup:function(callback){ // $.get("http://ipinfo.io",function(){},"jsonp").always(function(resp){ // var countryCode =(resp&&resp.country)?resp.country:""; // callback(countryCode); // }); //}, //hiddenInput:"full_number", //initialCountry:"auto", //localizedCountries:{'de':'Deutschland'}, //nationalMode:false, //onlyCountries:['us','gb','ch','ca','do'], }); $("input[name=phone],input.phone").on("close:countrydropdown",function(e,countryData){ $(this).val(''); //var mask=$(this).closest('.intl-tel-input').find('.selected-dial-code').html()+' '+$(this).attr('placeholder').replace(/[0-9]/g,'d'); $(this).mask($(this).attr('placeholder').replace(/[_]/g,'d')); }); } $(document).ready(function(){ //example with fancybox $('.popup').fancybox({ helpers:{title:null}, padding:'0', width:'800', beforeShow:function(){ phone_mask(); } }); //init phone_mask(); });
Javascript:
ymaps.ready(init); function init(){ var groups=[ { name:"Группа 1", style:"islands#blueCircleIcon", items:[ {name:"Санкт-Петербург, Московский пр-т, д. 44"}, {name:"Санкт-Петербург, ул. Байконурская, д. 14А, ТРК «Континент»"}, ] }, { name:"Группа 2", style:"islands#greenCircleIcon", items:[ {name:"Санкт-Петербург, Лиговский пр-т, д. 30А, ТРЦ «Галерея»"}, {name:"Санкт-Петербург, Петергофское ш., д. 51, ТРЦ «Жемчужная Плаза»"}, ] }, ]; var myMap=new ymaps.Map('map',{ center:[59.939095,30.315868], zoom:10 },{ searchControlProvider:'yandex#search' }), menu=$('<div class="menu"></div>'); for(var i=0,l=groups.length;i<l;i++){ createMenuGroup(groups[i]); } function createMenuGroup(group){ var menuItem=$('<div class="group"><p>'+group.name+'</p></div>'), collection=new ymaps.GeoObjectCollection(null,{preset:group.style}), submenu=$('<ul></ul>'); myMap.geoObjects.add(collection); menuItem.append(submenu).appendTo(menu); for(var j=0,m=group.items.length;j<m;j++){ createSubMenu(group.items[j],collection,submenu); } } function createSubMenu(item,collection,submenu){ var submenuItem=$('<li><a href="#">'+item.name+'</a></li>'); ymaps.geocode(item.name,{results:1}).then(function(res){ var coords=res.geoObjects.get(0).geometry.getCoordinates(); var placemark=new ymaps.Placemark(coords,{balloonContent:item.name}); collection.add(placemark); submenuItem.appendTo(submenu).find('a').bind('click',function(){ if(!placemark.balloon.isOpen()){ placemark.balloon.open(); } else{ placemark.balloon.close(); } return false; }); }); } menu.insertAfter($('#map')); }
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU"></script> <script> //js here </script> <div id="map" style="height:400px;"></div>