jQuery(function($){
function findTitle(){
let t = $('#title');
if(t.length) return t;
t = $('.editor-post-title__input');
if(t.length) return t;
return null;
}
function slugify(text){
return text
.toString()
.trim()
.toLowerCase()
.replace(/[\u0600-\u06FF]/g, '') // إزالة العربي من الـ slug
.replace(/[^\w\-]+/g, '-')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
}
function setCategoryByName(name){
$('.editor-post-taxonomies__hierarchical-terms-choice input').each(function(){
if($(this).closest('label').text().trim() === name){
$(this).prop('checked', true).trigger('change');
}
});
}
function init(){
const title = findTitle();
if(!title){ setTimeout(init,300); return; }
if(!$('#kb_v53_cat').length){
const sel = $('');
kbV53.cats.forEach(c=> sel.append(''));
title.before(sel);
}
const box = $('
').css({
position:'absolute',
background:'#fff',
border:'1px solid #ccc',
zIndex:999999,
maxHeight:'260px',
overflow:'auto',
display:'none'
});
title.after(box);
title.on('input focus',function(){
const q = title.val();
if(!q) return box.hide();
$.post(kbV53.ajax,{
action:'kb_search_v53',
nonce:kbV53.nonce,
q:q,
category:$('#kb_v53_cat').val()
},function(res){
box.empty();
if(!res.success || !res.data.length) return box.hide();
res.data.forEach(i=>{
$('')
.text(i.keyword)
.css({padding:'8px',cursor:'pointer'})
.appendTo(box)
.on('click',function(){
// 1️⃣ العنوان
title.val(i.keyword).trigger('input');
// 2️⃣ القسم تلقائي
setCategoryByName(i.category);
// 3️⃣ الاسم اللطيف تلقائي
const slug = slugify(i.keyword);
$('#post_name').val(slug).trigger('change');
box.hide();
});
});
box.show().width(title.outerWidth());
},'json');
});
$(document).on('click',e=>{
if(!$(e.target).closest('#kb_v53_box,#kb_v53_cat').length){
box.hide();
}
});
}
init();
});
سعر الدرهم الإماراتي اليوم - المفيد نيوز