jquery-asPieProgress
Advanced tools
Comparing version 0.4.6 to 0.4.7
/** | ||
* jQuery asPieProgress v0.4.6 | ||
* jQuery asPieProgress v0.4.7 | ||
* https://github.com/amazingSurge/jquery-asPieProgress | ||
@@ -475,3 +475,3 @@ * | ||
var info = { | ||
version:'0.4.6' | ||
version:'0.4.7' | ||
}; | ||
@@ -478,0 +478,0 @@ |
/** | ||
* jQuery asPieProgress v0.4.6 | ||
* jQuery asPieProgress v0.4.7 | ||
* https://github.com/amazingSurge/jquery-asPieProgress | ||
@@ -9,5 +9,5 @@ * | ||
(function(global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
if (typeof define === 'function' && define.amd) { | ||
define(['jquery'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
} else if (typeof exports !== 'undefined') { | ||
factory(require('jquery')); | ||
@@ -21,657 +21,683 @@ } else { | ||
} | ||
})(this, | ||
})(this, function(_jquery) { | ||
'use strict'; | ||
function(_jquery) { | ||
'use strict'; | ||
var _jquery2 = _interopRequireDefault(_jquery); | ||
var _jquery2 = _interopRequireDefault(_jquery); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule | ||
? obj | ||
: { | ||
default: obj | ||
}; | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError('Cannot call a class as a function'); | ||
} | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? | ||
function(obj) { | ||
return typeof obj; | ||
var _createClass = (function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ('value' in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
: | ||
function(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
return function(Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
})(); | ||
if ("value" in descriptor) | ||
descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
var SvgElement = function SvgElement(tag, attrs) { | ||
'use strict'; | ||
return function(Constructor, protoProps, staticProps) { | ||
if (protoProps) | ||
defineProperties(Constructor.prototype, protoProps); | ||
var elem = document.createElementNS('http://www.w3.org/2000/svg', tag); | ||
if (staticProps) | ||
defineProperties(Constructor, staticProps); | ||
if (!attrs) { | ||
return elem; | ||
} | ||
return Constructor; | ||
}; | ||
}(); | ||
var SvgElement = function SvgElement(tag, attrs) { | ||
'use strict'; | ||
var elem = document.createElementNS('http://www.w3.org/2000/svg', tag); | ||
if (!attrs) { | ||
return elem; | ||
for (var key in attrs) { | ||
if (!Object.hasOwnProperty.call(attrs, key)) { | ||
continue; | ||
} | ||
for (var key in attrs) { | ||
elem.setAttribute(key, attrs[key]); | ||
} | ||
return elem; | ||
}; | ||
if (!Object.hasOwnProperty.call(attrs, key)) { | ||
continue; | ||
} | ||
if (!Date.now) { | ||
Date.now = function() { | ||
'use strict'; | ||
elem.setAttribute(key, attrs[key]); | ||
} | ||
return elem; | ||
return new Date().getTime(); | ||
}; | ||
} | ||
if (!Date.now) { | ||
Date.now = function() { | ||
'use strict'; | ||
var vendors = ['webkit', 'moz']; | ||
for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { | ||
var vp = vendors[i]; | ||
window.requestAnimationFrame = window[vp + 'RequestAnimationFrame']; | ||
window.cancelAnimationFrame = | ||
window[vp + 'CancelAnimationFrame'] || | ||
window[vp + 'CancelRequestAnimationFrame']; | ||
} | ||
return new Date().getTime(); | ||
} | ||
; | ||
} | ||
if ( | ||
/iP(ad|hone|od).*OS (6|7|8)/.test(window.navigator.userAgent) || // iOS6 is buggy | ||
!window.requestAnimationFrame || | ||
!window.cancelAnimationFrame | ||
) { | ||
var lastTime = 0; | ||
window.requestAnimationFrame = function(callback) { | ||
'use strict'; | ||
var vendors = ['webkit', 'moz']; | ||
var now = getTime(); | ||
var nextTime = Math.max(lastTime + 16, now); | ||
return setTimeout(function() { | ||
callback((lastTime = nextTime)); | ||
}, nextTime - now); | ||
}; | ||
window.cancelAnimationFrame = clearTimeout; | ||
} | ||
for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { | ||
var vp = vendors[i]; | ||
window.requestAnimationFrame = window[vp + 'RequestAnimationFrame']; | ||
window.cancelAnimationFrame = window[vp + 'CancelAnimationFrame'] || window[vp + 'CancelRequestAnimationFrame']; | ||
var getTime = function getTime() { | ||
if (typeof window.performance !== 'undefined' && window.performance.now) { | ||
return window.performance.now(); | ||
} | ||
return Date.now(); | ||
}; | ||
if (/iP(ad|hone|od).*OS (6|7|8)/.test(window.navigator.userAgent) // iOS6 is buggy | ||
|| !window.requestAnimationFrame || !window.cancelAnimationFrame) { | ||
(function() { | ||
var lastTime = 0; | ||
window.requestAnimationFrame = function(callback) { | ||
'use strict'; | ||
var isPercentage = function isPercentage(n) { | ||
'use strict'; | ||
var now = getTime(); | ||
var nextTime = Math.max(lastTime + 16, now); | ||
return typeof n === 'string' && n.indexOf('%') !== -1; | ||
}; | ||
return setTimeout( | ||
var svgSupported = | ||
'createElementNS' in document && new SvgElement('svg', {}).createSVGRect; | ||
function() { | ||
callback(lastTime = nextTime); | ||
} | ||
, nextTime - now); | ||
} | ||
; | ||
window.cancelAnimationFrame = clearTimeout; | ||
})(); | ||
} | ||
var easingBezier = function easingBezier(mX1, mY1, mX2, mY2) { | ||
'use strict'; | ||
var getTime = function getTime() { | ||
if (typeof window.performance !== 'undefined' && window.performance.now) { | ||
var a = function a(aA1, aA2) { | ||
return 1.0 - 3.0 * aA2 + 3.0 * aA1; | ||
}; | ||
return window.performance.now(); | ||
} | ||
var b = function b(aA1, aA2) { | ||
return 3.0 * aA2 - 6.0 * aA1; | ||
}; | ||
return Date.now(); | ||
var c = function c(aA1) { | ||
return 3.0 * aA1; | ||
}; | ||
var isPercentage = function isPercentage(n) { | ||
'use strict'; | ||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
var calcBezier = function calcBezier(aT, aA1, aA2) { | ||
return ((a(aA1, aA2) * aT + b(aA1, aA2)) * aT + c(aA1)) * aT; | ||
}; | ||
return typeof n === 'string' && n.indexOf('%') !== -1; | ||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
var getSlope = function getSlope(aT, aA1, aA2) { | ||
return 3.0 * a(aA1, aA2) * aT * aT + 2.0 * b(aA1, aA2) * aT + c(aA1); | ||
}; | ||
var svgSupported = 'createElementNS' in document && new SvgElement('svg', {}).createSVGRect; | ||
var easingBezier = function easingBezier(mX1, mY1, mX2, mY2) { | ||
'use strict'; | ||
var a = function a(aA1, aA2) { | ||
return 1.0 - 3.0 * aA2 + 3.0 * aA1; | ||
}; | ||
var b = function b(aA1, aA2) { | ||
return 3.0 * aA2 - 6.0 * aA1; | ||
}; | ||
var c = function c(aA1) { | ||
return 3.0 * aA1; | ||
}; | ||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
var calcBezier = function calcBezier(aT, aA1, aA2) { | ||
return ((a(aA1, aA2) * aT + b(aA1, aA2)) * aT + c(aA1)) * aT; | ||
}; | ||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
var getSlope = function getSlope(aT, aA1, aA2) { | ||
return 3.0 * a(aA1, aA2) * aT * aT + 2.0 * b(aA1, aA2) * aT + c(aA1); | ||
}; | ||
var getTForX = function getTForX(aX) { | ||
// Newton raphson iteration | ||
var aGuessT = aX; | ||
for (var _i = 0; _i < 4; ++_i) { | ||
var currentSlope = getSlope(aGuessT, mX1, mX2); | ||
if (currentSlope === 0.0) { | ||
return aGuessT; | ||
} | ||
var currentX = calcBezier(aGuessT, mX1, mX2) - aX; | ||
aGuessT -= currentX / currentSlope; | ||
var getTForX = function getTForX(aX) { | ||
// Newton raphson iteration | ||
var aGuessT = aX; | ||
for (var _i = 0; _i < 4; ++_i) { | ||
var currentSlope = getSlope(aGuessT, mX1, mX2); | ||
if (currentSlope === 0.0) { | ||
return aGuessT; | ||
} | ||
return aGuessT; | ||
}; | ||
if (mX1 === mY1 && mX2 === mY2) { | ||
return { | ||
css: 'linear', | ||
fn: function fn(aX) { | ||
return aX; | ||
} | ||
}; | ||
var currentX = calcBezier(aGuessT, mX1, mX2) - aX; | ||
aGuessT -= currentX / currentSlope; | ||
} | ||
return aGuessT; | ||
}; | ||
if (mX1 === mY1 && mX2 === mY2) { | ||
return { | ||
css: 'cubic-bezier(' + mX1 + ',' + mY1 + ',' + mX2 + ',' + mY2 + ')', | ||
css: 'linear', | ||
fn: function fn(aX) { | ||
return calcBezier(getTForX(aX), mY1, mY2); | ||
return aX; | ||
} | ||
}; | ||
}; | ||
} | ||
var EASING = { | ||
ease: easingBezier(0.25, 0.1, 0.25, 1.0), | ||
linear: easingBezier(0.00, 0.0, 1.00, 1.0), | ||
'ease-in': easingBezier(0.42, 0.0, 1.00, 1.0), | ||
'ease-out': easingBezier(0.00, 0.0, 0.58, 1.0), | ||
'ease-in-out': easingBezier(0.42, 0.0, 0.58, 1.0) | ||
return { | ||
css: 'cubic-bezier(' + mX1 + ',' + mY1 + ',' + mX2 + ',' + mY2 + ')', | ||
fn: function fn(aX) { | ||
return calcBezier(getTForX(aX), mY1, mY2); | ||
} | ||
}; | ||
}; | ||
var DEFAULTS = { | ||
namespace: 'asPieProgress', | ||
classes: { | ||
svg: 'pie_progress__svg', | ||
element: 'pie_progress', | ||
number: 'pie_progress__number', | ||
content: 'pie_progress__content' | ||
}, | ||
min: 0, | ||
max: 100, | ||
goal: 100, | ||
size: 160, | ||
speed: 15, // speed of 1/100 | ||
barcolor: '#ef1e25', | ||
barsize: '4', | ||
trackcolor: '#f2f2f2', | ||
fillcolor: 'none', | ||
easing: 'ease', | ||
numberCallback: function numberCallback(n) { | ||
'use strict'; | ||
var EASING = { | ||
ease: easingBezier(0.25, 0.1, 0.25, 1.0), | ||
linear: easingBezier(0.0, 0.0, 1.0, 1.0), | ||
'ease-in': easingBezier(0.42, 0.0, 1.0, 1.0), | ||
'ease-out': easingBezier(0.0, 0.0, 0.58, 1.0), | ||
'ease-in-out': easingBezier(0.42, 0.0, 0.58, 1.0) | ||
}; | ||
var percentage = Math.round(this.getPercentage(n)); | ||
var DEFAULTS = { | ||
namespace: 'asPieProgress', | ||
classes: { | ||
svg: 'pie_progress__svg', | ||
element: 'pie_progress', | ||
number: 'pie_progress__number', | ||
content: 'pie_progress__content' | ||
}, | ||
min: 0, | ||
max: 100, | ||
goal: 100, | ||
size: 160, | ||
speed: 15, // speed of 1/100 | ||
barcolor: '#ef1e25', | ||
barsize: '4', | ||
trackcolor: '#f2f2f2', | ||
fillcolor: 'none', | ||
easing: 'ease', | ||
numberCallback: function numberCallback(n) { | ||
'use strict'; | ||
return percentage + '%'; | ||
}, | ||
var percentage = Math.round(this.getPercentage(n)); | ||
return percentage + '%'; | ||
}, | ||
contentCallback: null | ||
}; | ||
contentCallback: null | ||
}; | ||
var NAMESPACE$1 = 'asPieProgress'; | ||
var NAMESPACE$1 = 'asPieProgress'; | ||
var asPieProgress = function() { | ||
function asPieProgress(element, options) { | ||
_classCallCheck(this, asPieProgress); | ||
var asPieProgress = (function() { | ||
function asPieProgress(element, options) { | ||
_classCallCheck(this, asPieProgress); | ||
this.element = element; | ||
this.$element = (0, _jquery2.default)(element); | ||
this.element = element; | ||
this.$element = (0, _jquery2.default)(element); | ||
this.options = _jquery2.default.extend(true, {}, DEFAULTS, options, this.$element.data()); | ||
this.namespace = this.options.namespace; | ||
this.options = _jquery2.default.extend( | ||
true, | ||
{}, | ||
DEFAULTS, | ||
options, | ||
this.$element.data() | ||
); | ||
this.namespace = this.options.namespace; | ||
this.classes = this.options.classes; | ||
this.easing = EASING[this.options.easing] || EASING.ease; | ||
this.$element.addClass(this.classes.element); | ||
this.classes = this.options.classes; | ||
this.easing = EASING[this.options.easing] || EASING.ease; | ||
this.$element.addClass(this.classes.element); | ||
this.min = this.$element.attr('aria-valuemin'); | ||
this.max = this.$element.attr('aria-valuemax'); | ||
this.min = this.min ? parseInt(this.min, 10) : this.options.min; | ||
this.max = this.max ? parseInt(this.max, 10) : this.options.max; | ||
this.first = this.$element.attr('aria-valuenow'); | ||
this.first = this.first ? parseInt(this.first, 10) : this.options.first ? this.options.first : this.min; | ||
this.now = this.first; | ||
this.goal = this.options.goal; | ||
this.min = this.$element.attr('aria-valuemin'); | ||
this.max = this.$element.attr('aria-valuemax'); | ||
this.min = this.min ? parseInt(this.min, 10) : this.options.min; | ||
this.max = this.max ? parseInt(this.max, 10) : this.options.max; | ||
this.first = this.$element.attr('aria-valuenow'); | ||
this.first = this.first | ||
? parseInt(this.first, 10) | ||
: this.options.first ? this.options.first : this.min; | ||
this.now = this.first; | ||
this.goal = this.options.goal; | ||
this._frameId = null; | ||
this._frameId = null; | ||
this.initialized = false; | ||
this.initialized = false; | ||
this._trigger('init'); | ||
this.init(); | ||
} | ||
this._trigger('init'); | ||
this.init(); | ||
} | ||
_createClass(asPieProgress, [{ | ||
key: 'init', | ||
value: function init() { | ||
this.$number = this.$element.find('.' + this.classes.number); | ||
this.$content = this.$element.find('.' + this.classes.content); | ||
_createClass( | ||
asPieProgress, | ||
[ | ||
{ | ||
key: 'init', | ||
value: function init() { | ||
this.$number = this.$element.find('.' + this.classes.number); | ||
this.$content = this.$element.find('.' + this.classes.content); | ||
this.size = this.options.size; | ||
this.width = this.size; | ||
this.height = this.size; | ||
this.size = this.options.size; | ||
this.width = this.size; | ||
this.height = this.size; | ||
this.prepare(); | ||
this.prepare(); | ||
this.initialized = true; | ||
this._trigger('ready'); | ||
} | ||
}, { | ||
key: 'prepare', | ||
value: function prepare() { | ||
if (!svgSupported) { | ||
return; | ||
this.initialized = true; | ||
this._trigger('ready'); | ||
} | ||
}, | ||
{ | ||
key: 'prepare', | ||
value: function prepare() { | ||
if (!svgSupported) { | ||
return; | ||
} | ||
this.svg = new SvgElement('svg', { | ||
version: '1.1', | ||
preserveAspectRatio: 'xMinYMin meet', | ||
viewBox: '0 0 ' + this.width + ' ' + this.height | ||
}); | ||
this.svg = new SvgElement('svg', { | ||
version: '1.1', | ||
preserveAspectRatio: 'xMinYMin meet', | ||
viewBox: '0 0 ' + this.width + ' ' + this.height | ||
}); | ||
this.buildTrack(); | ||
this.buildBar(); | ||
this.buildTrack(); | ||
this.buildBar(); | ||
(0, _jquery2.default)('<div class="' + this.classes.svg + '"></div>').append(this.svg).appendTo(this.$element); | ||
} | ||
}, { | ||
key: 'buildTrack', | ||
value: function buildTrack() { | ||
var height = this.size, | ||
width = this.size; | ||
(0, _jquery2.default)( | ||
'<div class="' + this.classes.svg + '"></div>' | ||
) | ||
.append(this.svg) | ||
.appendTo(this.$element); | ||
} | ||
}, | ||
{ | ||
key: 'buildTrack', | ||
value: function buildTrack() { | ||
var height = this.size, | ||
width = this.size; | ||
var cx = width / 2, | ||
cy = height / 2; | ||
var cx = width / 2, | ||
cy = height / 2; | ||
var barsize = this.options.barsize; | ||
var barsize = this.options.barsize; | ||
var ellipse = new SvgElement('ellipse', { | ||
rx: cx - barsize / 2, | ||
ry: cy - barsize / 2, | ||
cx: cx, | ||
cy: cy, | ||
stroke: this.options.trackcolor, | ||
fill: this.options.fillcolor, | ||
'stroke-width': barsize | ||
}); | ||
var ellipse = new SvgElement('ellipse', { | ||
rx: cx - barsize / 2, | ||
ry: cy - barsize / 2, | ||
cx: cx, | ||
cy: cy, | ||
stroke: this.options.trackcolor, | ||
fill: this.options.fillcolor, | ||
'stroke-width': barsize | ||
}); | ||
this.svg.appendChild(ellipse); | ||
} | ||
}, { | ||
key: 'buildBar', | ||
value: function buildBar() { | ||
if (!svgSupported) { | ||
return; | ||
this.svg.appendChild(ellipse); | ||
} | ||
}, | ||
{ | ||
key: 'buildBar', | ||
value: function buildBar() { | ||
if (!svgSupported) { | ||
return; | ||
} | ||
var path = new SvgElement('path', { | ||
fill: 'none', | ||
'stroke-width': this.options.barsize, | ||
stroke: this.options.barcolor | ||
}); | ||
this.bar = path; | ||
this.svg.appendChild(path); | ||
var path = new SvgElement('path', { | ||
fill: 'none', | ||
'stroke-width': this.options.barsize, | ||
stroke: this.options.barcolor | ||
}); | ||
this.bar = path; | ||
this.svg.appendChild(path); | ||
this._drawBar(this.first); | ||
this._updateBar(); | ||
} | ||
}, { | ||
key: '_drawBar', | ||
value: function _drawBar(n) { | ||
if (!svgSupported) { | ||
return; | ||
this._drawBar(this.first); | ||
this._updateBar(); | ||
} | ||
}, | ||
{ | ||
key: '_drawBar', | ||
value: function _drawBar(n) { | ||
if (!svgSupported) { | ||
return; | ||
} | ||
this.barGoal = n; | ||
var height = this.size, | ||
width = this.size; | ||
this.barGoal = n; | ||
var height = this.size, | ||
width = this.size; | ||
var cx = width / 2, | ||
cy = height / 2, | ||
startAngle = 0; | ||
var cx = width / 2, | ||
cy = height / 2, | ||
startAngle = 0; | ||
var barsize = this.options.barsize; | ||
var barsize = this.options.barsize; | ||
var r = Math.min(cx, cy) - barsize / 2; | ||
this.r = r; | ||
var percentage = this.getPercentage(n); | ||
var r = Math.min(cx, cy) - barsize / 2; | ||
this.r = r; | ||
var percentage = this.getPercentage(n); | ||
if (percentage === 100) { | ||
percentage -= 0.0001; | ||
} | ||
var endAngle = startAngle + percentage * Math.PI * 2 / 100; | ||
if (percentage === 100) { | ||
percentage -= 0.0001; | ||
} | ||
var endAngle = startAngle + percentage * Math.PI * 2 / 100; | ||
var x1 = cx + r * Math.sin(startAngle), | ||
x2 = cx + r * Math.sin(endAngle), | ||
y1 = cy - r * Math.cos(startAngle), | ||
y2 = cy - r * Math.cos(endAngle); | ||
var x1 = cx + r * Math.sin(startAngle), | ||
x2 = cx + r * Math.sin(endAngle), | ||
y1 = cy - r * Math.cos(startAngle), | ||
y2 = cy - r * Math.cos(endAngle); | ||
// This is a flag for angles larger than than a half circle | ||
// It is required by the SVG arc drawing component | ||
var big = 0; | ||
// This is a flag for angles larger than than a half circle | ||
// It is required by the SVG arc drawing component | ||
var big = 0; | ||
if (endAngle - startAngle > Math.PI) { | ||
big = 1; | ||
} | ||
if (endAngle - startAngle > Math.PI) { | ||
big = 1; | ||
} | ||
// This string holds the path details | ||
var d = | ||
'M' + | ||
x1 + | ||
',' + | ||
y1 + | ||
' A' + | ||
r + | ||
',' + | ||
r + | ||
' 0 ' + | ||
big + | ||
' 1 ' + | ||
x2 + | ||
',' + | ||
y2; | ||
// This string holds the path details | ||
var d = 'M' + x1 + ',' + y1 + ' A' + r + ',' + r + ' 0 ' + big + ' 1 ' + x2 + ',' + y2; | ||
this.bar.setAttribute('d', d); | ||
} | ||
}, { | ||
key: '_updateBar', | ||
value: function _updateBar() { | ||
if (!svgSupported) { | ||
return; | ||
this.bar.setAttribute('d', d); | ||
} | ||
var percenage = this.getPercentage(this.now); | ||
}, | ||
{ | ||
key: '_updateBar', | ||
value: function _updateBar() { | ||
if (!svgSupported) { | ||
return; | ||
} | ||
var percenage = this.getPercentage(this.now); | ||
var length = this.bar.getTotalLength(); | ||
var offset = length * (1 - percenage / this.getPercentage(this.barGoal)); | ||
var length = this.bar.getTotalLength(); | ||
var offset = | ||
length * (1 - percenage / this.getPercentage(this.barGoal)); | ||
this.bar.style.strokeDasharray = length + ' ' + length; | ||
this.bar.style.strokeDashoffset = offset; | ||
} | ||
}, { | ||
key: '_trigger', | ||
value: function _trigger(eventType) { | ||
for (var _len = arguments.length, params = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
params[_key - 1] = arguments[_key]; | ||
this.bar.style.strokeDasharray = length + ' ' + length; | ||
this.bar.style.strokeDashoffset = offset; | ||
} | ||
}, | ||
{ | ||
key: '_trigger', | ||
value: function _trigger(eventType) { | ||
for ( | ||
var _len = arguments.length, | ||
params = Array(_len > 1 ? _len - 1 : 0), | ||
_key = 1; | ||
_key < _len; | ||
_key++ | ||
) { | ||
params[_key - 1] = arguments[_key]; | ||
} | ||
var data = [this].concat(params); | ||
var data = [this].concat(params); | ||
// event | ||
this.$element.trigger(NAMESPACE$1 + '::' + eventType, data); | ||
// event | ||
this.$element.trigger(NAMESPACE$1 + '::' + eventType, data); | ||
// callback | ||
eventType = eventType.replace(/\b\w+\b/g, | ||
// callback | ||
eventType = eventType.replace(/\b\w+\b/g, function(word) { | ||
return word.substring(0, 1).toUpperCase() + word.substring(1); | ||
}); | ||
var onFunction = 'on' + eventType; | ||
function(word) { | ||
return word.substring(0, 1).toUpperCase() + word.substring(1); | ||
if (typeof this.options[onFunction] === 'function') { | ||
this.options[onFunction].apply(this, params); | ||
} | ||
); | ||
var onFunction = 'on' + eventType; | ||
if (typeof this.options[onFunction] === 'function') { | ||
this.options[onFunction].apply(this, params); | ||
} | ||
} | ||
}, { | ||
key: 'getPercentage', | ||
value: function getPercentage(n) { | ||
return 100 * (n - this.min) / (this.max - this.min); | ||
} | ||
}, { | ||
key: 'go', | ||
value: function go(goal) { | ||
var that = this; | ||
this._clear(); | ||
if (isPercentage(goal)) { | ||
goal = parseInt(goal.replace('%', ''), 10); | ||
goal = Math.round(this.min + goal / 100 * (this.max - this.min)); | ||
}, | ||
{ | ||
key: 'getPercentage', | ||
value: function getPercentage(n) { | ||
return 100 * (n - this.min) / (this.max - this.min); | ||
} | ||
}, | ||
{ | ||
key: 'go', | ||
value: function go(goal) { | ||
var that = this; | ||
this._clear(); | ||
if (typeof goal === 'undefined') { | ||
goal = this.goal; | ||
} | ||
if (isPercentage(goal)) { | ||
goal = parseInt(goal.replace('%', ''), 10); | ||
goal = Math.round(this.min + goal / 100 * (this.max - this.min)); | ||
} | ||
if (typeof goal === 'undefined') { | ||
goal = this.goal; | ||
} | ||
if (goal > this.max) { | ||
goal = this.max; | ||
} else if (goal < this.min) { | ||
goal = this.min; | ||
} | ||
if (goal > this.max) { | ||
goal = this.max; | ||
} else if (goal < this.min) { | ||
goal = this.min; | ||
} | ||
if (this.barGoal < goal) { | ||
this._drawBar(goal); | ||
} | ||
if (this.barGoal < goal) { | ||
this._drawBar(goal); | ||
} | ||
var start = that.now; | ||
var startTime = getTime(); | ||
var endTime = startTime + Math.abs(start - goal) * 100 * that.options.speed / (that.max - that.min); | ||
var start = that.now; | ||
var startTime = getTime(); | ||
var endTime = | ||
startTime + | ||
Math.abs(start - goal) * | ||
100 * | ||
that.options.speed / | ||
(that.max - that.min); | ||
var animation = function animation(time) { | ||
var next = void 0; | ||
var animation = function animation(time) { | ||
var next = void 0; | ||
if (time > endTime) { | ||
next = goal; | ||
} else { | ||
var distance = (time - startTime) / that.options.speed; | ||
next = Math.round(that.easing.fn(distance / 100) * (that.max - that.min)); | ||
if (goal > start) { | ||
next = start + next; | ||
if (next > goal) { | ||
next = goal; | ||
} | ||
if (time > endTime) { | ||
next = goal; | ||
} else { | ||
next = start - next; | ||
var distance = (time - startTime) / that.options.speed; | ||
next = Math.round( | ||
that.easing.fn(distance / 100) * (that.max - that.min) | ||
); | ||
if (next < goal) { | ||
next = goal; | ||
if (goal > start) { | ||
next = start + next; | ||
if (next > goal) { | ||
next = goal; | ||
} | ||
} else { | ||
next = start - next; | ||
if (next < goal) { | ||
next = goal; | ||
} | ||
} | ||
} | ||
} | ||
that._update(next); | ||
that._update(next); | ||
if (next === goal) { | ||
window.cancelAnimationFrame(that._frameId); | ||
that._frameId = null; | ||
if (next === goal) { | ||
window.cancelAnimationFrame(that._frameId); | ||
that._frameId = null; | ||
if (that.now === that.goal) { | ||
that._trigger('finish'); | ||
if (that.now === that.goal) { | ||
that._trigger('finish'); | ||
} | ||
} else { | ||
that._frameId = window.requestAnimationFrame(animation); | ||
} | ||
} else { | ||
that._frameId = window.requestAnimationFrame(animation); | ||
} | ||
}; | ||
}; | ||
that._frameId = window.requestAnimationFrame(animation); | ||
} | ||
}, { | ||
key: '_update', | ||
value: function _update(n) { | ||
this.now = n; | ||
that._frameId = window.requestAnimationFrame(animation); | ||
} | ||
}, | ||
{ | ||
key: '_update', | ||
value: function _update(n) { | ||
this.now = n; | ||
this._updateBar(); | ||
this._updateBar(); | ||
this.$element.attr('aria-valuenow', this.now); | ||
this.$element.attr('aria-valuenow', this.now); | ||
if ( | ||
this.$number.length > 0 && | ||
typeof this.options.numberCallback === 'function' | ||
) { | ||
this.$number.html( | ||
this.options.numberCallback.call(this, [this.now]) | ||
); | ||
} | ||
if ( | ||
this.$content.length > 0 && | ||
typeof this.options.contentCallback === 'function' | ||
) { | ||
this.$content.html( | ||
this.options.contentCallback.call(this, [this.now]) | ||
); | ||
} | ||
if (this.$number.length > 0 && typeof this.options.numberCallback === 'function') { | ||
this.$number.html(this.options.numberCallback.call(this, [this.now])); | ||
this._trigger('update', n); | ||
} | ||
if (this.$content.length > 0 && typeof this.options.contentCallback === 'function') { | ||
this.$content.html(this.options.contentCallback.call(this, [this.now])); | ||
}, | ||
{ | ||
key: '_clear', | ||
value: function _clear() { | ||
if (this._frameId) { | ||
window.cancelAnimationFrame(this._frameId); | ||
this._frameId = null; | ||
} | ||
} | ||
this._trigger('update', n); | ||
} | ||
}, { | ||
key: '_clear', | ||
value: function _clear() { | ||
if (this._frameId) { | ||
window.cancelAnimationFrame(this._frameId); | ||
this._frameId = null; | ||
}, | ||
{ | ||
key: 'get', | ||
value: function get() { | ||
return this.now; | ||
} | ||
}, | ||
{ | ||
key: 'start', | ||
value: function start() { | ||
this._clear(); | ||
this._trigger('start'); | ||
this.go(this.goal); | ||
} | ||
}, | ||
{ | ||
key: 'reset', | ||
value: function reset() { | ||
this._clear(); | ||
this._drawBar(this.first); | ||
this._update(this.first); | ||
this._trigger('reset'); | ||
} | ||
}, | ||
{ | ||
key: 'stop', | ||
value: function stop() { | ||
this._clear(); | ||
this._trigger('stop'); | ||
} | ||
}, | ||
{ | ||
key: 'finish', | ||
value: function finish() { | ||
this._clear(); | ||
this._update(this.goal); | ||
this._trigger('finish'); | ||
} | ||
}, | ||
{ | ||
key: 'destroy', | ||
value: function destroy() { | ||
this.$element.data(NAMESPACE$1, null); | ||
this._trigger('destroy'); | ||
} | ||
} | ||
}, { | ||
key: 'get', | ||
value: function get() { | ||
return this.now; | ||
} | ||
}, { | ||
key: 'start', | ||
value: function start() { | ||
this._clear(); | ||
this._trigger('start'); | ||
this.go(this.goal); | ||
} | ||
}, { | ||
key: 'reset', | ||
value: function reset() { | ||
this._clear(); | ||
this._drawBar(this.first); | ||
this._update(this.first); | ||
this._trigger('reset'); | ||
} | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
this._clear(); | ||
this._trigger('stop'); | ||
} | ||
}, { | ||
key: 'finish', | ||
value: function finish() { | ||
this._clear(); | ||
this._update(this.goal); | ||
this._trigger('finish'); | ||
} | ||
}, { | ||
key: 'destroy', | ||
value: function destroy() { | ||
this.$element.data(NAMESPACE$1, null); | ||
this._trigger('destroy'); | ||
} | ||
}], [{ | ||
key: 'registerEasing', | ||
value: function registerEasing(name) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
], | ||
[ | ||
{ | ||
key: 'registerEasing', | ||
value: function registerEasing(name) { | ||
for ( | ||
var _len2 = arguments.length, | ||
args = Array(_len2 > 1 ? _len2 - 1 : 0), | ||
_key2 = 1; | ||
_key2 < _len2; | ||
_key2++ | ||
) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
EASING[name] = easingBezier.apply(undefined, args); | ||
} | ||
EASING[name] = easingBezier.apply(undefined, args); | ||
}, | ||
{ | ||
key: 'getEasing', | ||
value: function getEasing(name) { | ||
return EASING[name]; | ||
} | ||
}, | ||
{ | ||
key: 'setDefaults', | ||
value: function setDefaults(options) { | ||
_jquery2.default.extend( | ||
true, | ||
DEFAULTS, | ||
_jquery2.default.isPlainObject(options) && options | ||
); | ||
} | ||
} | ||
}, { | ||
key: 'getEasing', | ||
value: function getEasing(name) { | ||
return EASING[name]; | ||
} | ||
}, { | ||
key: 'setDefaults', | ||
value: function setDefaults(options) { | ||
_jquery2.default.extend(true, DEFAULTS, _jquery2.default.isPlainObject(options) && options); | ||
} | ||
}]); | ||
] | ||
); | ||
return asPieProgress; | ||
}(); | ||
return asPieProgress; | ||
})(); | ||
var info = { | ||
version: '0.4.6' | ||
}; | ||
var info = { | ||
version: '0.4.7' | ||
}; | ||
var NAMESPACE = 'asPieProgress'; | ||
var OtherAsPieProgress = _jquery2.default.fn.asPieProgress; | ||
var NAMESPACE = 'asPieProgress'; | ||
var OtherAsPieProgress = _jquery2.default.fn.asPieProgress; | ||
var jQueryAsPieProgress = function jQueryAsPieProgress(options) { | ||
var _this = this; | ||
var jQueryAsPieProgress = function jQueryAsPieProgress(options) { | ||
for ( | ||
var _len3 = arguments.length, | ||
args = Array(_len3 > 1 ? _len3 - 1 : 0), | ||
_key3 = 1; | ||
_key3 < _len3; | ||
_key3++ | ||
) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
if (typeof options === 'string') { | ||
var method = options; | ||
if (typeof options === 'string') { | ||
var _ret2 = function() { | ||
var method = options; | ||
if (/^_/.test(method)) { | ||
return { | ||
v: false | ||
}; | ||
} else if (/^(get)/.test(method)) { | ||
var instance = _this.first().data(NAMESPACE); | ||
if (instance && typeof instance[method] === 'function') { | ||
return { | ||
v: instance[method].apply(instance, args) | ||
}; | ||
} | ||
} else { | ||
return { | ||
v: _this.each( | ||
function() { | ||
var instance = _jquery2.default.data(this, NAMESPACE); | ||
if (instance && typeof instance[method] === 'function') { | ||
instance[method].apply(instance, args); | ||
} | ||
} | ||
) | ||
}; | ||
if (/^_/.test(method)) { | ||
return false; | ||
} else if (/^(get)/.test(method)) { | ||
var instance = this.first().data(NAMESPACE); | ||
if (instance && typeof instance[method] === 'function') { | ||
return instance[method].apply(instance, args); | ||
} | ||
} else { | ||
return this.each(function() { | ||
var instance = _jquery2.default.data(this, NAMESPACE); | ||
if (instance && typeof instance[method] === 'function') { | ||
instance[method].apply(instance, args); | ||
} | ||
}(); | ||
}); | ||
} | ||
} | ||
if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") | ||
return _ret2.v; | ||
return this.each(function() { | ||
if (!(0, _jquery2.default)(this).data(NAMESPACE)) { | ||
(0, _jquery2.default)(this).data( | ||
NAMESPACE, | ||
new asPieProgress(this, options) | ||
); | ||
} | ||
}); | ||
}; | ||
return this.each( | ||
_jquery2.default.fn.asPieProgress = jQueryAsPieProgress; | ||
function() { | ||
if (!(0, _jquery2.default)(this).data(NAMESPACE)) { | ||
(0, _jquery2.default)(this).data(NAMESPACE, new asPieProgress(this, options)); | ||
} | ||
} | ||
); | ||
}; | ||
_jquery2.default.fn.asPieProgress = jQueryAsPieProgress; | ||
_jquery2.default.asPieProgress = _jquery2.default.extend({ | ||
_jquery2.default.asPieProgress = _jquery2.default.extend( | ||
{ | ||
setDefaults: asPieProgress.setDefaults, | ||
@@ -682,7 +708,7 @@ registerEasing: asPieProgress.registerEasing, | ||
_jquery2.default.fn.asPieProgress = OtherAsPieProgress; | ||
return jQueryAsPieProgress; | ||
} | ||
}, info); | ||
} | ||
); | ||
}, | ||
info | ||
); | ||
}); |
/** | ||
* jQuery asPieProgress v0.4.6 | ||
* jQuery asPieProgress v0.4.7 | ||
* https://github.com/amazingSurge/jquery-asPieProgress | ||
@@ -8,2 +8,3 @@ * | ||
*/ | ||
!function(t,e){if("function"==typeof define&&define.amd)define(["jquery"],e);else if("undefined"!=typeof exports)e(require("jquery"));else{var i={exports:{}};e(t.jQuery),t.jqueryAsPieProgressEs=i.exports}}(this,function(t){"use strict";function e(t){return t&&t.__esModule?t:{default:t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var n=e(t),s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),a=function(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);if(!e)return i;for(var n in e)Object.hasOwnProperty.call(e,n)&&i.setAttribute(n,e[n]);return i};Date.now||(Date.now=function(){return(new Date).getTime()});for(var o=["webkit","moz"],u=0;u<o.length&&!window.requestAnimationFrame;++u){var h=o[u];window.requestAnimationFrame=window[h+"RequestAnimationFrame"],window.cancelAnimationFrame=window[h+"CancelAnimationFrame"]||window[h+"CancelRequestAnimationFrame"]}!/iP(ad|hone|od).*OS (6|7|8)/.test(window.navigator.userAgent)&&window.requestAnimationFrame&&window.cancelAnimationFrame||!function(){var t=0;window.requestAnimationFrame=function(e){var i=l(),n=Math.max(t+16,i);return setTimeout(function(){e(t=n)},n-i)},window.cancelAnimationFrame=clearTimeout}();var l=function(){return"undefined"!=typeof window.performance&&window.performance.now?window.performance.now():Date.now()},f=function(t){return"string"==typeof t&&t.indexOf("%")!==-1},c="createElementNS"in document&&new a("svg",{}).createSVGRect,m=function(t,e,i,n){var s=function(t,e){return 1-3*e+3*t},r=function(t,e){return 3*e-6*t},a=function(t){return 3*t},o=function(t,e,i){return((s(e,i)*t+r(e,i))*t+a(e))*t},u=function(t,e,i){return 3*s(e,i)*t*t+2*r(e,i)*t+a(e)},h=function(e){for(var n=e,s=0;s<4;++s){var r=u(n,t,i);if(0===r)return n;var a=o(n,t,i)-e;n-=a/r}return n};return t===e&&i===n?{css:"linear",fn:function(t){return t}}:{css:"cubic-bezier("+t+","+e+","+i+","+n+")",fn:function(t){return o(h(t),e,n)}}},d={ease:m(.25,.1,.25,1),linear:m(0,0,1,1),"ease-in":m(.42,0,1,1),"ease-out":m(0,0,.58,1),"ease-in-out":m(.42,0,.58,1)},p={namespace:"asPieProgress",classes:{svg:"pie_progress__svg",element:"pie_progress",number:"pie_progress__number",content:"pie_progress__content"},min:0,max:100,goal:100,size:160,speed:15,barcolor:"#ef1e25",barsize:"4",trackcolor:"#f2f2f2",fillcolor:"none",easing:"ease",numberCallback:function(t){var e=Math.round(this.getPercentage(t));return e+"%"},contentCallback:null},g="asPieProgress",v=function(){function t(e,s){i(this,t),this.element=e,this.$element=(0,n.default)(e),this.options=n.default.extend(!0,{},p,s,this.$element.data()),this.namespace=this.options.namespace,this.classes=this.options.classes,this.easing=d[this.options.easing]||d.ease,this.$element.addClass(this.classes.element),this.min=this.$element.attr("aria-valuemin"),this.max=this.$element.attr("aria-valuemax"),this.min=this.min?parseInt(this.min,10):this.options.min,this.max=this.max?parseInt(this.max,10):this.options.max,this.first=this.$element.attr("aria-valuenow"),this.first=this.first?parseInt(this.first,10):this.options.first?this.options.first:this.min,this.now=this.first,this.goal=this.options.goal,this._frameId=null,this.initialized=!1,this._trigger("init"),this.init()}return r(t,[{key:"init",value:function(){this.$number=this.$element.find("."+this.classes.number),this.$content=this.$element.find("."+this.classes.content),this.size=this.options.size,this.width=this.size,this.height=this.size,this.prepare(),this.initialized=!0,this._trigger("ready")}},{key:"prepare",value:function(){c&&(this.svg=new a("svg",{version:"1.1",preserveAspectRatio:"xMinYMin meet",viewBox:"0 0 "+this.width+" "+this.height}),this.buildTrack(),this.buildBar(),(0,n.default)('<div class="'+this.classes.svg+'"></div>').append(this.svg).appendTo(this.$element))}},{key:"buildTrack",value:function(){var t=this.size,e=this.size,i=e/2,n=t/2,s=this.options.barsize,r=new a("ellipse",{rx:i-s/2,ry:n-s/2,cx:i,cy:n,stroke:this.options.trackcolor,fill:this.options.fillcolor,"stroke-width":s});this.svg.appendChild(r)}},{key:"buildBar",value:function(){if(c){var t=new a("path",{fill:"none","stroke-width":this.options.barsize,stroke:this.options.barcolor});this.bar=t,this.svg.appendChild(t),this._drawBar(this.first),this._updateBar()}}},{key:"_drawBar",value:function(t){if(c){this.barGoal=t;var e=this.size,i=this.size,n=i/2,s=e/2,r=0,a=this.options.barsize,o=Math.min(n,s)-a/2;this.r=o;var u=this.getPercentage(t);100===u&&(u-=1e-4);var h=r+u*Math.PI*2/100,l=n+o*Math.sin(r),f=n+o*Math.sin(h),m=s-o*Math.cos(r),d=s-o*Math.cos(h),p=0;h-r>Math.PI&&(p=1);var g="M"+l+","+m+" A"+o+","+o+" 0 "+p+" 1 "+f+","+d;this.bar.setAttribute("d",g)}}},{key:"_updateBar",value:function(){if(c){var t=this.getPercentage(this.now),e=this.bar.getTotalLength(),i=e*(1-t/this.getPercentage(this.barGoal));this.bar.style.strokeDasharray=e+" "+e,this.bar.style.strokeDashoffset=i}}},{key:"_trigger",value:function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),n=1;n<e;n++)i[n-1]=arguments[n];var s=[this].concat(i);this.$element.trigger(g+"::"+t,s),t=t.replace(/\b\w+\b/g,function(t){return t.substring(0,1).toUpperCase()+t.substring(1)});var r="on"+t;"function"==typeof this.options[r]&&this.options[r].apply(this,i)}},{key:"getPercentage",value:function(t){return 100*(t-this.min)/(this.max-this.min)}},{key:"go",value:function(t){var e=this;this._clear(),f(t)&&(t=parseInt(t.replace("%",""),10),t=Math.round(this.min+t/100*(this.max-this.min))),"undefined"==typeof t&&(t=this.goal),t>this.max?t=this.max:t<this.min&&(t=this.min),this.barGoal<t&&this._drawBar(t);var i=e.now,n=l(),s=n+100*Math.abs(i-t)*e.options.speed/(e.max-e.min),r=function r(a){var o=void 0;if(a>s)o=t;else{var u=(a-n)/e.options.speed;o=Math.round(e.easing.fn(u/100)*(e.max-e.min)),t>i?(o=i+o,o>t&&(o=t)):(o=i-o,o<t&&(o=t))}e._update(o),o===t?(window.cancelAnimationFrame(e._frameId),e._frameId=null,e.now===e.goal&&e._trigger("finish")):e._frameId=window.requestAnimationFrame(r)};e._frameId=window.requestAnimationFrame(r)}},{key:"_update",value:function(t){this.now=t,this._updateBar(),this.$element.attr("aria-valuenow",this.now),this.$number.length>0&&"function"==typeof this.options.numberCallback&&this.$number.html(this.options.numberCallback.call(this,[this.now])),this.$content.length>0&&"function"==typeof this.options.contentCallback&&this.$content.html(this.options.contentCallback.call(this,[this.now])),this._trigger("update",t)}},{key:"_clear",value:function(){this._frameId&&(window.cancelAnimationFrame(this._frameId),this._frameId=null)}},{key:"get",value:function(){return this.now}},{key:"start",value:function(){this._clear(),this._trigger("start"),this.go(this.goal)}},{key:"reset",value:function(){this._clear(),this._drawBar(this.first),this._update(this.first),this._trigger("reset")}},{key:"stop",value:function(){this._clear(),this._trigger("stop")}},{key:"finish",value:function(){this._clear(),this._update(this.goal),this._trigger("finish")}},{key:"destroy",value:function(){this.$element.data(g,null),this._trigger("destroy")}}],[{key:"registerEasing",value:function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),n=1;n<e;n++)i[n-1]=arguments[n];d[t]=m.apply(void 0,i)}},{key:"getEasing",value:function(t){return d[t]}},{key:"setDefaults",value:function(t){n.default.extend(!0,p,n.default.isPlainObject(t)&&t)}}]),t}(),w={version:"0.4.6"},y="asPieProgress",b=n.default.fn.asPieProgress,_=function(t){for(var e=this,i=arguments.length,r=Array(i>1?i-1:0),a=1;a<i;a++)r[a-1]=arguments[a];if("string"==typeof t){var o=function(){var i=t;if(/^_/.test(i))return{v:!1};if(!/^(get)/.test(i))return{v:e.each(function(){var t=n.default.data(this,y);t&&"function"==typeof t[i]&&t[i].apply(t,r)})};var s=e.first().data(y);return s&&"function"==typeof s[i]?{v:s[i].apply(s,r)}:void 0}();if("object"===("undefined"==typeof o?"undefined":s(o)))return o.v}return this.each(function(){(0,n.default)(this).data(y)||(0,n.default)(this).data(y,new v(this,t))})};n.default.fn.asPieProgress=_,n.default.asPieProgress=n.default.extend({setDefaults:v.setDefaults,registerEasing:v.registerEasing,getEasing:v.getEasing,noConflict:function(){return n.default.fn.asPieProgress=b,_}},w)}); | ||
!function(t,e){if("function"==typeof define&&define.amd)define(["jquery"],e);else if("undefined"!=typeof exports)e(require("jquery"));else{var i={exports:{}};e(t.jQuery),t.jqueryAsPieProgressEs=i.exports}}(this,function(t){"use strict";function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(t){return t&&t.__esModule?t:{default:t}}(t),n=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),s=function(t,e){var i=document.createElementNS("http://www.w3.org/2000/svg",t);if(!e)return i;for(var n in e)Object.hasOwnProperty.call(e,n)&&i.setAttribute(n,e[n]);return i};Date.now||(Date.now=function(){return(new Date).getTime()});for(var a=["webkit","moz"],r=0;r<a.length&&!window.requestAnimationFrame;++r){var o=a[r];window.requestAnimationFrame=window[o+"RequestAnimationFrame"],window.cancelAnimationFrame=window[o+"CancelAnimationFrame"]||window[o+"CancelRequestAnimationFrame"]}if(/iP(ad|hone|od).*OS (6|7|8)/.test(window.navigator.userAgent)||!window.requestAnimationFrame||!window.cancelAnimationFrame){var h=0;window.requestAnimationFrame=function(t){var e=u(),i=Math.max(h+16,e);return setTimeout(function(){t(h=i)},i-e)},window.cancelAnimationFrame=clearTimeout}var u=function(){return void 0!==window.performance&&window.performance.now?window.performance.now():Date.now()},l=function(t){return"string"==typeof t&&-1!==t.indexOf("%")},f="createElementNS"in document&&new s("svg",{}).createSVGRect,c=function(t,e,i,n){var s=function(t,e){return 1-3*e+3*t},a=function(t,e){return 3*e-6*t},r=function(t){return 3*t},o=function(t,e,i){return((s(e,i)*t+a(e,i))*t+r(e))*t},h=function(t,e,i){return 3*s(e,i)*t*t+2*a(e,i)*t+r(e)},u=function(e){for(var n=e,s=0;s<4;++s){var a=h(n,t,i);if(0===a)return n;n-=(o(n,t,i)-e)/a}return n};return t===e&&i===n?{css:"linear",fn:function(t){return t}}:{css:"cubic-bezier("+t+","+e+","+i+","+n+")",fn:function(t){return o(u(t),e,n)}}},m={ease:c(.25,.1,.25,1),linear:c(0,0,1,1),"ease-in":c(.42,0,1,1),"ease-out":c(0,0,.58,1),"ease-in-out":c(.42,0,.58,1)},d={namespace:"asPieProgress",classes:{svg:"pie_progress__svg",element:"pie_progress",number:"pie_progress__number",content:"pie_progress__content"},min:0,max:100,goal:100,size:160,speed:15,barcolor:"#ef1e25",barsize:"4",trackcolor:"#f2f2f2",fillcolor:"none",easing:"ease",numberCallback:function(t){return Math.round(this.getPercentage(t))+"%"},contentCallback:null},g=function(){function t(n,s){e(this,t),this.element=n,this.$element=(0,i.default)(n),this.options=i.default.extend(!0,{},d,s,this.$element.data()),this.namespace=this.options.namespace,this.classes=this.options.classes,this.easing=m[this.options.easing]||m.ease,this.$element.addClass(this.classes.element),this.min=this.$element.attr("aria-valuemin"),this.max=this.$element.attr("aria-valuemax"),this.min=this.min?parseInt(this.min,10):this.options.min,this.max=this.max?parseInt(this.max,10):this.options.max,this.first=this.$element.attr("aria-valuenow"),this.first=this.first?parseInt(this.first,10):this.options.first?this.options.first:this.min,this.now=this.first,this.goal=this.options.goal,this._frameId=null,this.initialized=!1,this._trigger("init"),this.init()}return n(t,[{key:"init",value:function(){this.$number=this.$element.find("."+this.classes.number),this.$content=this.$element.find("."+this.classes.content),this.size=this.options.size,this.width=this.size,this.height=this.size,this.prepare(),this.initialized=!0,this._trigger("ready")}},{key:"prepare",value:function(){f&&(this.svg=new s("svg",{version:"1.1",preserveAspectRatio:"xMinYMin meet",viewBox:"0 0 "+this.width+" "+this.height}),this.buildTrack(),this.buildBar(),(0,i.default)('<div class="'+this.classes.svg+'"></div>').append(this.svg).appendTo(this.$element))}},{key:"buildTrack",value:function(){var t=this.size,e=this.size/2,i=t/2,n=this.options.barsize,a=new s("ellipse",{rx:e-n/2,ry:i-n/2,cx:e,cy:i,stroke:this.options.trackcolor,fill:this.options.fillcolor,"stroke-width":n});this.svg.appendChild(a)}},{key:"buildBar",value:function(){if(f){var t=new s("path",{fill:"none","stroke-width":this.options.barsize,stroke:this.options.barcolor});this.bar=t,this.svg.appendChild(t),this._drawBar(this.first),this._updateBar()}}},{key:"_drawBar",value:function(t){if(f){this.barGoal=t;var e=this.size,i=this.size/2,n=e/2,s=this.options.barsize,a=Math.min(i,n)-s/2;this.r=a;var r=this.getPercentage(t);100===r&&(r-=1e-4);var o=0+r*Math.PI*2/100,h=i+a*Math.sin(0),u=i+a*Math.sin(o),l=n-a*Math.cos(0),c=n-a*Math.cos(o),m=0;o-0>Math.PI&&(m=1);var d="M"+h+","+l+" A"+a+","+a+" 0 "+m+" 1 "+u+","+c;this.bar.setAttribute("d",d)}}},{key:"_updateBar",value:function(){if(f){var t=this.getPercentage(this.now),e=this.bar.getTotalLength(),i=e*(1-t/this.getPercentage(this.barGoal));this.bar.style.strokeDasharray=e+" "+e,this.bar.style.strokeDashoffset=i}}},{key:"_trigger",value:function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),n=1;n<e;n++)i[n-1]=arguments[n];var s=[this].concat(i);this.$element.trigger("asPieProgress::"+t,s);var a="on"+(t=t.replace(/\b\w+\b/g,function(t){return t.substring(0,1).toUpperCase()+t.substring(1)}));"function"==typeof this.options[a]&&this.options[a].apply(this,i)}},{key:"getPercentage",value:function(t){return 100*(t-this.min)/(this.max-this.min)}},{key:"go",value:function(t){var e=this;this._clear(),l(t)&&(t=parseInt(t.replace("%",""),10),t=Math.round(this.min+t/100*(this.max-this.min))),void 0===t&&(t=this.goal),t>this.max?t=this.max:t<this.min&&(t=this.min),this.barGoal<t&&this._drawBar(t);var i=e.now,n=u(),s=n+100*Math.abs(i-t)*e.options.speed/(e.max-e.min);e._frameId=window.requestAnimationFrame(function a(r){var o=void 0;if(r>s)o=t;else{var h=(r-n)/e.options.speed;o=Math.round(e.easing.fn(h/100)*(e.max-e.min)),t>i?(o=i+o)>t&&(o=t):(o=i-o)<t&&(o=t)}e._update(o),o===t?(window.cancelAnimationFrame(e._frameId),e._frameId=null,e.now===e.goal&&e._trigger("finish")):e._frameId=window.requestAnimationFrame(a)})}},{key:"_update",value:function(t){this.now=t,this._updateBar(),this.$element.attr("aria-valuenow",this.now),this.$number.length>0&&"function"==typeof this.options.numberCallback&&this.$number.html(this.options.numberCallback.call(this,[this.now])),this.$content.length>0&&"function"==typeof this.options.contentCallback&&this.$content.html(this.options.contentCallback.call(this,[this.now])),this._trigger("update",t)}},{key:"_clear",value:function(){this._frameId&&(window.cancelAnimationFrame(this._frameId),this._frameId=null)}},{key:"get",value:function(){return this.now}},{key:"start",value:function(){this._clear(),this._trigger("start"),this.go(this.goal)}},{key:"reset",value:function(){this._clear(),this._drawBar(this.first),this._update(this.first),this._trigger("reset")}},{key:"stop",value:function(){this._clear(),this._trigger("stop")}},{key:"finish",value:function(){this._clear(),this._update(this.goal),this._trigger("finish")}},{key:"destroy",value:function(){this.$element.data("asPieProgress",null),this._trigger("destroy")}}],[{key:"registerEasing",value:function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),n=1;n<e;n++)i[n-1]=arguments[n];m[t]=c.apply(void 0,i)}},{key:"getEasing",value:function(t){return m[t]}},{key:"setDefaults",value:function(t){i.default.extend(!0,d,i.default.isPlainObject(t)&&t)}}]),t}(),p={version:"0.4.7"},v=i.default.fn.asPieProgress,w=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),s=1;s<e;s++)n[s-1]=arguments[s];if("string"==typeof t){var a=t;if(/^_/.test(a))return!1;if(!/^(get)/.test(a))return this.each(function(){var t=i.default.data(this,"asPieProgress");t&&"function"==typeof t[a]&&t[a].apply(t,n)});var r=this.first().data("asPieProgress");if(r&&"function"==typeof r[a])return r[a].apply(r,n)}return this.each(function(){(0,i.default)(this).data("asPieProgress")||(0,i.default)(this).data("asPieProgress",new g(this,t))})};i.default.fn.asPieProgress=w,i.default.asPieProgress=i.default.extend({setDefaults:g.setDefaults,registerEasing:g.registerEasing,getEasing:g.getEasing,noConflict:function(){return i.default.fn.asPieProgress=v,w}},p)}); | ||
//# sourceMappingURL=jquery-asPieProgress.min.js.map |
@@ -5,3 +5,3 @@ { | ||
"description": "A jQuery plugin that animate the pie progress.", | ||
"version": "0.4.6", | ||
"version": "0.4.7", | ||
"homepage": "https://github.com/amazingSurge/jquery-asPieProgress", | ||
@@ -33,2 +33,3 @@ "author": { | ||
"main": "dist/jquery-asPieProgress.js", | ||
"module": "dist/jquery-asPieProgress.es.js", | ||
"files": [ | ||
@@ -48,3 +49,3 @@ "dist", | ||
"devDependencies": { | ||
"argv": "*", | ||
"yargs": "*", | ||
"assets-manager": "*", | ||
@@ -61,3 +62,4 @@ "babel-core": "*", | ||
"del": "*", | ||
"esformatter": "*", | ||
"prettier": "*", | ||
"gulp-nf-prettier": "*", | ||
"graceful-fs": "*", | ||
@@ -69,3 +71,2 @@ "gulp": "github:gulpjs/gulp#4.0", | ||
"gulp-csscomb": "*", | ||
"gulp-csslint": "*", | ||
"gulp-cssnano": "*", | ||
@@ -78,3 +79,2 @@ "gulp-eslint": "*", | ||
"gulp-if": "*", | ||
"gulp-jshint": "*", | ||
"gulp-notify": "*", | ||
@@ -87,3 +87,2 @@ "gulp-plumber": "*", | ||
"gulp-sass-unicode": "*", | ||
"gulp-scss-lint": "*", | ||
"gulp-size": "*", | ||
@@ -96,3 +95,3 @@ "gulp-sourcemaps": "*", | ||
"inquirer": "*", | ||
"jshint": "*", | ||
"semver": "*", | ||
"karma": "*", | ||
@@ -113,3 +112,3 @@ "karma-babel-preprocessor": "*", | ||
"node-notifier": "*", | ||
"normalize.css": "^4.2.0", | ||
"normalize.css": "^7.0.0", | ||
"path-exists": "*", | ||
@@ -116,0 +115,0 @@ "phantomjs-prebuilt": "*", |
export default { | ||
version:'0.4.6' | ||
version:'0.4.7' | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
98866
68
19
1569