티스토리 뷰

/** 
 * 트위터 bootstrap js 패턴
 */
;(function($){

    var Calculator = function( el, options ) {
        this.$el = $(el);
        this.options = $.extend({} , $.fn.calculator.defaults, options);


    }

    Calculator.prototype = {
        constructor : Calculator

        , show : function(){
            console.log( this.options );
        }
    }

    $.fn.calculator = function ( option ) {
        return this.each(function(){
            var $this = $(this)
                , data = $this.data('calculator')
                , options = typeof option == 'object' && option // objects 일경우만

                if ( !data ) {
                    $this.data('calculator',( data = new Calculator( this, options ) ) );
                }

                if ( typeof option == 'string' ) {
                    data[option](); // 바로 해당 메서드를 실행
                }
        });
    }

    $.fn.calculator.Constructor = Calculator;

    $.fn.calculator.defaults = {
        'monitor'  : '.calc-screen',
        'buttons'  : '.calc-button' ,
        'sign_monitor' : '.sign-monitor'
    }

})( window.jQuery );


'웹개발 > Javascript' 카테고리의 다른 글

자바스크립트 키코드.  (0) 2012.03.09
javascript constructor 속성  (0) 2012.03.09
Twitter jQuery  (0) 2012.03.05
천단위 콤마 찍기  (0) 2012.02.14
Javascript Match $1 표현하기  (0) 2012.02.10
댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함