-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (52 loc) · 1.81 KB
/
app.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
65
App = function(){};
App.prototype.init = function() {
this.add_control_listeners();
this.content = $('#content');
this._zindex = 10;
$('#controls .update_floor_size').trigger('click');
};
App.prototype.add_control_listeners = function() {
$('#controls .add_object').on('click', this.add_object.bind(this));
$('#controls .update_floor_size').on('click', this.update_floor_size.bind(this));
$('#content').on('click', 'button', this.handle_object_buttons.bind(this));
};
App.prototype.add_object = function(event) {
$( "#dialog" ).dialog({
buttons: [{
text: "OK",
click: this.generate_object.bind(this)
}]
});
};
App.prototype.generate_object = function(event) {
var button_container = $('<div>');
button_container.append($('<button>', {text: '+'}));
button_container.append($('<button>', {text: '-'}));
button_container.append($('<button>', {text: 'X'}));
var el = $('<div>', {'class': 'object'});
el.append(button_container);
el.append($('<div>', {text: $('#dialog .name').val()}));
el.appendTo('#content');
el.css('z-index', this.next_zindex());
el.offset($('#content').offset());
el.height(this.calc_pixels('#dialog .height'));
el.width(this.calc_pixels('#dialog .width'));
el.draggable();
$("#dialog").dialog("close");
};
App.prototype.handle_object_buttons = function(event) {
var obj = $(event.target).closest('.object');
obj.draggable('destroy');
obj.remove();
};
App.prototype.next_zindex = function() {
return this._zindex++;
};
App.prototype.calc_pixels = function(selector) {
return ($('#controls .factor').val() * $(selector).val()) + 'px';
};
App.prototype.update_floor_size = function(event) {
this.content.height(this.calc_pixels('#controls .height'));
this.content.width(this.calc_pixels('#controls .width'));
};
$(function () {(new App).init()});