Closed [Mail-for-Good] Create barkinet

Create barkinet
By barkinet
Assigned to barkinet

$(‘.hidden-code’).click(function(e) {
e.preventDefault();
$(this).children(‘.gist’).slideToggle();
});

var originalText;
$(‘.example-grid’).children().hover(
function() {
originalText = $(this).text();
$(this).html($(this).width()+’px’);
},
function() {
$(this).html(originalText);
}
);
// find close to coordinates

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(UserLocation);

} else {
// loc = “Geolocation is not supported by this browser.”;
NearestCity(38.8951, -77.0367);
}
}
getLocation();

// Callback function for asynchronous call to HTML5 geolocation
function UserLocation(position) {
NearestCity(position.coords.latitude, position.coords.longitude);
}

// Convert Degress to Radians
function Deg2Rad(deg) {
return deg * Math.PI / 180;
}

function PythagorasEquirectangular(lat1, lon1, lat2, lon2) {
lat1 = Deg2Rad(lat1);
lat2 = Deg2Rad(lat2);
lon1 = Deg2Rad(lon1);
lon2 = Deg2Rad(lon2);
var R = 6371; // km
var x = (lon2 – lon1) * Math.cos((lat1 + lat2) / 2);
var y = (lat2 – lat1);
var d = Math.sqrt(x * x + y * y) * R;
return d;
}

var cities = [];
var cityNames = [];

$.getJSON(‘assets/json/campsites2.json’).then(function(data) {
data.forEach(function(loc) {
const coordString = loc.coordinates;
let values = coordString.split(” “);

var lat = ConvertDMSToDD(parseFloat(values[0]));
var lng = ConvertDMSToDD(parseFloat(values[1]));
let coords = [loc.city, loc.state, loc.country, lat, lng];

cities.push(coords);

if(loc.state.length==0){
cityNames.push(loc.city+”, “+loc.country);
} else {
cityNames.push(loc.city+”, “+loc.state+”, “+loc.country);
}

});
});

function ConvertDMSToDD(degrees) {
var dd = degrees;

// if (direction == “S” || direction == “W”) {
// dd = dd * -1;
// } // Don’t do anything for N or E
return dd;
}

function NearestCity(latitude, longitude) {
var mindif = 100;
var closest = [];

for (index = 0; index < cities.length; ++index) {
var dif = PythagorasEquirectangular(latitude, longitude, cities[index][3], cities[index][4]);
if (dif < mindif) {
closest.push({index:index, dist:dif});
}
}

closest = closest.sort(function(a, b){
return a.dist – b.dist;
});

$.getJSON('assets/json/campsites2.json').then(function(data) {
$("#closeCamps").append(
`

The study groups nearest you:

`
);
for (let i = 0; i < closest.length; i++){
let loc = data[closest[i].index];
let img = loc.photoUrl || "http://ift.tt/2p1xKRP",
city = loc.city,
state = loc.state,
country = loc.country,
url = loc.url,
coords = loc.coordinates;
let location = '';
if(state.length==0){
location = city + ", " + country;
} else {
location = city + ", " + state + ", " + country;
}
$("#closeCamps").append(
`

`
);
}
});
}

//full list of locations
$.getJSON(‘assets/json/campsites2.json’).then(function(data) {

data.forEach(function(loc) {
const img = loc.photoUrl || “http://ift.tt/2p1xKRP”,
city = loc.city,
state = loc.state,
country = loc.country,
url = loc.url;
let location = ”;

if(state.length==0){
location = city + “, ” + country;
} else {
location = city + “, ” + state + “, ” + country;
}

$(“#camps”).append(
`

  • `
    );

    });
    });
    var typing_timer;
    //search
    $(‘#search’).on(‘keyup’, function () {
    var li = [];
    var valThis = this.value.toLowerCase();
    valThis = valThis.toLowerCase();
    valThis = valThis.replace(/\s+/g, ”);

    var searchFunc = function(){
    $(‘.city’).each(function() {
    var currentLiText = $(this).text(),
    showCurrentLi = ((currentLiText.toLowerCase()).replace(/\s+/g, ”)).indexOf(valThis) !== -1;
    $(this).parent().parent().toggle(showCurrentLi);

    if(showCurrentLi==true){
    li.push(showCurrentLi);

    }
    setTimeout(function(){
    $(‘.loader’).hide();
    }, 250);
    });
    var size = $(‘#camps’).find(‘li’).length;
    $(“#res”).html(li.length);
    }

    clearTimeout(this.typing_timer);

    this.typing_timer = setTimeout(searchFunc, 250)
    $(‘.loader’).show();

    });

    // responsive 16×9 iframe – restricted by parent’s width
    var resizeIframe = function() {
    $(‘.responsive-iframe iframe’).each(function(index, iframe) {
    var parentWidth = $(iframe).parent().width();
    $(iframe).width(parentWidth);
    $(iframe).height(parentWidth / 16 * 9);
    });
    };
    $(window).on(‘resize’, resizeIframe);
    resizeIframe();

    Labeled:

    April 21, 2017 at 04:20AM
    via GitHub http://ift.tt/2pJkXkM