用wordpress插件执行脚本

时间:2015-01-03 02:54:34

标签: javascript jquery wordpress

我正在使用插件“wp-video-lightbox”进行wordpress,为我的视频创建小浮动框。

我想使用像http://www.example.com/?video3这样的变量来提供像youtube这样的快捷方式,所以我试图找到一种在页面加载时执行脚本的方法(取决于变量)。

这是剧本中的功能:

/* ------------------------------------------------------------------------
        Class: prettyPhoto
        Use: Lightbox clone for jQuery
        Author: Stephane Caron (http://www.no-margin-for-errors.com)
        Version: 3.1.5
------------------------------------------------------------------------- */

(function($) {
        $.prettyPhoto = {version: '3.1.5'};

        $.fn.prettyPhoto = function(pp_settings) {

...

            $.prettyPhoto.initialize = function() {

                    settings = pp_settings;

                    if(settings.theme == 'pp_default') settings.horizontal_padding = 16;

                    // Find out if the picture is part of a set
                    theRel = $(this).attr(settings.hook);
                    galleryRegExp = /\[(?:.*)\]/;
                    isSet = (galleryRegExp.exec(theRel)) ? true : false;

                     // Put the SRCs, TITLEs, ALTs into an array.
                    pp_images = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr(settings.hook).indexOf(theRel) != -1) return $(n).attr('href'); }) : $.makeArray($(this).attr('href'));
                    pp_titles = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr(settings.hook).indexOf(theRel) != -1) return ($(n).find('img').attr('alt')) ? $(n).find('img').attr('alt') : ""; }) : $.makeArray($(this).find('img').attr('alt'));
                    pp_descriptions = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr(settings.hook).indexOf(theRel) != -1) return ($(n).attr('rev')) ? $(n).attr('rev') : ""; }) : $.makeArray($(this).attr('rev'));

                    if(pp_images.length > settings.overlay_gallery_max) settings.overlay_gallery = false;

                    set_position = jQuery.inArray($(this).attr('href'), pp_images); // Define where in the array the clicked item is positionned
                    rel_index = (isSet) ? set_position : $("a["+settings.hook+"^='"+theRel+"']").index($(this));

                    _build_overlay(this); // Build the overlay {this} being the caller

                    if(settings.allow_resize)
                            $(window).bind('scroll.prettyphoto',function(){ _center_overlay(); });


                    $.prettyPhoto.open();

                    return false;
            }

...

};

})(jQuery的);

当我使用<body onload="jQuery.prettyPhoto.initialize">时,似乎函数以字符串(?)的形式返回。我试过了 eval(jQuery.prettyPhoto.initialize),并 F=new Function(jQuery.prettyPhoto.initialize);return(F());没有成功。

有人有想法吗?

1 个答案:

答案 0 :(得分:0)

我相信你的函数永远不会被调用。尝试包括&#39;()&#39;就这样:

<body onload="jQuery.prettyPhoto.initialize()">
相关问题