JQuery와
그래서, 당신이해야 할 첫번째 일은 위젯이 저장 한 때 통지되도록 AJAX 호출에 후크입니다. 이를 위해 jQuery ajaxSuccess
함수를 사용합니다. 마지막으로
// Use a self executing function so we can safely use
// $ inside and know it = jQuery
(function($){
// Tie into all jQuery AJAX requests
$(document).ajaxSuccess(function(e, x, o){
// Make sure our widget is the one being saved
// id_base will equal whatever is set in the PHP for the widget
// In this example, we target the text widget
if(o.data && o.data.indexOf('id_base=text') > -1){
// Now, lets quickly find all the right elements
// and filter out the ones already set up, and finally
// apply the `markItUp` call, but we will delay just to give
// WP a chance to update the widget
window.setTimeout(function(){
$("textareas.markItUp:not(.markItUpEditor)").markItUp(mySettings);
}, 200);
}
});
})(jQuery);
PHP의/워드 프레스
을 새 JS는 위젯 페이지에서 만 파일 포함 WP 알려주기 : 자신의 js
파일이 넣습니다. 당신은 위젯 PHP 파일로, 당신이 위젯을 구축하고있다 functions.php
으로 또는 경우에 하나이 통합해야합니다 내가 게시 할 때
function register_markitup(){
wp_enqueue_script('markitup-widgets', WP_PLUGIN_URL . '/your-plugin/js/markitup-ajax.js');
}
add_action("admin_print_scripts-widgets.php", 'register_markitup');
편집 나는 잘못된 add_action
후크를했다. 방금 추가 한 .php
이 필요했습니다. 코드가 정확합니다.
나는 내일 부탁합니다. 그 2:30 AM 여기 ... 짧은 대답은 WP가 저장 후 위젯 내용을 업데이트함에 따라 각 위젯 AJAX 요청 후에 'markItUp' 함수를 다시 호출해야한다는 것입니다. 나는 내일 너를 보여줄 수있어 ... –
고마워. 나는 그것을 고대한다. 그러나 지금은 해결 방법을 찾을 수있었습니다. admin_head에 활성화 된 jit 파일을로드하는 데 사용되었습니다. 대신 jQuery 코드를 위젯 형태로 옮겼다. 위젯 페이지는 여러 개의 markItUp 영역을 사용하여 조금 느리게로드되는 것 같습니다. – Necati