프로그램/script

jQuery plugin 개발용 템플릿

mulderu 2015. 9. 24. 12:43

jQuery plugin개발을 위한 손쉬운 방법이 있어 공유 합니다.

아래와 같은 형태로 작업을 하면 기존의 방법보다 훨씬 편한것 같습니다.


 아래 부분이 키포인트 같아서 발춰해봅니다.

$.fn[pluginName] = function(options) {
        // Iterate through each DOM element and return it
        return this.each(function() {
            // prevent multiple instantiations
            if (!$.data(this, 'plugin_' + pluginName)) {
                $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
            }
        });
    };


Plugin의 접근을 $(p1).data('plugin_PluginTest') 형식으로 할 수 있도록 하고 있습니다. 좋은 아이디어 !



ref :  https://github.com/geetarista/jquery-plugin-template/blob/master/jquery.plugin-template.js