<commit_before>/**
 * Created by <NAME> on 4/7/2015.
 */

var x = document.getElementById("map_holder");
var map;
var infowindow;
var latlng;
var request;
var selected;
var sortyby ="PROMINENCE";
var place_details_sortbyprominence=[];
var place_details_sorbydistance = [];
$(document).ready(function () {

    $("#selecta").select2({
        placeholder: "Select Places...",
        allowClear: true,
        maximumSelectionSize: 5
    });

    $(document).on("change","#selecta",function(){
        selected = $("#selecta").select2("val");
        request = {
            location: latlng,
            radius:800,
            rankBy: google.maps.places.RankBy.PROMINENCE,
            types: selected
        };


    });

    $('#cmdSubmit').click(function () {

        if ($("#selecta").select2("val")) {
            $(this).hide();
            $("#noSubmit").show();

            getLocation();

            setTimeout(function () {
                $("#noSubmit").hide();
                $("#cmdSubmit").fadeIn();
            }, 2000)
        } else {
            $('#alert-msg').html("<div class='alert alert-warning alert-dismissable'> <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button><strong>Ops!&nbsp;</strong>Please select place/s.</div>");

        }
    });

    $(".sortby").click(function(){
        $(".sortby").removeClass("active");
        $(this).addClass("active");



            if($(this).text() ==='Distance'){

                if("leloo_by_distance" in localStorage){
                    alert("Distance");

                    display_sorted_results(localStorage.getItem("leloo_by_distance"))
                }else{

                    if($("#selecta").select2("val")){
                        request.types=selected;
                        request.radius=null;
                        request.rankBy =google.maps.places.RankBy.DISTANCE;
                        getLocation();
                    }

                }

            }else if($(this).text() ==='Popularity'){

                if("leloo_by_prominence" in localStorage){
                    alert("Prominence");
                    display_sorted_results(localStorage.getItem("leloo_by_prominence"))
                }else{
                    if($("#selecta").select2("val")){
                        request.types=selected;
                        request.radius=800;
                        request.rankBy =google.maps.places.RankBy.PROMINENCE;
                        getLocation();
                    }

                }
            }


    });
});


function getLocation() {

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition, showError);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {


    document.querySelector("#mapcanvas").style.height = '300px';
    latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    var myOptions = {
        zoom: 15,
        center: latlng,
        mapTypeControl: false,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL} ,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

    var infowindowmain = new google.maps.InfoWindow({
        map: map,
        position: latlng,
        content: "You are here! (at least within a " + position.coords.accuracy + " meter radius)"
    });

    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: "You are here! (at least within a " + position.coords.accuracy + " meter radius)"
    });
    google.maps.event.addListener(marker, 'click', function () {
        infowindow.setContent("You are here! (at least within a " + position.coords.accuracy + " meter radius)");
        infowindow.open(map, this);
    });

    request.location = latlng;

    selected = $("#selecta").select2("val");
    infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(map);
    service.nearbySearch(request, callback);

    findhim(latlng);

}

function findhim(point) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({latLng: point}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {

                var p_name = (results[0].name) ? "Place name: " + results[0].name + "<br/>" : '';
                var p_address = (results[0].formatted_address) ? "<h5>Your Location address:</h5><h6>" + results[0].formatted_address + "</h6" : '';
                document.getElementById("location_container").innerHTML = p_name + p_address;
            }
        }
    });


}

function callback(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {

        for (var i = 0; i < results.length; i++) {
            if(checkRadiusDistance(results[i],latlng,825)){
                createMarker(results[i]);
            }
        }
    }
}

function checkRadiusDistance(place,latlng,radius) {
    return google.maps.geometry.spherical.computeDistanceBetween(place.geometry.location, latlng) <= radius;
}


