New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-slider-easy

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-slider-easy - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

src/defaults.js

870

dist/angular-slider-easy.js

@@ -1,326 +0,584 @@

/**
* slider-easy is such a directive which generate a slider bar, and
* helps developer select the desired value
*
* @param option[expression]
* start[number]: a number of start point
* end[number]: a number of end point
* handles[array]: init points. if you want a range returned, this
* has to be set
* decimals[int]: the number you want to keep as decimal
* outFormatter[function]: the function used to format the text at
* hint area
* @author Howard.Zuo
* @date Jan 28th, 2016
*
**/
(function(global, factory) {
'use strict';
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("angular"));
else if(typeof define === 'function' && define.amd)
define(["angular"], factory);
else {
var a = typeof exports === 'object' ? factory(require("angular")) : factory(root["angular"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
if (typeof exports === 'object') {
module.exports = factory(require('angular'));
} else if (typeof define === 'function' && define.amd) {
define(['angular'], factory);
} else {
factory(global.angular);
}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sliderEasy = undefined;
var _angular = __webpack_require__(2);
var _angular2 = _interopRequireDefault(_angular);
var _options2 = __webpack_require__(3);
var _event = __webpack_require__(5);
var _throttle = __webpack_require__(6);
var _oper = __webpack_require__(7);
var _defaults = __webpack_require__(8);
var _slider = __webpack_require__(9);
__webpack_require__(10);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var sliderEasy = exports.sliderEasy = function () {
var mod = _angular2.default.module('angular-slider-easy', []);
var dir = function dir($timeout) {
return {
restrict: 'E',
scope: {
option: '=',
value: '='
},
link: function link($scope, element) {
var $doc = _angular2.default.element(document);
var $win = _angular2.default.element(window);
var _options = _angular2.default.extend({}, _defaults.defaults, $scope.option);
(0, _options2.validate)(_options);
if (!_options.handles || _options.handles.length === 0) {
_options.handles = [];
_options.handles[0] = _options.start;
}
var offset = 0;
var activeHandle;
var $handles = [];
var handlePos = {};
var move = function move(event) {
var e = (0, _event.getEvent)(event);
var movement = handlePos[activeHandle.attr('id')] + e.clientX - offset;
if (movement >= minPoint && movement <= maxPoint) {
activeHandle.css('left', movement + 'px');
if ($handles[1]) {
(0, _oper.setSelction)($selection, $handles[0], $handles[1]);
}
(0, _oper.setHintPosition)($hint, $handles[0], $handles[1]);
$scope.$apply(function () {
(0, _oper.setValue)(len, width, _options.decimals, $scope.value, $handles[0], $handles[1], _options);
(0, _oper.setOutput)($scope, _options);
});
}
(0, _event.preventDefault)(event);
};
var end = function end(event) {
offset = 0;
handlePos[activeHandle.attr('id')] = (0, _oper.getMovement)(activeHandle);
activeHandle = undefined;
$doc.off('mousemove touchmove', move);
$doc.off('mouseup touchend', end);
(0, _event.preventDefault)(event);
};
var getStart = function getStart(prehandle) {
return function (event) {
var e = (0, _event.getEvent)(event);
activeHandle = prehandle;
offset = e.clientX;
$doc.on('mousemove touchmove', move);
$doc.on('mouseup touchend', end);
(0, _event.preventDefault)(event);
};
};
var _refresh = (0, _slider.refresh)($scope, element, _options, $handles, handlePos);
var $track = _refresh.$track;
var $hint = _refresh.$hint;
var $selection = _refresh.$selection;
var len = _refresh.len;
var width = _refresh.width;
var minPoint = _refresh.minPoint;
var maxPoint = _refresh.maxPoint;
$timeout(_angular2.default.noop).then(function () {
var start0 = getStart($handles[0]);
var start1 = getStart($handles[1]);
(0, _slider.initClick)($selection, $track, $handles, $hint, len, width, _options, $scope, handlePos);
$handles[0].on('mousedown touchstart', start0);
if ($handles[1]) {
$handles[1].on('mousedown touchstart', start1);
}
});
var onResize = (0, _throttle.throttle)(function () {
var result = (0, _slider.refresh)($scope, element, _options, $handles, handlePos);
$track = result.$track;
$hint = result.$hint;
$selection = result.$selection;
len = result.len;
width = result.width;
minPoint = result.minPoint;
maxPoint = result.maxPoint;
}, 500);
$win.on('resize', onResize);
$scope.$on('$destroy', function () {
$handles[0].off('mousedown touchstart', start0);
if ($handles[1]) {
$handles[1].off('mousedown touchstart', start1);
}
$doc.off('mousemove touchmove', move);
$doc.off('mouseup touchend', end);
});
},
template: '<div class="slider"><div class="slider-track"><div class="slider-selection"></div></div><div class="hint"><div class="hint-arrow"></div><div class="hint-inner">{{ output }}</div></div></div>'
};
};
mod.directive('sliderEasy', ['$timeout', dir]);
return 'angular-slider-easy';
}();
}(window, function(ng) {
var mod = ng.module('angular-slider-easy', []);
/***/ },
/* 1 */,
/* 2 */
/***/ function(module, exports) {
var handle = '<div class="slider-handle"></div>';
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
var defaults = {
start: 0,
end: 100,
decimals: 0,
outFormatter: function(value, decimals) {
if (value.point) {
return 'Point is: ' + value.point;
} else {
return 'Range is: ' + (value.end - value.start).toFixed(decimals);
}
}
};
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validate = undefined;
var _detect = __webpack_require__(4);
var validateHandles = function validateHandles(options) {
if (options.handles && typeof options.handles[0] !== 'undefined') {
if (!(0, _detect.isNumber)(options.handles[0])) {
throw new Error('handles[0] must be number');
}
if (options.handles[0] < options.start || options.handles[0] > options.end) {
throw new Error('handles[0] must be in [start, end]');
}
}
if (options.handles && typeof options.handles[1] !== 'undefined') {
if (!(0, _detect.isNumber)(options.handles[1])) {
throw new Error('handles[1] must be number');
}
if (options.handles[1] < options.start || options.handles[1] > options.end) {
throw new Error('handles[1] must be in [start, end]');
}
}
};
var validate = exports.validate = function validate(options) {
if (!(0, _detect.isNumber)(options.start)) {
throw new Error('start must be number');
}
if (!(0, _detect.isNumber)(options.end)) {
throw new Error('end must be number');
}
if (options.start >= options.end) {
throw new Error('end must be bigger than start');
}
if (!(0, _detect.isPositiveInt)(options.decimals)) {
throw new Error('decimals must be +int');
}
validateHandles(options);
};
var _defaults = function(dest, src) {
var dst = dest || {};
if (!src || typeof src !== 'object') {
return dst;
}
for (var i in src) {
if (!dst[i] && typeof src[i] !== undefined & src[i] !== null) {
dst[i] = src[i];
}
}
return dst;
};
/***/ },
/* 4 */
/***/ function(module, exports) {
var isNumber = function(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
};
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var isNumber = exports.isNumber = function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
};
var isPositiveInt = exports.isPositiveInt = function isPositiveInt(n) {
return n === parseInt(n) && n === Math.abs(n);
};
var isPositiveInt = function(n) {
return n === parseInt(n) && n === Math.abs(n);
};
/***/ },
/* 5 */
/***/ function(module, exports) {
var validate = function(options) {
if (!isNumber(options.start)) {
throw new Error('start must be number');
}
if (!isNumber(options.end)) {
throw new Error('end must be number');
}
if (options.start >= options.end) {
throw new Error('end must be bigger than start');
}
if (!isPositiveInt(options.decimals)) {
throw new Error('decimals must be +int');
}
if (options.handles && typeof options.handles[0] !== 'undefined') {
if (!isNumber(options.handles[0])) {
throw new Error('handles[0] must be number');
}
if (options.handles[0] < options.start || options.handles[0] > options.end) {
throw new Error('handles[0] must be in [start, end]');
}
}
if (options.handles && typeof options.handles[1] !== 'undefined') {
if (!isNumber(options.handles[1])) {
throw new Error('handles[1] must be number');
}
if (options.handles[1] < options.start || options.handles[1] > options.end) {
throw new Error('handles[1] must be in [start, end]');
}
}
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var getEvent = exports.getEvent = function getEvent(e) {
if (e.touches && e.touches.length > 0) {
return e.touches[0];
}
if (window.jQuery && window.jQuery.Event && e instanceof window.jQuery.Event && e.originalEvent.touches && e.originalEvent.touches.length > 0) {
return e.originalEvent.touches[0];
}
return e;
};
var preventDefault = exports.preventDefault = function preventDefault(e) {
if (e.stopPropagation) {
e.stopPropagation();
}
if (e.preventDefault) {
e.preventDefault();
}
};
};
/***/ },
/* 6 */
/***/ function(module, exports) {
var getEvent = function(e) {
if (e.touches && e.touches.length > 0) {
return e.touches[0];
}
if (window.jQuery && window.jQuery.Event && e instanceof window.jQuery.Event && e.originalEvent.touches && e.originalEvent.touches.length > 0) {
return e.originalEvent.touches[0];
}
return e;
};
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var throttle = exports.throttle = function throttle(func, wait) {
var last, timer;
return function () {
var args = Array.prototype.slice.call(arguments);
var _this = this,
now = new Date().getTime();
if (typeof last === 'undefined') {
last = now;
return func.apply(_this, args);
}
clearTimeout(timer);
if (now - last > wait) {
last = new Date().getTime();
return func.apply(_this, args);
}
timer = setTimeout(function () {
last = new Date().getTime();
func.apply(_this, args);
}, wait + last - now);
};
};
var preventDefault = function(e) {
if (e.stopPropagation) {
e.stopPropagation();
}
if (e.preventDefault) {
e.preventDefault();
}
};
/***/ },
/* 7 */
/***/ function(module, exports) {
var getMovement = function(element) {
return parseInt(element.css('left'));
};
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var getMovement = exports.getMovement = function getMovement(element) {
return parseInt(element.css('left'));
};
var getPoint = exports.getPoint = function getPoint(len, width, num) {
return num / len * width;
};
var getValue = function getValue(len, width, mov, decimals, opts) {
return (mov / width * len + opts.start).toFixed(decimals);
};
var setRange = function setRange(len, width, decimals, value, $handle0, $handle1, opts) {
var handle0 = getMovement($handle0);
var handle1 = getMovement($handle1);
var max = Math.max(handle0, handle1);
var min = Math.min(handle0, handle1);
value.start = getValue(len, width, min, decimals, opts);
value.end = getValue(len, width, max, decimals, opts);
};
var setHintPosition = exports.setHintPosition = function setHintPosition($hint, $handle0, $handle1) {
var handle0 = getMovement($handle0);
if (!$handle1) {
$hint.css('left', handle0 - 3 - $hint.prop('clientWidth') / 2 + 'px');
return;
}
var handle1 = getMovement($handle1);
var max = Math.max(handle0, handle1);
var min = Math.min(handle0, handle1);
$hint.css('left', (max - min) / 2 + min - 3 - $hint.prop('clientWidth') / 2 + 'px');
};
var setValue = exports.setValue = function setValue(len, width, decimals, value, $handle0, $handle1, opts) {
if ($handle1) {
return setRange(len, width, decimals, value, $handle0, $handle1, opts);
}
value.point = getValue(len, width, getMovement($handle0), decimals, opts);
};
var setOutput = exports.setOutput = function setOutput($scope, _options) {
$scope.output = _options.outFormatter($scope.value);
};
var setSelction = exports.setSelction = function setSelction($selection, $handle0, $handle1) {
var handle0 = getMovement($handle0);
var handle1 = getMovement($handle1);
var max = Math.max(handle0, handle1);
var min = Math.min(handle0, handle1);
var wid = max - min;
$selection.css('left', min + 'px').css('width', wid + 'px');
};
var getPoint = function(len, width, num) {
return (num / len) * width;
};
/***/ },
/* 8 */
/***/ function(module, exports) {
var getValue = function(len, width, mov, decimals, opts) {
return ((mov / width) * len + opts.start).toFixed(decimals);
};
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var defaults = exports.defaults = {
start: 0,
end: 100,
decimals: 0,
outFormatter: function outFormatter(value, decimals) {
if (value.point) {
return 'Point is: ' + value.point;
}
return 'Range is: ' + (value.end - value.start).toFixed(decimals);
}
};
var setHintPosition = function($hint, $handle0, $handle1) {
var handle0 = getMovement($handle0);
if (!$handle1) {
$hint.css('left', (handle0 - 3 - $hint.prop('clientWidth') / 2) + 'px');
return;
}
var handle1 = getMovement($handle1);
var max = Math.max(handle0, handle1);
var min = Math.min(handle0, handle1);
$hint.css('left', ((max - min) / 2 + min - 3 - $hint.prop('clientWidth') / 2) + 'px');
};
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
var setValue = function(len, width, decimals, value, $handle0, $handle1, opts) {
if ($handle1) {
setRange(len, width, decimals, value, $handle0, $handle1, opts);
} else {
value.point = getValue(len, width, getMovement($handle0), decimals, opts);
}
};
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.initClick = exports.refresh = undefined;
var _angular = __webpack_require__(2);
var _angular2 = _interopRequireDefault(_angular);
var _event = __webpack_require__(5);
var _oper = __webpack_require__(7);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var handle = '<div class="slider-handle"></div>';
var retrieveElms = function retrieveElms(element) {
var $slider = _angular2.default.element(element.children()[0]);
var $track = _angular2.default.element($slider.children()[0]);
var $hint = _angular2.default.element($slider.children()[1]);
var $selection = _angular2.default.element($track.children()[0]);
return {
$slider: $slider,
$track: $track,
$hint: $hint,
$selection: $selection
};
};
var initHandle0 = function initHandle0(_options, $track, len, width, $hint, $scope, handlePos, $handles) {
if (!$handles[0]) {
$handles[0] = _angular2.default.element(handle);
$track.append($handles[0]);
$handles[0].attr('id', 'handle0');
}
var initPoint0 = (0, _oper.getPoint)(len, width, _options.handles[0] - _options.start);
if (typeof $scope.value.start !== 'undefined') {
$handles[0].css('left', (0, _oper.getPoint)(len, width, $scope.value.start - _options.start) + 'px');
handlePos.handle0 = (0, _oper.getPoint)(len, width, $scope.value.start - _options.start);
} else if (typeof $scope.value.point !== 'undefined') {
$handles[0].css('left', (0, _oper.getPoint)(len, width, $scope.value.point - _options.start) + 'px');
handlePos.handle0 = (0, _oper.getPoint)(len, width, $scope.value.point);
} else {
$handles[0].css('left', initPoint0 + 'px');
handlePos.handle0 = initPoint0;
}
(0, _oper.setHintPosition)($hint, $handles[0]);
};
var initHandle1 = function initHandle1(_options, $track, $selection, len, width, $hint, $scope, handlePos, $handles) {
var initPoint1 = void 0;
if (_options.handles[1]) {
if (!$handles[1]) {
$handles[1] = _angular2.default.element(handle);
$track.append($handles[1]);
$handles[1].attr('id', 'handle1');
}
initPoint1 = (0, _oper.getPoint)(len, width, _options.handles[1] - _options.start);
if (typeof $scope.value.end !== 'undefined') {
$handles[1].css('left', (0, _oper.getPoint)(len, width, $scope.value.end - _options.start) + 'px');
handlePos.handle1 = (0, _oper.getPoint)(len, width, $scope.value.end - _options.start);
} else {
$handles[1].css('left', initPoint1 + 'px');
handlePos.handle1 = initPoint1;
}
(0, _oper.setHintPosition)($hint, $handles[0], $handles[1]);
(0, _oper.setSelction)($selection, $handles[0], $handles[1]);
}
};
var refresh = exports.refresh = function refresh($scope, element, _options, $handles, handlePos) {
var _retrieveElms = retrieveElms(element);
var $slider = _retrieveElms.$slider;
var $track = _retrieveElms.$track;
var $hint = _retrieveElms.$hint;
var $selection = _retrieveElms.$selection;
var len = _options.end - _options.start;
var width = $slider.prop('clientWidth');
var minPoint = (0, _oper.getPoint)(len, width, 0);
var maxPoint = (0, _oper.getPoint)(len, width, _options.end - _options.start);
initHandle0(_options, $track, len, width, $hint, $scope, handlePos, $handles);
initHandle1(_options, $track, $selection, len, width, $hint, $scope, handlePos, $handles);
(0, _oper.setValue)(len, width, _options.decimals, $scope.value, $handles[0], $handles[1], _options);
(0, _oper.setOutput)($scope, _options);
return {
$track: $track,
$hint: $hint,
$selection: $selection,
len: len,
width: width,
minPoint: minPoint,
maxPoint: maxPoint
};
};
var initClick = exports.initClick = function initClick($selection, $track, $handles, $hint, len, width, _options, $scope, handlePos) {
$track.on('click', function (event) {
if (!event.target.classList.contains('slider-track') && !event.target.classList.contains('slider-selection')) {
return;
}
var e = (0, _event.getEvent)(event);
var target = event.target.classList.contains('slider-track') ? event.target : event.target.parentNode;
var clickedPosition = e.clientX - target.getBoundingClientRect().left;
if ($handles.length === 1) {
$handles[0].css('left', clickedPosition + 'px');
(0, _oper.setHintPosition)($hint, $handles[0], $handles[1]);
handlePos.handle0 = (0, _oper.getMovement)($handles[0]);
$scope.$apply(function () {
(0, _oper.setValue)(len, width, _options.decimals, $scope.value, $handles[0], $handles[1], _options);
(0, _oper.setOutput)($scope, _options);
});
} else {
var rightHandle = $handles.reduce(function (pre, $handle) {
return (0, _oper.getMovement)($handle) > (0, _oper.getMovement)(pre) ? $handle : pre;
});
var leftHandle = $handles.reduce(function (pre, $handle) {
return (0, _oper.getMovement)($handle) < (0, _oper.getMovement)(pre) ? $handle : pre;
});
if ((0, _oper.getMovement)(rightHandle) < clickedPosition) {
rightHandle.css('left', clickedPosition + 'px');
handlePos[rightHandle.attr('id')] = (0, _oper.getMovement)(rightHandle);
} else if ((0, _oper.getMovement)(leftHandle) > clickedPosition) {
leftHandle.css('left', clickedPosition + 'px');
handlePos[leftHandle.attr('id')] = (0, _oper.getMovement)(leftHandle);
} else if ((0, _oper.getMovement)(rightHandle) - clickedPosition < clickedPosition - (0, _oper.getMovement)(leftHandle)) {
rightHandle.css('left', clickedPosition + 'px');
handlePos[rightHandle.attr('id')] = (0, _oper.getMovement)(rightHandle);
} else if ((0, _oper.getMovement)(rightHandle) - clickedPosition >= clickedPosition - (0, _oper.getMovement)(leftHandle)) {
leftHandle.css('left', clickedPosition + 'px');
handlePos[leftHandle.attr('id')] = (0, _oper.getMovement)(leftHandle);
}
(0, _oper.setHintPosition)($hint, $handles[0], $handles[1]);
$scope.$apply(function () {
(0, _oper.setValue)(len, width, _options.decimals, $scope.value, $handles[0], $handles[1], _options);
(0, _oper.setOutput)($scope, _options);
});
(0, _oper.setSelction)($selection, $handles[0], $handles[1]);
}
});
};
var setOutput = function($scope, _options) {
$scope.output = _options.outFormatter($scope.value);
};
/***/ },
/* 10 */
/***/ function(module, exports) {
var setSelction = function($selection, $handle0, $handle1) {
var handle0 = getMovement($handle0);
var handle1 = getMovement($handle1);
var max = Math.max(handle0, handle1);
var min = Math.min(handle0, handle1);
var wid = max - min;
$selection.css('left', min + 'px').css('width', wid + 'px');
};
// removed by extract-text-webpack-plugin
var setRange = function(len, width, decimals, value, $handle0, $handle1, opts) {
var handle0 = getMovement($handle0);
var handle1 = getMovement($handle1);
var max = Math.max(handle0, handle1);
var min = Math.min(handle0, handle1);
value.start = getValue(len, width, min, decimals, opts);
value.end = getValue(len, width, max, decimals, opts);
};
var dir = function($timeout) {
return {
restrict: 'E',
scope: {
option: '=',
value: '='
},
link: function($scope, element) {
var $doc = ng.element(document);
var $win = ng.element(window);
var _options = _defaults($scope.option, defaults);
validate(_options);
if (!_options.handles) {
_options.handles = [];
_options.handles[0] = _options.start;
}
var $slider, $track, $hint, $selection;
var len, width;
var minPoint, maxPoint;
var $handle0, $handle1;
var initPoint0, initPoint1;
var offset = 0;
var activeHandle;
var handlePos = {};
var refresh = function() {
$slider = ng.element(element.children()[0]);
$track = ng.element($slider.children()[0]);
$hint = ng.element($slider.children()[1]);
$selection = ng.element($track.children()[0]);
len = _options.end - _options.start;
width = $slider.prop('clientWidth');
minPoint = getPoint(len, width, 0);
maxPoint = getPoint(len, width, _options.end - _options.start);
if (!$handle0) {
$handle0 = ng.element(handle);
$track.append($handle0);
$handle0.attr('id', 'handle0');
}
initPoint0 = getPoint(len, width, _options.handles[0] - _options.start);
if (typeof $scope.value.start !== 'undefined') {
$handle0.css('left', getPoint(len, width, $scope.value.start) + 'px');
handlePos.handle0 = getPoint(len, width, $scope.value.start);
} else if (typeof $scope.value.point !== 'undefined') {
$handle0.css('left', getPoint(len, width, $scope.value.point) + 'px');
handlePos.handle0 = getPoint(len, width, $scope.value.point);
} else {
$handle0.css('left', initPoint0 + 'px');
handlePos.handle0 = initPoint0;
}
setHintPosition($hint, $handle0);
if (_options.handles[1]) {
if (!$handle1) {
$handle1 = ng.element(handle);
$track.append($handle1);
$handle1.attr('id', 'handle1');
}
initPoint1 = getPoint(len, width, _options.handles[1] - _options.start);
if (typeof $scope.value.end !== 'undefined') {
$handle1.css('left', getPoint(len, width, $scope.value.end) + 'px');
handlePos.handle1 = getPoint(len, width, $scope.value.end);
} else {
$handle1.css('left', initPoint1 + 'px');
handlePos.handle1 = initPoint1;
}
setHintPosition($hint, $handle0, $handle1);
setSelction($selection, $handle0, $handle1);
}
setValue(len, width, _options.decimals, $scope.value, $handle0, $handle1, _options);
setOutput($scope, _options);
};
var move = function(event) {
var e = getEvent(event);
var movement = handlePos[activeHandle.attr('id')] + e.clientX - offset;
if (movement >= minPoint && movement <= maxPoint) {
activeHandle.css('left', movement + 'px');
if ($handle1) {
setSelction($selection, $handle0, $handle1);
}
setHintPosition($hint, $handle0, $handle1);
$scope.$apply(function() {
setValue(len, width, _options.decimals, $scope.value, $handle0, $handle1, _options);
setOutput($scope, _options);
});
}
preventDefault(event);
};
var end = function(event) {
offset = 0;
handlePos[activeHandle.attr('id')] = getMovement(activeHandle);
activeHandle = undefined;
$doc.off('mousemove touchmove', move);
$doc.off('mouseup touchend', end);
preventDefault(event);
};
var getStart = function(handle) {
return function(event) {
var e = getEvent(event);
activeHandle = handle;
offset = e.clientX;
$doc.on('mousemove touchmove', move);
$doc.on('mouseup touchend', end);
preventDefault(event);
};
};
$timeout(refresh)
.then(function() {
var start0 = getStart($handle0);
var start1 = getStart($handle1);
$handle0.on('mousedown touchstart', start0);
if ($handle1) {
$handle1.on('mousedown touchstart', start1);
}
});
$win.on('resize', function() {
//this workaround works for some resize case
$timeout(function() {
refresh();
}, 500);
});
$scope.$on('$destroy', function() {
$handle0.off('mousedown touchstart', start0);
if ($handle1) {
$handle1.off('mousedown touchstart', start1);
}
$doc.off('mousemove touchmove', move);
$doc.off('mouseup touchend', end);
});
},
template: '<div class="slider"><div class="slider-track"><div class="slider-selection"></div></div><div class="hint"><div class="hint-arrow"></div><div class="hint-inner">{{ output }}</div></div></div>'
};
};
mod.directive('sliderEasy', ['$timeout', dir]);
return 'angular-slider-easy';
}));
/***/ }
/******/ ])
});
;

