26 this.selected_target = null; |
26 this.selected_target = null; |
27 this.edge_layer = new paper.Layer(); |
27 this.edge_layer = new paper.Layer(); |
28 this.node_layer = new paper.Layer(); |
28 this.node_layer = new paper.Layer(); |
29 this.buttons_layer = new paper.Layer(); |
29 this.buttons_layer = new paper.Layer(); |
30 this.delete_list = []; |
30 this.delete_list = []; |
31 |
31 |
32 if (_renkan.options.show_minimap) { |
32 if (_renkan.options.show_minimap) { |
33 this.minimap = { |
33 this.minimap = { |
34 background_layer: new paper.Layer(), |
34 background_layer: new paper.Layer(), |
35 edge_layer: new paper.Layer(), |
35 edge_layer: new paper.Layer(), |
36 node_layer: new paper.Layer(), |
36 node_layer: new paper.Layer(), |
43 this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
43 this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
44 this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color; |
44 this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color; |
45 this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color; |
45 this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color; |
46 this.minimap.rectangle.strokeWidth = 4; |
46 this.minimap.rectangle.strokeWidth = 4; |
47 this.minimap.offset = new paper.Point(this.minimap.size.divide(2)); |
47 this.minimap.offset = new paper.Point(this.minimap.size.divide(2)); |
48 this.minimap.scale = .1; |
48 this.minimap.scale = 0.1; |
49 |
49 |
50 this.minimap.node_layer.activate(); |
50 this.minimap.node_layer.activate(); |
51 this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
51 this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
52 this.minimap.node_group.addChild(this.minimap.cliprectangle); |
52 this.minimap.node_group.addChild(this.minimap.cliprectangle); |
53 this.minimap.node_group.clipped = true; |
53 this.minimap.node_group.clipped = true; |
54 this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
54 this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
55 this.minimap.node_group.addChild(this.minimap.miniframe); |
55 this.minimap.node_group.addChild(this.minimap.miniframe); |
56 this.minimap.miniframe.fillColor = '#c0c0ff'; |
56 this.minimap.miniframe.fillColor = '#c0c0ff'; |
57 this.minimap.miniframe.opacity = .3; |
57 this.minimap.miniframe.opacity = 0.3; |
58 this.minimap.miniframe.strokeColor = '#000080'; |
58 this.minimap.miniframe.strokeColor = '#000080'; |
59 this.minimap.miniframe.strokeWidth = 3; |
59 this.minimap.miniframe.strokeWidth = 3; |
60 this.minimap.miniframe.__representation = new MiniFrame(this, null); |
60 this.minimap.miniframe.__representation = new MiniFrame(this, null); |
61 } |
61 } |
62 |
62 |
80 ['edit', 'remove', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) { |
80 ['edit', 'remove', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) { |
81 var img = new Image(); |
81 var img = new Image(); |
82 img.src = _renkan.options.static_url + 'img/' + imgname + '.png'; |
82 img.src = _renkan.options.static_url + 'img/' + imgname + '.png'; |
83 _this.icon_cache[imgname] = img; |
83 _this.icon_cache[imgname] = img; |
84 }); |
84 }); |
85 |
85 |
86 var throttledMouseMove = _.throttle(function(_event, _isTouch) { |
86 var throttledMouseMove = _.throttle(function(_event, _isTouch) { |
87 _this.onMouseMove(_event, _isTouch); |
87 _this.onMouseMove(_event, _isTouch); |
88 }, Utils._MOUSEMOVE_RATE); |
88 }, Utils._MOUSEMOVE_RATE); |
89 |
89 |
90 this.canvas_$.on({ |
90 this.canvas_$.on({ |
110 }, |
110 }, |
111 touchstart: function(_event) { |
111 touchstart: function(_event) { |
112 _event.preventDefault(); |
112 _event.preventDefault(); |
113 var _touches = _event.originalEvent.touches[0]; |
113 var _touches = _event.originalEvent.touches[0]; |
114 if ( |
114 if ( |
115 _renkan.options.allow_double_click |
115 _renkan.options.allow_double_click && |
116 && new Date() - _lastTap < Utils._DOUBLETAP_DELAY |
116 new Date() - _lastTap < Utils._DOUBLETAP_DELAY && |
117 && ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Utils._DOUBLETAP_DISTANCE ) |
117 ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Utils._DOUBLETAP_DISTANCE ) |
118 ) { |
118 ) { |
119 _lastTap = 0; |
119 _lastTap = 0; |
120 _this.onDoubleClick(_touches); |
120 _this.onDoubleClick(_touches); |
121 } else { |
121 } else { |
122 _lastTap = new Date(); |
122 _lastTap = new Date(); |
145 var _newScale = _event.originalEvent.scale * _originalScale, |
145 var _newScale = _event.originalEvent.scale * _originalScale, |
146 _scaleRatio = _newScale / _this.scale, |
146 _scaleRatio = _newScale / _this.scale, |
147 _newOffset = new paper.Point([ |
147 _newOffset = new paper.Point([ |
148 _this.canvas_$.width(), |
148 _this.canvas_$.width(), |
149 _this.canvas_$.height() |
149 _this.canvas_$.height() |
150 ]).multiply( .5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio )); |
150 ]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio )); |
151 _this.setScale(_newScale, _newOffset); |
151 _this.setScale(_newScale, _newOffset); |
152 } |
152 } |
153 }, |
153 }, |
154 touchend: function(_event) { |
154 touchend: function(_event) { |
155 _event.preventDefault(); |
155 _event.preventDefault(); |
254 bindClick(".Rk-AddNode-Button", "addNodeBtn"); |
254 bindClick(".Rk-AddNode-Button", "addNodeBtn"); |
255 bindClick(".Rk-AddEdge-Button", "addEdgeBtn"); |
255 bindClick(".Rk-AddEdge-Button", "addEdgeBtn"); |
256 bindClick(".Rk-Save-Button", "save"); |
256 bindClick(".Rk-Save-Button", "save"); |
257 bindClick(".Rk-Open-Button", "open"); |
257 bindClick(".Rk-Open-Button", "open"); |
258 this.$.find(".Rk-Bookmarklet-Button") |
258 this.$.find(".Rk-Bookmarklet-Button") |
259 .attr("href","javascript:" + Utils._BOOKMARKLET_CODE(_renkan)) |
259 /*jshint scripturl:true */ |
260 .click(function(){ |
260 .attr("href","javascript:" + Utils._BOOKMARKLET_CODE(_renkan)) |
261 _this.notif_$ |
261 .click(function(){ |
262 .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.")) |
262 _this.notif_$ |
263 .fadeIn() |
263 .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.")) |
264 .delay(5000) |
264 .fadeIn() |
265 .fadeOut(); |
265 .delay(5000) |
266 return false; |
266 .fadeOut(); |
267 }); |
267 return false; |
|
268 }); |
268 this.$.find(".Rk-TopBar-Button").mouseover(function() { |
269 this.$.find(".Rk-TopBar-Button").mouseover(function() { |
269 $(this).find(".Rk-TopBar-Tooltip").show(); |
270 $(this).find(".Rk-TopBar-Tooltip").show(); |
270 }).mouseout(function() { |
271 }).mouseout(function() { |
271 $(this).find(".Rk-TopBar-Tooltip").hide(); |
272 $(this).find(".Rk-TopBar-Tooltip").hide(); |
272 }); |
273 }); |
440 |
441 |
441 }; |
442 }; |
442 |
443 |
443 _(Scene.prototype).extend({ |
444 _(Scene.prototype).extend({ |
444 template: _.template( |
445 template: _.template( |
445 '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>' |
446 '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>' + |
446 + '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>' |
447 '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>' + |
447 + '<% if (options.show_user_list) { %><div class="Rk-Users"><div class="Rk-CurrentUser"><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-CurrentUser-Color"><% if (options.user_color_editable) { %><span class="Rk-Edit-ColorTip"></span><% } %></span>' |
448 '<% if (options.show_user_list) { %><div class="Rk-Users"><div class="Rk-CurrentUser"><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-CurrentUser-Color"><% if (options.user_color_editable) { %><span class="Rk-Edit-ColorTip"></span><% } %></span>' + |
448 + '<% if (options.user_color_editable) { print(colorPicker) } %></div><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div><% } %>' |
449 '<% if (options.user_color_editable) { print(colorPicker) } %></div><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div><% } %>' + |
449 + '<% if (options.home_button_url) {%><div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Home-Button" href="<%- options.home_button_url %>"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents">' |
450 '<% if (options.home_button_url) {%><div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Home-Button" href="<%- options.home_button_url %>"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents">' + |
450 + '<%- translate(options.home_button_title) %></div></div></a><% } %>' |
451 '<%- translate(options.home_button_title) %></div></div></a><% } %>' + |
451 + '<% if (options.show_fullscreen_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Full Screen")%></div></div></div><% } %>' |
452 '<% if (options.show_fullscreen_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Full Screen")%></div></div></div><% } %>' + |
452 + '<% if (options.editor_mode) { %>' |
453 '<% if (options.editor_mode) { %>' + |
453 + '<% if (options.show_addnode_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip">' |
454 '<% if (options.show_addnode_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip">' + |
454 + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Node")%></div></div></div><% } %>' |
455 '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Node")%></div></div></div><% } %>' + |
455 + '<% if (options.show_addedge_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip">' |
456 '<% if (options.show_addedge_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip">' + |
456 + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div><% } %>' |
457 '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div><% } %>' + |
457 + '<% if (options.show_save_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div><% } %>' |
458 '<% if (options.show_save_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div><% } %>' + |
458 + '<% if (options.show_open_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Open-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Open Project")%></div></div></div><% } %>' |
459 '<% if (options.show_open_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Open-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Open Project")%></div></div></div><% } %>' + |
459 + '<% if (options.show_bookmarklet) { %><div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents">' |
460 '<% if (options.show_bookmarklet) { %><div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents">' + |
460 + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a><% } %>' |
461 '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a><% } %>' + |
461 + '<div class="Rk-TopBar-Separator"></div><% }; if (options.show_search_field) { %>' |
462 '<div class="Rk-TopBar-Separator"></div><% }; if (options.show_search_field) { %>' + |
462 + '<form action="#" class="Rk-GraphSearch-Form"><input type="search" class="Rk-GraphSearch-Field" placeholder="<%- translate("Search in graph") %>" /></form><div class="Rk-TopBar-Separator"></div><% } %></div><% } %>' |
463 '<form action="#" class="Rk-GraphSearch-Form"><input type="search" class="Rk-GraphSearch-Field" placeholder="<%- translate("Search in graph") %>" /></form><div class="Rk-TopBar-Separator"></div><% } %></div><% } %>' + |
463 + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">' |
464 '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">' + |
464 + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">' |
465 '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">' + |
465 + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">«</div><% } %>' |
466 '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">«</div><% } %>' + |
466 + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomFit" title="<%-translate("Zoom Fit")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div>' |
467 '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomFit" title="<%-translate("Zoom Fit")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div>' + |
467 + '<% if (options.editor_mode) { %><div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><% } %>' |
468 '<% if (options.editor_mode) { %><div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><% } %>' + |
468 + '<% if (options.editor_mode || !isNaN(parseInt(options.default_view))) { %><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div><% } %></div>' |
469 '<% if (options.editor_mode || !isNaN(parseInt(options.default_view))) { %><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div><% } %></div>' + |
469 + '</div></div>' |
470 '</div></div>' |
470 ), |
471 ), |
471 fixSize: function(_autoscale) { |
472 fixSize: function(_autoscale) { |
472 var w = this.$.width(), |
473 var w = this.$.width(), |
473 h = this.$.height(); |
474 h = this.$.height(); |
474 if (this.renkan.options.show_top_bar) { |
475 if (this.renkan.options.show_top_bar) { |
506 _enddy = Math.cos(_endRads), |
507 _enddy = Math.cos(_endRads), |
507 _endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
508 _endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
508 _endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
509 _endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
509 _endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
510 _endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
510 _endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
511 _endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
511 _centerR = (_inR + _outR)/2, |
512 _centerR = (_inR + _outR) / 2, |
512 _centerRads = (_startRads + _endRads) / 2, |
513 _centerRads = (_startRads + _endRads) / 2, |
513 _centerX = Math.cos(_centerRads) * _centerR, |
514 _centerX = Math.cos(_centerRads) * _centerR, |
514 _centerY = Math.sin(_centerRads) * _centerR, |
515 _centerY = Math.sin(_centerRads) * _centerR, |
515 _centerXIn = Math.cos(_centerRads) * _inR, |
516 _centerXIn = Math.cos(_centerRads) * _inR, |
516 _centerXOut = Math.cos(_centerRads) * _outR, |
517 _centerXOut = Math.cos(_centerRads) * _outR, |
523 _path.add([_startXIn, _startYIn]); |
524 _path.add([_startXIn, _startYIn]); |
524 _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]); |
525 _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]); |
525 _path.lineTo([_endXOut, _endYOut]); |
526 _path.lineTo([_endXOut, _endYOut]); |
526 _path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]); |
527 _path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]); |
527 _path.fillColor = _options.buttons_background; |
528 _path.fillColor = _options.buttons_background; |
528 _path.opacity = .5; |
529 _path.opacity = 0.5; |
529 _path.closed = true; |
530 _path.closed = true; |
530 _path.__representation = _repr; |
531 _path.__representation = _repr; |
531 var _text = new paper.PointText(_textX,_textY); |
532 var _text = new paper.PointText(_textX,_textY); |
532 _text.characterStyle = { |
533 _text.characterStyle = { |
533 fontSize: _options.buttons_label_font_size, |
534 fontSize: _options.buttons_label_font_size, |
681 _minx = Math.min.apply(Math, _xx), |
682 _minx = Math.min.apply(Math, _xx), |
682 _miny = Math.min.apply(Math, _yy), |
683 _miny = Math.min.apply(Math, _yy), |
683 _maxx = Math.max.apply(Math, _xx), |
684 _maxx = Math.max.apply(Math, _xx), |
684 _maxy = Math.max.apply(Math, _yy); |
685 _maxy = Math.max.apply(Math, _yy); |
685 var _scale = Math.min( |
686 var _scale = Math.min( |
686 this.scale * .8 * this.renkan.options.minimap_width / paper.view.bounds.width, |
687 this.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width, |
687 this.scale * .8 * this.renkan.options.minimap_height / paper.view.bounds.height, |
688 this.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height, |
688 ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx), |
689 ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx), |
689 ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny) |
690 ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny) |
690 ); |
691 ); |
691 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
692 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
692 this.minimap.scale = _scale; |
693 this.minimap.scale = _scale; |
693 } |
694 } |
694 if (nodes.length === 1) { |
695 if (nodes.length === 1) { |
695 this.minimap.scale = .1; |
696 this.minimap.scale = 0.1; |
696 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)); |
697 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)); |
697 } |
698 } |
698 this.redraw(); |
699 this.redraw(); |
699 }, |
700 }, |
700 toPaperCoords: function(_point) { |
701 toPaperCoords: function(_point) { |
988 } |
989 } |
989 paper.view.draw(); |
990 paper.view.draw(); |
990 }, |
991 }, |
991 defaultDropHandler: function(_data) { |
992 defaultDropHandler: function(_data) { |
992 var newNode = {}; |
993 var newNode = {}; |
|
994 var snippet = ""; |
993 switch(_data["text/x-iri-specific-site"]) { |
995 switch(_data["text/x-iri-specific-site"]) { |
994 case "twitter": |
996 case "twitter": |
995 var snippet = $('<div>').html(_data["text/x-iri-selected-html"]), |
997 snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
996 tweetdiv = snippet.find(".tweet"); |
998 var tweetdiv = snippet.find(".tweet"); |
997 newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
999 newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
998 newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id"); |
1000 newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id"); |
999 newNode.image = tweetdiv.find(".avatar").attr("src"); |
1001 newNode.image = tweetdiv.find(".avatar").attr("src"); |
1000 newNode.description = tweetdiv.find(".js-tweet-text:first").text(); |
1002 newNode.description = tweetdiv.find(".js-tweet-text:first").text(); |
1001 break; |
1003 break; |
1002 case "google": |
1004 case "google": |
1003 var snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
1005 snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
1004 newNode.title = snippet.find("h3:first").text().trim(); |
1006 newNode.title = snippet.find("h3:first").text().trim(); |
1005 newNode.uri = snippet.find("h3 a").attr("href"); |
1007 newNode.uri = snippet.find("h3 a").attr("href"); |
1006 newNode.description = snippet.find(".st:first").text().trim(); |
1008 newNode.description = snippet.find(".st:first").text().trim(); |
1007 break; |
1009 break; |
1008 case undefined: |
|
1009 default: |
1010 default: |
1010 if (_data["text/x-iri-source-uri"]) { |
1011 if (_data["text/x-iri-source-uri"]) { |
1011 newNode.uri = _data["text/x-iri-source-uri"]; |
1012 newNode.uri = _data["text/x-iri-source-uri"]; |
1012 } |
1013 } |
1013 } |
1014 } |
1014 if (_data["text/plain"] || _data["text/x-iri-selected-text"]) { |
1015 if (_data["text/plain"] || _data["text/x-iri-selected-text"]) { |
1015 newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim(); |
1016 newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim(); |
1016 } |
1017 } |
1017 if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
1018 if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
1018 var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
1019 snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
1019 var _svgimgs = snippet.find("image"); |
1020 var _svgimgs = snippet.find("image"); |
1020 if (_svgimgs.length) { |
1021 if (_svgimgs.length) { |
1021 newNode.image = _svgimgs.attr("xlink:href"); |
1022 newNode.image = _svgimgs.attr("xlink:href"); |
1022 } |
1023 } |
1023 var _svgpaths = snippet.find("path"); |
1024 var _svgpaths = snippet.find("path"); |
1046 } |
1047 } |
1047 if (_data["text/x-iri-source-title"] && !newNode.title) { |
1048 if (_data["text/x-iri-source-title"] && !newNode.title) { |
1048 newNode.title = _data["text/x-iri-source-title"]; |
1049 newNode.title = _data["text/x-iri-source-title"]; |
1049 } |
1050 } |
1050 if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
1051 if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
1051 var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
1052 snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
1052 newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image; |
1053 newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image; |
1053 newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri; |
1054 newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri; |
1054 newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title; |
1055 newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title; |
1055 newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description; |
1056 newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description; |
1056 newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath; |
1057 newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath; |
1117 _repr.openEditor(); |
1118 _repr.openEditor(); |
1118 } |
1119 } |
1119 }, |
1120 }, |
1120 fullScreen: function() { |
1121 fullScreen: function() { |
1121 var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
1122 var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
1122 _el = this.renkan.$[0], |
1123 _el = this.renkan.$[0], |
1123 _requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
1124 _requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
1124 _cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"]; |
1125 _cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"], |
|
1126 i; |
1125 if (_isFull) { |
1127 if (_isFull) { |
1126 for (var i = 0; i < _cancelMethods.length; i++) { |
1128 for (i = 0; i < _cancelMethods.length; i++) { |
1127 if (typeof document[_cancelMethods[i]] === "function") { |
1129 if (typeof document[_cancelMethods[i]] === "function") { |
1128 document[_cancelMethods[i]](); |
1130 document[_cancelMethods[i]](); |
1129 break; |
1131 break; |
1130 } |
1132 } |
1131 } |
1133 } |
1132 } else { |
1134 } else { |
1133 for (var i = 0; i < _requestMethods.length; i++) { |
1135 for (i = 0; i < _requestMethods.length; i++) { |
1134 if (typeof _el[_requestMethods[i]] === "function") { |
1136 if (typeof _el[_requestMethods[i]] === "function") { |
1135 _el[_requestMethods[i]](); |
1137 _el[_requestMethods[i]](); |
1136 break; |
1138 break; |
1137 } |
1139 } |
1138 } |
1140 } |
1141 zoomOut: function() { |
1143 zoomOut: function() { |
1142 var _newScale = this.scale * Math.SQRT1_2, |
1144 var _newScale = this.scale * Math.SQRT1_2, |
1143 _offset = new paper.Point([ |
1145 _offset = new paper.Point([ |
1144 this.canvas_$.width(), |
1146 this.canvas_$.width(), |
1145 this.canvas_$.height() |
1147 this.canvas_$.height() |
1146 ]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 )); |
1148 ]).multiply( 0.5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 )); |
1147 this.setScale( _newScale, _offset ); |
1149 this.setScale( _newScale, _offset ); |
1148 }, |
1150 }, |
1149 zoomIn: function() { |
1151 zoomIn: function() { |
1150 var _newScale = this.scale * Math.SQRT2, |
1152 var _newScale = this.scale * Math.SQRT2, |
1151 _offset = new paper.Point([ |
1153 _offset = new paper.Point([ |
1152 this.canvas_$.width(), |
1154 this.canvas_$.width(), |
1153 this.canvas_$.height() |
1155 this.canvas_$.height() |
1154 ]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 )); |
1156 ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 )); |
1155 this.setScale( _newScale, _offset ); |
1157 this.setScale( _newScale, _offset ); |
1156 }, |
1158 }, |
1157 addNodeBtn: function() { |
1159 addNodeBtn: function() { |
1158 if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
1160 if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
1159 this.click_mode = false; |
1161 this.click_mode = false; |
1175 return false; |
1177 return false; |
1176 }, |
1178 }, |
1177 foldBins: function() { |
1179 foldBins: function() { |
1178 var foldBinsButton = this.$.find(".Rk-Fold-Bins"), |
1180 var foldBinsButton = this.$.find(".Rk-Fold-Bins"), |
1179 bins = this.renkan.$.find(".Rk-Bins"); |
1181 bins = this.renkan.$.find(".Rk-Bins"); |
|
1182 var _this = this; |
1180 if (bins.offset().left < 0) { |
1183 if (bins.offset().left < 0) { |
1181 bins.animate({left: 0},250); |
1184 bins.animate({left: 0},250); |
1182 var _this = this; |
|
1183 this.$.animate({left: 300},250,function() { |
1185 this.$.animate({left: 300},250,function() { |
1184 var w = _this.$.width(); |
1186 var w = _this.$.width(); |
1185 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1187 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1186 }); |
1188 }); |
1187 foldBinsButton.html("«"); |
1189 foldBinsButton.html("«"); |
1188 } else { |
1190 } else { |
1189 bins.animate({left: -300},250); |
1191 bins.animate({left: -300},250); |
1190 var _this = this; |
|
1191 this.$.animate({left: 0},250,function() { |
1192 this.$.animate({left: 0},250,function() { |
1192 var w = _this.$.width(); |
1193 var w = _this.$.width(); |
1193 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1194 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1194 }); |
1195 }); |
1195 foldBinsButton.html("»"); |
1196 foldBinsButton.html("»"); |
1196 } |
1197 } |
1197 }, |
1198 }, |
1198 save: function() { }, |
1199 save: function() { }, |
1199 open: function() { } |
1200 open: function() { } |
1200 }); |
1201 }); |
1201 |
1202 |
1202 /* Scene End */ |
1203 /* Scene End */ |
1203 |
1204 |
1204 return Scene; |
1205 return Scene; |
1205 |
1206 |
1206 }); |
1207 }); |