Home > Web Front-end > JS Tutorial > JCALCULATOR

JCALCULATOR

Susan Sarandon
Release: 2025-01-01 10:06:11
Original
533 people have browsed it

JCALCULATOR

(function(window, $, undefined) {
(function() {
var VERSION = '1.0',
pluginName = 'calculator',
autoInitSelector = '.calculator-here',
$body, $calculatorsContainer,
containerBuilt = false,
baseTemplate = ''
'

'
''
''
'',
defaults = {
            displayMode: 'extended',
            showIcon: false,
            icon: 'fa-calculator',
            position: 'bottom left',
            textAlignment: 'rtl',
            theme: 'material',
            buttonStyle: null,
            showMethod: 'click',
            showEvent: 'focus',
            offset: 12,
            keyboardNav: true,
            clearKey: null,
            plsmnsKey: null,
            percKey: null,
            readOnly: true,

            classes: '',
            inline: false,
            autoClose: false,
            // calcID: null,

            // events
            onInput: function() {},
            onResult: function() {},
            onSelect: '',
            onShow: '',
            onHide: '',
        },

        calculator;

    var Calculator = function(el, options) {
        this.el = el;
        this.$el = $(el);

        this.opts = $.extend(true, {}, defaults, options, this.$el.data());

        if ($body === undefined) {
            $body = $('body');
        }

        if (this.el.nodeName == 'INPUT') {
            this.elIsInput = true;
        }

        this.inited = false;
        this.visible = false;
        this.silent = false; // Need to prevent unnecessary rendering

        this.keys = [];



        // this._createShortCuts();
        this.init()
    };

    calculator = Calculator;

    calculator.prototype = {
        VERSION: VERSION,
        init: function() {


            if (!containerBuilt && !this.opts.inline && this.elIsInput) {
                this._buildCalculatorsContainer();
            }
            this._buildBaseHtml();

            if (this.elIsInput) {
                if (!this.opts.inline) {
                    // Set extra classes for proper transitions
                    this._setPositionClasses(this.opts.position);
                    this._bindEvents()
                }

                this.$calculator.on('mousedown', this._onMouseDownCalculator.bind(this));
                this.$calculator.on('mouseup', this._onMouseUpCalculator.bind(this));
            }




            if (this.opts.classes) {
                this.$calculator.addClass(this.opts.classes)
            }

            if (this.opts.keyboardNav) {
                this._bindKeyboardEvents();
            }
            // this.opts.calcID = 'jCalc_'   Math.floor(Math.random() * 10000000   10000);
            new $.fn.calculator.Body(this, '', this.opts);

            this.inited = true;
        },

        /*
        Keyboard binding

         */

        _bindKeyboardEvents: function() {
            this.$el.on('keydown.adp', this._onKeyDown.bind(this));
            this.$el.on('keyup.adp', this._onKeyUp.bind(this));
            this.$el.on('hotKey.adp', this._onHotKey.bind(this));
        },


        _onKeyDown: function(e) {
            var code = e.which;
            this._registerKey(code);

            if ((code >= 96 && code 
<p>})(window, jQuery);</p>


          

            
        
Copy after login

The above is the detailed content of JCALCULATOR. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template