/
BackgroundPicker.js
64 lines (63 loc) · 2 KB
/
BackgroundPicker.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Generated by CoffeeScript 1.2.1-pre
define(["vendor/backbone", "./Templates", "css!./res/css/BackgroundPicker.css"], function(Backbone, Templates, empty) {
var gradOptions;
gradOptions = {
type: function(value) {
return this._updatePicker({
type: value
});
},
direction: function(value) {
return this._updatePicker({
fillDirection: value
});
}
};
return Backbone.View.extend({
className: "backgroundPicker modal",
events: {
"click .ok": "okClicked",
"click [data-option]": "optionChosen"
},
initialize: function() {},
show: function(cb, bgOpts) {
this.$el.modal("show");
if (bgOpts != null) this._updatePicker(bgOpts);
return this.cb = cb;
},
_updatePicker: function(bgOpts) {
return this.$gradientPicker.gradientPicker("update", bgOpts);
},
_updateGradientPreview: function(styles) {
this.$gradientPreview.css("background-image", styles[0]);
return this.$gradientPreview.css("background-image", styles[1]);
},
okClicked: function() {
this.$el.modal("hide");
return this.cb(this.$gradientPicker.gradientPicker("currentState"));
},
optionChosen: function(e) {
var option, value;
option = e.currentTarget.dataset.option;
value = e.target.dataset.value;
return gradOptions[option].call(this, value);
},
render: function() {
var bgOpts,
_this = this;
this.$el.html(Templates.BackgroundPicker());
this.$el.modal();
this.$gradientPicker = this.$el.find(".gradientPicker");
this.$gradientPreview = this.$el.find(".gradientPreview");
this.$gradientPicker.css("width", 250);
bgOpts = this.options.bgOpts || {};
bgOpts.change = function(points, styles) {
return _this._updateGradientPreview(styles);
};
this.$gradientPicker.gradientPicker(bgOpts);
this.$el.modal("hide");
this.$el.find(".dropdown-toggle").dropdown();
return this.$el;
}
});
});