//testé avec jQuery v1.12.4
jQuery(function ($) {
// console.log('ici: ' + php_vars.toString() );
// console.log('ici: ' + php_vars);
// php_varsNew = php_vars.toString().split('.').join("");
// console.log(php_varsNew);
$(document.body).on('click', php_vars.toString(), function (event) {
var cl = $(this)[0].className.toString().toLowerCase();
//console.log($(this)[0].className);
//console.log(event.target.className);
$(php_vars).each(function (index, classN) {
var dot = classN.toString().split('.').join("").toLowerCase() ;
//console.log(dot +' ' + cl);
// console.log(cl.search(dot));
// console.log(cl.indexOf(dot));
// console.log(cl.includes(dot));
if (cl.indexOf(dot) !== -1) {
postid = dot;
//console.log(dot);
}
});
var ajax_url = "/wp-admin/admin-ajax.php";
var data = {
action: 'add_click',
type:'custom',
alexistracker_className: postid,
pageurl: window.location.pathname,
};
$.ajax({
url: ajax_url,
type: 'POST',
data: data,
beforeSend: function () {
},
success: function (response) {
//console.log(response);
}
});
//console.log(event.target.className);
//console.log($(this).attr('class') + php_vars);
})
$(document.body).on('click', '*[class*="alexistracker"]', function () {
//alert($(this).attr('class'));
//console.log($(this).get());
var postid;
$.each($(this).attr('class').split(' '), function (index, className) {
if (className.indexOf('alexistracker') === 0) {
postid = className;
//console.log($(this).get());
}
});
var ajax_url = "/wp-admin/admin-ajax.php";
var data = {
action: 'add_click',
type: 'regular',
alexistracker_className: postid,
pageurl: window.location.pathname,
};
$.ajax({
url: ajax_url,
type: 'POST',
data: data,
beforeSend: function () {
},
success: function (response) {
console.log(response);
}
});
})
// const divs = document.querySelectorAll("*[class*='test']"); //alexistracker
// divs.forEach(
// el => el.addEventListener('click', event => {
// console.log(event.target.classList[0]);
// // console.log(event.target.className );
// // console.log(event.target.textContent +' '+ event.target.innerText);
// console.log($(event.target).text() );
// var selectedStep = $(this).attr('class');
// console.log(selectedStep);
// var thisId = $(this).attr('id');
// var Trackersecondclass = event.target.classList[0];
// var Trackertext = $(event.target).text();
// var ajaxurl ="/wp-content/plugins/alexis-tracker/Addclick.php";
// var ajax_url = "/wp-admin/admin-ajax.php";
// var data = {
// action: 'add_click',
// //_wpnonce: WPAkismet.comment_author_url_nonce,
// id: thisId,
// cls: Trackersecondclass,
// txt: Trackertext
// };
// $.ajax({
// url: ajax_url,
// type: 'POST',
// data: data,
// beforeSend: function () {
// // Removes "x" link
// //$("a[commentid='" + thisId + "']").hide();
// // Show temp status
// //$("#author_comment_url_" + thisId).html($('').text(WPAkismet.strings['Removing...']));
// },
// success: function (response) {
// console.log(response);
// if (response) {
// // Show status/undo link
// // $("#author_comment_url_" + thisId)
// // .attr('cid', thisId)
// // .addClass('akismet_undo_link_removal')
// // .html(
// // $('').text(WPAkismet.strings['URL removed'])
// // )
// // .append(' ')
// // .append(
// // $('')
// // .text(WPAkismet.strings['(undo)'])
// // .addClass('akismet-span-link')
// // );
// }
// }
// });
// }));
}
)