').appendTo(this.renderer.labels_$);
+ this.arrow_angle = 0;
+ if (this.options.editor_mode) {
+ var Renderer = requtils.getRenderer();
+ this.normal_buttons = [
+ new Renderer.EdgeEditButton(this.renderer, null),
+ new Renderer.EdgeRemoveButton(this.renderer, null)
+ ];
+ this.pending_delete_buttons = [
+ new Renderer.EdgeRevertButton(this.renderer, null)
+ ];
+ this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons);
+ for (var i = 0; i < this.all_buttons.length; i++) {
+ this.all_buttons[i].source_representation = this;
+ }
+ this.active_buttons = [];
+ } else {
+ this.active_buttons = this.all_buttons = [];
+ }
+
+ if (this.renderer.minimap) {
+ this.renderer.minimap.edge_layer.activate();
+ this.minimap_line = new paper.Path();
+ this.minimap_line.add([0,0],[0,0]);
+ this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation;
+ this.minimap_line.strokeWidth = 1;
+ }
+ },
+ _getStrokeWidth: function() {
+ var thickness = (this.model.has('style') && this.model.get('style').thickness) || 1;
+ return this.options.edge_stroke_width + (thickness-1) * (this.options.edge_stroke_max_width - this.options.edge_stroke_width) / (this.options.edge_stroke_witdh_scale-1);
+ },
+ _getSelectedStrokeWidth: function() {
+ var thickness = (this.model.has('style') && this.model.get('style').thickness) || 1;
+ return this.options.selected_edge_stroke_width + (thickness-1) * (this.options.selected_edge_stroke_max_width - this.options.selected_edge_stroke_width) / (this.options.edge_stroke_witdh_scale-1);
+ },
+ _getArrowScale: function() {
+ var thickness = (this.model.has('style') && this.model.get('style').thickness) || 1;
+ return 1 + (thickness-1) * ((this.options.edge_arrow_max_width / this.options.edge_arrow_width) - 1) / (this.options.edge_stroke_witdh_scale-1);
+ },
+ redraw: function() {
+ var from = this.model.get("from"),
+ to = this.model.get("to");
+ if (!from || !to || (this.hidden && !this.ghost)) {
+ return;
+ }
+ this.from_representation = this.renderer.getRepresentationByModel(from);
+ this.to_representation = this.renderer.getRepresentationByModel(to);
+ if (typeof this.from_representation === "undefined" || typeof this.to_representation === "undefined" ||
+ (this.from_representation.hidden && !this.from_representation.ghost) ||
+ (this.to_representation.hidden && !this.to_representation.ghost)) {
+ this.hide();
+ return;
+ }
+ var _strokeWidth = this._getStrokeWidth(),
+ _arrow_scale = this._getArrowScale(),
+ _p0a = this.from_representation.paper_coords,
+ _p1a = this.to_representation.paper_coords,
+ _v = _p1a.subtract(_p0a),
+ _r = _v.length,
+ _u = _v.divide(_r),
+ _ortho = new paper.Point([- _u.y, _u.x]),
+ _group_pos = this.bundle.getPosition(this),
+ _delta = _ortho.multiply( this.options.edge_gap_in_bundles * _group_pos ),
+ _p0b = _p0a.add(_delta), /* Adding a 4 px difference */
+ _p1b = _p1a.add(_delta), /* to differentiate bundled links */
+ _a = _v.angle,
+ _textdelta = _ortho.multiply(this.options.edge_label_distance + 0.5 * _arrow_scale * this.options.edge_arrow_width),
+ _handle = _v.divide(3),
+ _color = (this.model.has("style") && this.model.get("style").color) || (this.model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
+ _dash = (this.model.has("style") && this.model.get("style").dash) ? this.options.default_dash_array : null,
+ _opacity;
+
+ if (this.model.get("delete_scheduled") || this.from_representation.model.get("delete_scheduled") || this.to_representation.model.get("delete_scheduled")) {
+ _opacity = 0.5;
+ this.line.dashArray = [2, 2];
+ } else {
+ _opacity = this.ghost ? this.options.ghost_opacity : 1;
+ this.line.dashArray = null;
+ }
+
+ var old_act_btn = this.active_buttons;
+
+ this.arrow.visible =
+ (this.model.has("style") && this.model.get("style").arrow) ||
+ !this.model.has("style") ||
+ typeof this.model.get("style").arrow === 'undefined';
+
+ this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons;
+
+ if (this.selected && this.renderer.isEditable() && old_act_btn !== this.active_buttons) {
+ old_act_btn.forEach(function(b) {
+ b.hide();
+ });
+ this.active_buttons.forEach(function(b) {
+ b.show();
+ });
+ }
+
+ this.paper_coords = _p0b.add(_p1b).divide(2);
+ this.line.strokeWidth = _strokeWidth;
+ this.line.strokeColor = _color;
+ this.line.dashArray = _dash;
+ this.line.opacity = _opacity;
+ this.line.segments[0].point = _p0a;
+ this.line.segments[1].point = this.paper_coords;
+ this.line.segments[1].handleIn = _handle.multiply(-1);
+ this.line.segments[1].handleOut = _handle;
+ this.line.segments[2].point = _p1a;
+ this.arrow.scale(_arrow_scale / this.arrow_scale);
+ this.arrow_scale = _arrow_scale;
+ this.arrow.fillColor = _color;
+ this.arrow.opacity = _opacity;
+ this.arrow.rotate(_a - this.arrow_angle, this.arrow.bounds.center);
+ this.arrow.position = this.paper_coords;
+
+ this.arrow_angle = _a;
+ if (_a > 90) {
+ _a -= 180;
+ _textdelta = _textdelta.multiply(-1);
+ }
+ if (_a < -90) {
+ _a += 180;
+ _textdelta = _textdelta.multiply(-1);
+ }
+ var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_edges) || "";
+ _text = Utils.shortenText(_text, this.options.node_label_max_length);
+ this.text.text(_text);
+ var _textpos = this.paper_coords.add(_textdelta);
+ this.text.css({
+ left: _textpos.x,
+ top: _textpos.y,
+ transform: "rotate(" + _a + "deg)",
+ "-moz-transform": "rotate(" + _a + "deg)",
+ "-webkit-transform": "rotate(" + _a + "deg)",
+ opacity: _opacity
+ });
+ this.text_angle = _a;
+
+ var _pc = this.paper_coords;
+ this.all_buttons.forEach(function(b) {
+ b.moveTo(_pc);
+ });
+
+ if (this.renderer.minimap) {
+ this.minimap_line.strokeColor = _color;
+ this.minimap_line.segments[0].point = this.renderer.toMinimapCoords(new paper.Point(this.from_representation.model.get("position")));
+ this.minimap_line.segments[1].point = this.renderer.toMinimapCoords(new paper.Point(this.to_representation.model.get("position")));
+ }
+ },
+ hide: function(){
+ this.hidden = true;
+ this.ghost = false;
+
+ this.text.hide();
+ this.line.visible = false;
+ this.arrow.visible = false;
+ this.minimap_line.visible = false;
+ },
+ show: function(ghost){
+ this.ghost = ghost;
+ if (this.ghost) {
+ this.text.css('opacity', 0.3);
+ this.line.opacity = 0.3;
+ this.arrow.opacity = 0.3;
+ this.minimap_line.opacity = 0.3;
+ } else {
+ this.hidden = false;
+
+ this.text.css('opacity', 1);
+ this.line.opacity = 1;
+ this.arrow.opacity = 1;
+ this.minimap_line.opacity = 1;
+ }
+ this.text.show();
+ this.line.visible = true;
+ this.arrow.visible = true;
+ this.minimap_line.visible = true;
+ this.redraw();
+ },
+ openEditor: function() {
+ this.renderer.removeRepresentationsOfType("editor");
+ var _editor = this.renderer.addRepresentation("EdgeEditor",null);
+ _editor.source_representation = this;
+ _editor.draw();
+ },
+ select: function() {
+ this.selected = true;
+ this.line.strokeWidth = this._getSelectedStrokeWidth();
+ if (this.renderer.isEditable()) {
+ this.active_buttons.forEach(function(b) {
+ b.show();
+ });
+ }
+ if (!this.options.editor_mode) {
+ this.openEditor();
+ }
+ this._super("select");
+ },
+ unselect: function(_newTarget) {
+ if (!_newTarget || _newTarget.source_representation !== this) {
+ this.selected = false;
+ if (this.options.editor_mode) {
+ this.all_buttons.forEach(function(b) {
+ b.hide();
+ });
+ }
+ this.line.strokeWidth = this._getStrokeWidth();
+ this._super("unselect");
+ }
+ },
+ mousedown: function(_event, _isTouch) {
+ if (_isTouch) {
+ this.renderer.unselectAll();
+ this.select();
+ }
+ },
+ mouseup: function(_event, _isTouch) {
+ if (!this.renkan.read_only && this.renderer.is_dragging) {
+ this.from_representation.saveCoords();
+ this.to_representation.saveCoords();
+ this.from_representation.is_dragging = false;
+ this.to_representation.is_dragging = false;
+ } else {
+ if (!_isTouch) {
+ this.openEditor();
+ }
+ this.model.trigger("clicked");
+ }
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ },
+ paperShift: function(_delta) {
+ if (this.options.editor_mode) {
+ if (!this.options.read_only) {
+ this.from_representation.paperShift(_delta);
+ this.to_representation.paperShift(_delta);
+ }
+ } else {
+ this.renderer.paperShift(_delta);
+ }
+ },
+ destroy: function() {
+ this._super("destroy");
+ this.line.remove();
+ this.arrow.remove();
+ this.text.remove();
+ if (this.renderer.minimap) {
+ this.minimap_line.remove();
+ }
+ this.all_buttons.forEach(function(b) {
+ b.destroy();
+ });
+ var _this = this;
+ this.bundle.edges = _.reject(this.bundle.edges, function(_edge) {
+ return _this === _edge;
+ });
+ }
+ }).value();
+
+ return Edge;
+
+});
+
+
+
+define('renderer/tempedge',['jquery', 'underscore', 'requtils', 'renderer/baserepresentation'], function ($, _, requtils, BaseRepresentation) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* TempEdge Class Begin */
+
+ //var TempEdge = Renderer.TempEdge = Utils.inherit(Renderer._BaseRepresentation);
+ var TempEdge = Utils.inherit(BaseRepresentation);
+
+ _(TempEdge.prototype).extend({
+ _init: function() {
+ this.renderer.edge_layer.activate();
+ this.type = "Temp-edge";
+
+ var _color = (this.project.get("users").get(this.renkan.current_user) || Utils._USER_PLACEHOLDER(this.renkan)).get("color");
+ this.line = new paper.Path();
+ this.line.strokeColor = _color;
+ this.line.dashArray = [4, 2];
+ this.line.strokeWidth = this.options.selected_edge_stroke_width;
+ this.line.add([0,0],[0,0]);
+ this.line.__representation = this;
+ this.arrow = new paper.Path();
+ this.arrow.fillColor = _color;
+ this.arrow.add(
+ [ 0, 0 ],
+ [ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
+ [ 0, this.options.edge_arrow_width ]
+ );
+ this.arrow.__representation = this;
+ this.arrow_angle = 0;
+ },
+ redraw: function() {
+ var _p0 = this.from_representation.paper_coords,
+ _p1 = this.end_pos,
+ _a = _p1.subtract(_p0).angle,
+ _c = _p0.add(_p1).divide(2);
+ this.line.segments[0].point = _p0;
+ this.line.segments[1].point = _p1;
+ this.arrow.rotate(_a - this.arrow_angle);
+ this.arrow.position = _c;
+ this.arrow_angle = _a;
+ },
+ paperShift: function(_delta) {
+ if (!this.renderer.isEditable()) {
+ this.renderer.removeRepresentation(_this);
+ paper.view.draw();
+ return;
+ }
+ this.end_pos = this.end_pos.add(_delta);
+ var _hitResult = paper.project.hitTest(this.end_pos);
+ this.renderer.findTarget(_hitResult);
+ this.redraw();
+ },
+ mouseup: function(_event, _isTouch) {
+ var _hitResult = paper.project.hitTest(_event.point),
+ _model = this.from_representation.model,
+ _endDrag = true;
+ if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
+ var _target = _hitResult.item.__representation;
+ if (_target.type.substr(0,4) === "Node") {
+ var _destmodel = _target.model || _target.source_representation.model;
+ if (_model !== _destmodel) {
+ var _data = {
+ id: Utils.getUID('edge'),
+ created_by: this.renkan.current_user,
+ from: _model,
+ to: _destmodel
+ };
+ if (this.renderer.isEditable()) {
+ this.project.addEdge(_data);
+ }
+ }
+ }
+
+ if (_model === _target.model || (_target.source_representation && _target.source_representation.model === _model)) {
+ _endDrag = false;
+ this.renderer.is_dragging = true;
+ }
+ }
+ if (_endDrag) {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ this.renderer.removeRepresentation(this);
+ paper.view.draw();
+ }
+ },
+ destroy: function() {
+ this.arrow.remove();
+ this.line.remove();
+ }
+ }).value();
+
+ /* TempEdge Class End */
+
+ return TempEdge;
+
+});
+
+
+define('renderer/baseeditor',['jquery', 'underscore', 'requtils', 'renderer/baserepresentation'], function ($, _, requtils, BaseRepresentation) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* _BaseEditor Begin */
+ //var _BaseEditor = Renderer._BaseEditor = Utils.inherit(Renderer._BaseRepresentation);
+ var _BaseEditor = Utils.inherit(BaseRepresentation);
+
+ _(_BaseEditor.prototype).extend({
+ _init: function() {
+ this.renderer.buttons_layer.activate();
+ this.type = "editor";
+ this.editor_block = new paper.Path();
+ var _pts = _.map(_.range(8), function() {return [0,0];});
+ this.editor_block.add.apply(this.editor_block, _pts);
+ this.editor_block.strokeWidth = this.options.tooltip_border_width;
+ this.editor_block.strokeColor = this.options.tooltip_border_color;
+ this.editor_block.opacity = this.options.tooltip_opacity;
+ this.editor_$ = $('
')
+ .appendTo(this.renderer.editor_$)
+ .css({
+ position: "absolute",
+ opacity: this.options.tooltip_opacity
+ })
+ .hide();
+ },
+ destroy: function() {
+ this.editor_block.remove();
+ this.editor_$.remove();
+ }
+ }).value();
+
+ /* _BaseEditor End */
+
+ return _BaseEditor;
+
+});
+
+
+define('renderer/nodeeditor',['jquery', 'underscore', 'requtils', 'renderer/baseeditor', 'renderer/shapebuilder', 'ckeditor-jquery'], function ($, _, requtils, BaseEditor, ShapeBuilder) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeEditor Begin */
+ //var NodeEditor = Renderer.NodeEditor = Utils.inherit(Renderer._BaseEditor);
+ var NodeEditor = Utils.inherit(BaseEditor);
+
+ _(NodeEditor.prototype).extend({
+ _init: function() {
+ BaseEditor.prototype._init.apply(this);
+ this.template = this.options.templates['templates/nodeeditor.html'];
+ //this.templates['default']= this.options.templates['templates/nodeeditor.html'];
+ //fusionner avec this.options.node_editor_templates
+ this.readOnlyTemplate = this.options.node_editor_templates;
+ },
+ draw: function() {
+ var _model = this.source_representation.model,
+ _created_by = _model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan),
+ _template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate[_model.get("type")] || this.readOnlyTemplate["default"]),
+ _image_placeholder = this.options.static_url + "img/image-placeholder.png",
+ _size = (_model.get("size") || 0);
+ this.editor_$
+ .html(_template({
+ node: {
+ _id: _model.get("_id"),
+ has_creator: !!_model.get("created_by"),
+ title: _model.get("title"),
+ uri: _model.get("uri"),
+ type: _model.get("type") || "default",
+ short_uri: Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
+ description: _model.get("description"),
+ image: _model.get("image") || "",
+ image_placeholder: _image_placeholder,
+ color: (_model.has("style") && _model.get("style").color) || _created_by.get("color"),
+ thickness: (_model.has("style") && _model.get("style").thickness) || 1,
+ dash: _model.has("style") && _model.get("style").dash ? "checked" : "",
+ clip_path: _model.get("clip_path") || false,
+ created_by_color: _created_by.get("color"),
+ created_by_title: _created_by.get("title"),
+ size: (_size > 0 ? "+" : "") + _size,
+ shape: _model.get("shape") || "circle"
+ },
+ renkan: this.renkan,
+ options: this.options,
+ shortenText: Utils.shortenText,
+ shapes : _(ShapeBuilder.builders).omit('svg').keys().value(),
+ types : _(this.options.node_editor_templates).keys().value(),
+ }));
+ this.redraw();
+ var _this = this,
+ editorInstance = _this.options.show_node_editor_description_richtext ?
+ $(".Rk-Edit-Description").ckeditor(_this.options.richtext_editor_config) :
+ false,
+ closeEditor = function() {
+ _this.renderer.removeRepresentation(_this);
+ paper.view.draw();
+ };
+
+ _this.cleanEditor = function() {
+ _this.editor_$.off("keyup");
+ _this.editor_$.find("input, textarea, select").off("change keyup paste");
+ _this.editor_$.find(".Rk-Edit-Image-File").off('change');
+ _this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").off('hover');
+ _this.editor_$.find(".Rk-Edit-Size-Btn").off('click');
+ _this.editor_$.find(".Rk-Edit-Image-Del").off('click');
+ _this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click');
+ _this.editor_$.find(".Rk-CloseX").off('click');
+ _this.editor_$.find(".Rk-Edit-Goto").off('click');
+
+ if(_this.options.show_node_editor_description_richtext) {
+ if(typeof editorInstance.editor !== 'undefined') {
+ var _editor = editorInstance.editor;
+ delete editorInstance.editor;
+ _editor.focusManager.blur(true);
+ _editor.destroy();
+ }
+ }
+ };
+
+ this.editor_$.find(".Rk-CloseX").click(function (e) {
+ e.preventDefault();
+ closeEditor();
+ });
+
+ this.editor_$.find(".Rk-Edit-Goto").click(function() {
+ if (!_model.get("uri")) {
+ return false;
+ }
+ });
+
+ if (this.renderer.isEditable()) {
+
+ var onFieldChange = _.throttle(function() {
+ _.defer(function() {
+ if (_this.renderer.isEditable()) {
+ var _data = {
+ title: _this.editor_$.find(".Rk-Edit-Title").val()
+ };
+ if (_this.options.show_node_editor_uri) {
+ _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
+ _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
+ }
+ if (_this.options.show_node_editor_image) {
+ _data.image = _this.editor_$.find(".Rk-Edit-Image").val();
+ _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
+ }
+ if (_this.options.show_node_editor_description) {
+ if(_this.options.show_node_editor_description_richtext) {
+ if(typeof editorInstance.editor !== 'undefined' &&
+ editorInstance.editor.checkDirty()) {
+ _data.description = editorInstance.editor.getData();
+ editorInstance.editor.resetDirty();
+ }
+ }
+ else {
+ _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
+ }
+ }
+ if (_this.options.show_node_editor_style) {
+ var dash = _this.editor_$.find(".Rk-Edit-Dash").is(':checked');
+ _data.style = _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {dash: dash});
+ }
+ if (_this.options.change_shapes) {
+ if(_model.get("shape")!==_this.editor_$.find(".Rk-Edit-Shape").val()){
+ _data.shape = _this.editor_$.find(".Rk-Edit-Shape").val();
+ }
+ }
+ if (_this.options.change_types) {
+ if(_model.get("type")!==_this.editor_$.find(".Rk-Edit-Type").val()){
+ _data.type = _this.editor_$.find(".Rk-Edit-Type").val();
+ }
+ }
+ _model.set(_data);
+ _this.redraw();
+ } else {
+ closeEditor();
+ }
+ });
+ }, 1000);
+
+ this.editor_$.on("keyup", function(_e) {
+ if (_e.keyCode === 27) {
+ closeEditor();
+ }
+ });
+
+ this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange);
+ if( _this.options.show_node_editor_description &&
+ _this.options.show_node_editor_description_richtext &&
+ typeof editorInstance.editor !== 'undefined')
+ {
+ editorInstance.editor.on("change", onFieldChange);
+ editorInstance.editor.on("blur", onFieldChange);
+ }
+
+ if(_this.options.allow_image_upload) {
+ this.editor_$.find(".Rk-Edit-Image-File").change(function() {
+ if (this.files.length) {
+ var f = this.files[0],
+ fr = new FileReader();
+ if (f.type.substr(0,5) !== "image") {
+ alert(_this.renkan.translate("This file is not an image"));
+ return;
+ }
+ if (f.size > (_this.options.uploaded_image_max_kb * 1024)) {
+ alert(_this.renkan.translate("Image size must be under ") + _this.options.uploaded_image_max_kb + _this.renkan.translate("KB"));
+ return;
+ }
+ fr.onload = function(e) {
+ _this.editor_$.find(".Rk-Edit-Image").val(e.target.result);
+ onFieldChange();
+ };
+ fr.readAsDataURL(f);
+ }
+ });
+ }
+ this.editor_$.find(".Rk-Edit-Title")[0].focus();
+
+ var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
+
+ this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
+ function(_e) {
+ _e.preventDefault();
+ _picker.show();
+ },
+ function(_e) {
+ _e.preventDefault();
+ _picker.hide();
+ }
+ );
+
+ _picker.find("li").hover(
+ function(_e) {
+ _e.preventDefault();
+ _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
+ },
+ function(_e) {
+ _e.preventDefault();
+ _this.editor_$.find(".Rk-Edit-Color").css("background", (_model.has("style") && _model.get("style").color) || (_model.get("created_by") || Utils._USER_PLACEHOLDER(_this.renkan)).get("color"));
+ }
+ ).click(function(_e) {
+ _e.preventDefault();
+ if (_this.renderer.isEditable()) {
+ _model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {color: $(this).attr("data-color")}));
+ _picker.hide();
+ paper.view.draw();
+ } else {
+ closeEditor();
+ }
+ });
+
+ var shiftSize = function(n) {
+ if (_this.renderer.isEditable()) {
+ var _newsize = n+(_model.get("size") || 0);
+ _this.editor_$.find("#Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize);
+ _model.set("size", _newsize);
+ paper.view.draw();
+ } else {
+ closeEditor();
+ }
+ };
+
+ this.editor_$.find("#Rk-Edit-Size-Down").click(function() {
+ shiftSize(-1);
+ return false;
+ });
+ this.editor_$.find("#Rk-Edit-Size-Up").click(function() {
+ shiftSize(1);
+ return false;
+ });
+
+ var shiftThickness = function(n) {
+ if (_this.renderer.isEditable()) {
+ var _oldThickness = ((_model.has('style') && _model.get('style').thickness) || 1),
+ _newThickness = n + _oldThickness;
+ if(_newThickness < 1 ) {
+ _newThickness = 1;
+ }
+ else if (_newThickness > _this.options.node_stroke_witdh_scale) {
+ _newThickness = _this.options.node_stroke_witdh_scale;
+ }
+ if (_newThickness !== _oldThickness) {
+ _this.editor_$.find("#Rk-Edit-Thickness-Value").text(_newThickness);
+ _model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {thickness: _newThickness}));
+ paper.view.draw();
+ }
+ }
+ else {
+ closeEditor();
+ }
+ };
+
+ this.editor_$.find("#Rk-Edit-Thickness-Down").click(function() {
+ shiftThickness(-1);
+ return false;
+ });
+ this.editor_$.find("#Rk-Edit-Thickness-Up").click(function() {
+ shiftThickness(1);
+ return false;
+ });
+
+ this.editor_$.find(".Rk-Edit-Image-Del").click(function() {
+ _this.editor_$.find(".Rk-Edit-Image").val('');
+ onFieldChange();
+ return false;
+ });
+ } else {
+ if (typeof this.source_representation.highlighted === "object") {
+ var titlehtml = this.source_representation.highlighted.replace(_(_model.get("title")).escape(),'
$1');
+ this.editor_$.find(".Rk-Display-Title" + (_model.get("uri") ? " a" : "")).html(titlehtml);
+ if (this.options.show_node_tooltip_description) {
+ this.editor_$.find(".Rk-Display-Description").html(this.source_representation.highlighted.replace(_(_model.get("description")).escape(),'
$1'));
+ }
+ }
+ }
+ this.editor_$.find("img").load(function() {
+ _this.redraw();
+ });
+ },
+ redraw: function() {
+ if (this.options.popup_editor){
+ var _coords = this.source_representation.paper_coords;
+ Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$);
+ }
+ this.editor_$.show();
+ paper.view.draw();
+ },
+ destroy: function() {
+ if(typeof this.cleanEditor !== 'undefined') {
+ this.cleanEditor();
+ }
+ this.editor_block.remove();
+ this.editor_$.remove();
+ }
+ }).value();
+
+ /* NodeEditor End */
+
+ return NodeEditor;
+
+});
+
+
+define('renderer/edgeeditor',['jquery', 'underscore', 'requtils', 'renderer/baseeditor'], function ($, _, requtils, BaseEditor) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* EdgeEditor Begin */
+
+ //var EdgeEditor = Renderer.EdgeEditor = Utils.inherit(Renderer._BaseEditor);
+ var EdgeEditor = Utils.inherit(BaseEditor);
+
+ _(EdgeEditor.prototype).extend({
+ _init: function() {
+ BaseEditor.prototype._init.apply(this);
+ this.template = this.options.templates['templates/edgeeditor.html'];
+ this.readOnlyTemplate = this.options.templates['templates/edgeeditor_readonly.html'];
+ },
+ draw: function() {
+ var _model = this.source_representation.model,
+ _from_model = _model.get("from"),
+ _to_model = _model.get("to"),
+ _created_by = _model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan),
+ _template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate);
+ this.editor_$
+ .html(_template({
+ edge: {
+ has_creator: !!_model.get("created_by"),
+ title: _model.get("title"),
+ uri: _model.get("uri"),
+ short_uri: Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
+ description: _model.get("description"),
+ color: (_model.has("style") && _model.get("style").color) || _created_by.get("color"),
+ dash: _model.has("style") && _model.get("style").dash ? "checked" : "",
+ arrow: (_model.has("style") && _model.get("style").arrow) || !_model.has("style") || (typeof _model.get("style").arrow === 'undefined') ? "checked" : "",
+ thickness: (_model.has("style") && _model.get("style").thickness) || 1,
+ from_title: _from_model.get("title"),
+ to_title: _to_model.get("title"),
+ from_color: (_from_model.has("style") && _from_model.get("style").color) || (_from_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
+ to_color: (_to_model.has("style") && _to_model.get("style").color) || (_to_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
+ created_by_color: _created_by.get("color"),
+ created_by_title: _created_by.get("title")
+ },
+ renkan: this.renkan,
+ shortenText: Utils.shortenText,
+ options: this.options
+ }));
+ this.redraw();
+ var _this = this,
+ closeEditor = function() {
+ _this.renderer.removeRepresentation(_this);
+ _this.editor_$.find(".Rk-Edit-Size-Btn").off('click');
+ paper.view.draw();
+ };
+ this.editor_$.find(".Rk-CloseX").click(closeEditor);
+ this.editor_$.find(".Rk-Edit-Goto").click(function() {
+ if (!_model.get("uri")) {
+ return false;
+ }
+ });
+
+ if (this.renderer.isEditable()) {
+
+ var onFieldChange = _.throttle(function() {
+ _.defer(function() {
+ if (_this.renderer.isEditable()) {
+ var _data = {
+ title: _this.editor_$.find(".Rk-Edit-Title").val()
+ };
+ if (_this.options.show_edge_editor_uri) {
+ _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
+ }
+ if (_this.options.show_node_editor_style) {
+ var dash = _this.editor_$.find(".Rk-Edit-Dash").is(':checked'),
+ arrow = _this.editor_$.find(".Rk-Edit-Arrow").is(':checked');
+ _data.style = _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {dash: dash, arrow: arrow});
+ }
+ _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
+ _model.set(_data);
+ paper.view.draw();
+ } else {
+ closeEditor();
+ }
+ });
+ },500);
+
+ this.editor_$.on("keyup", function(_e) {
+ if (_e.keyCode === 27) {
+ closeEditor();
+ }
+ });
+
+ this.editor_$.find("input").on("keyup change paste", onFieldChange);
+
+ this.editor_$.find(".Rk-Edit-Vocabulary").change(function() {
+ var e = $(this),
+ v = e.val();
+ if (v) {
+ _this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text());
+ _this.editor_$.find(".Rk-Edit-URI").val(v);
+ onFieldChange();
+ }
+ });
+ this.editor_$.find(".Rk-Edit-Direction").click(function() {
+ if (_this.renderer.isEditable()) {
+ _model.set({
+ from: _model.get("to"),
+ to: _model.get("from")
+ });
+ _this.draw();
+ } else {
+ closeEditor();
+ }
+ });
+
+ var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
+
+ this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
+ function(_e) {
+ _e.preventDefault();
+ _picker.show();
+ },
+ function(_e) {
+ _e.preventDefault();
+ _picker.hide();
+ }
+ );
+
+ _picker.find("li").hover(
+ function(_e) {
+ _e.preventDefault();
+ _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
+ },
+ function(_e) {
+ _e.preventDefault();
+ _this.editor_$.find(".Rk-Edit-Color").css("background", (_model.has("style") && _model.get("style").color)|| (_model.get("created_by") || Utils._USER_PLACEHOLDER(_this.renkan)).get("color"));
+ }
+ ).click(function(_e) {
+ _e.preventDefault();
+ if (_this.renderer.isEditable()) {
+ _model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {color: $(this).attr("data-color")}));
+ _picker.hide();
+ paper.view.draw();
+ } else {
+ closeEditor();
+ }
+ });
+ var shiftThickness = function(n) {
+ if (_this.renderer.isEditable()) {
+ var _oldThickness = ((_model.has('style') && _model.get('style').thickness) || 1),
+ _newThickness = n + _oldThickness;
+ if(_newThickness < 1 ) {
+ _newThickness = 1;
+ }
+ else if (_newThickness > _this.options.node_stroke_witdh_scale) {
+ _newThickness = _this.options.node_stroke_witdh_scale;
+ }
+ if (_newThickness !== _oldThickness) {
+ _this.editor_$.find("#Rk-Edit-Thickness-Value").text(_newThickness);
+ _model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {thickness: _newThickness}));
+ paper.view.draw();
+ }
+ }
+ else {
+ closeEditor();
+ }
+ };
+
+ this.editor_$.find("#Rk-Edit-Thickness-Down").click(function() {
+ shiftThickness(-1);
+ return false;
+ });
+ this.editor_$.find("#Rk-Edit-Thickness-Up").click(function() {
+ shiftThickness(1);
+ return false;
+ });
+ }
+ },
+ redraw: function() {
+ if (this.options.popup_editor){
+ var _coords = this.source_representation.paper_coords;
+ Utils.drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$);
+ }
+ this.editor_$.show();
+ paper.view.draw();
+ }
+ }).value();
+
+ /* EdgeEditor End */
+
+ return EdgeEditor;
+
+});
+
+
+define('renderer/nodebutton',['jquery', 'underscore', 'requtils', 'renderer/basebutton'], function ($, _, requtils, BaseButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* _NodeButton Begin */
+
+ //var _NodeButton = Renderer._NodeButton = Utils.inherit(Renderer._BaseButton);
+ var _NodeButton = Utils.inherit(BaseButton);
+
+ _(_NodeButton.prototype).extend({
+ setSectorSize: function() {
+ var sectorInner = this.source_representation.circle_radius;
+ if (sectorInner !== this.lastSectorInner) {
+ if (this.sector) {
+ this.sector.destroy();
+ }
+ this.sector = this.renderer.drawSector(
+ this, 1 + sectorInner,
+ Utils._NODE_BUTTON_WIDTH + sectorInner,
+ this.startAngle,
+ this.endAngle,
+ 1,
+ this.imageName,
+ this.renkan.translate(this.text)
+ );
+ this.lastSectorInner = sectorInner;
+ }
+ },
+ unselect: function() {
+ BaseButton.prototype.unselect.apply(this, Array.prototype.slice.call(arguments, 1));
+ if(this.source_representation && this.source_representation.buttons_timeout) {
+ clearTimeout(this.source_representation.buttons_timeout);
+ this.source_representation.hideButtons();
+ }
+ },
+ select: function() {
+ if(this.source_representation && this.source_representation.buttons_timeout) {
+ clearTimeout(this.source_representation.buttons_timeout);
+ }
+ this.sector.select();
+ },
+ }).value();
+
+
+ /* _NodeButton End */
+
+ return _NodeButton;
+
+});
+
+
+define('renderer/nodeeditbutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeEditButton Begin */
+
+ //var NodeEditButton = Renderer.NodeEditButton = Utils.inherit(Renderer._NodeButton);
+ var NodeEditButton = Utils.inherit(NodeButton);
+
+ _(NodeEditButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-edit-button";
+ this.lastSectorInner = 0;
+ this.startAngle = this.options.hide_nodes ? -125 : -135;
+ this.endAngle = this.options.hide_nodes ? -55 : -45;
+ this.imageName = "edit";
+ this.text = "Edit";
+ },
+ mouseup: function() {
+ if (!this.renderer.is_dragging) {
+ this.source_representation.openEditor();
+ }
+ }
+ }).value();
+
+ /* NodeEditButton End */
+
+ return NodeEditButton;
+
+});
+
+
+define('renderer/noderemovebutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeRemoveButton Begin */
+
+ //var NodeRemoveButton = Renderer.NodeRemoveButton = Utils.inherit(Renderer._NodeButton);
+ var NodeRemoveButton = Utils.inherit(NodeButton);
+
+ _(NodeRemoveButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-remove-button";
+ this.lastSectorInner = 0;
+ this.startAngle = this.options.hide_nodes ? -10 : 0;
+ this.endAngle = this.options.hide_nodes ? 45 : 90;
+ this.imageName = "remove";
+ this.text = "Remove";
+ },
+ mouseup: function() {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ this.renderer.removeRepresentationsOfType("editor");
+ if (this.renderer.isEditable()) {
+ if (this.options.element_delete_delay) {
+ var delid = Utils.getUID("delete");
+ this.renderer.delete_list.push({
+ id: delid,
+ time: new Date().valueOf() + this.options.element_delete_delay
+ });
+ this.source_representation.model.set("delete_scheduled", delid);
+ } else {
+ if (confirm(this.renkan.translate('Do you really wish to remove node ') + '"' + this.source_representation.model.get("title") + '"?')) {
+ this.project.removeNode(this.source_representation.model);
+ }
+ }
+ }
+ }
+ }).value();
+
+ /* NodeRemoveButton End */
+
+ return NodeRemoveButton;
+
+});
+
+
+define('renderer/nodehidebutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeRemoveButton Begin */
+
+ //var NodeRemoveButton = Renderer.NodeRemoveButton = Utils.inherit(Renderer._NodeButton);
+ var NodeHideButton = Utils.inherit(NodeButton);
+
+ _(NodeHideButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-hide-button";
+ this.lastSectorInner = 0;
+ this.startAngle = 45;
+ this.endAngle = 90;
+ this.imageName = "hide";
+ this.text = "Hide";
+ },
+ mouseup: function() {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ this.renderer.removeRepresentationsOfType("editor");
+ if (this.renderer.isEditable()) {
+ this.renderer.view.addHiddenNode(this.source_representation.model);
+ }
+ }
+ }).value();
+
+ /* NodeRemoveButton End */
+
+ return NodeHideButton;
+
+});
+
+
+define('renderer/nodeshowbutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeRemoveButton Begin */
+
+ //var NodeRemoveButton = Renderer.NodeRemoveButton = Utils.inherit(Renderer._NodeButton);
+ var NodeShowButton = Utils.inherit(NodeButton);
+
+ _(NodeShowButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-show-button";
+ this.lastSectorInner = 0;
+ this.startAngle = 90;
+ this.endAngle = 135;
+ this.imageName = "show";
+ this.text = "Show";
+ },
+ mouseup: function() {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ this.renderer.removeRepresentationsOfType("editor");
+ if (this.renderer.isEditable()) {
+ this.source_representation.showNeighbors(false);
+ }
+ }
+ }).value();
+
+ /* NodeShowButton End */
+
+ return NodeShowButton;
+
+});
+
+
+define('renderer/noderevertbutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeRevertButton Begin */
+
+ //var NodeRevertButton = Renderer.NodeRevertButton = Utils.inherit(Renderer._NodeButton);
+ var NodeRevertButton = Utils.inherit(NodeButton);
+
+ _(NodeRevertButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-revert-button";
+ this.lastSectorInner = 0;
+ this.startAngle = -135;
+ this.endAngle = 135;
+ this.imageName = "revert";
+ this.text = "Cancel deletion";
+ },
+ mouseup: function() {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ if (this.renderer.isEditable()) {
+ this.source_representation.model.unset("delete_scheduled");
+ }
+ }
+ }).value();
+
+ /* NodeRevertButton End */
+
+ return NodeRevertButton;
+
+});
+
+
+define('renderer/nodelinkbutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeLinkButton Begin */
+
+ //var NodeLinkButton = Renderer.NodeLinkButton = Utils.inherit(Renderer._NodeButton);
+ var NodeLinkButton = Utils.inherit(NodeButton);
+
+ _(NodeLinkButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-link-button";
+ this.lastSectorInner = 0;
+ this.startAngle = this.options.hide_nodes ? 135 : 90;
+ this.endAngle = this.options.hide_nodes ? 190 : 180;
+ this.imageName = "link";
+ this.text = "Link to another node";
+ },
+ mousedown: function(_event, _isTouch) {
+ if (this.renderer.isEditable()) {
+ var _off = this.renderer.canvas_$.offset(),
+ _point = new paper.Point([
+ _event.pageX - _off.left,
+ _event.pageY - _off.top
+ ]);
+ this.renderer.click_target = null;
+ this.renderer.removeRepresentationsOfType("editor");
+ this.renderer.addTempEdge(this.source_representation, _point);
+ }
+ }
+ }).value();
+
+ /* NodeLinkButton End */
+
+ return NodeLinkButton;
+
+});
+
+
+
+define('renderer/nodeenlargebutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeEnlargeButton Begin */
+
+ //var NodeEnlargeButton = Renderer.NodeEnlargeButton = Utils.inherit(Renderer._NodeButton);
+ var NodeEnlargeButton = Utils.inherit(NodeButton);
+
+ _(NodeEnlargeButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-enlarge-button";
+ this.lastSectorInner = 0;
+ this.startAngle = this.options.hide_nodes ? -55 : -45;
+ this.endAngle = this.options.hide_nodes ? -10 : 0;
+ this.imageName = "enlarge";
+ this.text = "Enlarge";
+ },
+ mouseup: function() {
+ var _newsize = 1 + (this.source_representation.model.get("size") || 0);
+ this.source_representation.model.set("size", _newsize);
+ this.source_representation.select();
+ this.select();
+ paper.view.draw();
+ }
+ }).value();
+
+ /* NodeEnlargeButton End */
+
+ return NodeEnlargeButton;
+
+});
+
+
+define('renderer/nodeshrinkbutton',['jquery', 'underscore', 'requtils', 'renderer/nodebutton'], function ($, _, requtils, NodeButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* NodeShrinkButton Begin */
+
+ //var NodeShrinkButton = Renderer.NodeShrinkButton = Utils.inherit(Renderer._NodeButton);
+ var NodeShrinkButton = Utils.inherit(NodeButton);
+
+ _(NodeShrinkButton.prototype).extend({
+ _init: function() {
+ this.type = "Node-shrink-button";
+ this.lastSectorInner = 0;
+ this.startAngle = this.options.hide_nodes ? -170 : -180;
+ this.endAngle = this.options.hide_nodes ? -125 : -135;
+ this.imageName = "shrink";
+ this.text = "Shrink";
+ },
+ mouseup: function() {
+ var _newsize = -1 + (this.source_representation.model.get("size") || 0);
+ this.source_representation.model.set("size", _newsize);
+ this.source_representation.select();
+ this.select();
+ paper.view.draw();
+ }
+ }).value();
+
+ /* NodeShrinkButton End */
+
+ return NodeShrinkButton;
+
+});
+
+
+define('renderer/edgeeditbutton',['jquery', 'underscore', 'requtils', 'renderer/basebutton'], function ($, _, requtils, BaseButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* EdgeEditButton Begin */
+
+ //var EdgeEditButton = Renderer.EdgeEditButton = Utils.inherit(Renderer._BaseButton);
+ var EdgeEditButton = Utils.inherit(BaseButton);
+
+ _(EdgeEditButton.prototype).extend({
+ _init: function() {
+ this.type = "Edge-edit-button";
+ this.sector = this.renderer.drawSector(this, Utils._EDGE_BUTTON_INNER, Utils._EDGE_BUTTON_OUTER, -270, -90, 1, "edit", this.renkan.translate("Edit"));
+ },
+ mouseup: function() {
+ if (!this.renderer.is_dragging) {
+ this.source_representation.openEditor();
+ }
+ }
+ }).value();
+
+ /* EdgeEditButton End */
+
+ return EdgeEditButton;
+
+});
+
+
+define('renderer/edgeremovebutton',['jquery', 'underscore', 'requtils', 'renderer/basebutton'], function ($, _, requtils, BaseButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* EdgeRemoveButton Begin */
+
+ //var EdgeRemoveButton = Renderer.EdgeRemoveButton = Utils.inherit(Renderer._BaseButton);
+ var EdgeRemoveButton = Utils.inherit(BaseButton);
+
+ _(EdgeRemoveButton.prototype).extend({
+ _init: function() {
+ this.type = "Edge-remove-button";
+ this.sector = this.renderer.drawSector(this, Utils._EDGE_BUTTON_INNER, Utils._EDGE_BUTTON_OUTER, -90, 90, 1, "remove", this.renkan.translate("Remove"));
+ },
+ mouseup: function() {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ this.renderer.removeRepresentationsOfType("editor");
+ if (this.renderer.isEditable()) {
+ if (this.options.element_delete_delay) {
+ var delid = Utils.getUID("delete");
+ this.renderer.delete_list.push({
+ id: delid,
+ time: new Date().valueOf() + this.options.element_delete_delay
+ });
+ this.source_representation.model.set("delete_scheduled", delid);
+ } else {
+ if (confirm(this.renkan.translate('Do you really wish to remove edge ') + '"' + this.source_representation.model.get("title") + '"?')) {
+ this.project.removeEdge(this.source_representation.model);
+ }
+ }
+ }
+ }
+ }).value();
+
+ /* EdgeRemoveButton End */
+
+ return EdgeRemoveButton;
+
+});
+
+
+define('renderer/edgerevertbutton',['jquery', 'underscore', 'requtils', 'renderer/basebutton'], function ($, _, requtils, BaseButton) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* EdgeRevertButton Begin */
+
+ //var EdgeRevertButton = Renderer.EdgeRevertButton = Utils.inherit(Renderer._BaseButton);
+ var EdgeRevertButton = Utils.inherit(BaseButton);
+
+ _(EdgeRevertButton.prototype).extend({
+ _init: function() {
+ this.type = "Edge-revert-button";
+ this.sector = this.renderer.drawSector(this, Utils._EDGE_BUTTON_INNER, Utils._EDGE_BUTTON_OUTER, -135, 135, 1, "revert", this.renkan.translate("Cancel deletion"));
+ },
+ mouseup: function() {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ if (this.renderer.isEditable()) {
+ this.source_representation.model.unset("delete_scheduled");
+ }
+ }
+ }).value();
+
+ /* EdgeRevertButton End */
+
+ return EdgeRevertButton;
+
+});
+
+
+define('renderer/miniframe',['jquery', 'underscore', 'requtils', 'renderer/baserepresentation'], function ($, _, requtils, BaseRepresentation) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* MiniFrame Begin */
+
+ //var MiniFrame = Renderer.MiniFrame = Utils.inherit(Renderer._BaseRepresentation);
+ var MiniFrame = Utils.inherit(BaseRepresentation);
+
+ _(MiniFrame.prototype).extend({
+ paperShift: function(_delta) {
+ this.renderer.offset = this.renderer.offset.subtract(_delta.divide(this.renderer.minimap.scale).multiply(this.renderer.scale));
+ this.renderer.redraw();
+ },
+ mouseup: function(_delta) {
+ this.renderer.click_target = null;
+ this.renderer.is_dragging = false;
+ }
+ }).value();
+
+
+ /* MiniFrame End */
+
+ return MiniFrame;
+
+});
+
+
+define('renderer/scene',['jquery', 'underscore', 'filesaver', 'requtils', 'renderer/miniframe'], function ($, _, filesaver, requtils, MiniFrame) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* Scene Begin */
+
+ var Scene = function(_renkan) {
+ this.renkan = _renkan;
+ this.$ = $(".Rk-Render");
+ this.representations = [];
+ this.$.html(_renkan.options.templates['templates/scene.html'](_renkan));
+ this.onStatusChange();
+ this.canvas_$ = this.$.find(".Rk-Canvas");
+ this.labels_$ = this.$.find(".Rk-Labels");
+ if (!_renkan.options.popup_editor){
+ this.editor_$ = $("#" + _renkan.options.editor_panel);
+ }else{
+ this.editor_$ = this.$.find(".Rk-Editor");
+ }
+ this.notif_$ = this.$.find(".Rk-Notifications");
+ paper.setup(this.canvas_$[0]);
+ this.totalScroll = 0;
+ this.mouse_down = false;
+ this.click_target = null;
+ this.selected_target = null;
+ this.edge_layer = new paper.Layer();
+ this.node_layer = new paper.Layer();
+ this.buttons_layer = new paper.Layer();
+ this.delete_list = [];
+ this.redrawActive = true;
+
+ if (_renkan.options.show_minimap) {
+ this.minimap = {
+ background_layer: new paper.Layer(),
+ edge_layer: new paper.Layer(),
+ node_layer: new paper.Layer(),
+ node_group: new paper.Group(),
+ size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height )
+ };
+
+ this.minimap.background_layer.activate();
+ this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size);
+ this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4]));
+ this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color;
+ this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color;
+ this.minimap.rectangle.strokeWidth = 4;
+ this.minimap.offset = new paper.Point(this.minimap.size.divide(2));
+ this.minimap.scale = 0.1;
+
+ this.minimap.node_layer.activate();
+ this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
+ this.minimap.node_group.addChild(this.minimap.cliprectangle);
+ this.minimap.node_group.clipped = true;
+ this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
+ this.minimap.node_group.addChild(this.minimap.miniframe);
+ this.minimap.miniframe.fillColor = '#c0c0ff';
+ this.minimap.miniframe.opacity = 0.3;
+ this.minimap.miniframe.strokeColor = '#000080';
+ this.minimap.miniframe.strokeWidth = 2;
+ this.minimap.miniframe.__representation = new MiniFrame(this, null);
+ }
+
+ this.throttledPaperDraw = _(function() {
+ paper.view.draw();
+ }).throttle(100).value();
+
+ this.bundles = [];
+ this.click_mode = false;
+
+ var _this = this,
+ _allowScroll = true,
+ _originalScale = 1,
+ _zooming = false,
+ _lastTapX = 0,
+ _lastTapY = 0;
+
+ this.image_cache = {};
+ this.icon_cache = {};
+
+ ['edit', 'remove', 'hide', 'show', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) {
+ var img = new Image();
+ img.src = _renkan.options.static_url + 'img/' + imgname + '.png';
+ _this.icon_cache[imgname] = img;
+ });
+
+ var throttledMouseMove = _.throttle(function(_event, _isTouch) {
+ _this.onMouseMove(_event, _isTouch);
+ }, Utils._MOUSEMOVE_RATE);
+
+ this.canvas_$.on({
+ mousedown: function(_event) {
+ _event.preventDefault();
+ _this.onMouseDown(_event, false);
+ },
+ mousemove: function(_event) {
+ _event.preventDefault();
+ throttledMouseMove(_event, false);
+ },
+ mouseup: function(_event) {
+ _event.preventDefault();
+ _this.onMouseUp(_event, false);
+ },
+ mousewheel: function(_event, _delta) {
+ if(_renkan.options.zoom_on_scroll) {
+ _event.preventDefault();
+ if (_allowScroll) {
+ _this.onScroll(_event, _delta);
+ }
+ }
+ },
+ touchstart: function(_event) {
+ _event.preventDefault();
+ var _touches = _event.originalEvent.touches[0];
+ if (
+ _renkan.options.allow_double_click &&
+ new Date() - _lastTap < Utils._DOUBLETAP_DELAY &&
+ ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Utils._DOUBLETAP_DISTANCE )
+ ) {
+ _lastTap = 0;
+ _this.onDoubleClick(_touches);
+ } else {
+ _lastTap = new Date();
+ _lastTapX = _touches.pageX;
+ _lastTapY = _touches.pageY;
+ _originalScale = _this.view.scale;
+ _zooming = false;
+ _this.onMouseDown(_touches, true);
+ }
+ },
+ touchmove: function(_event) {
+ _event.preventDefault();
+ _lastTap = 0;
+ if (_event.originalEvent.touches.length === 1) {
+ _this.onMouseMove(_event.originalEvent.touches[0], true);
+ } else {
+ if (!_zooming) {
+ _this.onMouseUp(_event.originalEvent.touches[0], true);
+ _this.click_target = null;
+ _this.is_dragging = false;
+ _zooming = true;
+ }
+ if (_event.originalEvent.scale === "undefined") {
+ return;
+ }
+ var _newScale = _event.originalEvent.scale * _originalScale,
+ _scaleRatio = _newScale / _this.view.scale,
+ _newOffset = new paper.Point([
+ _this.canvas_$.width(),
+ _this.canvas_$.height()
+ ]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.view.offset.multiply( _scaleRatio ));
+ _this.view.setScale(_newScale, _newOffset);
+ }
+ },
+ touchend: function(_event) {
+ _event.preventDefault();
+ _this.onMouseUp(_event.originalEvent.changedTouches[0], true);
+ },
+ dblclick: function(_event) {
+ _event.preventDefault();
+ if (_renkan.options.allow_double_click) {
+ _this.onDoubleClick(_event);
+ }
+ },
+ mouseleave: function(_event) {
+ _event.preventDefault();
+ //_this.onMouseUp(_event, false);
+ _this.click_target = null;
+ _this.is_dragging = false;
+ },
+ dragover: function(_event) {
+ _event.preventDefault();
+ },
+ dragenter: function(_event) {
+ _event.preventDefault();
+ _allowScroll = false;
+ },
+ dragleave: function(_event) {
+ _event.preventDefault();
+ _allowScroll = true;
+ },
+ drop: function(_event) {
+ _event.preventDefault();
+ _allowScroll = true;
+ var res = {};
+ _.each(_event.originalEvent.dataTransfer.types, function(t) {
+ try {
+ res[t] = _event.originalEvent.dataTransfer.getData(t);
+ } catch(e) {}
+ });
+ var text = _event.originalEvent.dataTransfer.getData("Text");
+ if (typeof text === "string") {
+ switch(text[0]) {
+ case "{":
+ case "[":
+ try {
+ var data = JSON.parse(text);
+ _.extend(res,data);
+ }
+ catch(e) {
+ if (!res["text/plain"]) {
+ res["text/plain"] = text;
+ }
+ }
+ break;
+ case "<":
+ if (!res["text/html"]) {
+ res["text/html"] = text;
+ }
+ break;
+ default:
+ if (!res["text/plain"]) {
+ res["text/plain"] = text;
+ }
+ }
+ }
+ var url = _event.originalEvent.dataTransfer.getData("URL");
+ if (url && !res["text/uri-list"]) {
+ res["text/uri-list"] = url;
+ }
+ _this.dropData(res, _event.originalEvent);
+ }
+ });
+
+ var bindClick = function(selector, fname) {
+ _this.$.find(selector).click(function(evt) {
+ _this[fname](evt);
+ return false;
+ });
+ };
+
+ if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
+ this.$.find(".Rk-ZoomSetSaved").show();
+ }
+ this.$.find(".Rk-CurrentUser").mouseenter(
+ function() { _this.$.find(".Rk-UserList").slideDown(); }
+ );
+ this.$.find(".Rk-Users").mouseleave(
+ function() { _this.$.find(".Rk-UserList").slideUp(); }
+ );
+ bindClick(".Rk-FullScreen-Button", "fullScreen");
+ bindClick(".Rk-AddNode-Button", "addNodeBtn");
+ bindClick(".Rk-AddEdge-Button", "addEdgeBtn");
+ bindClick(".Rk-Save-Button", "save");
+ bindClick(".Rk-Open-Button", "open");
+ bindClick(".Rk-Export-Button", "exportProject");
+ this.$.find(".Rk-Bookmarklet-Button")
+ /*jshint scripturl:true */
+ .attr("href","javascript:" + Utils._BOOKMARKLET_CODE(_renkan))
+ .click(function(){
+ _this.notif_$
+ .text(_renkan.translate("Drag this button to your bookmark bar. When on a third-party website, click it to enable drag-and-drop from the website to Renkan."))
+ .fadeIn()
+ .delay(5000)
+ .fadeOut();
+ return false;
+ });
+ this.$.find(".Rk-TopBar-Button").mouseover(function() {
+ $(this).find(".Rk-TopBar-Tooltip").show();
+ }).mouseout(function() {
+ $(this).find(".Rk-TopBar-Tooltip").hide();
+ });
+ bindClick(".Rk-Fold-Bins", "foldBins");
+
+ paper.view.onResize = function(_event) {
+ var _ratio,
+ newWidth = _event.width,
+ newHeight = _event.height;
+
+ if (_this.minimap) {
+ _this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size);
+ _this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4]));
+ _this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size);
+ }
+
+ var ratioH = newHeight/(newHeight-_event.delta.height),
+ ratioW = newWidth/(newWidth-_event.delta.width);
+ if (newHeight < newWidth) {
+ _ratio = ratioH;
+ } else {
+ _ratio = ratioW;
+ }
+
+ _this.view.resizeZoom(ratioW, ratioH, _ratio);
+
+ _this.redraw();
+
+ };
+
+ var _thRedraw = _.throttle(function() {
+ _this.redraw();
+ },50);
+
+ this.addRepresentations("Node", this.renkan.project.get("nodes"));
+ this.addRepresentations("Edge", this.renkan.project.get("edges"));
+ this.renkan.project.on("change:title", function() {
+ _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
+ });
+
+ this.$.find(".Rk-PadTitle").on("keyup input paste", function() {
+ _renkan.project.set({"title": $(this).val()});
+ });
+
+ var _thRedrawUsers = _.throttle(function() {
+ _this.redrawUsers();
+ }, 100);
+
+ _thRedrawUsers();
+
+ // register model events
+ this.renkan.project.on("change:saveStatus", function(){
+ switch (_this.renkan.project.get("saveStatus")) {
+ case 0: //clean
+ _this.$.find(".Rk-Save-Button").removeClass("to-save");
+ _this.$.find(".Rk-Save-Button").removeClass("saving");
+ _this.$.find(".Rk-Save-Button").addClass("saved");
+ break;
+ case 1: //dirty
+ _this.$.find(".Rk-Save-Button").removeClass("saved");
+ _this.$.find(".Rk-Save-Button").removeClass("saving");
+ _this.$.find(".Rk-Save-Button").addClass("to-save");
+ break;
+ case 2: //saving
+ _this.$.find(".Rk-Save-Button").removeClass("saved");
+ _this.$.find(".Rk-Save-Button").removeClass("to-save");
+ _this.$.find(".Rk-Save-Button").addClass("saving");
+ break;
+ }
+ });
+
+ this.renkan.project.on("change:loadingStatus", function(){
+ if (_this.renkan.project.get("loadingStatus")){
+ var animate = _this.$.find(".loader").addClass("run");
+ var timer = setTimeout(function(){
+ _this.$.find(".loader").hide(250);
+ }, 3000);
+ }
+ else{
+ Backbone.history.start();
+ _thRedraw();
+ }
+ });
+
+ this.renkan.project.on("add:users remove:users", _thRedrawUsers);
+
+ this.renkan.project.on("add:views remove:views", function(_node) {
+ if(_this.renkan.project.get('views').length > 0) {
+ _this.$.find(".Rk-ZoomSetSaved").show();
+ }
+ else {
+ _this.$.find(".Rk-ZoomSetSaved").hide();
+ }
+ });
+
+ this.renkan.project.on("add:nodes", function(_node) {
+ _this.addRepresentation("Node", _node);
+ if (!_this.renkan.project.get("loadingStatus")){
+ _thRedraw();
+ }
+ });
+ this.renkan.project.on("add:edges", function(_edge) {
+ _this.addRepresentation("Edge", _edge);
+ if (!_this.renkan.project.get("loadingStatus")){
+ _thRedraw();
+ }
+ });
+ this.renkan.project.on("change:title", function(_model, _title) {
+ var el = _this.$.find(".Rk-PadTitle");
+ if (el.is("input")) {
+ if (el.val() !== _title) {
+ el.val(_title);
+ }
+ } else {
+ el.text(_title);
+ }
+ });
+
+ //register router events
+ this.renkan.router.on("router", function(_params){
+ _this.parameters(_params);
+ });
+
+ if (_renkan.options.size_bug_fix) {
+ var _delay = (
+ typeof _renkan.options.size_bug_fix === "number" ?
+ _renkan.options.size_bug_fix
+ : 500
+ );
+ window.setTimeout(
+ function() {
+ _this.fixSize();
+ },
+ _delay
+ );
+ }
+
+ if (_renkan.options.force_resize) {
+ $(window).resize(function() {
+ _this.autoScale();
+ });
+ }
+
+ if (_renkan.options.show_user_list && _renkan.options.user_color_editable) {
+ var $cpwrapper = this.$.find(".Rk-Users .Rk-Edit-ColorPicker-Wrapper"),
+ $cplist = this.$.find(".Rk-Users .Rk-Edit-ColorPicker");
+
+ $cpwrapper.hover(
+ function(_e) {
+ if (_this.isEditable()) {
+ _e.preventDefault();
+ $cplist.show();
+ }
+ },
+ function(_e) {
+ _e.preventDefault();
+ $cplist.hide();
+ }
+ );
+
+ $cplist.find("li").mouseenter(
+ function(_e) {
+ if (_this.isEditable()) {
+ _e.preventDefault();
+ _this.$.find(".Rk-CurrentUser-Color").css("background", $(this).attr("data-color"));
+ }
+ }
+ );
+ }
+
+ if (_renkan.options.show_search_field) {
+
+ var lastval = '';
+
+ this.$.find(".Rk-GraphSearch-Field").on("keyup change paste input", function() {
+ var $this = $(this),
+ val = $this.val();
+ if (val === lastval) {
+ return;
+ }
+ lastval = val;
+ if (val.length < 2) {
+ _renkan.project.get("nodes").each(function(n) {
+ _this.getRepresentationByModel(n).unhighlight();
+ });
+ } else {
+ var rxs = Utils.regexpFromTextOrArray(val);
+ _renkan.project.get("nodes").each(function(n) {
+ if (rxs.test(n.get("title")) || rxs.test(n.get("description"))) {
+ _this.getRepresentationByModel(n).highlight(rxs);
+ } else {
+ _this.getRepresentationByModel(n).unhighlight();
+ }
+ });
+ }
+ });
+ }
+
+ this.redraw();
+
+ window.setInterval(function() {
+ var _now = new Date().valueOf();
+ _this.delete_list.forEach(function(d) {
+ if (_now >= d.time) {
+ var el = _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id});
+ if (el) {
+ project.removeNode(el);
+ }
+ el = _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
+ if (el) {
+ project.removeEdge(el);
+ }
+ }
+ });
+ _this.delete_list = _this.delete_list.filter(function(d) {
+ return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
+ });
+ }, 500);
+
+ if (this.minimap) {
+ window.setInterval(function() {
+ _this.rescaleMinimap();
+ }, 2000);
+ }
+
+ };
+
+ _(Scene.prototype).extend({
+ fixSize: function() {
+ if(typeof this.view === 'undefined') {
+ this.view = this.addRepresentation("View", this.renkan.project.get("views").last());
+ this.view.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
+ }
+ else{
+ this.view.autoScale();
+ }
+ },
+ drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
+ var _options = this.renkan.options,
+ _startRads = _startAngle * Math.PI / 180,
+ _endRads = _endAngle * Math.PI / 180,
+ _img = this.icon_cache[_imgname],
+ _startdx = - Math.sin(_startRads),
+ _startdy = Math.cos(_startRads),
+ _startXIn = Math.cos(_startRads) * _inR + _padding * _startdx,
+ _startYIn = Math.sin(_startRads) * _inR + _padding * _startdy,
+ _startXOut = Math.cos(_startRads) * _outR + _padding * _startdx,
+ _startYOut = Math.sin(_startRads) * _outR + _padding * _startdy,
+ _enddx = - Math.sin(_endRads),
+ _enddy = Math.cos(_endRads),
+ _endXIn = Math.cos(_endRads) * _inR - _padding * _enddx,
+ _endYIn = Math.sin(_endRads) * _inR - _padding * _enddy,
+ _endXOut = Math.cos(_endRads) * _outR - _padding * _enddx,
+ _endYOut = Math.sin(_endRads) * _outR - _padding * _enddy,
+ _centerR = (_inR + _outR) / 2,
+ _centerRads = (_startRads + _endRads) / 2,
+ _centerX = Math.cos(_centerRads) * _centerR,
+ _centerY = Math.sin(_centerRads) * _centerR,
+ _centerXIn = Math.cos(_centerRads) * _inR,
+ _centerXOut = Math.cos(_centerRads) * _outR,
+ _centerYIn = Math.sin(_centerRads) * _inR,
+ _centerYOut = Math.sin(_centerRads) * _outR,
+ _textX = Math.cos(_centerRads) * (_outR + 3),
+ _textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2;
+ this.buttons_layer.activate();
+ var _path = new paper.Path();
+ _path.add([_startXIn, _startYIn]);
+ _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]);
+ _path.lineTo([_endXOut, _endYOut]);
+ _path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]);
+ _path.fillColor = _options.buttons_background;
+ _path.opacity = 0.5;
+ _path.closed = true;
+ _path.__representation = _repr;
+ var _text = new paper.PointText(_textX,_textY);
+ _text.characterStyle = {
+ fontSize: _options.buttons_label_font_size,
+ fillColor: _options.buttons_label_color
+ };
+ if (_textX > 2) {
+ _text.paragraphStyle.justification = 'left';
+ } else if (_textX < -2) {
+ _text.paragraphStyle.justification = 'right';
+ } else {
+ _text.paragraphStyle.justification = 'center';
+ }
+ _text.visible = false;
+ var _visible = false,
+ _restPos = new paper.Point(-200, -200),
+ _grp = new paper.Group([_path, _text]),
+ //_grp = new paper.Group([_path]),
+ _delta = _grp.position,
+ _imgdelta = new paper.Point([_centerX, _centerY]),
+ _currentPos = new paper.Point(0,0);
+ _text.content = _caption;
+ // set group pivot to not depend on text visibility that changes the group bounding box.
+ _grp.pivot = _grp.bounds.center;
+ _grp.visible = false;
+ _grp.position = _restPos;
+ var _res = {
+ show: function() {
+ _visible = true;
+ _grp.position = _currentPos.add(_delta);
+ _grp.visible = true;
+ },
+ moveTo: function(_point) {
+ _currentPos = _point;
+ if (_visible) {
+ _grp.position = _point.add(_delta);
+ }
+ },
+ hide: function() {
+ _visible = false;
+ _grp.visible = false;
+ _grp.position = _restPos;
+ },
+ select: function() {
+ _path.opacity = 0.8;
+ _text.visible = true;
+ },
+ unselect: function() {
+ _path.opacity = 0.5;
+ _text.visible = false;
+ },
+ destroy: function() {
+ _grp.remove();
+ }
+ };
+ var showImage = function() {
+ var _raster = new paper.Raster(_img);
+ _raster.position = _imgdelta.add(_grp.position).subtract(_delta);
+ _raster.locked = true; // Disable mouse events on icon
+ _grp.addChild(_raster);
+ };
+ if (_img.width) {
+ showImage();
+ } else {
+ $(_img).on("load",showImage);
+ }
+
+ return _res;
+ },
+ addToBundles: function(_edgeRepr) {
+ var _bundle = _(this.bundles).find(function(_bundle) {
+ return (
+ ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) ||
+ ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation )
+ );
+ });
+ if (typeof _bundle !== "undefined") {
+ _bundle.edges.push(_edgeRepr);
+ } else {
+ _bundle = {
+ from: _edgeRepr.from_representation,
+ to: _edgeRepr.to_representation,
+ edges: [ _edgeRepr ],
+ getPosition: function(_er) {
+ var _dir = (_er.from_representation === this.from) ? 1 : -1;
+ return _dir * ( _(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 );
+ }
+ };
+ this.bundles.push(_bundle);
+ }
+ return _bundle;
+ },
+ isEditable: function() {
+ return (this.renkan.options.editor_mode && !this.renkan.read_only);
+ },
+ onStatusChange: function() {
+ var savebtn = this.$.find(".Rk-Save-Button"),
+ tip = savebtn.find(".Rk-TopBar-Tooltip-Contents");
+ if (this.renkan.read_only) {
+ savebtn.removeClass("disabled Rk-Save-Online").addClass("Rk-Save-ReadOnly");
+ tip.text(this.renkan.translate("Connection lost"));
+ } else {
+ if (this.renkan.options.manual_save) {
+ savebtn.removeClass("Rk-Save-ReadOnly Rk-Save-Online");
+ tip.text(this.renkan.translate("Save Project"));
+ } else {
+ savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online");
+ tip.text(this.renkan.translate("Auto-save enabled"));
+ }
+ }
+ this.redrawUsers();
+ },
+ redrawMiniframe: function() {
+ var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
+ bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
+ this.minimap.miniframe.fitBounds(topleft, bottomright);
+ },
+ rescaleMinimap: function() {
+ var nodes = this.renkan.project.get("nodes");
+ if (nodes.length > 1) {
+ var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
+ _yy = nodes.map(function(_node) { return _node.get("position").y; }),
+ _minx = Math.min.apply(Math, _xx),
+ _miny = Math.min.apply(Math, _yy),
+ _maxx = Math.max.apply(Math, _xx),
+ _maxy = Math.max.apply(Math, _yy);
+ var _scale = Math.min(
+ this.view.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width,
+ this.view.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height,
+ ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx),
+ ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny)
+ );
+ this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
+ this.minimap.scale = _scale;
+ }
+ if (nodes.length === 1) {
+ this.minimap.scale = 0.1;
+ 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));
+ }
+ this.redraw();
+ },
+ toPaperCoords: function(_point) {
+ return _point.multiply(this.view.scale).add(this.view.offset);
+ },
+ toMinimapCoords: function(_point) {
+ return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft);
+ },
+ toModelCoords: function(_point) {
+ return _point.subtract(this.view.offset).divide(this.view.scale);
+ },
+ addRepresentation: function(_type, _model) {
+ var RendererType = requtils.getRenderer()[_type];
+ var _repr = new RendererType(this, _model);
+ this.representations.push(_repr);
+ return _repr;
+ },
+ addRepresentations: function(_type, _collection) {
+ var _this = this;
+ _collection.forEach(function(_model) {
+ _this.addRepresentation(_type, _model);
+ });
+ },
+ userTemplate: _.template(
+ '
<%=name%>'
+ ),
+ redrawUsers: function() {
+ if (!this.renkan.options.show_user_list) {
+ return;
+ }
+ var allUsers = [].concat((this.renkan.project.current_user_list || {}).models || [], (this.renkan.project.get("users") || {}).models || []),
+ ulistHtml = '',
+ $userpanel = this.$.find(".Rk-Users"),
+ $name = $userpanel.find(".Rk-CurrentUser-Name"),
+ $cpitems = $userpanel.find(".Rk-Edit-ColorPicker li"),
+ $colorsquare = $userpanel.find(".Rk-CurrentUser-Color"),
+ _this = this;
+ $name.off("click").text(this.renkan.translate("
"));
+ $cpitems.off("mouseleave click");
+ allUsers.forEach(function(_user) {
+ if (_user.get("_id") === _this.renkan.current_user) {
+ $name.text(_user.get("title"));
+ $colorsquare.css("background", _user.get("color"));
+ if (_this.isEditable()) {
+
+ if (_this.renkan.options.user_name_editable) {
+ $name.click(function() {
+ var $this = $(this),
+ $input = $('').val(_user.get("title")).blur(function() {
+ _user.set("title", $(this).val());
+ _this.redrawUsers();
+ _this.redraw();
+ });
+ $this.empty().html($input);
+ $input.select();
+ });
+ }
+
+ if (_this.renkan.options.user_color_editable) {
+ $cpitems.click(
+ function(_e) {
+ _e.preventDefault();
+ if (_this.isEditable()) {
+ _user.set("color", $(this).attr("data-color"));
+ }
+ $(this).parent().hide();
+ }
+ ).mouseleave(function() {
+ $colorsquare.css("background", _user.get("color"));
+ });
+ }
+ }
+
+ } else {
+ ulistHtml += _this.userTemplate({
+ name: _user.get("title"),
+ background: _user.get("color")
+ });
+ }
+ });
+ $userpanel.find(".Rk-UserList").html(ulistHtml);
+ },
+ removeRepresentation: function(_representation) {
+ _representation.destroy();
+ this.representations = _.reject(this.representations,
+ function(_repr) {
+ return _repr === _representation;
+ }
+ );
+ },
+ getRepresentationByModel: function(_model) {
+ if (!_model) {
+ return undefined;
+ }
+ return _.find(this.representations, function(_repr) {
+ return _repr.model === _model;
+ });
+ },
+ removeRepresentationsOfType: function(_type) {
+ var _representations = _.filter(this.representations,function(_repr) {
+ return _repr.type === _type;
+ }),
+ _this = this;
+ _.each(_representations, function(_repr) {
+ _this.removeRepresentation(_repr);
+ });
+ },
+ highlightModel: function(_model) {
+ var _repr = this.getRepresentationByModel(_model);
+ if (_repr) {
+ _repr.highlight();
+ }
+ },
+ unhighlightAll: function(_model) {
+ _.each(this.representations, function(_repr) {
+ _repr.unhighlight();
+ });
+ },
+ unselectAll: function(_model) {
+ _.each(this.representations, function(_repr) {
+ _repr.unselect();
+ });
+ },
+ redraw: function() {
+ var _this = this;
+ if(! this.redrawActive ) {
+ return;
+ }
+ _.each(this.representations, function(_representation) {
+ _representation.redraw({ dontRedrawEdges:true });
+ });
+ if (this.minimap && typeof this.view !== 'undefined') {
+ this.redrawMiniframe();
+ }
+ paper.view.draw();
+ },
+ addTempEdge: function(_from, _point) {
+ var _tmpEdge = this.addRepresentation("TempEdge",null);
+ _tmpEdge.end_pos = _point;
+ _tmpEdge.from_representation = _from;
+ _tmpEdge.redraw();
+ this.click_target = _tmpEdge;
+ },
+ findTarget: function(_hitResult) {
+ if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
+ var _newTarget = _hitResult.item.__representation;
+ if (this.selected_target !== _hitResult.item.__representation) {
+ if (this.selected_target) {
+ this.selected_target.unselect(_newTarget);
+ }
+ _newTarget.select(this.selected_target);
+ this.selected_target = _newTarget;
+ }
+ } else {
+ if (this.selected_target) {
+ this.selected_target.unselect();
+ }
+ this.selected_target = null;
+ }
+ },
+ onMouseMove: function(_event) {
+ var _off = this.canvas_$.offset(),
+ _point = new paper.Point([
+ _event.pageX - _off.left,
+ _event.pageY - _off.top
+ ]),
+ _delta = _point.subtract(this.last_point);
+ this.last_point = _point;
+ if (!this.is_dragging && this.mouse_down && _delta.length > Utils._MIN_DRAG_DISTANCE) {
+ this.is_dragging = true;
+ }
+ var _hitResult = paper.project.hitTest(_point);
+ if (this.is_dragging) {
+ if (this.click_target && typeof this.click_target.paperShift === "function") {
+ this.click_target.paperShift(_delta);
+ } else {
+ this.view.paperShift(_delta);
+ }
+ } else {
+ this.findTarget(_hitResult);
+ }
+ paper.view.draw();
+ },
+ onMouseDown: function(_event, _isTouch) {
+ var _off = this.canvas_$.offset(),
+ _point = new paper.Point([
+ _event.pageX - _off.left,
+ _event.pageY - _off.top
+ ]);
+ this.last_point = _point;
+ this.mouse_down = true;
+ if (!this.click_target || this.click_target.type !== "Temp-edge") {
+ this.removeRepresentationsOfType("editor");
+ this.is_dragging = false;
+ var _hitResult = paper.project.hitTest(_point);
+ if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
+ this.click_target = _hitResult.item.__representation;
+ this.click_target.mousedown(_event, _isTouch);
+ } else {
+ this.click_target = null;
+ if (this.isEditable() && this.click_mode === Utils._CLICKMODE_ADDNODE) {
+ var _coords = this.toModelCoords(_point),
+ _data = {
+ id: Utils.getUID('node'),
+ created_by: this.renkan.current_user,
+ position: {
+ x: _coords.x,
+ y: _coords.y
+ }
+ };
+ var _node = this.renkan.project.addNode(_data);
+ this.getRepresentationByModel(_node).openEditor();
+ }
+ }
+ }
+ if (this.click_mode) {
+ if (this.isEditable() && this.click_mode === Utils._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") {
+ this.removeRepresentationsOfType("editor");
+ this.addTempEdge(this.click_target, _point);
+ this.click_mode = Utils._CLICKMODE_ENDEDGE;
+ this.notif_$.fadeOut(function() {
+ $(this).html(this.renkan.translate("Click on a second node to complete the edge")).fadeIn();
+ });
+ } else {
+ this.notif_$.hide();
+ this.click_mode = false;
+ }
+ }
+ paper.view.draw();
+ },
+ onMouseUp: function(_event, _isTouch) {
+ this.mouse_down = false;
+ if (this.click_target) {
+ var _off = this.canvas_$.offset();
+ this.click_target.mouseup(
+ {
+ point: new paper.Point([
+ _event.pageX - _off.left,
+ _event.pageY - _off.top
+ ])
+ },
+ _isTouch
+ );
+ } else {
+ this.click_target = null;
+ this.is_dragging = false;
+ if (_isTouch) {
+ this.unselectAll();
+ }
+ this.view.updateUrl();
+ }
+ paper.view.draw();
+ },
+ onScroll: function(_event, _scrolldelta) {
+ this.totalScroll += _scrolldelta;
+ if (Math.abs(this.totalScroll) >= 1) {
+ var _off = this.canvas_$.offset(),
+ _delta = new paper.Point([
+ _event.pageX - _off.left,
+ _event.pageY - _off.top
+ ]).subtract(this.view.offset).multiply( Math.SQRT2 - 1 );
+ if (this.totalScroll > 0) {
+ this.view.setScale( this.view.scale * Math.SQRT2, this.view.offset.subtract(_delta) );
+ } else {
+ this.view.setScale( this.view.scale * Math.SQRT1_2, this.view.offset.add(_delta.divide(Math.SQRT2)));
+ }
+ this.totalScroll = 0;
+ }
+ },
+ onDoubleClick: function(_event) {
+ var _off = this.canvas_$.offset(),
+ _point = new paper.Point([
+ _event.pageX - _off.left,
+ _event.pageY - _off.top
+ ]);
+ var _hitResult = paper.project.hitTest(_point);
+
+ if (!this.isEditable()) {
+ if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
+ if (_hitResult.item.__representation.model.get('uri')){
+ window.open(_hitResult.item.__representation.model.get('uri'), '_blank');
+ }
+ }
+ return;
+ }
+ if (this.isEditable() && (!_hitResult || typeof _hitResult.item.__representation === "undefined")) {
+ var _coords = this.toModelCoords(_point),
+ _data = {
+ id: Utils.getUID('node'),
+ created_by: this.renkan.current_user,
+ position: {
+ x: _coords.x,
+ y: _coords.y
+ }
+ },
+ _node = this.renkan.project.addNode(_data);
+ this.getRepresentationByModel(_node).openEditor();
+ }
+ paper.view.draw();
+ },
+ defaultDropHandler: function(_data) {
+ var newNode = {};
+ var snippet = "";
+ switch(_data["text/x-iri-specific-site"]) {
+ case "twitter":
+ snippet = $('').html(_data["text/x-iri-selected-html"]);
+ var tweetdiv = snippet.find(".tweet");
+ newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name");
+ newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id");
+ newNode.image = tweetdiv.find(".avatar").attr("src");
+ newNode.description = tweetdiv.find(".js-tweet-text:first").text();
+ break;
+ case "google":
+ snippet = $('
').html(_data["text/x-iri-selected-html"]);
+ newNode.title = snippet.find("h3:first").text().trim();
+ newNode.uri = snippet.find("h3 a").attr("href");
+ newNode.description = snippet.find(".st:first").text().trim();
+ break;
+ default:
+ if (_data["text/x-iri-source-uri"]) {
+ newNode.uri = _data["text/x-iri-source-uri"];
+ }
+ }
+ if (_data["text/plain"] || _data["text/x-iri-selected-text"]) {
+ newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim();
+ }
+ if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
+ snippet = $('
').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
+ var _svgimgs = snippet.find("image");
+ if (_svgimgs.length) {
+ newNode.image = _svgimgs.attr("xlink:href");
+ }
+ var _svgpaths = snippet.find("path");
+ if (_svgpaths.length) {
+ newNode.clipPath = _svgpaths.attr("d");
+ }
+ var _imgs = snippet.find("img");
+ if (_imgs.length) {
+ newNode.image = _imgs[0].src;
+ }
+ var _as = snippet.find("a");
+ if (_as.length) {
+ newNode.uri = _as[0].href;
+ }
+ newNode.title = snippet.find("[title]").attr("title") || newNode.title;
+ newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim();
+ }
+ if (_data["text/uri-list"]) {
+ newNode.uri = _data["text/uri-list"];
+ }
+ if (_data["text/x-moz-url"] && !newNode.title) {
+ newNode.title = (_data["text/x-moz-url"].split("\n")[1] || "").trim();
+ if (newNode.title === newNode.uri) {
+ newNode.title = false;
+ }
+ }
+ if (_data["text/x-iri-source-title"] && !newNode.title) {
+ newNode.title = _data["text/x-iri-source-title"];
+ }
+ if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
+ snippet = $('
').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
+ newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image;
+ newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri;
+ newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title;
+ newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description;
+ newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath;
+ }
+
+ if (!newNode.title) {
+ newNode.title = this.renkan.translate("Dragged resource");
+ }
+ var fields = ["title", "description", "uri", "image"];
+ for (var i = 0; i < fields.length; i++) {
+ var f = fields[i];
+ if (_data["text/x-iri-" + f] || _data[f]) {
+ newNode[f] = _data["text/x-iri-" + f] || _data[f];
+ }
+ if (newNode[f] === "none" || newNode[f] === "null") {
+ newNode[f] = undefined;
+ }
+ }
+
+ if(typeof this.renkan.options.drop_enhancer === "function"){
+ newNode = this.renkan.options.drop_enhancer(newNode, _data);
+ }
+
+ return newNode;
+
+ },
+ dropData: function(_data, _event) {
+ if (!this.isEditable()) {
+ return;
+ }
+ if (_data["text/json"] || _data["application/json"]) {
+ try {
+ var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]);
+ _.extend(_data,jsondata);
+ }
+ catch(e) {}
+ }
+
+ var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data);
+
+ var _off = this.canvas_$.offset(),
+ _point = new paper.Point([
+ _event.pageX - _off.left,
+ _event.pageY - _off.top
+ ]),
+ _coords = this.toModelCoords(_point),
+ _nodedata = {
+ id: Utils.getUID('node'),
+ created_by: this.renkan.current_user,
+ uri: newNode.uri || "",
+ title: newNode.title || "",
+ description: newNode.description || "",
+ image: newNode.image || "",
+ color: newNode.color || undefined,
+ clip_path: newNode.clipPath || undefined,
+ position: {
+ x: _coords.x,
+ y: _coords.y
+ }
+ };
+ var _node = this.renkan.project.addNode(_nodedata),
+ _repr = this.getRepresentationByModel(_node);
+ if (_event.type === "drop") {
+ _repr.openEditor();
+ }
+ },
+ fullScreen: function() {
+ var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen,
+ _el = this.renkan.$[0],
+ _requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"],
+ _cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"],
+ i;
+ if (_isFull) {
+ for (i = 0; i < _cancelMethods.length; i++) {
+ if (typeof document[_cancelMethods[i]] === "function") {
+ document[_cancelMethods[i]]();
+ break;
+ }
+ }
+ var widthAft = this.$.width();
+ var heightAft = this.$.height();
+
+ if (this.renkan.options.show_top_bar) {
+ heightAft -= this.$.find(".Rk-TopBar").height();
+ }
+ if (this.renkan.options.show_bins && (this.renkan.$.find(".Rk-Bins").position().left > 0)) {
+ widthAft -= this.renkan.$.find(".Rk-Bins").width();
+ }
+
+ paper.view.viewSize = new paper.Size([widthAft, heightAft]);
+
+ } else {
+ for (i = 0; i < _requestMethods.length; i++) {
+ if (typeof _el[_requestMethods[i]] === "function") {
+ _el[_requestMethods[i]]();
+ break;
+ }
+ }
+ this.redraw();
+ }
+ },
+ addNodeBtn: function() {
+ if (this.click_mode === Utils._CLICKMODE_ADDNODE) {
+ this.click_mode = false;
+ this.notif_$.hide();
+ } else {
+ this.click_mode = Utils._CLICKMODE_ADDNODE;
+ this.notif_$.text(this.renkan.translate("Click on the background canvas to add a node")).fadeIn();
+ }
+ return false;
+ },
+ addEdgeBtn: function() {
+ if (this.click_mode === Utils._CLICKMODE_STARTEDGE || this.click_mode === Utils._CLICKMODE_ENDEDGE) {
+ this.click_mode = false;
+ this.notif_$.hide();
+ } else {
+ this.click_mode = Utils._CLICKMODE_STARTEDGE;
+ this.notif_$.text(this.renkan.translate("Click on a first node to start the edge")).fadeIn();
+ }
+ return false;
+ },
+ exportProject: function() {
+ var projectJSON = this.renkan.project.toJSON(),
+ downloadLink = document.createElement("a"),
+ projectId = projectJSON.id,
+ fileNameToSaveAs = projectId + ".json";
+
+ // clean ids
+ delete projectJSON.id;
+ delete projectJSON._id;
+ delete projectJSON.space_id;
+
+ var objId,
+ idsMap = {},
+ hiddenNodes;
+
+ _.each(projectJSON.nodes, function(e,i,l) {
+ objId = e.id || e._id;
+ delete e._id;
+ delete e.id;
+ idsMap[objId] = e['@id'] = Utils.getUUID4();
+ });
+ _.each(projectJSON.edges, function(e,i,l) {
+ delete e._id;
+ delete e.id;
+ e.to = idsMap[e.to];
+ e.from = idsMap[e.from];
+ });
+ _.each(projectJSON.views, function(e,i,l) {
+ delete e._id;
+ delete e.id;
+
+ if(e.hidden_nodes) {
+ hiddenNodes = e.hidden_nodes;
+ e.hidden_nodes = [];
+ _.each(hiddenNodes, function(h,j) {
+ e.hidden_nodes.push(idsMap[h]);
+ });
+ }
+ });
+ projectJSON.users = [];
+
+ var projectJSONStr = JSON.stringify(projectJSON, null, 2);
+ var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"});
+ filesaver(blob,fileNameToSaveAs);
+
+ },
+ parameters: function(_params){
+ this.removeRepresentationsOfType("View");
+ if ($.isEmptyObject(_params)){
+ this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view)));
+ if (!this.renkan.options.default_view){
+ this.view.autoScale();
+ }
+ return;
+ }
+ if (typeof _params.viewIndex !== 'undefined'){
+ this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(_params.viewIndex)));
+ if (!this.renkan.options.default_view){
+ this.view.autoScale();
+ }
+ }
+ if (typeof _params.view !== 'undefined' && _params.view.split(",").length >= 3){
+ var viewParams = _params.view.split(",");
+ var params = {
+ "project": this.renkan.project,
+ "offset": {
+ "x": parseFloat(viewParams[0]),
+ "y": parseFloat(viewParams[1])
+ },
+ "zoom_level": parseFloat(viewParams[2])
+ };
+ if (this.view){
+ this.view.setScale(params.zoom_level, new paper.Point(params.offset));
+ } else{
+ this.view = this.addRepresentation("View", null);
+ this.view.params = params;
+ this.view.init();
+ }
+ }
+ if (!this.view){
+ this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view)));
+ this.view.autoScale();
+ }
+ //other parameters must go after because most of them depends on a view that must be initialize before
+ this.unhighlightAll();
+ if (typeof _params.idNode !== 'undefined'){
+ this.highlightModel(this.renkan.project.get("nodes").get(_params.idNode));
+ }
+ },
+ validViewIndex: function(index){
+ //check if the view index exist (negative index is from the end) and return the correct index or false if doesn't exist
+ var _index = parseInt(index);
+ var validIndex = 0;
+ if (_index < 0){
+ validIndex = this.renkan.project.get("views").length + _index;
+ } else {
+ validIndex = _index;
+ }
+ if (typeof this.renkan.project.get("views").at(_index) === 'undefined'){
+ validIndex = 0;
+ }
+ return validIndex;
+ },
+ foldBins: function() {
+ var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
+ bins = this.renkan.$.find(".Rk-Bins");
+ var _this = this,
+ sizeBef = _this.canvas_$.width(),
+ sizeAft;
+ if (bins.position().left < 0) {
+ bins.animate({left: 0},250);
+ this.$.animate({left: 300},250,function() {
+ var w = _this.$.width();
+ paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
+ });
+ if ((sizeBef - bins.width()) < bins.height()){
+ sizeAft = sizeBef;
+ } else {
+ sizeAft = sizeBef - bins.width();
+ }
+ foldBinsButton.html("«");
+ } else {
+ bins.animate({left: -300},250);
+ this.$.animate({left: 0},250,function() {
+ var w = _this.$.width();
+ paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
+ });
+ sizeAft = sizeBef+300;
+ foldBinsButton.html("»");
+ }
+ _this.view.resizeZoom(1, 1, (sizeAft/sizeBef));
+ },
+ save: function() { },
+ open: function() { }
+ }).value();
+
+ /* Scene End */
+
+ return Scene;
+
+});
+
+define('renderer/viewrepr',['jquery', 'underscore', 'requtils', 'renderer/baserepresentation'], function ($, _, requtils, BaseRepresentation) {
+ 'use strict';
+
+ var Utils = requtils.getUtils();
+
+ /* Rkns.Renderer.View Class */
+
+ /* The representation for the view. */
+
+ var ViewRepr = Utils.inherit(BaseRepresentation);
+
+ _(ViewRepr.prototype).extend({
+ _init: function() {
+ var _this = this;
+ this.$ = $(".Rk-Render");
+ this.type = "View";
+ this.hiddenNodes = [];
+ this.scale = 1;
+ this.initialScale = 1;
+ this.offset = paper.view.center;
+ this.params = {};
+
+ if (this.model){
+ this.params = {
+ "zoom_level": _this.model.get("zoom_level"),
+ "offset": _this.model.get("offset"),
+ "hidden_nodes": _this.model.get("hidden_nodes")
+ };
+ }
+
+ this.init();
+
+ var bindClick = function(selector, fname) {
+ _this.$.find(selector).click(function(evt) {
+ _this[fname](evt);
+ return false;
+ });
+ };
+
+ bindClick(".Rk-ZoomOut", "zoomOut");
+ bindClick(".Rk-ZoomIn", "zoomIn");
+ bindClick(".Rk-ZoomFit", "autoScale");
+
+ this.$.find(".Rk-ZoomSave").click( function() {
+ var offset = {
+ "x": _this.offset.x,
+ "y": _this.offset.y
+ };
+ _this.model = _this.renkan.project.addView( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } );
+ _this.params = {
+ "zoom_level": _this.model.get("zoom_level"),
+ "offset": _this.model.get("offset"),
+ "hidden_nodes": _this.model.get("hidden_nodes")
+ };
+ _this.updateUrl();
+ });
+
+ this.$.find(".Rk-ZoomSetSaved").click( function() {
+ _this.model = _this.renkan.project.get("views").at(_this.renkan.project.get("views").length -1);
+ _this.params = {
+ "zoom_level": _this.model.get("zoom_level"),
+ "offset": _this.model.get("offset"),
+ "hidden_nodes": _this.model.get("hidden_nodes")
+ };
+ _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
+ _this.showNodes(false);
+ if (_this.options.hide_nodes){
+ _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
+ _this.hideNodes();
+ }
+ _this.updateUrl();
+ });
+
+ this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
+ _this.showNodes(true);
+ _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() {
+ _this.hideNodes();
+ });
+ });
+ this.$.find(".Rk-ShowHiddenNodes").click( function() {
+ _this.showNodes(false);
+ _this.$.find(".Rk-ShowHiddenNodes").off( "mouseleave" );
+ });
+ if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
+ this.$.find(".Rk-ZoomSetSaved").show();
+ }
+ },
+ redraw: function(options) {
+ //console.log("view : ", this.model.toJSON());
+ },
+ init: function(){
+ var _this = this;
+ _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
+
+ if (_this.options.hide_nodes){
+ _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
+ _this.hideNodes();
+ }
+ },
+ addHiddenNode: function(_model){
+ this.hideNode(_model);
+ this.hiddenNodes.push(_model.id);
+ this.updateUrl();
+ },
+ hideNode: function(_model){
+ if (typeof this.renderer.getRepresentationByModel(_model) !== 'undefined'){
+ this.renderer.getRepresentationByModel(_model).hide();
+ }
+ },
+ hideNodes: function(){
+ var _this = this;
+ this.hiddenNodes.forEach(function(_id, index){
+ var node = _this.renkan.project.get("nodes").get(_id);
+ if (typeof node !== 'undefined'){
+ return _this.hideNode(_this.renkan.project.get("nodes").get(_id));
+ }else{
+ _this.hiddenNodes.splice(index, 1);
+ }
+ });
+ paper.view.draw();
+ },
+ showNodes: function(ghost){
+ var _this = this;
+ this.hiddenNodes.forEach(function(_id){
+ _this.renderer.getRepresentationByModel(_this.renkan.project.get("nodes").get(_id)).show(ghost);
+ });
+ if (!ghost){
+ this.hiddenNodes = [];
+ }
+ paper.view.draw();
+ },
+ setScale: function(_newScale, _offset) {
+ if ((_newScale/this.initialScale) > Utils._MIN_SCALE && (_newScale/this.initialScale) < Utils._MAX_SCALE) {
+ this.scale = _newScale;
+ if (_offset) {
+ this.offset = _offset;
+ }
+ this.renderer.redraw();
+ this.updateUrl();
+ }
+ },
+ zoomOut: function() {
+ var _newScale = this.scale * Math.SQRT1_2,
+ _offset = new paper.Point([
+ this.renderer.canvas_$.width(),
+ this.renderer.canvas_$.height()
+ ]).multiply( 0.5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 ));
+ this.setScale( _newScale, _offset );
+ },
+ zoomIn: function() {
+ var _newScale = this.scale * Math.SQRT2,
+ _offset = new paper.Point([
+ this.renderer.canvas_$.width(),
+ this.renderer.canvas_$.height()
+ ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 ));
+ this.setScale( _newScale, _offset );
+ },
+ resizeZoom: function(_scaleWidth, _scaleHeight, _ratio) {
+ var _newScale = this.scale * _ratio,
+ _offset = new paper.Point([
+ (this.offset.x * _scaleWidth),
+ (this.offset.y * _scaleHeight)
+ ]);
+ this.setScale( _newScale, _offset );
+ },
+ autoScale: function(force_view) {
+ var nodes = this.renkan.project.get("nodes");
+ if (nodes.length > 1) {
+ var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
+ _yy = nodes.map(function(_node) { return _node.get("position").y; }),
+ _minx = Math.min.apply(Math, _xx),
+ _miny = Math.min.apply(Math, _yy),
+ _maxx = Math.max.apply(Math, _xx),
+ _maxy = Math.max.apply(Math, _yy);
+ var _scale = Math.min( (paper.view.size.width - 2 * this.renkan.options.autoscale_padding) / (_maxx - _minx), (paper.view.size.height - 2 * this.renkan.options.autoscale_padding) / (_maxy - _miny));
+ this.initialScale = _scale;
+ // Override calculated scale if asked
+ if((typeof force_view !== "undefined") && parseFloat(force_view.zoom_level)>0 && parseFloat(force_view.offset.x)>0 && parseFloat(force_view.offset.y)>0){
+ this.setScale(parseFloat(force_view.zoom_level), new paper.Point(parseFloat(force_view.offset.x), parseFloat(force_view.offset.y)));
+ }
+ else{
+ this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)));
+ }
+ }
+ if (nodes.length === 1) {
+ this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])));
+ }
+ },
+ paperShift: function(_delta) {
+ this.offset = this.offset.add(_delta);
+ this.renderer.redraw();
+ },
+ updateUrl: function(){
+ if(this.options.update_url){
+ var result = {};
+ var parameters = Backbone.history.getFragment().split('?');
+ if (parameters.length > 1){
+ parameters[1].split("&").forEach(function(part) {
+ var item = part.split("=");
+ result[item[0]] = decodeURIComponent(item[1]);
+ });
+ }
+ result.view = Math.round(this.offset.x*1000)/1000 + ',' + Math.round(this.offset.y*1000)/1000 + ',' + Math.round(this.scale*1000)/1000;
+
+ if (this.renkan.project.get("views").indexOf(this.model) > -1){
+ result.viewIndex = this.renkan.project.get("views").indexOf(this.model);
+ if (result.viewIndex === this.renkan.project.get("views").length - 1){
+ result.viewIndex = -1;
+ }
+ } else {
+ if (result.viewIndex){
+ delete result.viewIndex;
+ }
+ }
+ this.renkan.router.navigate("?" + decodeURIComponent($.param(result)), {trigger: false, replace: true});
+ }
+ },
+ destroy: function(_event) {
+ this._super("destroy");
+ this.showNodes(false);
+ }
+ }).value();
+
+ return ViewRepr;
+
+});
+
+
+//Load modules and use them
+if( typeof require.config === "function" ) {
+ require.config({
+ paths: {
+ 'jquery':'../lib/jquery/jquery',
+ 'underscore':'../lib/lodash/lodash',
+ 'filesaver' :'../lib/FileSaver/FileSaver',
+ 'requtils':'require-utils',
+ 'ckeditor-core':'../lib/ckeditor/ckeditor',
+ 'ckeditor-jquery':'../lib/ckeditor/adapters/jquery'
+ },
+ shim: {
+ 'ckeditor-jquery':{
+ deps:['jquery','ckeditor-core']
+ }
+ },
+ });
+}
+
+require(['renderer/baserepresentation',
+ 'renderer/basebutton',
+ 'renderer/noderepr',
+ 'renderer/edge',
+ 'renderer/tempedge',
+ 'renderer/baseeditor',
+ 'renderer/nodeeditor',
+ 'renderer/edgeeditor',
+ 'renderer/nodebutton',
+ 'renderer/nodeeditbutton',
+ 'renderer/noderemovebutton',
+ 'renderer/nodehidebutton',
+ 'renderer/nodeshowbutton',
+ 'renderer/noderevertbutton',
+ 'renderer/nodelinkbutton',
+ 'renderer/nodeenlargebutton',
+ 'renderer/nodeshrinkbutton',
+ 'renderer/edgeeditbutton',
+ 'renderer/edgeremovebutton',
+ 'renderer/edgerevertbutton',
+ 'renderer/miniframe',
+ 'renderer/scene',
+ 'renderer/viewrepr'
+ ], function(BaseRepresentation, BaseButton, NodeRepr, Edge, TempEdge, BaseEditor, NodeEditor, EdgeEditor, NodeButton, NodeEditButton, NodeRemoveButton, NodeHideButton, NodeShowButton, NodeRevertButton, NodeLinkButton, NodeEnlargeButton, NodeShrinkButton, EdgeEditButton, EdgeRemoveButton, EdgeRevertButton, MiniFrame, Scene, ViewRepr){
+
+ 'use strict';
+
+ var Rkns = window.Rkns;
+
+ if(typeof Rkns.Renderer === "undefined"){
+ Rkns.Renderer = {};
+ }
+ var Renderer = Rkns.Renderer;
+
+ Renderer._BaseRepresentation = BaseRepresentation;
+ Renderer._BaseButton = BaseButton;
+ Renderer.Node = NodeRepr;
+ Renderer.Edge = Edge;
+ Renderer.View = ViewRepr;
+ Renderer.TempEdge = TempEdge;
+ Renderer._BaseEditor = BaseEditor;
+ Renderer.NodeEditor = NodeEditor;
+ Renderer.EdgeEditor = EdgeEditor;
+ Renderer._NodeButton = NodeButton;
+ Renderer.NodeEditButton = NodeEditButton;
+ Renderer.NodeRemoveButton = NodeRemoveButton;
+ Renderer.NodeHideButton = NodeHideButton;
+ Renderer.NodeShowButton = NodeShowButton;
+ Renderer.NodeRevertButton = NodeRevertButton;
+ Renderer.NodeLinkButton = NodeLinkButton;
+ Renderer.NodeEnlargeButton = NodeEnlargeButton;
+ Renderer.NodeShrinkButton = NodeShrinkButton;
+ Renderer.EdgeEditButton = EdgeEditButton;
+ Renderer.EdgeRemoveButton = EdgeRemoveButton;
+ Renderer.EdgeRevertButton = EdgeRevertButton;
+ Renderer.MiniFrame = MiniFrame;
+ Renderer.Scene = Scene;
+
+ startRenkan();
+});
+
+define("main-renderer", function(){});
+