function createMarker(place) {

    var placeLoc = place.geometry.location;

    var marker = new google.maps.Marker({
        map: map,
        position: place.geometry.location
    });

    var requestdata = {
        placeId: place.place_id
    };

    document.getElementById("placeres").innerHTML="";
    var service = new google.maps.places.PlacesService(map);
    service.getDetails(requestdata, function(placedata, status) {

        if (status == google.maps.places.PlacesServiceStatus.OK)
        {

           // console.log(JSON.stringify(placedata))
            if(request.rankBy === google.maps.places.RankBy.PROMINENCE){
                place_details_sortbyprominence.push((placedata));

                //document.getElementById("json_container_prominence").innerHTML=(JSON.stringify(place_details_sortbyprominence));
                localStorage.setItem("leloo_by_prominence",JSON.stringify(place_details_sortbyprominence));
                display_sorted_results(localStorage.getItem("leloo_by_prominence"));

            }else if(request.rankBy === google.maps.places.RankBy.DISTANCE){
                place_details_sorbydistance.push((placedata));

                //document.getElementById("json_container_distance").innerHTML=(JSON.stringify(place_details_sorbydistance));
                localStorage.setItem("leloo_by_distance",JSON.stringify(place_details_sorbydistance));
                display_sorted_results(localStorage.getItem("leloo_by_distance"));<commit_msg>remove alerts<commit_after>/**
 * Created by <NAME> on 4/7/2015.
 */

var x = document.getElementById("map_holder");
var map;
var infowindow;
var latlng;
var request;
var selected;
var sortyby ="PROMINENCE";
var place_details_sortbyprominence=[];
var place_details_sorbydistance = [];
$(document).ready(function () {

    $("#selecta").select2({
        placeholder: "Select Places...",
        allowClear: true,
        maximumSelectionSize: 5
    });

    $(document).on("change","#selecta",function(){
        selected = $("#selecta").select2("val");
        request = {
            location: latlng,
            radius:800,
            rankBy: google.maps.places.RankBy.PROMINENCE,
            types: selected
        };


    });

    $('#cmdSubmit').click(function () {

        if ($("#selecta").select2("val")) {
            $(this).hide();
            $("#noSubmit").show();

            getLocation();

            setTimeout(function () {
                $("#noSubmit").hide();
                $("#cmdSubmit").fadeIn();
            }, 2000)
        } else {
            $('#alert-msg').html("<div class='alert alert-warning alert-dismissable'> <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button><strong>Ops!&nbsp;</strong>Please select place/s.</div>");

        }
    });

    $(".sortby").click(function(){
        $(".sortby").removeClass("active");
        $(this).addClass("active");



            if($(this).text() ==='Distance'){

                if("leloo_by_distance" in localStorage){
                    display_sorted_results(localStorage.getItem("leloo_by_distance"))
                }else{

                    if($("#selecta").select2("val")){
                        request.types=selected;
                        request.radius=null;
                        request.rankBy =google.maps.places.RankBy.DISTANCE;
                        getLocation();
                    }

                }

            }else if($(this).text() ==='Popularity'){

                if("leloo_by_prominence" in localStorage){

                    display_sorted_results(localStorage.getItem("leloo_by_prominence"))
                }else{
                    if($("#selecta").select2("val")){
                        request.types=selected;
                        request.radius=800;
                        request.rankBy =google.maps.places.RankBy.PROMINENCE;
                        getLocation();
                    }

                }
            }


    });
});


function getLocation() {

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition, showError);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {


    document.querySelector("#mapcanvas").style.height = '300px';
    latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    var myOptions = {
        zoom: 15,
        center: latlng,
        mapTypeControl: false,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL} ,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

    var infowindowmain = new google.maps.InfoWindow({
        map: map,
        position: latlng,
        content: "You are here! (at least within a " + position.coords.accuracy + " meter radius)"
    });

    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: "You are here! (at least within a " + position.coords.accuracy + " meter radius)"
    });
    google.maps.event.addListener(marker, 'click', function () {
        infowindow.setContent("You are here! (at least within a " + position.coords.accuracy + " meter radius)");
        infowindow.open(map, this);
    });

    request.location = latlng;

    selected = $("#selecta").select2("val");
    infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(map);
    service.nearbySearch(request, callback);

    findhim(latlng);

}

function findhim(point) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({latLng: point}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {

                var p_name = (results[0].name) ? "Place name: " + results[0].name + "<br/>" : '';
                var p_address = (results[0].formatted_address) ? "<h5>Your Location address:</h5><h6>" + results[0].formatted_address + "</h6" : '';
                document.getElementById("location_container").innerHTML = p_name + p_address;
            }
        }
    });


}

function callback(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {

        for (var i = 0; i < results.length; i++) {
            if(checkRadiusDistance(results[i],latlng,825)){
                createMarker(results[i]);
            }
        }
    }
}

function checkRadiusDistance(place,latlng,radius) {
    return google.maps.geometry.spherical.computeDistanceBetween(place.geometry.location, latlng) <= radius;
}


function createMarker(place) {

    var placeLoc = place.geometry.location;

    var marker = new google.maps.Marker({
        map: map,
        position: place.geometry.location
    });

    var requestdata = {
        placeId: place.place_id
    };

    document.getElementById("placeres").innerHTML="";
    var service = new google.maps.places.PlacesService(map);
    service.getDetails(requestdata, function(placedata, status) {

        if (status == google.maps.places.PlacesServiceStatus.OK)
        {


            if(request.rankBy === google.maps.places.RankBy.PROMINENCE){
                place_details_sortbyprominence.push((placedata));
                localStorage.setItem("leloo_by_prominence",JSON.stringify(place_details_sortbyprominence));
                display_sorted_results(localStorage.getItem("leloo_by_prominence"));

            }else if(request.rankBy === google.maps.places.RankBy.DISTANCE){
                place_details_sorbydistance.push((placedata));
                localStorage.setItem("leloo_by_distance",JSON.stringify(place_details_sorbydistance));
                display_sorted_results(localStorage.getItem("leloo_by_distance"));
{'fraction_non_alphanumeric': 0.14077632883398156, 'fraction_numerical': 0.006253336383741325, 'mean_word_length': 2.331808943089431, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2051869', 'n_tokens_mistral': 3871, 'n_tokens_neox': 3624, 'n_words': 603}