spectrum_picker.js 1.0 KB

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