450 test: function() { return true }, |
451 test: function() { return true }, |
451 replace: function(_text) { return text } |
452 replace: function(_text) { return text } |
452 } |
453 } |
453 } |
454 } |
454 } |
455 } |
455 })() |
456 })(), |
|
457 /* The minimum distance (in pixels) the mouse has to move to consider an element was dragged */ |
|
458 _MIN_DRAG_DISTANCE: 2, |
|
459 /* Distance between the inner and outer radius of buttons that appear when hovering on a node */ |
|
460 _NODE_BUTTON_WIDTH: 40, |
|
461 |
|
462 _EDGE_BUTTON_INNER: 2, |
|
463 _EDGE_BUTTON_OUTER: 40, |
|
464 /* Constants used to know if a specific action is to be performed when clicking on the canvas */ |
|
465 _CLICKMODE_ADDNODE: 1, |
|
466 _CLICKMODE_STARTEDGE: 2, |
|
467 _CLICKMODE_ENDEDGE: 3, |
|
468 /* Node size step: Used to calculate the size change when clicking the +/- buttons */ |
|
469 _NODE_SIZE_STEP: Math.LN2/4, |
|
470 _MIN_SCALE: 1/20, |
|
471 _MAX_SCALE: 20, |
|
472 _MOUSEMOVE_RATE: 80, |
|
473 _DOUBLETAP_DELAY: 800, |
|
474 /* Maximum distance in pixels (squared, to reduce calculations) |
|
475 * between two taps when double-tapping on a touch terminal */ |
|
476 _DOUBLETAP_DISTANCE: 20*20, |
|
477 /* A placeholder so a default colour is displayed when a node has a null value for its user property */ |
|
478 _USER_PLACEHOLDER: function(_renkan) { |
|
479 return { |
|
480 color: _renkan.options.default_user_color, |
|
481 title: _renkan.translate("(unknown user)"), |
|
482 get: function(attr) { |
|
483 return this[attr] || false; |
|
484 } |
|
485 }; |
|
486 }, |
|
487 /* The code for the "Drag and Add Bookmarklet", slightly minified and with whitespaces removed, though |
|
488 * it doesn't seem that it's still a requirement in newer browsers (i.e. the ones compatibles with canvas drawing) |
|
489 */ |
|
490 _BOOKMARKLET_CODE: function(_renkan) { |
|
491 return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">" |
|
492 + _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") |
|
493 + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();"; |
|
494 }, |
|
495 /* Shortens text to the required length then adds ellipsis */ |
|
496 shortenText: function(_text, _maxlength) { |
|
497 return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text); |
|
498 }, |
|
499 /* Drawing an edit box with an arrow and positioning the edit box according to the position of the node/edge being edited |
|
500 * Called by Rkns.Renderer.NodeEditor and Rkns.Renderer.EdgeEditor */ |
|
501 drawEditBox: function(_options, _coords, _path, _xmargin, _selector) { |
|
502 _selector.css({ |
|
503 width: ( _options.tooltip_width - 2* _options.tooltip_padding ) |
|
504 }); |
|
505 var _height = _selector.outerHeight() + 2* _options.tooltip_padding, |
|
506 _isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
507 _left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ), |
|
508 _right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ), |
|
509 _top = _coords.y - _height / 2; |
|
510 if (_top + _height > (paper.view.size.height - _options.tooltip_margin)) { |
|
511 _top = Math.max( paper.view.size.height - _options.tooltip_margin, _coords.y + _options.tooltip_arrow_width / 2 ) - _height; |
|
512 } |
|
513 if (_top < _options.tooltip_margin) { |
|
514 _top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 ); |
|
515 } |
|
516 var _bottom = _top + _height; |
|
517 _path.segments[0].point |
|
518 = _path.segments[7].point |
|
519 = _coords.add([_isLeft * _xmargin, 0]); |
|
520 _path.segments[1].point.x |
|
521 = _path.segments[2].point.x |
|
522 = _path.segments[5].point.x |
|
523 = _path.segments[6].point.x |
|
524 = _left; |
|
525 _path.segments[3].point.x |
|
526 = _path.segments[4].point.x |
|
527 = _right; |
|
528 _path.segments[2].point.y |
|
529 = _path.segments[3].point.y |
|
530 = _top; |
|
531 _path.segments[4].point.y |
|
532 = _path.segments[5].point.y |
|
533 = _bottom; |
|
534 _path.segments[1].point.y = _coords.y - _options.tooltip_arrow_width / 2; |
|
535 _path.segments[6].point.y = _coords.y + _options.tooltip_arrow_width / 2; |
|
536 _path.closed = true; |
|
537 _path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]); |
|
538 _selector.css({ |
|
539 left: (_options.tooltip_padding + Math.min(_left, _right)), |
|
540 top: (_options.tooltip_padding + _top) |
|
541 }); |
|
542 return _path; |
|
543 } |
456 }; |
544 }; |
457 })(window); |
545 })(window); |
458 |
546 |
459 /* END main.js */ |
547 /* END main.js */ |