JQuery UI: How to call a widget function with its namespace

后端 未结 3 1567
半阙折子戏
半阙折子戏 2021-02-05 08:44

I created two custom JQuery UI widgets with same name but with different namespaces as given below: First widget:

$.widget(\'finance.dialog\',{....}); // this wa         


        
3条回答
  •  庸人自扰
    2021-02-05 09:25

    I think these two functions can help in such case. The first load a widget by pointing to the function created by JQ on the namespace object. The second use the name directly which I think will not be conflict as long as name is unique.

            /**
             * Apply the JQuery UI widget on an element with the given selector
             * @param {String} emSelector selector
             * @param {String} namespace widget namespace
             * @param {String} widgetName widget name
             * @param {Object}[options] options options object or null
             */
            jqUIWidgetByNSAndName:function(emSelector, namespace, widgetName, options) {
                var em = $(emSelector);
                $[namespace][widgetName].call(em, options, em);
            },
    
    
            /**
             * Apply the JQuery UI widget on an element with the given selector
             * @param {String} emSelector selector
             * @param {String} widgetName widget name
             * @param {Object}[options] options options object or null
             */
            jqUIWidgetByName:function (emSelector, widgetName, options) {
                var em = $(emSelector);
                $.fn[widgetName].call(em, options);
            }
    
            //Example1 - with namespace
            this.jqUIWidgetByNSAndName("#abc", "cg", "WebsiteGlass", options);
    
            //Example2 - without namespace
            this.jqUIWidgetByName("#abc",  "WebsiteGlass", options);

提交回复
热议问题