开发者

jQuery removing repetition in multiple Colorbox method calls

I needed some advice on how i can remove the repetition in my current project.

I have several colorbox dialog windows which are of the same size, have the same transition etc when they are called but perform different jquery manipulations, AJAX calls etc when they have completed loading.

Currently they are all in their own seperate declarations but i would like to move them into one as it is becoming unmanageable. I assume that the best way to deal with this is to create a function and pass parameters to said function for the defaults such as dimensions and 开发者_运维知识库transitions but i was not sure how to deal with the the more unique aspects when they are needed.

For example if i have two colorbox methods like so:

$(".pricing > tbody > tr > th > .price_report > a").colorbox({
    transition: "elastic",
    innerWidth: "800px",
    innerHeight: "800px",
    opacity: "0.5",
    onComplete:function(){ 

        $("myDiv").addClass("dialogLoaded").append('<span class="mySpan" />');

        }
});

and:

$(".wrap .widget .dialog_call").colorbox({
    transition: "elastic",
    innerWidth: "800px",
    innerHeight: "800px",
    opacity: "0.5",
    onComplete:function(){ 
        $.ajax({
          url: "test.html",
          cache: false,
          success: function(html){
            $("#results").append(html);
          }
        });
    }
});

So this can obviously be turned into a function but how would i pass the differences in the code to the onComplete event when needed?


Answered here:

Allowing javascript function to accept any number of arguments

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