| author | durandn |
| Tue, 07 Jun 2016 10:46:20 +0200 | |
| changeset 612 | aa4987fede52 |
| parent 435 | e529b633c339 |
| permissions | -rw-r--r-- |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
1 |
|
| 284 | 2 |
define(['jquery', 'underscore'], function ($, _) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
3 |
'use strict'; |
| 284 | 4 |
|
5 |
/* Rkns.Renderer._BaseRepresentation Class */ |
|
6 |
||
7 |
/* In Renkan, a "Representation" is a sort of ViewModel (in the MVVM paradigm) and bridges the gap between |
|
8 |
* models (written with Backbone.js) and the view (written with Paper.js) |
|
9 |
* Renkan's representations all inherit from Rkns.Renderer._BaseRepresentation '*/ |
|
10 |
||
11 |
var _BaseRepresentation = function(_renderer, _model) { |
|
12 |
if (typeof _renderer !== "undefined") { |
|
13 |
this.renderer = _renderer; |
|
14 |
this.renkan = _renderer.renkan; |
|
15 |
this.project = _renderer.renkan.project; |
|
16 |
this.options = _renderer.renkan.options; |
|
17 |
this.model = _model; |
|
18 |
if (this.model) { |
|
19 |
var _this = this; |
|
20 |
this._changeBinding = function() { |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
21 |
_this.redraw({change: true}); |
| 284 | 22 |
}; |
23 |
this._removeBinding = function() { |
|
24 |
_renderer.removeRepresentation(_this); |
|
| 433 | 25 |
_.defer(function() { |
| 284 | 26 |
_renderer.redraw(); |
| 433 | 27 |
}); |
| 284 | 28 |
}; |
29 |
this._selectBinding = function() { |
|
30 |
_this.select(); |
|
31 |
}; |
|
32 |
this._unselectBinding = function() { |
|
33 |
_this.unselect(); |
|
34 |
}; |
|
35 |
this.model.on("change", this._changeBinding ); |
|
36 |
this.model.on("remove", this._removeBinding ); |
|
37 |
this.model.on("select", this._selectBinding ); |
|
38 |
this.model.on("unselect", this._unselectBinding ); |
|
39 |
} |
|
40 |
} |
|
41 |
}; |
|
42 |
||
43 |
/* Rkns.Renderer._BaseRepresentation Methods */ |
|
44 |
||
45 |
_(_BaseRepresentation.prototype).extend({ |
|
46 |
_super: function(_func) { |
|
47 |
return _BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); |
|
48 |
}, |
|
49 |
redraw: function() {}, |
|
50 |
moveTo: function() {}, |
|
| 396 | 51 |
show: function() { return "BaseRepresentation.show"; }, |
| 284 | 52 |
hide: function() {}, |
53 |
select: function() { |
|
54 |
if (this.model) { |
|
55 |
this.model.trigger("selected"); |
|
56 |
} |
|
57 |
}, |
|
58 |
unselect: function() { |
|
59 |
if (this.model) { |
|
60 |
this.model.trigger("unselected"); |
|
61 |
} |
|
62 |
}, |
|
63 |
highlight: function() {}, |
|
64 |
unhighlight: function() {}, |
|
65 |
mousedown: function() {}, |
|
66 |
mouseup: function() { |
|
67 |
if (this.model) { |
|
68 |
this.model.trigger("clicked"); |
|
69 |
} |
|
70 |
}, |
|
71 |
destroy: function() { |
|
72 |
if (this.model) { |
|
73 |
this.model.off("change", this._changeBinding ); |
|
74 |
this.model.off("remove", this._removeBinding ); |
|
75 |
this.model.off("select", this._selectBinding ); |
|
76 |
this.model.off("unselect", this._unselectBinding ); |
|
77 |
} |
|
78 |
} |
|
| 433 | 79 |
}).value(); |
| 284 | 80 |
|
81 |
/* End of Rkns.Renderer._BaseRepresentation Class */ |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
82 |
|
| 284 | 83 |
return _BaseRepresentation; |
84 |
||
85 |
}); |