UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

106 lines 3.54 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.directives').directive('slider', [ 'cultureService', function (cultureService) { return { restrict: 'E', replace: true, scope: { tag: '<?', disabled: '=?', visible: '=?', cssClass: '=?', step: '=?', min: '=?', max: '=?', from: '=?', to: '=?', dual: '=?', model: '=?' }, templateUrl: '/templates/framework/directives/slider/template.html', link: function (scope, element, attr) { scope.vm = { instance: null }; scope.vm.init = function () { if (angular.isUndefined(scope.disabled)) { scope.disabled = false; } if (angular.isUndefined(scope.visible)) { scope.visible = true; } if (angular.isUndefined(scope.cssClass)) { scope.cssClass = ''; } if (angular.isUndefined(scope.min)) { scope.min = 0; } if (angular.isUndefined(scope.max)) { scope.max = 100; } if (angular.isUndefined(scope.step)) { scope.step = 10; } if (angular.isUndefined(scope.model)) { scope.model = 0; } if (angular.isUndefined(scope.dual)) { scope.dual = false; } scope.vm.bind(); }; scope.vm.update = function (data) { if (scope.disabled || !scope.vm.instance) return; scope.min = data.min; scope.max = data.max; scope.from = data.from; scope.to = data.to; scope.model = data.from; }; scope.vm.updateBack = function (data) { if (scope.disabled || !scope.vm.instance) return; scope.vm.instance.update(data); }; scope.vm.bind = function () { element.find('input').ionRangeSlider({ min: scope.min, max: scope.max, from: scope.from || scope.model, to: scope.dual ? scope.to : undefined, type: scope.dual ? 'double' : 'single', onStart: scope.vm.update, onChange: scope.vm.update, step: scope.step, disable: scope.disabled, prettify: function (num) { if (!cultureService.rtl) return num; var tmp_min = scope.min, tmp_max = scope.max, tmp_num = num; if (scope.min < 0) { tmp_min = 0; tmp_max = scope.max - scope.min; tmp_num = num - scope.min; tmp_num = tmp_max - tmp_num; return tmp_num + scope.min; } else { num = scope.max - num; return num; } } }); scope.$watch('disabled', function (val) { scope.vm.updateBack({ disable: val }); }); scope.vm.instance = element.find('input').data('ionRangeSlider'); scope.$on('$destroy', function () { scope.vm.instance.destroy(); }); }; scope.vm.init(); } }; } ]); }(jQuery, angular, _, window, document));