pip-webui
Version:
HTML5 UI for LOB applications
72 lines (57 loc) • 2.25 kB
JavaScript
/**
* @file Color picker control
* @copyright Digital Living Software Corp. 2014-2016
*/
(function (angular, _) {
'use strict';
var thisModule = angular.module('pipColorPicker', ['pipUtils', 'pipFocused', 'pipBasicControls.Templates']);
thisModule.directive('pipColorPicker',
function () {
return {
restrict: 'EA',
scope: {
ngDisabled: '&',
colors: '=pipColors',
currentColor: '=ngModel',
colorChange: '&ngChange'
},
templateUrl: 'color_picker/color_picker.html',
controller: 'pipColorPickerController'
};
}
);
thisModule.controller('pipColorPickerController',
function ($scope, $element, $attrs, $timeout) {
var
DEFAULT_COLORS = ['purple', 'lightgreen', 'green', 'darkred', 'pink', 'yellow', 'cyan'];
$scope.class = $attrs.class || '';
if (!$scope.colors || _.isArray($scope.colors) && $scope.colors.length === 0) {
$scope.colors = DEFAULT_COLORS;
}
$scope.currentColor = $scope.currentColor || $scope.colors[0];
$scope.currentColorIndex = $scope.colors.indexOf($scope.currentColor);
$scope.disabled = function () {
if ($scope.ngDisabled) {
return $scope.ngDisabled();
}
return true;
};
$scope.selectColor = function (index) {
if ($scope.disabled()) {
return;
}
$scope.currentColorIndex = index;
$scope.currentColor = $scope.colors[$scope.currentColorIndex];
$timeout(function () {
$scope.$apply();
});
if ($scope.colorChange) {
$scope.colorChange();
}
};
$scope.enterSpacePress = function (event) {
$scope.selectColor(event.index);
};
}
);
})(window.angular, window._);