var map; function mapInit() { var canvas = document.getElementById('map-canvas'); var coords = canvas.getAttribute('data-coords'); var commaPos = coords.indexOf(','); var lat = parseFloat(coords.substring(0, commaPos)); var lng = parseFloat(coords.substring(commaPos + 1, coords.length)); var myLatlng = new google.maps.LatLng(lat, lng); var mapOptions = { zoom: 15, center: myLatlng }; map = new google.maps.Map(canvas, mapOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map }); } /* */ function addError(inputId, msg){ var $input = $('#reg_form '+ inputId); var $error = $("
").attr("class", "pwf-msg").append( $("
").attr("class", "msg-error").append(msg) ); $input.parent().parent().append($error) } !function ($) { var $win = $(window); var $html = $('html'); var $body = $('body'); var $doc = $(document); $.widget( "custom.catcomplete", $.ui.autocomplete, { _renderMenu: function( ul, items ) { var that = this, currentCategory = ""; $.each( items, function( index, item ) { if ( item.category != currentCategory ) { ul.append( "
  • " + item.category + "
  • " ); currentCategory = item.category; } that._renderItemData( ul, item ); }); } }); /* submiting registration form */ $(function () { $('#reg_form').on('submit', function(event){ event.preventDefault(); var formData = $(this).serialize(); $.post('register/', formData, function(data){ if(data.success){ //register success // remove input values $('#reg_form input').each(function(i){ $(this).val(""); }); // close popup $.fancybox.close(); } else{ //hide help messages $("#reg_form .msg-help:visible").hide(); //delete previous errors $("#reg_form .msg-error").parent().remove(); //generate new errors var form_inputs = ['first_name', 'last_name', 'email', 'password1', 'password2'] for(var i= 0; i < form_inputs.length; i++){ if(form_inputs[i] in data){ var input_id = '#id_'+form_inputs[i]; addError(input_id, data[form_inputs[i]]) } } } }); }); /* submiting login form $('#log_form').on('submit', function(event){ event.preventDefault(); var formData = $(this).serialize(); var url = 'login/'; $.ajax({ url: url, type: 'post', data: formData, success: function(data){ if(data.success){ console.log('success'); } else{ console.log(data); } } }); }); */ /* Нестандартное оформление для поля select */ $.fn.customSelect = function () { return $(this).each(function() { var $this = $(this); var $options = $this.children('option'); var numberOfOptions = $this.children('option').length; var $selected = $(":selected", $this); // Hides the select element $this.addClass('s-hidden'); // Wrap the select element in a div $this.wrap('
    '); // Insert a styled div to sit over the top of the hidden select element $this.after('
    '); // Cache the styled div var $styledSelect = $this.next('div.custom-select-wrap'); var $styledSelectText = $styledSelect.children('.custom-select-text'); // Show the first select option in the styled div $styledSelectText.text($this.children('option').eq(0).text()); if ( $options.index($selected) == 0 && (!$this.children('option').eq(0).val() || !$this.children('option').eq(0).attr('value')) ) { $styledSelectText.addClass('placeholder'); } var $menu = $('
    ').insertAfter($styledSelect); var $optionsWrap = $menu.find('.scroll-content'); // Insert an unordered list after the styled div and also cache the list var $list = $('