@@ -1,1 +0,1 @@

!function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("angular")):"function"==typeof define&&define.amd?define(["angular"],t):t(e.angular)}(window,function(e){var t=e.module("angular-slider-easy",[]),n='<div class="slider-handle"></div>',o={start:0,end:100,decimals:0,outFormatter:function(e,t){return e.point?"Point is: "+e.point:"Range is: "+(e.end-e.start).toFixed(t)}},r=function(e,t){var n=e||{};if(!t||"object"!=typeof t)return n;for(var o in t)!n[o]&&void 0!==typeof t[o]&null!==t[o]&&(n[o]=t[o]);return n},i=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},a=function(e){return e===parseInt(e)&&e===Math.abs(e)},s=function(e){if(!i(e.start))throw new Error("start must be number");if(!i(e.end))throw new Error("end must be number");if(e.start>=e.end)throw new Error("end must be bigger than start");if(!a(e.decimals))throw new Error("decimals must be +int");if(e.handles&&"undefined"!=typeof e.handles[0]){if(!i(e.handles[0]))throw new Error("handles[0] must be number");if(e.handles[0]<e.start||e.handles[0]>e.end)throw new Error("handles[0] must be in [start, end]")}if(e.handles&&"undefined"!=typeof e.handles[1]){if(!i(e.handles[1]))throw new Error("handles[1] must be number");if(e.handles[1]<e.start||e.handles[1]>e.end)throw new Error("handles[1] must be in [start, end]")}},u=function(e){return e.touches&&e.touches.length>0?e.touches[0]:window.jQuery&&window.jQuery.Event&&e instanceof window.jQuery.Event&&e.originalEvent.touches&&e.originalEvent.touches.length>0?e.originalEvent.touches[0]:e},d=function(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()},l=function(e){return parseInt(e.css("left"))},c=function(e,t,n){return n/e*t},f=function(e,t,n,o,r){return(n/t*e+r.start).toFixed(o)},h=function(e,t,n){var o=l(t);if(!n)return void e.css("left",o-3-e.prop("clientWidth")/2+"px");var r=l(n),i=Math.max(o,r),a=Math.min(o,r);e.css("left",(i-a)/2+a-3-e.prop("clientWidth")/2+"px")},p=function(e,t,n,o,r,i,a){i?w(e,t,n,o,r,i,a):o.point=f(e,t,l(r),n,a)},v=function(e,t){e.output=t.outFormatter(e.value)},m=function(e,t,n){var o=l(t),r=l(n),i=Math.max(o,r),a=Math.min(o,r),s=i-a;e.css("left",a+"px").css("width",s+"px")},w=function(e,t,n,o,r,i,a){var s=l(r),u=l(i),d=Math.max(s,u),c=Math.min(s,u);o.start=f(e,t,c,n,a),o.end=f(e,t,d,n,a)},x=function(t){return{restrict:"E",scope:{option:"=",value:"="},link:function(i,a){var f=e.element(document),w=e.element(window),x=r(i.option,o);s(x),x.handles||(x.handles=[],x.handles[0]=x.start);var y,b,g,E,M,F,j,$,P,Q,W,k,D,I=0,N={},X=function(){y=e.element(a.children()[0]),b=e.element(y.children()[0]),g=e.element(y.children()[1]),E=e.element(b.children()[0]),M=x.end-x.start,F=y.prop("clientWidth"),j=c(M,F,0),$=c(M,F,x.end-x.start),P||(P=e.element(n),b.append(P),P.attr("id","handle0")),W=c(M,F,x.handles[0]-x.start),"undefined"!=typeof i.value.start?(P.css("left",c(M,F,i.value.start)+"px"),N.handle0=c(M,F,i.value.start)):"undefined"!=typeof i.value.point?(P.css("left",c(M,F,i.value.point)+"px"),N.handle0=c(M,F,i.value.point)):(P.css("left",W+"px"),N.handle0=W),h(g,P),x.handles[1]&&(Q||(Q=e.element(n),b.append(Q),Q.attr("id","handle1")),k=c(M,F,x.handles[1]-x.start),"undefined"!=typeof i.value.end?(Q.css("left",c(M,F,i.value.end)+"px"),N.handle1=c(M,F,i.value.end)):(Q.css("left",k+"px"),N.handle1=k),h(g,P,Q),m(E,P,Q)),p(M,F,x.decimals,i.value,P,Q,x),v(i,x)},q=function(e){var t=u(e),n=N[D.attr("id")]+t.clientX-I;n>=j&&$>=n&&(D.css("left",n+"px"),Q&&m(E,P,Q),h(g,P,Q),i.$apply(function(){p(M,F,x.decimals,i.value,P,Q,x),v(i,x)})),d(e)},z=function(e){I=0,N[D.attr("id")]=l(D),D=void 0,f.off("mousemove touchmove",q),f.off("mouseup touchend",z),d(e)},R=function(e){return function(t){var n=u(t);D=e,I=n.clientX,f.on("mousemove touchmove",q),f.on("mouseup touchend",z),d(t)}};t(X).then(function(){var e=R(P),t=R(Q);P.on("mousedown touchstart",e),Q&&Q.on("mousedown touchstart",t)}),w.on("resize",function(){t(function(){X()},500)}),i.$on("$destroy",function(){P.off("mousedown touchstart",start0),Q&&Q.off("mousedown touchstart",start1),f.off("mousemove touchmove",q),f.off("mouseup touchend",z)})},template:'<div class="slider"><div class="slider-track"><div class="slider-selection"></div></div><div class="hint"><div class="hint-arrow"></div><div class="hint-inner">{{ output }}</div></div></div>'}};return t.directive("sliderEasy",["$timeout",x]),"angular-slider-easy"});
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("angular"));else if("function"==typeof define&&define.amd)define(["angular"],t);else{var n=t("object"==typeof exports?require("angular"):e.angular);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this,function(e){return function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.sliderEasy=void 0;var o=n(2),r=i(o),s=n(3),a=n(5),u=n(6),l=n(7),d=n(8),c=n(9);n(10);t.sliderEasy=function(){var e=r["default"].module("angular-slider-easy",[]),t=function(e){return{restrict:"E",scope:{option:"=",value:"="},link:function(t,n){var i=r["default"].element(document),o=r["default"].element(window),f=r["default"].extend({},d.defaults,t.option);(0,s.validate)(f),f.handles&&0!==f.handles.length||(f.handles=[],f.handles[0]=f.start);var v,p=0,h=[],m={},g=function(e){var n=(0,a.getEvent)(e),i=m[v.attr("id")]+n.clientX-p;i>=_&&j>=i&&(v.css("left",i+"px"),h[1]&&(0,l.setSelction)(b,h[0],h[1]),(0,l.setHintPosition)(M,h[0],h[1]),t.$apply(function(){(0,l.setValue)($,E,f.decimals,t.value,h[0],h[1],f),(0,l.setOutput)(t,f)})),(0,a.preventDefault)(e)},w=function O(e){p=0,m[v.attr("id")]=(0,l.getMovement)(v),v=void 0,i.off("mousemove touchmove",g),i.off("mouseup touchend",O),(0,a.preventDefault)(e)},y=function(e){return function(t){var n=(0,a.getEvent)(t);v=e,p=n.clientX,i.on("mousemove touchmove",g),i.on("mouseup touchend",w),(0,a.preventDefault)(t)}},P=(0,c.refresh)(t,n,f,h,m),x=P.$track,M=P.$hint,b=P.$selection,$=P.len,E=P.width,_=P.minPoint,j=P.maxPoint;e(r["default"].noop).then(function(){var e=y(h[0]),n=y(h[1]);(0,c.initClick)(b,x,h,M,$,E,f,t,m),h[0].on("mousedown touchstart",e),h[1]&&h[1].on("mousedown touchstart",n)});var k=(0,u.throttle)(function(){var e=(0,c.refresh)(t,n,f,h,m);x=e.$track,M=e.$hint,b=e.$selection,$=e.len,E=e.width,_=e.minPoint,j=e.maxPoint},500);o.on("resize",k),t.$on("$destroy",function(){h[0].off("mousedown touchstart",start0),h[1]&&h[1].off("mousedown touchstart",start1),i.off("mousemove touchmove",g),i.off("mouseup touchend",w)})},template:'<div class="slider"><div class="slider-track"><div class="slider-selection"></div></div><div class="hint"><div class="hint-arrow"></div><div class="hint-inner">{{ output }}</div></div></div>'}};return e.directive("sliderEasy",["$timeout",t]),"angular-slider-easy"}()},,function(t,n){t.exports=e},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.validate=void 0;var i=n(4),o=function(e){if(e.handles&&"undefined"!=typeof e.handles[0]){if(!(0,i.isNumber)(e.handles[0]))throw new Error("handles[0] must be number");if(e.handles[0]<e.start||e.handles[0]>e.end)throw new Error("handles[0] must be in [start, end]")}if(e.handles&&"undefined"!=typeof e.handles[1]){if(!(0,i.isNumber)(e.handles[1]))throw new Error("handles[1] must be number");if(e.handles[1]<e.start||e.handles[1]>e.end)throw new Error("handles[1] must be in [start, end]")}};t.validate=function(e){if(!(0,i.isNumber)(e.start))throw new Error("start must be number");if(!(0,i.isNumber)(e.end))throw new Error("end must be number");if(e.start>=e.end)throw new Error("end must be bigger than start");if(!(0,i.isPositiveInt)(e.decimals))throw new Error("decimals must be +int");o(e)}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.isNumber=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},t.isPositiveInt=function(e){return e===parseInt(e)&&e===Math.abs(e)}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.getEvent=function(e){return e.touches&&e.touches.length>0?e.touches[0]:window.jQuery&&window.jQuery.Event&&e instanceof window.jQuery.Event&&e.originalEvent.touches&&e.originalEvent.touches.length>0?e.originalEvent.touches[0]:e},t.preventDefault=function(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.throttle=function(e,t){var n,i;return function(){var o=Array.prototype.slice.call(arguments),r=this,s=(new Date).getTime();return"undefined"==typeof n?(n=s,e.apply(r,o)):(clearTimeout(i),s-n>t?(n=(new Date).getTime(),e.apply(r,o)):void(i=setTimeout(function(){n=(new Date).getTime(),e.apply(r,o)},t+n-s)))}}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=t.getMovement=function(e){return parseInt(e.css("left"))},i=(t.getPoint=function(e,t,n){return n/e*t},function(e,t,n,i,o){return(n/t*e+o.start).toFixed(i)}),o=function(e,t,o,r,s,a,u){var l=n(s),d=n(a),c=Math.max(l,d),f=Math.min(l,d);r.start=i(e,t,f,o,u),r.end=i(e,t,c,o,u)};t.setHintPosition=function(e,t,i){var o=n(t);if(!i)return void e.css("left",o-3-e.prop("clientWidth")/2+"px");var r=n(i),s=Math.max(o,r),a=Math.min(o,r);e.css("left",(s-a)/2+a-3-e.prop("clientWidth")/2+"px")},t.setValue=function(e,t,r,s,a,u,l){return u?o(e,t,r,s,a,u,l):void(s.point=i(e,t,n(a),r,l))},t.setOutput=function(e,t){e.output=t.outFormatter(e.value)},t.setSelction=function(e,t,i){var o=n(t),r=n(i),s=Math.max(o,r),a=Math.min(o,r),u=s-a;e.css("left",a+"px").css("width",u+"px")}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.defaults={start:0,end:100,decimals:0,outFormatter:function(e,t){return e.point?"Point is: "+e.point:"Range is: "+(e.end-e.start).toFixed(t)}}},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.initClick=t.refresh=void 0;var o=n(2),r=i(o),s=n(5),a=n(7),u='<div class="slider-handle"></div>',l=function(e){var t=r["default"].element(e.children()[0]),n=r["default"].element(t.children()[0]),i=r["default"].element(t.children()[1]),o=r["default"].element(n.children()[0]);return{$slider:t,$track:n,$hint:i,$selection:o}},d=function(e,t,n,i,o,s,l,d){d[0]||(d[0]=r["default"].element(u),t.append(d[0]),d[0].attr("id","handle0"));var c=(0,a.getPoint)(n,i,e.handles[0]-e.start);"undefined"!=typeof s.value.start?(d[0].css("left",(0,a.getPoint)(n,i,s.value.start-e.start)+"px"),l.handle0=(0,a.getPoint)(n,i,s.value.start-e.start)):"undefined"!=typeof s.value.point?(d[0].css("left",(0,a.getPoint)(n,i,s.value.point-e.start)+"px"),l.handle0=(0,a.getPoint)(n,i,s.value.point)):(d[0].css("left",c+"px"),l.handle0=c),(0,a.setHintPosition)(o,d[0])},c=function(e,t,n,i,o,s,l,d,c){var f=void 0;e.handles[1]&&(c[1]||(c[1]=r["default"].element(u),t.append(c[1]),c[1].attr("id","handle1")),f=(0,a.getPoint)(i,o,e.handles[1]-e.start),"undefined"!=typeof l.value.end?(c[1].css("left",(0,a.getPoint)(i,o,l.value.end-e.start)+"px"),d.handle1=(0,a.getPoint)(i,o,l.value.end-e.start)):(c[1].css("left",f+"px"),d.handle1=f),(0,a.setHintPosition)(s,c[0],c[1]),(0,a.setSelction)(n,c[0],c[1]))};t.refresh=function(e,t,n,i,o){var r=l(t),s=r.$slider,u=r.$track,f=r.$hint,v=r.$selection,p=n.end-n.start,h=s.prop("clientWidth"),m=(0,a.getPoint)(p,h,0),g=(0,a.getPoint)(p,h,n.end-n.start);return d(n,u,p,h,f,e,o,i),c(n,u,v,p,h,f,e,o,i),(0,a.setValue)(p,h,n.decimals,e.value,i[0],i[1],n),(0,a.setOutput)(e,n),{$track:u,$hint:f,$selection:v,len:p,width:h,minPoint:m,maxPoint:g}},t.initClick=function(e,t,n,i,o,r,u,l,d){t.on("click",function(t){if(t.target.classList.contains("slider-track")||t.target.classList.contains("slider-selection")){var c=(0,s.getEvent)(t),f=t.target.classList.contains("slider-track")?t.target:t.target.parentNode,v=c.clientX-f.getBoundingClientRect().left;if(1===n.length)n[0].css("left",v+"px"),(0,a.setHintPosition)(i,n[0],n[1]),d.handle0=(0,a.getMovement)(n[0]),l.$apply(function(){(0,a.setValue)(o,r,u.decimals,l.value,n[0],n[1],u),(0,a.setOutput)(l,u)});else{var p=n.reduce(function(e,t){return(0,a.getMovement)(t)>(0,a.getMovement)(e)?t:e}),h=n.reduce(function(e,t){return(0,a.getMovement)(t)<(0,a.getMovement)(e)?t:e});(0,a.getMovement)(p)<v?(p.css("left",v+"px"),d[p.attr("id")]=(0,a.getMovement)(p)):(0,a.getMovement)(h)>v?(h.css("left",v+"px"),d[h.attr("id")]=(0,a.getMovement)(h)):(0,a.getMovement)(p)-v<v-(0,a.getMovement)(h)?(p.css("left",v+"px"),d[p.attr("id")]=(0,a.getMovement)(p)):(0,a.getMovement)(p)-v>=v-(0,a.getMovement)(h)&&(h.css("left",v+"px"),d[h.attr("id")]=(0,a.getMovement)(h)),(0,a.setHintPosition)(i,n[0],n[1]),l.$apply(function(){(0,a.setValue)(o,r,u.decimals,l.value,n[0],n[1],u),(0,a.setOutput)(l,u)}),(0,a.setSelction)(e,n[0],n[1])}}})}},function(e,t){}])});
{
"name": "angular-slider-easy",
"version": "1.0.8",
"version": "1.1.0",
"description": "An angular slider directive aim to ease the way to build up friendly app",

@@ -9,3 +9,23 @@ "repository": {

},
"main": "./src/angular-slider-easy.js",
"main": "./dist/angular-slider-easy.js",
"scripts": {
"start": "webpack-dev-server --content-base build/ --hot --inline --debug --devtool source-map",
"dist": "rm -rf dist/; webpack --config webpack.config.prod.js",
"prepublish": "npm run dist"
},
"files": [
"dist/angular-slider-easy.js",
"dist/angular-slider-easy.min.js",
"dist/angular-slider-easy.css",
"src/style/oper.js",
"src/utils/detect.js",
"src/utils/event.js",
"src/utils/throttle.js",
"src/validator/options.js",
"src/angular-slider-easy.less",
"src/defaults.js",
"src/index.js",
"src/slider.js",
"src/variables.less"
],
"keywords": [

@@ -22,10 +42,18 @@ "angularjs",

"devDependencies": {
"gulp": "^3.9.0",
"gulp-autoprefixer": "^3.1.0",
"gulp-less": "^3.0.5",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.5.1",
"gulp-webserver": "^0.9.1",
"merge-stream": "^1.0.0"
"autoprefixer": "^6.3.6",
"babel-core": "^6.10.4",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"less-loader": "^2.2.3",
"postcss-loader": "^0.9.1",
"style-loader": "^0.13.1",
"unminified-webpack-plugin": "^1.0.1",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
},
"peerDependencies": {
"angular": "^1.4.7"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc