spectrumPicker.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. define([
  2. 'angular',
  3. 'spectrum'
  4. ],
  5. function (angular) {
  6. 'use strict';
  7. angular
  8. .module('grafana.directives')
  9. .directive('spectrumPicker', function() {
  10. return {
  11. restrict: 'E',
  12. require: 'ngModel',
  13. scope: false,
  14. replace: true,
  15. template: "<span><input class='input-small' /></span>",
  16. link: function(scope, element, attrs, ngModel) {
  17. var input = element.find('input');
  18. var options = angular.extend({
  19. showAlpha: true,
  20. showButtons: false,
  21. color: ngModel.$viewValue,
  22. change: function(color) {
  23. scope.$apply(function() {
  24. ngModel.$setViewValue(color.toRgbString());
  25. });
  26. }
  27. }, scope.$eval(attrs.options));
  28. ngModel.$render = function() {
  29. input.spectrum('set', ngModel.$viewValue || '');
  30. };
  31. input.spectrum(options);
  32. scope.$on('$destroy', function() {
  33. input.spectrum('destroy');
  34. });
  35. }
  36. };
  37. });
  38. });