如何在jQuery插件中公开公共函数的所有属性

时间:2012-04-20 08:45:58

标签: jquery jquery-plugins

这是我的插件(试图允许设计人员轻松地将Flowplayer添加到我的网站)

 (function ($) {
     $.fn.irvVideoPlayer = function (options) {

         var settings = $.extend({
             'fpKey': '#@12345678905',
             'videoPath': 'path-to-my-video.mp4',
             'seekTo': 1,
             'autoPlay': true,
             'src': "/flash/flowplayer/flowplayer.commercial-3.2.9.swf"
         }, options);

         return this.each(function () {

             var $this = $(this);

             var firstTimeVisitor, playedOnce;

             firstTimeVisitor = function () {
                 if ($.cookie("videoplayerhome") == null) {
                     firstTimeVisitor = null;
                     $.cookie("videoplayerhome", "Video Loaded", {
                         path: "/",
                         expires: 30
                     })
                 } else {
                     this.seek(settings.seekTo).pause();
                     $.cookie("playedOnce", "User Pressed Play");
                 }
             }

             playedOnce = function () {
                 if ($.cookie("playedOnce") == null) {
                     playedOnce = null
                 } else {
                     $f().seek(0);
                     $.cookie("playedOnce", null);
                 }
             };

             fpPlayer = {
                 src: settings.src,
                 wmode: "transparent"
             };

             this.fpConfig = {
                     key: settings.fpKey,
                     plugins: {
                         controls: {
                             autoHide: false,
                             background: "#272D6A",
                             backgroundGradient: "none"
                         },
                         lighttpd: {
                             url: "/flash/flowplayer/flowplayer.pseudostreaming-3.2.9.swf"
                         }
                     },
                     clip: {
                         provider: "lighttpd",
                         autoBuffering: true,
                         ipadUrl:  settings.videoPath + "/playlist.m3u8",
                         autoPlay: settings.autoPlay
                     },
                     onStart: firstTimeVisitor,
                     onResume: playedOnce,
                     playlist: [{
                         url: settings.videoPath
                     }],
                     canvas: {
                         background: "#000000",
                         backgroundGradient: "none"
                     }
                 }


             $(this, fpPlayer, this.fpConfigSetup()).ipad();

         });

         return this.initialize();

     };
 })(jQuery);

我能够像这样使用这个插件:

$('#homePageVideo').irvVideoPlayer({
seekTo: 10
});

很棒!,但有时我需要访问fpConfig中设置的所有属性,并希望能够做到这样的事情:

fpConfig.plugins.controls.all = false;
fpConfig.plugins.controls.play = true;
fpConfig.plugins.controls.scrubber = true;
fpConfig.canvas.background = "#444444"
// etc....

0 个答案:

没有答案