| author | ymh <ymh.work@gmail.com> |
| Fri, 16 May 2014 14:09:57 +0200 | |
| changeset 293 | fba23fde14ba |
| parent 284 | fa8035885814 |
| child 396 | b51c25ef4292 |
| 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() { |
|
21 |
_this.redraw(); |
|
22 |
}; |
|
23 |
this._removeBinding = function() { |
|
24 |
_renderer.removeRepresentation(_this); |
|
25 |
_(function() { |
|
26 |
_renderer.redraw(); |
|
27 |
}).defer(); |
|
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() {}, |
|
51 |
show: function() { return "chaud cacao"; }, |
|
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 |
} |
|
79 |
}); |
|
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 |
}); |