2015-07-31 17:11:55 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
/* jshint validthis: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sgColorPicker - Color picker widget
|
|
|
|
* @restrict element
|
|
|
|
* @param {function} sgOnSelect - the function to call when clicking on a color.
|
|
|
|
* One variable is available: color.
|
|
|
|
* @ngInject
|
|
|
|
* @example:
|
|
|
|
|
|
|
|
<sg-color-picker sg-on-select="properties.calendar.color = color"></sg-color-picker>
|
|
|
|
*/
|
2015-10-15 21:10:37 +02:00
|
|
|
function sgColorPicker() {
|
2015-07-31 17:11:55 +02:00
|
|
|
return {
|
|
|
|
restrict: 'E',
|
2015-10-15 21:10:37 +02:00
|
|
|
require: 'ngModel',
|
2015-07-31 17:11:55 +02:00
|
|
|
template: [
|
|
|
|
'<md-menu>',
|
2015-10-15 21:10:37 +02:00
|
|
|
' <md-button class="md-icon-button"',
|
2015-07-31 17:11:55 +02:00
|
|
|
' label:aria-label="Options"',
|
2015-10-15 21:10:37 +02:00
|
|
|
' ng-style="{ \'background-color\': sgColor }"',
|
2015-07-31 17:11:55 +02:00
|
|
|
' ng-click="$mdOpenMenu()"',
|
|
|
|
' md-menu-origin="md-menu-origin">',
|
2015-12-10 17:45:12 +01:00
|
|
|
' <md-icon ng-style="{ color: sgIconColor }">color_lens</md-icon>',
|
2015-07-31 17:11:55 +02:00
|
|
|
' </md-button>',
|
2015-11-17 21:15:39 +01:00
|
|
|
' <md-menu-content width="3">',
|
|
|
|
' <md-content class="md-padding">',
|
|
|
|
' <md-grid-list class="sg-color-picker" md-cols="7" md-row-height="1:1" md-gutter="0.5em">',
|
|
|
|
' <md-grid-tile ng-repeat="color in ::sgColors track by $index"',
|
|
|
|
' ng-style="{ \'background-color\': color }"',
|
|
|
|
' ng-class="{ selected: color == sgColor }"',
|
|
|
|
' ng-click="setColor(color)"><md-icon ng-style="{ color: color }">check_box</md-icon></md-grid-tile>',
|
|
|
|
' </md-grid-list>',
|
|
|
|
' </md-content>',
|
2015-07-31 17:11:55 +02:00
|
|
|
' </md-menu-content>',
|
|
|
|
'</md-menu>'
|
|
|
|
].join(''),
|
|
|
|
replace: true,
|
|
|
|
controller: sgColorPickerController,
|
|
|
|
link: link
|
|
|
|
};
|
|
|
|
|
2015-10-15 21:10:37 +02:00
|
|
|
function link(scope, iElement, iAttr, ngModelController) {
|
|
|
|
// Expose ng-model value to scope
|
|
|
|
ngModelController.$render = function() {
|
|
|
|
scope.sgColor = ngModelController.$viewValue;
|
2015-12-10 17:45:12 +01:00
|
|
|
scope.sgIconColor = contrast(ngModelController.$viewValue);
|
2015-10-15 21:10:37 +02:00
|
|
|
};
|
2015-07-31 17:11:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-10-15 21:10:37 +02:00
|
|
|
sgColorPickerController.$inject = ['$scope', '$element', 'sgColors'];
|
|
|
|
function sgColorPickerController($scope, $element, sgColors) {
|
|
|
|
var ngModelController = $element.controller('ngModel');
|
2015-07-31 17:11:55 +02:00
|
|
|
|
2015-10-15 21:10:37 +02:00
|
|
|
$scope.sgColors = sgColors.selection;
|
|
|
|
$scope.setColor = function(color) {
|
|
|
|
// Update scope value and ng-model
|
|
|
|
$scope.sgColor = color;
|
2015-12-10 17:45:12 +01:00
|
|
|
$scope.sgIconColor = contrast(color);
|
2015-10-15 21:10:37 +02:00
|
|
|
ngModelController.$setViewValue(color);
|
2015-07-31 17:11:55 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.Common')
|
|
|
|
.directive('sgColorPicker', sgColorPicker);
|
|
|
|
})();
|