IT/Script

jquery plugin

상짱 2020. 6. 22. 18:09
반응형

- 요 몇일 성과없는 개발이라고 해야 되나..

- 나름 공부도 했지만, 명확히 이것이 무엇이다 라고 할 수준까지는 못한 것 같다.

- 일정의 압박과 함께...

- 그래도 jquery plugin 쪽에 제일 기본이라고 되는 부분에 대해서는 나름대로 명확한 기준이 생긴것 같다.

 

- page tab 및 modal alert / confirm 창을 custom tag 나 jquery plugin 으로 개발을 하는 방법을 찾다가..

- plugin 쪽은 문외한이라.. 공부하다보니, 

- 제일 기본적인 개념 및 문법이라고 보이는 사이트(https://www.ostraining.com/blog/coding/custom-jquery-plugin/)라고 판단된다.

 

- https://www.ostraining.com/blog/coding/custom-jquery-plugin/

 

How to Create a Custom jQuery Plugin

jQuery is, in my humble opinion, the best Javascript library. Much of jQuery's popularity is due to the fact that it considerably reduces development time. Their slogan is "write less, do more", which is a great summary of jQuery's benefits. What make jQue

www.ostraining.com

 

- hello 라는 이름을 가진 plugin 생성

; // plugin 의 앞의 종결문자 없을 경우를 대비해서 작성
(function ( $ ) { // 영역지정 
 
    $.fn.hello = function( options ) { // hello 라는 plugin 이름
 
        // Default options
        var settings = $.extend({
            name: 'John Doe'
            , color: 'orange'
        }, options );
 
        // Apply options
        // this 는 호출하는 태그이다. ( 아래 <div id='here'> )
        // div tag 에 name 을 붙이고, 색상을 설정한다.
        return this.append('Hello ' + settings.name + '!').css({ color: settings.color });

    };
 
}( jQuery ));

 

- plugin 호출

<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="/jquery-hello.js"></script>
<script>
$( document ).ready(function() {
    $( '#here' ).hello({
    	name: 'Valentin Garcia'
        , color: 'green'
    });
});
</script>

<div id="here"></div>

 

- plugin 확장(?)

- 스크립트 패턴이라고 해야할까?  jquery module 패턴이라고 해야 할까?

- 검색결과 모듈 패턴은 계속 만들어지고 있으며, 아래 소스는 현재 가장 많이 사용한다는 패턴으로 파악된다.

;(function( $, window, document, undefined ){
	let pluginName = "pageTabs";
    let defaultOption = {}    
    function Plugin( element , options ){
    	this.element = element;
        this.settings = $.extend( {} , defaultOption , options );
        this.init();
    }
    
    $.extend( Plugin.prototype , {
    	init : function(){}
    });
    
    $.fn[pluginName] = function(options){
    	return this.each(function(){
        	if( !$.data( this, "Plugin_" + pluginName)){
            	$.data( this , "Plugin_" + pluginName , new Plugin( this, options));
			}
		});
    };
}( jQuery, window, document ));

 

반응형

'IT > Script' 카테고리의 다른 글

VSCode Terminal 에 node.js 환경경로 잡기  (0) 2024.04.30
vue-router 사용  (0) 2024.03.24
Vue 프로젝트 생성, 실행  (1) 2024.03.23
Illegal hex characters in escape (%) pattern  (0) 2020.03.10
jquery history 제어  (0) 2020.02.28
FullCalendar 중첩? 중복제거 addEventSource  (2) 2020.01.14
enter key code  (0) 2020.01.07
FullCalendar 한글설정  (0) 2020.01.03