Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending the plugin #45

Closed
keebeegee opened this issue Aug 6, 2016 · 1 comment
Closed

Extending the plugin #45

keebeegee opened this issue Aug 6, 2016 · 1 comment

Comments

@keebeegee
Copy link

keebeegee commented Aug 6, 2016

Hi dabeng,
I'd like to add new factory functions without doing a fork. (Will be more than happy to share them with the community).
Found this approach:
http://stackoverflow.com/questions/2050985/best-way-to-extend-a-jquery-plugin/4414356#4414356

(function($) {
/**
 *  Namespace: the namespace the plugin is located under
 *  pluginName: the name of the plugin
 */
    var extensionMethods = {
        /*
         * retrieve the id of the element
         * this is some context within the existing plugin
         */
        showId: function(){
            return this.element[0].id;
        }
    };

    $.extend(true, $[ Namespace ][ pluginName ].prototype, extensionMethods);


})(jQuery);

To make it work I would need to provide the 'namespace' and 'pluginName'. Looks to me that these concepts are used ambiguously in literature. Tried several combinations to get the extension pattern to work, without success.

Any thoughts on this?

kbg

@keebeegee
Copy link
Author

Never mind! A simply

(function($) {

        $.extend($.fn.orgchart, {
            getHierarchyCust1: function(){
                console.log('found custom method getHierarchyCust');
            }
        });


})(jQuery);

does it for me at this point
tx ./kbg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant