开发者

Creating a jquery dialog as an API

开发者 https://www.devze.com 2023-03-10 17:02 出处:网络
In my current application I am using jquery UI dialog at many places , so I am planning to create a method like

In my current application I am using jquery UI dialog at many places , so I am planning to create a method like

 var MYAPP = MYAPP || {};

   MYAPP.overlay = (function(){
       $("#id").dialog();

   }());

This is my idea but now the problem is my overlay is used for different purp开发者_StackOverflow社区ose like overlay form, video, confirmation message etc. Is there a way I can have all the option inside my API . so I just have to call MYAPP.overlay("video",some other parameter) and it will create the overlay without have to repeat the code again and again....any idea or suggestion will be appreciated..


I'm not sure what you are trying to accomplish with the immediately executing anonymous function, but you can do something like this:

MYAPP.overlay = function MYAPP$overlay(id, paramsObj) {
    // do something based on element type, id, or params obj here.
    $(id).dialog();

    // possibly return something if needed.
};


yes you can use parameters. here is a very generic way of doing it:

MYAPP.overlay = (function(){
        // complex code ....

        return function(arg) {
          alert(arg);
        }
     })();

// example
MYAPP.overlay('hello');

will alert hello

0

精彩评论

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