Вход Регистрация
Файл: CloudBox-main/CloudBox/admin_assets/js/jquery.knob.js
Строк: 591
<?php
/*!jQuery Knob*/
/**
 * Downward compatible, touchable dial
 *
 * Version: 1.2.8
 * Requires: jQuery v1.7+
 *
 * Copyright (c) 2012 Anthony Terrien
 * Under MIT License (http://www.opensource.org/licenses/mit-license.php)
 *
 * Thanks to vor, eskimoblood, spiffistan, FabrizioC
 */
(function ($) {

    
/**
     * Kontrol library
     */
    
"use strict";

    
/**
     * Definition of globals and core
     */
    
var = {}, // kontrol
        
max Math.max,
        
min Math.min;

    
k.= {};
    
k.c.= $(document);
    
k.c.= function (e) {
        return 
e.originalEvent.touches.length 1;
    };

    
/**
     * Kontrol Object
     *
     * Definition of an abstract UI control
     *
     * Each concrete component must call this one.
     * <code>
     * k.o.call(this);
     * </code>
     */
    
k.= function () {
        var 
this;

        
this.null// array of options
        
this.$ = null// jQuery wrapped element
        
this.null// mixed HTMLInputElement or array of HTMLInputElement
        
this.null// deprecated 2D graphics context for 'pre-rendering'
        
this.null// value ; mixed array or integer
        
this.cv null// change value ; not commited value
        
this.0// canvas x position
        
this.0// canvas y position
        
this.0// canvas width
        
this.0// canvas height
        
this.$c null// jQuery canvas element
        
this.null// rendered canvas context
        
this.0// touches index
        
this.isInit false;
        
this.fgColor null// main color
        
this.pColor null// previous color
        
this.dH null// draw hook
        
this.cH null// change hook
        
this.eH null// cancel hook
        
this.rH null// release hook
        
this.scale 1// scale factor
        
this.relative false;
        
this.relativeWidth false;
        
this.relativeHeight false;
        
this.$div null// component div

        
this.run = function () {
            var 
cf = function (econf) {
                var 
k;
                for (
k in conf) {
                    
s.o[k] = conf[k];
                }
                
s._carve().init();
                
s._configure()
                    .
_draw();
            };

            if (
this.$.data('kontroled')) return;
            
this.$.data('kontroled'true);

            
this.extend();
            
this.= $.extend(
                {
                    
// Config
                    
minthis.$.data('min') !== undefined this.$.data('min') : 0,
                    
maxthis.$.data('max') !== undefined this.$.data('max') : 100,
                    
stoppertrue,
                    
readOnlythis.$.data('readonly') || (this.$.attr('readonly') === 'readonly'),

                    
// UI
                    
cursor: (this.$.data('cursor') === true && 30) ||
                        
this.$.data('cursor') || 0,
                    
thickness: (
                        
this.$.data('thickness') &&
                            
Math.max(Math.min(this.$.data('thickness'), 1), 0.01)
                        ) || 
0.35,
                    
lineCapthis.$.data('linecap') || 'butt',
                    
widththis.$.data('width') || 200,
                    
heightthis.$.data('height') || 200,
                    
displayInputthis.$.data('displayinput') == null || this.$.data('displayinput'),
                    
displayPreviousthis.$.data('displayprevious'),
                    
fgColorthis.$.data('fgcolor') || '#87CEEB',
                    
inputColorthis.$.data('inputcolor'),
                    
fontthis.$.data('font') || 'Arial',
                    
fontWeightthis.$.data('font-weight') || 'bold',
                    
inlinefalse,
                    
stepthis.$.data('step') || 1,
                    
rotationthis.$.data('rotation'),

                    
// Hooks
                    
drawnull// function () {}
                    
changenull// function (value) {}
                    
cancelnull// function () {}
                    
releasenull// function (value) {}

                    // Output formatting, allows to add unit: %, ms ...
                    
format: function (v) {
                        return 
v;
                    },
                    
parse: function (v) {
                        return 
parseFloat(v);
                    }
                }, 
this.o
            
);

            
// finalize options
            
this.o.flip this.o.rotation === 'anticlockwise' || this.o.rotation === 'acw';
            if (!
this.o.inputColor) {
                
this.o.inputColor this.o.fgColor;
            }

            
// routing value
            
if (this.$.is('fieldset')) {

                
// fieldset = array of integer
                
this.= {};
                
this.this.$.find('input');
                
this.i.each(function (k) {
                    var 
$this = $(this);
                    
s.i[k] = $this;
                    
s.v[k] = s.o.parse($this.val());

                    
$this.bind(
                        
'change blur'
                        
, function () {
                            var 
val = {};
                            
val[k] = $this.val();
                            
s.val(val);
                        }
                    );
                });
                
this.$.find('legend').remove();

            } else {

                
// input = integer
                
this.this.$;
                
this.this.o.parse(this.$.val());
                (
this.=== '') && (this.this.o.min);

                
this.$.bind(
                    
'change blur'
                    
, function () {
                        
s.val(s._validate(s.o.parse(s.$.val())));
                    }
                );

            }

            (!
this.o.displayInput) && this.$.hide();

            
// adds needed DOM elements (canvas, div)
            
this.$c = $(document.createElement('canvas')).attr({
                
widththis.o.width,
                
heightthis.o.height
            
});

            
// wraps all elements in a div
            // add to DOM before Canvas init is triggered
            
this.$div = $('<div style="'
                
+ (this.o.inline 'display:inline;' '')
                + 
'width:' this.o.width 'px;height:' this.o.height 'px;'
                
'"></div>');

            
this.$.wrap(this.$div).before(this.$c);
            
this.$div this.$.parent();

            if (
typeof G_vmlCanvasManager !== 'undefined') {
                
G_vmlCanvasManager.initElement(this.$c[0]);
            }

            
this.this.$c[0].getContext this.$c[0].getContext('2d') : null;

            if (!
this.c) {
                throw {
                    
name"CanvasNotSupportedException",
                    
message"Canvas not supported. Please use excanvas on IE8.0.",
                    
toString: function () {
                        return 
this.name ": " this.message
                    
}
                }
            }

            
// hdpi support
            
this.scale = (window.devicePixelRatio || 1) /
                (
                    
this.c.webkitBackingStorePixelRatio ||
                        
this.c.mozBackingStorePixelRatio ||
                        
this.c.msBackingStorePixelRatio ||
                        
this.c.oBackingStorePixelRatio ||
                        
this.c.backingStorePixelRatio || 1
                    
);

            
// detects relative width / height
            
this.relativeWidth = ((this.o.width !== 0) &&
                
this.o.width.indexOf('%'));
            
this.relativeHeight = ((this.o.height !== 0) &&
                
this.o.height.indexOf('%'));
            
this.relative = (this.relativeWidth || this.relativeHeight);

            
// computes size and carves the component
            
this._carve();

            
// prepares props for transaction
            
if (this.instanceof Object) {
                
this.cv = {};
                
this.copy(this.vthis.cv);
            } else {
                
this.cv this.v;
            }

            
// binds configure event
            
this.$
                .
bind("configure"cf)
                .
parent()
                .
bind("configure"cf);

            
// finalize init
            
this._listen()
                .
_configure()
                .
_xy()
                .
init();

            
this.isInit true;

            
this.$.val(this.o.format(this.v));
            
this._draw();

            return 
this;
        };

        
this._carve = function () {
            if (
this.relative) {
                var 
this.relativeWidth ?
                        
this.$div.parent().width() *
                            
parseInt(this.o.width) / 100 :
                        
this.$div.parent().width(),
                    
this.relativeHeight ?
                        
this.$div.parent().height() *
                            
parseInt(this.o.height) / 100 :
                        
this.$div.parent().height();

                
// apply relative
                
this.this.Math.min(wh);
            } else {
                
this.this.o.width;
                
this.this.o.height;
            }

            
// finalize div
            
this.$div.css({
                
'width'this.'px',
                
'height'this.'px'
            
});

            
// finalize canvas with computed width
            
this.$c.attr({
                
widththis.w,
                
heightthis.h
            
});

            
// scaling
            
if (this.scale !== 1) {
                
this.$c[0].width this.$c[0].width this.scale;
                
this.$c[0].height this.$c[0].height this.scale;
                
this.$c.width(this.w);
                
this.$c.height(this.h);
            }

            return 
this;
        }

        
this._draw = function () {

            
// canvas pre-rendering
            
var true;

            
s.s.c;

            
s.clear();

            
s.dH
            
&& (s.dH());

            (
!== false) && s.draw();

        };

        
this._touch = function (e) {

            var 
touchMove = function (e) {

                var 
s.xy2val(
                    
e.originalEvent.touches[s.t].pageX,
                    
e.originalEvent.touches[s.t].pageY
                
);

                if (
== s.cv) return;

                if (
s.cH && (s.cH(v) === false)) return;

                
s.change(s._validate(v));
                
s._draw();
            };

            
// get touches index
            
this.k.c.t(e);

            
// First touch
            
touchMove(e);

            
// Touch events listeners
            
k.c.d
                
.bind("touchmove.k"touchMove)
                .
bind(
                
"touchend.k"
                
, function () {
                    
k.c.d.unbind('touchmove.k touchend.k');
                    
s.val(s.cv);
                }
            );

            return 
this;
        };

        
this._mouse = function (e) {

            var 
mouseMove = function (e) {
                var 
s.xy2val(e.pageXe.pageY);

                if (
== s.cv) return;

                if (
s.cH && (s.cH(v) === false)) return;

                
s.change(s._validate(v));
                
s._draw();
            };

            
// First click
            
mouseMove(e);

            
// Mouse events listeners
            
k.c.d
                
.bind("mousemove.k"mouseMove)
                .
bind(
                
// Escape key cancel current change
                
"keyup.k"
                
, function (e) {
                    if (
e.keyCode === 27) {
                        
k.c.d.unbind("mouseup.k mousemove.k keyup.k");

                        if (
                            
s.eH
                                
&& (s.eH() === false)
                            ) return;

                        
s.cancel();
                    }
                }
            )
                .
bind(
                
"mouseup.k"
                
, function (e) {
                    
k.c.d.unbind('mousemove.k mouseup.k keyup.k');
                    
s.val(s.cv);
                }
            );

            return 
this;
        };

        
this._xy = function () {
            var 
this.$c.offset();
            
this.o.left;
            
this.o.top;
            return 
this;
        };

        
this._listen = function () {

            if (!
this.o.readOnly) {
                
this.$c
                    
.bind(
                    
"mousedown"
                    
, function (e) {
                        
e.preventDefault();
                        
s._xy()._mouse(e);
                    }
                )
                    .
bind(
                    
"touchstart"
                    
, function (e) {
                        
e.preventDefault();
                        
s._xy()._touch(e);
                    }
                );

                
this.listen();
            } else {
                
this.$.attr('readonly''readonly');
            }

            if (
this.relative) {
                $(
window).resize(function () {
                    
s._carve()
                        .
init();
                    
s._draw();
                });
            }

            return 
this;
        };

        
this._configure = function () {

            
// Hooks
            
if (this.o.drawthis.dH this.o.draw;
            if (
this.o.changethis.cH this.o.change;
            if (
this.o.cancelthis.eH this.o.cancel;
            if (
this.o.releasethis.rH this.o.release;

            if (
this.o.displayPrevious) {
                
this.pColor this.h2rgba(this.o.fgColor"0.4");
                
this.fgColor this.h2rgba(this.o.fgColor"0.6");
            } else {
                
this.fgColor this.o.fgColor;
            }

            return 
this;
        };

        
this._clear = function () {
            
this.$c[0].width this.$c[0].width;
        };

        
this._validate = function (v) {
            return (~~(((
0) ? -0.5 0.5) + (this.o.step))) * this.o.step;
        };

        
// Abstract methods
        
this.listen = function () {
        }; 
// on start, one time
        
this.extend = function () {
        }; 
// each time configure triggered
        
this.init = function () {
        }; 
// each time configure triggered
        
this.change = function (v) {
        }; 
// on change
        
this.val = function (v) {
        }; 
// on release
        
this.xy2val = function (xy) {
        }; 
//
        
this.draw = function () {
        }; 
// on change / on release
        
this.clear = function () {
            
this._clear();
        };

        
// Utils
        
this.h2rgba = function (ha) {
            var 
rgb;
            
h.substring(17)
            
rgb = [parseInt(h.substring(02), 16)
                , 
parseInt(h.substring(24), 16)
                , 
parseInt(h.substring(46), 16)];
            return 
"rgba(" rgb[0] + "," rgb[1] + "," rgb[2] + "," ")";
        };

        
this.copy = function (ft) {
            for (var 
i in f) {
                
t[i] = f[i];
            }
        };
    };


    
/**
     * k.Dial
     */
    
k.Dial = function () {
        
k.o.call(this);

        
this.startAngle null;
        
this.xy null;
        
this.radius null;
        
this.lineWidth null;
        
this.cursorExt null;
        
this.w2 null;
        
this.PI2 Math.PI;

        
this.extend = function () {
            
this.= $.extend(
                {
                    
bgColorthis.$.data('bgcolor') || '#EEEEEE',
                    
angleOffsetthis.$.data('angleoffset') || 0,
                    
angleArcthis.$.data('anglearc') || 360,
                    
inlinetrue
                
}, this.o
            
);
        };

        
this.val = function (vtriggerRelease) {
            if (
null != v) {

                
// reverse format
                
this.o.parse(v);

                if (
                    
triggerRelease !== false && (!= this.v) && this.rH &&
                        (
this.rH(v) === false)
                    ) return;

                
this.cv this.o.stopper max(min(vthis.o.max), this.o.min) : v;
                
this.this.cv;
                
this.$.val(this.o.format(this.v));
                
this._draw();
            } else {
                return 
this.v;
            }
        };

        
this.xy2val = function (xy) {
            var 
aret;

            
Math.atan2(
                
- (this.this.w2)
                , -(
this.this.w2)
            ) - 
this.angleOffset;

            if (
this.o.flip) {
                
this.angleArc this.PI2;
            }

            if (
this.angleArc != this.PI2 && (0) && (> -0.5)) {
                
// if isset angleArc option, set to min if .5 under min
                
0;
            } else if (
0) {
                
+= this.PI2;
            }

            
ret = ~~(0.5 + (* (this.o.max this.o.min) / this.angleArc))
                + 
this.o.min;

            
this.o.stopper && (ret max(min(retthis.o.max), this.o.min));

            return 
ret;
        };

        
this.listen = function () {
            
// bind MouseWheel
            
var thismwTimerStopmwTimerRelease,
                
mw = function (e) {
                    
e.preventDefault();

                    var 
ori e.originalEvent
                        
deltaX ori.detail || ori.wheelDeltaX
                        
deltaY ori.detail || ori.wheelDeltaY
                        
s._validate(s.o.parse(s.$.val()))
                            + (
deltaX || deltaY s.o.step deltaX || deltaY ? -s.o.step 0);

                    
max(min(vs.o.max), s.o.min);

                    
s.val(vfalse);

                    if (
s.rH) {
                        
// Handle mousewheel stop
                        
clearTimeout(mwTimerStop);
                        
mwTimerStop setTimeout(function () {
                            
s.rH(v);
                            
mwTimerStop null;
                        }, 
100);

                        
// Handle mousewheel releases
                        
if (!mwTimerRelease) {
                            
mwTimerRelease setTimeout(function () {
                                if (
mwTimerStops.rH(v);
                                
mwTimerRelease null;
                            }, 
200);
                        }
                    }
                }
                , 
kvalto1kv = {37: -s.o.step38s.o.step39s.o.step40: -s.o.step};

            
this.$
                .
bind(
                
"keydown"
                
, function (e) {
                    var 
kc e.keyCode;

                    
// numpad support
                    
if (kc >= 96 && kc <= 105) {
                        
kc e.keyCode kc 48;
                    }

                    
kval parseInt(String.fromCharCode(kc));

                    if (
isNaN(kval)) {

                        (
kc !== 13)         // enter
                            
&& (kc !== 8)       // bs
                            
&& (kc !== 9)       // tab
                            
&& (kc !== 189)     // -
                            
&& (kc !== 190 || s.$.val().match(/./))     // . only allowed once
                        
&& e.preventDefault();

                        
// arrows
                        
if ($.inArray(kc, [37383940]) > -1) {
                            
e.preventDefault();

                            var 
s.o.parse(s.$.val()) + kv[kc] * m;
                            
s.o.stopper && (max(min(vs.o.max), s.o.min));

                            
s.change(v);
                            
s._draw();

                            
// long time keydown speed-up
                            
to window.setTimeout(
                                function () {
                                    
*= 2;
                                }, 
30
                            
);
                        }
                    }
                }
            )
                .
bind(
                
"keyup"
                
, function (e) {
                    if (
isNaN(kval)) {
                        if (
to) {
                            
window.clearTimeout(to);
                            
to null;
                            
1;
                            
s.val(s.$.val());
                        }
                    } else {
                        
// kval postcond
                        
(s.$.val() > s.o.max && s.$.val(s.o.max))
                        || (
s.$.val() < s.o.min && s.$.val(s.o.min));
                    }

                }
            );

            
this.$c.bind("mousewheel DOMMouseScroll"mw);
            
this.$.bind("mousewheel DOMMouseScroll"mw)
        };

        
this.init = function () {

            if (
                
this.this.o.min
                    
|| this.this.o.max
                
this.this.o.min;

            
this.$.val(this.v);
            
this.w2 this.2;
            
this.cursorExt this.o.cursor 100;
            
this.xy this.w2 this.scale;
            
this.lineWidth this.xy this.o.thickness;
            
this.lineCap this.o.lineCap;
            
this.radius this.xy this.lineWidth 2;

            
this.o.angleOffset
            
&& (this.o.angleOffset isNaN(this.o.angleOffset) ? this.o.angleOffset);

            
this.o.angleArc
            
&& (this.o.angleArc isNaN(this.o.angleArc) ? this.PI2 this.o.angleArc);

            
// deg to rad
            
this.angleOffset this.o.angleOffset Math.PI 180;
            
this.angleArc this.o.angleArc Math.PI 180;

            
// compute start and end angles
            
this.startAngle 1.5 Math.PI this.angleOffset;
            
this.endAngle 1.5 Math.PI this.angleOffset this.angleArc;

            var 
max(
                
String(Math.abs(this.o.max)).length
                
String(Math.abs(this.o.min)).length
                
2
            
) + 2;

            
this.o.displayInput
                
&& this.i.css({
                
'width': ((this.4) >> 0) + 'px''height': ((this.3) >> 0) + 'px''position''absolute''vertical-align''middle''margin-top': ((this.3) >> 0) + 'px''margin-left''-' + ((this.2) >> 0) + 'px''border'0'background''none''font'this.o.fontWeight ' ' + ((this.s) >> 0) + 'px ' this.o.font'text-align''center''color'this.o.inputColor || this.o.fgColor'padding''0px''-webkit-appearance''none'
            
})
            || 
this.i.css({
                
'width''0px''visibility''hidden'
            
});
        };

        
this.change = function (v) {
            
this.cv v;
            
this.$.val(this.o.format(v));
        };

        
this.angle = function (v) {
            return (
this.o.min) * this.angleArc / (this.o.max this.o.min);
        };

        
this.arc = function (v) {
            var 
saea;
            
this.angle(v);
            if (
this.o.flip) {
                
sa this.endAngle 0.00001;
                
ea sa 0.00001;
            } else {
                
sa this.startAngle 0.00001;
                
ea sa 0.00001;
            }
            
this.o.cursor
                
&& (sa ea this.cursorExt)
            && (
ea ea this.cursorExt);
            return {
                
ssa,
                
eea,
                
dthis.o.flip && !this.o.cursor
            
};
        };

        
this.draw = function () {

            var 
this.g,                 // context
                
this.arc(this.cv)       // Arc
                
pa                        // Previous arc
                
1;

            
c.lineWidth this.lineWidth;
            
c.lineCap this.lineCap;
            
c.strokeStyle this.o.bgColor;
            
c.arc(this.xythis.xythis.radiusthis.endAngle 0.00001this.startAngle 0.00001true);
            
c.stroke();

            if (
this.o.displayPrevious) {
                
pa this.arc(this.v);
                
c.beginPath();
                
c.strokeStyle this.pColor;
                
c.arc(this.xythis.xythis.radiuspa.spa.epa.d);
                
c.stroke();
                
= (this.cv == this.v);
            }

            
c.beginPath();
            
c.strokeStyle this.o.fgColor this.fgColor;
            
c.arc(this.xythis.xythis.radiusa.sa.ea.d);
            
c.stroke();
        };

        
this.cancel = function () {
            
this.val(this.v);
        };
    };

    $.
fn.dial = $.fn.knob = function (o) {
        return 
this.each(
            function () {
                var 
= new k.Dial();
                
d.o;
                
d.$ = $(this);
                
d.run();
            }
        ).
parent();
    };

})(
jQuery);
?>
Онлайн: 3
Реклама