markItUp的Word preSS部件 [英] markItUp for Wordpress widget

查看:167
本文介绍了markItUp的Word preSS部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用markItUp用于在WP小部件一个textarea(即,在widgets.php页,在创建和编辑窗口小部件)。

I am using markItUp for a textarea in a WP widget (that is, on widgets.php page, while creating and editing a widget).

textarea的是markItUp'ed当我第一次打开窗口小部件,但在我点击保存功能丢失,我回一个普通文本区域。

The textarea is markItUp'ed when I first open the widget, but after I click save the functionality is lost and I am back to a regular textarea.

我比较源$ C ​​$ C对于之前保存后,保存页面的版本并没有-obviously没有区别,因为网页没有重新加载。 jQuery的是否需要为每一个Ajax调用调用?

I compared the source code for the before-save and after-save versions of the page and there is no difference -obviously, as the page isn't reloaded. Does jQuery need to be invoked for every ajax call?

我尝试添加

jQuery(".markitup").markItUp(mySettings);

小部件的表单处理函数中,但没有帮助。 我试图做出改变本次活动结合保存按钮太多,但似乎没有有所作为(有,我得到了它一个很好的机会都是错误的)。

inside the widget's form handling function but that didn't help. I tried to make changes binding this event to the save button too but that didn't seem to make a difference (there is a good chance that I got it all wrong).

我是一个小code-黑客使用PHP,Ajax和jQuery的最小的知识,所以任何指针可以提供帮助。谢谢你。

I am a petty code-hacker with minimal knowledge of PHP, Ajax and jQuery, so any pointer can help. Thanks.

推荐答案

jQuery的

所以,你需要做的第一件事就是钩到了AJAX调用,所以你会通知小部件已保存。要做到这一点,我们将使用jQuery的的ajaxSuccess 功能。把这个在自己的 JS 文件:

So, the first thing you need to do is hook into the AJAX call so you are notified when the widgets have been saved. To do this, we will use the jQuery ajaxSuccess function. Put this in its own js file:

// 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 /字preSS

最后,告诉WP,包括小部件页面上新的JS文件的只有的。您需要将这一要么到的functions.php 或者如果你正在建设一个小部件,进入小部件PHP文件:

Finally, tell WP to include your new js file only on the widgets page. You will need to incorporate this either into functions.php or if you are building a widget, into the widgets PHP file:

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 我刚添加。在code现在是正确的。

Edit I had an incorrect add_action hook when I posted. It needed the .php which I just added. The code is correct now.

这篇关于markItUp的Word preSS部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