| 1 |
var $ = jQuery; |
| 2 |
var save_method; //for save method string |
| 3 |
var host=window.location.hostname; |
| 4 |
var fullpath=window.location.pathname; |
| 5 |
var fullparam=window.location.search.split('&'); |
| 6 |
|
| 7 |
var firstparam=fullparam[0]; |
| 8 |
var secoundparam=fullparam[1]; |
| 9 |
|
| 10 |
jQuery(document).ready(function () { |
| 11 |
|
| 12 |
$(document).on('click', '.SwalBtn1', function() { |
| 13 |
swal.clickConfirm(); |
| 14 |
}); |
| 15 |
$(document).on('click', '.SwalBtn2', function() { |
| 16 |
window.open( |
| 17 |
"https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/", |
| 18 |
'_blank' |
| 19 |
); |
| 20 |
|
| 21 |
swal.clickConfirm(); |
| 22 |
}); |
| 23 |
$(document).on('click', '.SwalBtn3', function() { |
| 24 |
sessionStorage.setItem("sr_pop", "1"); |
| 25 |
swal.clickConfirm(); |
| 26 |
}); |
| 27 |
|
| 28 |
if(sessionStorage && (firstparam=="?page=seo-redirection.php" && !secoundparam) || secoundparam=="tab=cutom") |
| 29 |
{ |
| 30 |
|
| 31 |
if (seoredirection.msg.length > 0 && !sessionStorage.getItem("sr_pop")==true) |
| 32 |
{ |
| 33 |
swal({ |
| 34 |
title:"Don't lose your traffic!<br><br>"+ |
| 35 |
seoredirection.msg, |
| 36 |
type: "warning", |
| 37 |
animation: "slide-from-top", |
| 38 |
html: '<center><button type="button" role="button" class="SwalBtn1 customSwalBtn1">' + 'Close' + '</button>' + |
| 39 |
'<button type="button" role="button" class="SwalBtn2 customSwalBtn2">' + 'Fix now' + '</button>'+ |
| 40 |
'<button type="button" role="button" class="SwalBtn3 customSwalBtn3">' + "Don't show again" + '</button></center>', |
| 41 |
showCancelButton: false, |
| 42 |
showConfirmButton: false |
| 43 |
}); |
| 44 |
|
| 45 |
// swal({ |
| 46 |
// title: seoredirection.msg, |
| 47 |
// type: "warning", |
| 48 |
// showCancelButton: true, |
| 49 |
// confirmButtonColor: '#DD6B55', |
| 50 |
// cancelButtonColor :'#5bc0de', |
| 51 |
// confirmButtonText: "Don't Show Again", |
| 52 |
// cancelButtonText: " Ok ", |
| 53 |
// closeOnConfirm: true, |
| 54 |
// closeOnCancel: true, |
| 55 |
// animation: "slide-from-top", |
| 56 |
// html:true, |
| 57 |
// }, |
| 58 |
// function (isConfirm) { |
| 59 |
// if (isConfirm) { |
| 60 |
// sessionStorage.setItem("bool", "1"); |
| 61 |
// } |
| 62 |
// } |
| 63 |
// |
| 64 |
// ); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
// swal("Warning!", seoredirection.msg, "warning"); |
| 69 |
|
| 70 |
$('div.edit_template').click(function (event) { |
| 71 |
$('.loading').show(); |
| 72 |
var ele = $(this); |
| 73 |
$(this).attr('disabled', true); |
| 74 |
save_method = 'Update'; |
| 75 |
event.preventDefault(); |
| 76 |
var parent = $(this).parent(); |
| 77 |
var editID = parent.attr("href"); |
| 78 |
$.ajax({ |
| 79 |
url: seoredirection.ajax_url, |
| 80 |
type: "POST", |
| 81 |
data: { |
| 82 |
'action': 'customUpdateRec', |
| 83 |
'ID': editID, |
| 84 |
}, |
| 85 |
success: function (data) { |
| 86 |
var record = $.parseJSON(data); |
| 87 |
if (record.status == 'suucess') |
| 88 |
{ |
| 89 |
clr(); |
| 90 |
$('#edit').val(editID); |
| 91 |
$('#add_new').val(""); |
| 92 |
$('#edit_exist').val("1"); |
| 93 |
$('#myModal').modal('show'); // show bootstrap modal |
| 94 |
$('.loading').hide(); |
| 95 |
$('.modal-title').text('Edit Custom Redirection'); // Set Title to Bootstrap modal title |
| 96 |
$('#btnSave').val(save_method); //change button text |
| 97 |
$('#btnSave').attr('disabled', false); //set button enable |
| 98 |
var newdata = record.rec; |
| 99 |
$('#redirect_from_type').val(newdata.redirect_from_type); |
| 100 |
$('#redirect_from').val(newdata.redirect_from); |
| 101 |
|
| 102 |
if(newdata.redirect_from_folder_settings>0) |
| 103 |
$('#redirect_from_folder_settings').val(newdata.redirect_from_folder_settings); |
| 104 |
else |
| 105 |
$('#redirect_from_folder_settings').val(1); |
| 106 |
|
| 107 |
$('#redirect_from_subfolders').val(newdata.redirect_from_subfolders); |
| 108 |
$('#redirect_to_type').val(newdata.redirect_to_type); |
| 109 |
$('#redirect_to').val(newdata.redirect_to); |
| 110 |
$('#redirect_to_folder_settings').val(newdata.redirect_to_folder_settings); |
| 111 |
$('#redirect_type').val(newdata.redirect_type); |
| 112 |
|
| 113 |
redirect_from_type_change(); |
| 114 |
//redirect_to_folder_settings_change(); |
| 115 |
//redirect_to_type_change(); |
| 116 |
|
| 117 |
} |
| 118 |
} |
| 119 |
}); |
| 120 |
}); |
| 121 |
|
| 122 |
$("input").change(function () { |
| 123 |
if($(this).parent().parent().hasClass('has-error')){ |
| 124 |
$(this).parent().parent().removeClass('has-error'); |
| 125 |
$(this).next().empty(); |
| 126 |
} |
| 127 |
}); |
| 128 |
$("textarea").change(function () { |
| 129 |
if($(this).parent().parent().hasClass('has-error')){ |
| 130 |
$(this).parent().parent().removeClass('has-error'); |
| 131 |
$(this).next().empty(); |
| 132 |
} |
| 133 |
}); |
| 134 |
$("select").change(function () { |
| 135 |
if($(this).parent().parent().hasClass('has-error')){ |
| 136 |
$(this).parent().parent().removeClass('has-error'); |
| 137 |
$(this).next().empty(); |
| 138 |
} |
| 139 |
}); |
| 140 |
}); |
| 141 |
function clr() { |
| 142 |
$('.help-block').hide(); |
| 143 |
$('#redirect_from_type').show(); |
| 144 |
$('#redirect_from_folder_settings').hide(); |
| 145 |
$('#redirect_from_subfolders').hide(); |
| 146 |
$('#redirect_from').attr('class', 'Page_background_1 regular-text'); |
| 147 |
$('#redirect_to_type').show(); |
| 148 |
$('#redirect_to').attr('class', 'Page_background_1 regular-text'); |
| 149 |
$('#redirect_to_folder_settings').hide(); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
} |
| 155 |
function add_rec() { |
| 156 |
clr(); |
| 157 |
$('.loading').show(); |
| 158 |
save_method = 'Add New'; |
| 159 |
$(this).attr('disabled', true); |
| 160 |
$('#add_new').val("1"); |
| 161 |
$('#edit').val(""); |
| 162 |
$('#edit_exist').val(""); |
| 163 |
$('#myform')[0].reset(); // reset form on modals |
| 164 |
$('#myModal').modal('show'); // show bootstrap modal |
| 165 |
$('.loading').hide(); |
| 166 |
$('.modal-title').text('Add Custom Redirection'); // Set Title to Bootstrap modal title |
| 167 |
$('#btnSave').val(save_method); //change button text |
| 168 |
$('#btnSave').attr('disabled', false); //set button enable |
| 169 |
} |
| 170 |
function save_function() |
| 171 |
{ |
| 172 |
$('.loading').show(); |
| 173 |
$('#btnSave').val('Saving...'); //change button text |
| 174 |
$('#btnSave').attr('disabled', true); //set button disable |
| 175 |
var formData = $('#myform').serialize(); |
| 176 |
msg = $("#msg_response"); |
| 177 |
$.ajax({ |
| 178 |
url: seoredirection.ajax_url, |
| 179 |
type: "POST", |
| 180 |
data: { |
| 181 |
'action': 'customAddUpdate', |
| 182 |
'formData': formData, |
| 183 |
}, |
| 184 |
success: function (data) { |
| 185 |
|
| 186 |
data = $.parseJSON(data); |
| 187 |
if (data.status == 'error') //if success close modal and reload ajax table |
| 188 |
{ |
| 189 |
$('.loading').hide(); |
| 190 |
msg.html('<span style="color:red">' + data.msg + '</span>') |
| 191 |
|
| 192 |
} |
| 193 |
else if (data.status == 'success') |
| 194 |
{ |
| 195 |
$('#myModal').modal('hide'); |
| 196 |
$('.loading').hide(); |
| 197 |
//msg.html('<span style="color:green">' + data.msg + '</span>') |
| 198 |
console.log(data.msg); |
| 199 |
swal({ |
| 200 |
title: data.msg, |
| 201 |
type: "success", |
| 202 |
confirmButtonColor: '#5cb85c', |
| 203 |
confirmButtonText: "ok", |
| 204 |
closeOnConfirm: true, |
| 205 |
animation: "slide-from-top", |
| 206 |
}).then(function() { |
| 207 |
$('.loading').show(); |
| 208 |
window.location.href = data.url; |
| 209 |
}); |
| 210 |
} |
| 211 |
if (data.inputerror) { |
| 212 |
$('.loading').hide(); |
| 213 |
for (var i = 0; i < data.inputerror.length; i++) { |
| 214 |
$('.help-block').show(); |
| 215 |
$('[name="' + data.inputerror[i] + '"]').next().text(data.error_string[i]); |
| 216 |
} |
| 217 |
} |
| 218 |
$('#btnSave').val(save_method); //change button text |
| 219 |
$('#btnSave').attr('disabled', false); //set button enable |
| 220 |
}, |
| 221 |
error: function (jqXHR, textStatus, errorThrown) { |
| 222 |
console.log(jqXHR, textStatus, errorThrown); |
| 223 |
$('.loading').hide(); |
| 224 |
$('#btnSave').val(save_method); //change button text |
| 225 |
$('#btnSave').attr('disabled', false); //set button enable |
| 226 |
} |
| 227 |
}); |
| 228 |
} |
| 229 |
|
| 230 |
function redirect_from_type_change() |
| 231 |
{ |
| 232 |
if (document.getElementById('redirect_from_type').value == 'Folder') |
| 233 |
{ |
| 234 |
document.getElementById('redirect_from_folder_settings').style.display = 'inline'; |
| 235 |
document.getElementById('redirect_from').className = 'Folder_background_1'; |
| 236 |
redirect_to_folder_settings_change(); |
| 237 |
} |
| 238 |
else if (document.getElementById('redirect_from_type').value == 'Page') |
| 239 |
{ |
| 240 |
document.getElementById('redirect_from_folder_settings').style.display = 'none'; |
| 241 |
document.getElementById('redirect_from').className = 'Page_background_1 regular-text'; |
| 242 |
document.getElementById('redirect_from_subfolders').style.display = 'none'; |
| 243 |
} |
| 244 |
else if (document.getElementById('redirect_from_type').value == 'Regex') |
| 245 |
{ |
| 246 |
document.getElementById('redirect_from_folder_settings').style.display = 'none'; |
| 247 |
document.getElementById('redirect_from').className = 'Regex_background_1'; |
| 248 |
document.getElementById('redirect_from_subfolders').style.display = 'none'; |
| 249 |
} |
| 250 |
|
| 251 |
check_redirect_from(); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
function redirect_to_type_change() |
| 256 |
{ |
| 257 |
if (document.getElementById('redirect_to_type').value == 'Folder') |
| 258 |
{ |
| 259 |
document.getElementById('redirect_to_folder_settings').style.display = 'inline'; |
| 260 |
document.getElementById('redirect_to').className = 'Folder_background_1'; |
| 261 |
} |
| 262 |
else if (document.getElementById('redirect_to_type').value == 'Page') |
| 263 |
{ |
| 264 |
document.getElementById('redirect_to_folder_settings').style.display = 'none'; |
| 265 |
document.getElementById('redirect_to').className = 'Page_background_1 regular-text'; |
| 266 |
} |
| 267 |
|
| 268 |
check_redirect_to(); |
| 269 |
} |
| 270 |
|
| 271 |
function redirect_to_folder_settings_change() |
| 272 |
{ |
| 273 |
|
| 274 |
if (document.getElementById('redirect_from_folder_settings').value == '1') |
| 275 |
{ |
| 276 |
document.getElementById('redirect_from_subfolders').style.display = 'none'; |
| 277 |
} else |
| 278 |
{ |
| 279 |
document.getElementById('redirect_from_subfolders').style.display = 'block'; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
function check_redirect_from() |
| 284 |
{ |
| 285 |
|
| 286 |
var rfrom = document.getElementById('redirect_from').value; |
| 287 |
|
| 288 |
if (rfrom != '') { |
| 289 |
var cr = rfrom.substring(rfrom.length - 1); |
| 290 |
if (document.getElementById('redirect_from_type').value == 'Folder' && cr != '/') |
| 291 |
document.getElementById('redirect_from').value = rfrom + '/'; |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
function check_redirect_to() |
| 297 |
{ |
| 298 |
|
| 299 |
var rto = document.getElementById('redirect_to').value; |
| 300 |
|
| 301 |
|
| 302 |
if (rto != '') { |
| 303 |
var cr = rto.substring(rto.length - 1); |
| 304 |
if (document.getElementById('redirect_to_type').value == 'Folder' && cr != '/') |
| 305 |
document.getElementById('redirect_to').value = rto + '/'; |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
if((firstparam=="?page=seo-redirection.php" && !secoundparam) || secoundparam=="tab=cutom") |
| 310 |
{ |
| 311 |
redirect_from_type_change(); |
| 312 |
redirect_to_type_change(); |
| 313 |
} |
| 314 |
var update_cnt=0; |
| 315 |
var insert_cnt=0; |
| 316 |
|
| 317 |
function import_function(total,offset) |
| 318 |
{ |
| 319 |
var ele = $("#btnImport"); |
| 320 |
ele.attr("disabled",true); |
| 321 |
$(".import_msg").html(""); |
| 322 |
$(".import_msg").removeClass('success'); |
| 323 |
$(".import_msg").removeClass('error'); |
| 324 |
|
| 325 |
if(offset!=0) |
| 326 |
{ |
| 327 |
newwdth = $('.progress-bar').width(); |
| 328 |
wdth = offset*100/total; |
| 329 |
} |
| 330 |
else |
| 331 |
wdth = 0; |
| 332 |
$.ajax({ |
| 333 |
url: seoredirection.ajax_url+'?action=importFromRedirection&offset='+offset, |
| 334 |
type: "POST", |
| 335 |
beforeSend: function(){ |
| 336 |
if($('.modal-body .progress_wrap').find(".progress").length == 0) |
| 337 |
{ |
| 338 |
$('.modal-body .progress_wrap').html('<div class="progress"><div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div></div>').fadeIn(); |
| 339 |
} |
| 340 |
$('.progress-bar').css("width",Math.round(wdth)+"%"); |
| 341 |
|
| 342 |
if(wdth > 0) |
| 343 |
$('.progress-bar').html(" "+Math.round(wdth)+"% "); |
| 344 |
}, |
| 345 |
success: function (data) { |
| 346 |
/*console.log(data);*/ |
| 347 |
if(wdth > 0) |
| 348 |
$('.progress-bar').html(" "+Math.round(wdth)+"% "); |
| 349 |
var record = $.parseJSON(data); |
| 350 |
if(record.status=="success") |
| 351 |
{ |
| 352 |
|
| 353 |
offset = parseInt(offset)+1; |
| 354 |
|
| 355 |
update_cnt = parseInt(update_cnt)+parseInt(record.updateCnt); |
| 356 |
insert_cnt = parseInt(insert_cnt)+parseInt(record.insertCnt); |
| 357 |
if(total > offset) |
| 358 |
{ |
| 359 |
import_function(total,offset); |
| 360 |
} |
| 361 |
else |
| 362 |
{ |
| 363 |
//$(".sr_notice .notice-dismiss").trigger("click"); |
| 364 |
$(".sr_notice").remove(); |
| 365 |
$('.progress-bar').css("width","100%"); |
| 366 |
$('.progress-bar').html(" 100% "); |
| 367 |
setTimeout(function() { |
| 368 |
$(".modal-body .progress_wrap").fadeOut().html(""); |
| 369 |
var msgele = $(".import_msg").html(record.msg).hide(); |
| 370 |
msgele.find(".insert_cnt").html(insert_cnt); |
| 371 |
msgele.find(".update_cnt").html(update_cnt); |
| 372 |
msgele.show(); |
| 373 |
msgele.addClass('success'); |
| 374 |
console.log(1); |
| 375 |
// ele.attr("disabled",false); |
| 376 |
}, 3000); |
| 377 |
|
| 378 |
} |
| 379 |
|
| 380 |
} |
| 381 |
else |
| 382 |
{ |
| 383 |
$(".import_msg").html(record.msg); |
| 384 |
$(".import_msg").addClass('error'); |
| 385 |
ele.attr("disabled",false); |
| 386 |
} |
| 387 |
} |
| 388 |
}); |
| 389 |
} |
| 390 |
|
| 391 |
$("body").on("click",".sr_notice .notice-dismiss",function(e){ |
| 392 |
e.preventDefault(); |
| 393 |
console.log("called"); |
| 394 |
$.ajax({ |
| 395 |
url: seoredirection.ajax_url+'?action=sr_dismiss_notice', |
| 396 |
type: "POST", |
| 397 |
success: function (data) { |
| 398 |
console.log(data); |
| 399 |
} |
| 400 |
}); |
| 401 |
}); |
| 402 |
|
| 403 |
$("body").on("click",".chkall",function(e){ |
| 404 |
//e.preventDefault(); |
| 405 |
if (this.checked) { |
| 406 |
$(".chkthis").each(function() { |
| 407 |
this.checked=true; |
| 408 |
}); |
| 409 |
} else { |
| 410 |
$(".chkthis").each(function() { |
| 411 |
this.checked=false; |
| 412 |
}); |
| 413 |
} |
| 414 |
|
| 415 |
}); |
| 416 |
$("body").on("click",".chkthis",function(e){ |
| 417 |
if ($(this).is(":checked")) { |
| 418 |
var isAllChecked = 0; |
| 419 |
$(".chkthis").each(function() { |
| 420 |
if (!this.checked) |
| 421 |
isAllChecked = 1; |
| 422 |
}); |
| 423 |
|
| 424 |
if (isAllChecked == 0) { |
| 425 |
$(".chkall").prop("checked", true); |
| 426 |
} |
| 427 |
} |
| 428 |
else { |
| 429 |
$(".chkall").prop("checked", false); |
| 430 |
} |
| 431 |
}); |
| 432 |
|
| 433 |
|
| 434 |
function delete_function() |
| 435 |
{ |
| 436 |
console.log("called"); |
| 437 |
if($(".chkthis:checked").length > 0) |
| 438 |
jQuery(this).parents('form').submit(); |
| 439 |
else |
| 440 |
return false; |
| 441 |
} |