20 color: _renkan.options.default_user_color, |
20 color: _renkan.options.default_user_color, |
21 title: _renkan.translate("(unknown user)"), |
21 title: _renkan.translate("(unknown user)"), |
22 get: function(attr) { |
22 get: function(attr) { |
23 return this[attr] || false; |
23 return this[attr] || false; |
24 } |
24 } |
25 } |
25 }; |
26 }, |
26 }, |
27 _BOOKMARKLET_CODE: function(_renkan) { |
27 _BOOKMARKLET_CODE: function(_renkan) { |
28 return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">" |
28 return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">" |
29 + _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") |
29 + _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") |
30 + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();" |
30 + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();"; |
31 }, |
31 }, |
32 shortenText : function(_text, _maxlength) { |
32 shortenText : function(_text, _maxlength) { |
33 return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text); |
33 return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text); |
34 }, |
34 }, |
35 drawEditBox : function(_options, _coords, _path, _xmargin, _selector) { |
35 drawEditBox : function(_options, _coords, _path, _xmargin, _selector) { |
36 _selector.css({ |
36 _selector.css({ |
37 width: ( _options.tooltip_width - 2* _options.tooltip_padding ), |
37 width: ( _options.tooltip_width - 2* _options.tooltip_padding ), |
38 }) |
38 }); |
39 var _height = _selector.outerHeight() + 2* _options.tooltip_padding, |
39 var _height = _selector.outerHeight() + 2* _options.tooltip_padding, |
40 _isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
40 _isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
41 _left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ), |
41 _left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ), |
42 _right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ), |
42 _right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ), |
43 _top = _coords.y - _height / 2; |
43 _top = _coords.y - _height / 2; |
86 this.model = _model; |
86 this.model = _model; |
87 if (this.model) { |
87 if (this.model) { |
88 var _this = this; |
88 var _this = this; |
89 this._changeBinding = function() { |
89 this._changeBinding = function() { |
90 _this.redraw(); |
90 _this.redraw(); |
91 } |
91 }; |
92 this._removeBinding = function() { |
92 this._removeBinding = function() { |
93 _renderer.removeRepresentation(_this); |
93 _renderer.removeRepresentation(_this); |
94 _(function() { |
94 _(function() { |
95 _renderer.redraw() |
95 _renderer.redraw(); |
96 }).defer(); |
96 }).defer(); |
97 } |
97 }; |
98 this._selectBinding = function() { |
98 this._selectBinding = function() { |
99 _this.select(); |
99 _this.select(); |
100 } |
100 }; |
101 this._unselectBinding = function() { |
101 this._unselectBinding = function() { |
102 _this.unselect(); |
102 _this.unselect(); |
103 } |
103 }; |
104 this.model.on("change", this._changeBinding ); |
104 this.model.on("change", this._changeBinding ); |
105 this.model.on("remove", this._removeBinding ); |
105 this.model.on("remove", this._removeBinding ); |
106 this.model.on("select", this._selectBinding ); |
106 this.model.on("select", this._selectBinding ); |
107 this.model.on("unselect", this._unselectBinding ); |
107 this.model.on("unselect", this._unselectBinding ); |
108 } |
108 } |
109 } |
109 } |
110 } |
110 }; |
111 |
111 |
112 Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) { |
112 Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) { |
113 Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); |
113 Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); |
114 } |
114 }; |
115 |
115 |
116 Rkns.Renderer._BaseRepresentation.prototype.redraw = function() {} |
116 Rkns.Renderer._BaseRepresentation.prototype.redraw = function() {}; |
117 |
117 |
118 Rkns.Renderer._BaseRepresentation.prototype.moveTo = function() {} |
118 Rkns.Renderer._BaseRepresentation.prototype.moveTo = function() {}; |
119 |
119 |
120 Rkns.Renderer._BaseRepresentation.prototype.show = function() {} |
120 Rkns.Renderer._BaseRepresentation.prototype.show = function() {}; |
121 |
121 |
122 Rkns.Renderer._BaseRepresentation.prototype.hide = function() {} |
122 Rkns.Renderer._BaseRepresentation.prototype.hide = function() {}; |
123 |
123 |
124 Rkns.Renderer._BaseRepresentation.prototype.select = function() { |
124 Rkns.Renderer._BaseRepresentation.prototype.select = function() { |
125 if (this.model) { |
125 if (this.model) { |
126 this.model.trigger("selected"); |
126 this.model.trigger("selected"); |
127 } |
127 } |
128 } |
128 }; |
129 |
129 |
130 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() { |
130 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() { |
131 if (this.model) { |
131 if (this.model) { |
132 this.model.trigger("unselected"); |
132 this.model.trigger("unselected"); |
133 } |
133 } |
134 } |
134 }; |
135 |
135 |
136 Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {} |
136 Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {}; |
137 |
137 |
138 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {} |
138 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {}; |
139 |
139 |
140 Rkns.Renderer._BaseRepresentation.prototype.mousedown = function() {} |
140 Rkns.Renderer._BaseRepresentation.prototype.mousedown = function() {}; |
141 |
141 |
142 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() { |
142 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() { |
143 if (this.model) { |
143 if (this.model) { |
144 this.model.trigger("clicked"); |
144 this.model.trigger("clicked"); |
145 } |
145 } |
146 } |
146 }; |
147 |
147 |
148 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() { |
148 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() { |
149 if (this.model) { |
149 if (this.model) { |
150 this.model.off("change", this._changeBinding ); |
150 this.model.off("change", this._changeBinding ); |
151 this.model.off("remove", this._removeBinding ); |
151 this.model.off("remove", this._removeBinding ); |
152 this.model.off("select", this._selectBinding ); |
152 this.model.off("select", this._selectBinding ); |
153 this.model.off("unselect", this._unselectBinding ); |
153 this.model.off("unselect", this._unselectBinding ); |
154 } |
154 } |
155 } |
155 }; |
156 |
156 |
157 /* */ |
157 /* */ |
158 |
158 |
159 Rkns.Renderer._BaseButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
159 Rkns.Renderer._BaseButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
160 |
160 |
161 Rkns.Renderer._BaseButton.prototype.moveTo = function(_pos) { |
161 Rkns.Renderer._BaseButton.prototype.moveTo = function(_pos) { |
162 this.sector.moveTo(_pos); |
162 this.sector.moveTo(_pos); |
163 } |
163 }; |
164 |
164 |
165 Rkns.Renderer._BaseButton.prototype.show = function() { |
165 Rkns.Renderer._BaseButton.prototype.show = function() { |
166 this.sector.show(); |
166 this.sector.show(); |
167 } |
167 }; |
168 |
168 |
169 Rkns.Renderer._BaseButton.prototype.hide = function() { |
169 Rkns.Renderer._BaseButton.prototype.hide = function() { |
170 this.sector.hide(); |
170 this.sector.hide(); |
171 } |
171 }; |
172 |
172 |
173 Rkns.Renderer._BaseButton.prototype.select = function() { |
173 Rkns.Renderer._BaseButton.prototype.select = function() { |
174 this.sector.select(); |
174 this.sector.select(); |
175 } |
175 }; |
176 |
176 |
177 Rkns.Renderer._BaseButton.prototype.unselect = function(_newTarget) { |
177 Rkns.Renderer._BaseButton.prototype.unselect = function(_newTarget) { |
178 this.sector.unselect(); |
178 this.sector.unselect(); |
179 if (!_newTarget || (_newTarget !== this.source_representation && _newTarget.source_representation !== this.source_representation)) { |
179 if (!_newTarget || (_newTarget !== this.source_representation && _newTarget.source_representation !== this.source_representation)) { |
180 this.source_representation.unselect(); |
180 this.source_representation.unselect(); |
181 } |
181 } |
182 } |
182 }; |
183 |
183 |
184 Rkns.Renderer._BaseButton.prototype.destroy = function() { |
184 Rkns.Renderer._BaseButton.prototype.destroy = function() { |
185 this.sector.destroy(); |
185 this.sector.destroy(); |
186 } |
186 }; |
187 |
187 |
188 /* */ |
188 /* */ |
189 |
189 |
190 Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
190 Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
191 |
191 |
226 this.renderer.minimap.node_layer.activate(); |
226 this.renderer.minimap.node_layer.activate(); |
227 this.minimap_circle = new paper.Path.Circle([0, 0], 1); |
227 this.minimap_circle = new paper.Path.Circle([0, 0], 1); |
228 this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation; |
228 this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation; |
229 this.renderer.minimap.node_group.addChild(this.minimap_circle); |
229 this.renderer.minimap.node_group.addChild(this.minimap_circle); |
230 } |
230 } |
231 } |
231 }; |
232 |
232 |
233 Rkns.Renderer.Node.prototype.redraw = function(_dontRedrawEdges) { |
233 Rkns.Renderer.Node.prototype.redraw = function(_dontRedrawEdges) { |
234 var _model_coords = new paper.Point(this.model.get("position")), |
234 var _model_coords = new paper.Point(this.model.get("position")), |
235 _baseRadius = this.options.node_size_base * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP); |
235 _baseRadius = this.options.node_size_base * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP); |
236 if (!this.is_dragging || !this.paper_coords) { |
236 if (!this.is_dragging || !this.paper_coords) { |
421 if (this.renderer.minimap) { |
421 if (this.renderer.minimap) { |
422 this.minimap_circle.strokeColor = undefined; |
422 this.minimap_circle.strokeColor = undefined; |
423 } |
423 } |
424 this.super("unselect"); |
424 this.super("unselect"); |
425 } |
425 } |
426 } |
426 }; |
427 |
427 |
428 Rkns.Renderer.Node.prototype.highlight = function() { |
428 Rkns.Renderer.Node.prototype.highlight = function() { |
429 if (this.highlighted) { |
429 if (this.highlighted) { |
430 return; |
430 return; |
431 } |
431 } |
432 this.highlighted = true; |
432 this.highlighted = true; |
433 this.redraw(); |
433 this.redraw(); |
434 this.renderer.throttledPaperDraw(); |
434 this.renderer.throttledPaperDraw(); |
435 } |
435 }; |
436 |
436 |
437 Rkns.Renderer.Node.prototype.unhighlight = function() { |
437 Rkns.Renderer.Node.prototype.unhighlight = function() { |
438 if (!this.highlighted) { |
438 if (!this.highlighted) { |
439 return; |
439 return; |
440 } |
440 } |
441 this.highlighted = false; |
441 this.highlighted = false; |
442 this.redraw(); |
442 this.redraw(); |
443 this.renderer.throttledPaperDraw(); |
443 this.renderer.throttledPaperDraw(); |
444 } |
444 }; |
445 |
445 |
446 Rkns.Renderer.Node.prototype.saveCoords = function() { |
446 Rkns.Renderer.Node.prototype.saveCoords = function() { |
447 var _coords = this.renderer.toModelCoords(this.paper_coords), |
447 var _coords = this.renderer.toModelCoords(this.paper_coords), |
448 _data = { |
448 _data = { |
449 position: { |
449 position: { |
537 this.minimap_line = new paper.Path(); |
537 this.minimap_line = new paper.Path(); |
538 this.minimap_line.add([0,0],[0,0]); |
538 this.minimap_line.add([0,0],[0,0]); |
539 this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation; |
539 this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation; |
540 this.minimap_line.strokeWidth = 1; |
540 this.minimap_line.strokeWidth = 1; |
541 } |
541 } |
542 } |
542 }; |
543 |
543 |
544 Rkns.Renderer.Edge.prototype.redraw = function() { |
544 Rkns.Renderer.Edge.prototype.redraw = function() { |
545 this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
545 this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
546 this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
546 this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
547 if (!this.from_representation || !this.to_representation) { |
547 if (!this.from_representation || !this.to_representation) { |
626 if (this.renderer.minimap) { |
626 if (this.renderer.minimap) { |
627 this.minimap_line.strokeColor = _color; |
627 this.minimap_line.strokeColor = _color; |
628 this.minimap_line.segments[0].point = this.renderer.toMinimapCoords(new paper.Point(this.from_representation.model.get("position"))); |
628 this.minimap_line.segments[0].point = this.renderer.toMinimapCoords(new paper.Point(this.from_representation.model.get("position"))); |
629 this.minimap_line.segments[1].point = this.renderer.toMinimapCoords(new paper.Point(this.to_representation.model.get("position"))); |
629 this.minimap_line.segments[1].point = this.renderer.toMinimapCoords(new paper.Point(this.to_representation.model.get("position"))); |
630 } |
630 } |
631 } |
631 }; |
632 |
632 |
633 Rkns.Renderer.Edge.prototype.openEditor = function() { |
633 Rkns.Renderer.Edge.prototype.openEditor = function() { |
634 this.renderer.removeRepresentationsOfType("editor"); |
634 this.renderer.removeRepresentationsOfType("editor"); |
635 var _editor = this.renderer.addRepresentation("EdgeEditor",null); |
635 var _editor = this.renderer.addRepresentation("EdgeEditor",null); |
636 _editor.source_representation = this; |
636 _editor.source_representation = this; |
637 _editor.draw(); |
637 _editor.draw(); |
638 } |
638 }; |
639 |
639 |
640 Rkns.Renderer.Edge.prototype.select = function() { |
640 Rkns.Renderer.Edge.prototype.select = function() { |
641 this.selected = true; |
641 this.selected = true; |
642 this.line.strokeWidth = this.options.selected_edge_stroke_width; |
642 this.line.strokeWidth = this.options.selected_edge_stroke_width; |
643 if (this.renderer.isEditable()) { |
643 if (this.renderer.isEditable()) { |
683 } |
683 } |
684 this.model.trigger("clicked"); |
684 this.model.trigger("clicked"); |
685 } |
685 } |
686 this.renderer.click_target = null; |
686 this.renderer.click_target = null; |
687 this.renderer.is_dragging = false; |
687 this.renderer.is_dragging = false; |
688 } |
688 }; |
689 |
689 |
690 Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
690 Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
691 if (this.options.editor_mode) { |
691 if (this.options.editor_mode) { |
692 if (!this.options.read_only) { |
692 if (!this.options.read_only) { |
693 this.from_representation.paperShift(_delta); |
693 this.from_representation.paperShift(_delta); |
694 this.to_representation.paperShift(_delta); |
694 this.to_representation.paperShift(_delta); |
695 } |
695 } |
696 } else { |
696 } else { |
697 this.renderer.paperShift(_delta); |
697 this.renderer.paperShift(_delta); |
698 } |
698 } |
699 } |
699 }; |
700 |
700 |
701 Rkns.Renderer.Edge.prototype.destroy = function() { |
701 Rkns.Renderer.Edge.prototype.destroy = function() { |
702 this.super("destroy"); |
702 this.super("destroy"); |
703 this.line.remove(); |
703 this.line.remove(); |
704 this.arrow.remove(); |
704 this.arrow.remove(); |
795 this.renderer.click_target = null; |
795 this.renderer.click_target = null; |
796 this.renderer.is_dragging = false; |
796 this.renderer.is_dragging = false; |
797 this.renderer.removeRepresentation(this); |
797 this.renderer.removeRepresentation(this); |
798 paper.view.draw(); |
798 paper.view.draw(); |
799 } |
799 } |
800 } |
800 }; |
801 |
801 |
802 Rkns.Renderer.TempEdge.prototype.destroy = function() { |
802 Rkns.Renderer.TempEdge.prototype.destroy = function() { |
803 this.arrow.remove(); |
803 this.arrow.remove(); |
804 this.line.remove(); |
804 this.line.remove(); |
805 } |
805 }; |
806 |
806 |
807 /* */ |
807 /* */ |
808 |
808 |
809 Rkns.Renderer._BaseEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
809 Rkns.Renderer._BaseEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
810 |
810 |
811 Rkns.Renderer._BaseEditor.prototype._init = function() { |
811 Rkns.Renderer._BaseEditor.prototype._init = function() { |
812 this.renderer.buttons_layer.activate(); |
812 this.renderer.buttons_layer.activate(); |
813 this.type = "editor"; |
813 this.type = "editor"; |
814 this.editor_block = new paper.Path(); |
814 this.editor_block = new paper.Path(); |
815 var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
815 var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0];}); |
816 this.editor_block.add.apply(this.editor_block, _pts); |
816 this.editor_block.add.apply(this.editor_block, _pts); |
817 this.editor_block.strokeWidth = this.options.tooltip_border_width; |
817 this.editor_block.strokeWidth = this.options.tooltip_border_width; |
818 this.editor_block.strokeColor = this.options.tooltip_border_color; |
818 this.editor_block.strokeColor = this.options.tooltip_border_color; |
819 this.editor_block.opacity = .8; |
819 this.editor_block.opacity = .8; |
820 this.editor_$ = Rkns.$('<div>') |
820 this.editor_$ = Rkns.$('<div>') |
1239 this.lastSectorInner = 0; |
1239 this.lastSectorInner = 0; |
1240 this.startAngle = -135; |
1240 this.startAngle = -135; |
1241 this.endAngle = 135; |
1241 this.endAngle = 135; |
1242 this.imageName = "revert"; |
1242 this.imageName = "revert"; |
1243 this.text = "Cancel deletion"; |
1243 this.text = "Cancel deletion"; |
1244 } |
1244 }; |
1245 |
1245 |
1246 Rkns.Renderer.NodeRevertButton.prototype.mouseup = function() { |
1246 Rkns.Renderer.NodeRevertButton.prototype.mouseup = function() { |
1247 this.renderer.click_target = null; |
1247 this.renderer.click_target = null; |
1248 this.renderer.is_dragging = false; |
1248 this.renderer.is_dragging = false; |
1249 if (this.renderer.isEditable()) { |
1249 if (this.renderer.isEditable()) { |
1250 this.source_representation.model.unset("delete_scheduled"); |
1250 this.source_representation.model.unset("delete_scheduled"); |
1251 } |
1251 } |
1252 } |
1252 }; |
1253 |
1253 |
1254 /* */ |
1254 /* */ |
1255 |
1255 |
1256 Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton); |
1256 Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton); |
1257 |
1257 |
1307 this.lastSectorInner = 0; |
1307 this.lastSectorInner = 0; |
1308 this.startAngle = -180; |
1308 this.startAngle = -180; |
1309 this.endAngle = -135; |
1309 this.endAngle = -135; |
1310 this.imageName = "shrink"; |
1310 this.imageName = "shrink"; |
1311 this.text = "Shrink"; |
1311 this.text = "Shrink"; |
1312 } |
1312 }; |
1313 |
1313 |
1314 Rkns.Renderer.NodeShrinkButton.prototype.mouseup = function() { |
1314 Rkns.Renderer.NodeShrinkButton.prototype.mouseup = function() { |
1315 var _newsize = -1 + (this.source_representation.model.get("size") || 0); |
1315 var _newsize = -1 + (this.source_representation.model.get("size") || 0); |
1316 this.source_representation.model.set("size", _newsize); |
1316 this.source_representation.model.set("size", _newsize); |
1317 this.source_representation.select(); |
1317 this.source_representation.select(); |
1318 this.select(); |
1318 this.select(); |
1319 paper.view.draw(); |
1319 paper.view.draw(); |
1320 } |
1320 }; |
1321 |
1321 |
1322 /* */ |
1322 /* */ |
1323 |
1323 |
1324 Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton); |
1324 Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton); |
1325 |
1325 |
1326 Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
1326 Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
1327 this.type = "Edge-edit-button"; |
1327 this.type = "Edge-edit-button"; |
1328 this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -270, -90, 1, "edit", this.renkan.translate("Edit")); |
1328 this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -270, -90, 1, "edit", this.renkan.translate("Edit")); |
1329 } |
1329 }; |
1330 |
1330 |
1331 Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
1331 Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
1332 if (!this.renderer.is_dragging) { |
1332 if (!this.renderer.is_dragging) { |
1333 this.source_representation.openEditor(); |
1333 this.source_representation.openEditor(); |
1334 } |
1334 } |
1335 } |
1335 }; |
1336 |
1336 |
1337 /* */ |
1337 /* */ |
1338 |
1338 |
1339 Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton); |
1339 Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton); |
1340 |
1340 |
1341 Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
1341 Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
1342 this.type = "Edge-remove-button"; |
1342 this.type = "Edge-remove-button"; |
1343 this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -90, 90, 1, "remove", this.renkan.translate("Remove")); |
1343 this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -90, 90, 1, "remove", this.renkan.translate("Remove")); |
1344 } |
1344 }; |
1345 |
1345 |
1346 Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
1346 Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
1347 this.renderer.click_target = null; |
1347 this.renderer.click_target = null; |
1348 this.renderer.is_dragging = false; |
1348 this.renderer.is_dragging = false; |
1349 this.renderer.removeRepresentationsOfType("editor"); |
1349 this.renderer.removeRepresentationsOfType("editor"); |
1353 id: delid, |
1353 id: delid, |
1354 time: new Date().valueOf() + this.options.element_delete_delay |
1354 time: new Date().valueOf() + this.options.element_delete_delay |
1355 }); |
1355 }); |
1356 this.source_representation.model.set("delete_scheduled", delid); |
1356 this.source_representation.model.set("delete_scheduled", delid); |
1357 } |
1357 } |
1358 } |
1358 }; |
1359 |
1359 |
1360 /* */ |
1360 /* */ |
1361 |
1361 |
1362 Rkns.Renderer.EdgeRevertButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton); |
1362 Rkns.Renderer.EdgeRevertButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton); |
1363 |
1363 |
1364 Rkns.Renderer.EdgeRevertButton.prototype._init = function() { |
1364 Rkns.Renderer.EdgeRevertButton.prototype._init = function() { |
1365 this.type = "Edge-revert-button"; |
1365 this.type = "Edge-revert-button"; |
1366 this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -135, 135, 1, "revert", this.renkan.translate("Cancel deletion")); |
1366 this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -135, 135, 1, "revert", this.renkan.translate("Cancel deletion")); |
1367 } |
1367 }; |
1368 |
1368 |
1369 Rkns.Renderer.EdgeRevertButton.prototype.mouseup = function() { |
1369 Rkns.Renderer.EdgeRevertButton.prototype.mouseup = function() { |
1370 this.renderer.click_target = null; |
1370 this.renderer.click_target = null; |
1371 this.renderer.is_dragging = false; |
1371 this.renderer.is_dragging = false; |
1372 if (this.renderer.isEditable()) { |
1372 if (this.renderer.isEditable()) { |
1373 this.source_representation.model.unset("delete_scheduled"); |
1373 this.source_representation.model.unset("delete_scheduled"); |
1374 } |
1374 } |
1375 } |
1375 }; |
1376 |
1376 |
1377 /* */ |
1377 /* */ |
1378 |
1378 |
1379 Rkns.Renderer.MiniFrame = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
1379 Rkns.Renderer.MiniFrame = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
1380 |
1380 |
1381 Rkns.Renderer.MiniFrame.prototype.paperShift = function(_delta) { |
1381 Rkns.Renderer.MiniFrame.prototype.paperShift = function(_delta) { |
1382 this.renderer.offset = this.renderer.offset.subtract(_delta.divide(this.renderer.minimap.scale).multiply(this.renderer.scale)); |
1382 this.renderer.offset = this.renderer.offset.subtract(_delta.divide(this.renderer.minimap.scale).multiply(this.renderer.scale)); |
1383 this.renderer.redraw(); |
1383 this.renderer.redraw(); |
1384 } |
1384 }; |
1385 |
1385 |
1386 Rkns.Renderer.MiniFrame.prototype.mouseup = function(_delta) { |
1386 Rkns.Renderer.MiniFrame.prototype.mouseup = function(_delta) { |
1387 this.renderer.click_target = null; |
1387 this.renderer.click_target = null; |
1388 this.renderer.is_dragging = false; |
1388 this.renderer.is_dragging = false; |
1389 } |
1389 }; |
1390 |
1390 |
1391 /* */ |
1391 /* */ |
1392 |
1392 |
1393 Rkns.Renderer.Scene = function(_renkan) { |
1393 Rkns.Renderer.Scene = function(_renkan) { |
1394 this.renkan = _renkan; |
1394 this.renkan = _renkan; |
1417 background_layer: new paper.Layer(), |
1417 background_layer: new paper.Layer(), |
1418 edge_layer: new paper.Layer(), |
1418 edge_layer: new paper.Layer(), |
1419 node_layer: new paper.Layer(), |
1419 node_layer: new paper.Layer(), |
1420 node_group: new paper.Group(), |
1420 node_group: new paper.Group(), |
1421 size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height ) |
1421 size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height ) |
1422 } |
1422 }; |
1423 |
1423 |
1424 this.minimap.background_layer.activate(); |
1424 this.minimap.background_layer.activate(); |
1425 this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); |
1425 this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); |
1426 this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
1426 this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
1427 this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color; |
1427 this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color; |
1781 project.removeEdge(el); |
1781 project.removeEdge(el); |
1782 } |
1782 } |
1783 } |
1783 } |
1784 }); |
1784 }); |
1785 _this.delete_list = _this.delete_list.filter(function(d) { |
1785 _this.delete_list = _this.delete_list.filter(function(d) { |
1786 return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id}) |
1786 return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id}); |
1787 }); |
1787 }); |
1788 }, 500); |
1788 }, 500); |
1789 |
1789 |
1790 if (this.minimap) { |
1790 if (this.minimap) { |
1791 window.setInterval(function() { |
1791 window.setInterval(function() { |
1792 _this.rescaleMinimap() |
1792 _this.rescaleMinimap(); |
1793 }, 2000); |
1793 }, 2000); |
1794 } |
1794 } |
1795 |
1795 |
1796 } |
1796 }; |
1797 |
1797 |
1798 Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
1798 Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
1799 '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>' |
1799 '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>' |
1800 + '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>' |
1800 + '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>' |
1801 + '<div class="Rk-Users"><div class="Rk-CurrentUser"><span class="Rk-CurrentUser-Color"></span><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div>' |
1801 + '<div class="Rk-Users"><div class="Rk-CurrentUser"><span class="Rk-CurrentUser-Color"></span><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div>' |
1932 showImage(); |
1932 showImage(); |
1933 } else { |
1933 } else { |
1934 Rkns.$(_img).on("load",showImage); |
1934 Rkns.$(_img).on("load",showImage); |
1935 } |
1935 } |
1936 |
1936 |
1937 return _res |
1937 return _res; |
1938 } |
1938 }; |
1939 |
1939 |
1940 Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
1940 Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
1941 var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
1941 var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
1942 return ( |
1942 return ( |
1943 ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
1943 ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
1944 || ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
1944 || ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
1945 ); |
1945 ); |
1946 }); |
1946 }); |
1947 if (typeof _bundle !== "undefined") { |
1947 if (typeof _bundle !== "undefined") { |
1948 _bundle.edges.push(_edgeRepr) |
1948 _bundle.edges.push(_edgeRepr); |
1949 } else { |
1949 } else { |
1950 _bundle = { |
1950 _bundle = { |
1951 from: _edgeRepr.from_representation, |
1951 from: _edgeRepr.from_representation, |
1952 to: _edgeRepr.to_representation, |
1952 to: _edgeRepr.to_representation, |
1953 edges: [ _edgeRepr ], |
1953 edges: [ _edgeRepr ], |
1954 getPosition: function(_er) { |
1954 getPosition: function(_er) { |
1955 var _dir = (_er.from_representation === this.from) ? 1 : -1; |
1955 var _dir = (_er.from_representation === this.from) ? 1 : -1; |
1956 return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
1956 return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
1957 } |
1957 } |
1958 } |
1958 }; |
1959 this.bundles.push(_bundle); |
1959 this.bundles.push(_bundle); |
1960 } |
1960 } |
1961 return _bundle; |
1961 return _bundle; |
1962 } |
1962 }; |
1963 |
1963 |
1964 Rkns.Renderer.Scene.prototype.isEditable = function() { |
1964 Rkns.Renderer.Scene.prototype.isEditable = function() { |
1965 return (this.renkan.options.editor_mode && !this.renkan.read_only) |
1965 return (this.renkan.options.editor_mode && !this.renkan.read_only); |
1966 } |
1966 }; |
1967 |
1967 |
1968 Rkns.Renderer.Scene.prototype.onStatusChange = function() { |
1968 Rkns.Renderer.Scene.prototype.onStatusChange = function() { |
1969 var savebtn = this.$.find(".Rk-Save-Button"), |
1969 var savebtn = this.$.find(".Rk-Save-Button"), |
1970 tip = savebtn.find(".Rk-TopBar-Tooltip-Contents"); |
1970 tip = savebtn.find(".Rk-TopBar-Tooltip-Contents"); |
1971 if (this.renkan.read_only) { |
1971 if (this.renkan.read_only) { |
1978 } else { |
1978 } else { |
1979 savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online"); |
1979 savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online"); |
1980 tip.text(this.renkan.translate("Auto-save enabled")); |
1980 tip.text(this.renkan.translate("Auto-save enabled")); |
1981 } |
1981 } |
1982 } |
1982 } |
1983 } |
1983 }; |
1984 |
1984 |
1985 Rkns.Renderer.Scene.prototype.setScale = function(_newScale, _offset) { |
1985 Rkns.Renderer.Scene.prototype.setScale = function(_newScale, _offset) { |
1986 if (_newScale > Rkns.Renderer._MIN_SCALE && _newScale < Rkns.Renderer._MAX_SCALE) { |
1986 if (_newScale > Rkns.Renderer._MIN_SCALE && _newScale < Rkns.Renderer._MAX_SCALE) { |
1987 this.scale = _newScale; |
1987 this.scale = _newScale; |
1988 if (_offset) { |
1988 if (_offset) { |
1989 this.offset = _offset |
1989 this.offset = _offset; |
1990 } |
1990 } |
1991 this.redraw(); |
1991 this.redraw(); |
1992 } |
1992 } |
1993 } |
1993 }; |
1994 |
1994 |
1995 Rkns.Renderer.Scene.prototype.autoScale = function() { |
1995 Rkns.Renderer.Scene.prototype.autoScale = function() { |
1996 var nodes = this.renkan.project.get("nodes") |
1996 var nodes = this.renkan.project.get("nodes"); |
1997 if (nodes.length > 1) { |
1997 if (nodes.length > 1) { |
1998 var _xx = nodes.map(function(_node) { return _node.get("position").x }), |
1998 var _xx = nodes.map(function(_node) { return _node.get("position").x; }), |
1999 _yy = nodes.map(function(_node) { return _node.get("position").y }), |
1999 _yy = nodes.map(function(_node) { return _node.get("position").y; }), |
2000 _minx = Math.min.apply(Math, _xx), |
2000 _minx = Math.min.apply(Math, _xx), |
2001 _miny = Math.min.apply(Math, _yy), |
2001 _miny = Math.min.apply(Math, _yy), |
2002 _maxx = Math.max.apply(Math, _xx), |
2002 _maxx = Math.max.apply(Math, _xx), |
2003 _maxy = Math.max.apply(Math, _yy); |
2003 _maxy = Math.max.apply(Math, _yy); |
2004 var _scale = Math.max(Rkns.Renderer._MIN_SCALE, Math.min(Rkns.Renderer._MAX_SCALE, (paper.view.size.width - 2 * Rkns.Renderer._AUTOSCALE_MARGIN) / (_maxx - _minx), (paper.view.size.height - 2 * Rkns.Renderer._AUTOSCALE_MARGIN) / (_maxy - _miny))); |
2004 var _scale = Math.max(Rkns.Renderer._MIN_SCALE, Math.min(Rkns.Renderer._MAX_SCALE, (paper.view.size.width - 2 * Rkns.Renderer._AUTOSCALE_MARGIN) / (_maxx - _minx), (paper.view.size.height - 2 * Rkns.Renderer._AUTOSCALE_MARGIN) / (_maxy - _miny))); |
2005 this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale))); |
2005 this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale))); |
2006 } |
2006 } |
2007 if (nodes.length === 1) { |
2007 if (nodes.length === 1) { |
2008 this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]))); |
2008 this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]))); |
2009 } |
2009 } |
2010 } |
2010 }; |
2011 |
2011 |
2012 Rkns.Renderer.Scene.prototype.redrawMiniframe = function() { |
2012 Rkns.Renderer.Scene.prototype.redrawMiniframe = function() { |
2013 var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
2013 var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
2014 bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
2014 bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
2015 this.minimap.miniframe.fitBounds(topleft, bottomright); |
2015 this.minimap.miniframe.fitBounds(topleft, bottomright); |
2016 } |
2016 }; |
2017 |
2017 |
2018 Rkns.Renderer.Scene.prototype.rescaleMinimap = function() { |
2018 Rkns.Renderer.Scene.prototype.rescaleMinimap = function() { |
2019 var nodes = this.renkan.project.get("nodes") |
2019 var nodes = this.renkan.project.get("nodes"); |
2020 if (nodes.length > 1) { |
2020 if (nodes.length > 1) { |
2021 var _xx = nodes.map(function(_node) { return _node.get("position").x }), |
2021 var _xx = nodes.map(function(_node) { return _node.get("position").x; }), |
2022 _yy = nodes.map(function(_node) { return _node.get("position").y }), |
2022 _yy = nodes.map(function(_node) { return _node.get("position").y; }), |
2023 _minx = Math.min.apply(Math, _xx), |
2023 _minx = Math.min.apply(Math, _xx), |
2024 _miny = Math.min.apply(Math, _yy), |
2024 _miny = Math.min.apply(Math, _yy), |
2025 _maxx = Math.max.apply(Math, _xx), |
2025 _maxx = Math.max.apply(Math, _xx), |
2026 _maxy = Math.max.apply(Math, _yy); |
2026 _maxy = Math.max.apply(Math, _yy); |
2027 var _scale = Math.min( |
2027 var _scale = Math.min( |
2036 if (nodes.length === 1) { |
2036 if (nodes.length === 1) { |
2037 this.minimap.scale = .1; |
2037 this.minimap.scale = .1; |
2038 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale)); |
2038 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale)); |
2039 } |
2039 } |
2040 this.redraw(); |
2040 this.redraw(); |
2041 } |
2041 }; |
2042 |
2042 |
2043 Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
2043 Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
2044 return _point.multiply(this.scale).add(this.offset); |
2044 return _point.multiply(this.scale).add(this.offset); |
2045 } |
2045 }; |
2046 |
2046 |
2047 Rkns.Renderer.Scene.prototype.toMinimapCoords = function(_point) { |
2047 Rkns.Renderer.Scene.prototype.toMinimapCoords = function(_point) { |
2048 return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
2048 return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
2049 } |
2049 }; |
2050 |
2050 |
2051 Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
2051 Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
2052 return _point.subtract(this.offset).divide(this.scale); |
2052 return _point.subtract(this.offset).divide(this.scale); |
2053 } |
2053 }; |
2054 |
2054 |
2055 Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
2055 Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
2056 var _repr = new Rkns.Renderer[_type](this, _model); |
2056 var _repr = new Rkns.Renderer[_type](this, _model); |
2057 this.representations.push(_repr); |
2057 this.representations.push(_repr); |
2058 return _repr; |
2058 return _repr; |
2059 } |
2059 }; |
2060 |
2060 |
2061 Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
2061 Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
2062 var _this = this; |
2062 var _this = this; |
2063 _collection.forEach(function(_model) { |
2063 _collection.forEach(function(_model) { |
2064 _this.addRepresentation(_type, _model); |
2064 _this.addRepresentation(_type, _model); |
2065 }); |
2065 }); |
2066 } |
2066 }; |
2067 |
2067 |
2068 Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template( |
2068 Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template( |
2069 '<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
2069 '<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
2070 ); |
2070 ); |
2071 |
2071 |
2081 background: _user.get("color") |
2081 background: _user.get("color") |
2082 }) |
2082 }) |
2083 ) |
2083 ) |
2084 ); |
2084 ); |
2085 } |
2085 } |
2086 } |
2086 }; |
2087 |
2087 |
2088 Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
2088 Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
2089 _representation.destroy(); |
2089 _representation.destroy(); |
2090 this.representations = Rkns._(this.representations).reject( |
2090 this.representations = Rkns._(this.representations).reject( |
2091 function(_repr) { |
2091 function(_repr) { |
2092 return _repr == _representation |
2092 return _repr == _representation; |
2093 } |
2093 } |
2094 ); |
2094 ); |
2095 } |
2095 }; |
2096 |
2096 |
2097 Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
2097 Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
2098 return Rkns._(this.representations).find(function(_repr) { |
2098 return Rkns._(this.representations).find(function(_repr) { |
2099 return _repr.model === _model; |
2099 return _repr.model === _model; |
2100 }); |
2100 }); |
2101 } |
2101 }; |
2102 |
2102 |
2103 Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
2103 Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
2104 var _representations = Rkns._(this.representations).filter(function(_repr) { |
2104 var _representations = Rkns._(this.representations).filter(function(_repr) { |
2105 return _repr.type == _type; |
2105 return _repr.type == _type; |
2106 }), |
2106 }), |
2107 _this = this; |
2107 _this = this; |
2108 Rkns._(_representations).each(function(_repr) { |
2108 Rkns._(_representations).each(function(_repr) { |
2109 _this.removeRepresentation(_repr); |
2109 _this.removeRepresentation(_repr); |
2110 }); |
2110 }); |
2111 } |
2111 }; |
2112 |
2112 |
2113 Rkns.Renderer.Scene.prototype.highlightModel = function(_model) { |
2113 Rkns.Renderer.Scene.prototype.highlightModel = function(_model) { |
2114 var _repr = this.getRepresentationByModel(_model); |
2114 var _repr = this.getRepresentationByModel(_model); |
2115 if (_repr) { |
2115 if (_repr) { |
2116 _repr.highlight(); |
2116 _repr.highlight(); |
2117 } |
2117 } |
2118 } |
2118 }; |
2119 |
2119 |
2120 Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) { |
2120 Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) { |
2121 Rkns._(this.representations).each(function(_repr) { |
2121 Rkns._(this.representations).each(function(_repr) { |
2122 _repr.unhighlight(); |
2122 _repr.unhighlight(); |
2123 }); |
2123 }); |
2124 } |
2124 }; |
2125 |
2125 |
2126 Rkns.Renderer.Scene.prototype.unselectAll = function(_model) { |
2126 Rkns.Renderer.Scene.prototype.unselectAll = function(_model) { |
2127 Rkns._(this.representations).each(function(_repr) { |
2127 Rkns._(this.representations).each(function(_repr) { |
2128 _repr.unselect(); |
2128 _repr.unselect(); |
2129 }); |
2129 }); |
2130 } |
2130 }; |
2131 |
2131 |
2132 Rkns.Renderer.Scene.prototype.redraw = function() { |
2132 Rkns.Renderer.Scene.prototype.redraw = function() { |
2133 Rkns._(this.representations).each(function(_representation) { |
2133 Rkns._(this.representations).each(function(_representation) { |
2134 _representation.redraw(true); |
2134 _representation.redraw(true); |
2135 }); |
2135 }); |
2136 if (this.minimap) { |
2136 if (this.minimap) { |
2137 this.redrawMiniframe(); |
2137 this.redrawMiniframe(); |
2138 } |
2138 } |
2139 paper.view.draw(); |
2139 paper.view.draw(); |
2140 } |
2140 }; |
2141 |
2141 |
2142 Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
2142 Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
2143 var _tmpEdge = this.addRepresentation("TempEdge",null); |
2143 var _tmpEdge = this.addRepresentation("TempEdge",null); |
2144 _tmpEdge.end_pos = _point; |
2144 _tmpEdge.end_pos = _point; |
2145 _tmpEdge.from_representation = _from; |
2145 _tmpEdge.from_representation = _from; |
2146 _tmpEdge.redraw(); |
2146 _tmpEdge.redraw(); |
2147 this.click_target = _tmpEdge; |
2147 this.click_target = _tmpEdge; |
2148 } |
2148 }; |
2149 |
2149 |
2150 Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
2150 Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
2151 if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
2151 if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
2152 var _newTarget = _hitResult.item.__representation; |
2152 var _newTarget = _hitResult.item.__representation; |
2153 if (this.selected_target !== _hitResult.item.__representation) { |
2153 if (this.selected_target !== _hitResult.item.__representation) { |