2017-01-11 23:27:41 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, vars-on-top, no-unused-vars, max-len */
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-01-11 23:27:41 -05:00
|
|
|
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
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);
|
2016-07-26 23:32:10 -04:00
|
|
|
// Updates the the preview color with the hex-color input
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
2016-07-26 23:32:10 -04:00
|
|
|
// Updates the preview color with a click on a suggested color
|
2016-07-24 16:45:11 -04:00
|
|
|
Labels.prototype.setSuggestedColor = function(e) {
|
|
|
|
var color;
|
|
|
|
color = $(e.currentTarget).data('color');
|
|
|
|
$('input#label_color').val(color);
|
|
|
|
this.updateColorPreview();
|
2016-07-26 23:32:10 -04:00
|
|
|
// Notify the form, that color has changed
|
2016-07-24 16:45:11 -04:00
|
|
|
$('.label-form').trigger('keyup');
|
|
|
|
return e.preventDefault();
|
|
|
|
};
|
|
|
|
|
|
|
|
return Labels;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|