File: /home/dreamlan/public_html/wp-content/plugins/dreamland-nepal/public/js/dreamland-nepal-public.js
(function( $ ) {
'use strict';
/**
* All of the code for your public-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
function getAPIdata(ID,pID){
$('#mapinner-content .inner-content-box .inner-content-box-inner').empty();
if(ID != "null" && pID == ""){
$.ajax({
url : window.location.origin + "/wp-json/w1/v1/dreamland-nepals/"+ID,
}).done(function(data){
$('.nasc-loader-wrapper').hide();
if(data != ""){
$('#mapinner-content .inner-content-box .inner-content-box-inner').append(convertToTable(data));
}else{
noDataComing();
}
}).fail(function(msg) {
});
}else if(ID == "null" && pID != ""){
$.ajax({
url : window.location.origin + "/wp-json/wp/v2/dreamlandnepalposts/"+pID,
}).done(function(datas){
$('.nasc-loader-wrapper').hide();
if(datas != ""){
$('#mapinner-content .inner-content-box .inner-content-box-inner').append(getOnlyContent(datas));
}else{
noDataComing();
}
}).fail(function(msg) {
});
}else{
$.ajax({
url : window.location.origin + "/wp-json/w1/v1/dreamland-nepals/"+ID,
}).done(function(data){
if(data != ""){
$('.nasc-loader-wrapper').hide();
$('#mapinner-content .inner-content-box .inner-content-box-inner').append(convertToTable(data));
}
$.ajax({
url : window.location.origin + "/wp-json/wp/v2/dreamlandnepalposts/"+pID,
}).done(function(datas){
if(datas != ""){
$('.nasc-loader-wrapper').hide();
$('#mapinner-content .inner-content-box .inner-content-box-inner').append(getOnlyContent(datas));
}
if(datas == "" && data == ""){
noDataComing()
}
}).fail(function(msg) {
});
}).fail(function(msg) {
noDataComing()
});
}
}
function noDataComing(){
$('.nasc-loader-wrapper').hide();
$('#mapinner-content .inner-content-box .inner-content-box-inner').append("<p>Data are coming soon</p>");
}
function convertToTable(data){
var res = "";
if(data != ""){
res += "<div>"+
"<table>"+
"<tr><th>Ward No</th><th>Former VDC</th><th>Population</th><th>Area</th></tr>";
$.each(data,function(index,value){
res += "<tr>"+
"<td>" + value.No + "</td>"+
"<td>" + value.name + "</td>"+
"<td>" + value.population + "</td>"+
"<td>" + value.area + "</td>"+
"</tr>";
});
res += "</table></div>";
}
return res;
}
function getOnlyContent(data){
var res= "<div>";
res += "<p>"+data.content['rendered']+"</p>";
res += "</div>";
return res;
}
$(document).ready(function(){
$('.nasc-loader-wrapper').hide();
$('#mapid-content').hide();
$('#mapinner-content').hide();
$('#mapinner-content .fire-close').click(function(){
$(this).parent().hide();
});
$('#mapid-content .fire-close').click(function(){
$(this).parent().hide();
});
// $('#VIEWwards').click(function(){
// let ID = $(this).attr('data-id');
// getAPIdata(ID);
// $('#mapinner-content').show();
// });
});
$(document).on('click','#VIEWwards',function(){
let ID = $(this).attr('data-id');
let post_id = $(this).attr('data-content');
$('.nasc-loader-wrapper').show();
if(ID == "null" && pID == ""){
$('.nasc-loader-wrapper').hide();
noDataComing();
}else{
getAPIdata(ID,post_id);
}
$('#mapinner-content').show();
});
$(document).on('click','#VIEWINFO',function(){
let ID = $(this).attr('data-id');
$('#mapinner-content .inner-content-box .inner-content-box-inner').empty();
$('.nasc-loader-wrapper').show();
if(ID != "null"){
$.ajax({
url : window.location.origin + "/wp-json/wp/v2/dreamlandnepalposts/"+ID,
}).done(function(data){
$('.nasc-loader-wrapper').hide();
$('#mapinner-content .inner-content-box .inner-content-box-inner').append(getOnlyContent(data));
});
}else{
$('.nasc-loader-wrapper').hide();
$('#mapinner-content .inner-content-box .inner-content-box-inner').append("<p>Data are coming soon</p>")
}
$('#mapinner-content').show();
});
})( jQuery );