client/js/paper-renderer.js
changeset 196 2a2fcec209d0
parent 195 15e048e00002
child 197 4e13edb46c0d
equal deleted inserted replaced
195:15e048e00002 196:2a2fcec209d0
   280     
   280     
   281     this.circle.opacity = this.options.show_node_circles ? opacity : .01;
   281     this.circle.opacity = this.options.show_node_circles ? opacity : .01;
   282     
   282     
   283     var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_nodes) || "";
   283     var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_nodes) || "";
   284     _text = shortenText(_text, this.options.node_label_max_length);
   284     _text = shortenText(_text, this.options.node_label_max_length);
   285     this.title.text(_text);
   285     
       
   286     if (typeof this.highlighted === "object") {
       
   287         this.title.html(this.highlighted.replace(_(_text).escape(),'<span class="Rk-Highlighted">$1</span>'));
       
   288     } else {
       
   289         this.title.text(_text);
       
   290     }
       
   291     
   286     this.title.css({
   292     this.title.css({
   287         left: this.paper_coords.x,
   293         left: this.paper_coords.x,
   288         top: this.paper_coords.y + this.circle_radius * this.h_ratio + this.options.node_label_distance,
   294         top: this.paper_coords.y + this.circle_radius * this.h_ratio + this.options.node_label_distance,
   289         opacity: opacity
   295         opacity: opacity
   290     });
   296     });
   510             this.minimap_circle.strokeColor = undefined;
   516             this.minimap_circle.strokeColor = undefined;
   511         }
   517         }
   512         this._super("unselect");
   518         this._super("unselect");
   513     }
   519     }
   514 },
   520 },
   515 highlight: function() {
   521 highlight: function(textToReplace) {
   516     if (this.highlighted) {
   522     var hlvalue = textToReplace || true;
       
   523     if (this.highlighted === hlvalue) {
   517         return;
   524         return;
   518     }
   525     }
   519     this.highlighted = true;
   526     this.highlighted = hlvalue;
   520     this.redraw();
   527     this.redraw();
   521     this.renderer.throttledPaperDraw();
   528     this.renderer.throttledPaperDraw();
   522 },
   529 },
   523 unhighlight: function() {
   530 unhighlight: function() {
   524     if (!this.highlighted) {
   531     if (!this.highlighted) {
   933 ),
   940 ),
   934 readOnlyTemplate: _.template(
   941 readOnlyTemplate: _.template(
   935     '<h2><span class="Rk-CloseX">&times;</span><% if (options.show_node_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-node.color%>;"></span><% } %>'
   942     '<h2><span class="Rk-CloseX">&times;</span><% if (options.show_node_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-node.color%>;"></span><% } %>'
   936     + '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
   943     + '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
   937     + '<% if (node.uri && options.show_node_tooltip_uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
   944     + '<% if (node.uri && options.show_node_tooltip_uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
   938     + '<% if (options.show_node_tooltip_description) { %><p><%-node.description%></p><% } %>'
   945     + '<% if (options.show_node_tooltip_description) { %><p class="Rk-Display-Description"><%-node.description%></p><% } %>'
   939     + '<% if (node.image && options.show_node_tooltip_image) { %><img class="Rk-Display-ImgPreview" src="<%-node.image%>" /><% } %>'
   946     + '<% if (node.image && options.show_node_tooltip_image) { %><img class="Rk-Display-ImgPreview" src="<%-node.image%>" /><% } %>'
   940     + '<% if (node.has_creator && options.show_node_tooltip_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- shortenText(node.created_by_title, 25) %></p><% } %>'
   947     + '<% if (node.has_creator && options.show_node_tooltip_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- shortenText(node.created_by_title, 25) %></p><% } %>'
   941 ),
   948 ),
   942 draw: function() {
   949 draw: function() {
   943     var _model = this.source_representation.model,
   950     var _model = this.source_representation.model,
  1087         });
  1094         });
  1088         this.editor_$.find(".Rk-Edit-Size-Up").click(function() {
  1095         this.editor_$.find(".Rk-Edit-Size-Up").click(function() {
  1089             shiftSize(1);
  1096             shiftSize(1);
  1090             return false;
  1097             return false;
  1091         });
  1098         });
       
  1099     } else {
       
  1100         if (typeof this.source_representation.highlighted === "object") {
       
  1101             var titlehtml = this.source_representation.highlighted.replace(_(_model.get("title")).escape(),'<span class="Rk-Highlighted">$1</span>');
       
  1102             this.editor_$.find(".Rk-Display-Title" + (_model.get("uri") ? " a" : "")).html(titlehtml);
       
  1103             if (this.options.show_node_tooltip_description) {
       
  1104                 this.editor_$.find(".Rk-Display-Description").html(this.source_representation.highlighted.replace(_(_model.get("description")).escape(),'<span class="Rk-Highlighted">$1</span>'))
       
  1105             }
       
  1106         }
  1092     }
  1107     }
  1093     this.editor_$.find("img").load(function() {
  1108     this.editor_$.find("img").load(function() {
  1094         _this.redraw();
  1109         _this.redraw();
  1095     });
  1110     });
  1096 },
  1111 },
  1861                 }
  1876                 }
  1862             }
  1877             }
  1863         );
  1878         );
  1864     }
  1879     }
  1865     
  1880     
       
  1881     if (_renkan.options.show_search_field) {
       
  1882         
       
  1883         var lastval = '';
       
  1884         
       
  1885         this.$.find(".Rk-GraphSearch-Field").on("keyup change paste input", function() {
       
  1886             var $this = $(this),
       
  1887                 val = $this.val();
       
  1888             if (val === lastval) {
       
  1889                 return;
       
  1890             }
       
  1891             if (val.length < 2) {
       
  1892                 _renkan.project.get("nodes").each(function(n) {
       
  1893                     _this.getRepresentationByModel(n).unhighlight();
       
  1894                 });
       
  1895             } else {
       
  1896                 var rxs = Rkns.Utils.regexpFromTextOrArray(val);
       
  1897                 _renkan.project.get("nodes").each(function(n) {
       
  1898                     if (rxs.test(n.get("title")) || rxs.test(n.get("description"))) {
       
  1899                         _this.getRepresentationByModel(n).highlight(rxs);
       
  1900                     } else {
       
  1901                         _this.getRepresentationByModel(n).unhighlight(); 
       
  1902                     }
       
  1903                 });
       
  1904             }
       
  1905         });
       
  1906     }
       
  1907     
  1866     this.redraw();
  1908     this.redraw();
  1867     
  1909     
  1868     window.setInterval(function() {
  1910     window.setInterval(function() {
  1869         var _now = new Date().valueOf();
  1911         var _now = new Date().valueOf();
  1870         _this.delete_list.forEach(function(d) {
  1912         _this.delete_list.forEach(function(d) {
  1908     + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div><% } %>'
  1950     + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div><% } %>'
  1909     + '<% 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><% } %>'
  1951     + '<% 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><% } %>'
  1910     + '<% 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><% } %>'
  1952     + '<% 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><% } %>'
  1911     + '<% 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">'
  1953     + '<% 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">'
  1912     + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a><% } %>'
  1954     + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a><% } %>'
  1913     + '<div class="Rk-TopBar-Separator"></div>'
  1955     + '<div class="Rk-TopBar-Separator"></div><% }; if (options.show_search_field) { %>'
  1914     + '<% } %></div><% } %>'
  1956     + '<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><% } %>'
  1915     + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">'
  1957     + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">'
  1916     + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">'
  1958     + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">'
  1917     + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
  1959     + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
  1918     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
  1960     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
  1919     + '</div></div>'
  1961     + '</div></div>'