BigW Consortium Gitlab

labels.js 1.5 KB
Newer Older
Fatih Acet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
(function() {
  var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  this.Labels = (function() {
    function Labels() {
      this.setSuggestedColor = bind(this.setSuggestedColor, this);
      this.updateColorPreview = bind(this.updateColorPreview, this);
      var form;
      form = $('.label-form');
      this.cleanBinding();
      this.addBinding();
      this.updateColorPreview();
    }

    Labels.prototype.addBinding = function() {
      $(document).on('click', '.suggest-colors a', this.setSuggestedColor);
      return $(document).on('input', 'input#label_color', this.updateColorPreview);
    };

    Labels.prototype.cleanBinding = function() {
      $(document).off('click', '.suggest-colors a');
      return $(document).off('input', 'input#label_color');
    };

    Labels.prototype.updateColorPreview = function() {
      var previewColor;
      previewColor = $('input#label_color').val();
      return $('div.label-color-preview').css('background-color', previewColor);
29
    // Updates the the preview color with the hex-color input
Fatih Acet committed
30 31
    };

32
    // Updates the preview color with a click on a suggested color
Fatih Acet committed
33 34 35 36 37
    Labels.prototype.setSuggestedColor = function(e) {
      var color;
      color = $(e.currentTarget).data('color');
      $('input#label_color').val(color);
      this.updateColorPreview();
38
      // Notify the form, that color has changed
Fatih Acet committed
39 40 41 42 43 44 45 46 47
      $('.label-form').trigger('keyup');
      return e.preventDefault();
    };

    return Labels;

  })();

}).call(this);