client/js/paper-renderer.js
author ymh <ymh.work@gmail.com>
Sat, 26 Apr 2014 14:32:42 +0200
changeset 277 1a54f4e626df
parent 276 900467290a0a
child 278 b45dda454dd6
permissions -rw-r--r--
correct _renkan reference
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
     1
/* paper-renderer.js */
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
     2
"use strict";
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
     3
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
     4
(function(root) {
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
     5
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
     6
    var Rkns = root.Rkns,
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
     7
    _ = Rkns._,
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
     8
    $ = Rkns.$;
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
     9
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    10
    /* Rkns.Renderer Object */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    11
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    12
    /* This object contains constants, utility functions and classes for Renkan's Graph Manipulation GUI */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    13
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    14
    var Renderer = Rkns.Renderer = {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    15
    /* The minimum distance (in pixels) the mouse has to move to consider an element was dragged */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    16
    _MIN_DRAG_DISTANCE = 2,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    17
    /* Distance between the inner and outer radius of buttons that appear when hovering on a node */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    18
    _NODE_BUTTON_WIDTH = 40,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    19
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    20
    _EDGE_BUTTON_INNER = 2,
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    21
    _EDGE_BUTTON_OUTER = 40,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    22
    /* Constants used to know if a specific action is to be performed when clicking on the canvas */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    23
    _CLICKMODE_ADDNODE = 1,
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    24
    _CLICKMODE_STARTEDGE = 2,
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    25
    _CLICKMODE_ENDEDGE = 3,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    26
    /* Node size step: Used to calculate the size change when clicking the +/- buttons */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    27
    _NODE_SIZE_STEP = Math.LN2/4,
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    28
    _MIN_SCALE = 1/20,
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    29
    _MAX_SCALE = 20,
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    30
    _MOUSEMOVE_RATE = 80,
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    31
    _DOUBLETAP_DELAY = 800,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    32
    /* Maximum distance in pixels (squared, to reduce calculations)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    33
     * between two taps when double-tapping on a touch terminal */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    34
    _DOUBLETAP_DISTANCE = 20*20,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    35
    /* A placeholder so a default colour is displayed when a node has a null value for its user property */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    36
    _USER_PLACEHOLDER = function(_renkan) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    37
        return {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    38
            color: _renkan.options.default_user_color,
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    39
            title: _renkan.translate("(unknown user)"),
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    40
            get: function(attr) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    41
                return this[attr] || false;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    42
            }
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    43
        };
70
47b3125130a2 bookmarklet evolution
veltr
parents: 69
diff changeset
    44
    },
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    45
    /* The code for the "Drag and Add Bookmarklet", slightly minified and with whitespaces removed, though
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    46
     * it doesn't seem that it's still a requirement in newer browsers (i.e. the ones compatibles with canvas drawing)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    47
     */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    48
    _BOOKMARKLET_CODE = function(_renkan) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    49
        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;\">"
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    50
        + _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_")
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    51
        + "</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);})();";
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
    52
    },
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    53
    /* Shortens text to the required length then adds ellipsis */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    54
    shortenText = function(_text, _maxlength) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    55
        return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text);
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    56
    },
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    57
    /* Drawing an edit box with an arrow and positioning the edit box according to the position of the node/edge being edited
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    58
     * Called by Rkns.Renderer.NodeEditor and Rkns.Renderer.EdgeEditor */
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    59
    drawEditBox = function(_options, _coords, _path, _xmargin, _selector) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
    60
        _selector.css({
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 207
diff changeset
    61
            width: ( _options.tooltip_width - 2* _options.tooltip_padding )
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
    62
        });
120
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    63
        var _height = _selector.outerHeight() + 2* _options.tooltip_padding,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    64
        _isLeft = (_coords.x < paper.view.center.x ? 1 : -1),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    65
        _left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    66
        _right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    67
        _top = _coords.y - _height / 2;
163
fca0475da9a7 Changes for metadataplayer compatibility
veltr
parents: 161
diff changeset
    68
        if (_top + _height > (paper.view.size.height - _options.tooltip_margin)) {
fca0475da9a7 Changes for metadataplayer compatibility
veltr
parents: 161
diff changeset
    69
            _top = Math.max( paper.view.size.height - _options.tooltip_margin, _coords.y + _options.tooltip_arrow_width / 2 ) - _height;
fca0475da9a7 Changes for metadataplayer compatibility
veltr
parents: 161
diff changeset
    70
        }
120
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    71
        if (_top < _options.tooltip_margin) {
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    72
            _top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 );
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    73
        }
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    74
        var _bottom = _top + _height;
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    75
        _path.segments[0].point
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    76
        = _path.segments[7].point
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    77
        = _coords.add([_isLeft * _xmargin, 0]);
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    78
        _path.segments[1].point.x
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    79
        = _path.segments[2].point.x
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    80
        = _path.segments[5].point.x
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    81
        = _path.segments[6].point.x
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    82
        = _left;
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    83
        _path.segments[3].point.x
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    84
        = _path.segments[4].point.x
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    85
        = _right;
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    86
        _path.segments[2].point.y
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    87
        = _path.segments[3].point.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    88
        = _top;
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    89
        _path.segments[4].point.y
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    90
        = _path.segments[5].point.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    91
        = _bottom;
120
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    92
        _path.segments[1].point.y = _coords.y - _options.tooltip_arrow_width / 2;
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    93
        _path.segments[6].point.y = _coords.y + _options.tooltip_arrow_width / 2;
28
805d85b3f390 Publishing tests
veltr
parents: 26
diff changeset
    94
        _path.closed = true;
120
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    95
        _path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]);
28
805d85b3f390 Publishing tests
veltr
parents: 26
diff changeset
    96
        _selector.css({
120
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    97
            left: (_options.tooltip_padding + Math.min(_left, _right)),
112a82ddd7e5 Settings transferred from paper-renderer.js to defaults.js
veltr
parents: 119
diff changeset
    98
            top: (_options.tooltip_padding + _top)
28
805d85b3f390 Publishing tests
veltr
parents: 26
diff changeset
    99
        });
153
7fcb35795ff4 Now showing images in publish tooltips
veltr
parents: 152
diff changeset
   100
        return _path;
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
   101
    };
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
   102
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   103
    /* Rkns.Renderer._BaseRepresentation Class */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
   104
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   105
    /* In Renkan, a "Representation" is a sort of ViewModel (in the MVVM paradigm) and bridges the gap between
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   106
     * models (written with Backbone.js) and the view (written with Paper.js)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   107
     * Renkan's representations all inherit from Rkns.Renderer._BaseRepresentation '*/
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
   108
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   109
    var _BaseRepresentation = Renderer._BaseRepresentation = function(_renderer, _model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   110
        if (typeof _renderer !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   111
            this.renderer = _renderer;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   112
            this.renkan = _renderer.renkan;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   113
            this.project = _renderer.renkan.project;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   114
            this.options = _renderer.renkan.options;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   115
            this.model = _model;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   116
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   117
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   118
                this._changeBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   119
                    _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   120
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   121
                this._removeBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   122
                    _renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   123
                    _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   124
                        _renderer.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   125
                    }).defer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   126
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   127
                this._selectBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   128
                    _this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   129
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   130
                this._unselectBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   131
                    _this.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   132
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   133
                this.model.on("change", this._changeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   134
                this.model.on("remove", this._removeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   135
                this.model.on("select", this._selectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   136
                this.model.on("unselect", this._unselectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   137
            }
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
   138
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   139
    };
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
   140
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   141
    /* Rkns.Renderer._BaseRepresentation Methods */
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
   142
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   143
    _(_BaseRepresentation.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   144
        _super: function(_func) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   145
            return _BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   146
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   147
        redraw: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   148
        moveTo: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   149
        show: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   150
        hide: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   151
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   152
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   153
                this.model.trigger("selected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   154
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   155
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   156
        unselect: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   157
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   158
                this.model.trigger("unselected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   159
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   160
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   161
        highlight: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   162
        unhighlight: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   163
        mousedown: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   164
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   165
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   166
                this.model.trigger("clicked");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   167
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   168
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   169
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   170
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   171
                this.model.off("change", this._changeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   172
                this.model.off("remove", this._removeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   173
                this.model.off("select", this._selectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   174
                this.model.off("unselect", this._unselectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   175
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   176
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   177
    });
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
   178
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   179
    /* End of Rkns.Renderer._BaseRepresentation Class */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
   180
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   181
    /* Rkns.Renderer._BaseButton Class */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
   182
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   183
    /* BaseButton is extended by contextual buttons that appear when hovering on nodes and edges */
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
   184
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   185
    var _BaseButton = Renderer._BaseButton = Rkns.Utils.inherit(_BaseRepresentation);
1
45cca39b00ac First rendering tests
veltr
parents:
diff changeset
   186
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   187
    _(_BaseButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   188
        moveTo: function(_pos) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   189
            this.sector.moveTo(_pos);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   190
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   191
        show: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   192
            this.sector.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   193
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   194
        hide: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   195
            this.sector.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   196
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   197
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   198
            this.sector.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   199
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   200
        unselect: function(_newTarget) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   201
            this.sector.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   202
            if (!_newTarget || (_newTarget !== this.source_representation && _newTarget.source_representation !== this.source_representation)) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   203
                this.source_representation.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   204
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   205
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   206
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   207
            this.sector.destroy();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   208
        }
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   209
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   210
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   211
    /* End of Rkns.Renderer._BaseButton Class */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   212
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   213
    /* Rkns.Renderer.Node Class */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   214
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   215
    /* The representation for the node : A circle, with an image inside and a text label underneath.
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   216
     * The circle and the image are drawn on canvas and managed by Paper.js.
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   217
     * The text label is an HTML node, managed by jQuery. */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   218
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   219
    var NodeRepr = Renderer.Node = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   220
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   221
    _(NodeRepr.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   222
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   223
            this.renderer.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   224
            this.type = "Node";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   225
            this.circle = new paper.Path.Circle([0, 0], 1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   226
            this.circle.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   227
            if (this.options.show_node_circles) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   228
                this.circle.strokeWidth = this.options.node_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   229
                this.h_ratio = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   230
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   231
                this.h_ratio = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   232
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   233
            this.title = $('<div class="Rk-Label">').appendTo(this.renderer.labels_$);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   234
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   235
                this.normal_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   236
                                       new NodeEditButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   237
                                       new NodeRemoveButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   238
                                       new NodeLinkButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   239
                                       new NodeEnlargeButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   240
                                       new NodeShrinkButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   241
                                       ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   242
                this.pending_delete_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   243
                                               new NodeRevertButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   244
                                               ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   245
                this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   246
                for (var i = 0; i < this.all_buttons.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   247
                    this.all_buttons[i].source_representation = this;
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
   248
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   249
                this.active_buttons = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   250
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   251
                this.active_buttons = this.all_buttons = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   252
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   253
            this.last_circle_radius = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   254
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   255
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   256
                this.renderer.minimap.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   257
                this.minimap_circle = new paper.Path.Circle([0, 0], 1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   258
                this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   259
                this.renderer.minimap.node_group.addChild(this.minimap_circle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   260
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   261
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   262
        redraw: function(_dontRedrawEdges) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   263
            var _model_coords = new paper.Point(this.model.get("position")),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   264
            _baseRadius = this.options.node_size_base * Math.exp((this.model.get("size") || 0) * _NODE_SIZE_STEP);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   265
            if (!this.is_dragging || !this.paper_coords) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   266
                this.paper_coords = this.renderer.toPaperCoords(_model_coords);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   267
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   268
            this.circle_radius = _baseRadius * this.renderer.scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   269
            if (this.last_circle_radius !== this.circle_radius) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   270
                this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   271
                    b.setSectorSize();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   272
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   273
                var square = new paper.Size(this.circle_radius, this.circle_radius),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   274
                topleft = this.paper_coords.subtract(square),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   275
                bounds = new paper.Rectangle(topleft, square.multiply(2));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   276
                this.circle.scale(this.circle_radius / this.last_circle_radius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   277
                if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   278
                    this.node_image.scale(this.circle_radius / this.last_circle_radius);
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
   279
                }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   280
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   281
            this.circle.position = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   282
            if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   283
                this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   284
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   285
            this.last_circle_radius = this.circle_radius;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   286
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   287
            var old_act_btn = this.active_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   288
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   289
            if (this.model.get("delete_scheduled")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   290
                var opacity = .5;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   291
                this.active_buttons = this.pending_delete_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   292
                this.circle.dashArray = [2,2];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   293
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   294
                var opacity = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   295
                this.active_buttons = this.normal_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   296
                this.circle.dashArray = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   297
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   298
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   299
            if (this.selected && this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   300
                if (old_act_btn !== this.active_buttons) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   301
                    old_act_btn.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   302
                        b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   303
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   304
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   305
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   306
                    b.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   307
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   308
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   309
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   310
            if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   311
                this.node_image.opacity = this.highlighted ? opacity * .5 : (opacity - .01);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   312
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   313
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   314
            this.circle.fillColor = this.highlighted ? this.options.highlighted_node_fill_color : this.options.node_fill_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   315
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   316
            this.circle.opacity = this.options.show_node_circles ? opacity : .01;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   317
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   318
            var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_nodes) || "";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   319
            _text = shortenText(_text, this.options.node_label_max_length);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   320
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   321
            if (typeof this.highlighted === "object") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   322
                this.title.html(this.highlighted.replace(_(_text).escape(),'<span class="Rk-Highlighted">$1</span>'));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   323
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   324
                this.title.text(_text);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   325
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   326
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   327
            this.title.css({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   328
                left: this.paper_coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   329
                top: this.paper_coords.y + this.circle_radius * this.h_ratio + this.options.node_label_distance,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   330
                opacity: opacity
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   331
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   332
            var _color = this.model.get("color") || (this.model.get("created_by") || _USER_PLACEHOLDER(this.renkan)).get("color");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   333
            this.circle.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   334
            var _pc = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   335
            this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   336
                b.moveTo(_pc);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   337
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   338
            var lastImage = this.img;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   339
            this.img = this.model.get("image");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   340
            if (this.img && this.img !== lastImage) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   341
                this.showImage();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   342
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   343
            if (this.node_image && !this.img) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   344
                this.node_image.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   345
                delete this.node_image;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   346
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   347
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   348
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   349
                this.minimap_circle.fillColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   350
                var minipos = this.renderer.toMinimapCoords(_model_coords),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   351
                miniradius = this.renderer.minimap.scale * _baseRadius,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   352
                minisize = new paper.Size([miniradius, miniradius]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   353
                this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   354
            }
118
c0e03c7137e3 Fix for edges with missing nodes
veltr
parents: 117
diff changeset
   355
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   356
            if (!_dontRedrawEdges) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   357
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   358
                _.each(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   359
                        this.project.get("edges").filter(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   360
                                function (ed) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   361
                                    return ((ed.get("to") === _this.model) || (ed.get("from") === _this.model));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   362
                                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   363
                        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   364
                        function(edge, index, list) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   365
                            var repr = _this.renderer.getRepresentationByModel(edge);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   366
                            if (repr && typeof repr.from_representation !== "undefined" && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   367
                                repr.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   368
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   369
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   370
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   371
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   372
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   373
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   374
        showImage: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   375
            if (typeof this.renderer.image_cache[this.img] === "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   376
                var _image = new Image();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   377
                this.renderer.image_cache[this.img] = _image;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   378
                _image.src = this.img;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   379
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   380
                var _image = this.renderer.image_cache[this.img];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   381
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   382
            if (_image.width) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   383
                if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   384
                    this.node_image.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   385
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   386
                this.renderer.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   387
                var width = _image.width,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   388
                height = _image.height,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   389
                clipPath = this.model.get("clip_path"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   390
                hasClipPath = (typeof clipPath !== "undefined" && clipPath);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   391
                if (hasClipPath) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   392
                    var _clip = new paper.Path(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   393
                    instructions = clipPath.match(/[a-z][^a-z]+/gi) || [],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   394
                    lastCoords = [0,0],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   395
                    minX = Infinity,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   396
                    minY = Infinity,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   397
                    maxX = -Infinity,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   398
                    maxY = -Infinity;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   399
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   400
                    var transformCoords = function(tabc, relative) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   401
                        var newCoords = tabc.slice(1).map(function(v, k) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   402
                            var res = parseFloat(v),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   403
                            isY = k % 2;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   404
                            if (isY) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   405
                                res = ( res - .5 ) * height;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   406
                            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   407
                                res = ( res - .5 ) * width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   408
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   409
                            if (relative) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   410
                                res += lastCoords[isY];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   411
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   412
                            if (isY) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   413
                                minY = Math.min(minY, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   414
                                maxY = Math.max(maxY, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   415
                            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   416
                                minX = Math.min(minX, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   417
                                maxX = Math.max(maxX, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   418
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   419
                            return res;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   420
                        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   421
                        lastCoords = newCoords.slice(-2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   422
                        return newCoords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   423
                    };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   424
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   425
                    instructions.forEach(function(instr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   426
                        var coords = instr.match(/([a-z]|[0-9.-]+)/ig) || [""];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   427
                        switch(coords[0]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   428
                        case "M":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   429
                            _clip.moveTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   430
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   431
                        case "m":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   432
                            _clip.moveTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   433
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   434
                        case "L":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   435
                            _clip.lineTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   436
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   437
                        case "l":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   438
                            _clip.lineTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   439
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   440
                        case "C":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   441
                            _clip.cubicCurveTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   442
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   443
                        case "c":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   444
                            _clip.cubicCurveTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   445
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   446
                        case "Q":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   447
                            _clip.quadraticCurveTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   448
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   449
                        case "q":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   450
                            _clip.quadraticCurveTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   451
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   452
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   453
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   454
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   455
                    var baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](maxX - minX, maxY - minY) / 2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   456
                    centerPoint = new paper.Point((maxX + minX) / 2, (maxY + minY) / 2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   457
                    if (!this.options.show_node_circles) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   458
                        this.h_ratio = (maxY - minY) / (2 * baseRadius);
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   459
                    }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   460
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   461
                    var baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](width, height) / 2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   462
                    centerPoint = new paper.Point(0,0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   463
                    if (!this.options.show_node_circles) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   464
                        this.h_ratio = height / (2 * baseRadius);
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   465
                    }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   466
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   467
                var _raster = new paper.Raster(_image);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   468
                _raster.locked = true; // Disable mouse events on icon
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   469
                if (hasClipPath) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   470
                    _raster = new paper.Group(_clip, _raster);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   471
                    _raster.opacity = .99;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   472
                    /* This is a workaround to allow clipping at group level
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   473
                     * If opacity was set to 1, paper.js would merge all clipping groups in one (known bug).
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   474
                     */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   475
                    _raster.clipped = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   476
                    _clip.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   477
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   478
                if (this.options.clip_node_images) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   479
                    var _circleClip = new paper.Path.Circle(centerPoint, baseRadius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   480
                    _raster = new paper.Group(_circleClip, _raster);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   481
                    _raster.opacity = .99;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   482
                    _raster.clipped = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   483
                    _circleClip.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   484
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   485
                this.image_delta = centerPoint.divide(baseRadius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   486
                this.node_image = _raster;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   487
                this.node_image.__representation = _this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   488
                this.node_image.scale(this.circle_radius / baseRadius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   489
                this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   490
                this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   491
                this.renderer.throttledPaperDraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   492
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   493
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   494
                $(_image).on("load", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   495
                    _this.showImage();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   496
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   497
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   498
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   499
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   500
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   501
                if (!this.renkan.read_only) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   502
                    this.is_dragging = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   503
                    this.paper_coords = this.paper_coords.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   504
                    this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   505
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   506
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   507
                this.renderer.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   508
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   509
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   510
        openEditor: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   511
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   512
            var _editor = this.renderer.addRepresentation("NodeEditor",null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   513
            _editor.source_representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   514
            _editor.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   515
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   516
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   517
            this.selected = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   518
            this.circle.strokeWidth = this.options.selected_node_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   519
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   520
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   521
                    b.show();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   522
                });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   523
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   524
            var _uri = this.model.get("uri");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   525
            if (_uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   526
                $('.Rk-Bin-Item').each(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   527
                    var _el = $(this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   528
                    if (_el.attr("data-uri") == _uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   529
                        _el.addClass("selected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   530
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   531
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   532
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   533
            if (!this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   534
                this.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   535
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   536
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   537
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   538
                this.minimap_circle.strokeWidth = this.options.minimap_highlight_weight;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   539
                this.minimap_circle.strokeColor = this.options.minimap_highlight_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   540
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   541
            this._super("select");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   542
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   543
        unselect: function(_newTarget) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   544
            if (!_newTarget || _newTarget.source_representation !== this) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   545
                this.selected = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   546
                this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   547
                    b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   548
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   549
                this.circle.strokeWidth = this.options.node_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   550
                $('.Rk-Bin-Item').removeClass("selected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   551
                if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   552
                    this.minimap_circle.strokeColor = undefined;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   553
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   554
                this._super("unselect");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   555
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   556
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   557
        highlight: function(textToReplace) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   558
            var hlvalue = textToReplace || true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   559
            if (this.highlighted === hlvalue) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   560
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   561
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   562
            this.highlighted = hlvalue;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   563
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   564
            this.renderer.throttledPaperDraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   565
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   566
        unhighlight: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   567
            if (!this.highlighted) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   568
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   569
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   570
            this.highlighted = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   571
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   572
            this.renderer.throttledPaperDraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   573
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   574
        saveCoords: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   575
            var _coords = this.renderer.toModelCoords(this.paper_coords),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   576
            _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   577
                position: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   578
                    x: _coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   579
                    y: _coords.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   580
                }
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
   581
            };
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   582
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   583
                this.model.set(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   584
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   585
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   586
        mousedown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   587
            if (_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   588
                this.renderer.unselectAll();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   589
                this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   590
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   591
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   592
        mouseup: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   593
            if (this.renderer.is_dragging && this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   594
                this.saveCoords();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   595
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   596
                if (!_isTouch && !this.model.get("delete_scheduled")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   597
                    this.openEditor();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   598
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   599
                this.model.trigger("clicked");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   600
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   601
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   602
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   603
            this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   604
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   605
        destroy: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   606
            this._super("destroy");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   607
            this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   608
                b.destroy();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   609
            });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   610
            this.circle.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   611
            this.title.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   612
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   613
                this.minimap_circle.remove();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   614
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   615
            if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   616
                this.node_image.remove();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   617
            }
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   618
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   619
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   620
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   621
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   622
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   623
    var Edge = Renderer.Edge = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   624
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   625
    _(Edge.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   626
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   627
            this.renderer.edge_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   628
            this.type = "Edge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   629
            this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   630
            this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   631
            this.bundle = this.renderer.addToBundles(this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   632
            this.line = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   633
            this.line.add([0,0],[0,0],[0,0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   634
            this.line.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   635
            this.line.strokeWidth = this.options.edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   636
            this.arrow = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   637
            this.arrow.add(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   638
                    [ 0, 0 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   639
                    [ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   640
                    [ 0, this.options.edge_arrow_width ]
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   641
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   642
            this.arrow.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   643
            this.text = $('<div class="Rk-Label Rk-Edge-Label">').appendTo(this.renderer.labels_$);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   644
            this.arrow_angle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   645
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   646
                this.normal_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   647
                                       new EdgeEditButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   648
                                       new EdgeRemoveButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   649
                                       ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   650
                this.pending_delete_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   651
                                               new EdgeRevertButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   652
                                               ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   653
                this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   654
                for (var i = 0; i < this.all_buttons.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   655
                    this.all_buttons[i].source_representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   656
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   657
                this.active_buttons = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   658
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   659
                this.active_buttons = this.all_buttons = [];
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   660
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   661
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   662
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   663
                this.renderer.minimap.edge_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   664
                this.minimap_line = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   665
                this.minimap_line.add([0,0],[0,0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   666
                this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   667
                this.minimap_line.strokeWidth = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   668
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   669
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   670
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   671
            var from = this.model.get("from"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   672
            to = this.model.get("to");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   673
            if (!from || !to) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   674
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   675
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   676
            this.from_representation = this.renderer.getRepresentationByModel(from);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   677
            this.to_representation = this.renderer.getRepresentationByModel(to);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   678
            if (typeof this.from_representation === "undefined" || typeof this.to_representation === "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   679
                return;
57
01f66ed90e32 Drag node/edge only saved at mouse up.
veltr
parents: 56
diff changeset
   680
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   681
            var _p0a = this.from_representation.paper_coords,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   682
            _p1a = this.to_representation.paper_coords,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   683
            _v = _p1a.subtract(_p0a),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   684
            _r = _v.length,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   685
            _u = _v.divide(_r),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   686
            _ortho = new paper.Point([- _u.y, _u.x]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   687
            _group_pos = this.bundle.getPosition(this),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   688
            _delta = _ortho.multiply( this.options.edge_gap_in_bundles * _group_pos ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   689
            _p0b = _p0a.add(_delta), /* Adding a 4 px difference */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   690
            _p1b = _p1a.add(_delta), /* to differentiate bundled links */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   691
            _a = _v.angle,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   692
            _textdelta = _ortho.multiply(this.options.edge_label_distance),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   693
            _handle = _v.divide(3),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   694
            _color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || _USER_PLACEHOLDER(this.renkan)).get("color");
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
   695
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   696
            if (this.model.get("delete_scheduled") || this.from_representation.model.get("delete_scheduled") || this.to_representation.model.get("delete_scheduled")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   697
                var opacity = .5;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   698
                this.line.dashArray = [2, 2];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   699
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   700
                var opacity = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   701
                this.line.dashArray = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   702
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   703
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   704
            var old_act_btn = this.active_buttons;
2
3360c3f7fb18 Added Edge management to the rendering engine
veltr
parents: 1
diff changeset
   705
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   706
            this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   707
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   708
            if (this.selected && this.renderer.isEditable() && old_act_btn !== this.active_buttons) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   709
                old_act_btn.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   710
                    b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   711
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   712
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   713
                    b.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   714
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   715
            }
2
3360c3f7fb18 Added Edge management to the rendering engine
veltr
parents: 1
diff changeset
   716
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   717
            this.paper_coords = _p0b.add(_p1b).divide(2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   718
            this.line.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   719
            this.line.opacity = opacity;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   720
            this.line.segments[0].point = _p0a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   721
            this.line.segments[1].point = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   722
            this.line.segments[1].handleIn = _handle.multiply(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   723
            this.line.segments[1].handleOut = _handle;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   724
            this.line.segments[2].point = _p1a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   725
            this.arrow.rotate(_a - this.arrow_angle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   726
            this.arrow.fillColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   727
            this.arrow.opacity = opacity;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   728
            this.arrow.position = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   729
            this.arrow_angle = _a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   730
            if (_a > 90) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   731
                _a -= 180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   732
                _textdelta = _textdelta.multiply(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   733
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   734
            if (_a < -90) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   735
                _a += 180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   736
                _textdelta = _textdelta.multiply(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   737
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   738
            var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_edges) || "";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   739
            _text = shortenText(_text, this.options.node_label_max_length);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   740
            this.text.text(_text);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   741
            var _textpos = this.paper_coords.add(_textdelta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   742
            this.text.css({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   743
                left: _textpos.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   744
                top: _textpos.y,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   745
                transform: "rotate(" + _a + "deg)",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   746
                "-moz-transform": "rotate(" + _a + "deg)",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   747
                "-webkit-transform": "rotate(" + _a + "deg)",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   748
                opacity: opacity
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   749
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   750
            this.text_angle = _a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   751
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   752
            var _pc = this.paper_coords;
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
   753
            this.all_buttons.forEach(function(b) {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   754
                b.moveTo(_pc);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   755
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   756
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   757
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   758
                this.minimap_line.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   759
                this.minimap_line.segments[0].point = this.renderer.toMinimapCoords(new paper.Point(this.from_representation.model.get("position")));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   760
                this.minimap_line.segments[1].point = this.renderer.toMinimapCoords(new paper.Point(this.to_representation.model.get("position")));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   761
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   762
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   763
        openEditor: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   764
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   765
            var _editor = this.renderer.addRepresentation("EdgeEditor",null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   766
            _editor.source_representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   767
            _editor.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   768
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   769
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   770
            this.selected = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   771
            this.line.strokeWidth = this.options.selected_edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   772
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   773
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   774
                    b.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   775
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   776
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   777
            if (!this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   778
                this.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   779
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   780
            this._super("select");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   781
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   782
        unselect: function(_newTarget) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   783
            if (!_newTarget || _newTarget.source_representation !== this) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   784
                this.selected = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   785
                if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   786
                    this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   787
                        b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   788
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   789
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   790
                this.line.strokeWidth = this.options.edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   791
                this._super("unselect");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   792
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   793
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   794
        mousedown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   795
            if (_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   796
                this.renderer.unselectAll();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   797
                this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   798
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   799
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   800
        mouseup: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   801
            if (!this.renkan.read_only && this.renderer.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   802
                this.from_representation.saveCoords();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   803
                this.to_representation.saveCoords();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   804
                this.from_representation.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   805
                this.to_representation.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   806
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   807
                if (!_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   808
                    this.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   809
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   810
                this.model.trigger("clicked");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   811
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   812
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   813
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   814
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   815
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   816
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   817
                if (!this.options.read_only) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   818
                    this.from_representation.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   819
                    this.to_representation.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   820
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   821
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   822
                this.renderer.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   823
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   824
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   825
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   826
            this._super("destroy");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   827
            this.line.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   828
            this.arrow.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   829
            this.text.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   830
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   831
                this.minimap_line.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   832
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   833
            this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   834
                b.destroy();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   835
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   836
            var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   837
            this.bundle.edges = _(this.bundle.edges).reject(function(_edge) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   838
                return _edge === _this;
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
   839
            });
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 113
diff changeset
   840
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   841
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   842
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   843
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   844
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   845
    var TempEdge = Renderer.TempEdge = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   846
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   847
    _(TempEdge.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   848
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   849
            this.renderer.edge_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   850
            this.type = "Temp-edge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   851
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   852
            var _color = (this.project.get("users").get(this.renkan.current_user) || _USER_PLACEHOLDER(this.renkan)).get("color");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   853
            this.line = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   854
            this.line.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   855
            this.line.dashArray = [4, 2];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   856
            this.line.strokeWidth = this.options.selected_edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   857
            this.line.add([0,0],[0,0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   858
            this.line.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   859
            this.arrow = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   860
            this.arrow.fillColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   861
            this.arrow.add(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   862
                    [ 0, 0 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   863
                    [ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   864
                    [ 0, this.options.edge_arrow_width ]
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   865
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   866
            this.arrow.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   867
            this.arrow_angle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   868
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   869
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   870
            var _p0 = this.from_representation.paper_coords,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   871
            _p1 = this.end_pos,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   872
            _a = _p1.subtract(_p0).angle,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   873
            _c = _p0.add(_p1).divide(2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   874
            this.line.segments[0].point = _p0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   875
            this.line.segments[1].point = _p1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   876
            this.arrow.rotate(_a - this.arrow_angle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   877
            this.arrow.position = _c;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   878
            this.arrow_angle = _a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   879
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   880
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   881
            if (!this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   882
                this.renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   883
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   884
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   885
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   886
            this.end_pos = this.end_pos.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   887
            var _hitResult = paper.project.hitTest(this.end_pos);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   888
            this.renderer.findTarget(_hitResult);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   889
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   890
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   891
        mouseup: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   892
            var _hitResult = paper.project.hitTest(_event.point),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   893
            _model = this.from_representation.model,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   894
            _endDrag = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   895
            if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   896
                var _target = _hitResult.item.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   897
                if (_target.type.substr(0,4) === "Node") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   898
                    var _destmodel = _target.model || _target.source_representation.model;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   899
                    if (_model !== _destmodel) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   900
                        var _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   901
                                id: Rkns.Utils.getUID('edge'),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   902
                                created_by: this.renkan.current_user,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   903
                                from: _model,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   904
                                to: _destmodel
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   905
                        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   906
                        if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   907
                            this.project.addEdge(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   908
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   909
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   910
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   911
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   912
                if (_model === _target.model || (_target.source_representation && _target.source_representation.model === _model)) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   913
                    _endDrag = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   914
                    this.renderer.is_dragging = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   915
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   916
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   917
            if (_endDrag) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   918
                this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   919
                this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   920
                this.renderer.removeRepresentation(this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   921
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   922
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   923
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   924
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   925
            this.arrow.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   926
            this.line.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   927
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   928
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   929
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   930
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   931
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   932
    var _BaseEditor = Renderer._BaseEditor = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   933
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   934
    _(_BaseEditor.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   935
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   936
            this.renderer.buttons_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   937
            this.type = "editor";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   938
            this.editor_block = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   939
            var _pts = _(_.range(8)).map(function() {return [0,0];});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   940
            this.editor_block.add.apply(this.editor_block, _pts);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   941
            this.editor_block.strokeWidth = this.options.tooltip_border_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   942
            this.editor_block.strokeColor = this.options.tooltip_border_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   943
            this.editor_block.opacity = .8;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   944
            this.editor_$ = $('<div>')
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   945
            .appendTo(this.renderer.editor_$)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   946
            .css({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   947
                position: "absolute",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   948
                opacity: .8
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   949
            })
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   950
            .hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   951
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   952
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   953
            this.editor_block.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   954
            this.editor_$.remove();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   955
        }
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
   956
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   957
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   958
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   959
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   960
    var NodeEditor = Renderer.NodeEditor = Rkns.Utils.inherit(_BaseEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   961
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   962
    _(NodeEditor.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   963
        template: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   964
                '<h2><span class="Rk-CloseX">&times;</span><%-renkan.translate("Edit Node")%></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   965
                + '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-node.title%>"/></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   966
                + '<% if (options.show_node_editor_uri) { %><p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-node.uri%>"/><a class="Rk-Edit-Goto" href="<%-node.uri%>" target="_blank"></a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   967
                + '<% if (options.show_node_editor_description) { %><p><label><%-renkan.translate("Description:")%></label><textarea class="Rk-Edit-Description"><%-node.description%></textarea></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   968
                + '<% if (options.show_node_editor_size) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Size:")%></span><a href="#" class="Rk-Edit-Size-Down">-</a><span class="Rk-Edit-Size-Value"><%-node.size%></span><a href="#" class="Rk-Edit-Size-Up">+</a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   969
                + '<% if (options.show_node_editor_color) { %><div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-renkan.translate("Node color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-node.color%>;"><span class="Rk-Edit-ColorTip"></span></span>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   970
                + '<%= renkan.colorPicker %><span class="Rk-Edit-ColorPicker-Text"><%- renkan.translate("Choose color") %></span></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   971
                + '<% if (options.show_node_editor_image) { %><div class="Rk-Edit-ImgWrap"><div class="Rk-Edit-ImgPreview"><img src="<%-node.image || node.image_placeholder%>" />'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   972
                + '<% if (node.clip_path) { %><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 1 1" preserveAspectRatio="none"><path style="stroke-width: .02; stroke:red; fill-opacity:.3; fill:red;" d="<%- node.clip_path %>"/></svg><% }%>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   973
                + '</div></div><p><label><%-renkan.translate("Image URL:")%></label><input class="Rk-Edit-Image" type="text" value="<%-node.image%>"/></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   974
                + '<p><label><%-renkan.translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p><% } %>'    
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   975
                + '<% if (options.show_node_editor_creator && node.has_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><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   976
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   977
        readOnlyTemplate: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   978
                '<h2><span class="Rk-CloseX">&times;</span><% if (options.show_node_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-node.color%>;"></span><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   979
                + '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   980
                + '<% if (node.uri && options.show_node_tooltip_uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   981
                + '<% if (options.show_node_tooltip_description) { %><p class="Rk-Display-Description"><%-node.description%></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   982
                + '<% if (node.image && options.show_node_tooltip_image) { %><img class="Rk-Display-ImgPreview" src="<%-node.image%>" /><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   983
                + '<% 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><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   984
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   985
        draw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   986
            var _model = this.source_representation.model,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   987
            _created_by = _model.get("created_by") || _USER_PLACEHOLDER(this.renkan),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   988
            _template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   989
            _image_placeholder = this.options.static_url + "img/image-placeholder.png",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   990
            _size = (_model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   991
            this.editor_$
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   992
            .html(_template({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   993
                node: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   994
                    has_creator: !!_model.get("created_by"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   995
                    title: _model.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   996
                    uri: _model.get("uri"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   997
                    short_uri:  shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   998
                    description: _model.get("description"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   999
                    image: _model.get("image") || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1000
                    image_placeholder: _image_placeholder,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1001
                    color: _model.get("color") || _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1002
                    clip_path: _model.get("clip_path") || false,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1003
                    created_by_color: _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1004
                    created_by_title: _created_by.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1005
                    size: (_size > 0 ? "+" : "") + _size
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1006
                },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1007
                renkan: this.renkan,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1008
                options: this.options,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1009
                shortenText: shortenText
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1010
            }));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1011
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1012
            var _this = this,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1013
            closeEditor = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1014
                _this.renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1015
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1016
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1017
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1018
            this.editor_$.find(".Rk-CloseX").click(closeEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1019
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1020
            this.editor_$.find(".Rk-Edit-Goto").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1021
                if (!_model.get("uri")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1022
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1023
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1024
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1025
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1026
            if (this.renderer.isEditable()) {
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
  1027
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1028
                var onFieldChange = _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1029
                    _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1030
                        if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1031
                            var _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1032
                                    title: _this.editor_$.find(".Rk-Edit-Title").val()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1033
                            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1034
                            if (_this.options.show_node_editor_uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1035
                                _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1036
                                _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1037
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1038
                            if (_this.options.show_node_editor_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1039
                                _data.image = _this.editor_$.find(".Rk-Edit-Image").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1040
                                _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1041
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1042
                            if (_this.options.show_node_editor_description) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1043
                                _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1044
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1045
                            _model.set(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1046
                            _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1047
                        } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1048
                            closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1049
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1050
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1051
                    }).defer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1052
                }).throttle(500);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1053
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1054
                this.editor_$.on("keyup", function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1055
                    if (_e.keyCode === 27) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1056
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1057
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1058
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1059
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1060
                this.editor_$.find("input, textarea").on("change keyup paste", onFieldChange);
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
  1061
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1062
                this.editor_$.find(".Rk-Edit-Image-File").change(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1063
                    if (this.files.length) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1064
                        var f = this.files[0],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1065
                        fr = new FileReader();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1066
                        if (f.type.substr(0,5) !== "image") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1067
                            alert(_this.renkan.translate("This file is not an image"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1068
                            return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1069
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1070
                        if (f.size > (_this.options.uploaded_image_max_kb * 1024)) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1071
                            alert(_this.renkan.translate("Image size must be under ") + _this.options.uploaded_image_max_kb + _this.renkan.translate("KB"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1072
                            return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1073
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1074
                        fr.onload = function(e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1075
                            _this.editor_$.find(".Rk-Edit-Image").val(e.target.result);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1076
                            onFieldChange();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1077
                        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1078
                        fr.readAsDataURL(f);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1079
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1080
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1081
                this.editor_$.find(".Rk-Edit-Title")[0].focus();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1082
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1083
                var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1084
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1085
                this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1086
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1087
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1088
                            _picker.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1089
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1090
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1091
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1092
                            _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1093
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1094
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1095
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1096
                _picker.find("li").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1097
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1098
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1099
                            _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1100
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1101
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1102
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1103
                            _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || _USER_PLACEHOLDER(_this.renkan)).get("color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1104
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1105
                ).click(function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1106
                    _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1107
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1108
                        _model.set("color", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1109
                        _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1110
                        paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1111
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1112
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1113
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1114
                });
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
  1115
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1116
                var shiftSize = function(n) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1117
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1118
                        var _newsize = n+(_model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1119
                        _this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1120
                        _model.set("size", _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1121
                        paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1122
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1123
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1124
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1125
                };
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1126
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1127
                this.editor_$.find(".Rk-Edit-Size-Down").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1128
                    shiftSize(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1129
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1130
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1131
                this.editor_$.find(".Rk-Edit-Size-Up").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1132
                    shiftSize(1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1133
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1134
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1135
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1136
                if (typeof this.source_representation.highlighted === "object") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1137
                    var titlehtml = this.source_representation.highlighted.replace(_(_model.get("title")).escape(),'<span class="Rk-Highlighted">$1</span>');
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1138
                    this.editor_$.find(".Rk-Display-Title" + (_model.get("uri") ? " a" : "")).html(titlehtml);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1139
                    if (this.options.show_node_tooltip_description) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1140
                        this.editor_$.find(".Rk-Display-Description").html(this.source_representation.highlighted.replace(_(_model.get("description")).escape(),'<span class="Rk-Highlighted">$1</span>'));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1141
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1142
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1143
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1144
            this.editor_$.find("img").load(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1145
                _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1146
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1147
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1148
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1149
            var _coords = this.source_representation.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1150
            drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * .75, this.editor_$);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1151
            this.editor_$.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1152
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1153
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1154
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1155
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1156
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1157
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1158
    var EdgeEditor = Renderer.EdgeEditor = Rkns.Utils.inherit(_BaseEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1159
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1160
    _(EdgeEditor.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1161
        template: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1162
                '<h2><span class="Rk-CloseX">&times;</span><%-renkan.translate("Edit Edge")%></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1163
                + '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-edge.title%>"/></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1164
                + '<% if (options.show_edge_editor_uri) { %><p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-edge.uri%>"/><a class="Rk-Edit-Goto" href="<%-edge.uri%>" target="_blank"></a></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1165
                + '<% if (options.properties.length) { %><p><label><%-renkan.translate("Choose from vocabulary:")%></label><select class="Rk-Edit-Vocabulary">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1166
                + '<% _(options.properties).each(function(ontology) { %><option class="Rk-Edit-Vocabulary-Class" value=""><%- renkan.translate(ontology.label) %></option>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1167
                + '<% _(ontology.properties).each(function(property) { var uri = ontology["base-uri"] + property.uri; %><option class="Rk-Edit-Vocabulary-Property" value="<%- uri %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1168
                + '"<% if (uri === edge.uri) { %> selected<% } %>><%- renkan.translate(property.label) %></option>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1169
                + '<% }) %><% }) %></select></p><% } } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1170
                + '<% if (options.show_edge_editor_color) { %><div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-renkan.translate("Edge color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-edge.color%>;"><span class="Rk-Edit-ColorTip"></span></span>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1171
                + '<%= renkan.colorPicker %><span class="Rk-Edit-ColorPicker-Text"><%- renkan.translate("Choose color") %></span></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1172
                + '<% if (options.show_edge_editor_direction) { %><p><span class="Rk-Edit-Direction"><%- renkan.translate("Change edge direction") %></span></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1173
                + '<% if (options.show_edge_editor_nodes) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- shortenText(edge.from_title, 25) %></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1174
                + '<p><span class="Rk-Editor-Label"><%-renkan.translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- shortenText(edge.to_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1175
                + '<% if (options.show_edge_editor_creator && edge.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- shortenText(edge.created_by_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1176
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1177
        readOnlyTemplate: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1178
                '<h2><span class="Rk-CloseX">&times;</span><% if (options.show_edge_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-edge.color%>;"></span><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1179
                + '<span class="Rk-Display-Title"><% if (edge.uri) { %><a href="<%-edge.uri%>" target="_blank"><% } %><%-edge.title%><% if (edge.uri) { %></a><% } %></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1180
                + '<% if (options.show_edge_tooltip_uri && edge.uri) { %><p class="Rk-Display-URI"><a href="<%-edge.uri%>" target="_blank"><%-edge.short_uri%></a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1181
                + '<p><%-edge.description%></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1182
                + '<% if (options.show_edge_tooltip_nodes) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- shortenText(edge.from_title, 25) %></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1183
                + '<p><span class="Rk-Editor-Label"><%-renkan.translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- shortenText(edge.to_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1184
                + '<% if (options.show_edge_tooltip_creator && edge.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- shortenText(edge.created_by_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1185
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1186
        draw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1187
            var _model = this.source_representation.model,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1188
            _from_model = _model.get("from"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1189
            _to_model = _model.get("to"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1190
            _created_by = _model.get("created_by") || _USER_PLACEHOLDER(this.renkan),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1191
            _template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1192
            this.editor_$
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1193
            .html(_template({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1194
                edge: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1195
                    has_creator: !!_model.get("created_by"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1196
                    title: _model.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1197
                    uri: _model.get("uri"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1198
                    short_uri:  shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1199
                    description: _model.get("description"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1200
                    color: _model.get("color") || _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1201
                    from_title: _from_model.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1202
                    to_title: _to_model.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1203
                    from_color: _from_model.get("color") || (_from_model.get("created_by") || _USER_PLACEHOLDER(this.renkan)).get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1204
                    to_color: _to_model.get("color") || (_to_model.get("created_by") || _USER_PLACEHOLDER(this.renkan)).get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1205
                    created_by_color: _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1206
                    created_by_title: _created_by.get("title")
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1207
                },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1208
                renkan: this.renkan,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1209
                shortenText: shortenText,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1210
                options: this.options
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1211
            }));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1212
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1213
            var _this = this,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1214
            closeEditor = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1215
                _this.renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1216
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1217
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1218
            this.editor_$.find(".Rk-CloseX").click(closeEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1219
            this.editor_$.find(".Rk-Edit-Goto").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1220
                if (!_model.get("uri")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1221
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1222
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1223
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1224
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1225
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1226
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1227
                var onFieldChange = _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1228
                    _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1229
                        if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1230
                            var _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1231
                                    title: _this.editor_$.find(".Rk-Edit-Title").val()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1232
                            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1233
                            if (_this.options.show_edge_editor_uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1234
                                _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1235
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1236
                            _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1237
                            _model.set(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1238
                            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1239
                        } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1240
                            closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1241
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1242
                    }).defer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1243
                }).throttle(500);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1244
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1245
                this.editor_$.on("keyup", function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1246
                    if (_e.keyCode === 27) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1247
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1248
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1249
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1250
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1251
                this.editor_$.find("input").on("keyup change paste", onFieldChange);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1252
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1253
                this.editor_$.find(".Rk-Edit-Vocabulary").change(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1254
                    var e = $(this),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1255
                    v = e.val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1256
                    if (v) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1257
                        _this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text());
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1258
                        _this.editor_$.find(".Rk-Edit-URI").val(v);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1259
                        onFieldChange();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1260
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1261
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1262
                this.editor_$.find(".Rk-Edit-Direction").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1263
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1264
                        _model.set({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1265
                            from: _model.get("to"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1266
                            to: _model.get("from")
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1267
                        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1268
                        _this.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1269
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1270
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1271
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1272
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1273
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1274
                var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1275
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1276
                this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1277
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1278
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1279
                            _picker.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1280
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1281
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1282
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1283
                            _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1284
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1285
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1286
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1287
                _picker.find("li").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1288
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1289
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1290
                            _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1291
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1292
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1293
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1294
                            _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || _USER_PLACEHOLDER(_this.renkan)).get("color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1295
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1296
                ).click(function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1297
                    _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1298
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1299
                        _model.set("color", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1300
                        _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1301
                        paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1302
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1303
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1304
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1305
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1306
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1307
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1308
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1309
            var _coords = this.source_representation.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1310
            drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1311
            this.editor_$.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1312
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1313
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1314
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1315
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1316
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1317
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1318
    var _NodeButton = Renderer._NodeButton = Rkns.Utils.inherit(_BaseButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1319
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1320
    _(_NodeButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1321
        setSectorSize: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1322
            var sectorInner = this.source_representation.circle_radius;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1323
            if (sectorInner !== this.lastSectorInner) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1324
                if (this.sector) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1325
                    this.sector.destroy();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1326
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1327
                this.sector = this.renderer.drawSector(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1328
                        this, 1 + sectorInner,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1329
                        _NODE_BUTTON_WIDTH + sectorInner,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1330
                        this.startAngle,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1331
                        this.endAngle,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1332
                        1,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1333
                        this.imageName,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1334
                        this.renkan.translate(this.text)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1335
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1336
                this.lastSectorInner = sectorInner;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1337
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1338
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1339
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1340
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1341
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1342
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1343
    var NodeEditButton = Renderer.NodeEditButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1344
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1345
    _(NodeEditButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1346
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1347
            this.type = "Node-edit-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1348
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1349
            this.startAngle = -135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1350
            this.endAngle = -45;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1351
            this.imageName = "edit";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1352
            this.text = "Edit";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1353
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1354
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1355
            if (!this.renderer.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1356
                this.source_representation.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1357
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1358
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1359
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1360
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1361
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1362
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1363
    var NodeRemoveButton = Renderer.NodeRemoveButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1364
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1365
    _(NodeRemoveButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1366
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1367
            this.type = "Node-remove-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1368
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1369
            this.startAngle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1370
            this.endAngle = 90;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1371
            this.imageName = "remove";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1372
            this.text = "Remove";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1373
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1374
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1375
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1376
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1377
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1378
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1379
                if (this.options.element_delete_delay) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1380
                    var delid = Rkns.Utils.getUID("delete");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1381
                    this.renderer.delete_list.push({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1382
                        id: delid,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1383
                        time: new Date().valueOf() + this.options.element_delete_delay
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1384
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1385
                    this.source_representation.model.set("delete_scheduled", delid);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1386
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1387
                    if (confirm(this.renkan.translate('Do you really wish to remove node ') + '"' + this.source_representation.model.get("title") + '"?')) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1388
                        this.project.removeNode(this.source_representation.model);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1389
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1390
                }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1391
            }
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
  1392
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1393
    });
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
  1394
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1395
    /* */
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
  1396
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1397
    var NodeRevertButton = Renderer.NodeRevertButton = Rkns.Utils.inherit(_NodeButton);
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
  1398
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1399
    _(NodeRevertButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1400
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1401
            this.type = "Node-revert-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1402
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1403
            this.startAngle = -135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1404
            this.endAngle = 135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1405
            this.imageName = "revert";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1406
            this.text = "Cancel deletion";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1407
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1408
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1409
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1410
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1411
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1412
                this.source_representation.model.unset("delete_scheduled");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1413
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1414
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1415
    });
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1416
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1417
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1418
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1419
    var NodeLinkButton = Renderer.NodeLinkButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1420
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1421
    _(NodeLinkButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1422
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1423
            this.type = "Node-link-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1424
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1425
            this.startAngle = 90;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1426
            this.endAngle = 180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1427
            this.imageName = "link";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1428
            this.text = "Link to another node";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1429
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1430
        mousedown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1431
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1432
                var _off = this.renderer.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1433
                _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1434
                                          _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1435
                                          _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1436
                                          ]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1437
                this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1438
                this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1439
                this.renderer.addTempEdge(this.source_representation, _point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1440
            }
194
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1441
        }
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1442
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1443
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1444
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1445
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1446
    var NodeEnlargeButton = Renderer.NodeEnlargeButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1447
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1448
    _(NodeEnlargeButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1449
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1450
            this.type = "Node-enlarge-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1451
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1452
            this.startAngle = -45;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1453
            this.endAngle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1454
            this.imageName = "enlarge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1455
            this.text = "Enlarge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1456
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1457
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1458
            var _newsize = 1 + (this.source_representation.model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1459
            this.source_representation.model.set("size", _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1460
            this.source_representation.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1461
            this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1462
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1463
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1464
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1465
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1466
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1467
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1468
    var NodeShrinkButton = Renderer.NodeShrinkButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1469
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1470
    _(NodeShrinkButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1471
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1472
            this.type = "Node-shrink-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1473
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1474
            this.startAngle = -180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1475
            this.endAngle = -135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1476
            this.imageName = "shrink";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1477
            this.text = "Shrink";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1478
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1479
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1480
            var _newsize = -1 + (this.source_representation.model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1481
            this.source_representation.model.set("size", _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1482
            this.source_representation.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1483
            this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1484
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1485
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1486
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1487
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1488
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1489
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1490
    var EdgeEditButton = Renderer.EdgeEditButton = Rkns.Utils.inherit(_BaseButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1491
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1492
    _(EdgeEditButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1493
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1494
            this.type = "Edge-edit-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1495
            this.sector = this.renderer.drawSector(this, _EDGE_BUTTON_INNER, _EDGE_BUTTON_OUTER, -270, -90, 1, "edit", this.renkan.translate("Edit"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1496
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1497
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1498
            if (!this.renderer.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1499
                this.source_representation.openEditor();
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 113
diff changeset
  1500
            }
194
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1501
        }
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1502
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1503
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1504
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1505
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1506
    var EdgeRemoveButton = Renderer.EdgeRemoveButton = Rkns.Utils.inherit(_BaseButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1507
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1508
    _(EdgeRemoveButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1509
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1510
            this.type = "Edge-remove-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1511
            this.sector = this.renderer.drawSector(this, _EDGE_BUTTON_INNER, _EDGE_BUTTON_OUTER, -90, 90, 1, "remove", this.renkan.translate("Remove"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1512
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1513
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1514
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1515
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1516
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1517
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1518
                if (this.options.element_delete_delay) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1519
                    var delid = Rkns.Utils.getUID("delete");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1520
                    this.renderer.delete_list.push({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1521
                        id: delid,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1522
                        time: new Date().valueOf() + this.options.element_delete_delay
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1523
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1524
                    this.source_representation.model.set("delete_scheduled", delid);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1525
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1526
                    if (confirm(this.renkan.translate('Do you really wish to remove edge ') + '"' + this.source_representation.model.get("title") + '"?')) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1527
                        this.project.removeEdge(this.source_representation.model);
173
009427475db2 Improvements for MDP and CG
veltr
parents: 170
diff changeset
  1528
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1529
                }
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1530
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1531
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1532
    });
7
ae86ecebb1be Added Edit-Remove buttons
veltr
parents: 6
diff changeset
  1533
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1534
    /* */
7
ae86ecebb1be Added Edit-Remove buttons
veltr
parents: 6
diff changeset
  1535
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1536
    var EdgeRevertButton = Renderer.EdgeRevertButton = Rkns.Utils.inherit(_BaseButton);
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
  1537
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1538
    _(EdgeRevertButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1539
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1540
            this.type = "Edge-revert-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1541
            this.sector = this.renderer.drawSector(this, _EDGE_BUTTON_INNER, _EDGE_BUTTON_OUTER, -135, 135, 1, "revert", this.renkan.translate("Cancel deletion"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1542
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1543
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1544
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1545
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1546
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1547
                this.source_representation.model.unset("delete_scheduled");
174
756cfa6570d2 Setting element_delete_delay now shows remove confirm dialog
veltr
parents: 173
diff changeset
  1548
            }
756cfa6570d2 Setting element_delete_delay now shows remove confirm dialog
veltr
parents: 173
diff changeset
  1549
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1550
    });
7
ae86ecebb1be Added Edit-Remove buttons
veltr
parents: 6
diff changeset
  1551
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1552
    /* */
11
c73bfb5c0af6 UI Improvements before merge
veltr
parents: 10
diff changeset
  1553
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1554
    var MiniFrame = Renderer.MiniFrame = Rkns.Utils.inherit(_BaseRepresentation);
11
c73bfb5c0af6 UI Improvements before merge
veltr
parents: 10
diff changeset
  1555
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1556
    _(MiniFrame.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1557
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1558
            this.renderer.offset = this.renderer.offset.subtract(_delta.divide(this.renderer.minimap.scale).multiply(this.renderer.scale));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1559
            this.renderer.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1560
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1561
        mouseup: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1562
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1563
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1564
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1565
    });
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
  1566
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1567
    /* */
15
de8528eb3662 Commit before merge
veltr
parents: 11
diff changeset
  1568
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1569
    var Scene = Renderer.Scene = function(_renkan) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1570
        this.renkan = _renkan;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1571
        this.$ = $(".Rk-Render");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1572
        this.representations = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1573
        this.$.html(this.template(_renkan));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1574
        this.onStatusChange();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1575
        this.canvas_$ = this.$.find(".Rk-Canvas");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1576
        this.labels_$ = this.$.find(".Rk-Labels");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1577
        this.editor_$ = this.$.find(".Rk-Editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1578
        this.notif_$ = this.$.find(".Rk-Notifications");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1579
        paper.setup(this.canvas_$[0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1580
        this.scale = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1581
        this.initialScale = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1582
        this.offset = paper.view.center;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1583
        this.totalScroll = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1584
        this.mouse_down = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1585
        this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1586
        this.selected_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1587
        this.edge_layer = new paper.Layer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1588
        this.node_layer = new paper.Layer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1589
        this.buttons_layer = new paper.Layer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1590
        this.delete_list = [];
70
47b3125130a2 bookmarklet evolution
veltr
parents: 69
diff changeset
  1591
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1592
        if (_renkan.options.show_minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1593
            this.minimap = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1594
                    background_layer: new paper.Layer(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1595
                    edge_layer: new paper.Layer(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1596
                    node_layer: new paper.Layer(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1597
                    node_group: new paper.Group(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1598
                    size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height )
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1599
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1600
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1601
            this.minimap.background_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1602
            this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1603
            this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4]));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1604
            this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1605
            this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1606
            this.minimap.rectangle.strokeWidth = 4;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1607
            this.minimap.offset = new paper.Point(this.minimap.size.divide(2));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1608
            this.minimap.scale = .1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1609
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1610
            this.minimap.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1611
            this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1612
            this.minimap.node_group.addChild(this.minimap.cliprectangle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1613
            this.minimap.node_group.clipped = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1614
            this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1615
            this.minimap.node_group.addChild(this.minimap.miniframe);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1616
            this.minimap.miniframe.fillColor = '#c0c0ff';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1617
            this.minimap.miniframe.opacity = .3;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1618
            this.minimap.miniframe.strokeColor = '#000080';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1619
            this.minimap.miniframe.strokeWidth = 3;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1620
            this.minimap.miniframe.__representation = new MiniFrame(this, null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1621
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1622
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1623
        this.throttledPaperDraw = _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1624
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1625
        }).throttle(100);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1626
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1627
        this.bundles = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1628
        this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1629
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1630
        var _this = this,
154
0f87088e03bc Started work on iPad compatibility
veltr
parents: 153
diff changeset
  1631
        _allowScroll = true,
0f87088e03bc Started work on iPad compatibility
veltr
parents: 153
diff changeset
  1632
        _originalScale,
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1633
        _zooming = false,
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1634
        _lastTapDate,
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1635
        _lastTapX,
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1636
        _lastTapY;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1637
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1638
        this.image_cache = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1639
        this.icon_cache = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1640
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1641
        ['edit', 'remove', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1642
            var img = new Image();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1643
            img.src = _renkan.options.static_url + 'img/' + imgname + '.png';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1644
            _this.icon_cache[imgname] = img;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1645
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1646
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1647
        var throttledMouseMove = _.throttle(function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1648
            _this.onMouseMove(_event, _isTouch);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1649
        }, _MOUSEMOVE_RATE);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1650
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1651
        this.canvas_$.on({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1652
            mousedown: function(_event) {
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 207
diff changeset
  1653
                _event.preventDefault();
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1654
                _this.onMouseDown(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1655
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1656
            mousemove: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1657
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1658
                throttledMouseMove(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1659
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1660
            mouseup: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1661
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1662
                _this.onMouseUp(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1663
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1664
            mousewheel: function(_event, _delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1665
                if(_renkan.options.zoom_on_scroll) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1666
                    _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1667
                    if (_allowScroll) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1668
                        _this.onScroll(_event, _delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1669
                    }
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 207
diff changeset
  1670
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1671
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1672
            touchstart: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1673
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1674
                var _touches = _event.originalEvent.touches[0];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1675
                if (
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1676
                        _renkan.options.allow_double_click
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1677
                        && new Date() - _lastTap < _DOUBLETAP_DELAY
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1678
                        && ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < _DOUBLETAP_DISTANCE )
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1679
                ) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1680
                    _lastTap = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1681
                    _this.onDoubleClick(_touches);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1682
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1683
                    _lastTap = new Date();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1684
                    _lastTapX = _touches.pageX;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1685
                    _lastTapY = _touches.pageY;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1686
                    _originalScale = _this.scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1687
                    _zooming = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1688
                    _this.onMouseDown(_touches, true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1689
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1690
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1691
            touchmove: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1692
                _event.preventDefault();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1693
                _lastTap = 0;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1694
                if (_event.originalEvent.touches.length == 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1695
                    _this.onMouseMove(_event.originalEvent.touches[0], true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1696
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1697
                    if (!_zooming) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1698
                        _this.onMouseUp(_event.originalEvent.touches[0], true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1699
                        _this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1700
                        _this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1701
                        _zooming = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1702
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1703
                    if (_event.originalEvent.scale === "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1704
                        return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1705
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1706
                    var _newScale = _event.originalEvent.scale * _originalScale,
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1707
                    _scaleRatio = _newScale / _this.scale,
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1708
                    _newOffset = new paper.Point([
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1709
                                                  _this.canvas_$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1710
                                                  _this.canvas_$.height()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1711
                                                  ]).multiply( .5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio ));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1712
                    _this.setScale(_newScale, _this.offset);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1713
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1714
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1715
            touchend: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1716
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1717
                _this.onMouseUp(_event.originalEvent.changedTouches[0], true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1718
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1719
            dblclick: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1720
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1721
                if (_renkan.options.allow_double_click) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1722
                    _this.onDoubleClick(_event);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1723
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1724
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1725
            mouseleave: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1726
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1727
                _this.onMouseUp(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1728
                _this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1729
                _this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1730
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1731
            dragover: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1732
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1733
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1734
            dragenter: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1735
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1736
                _allowScroll = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1737
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1738
            dragleave: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1739
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1740
                _allowScroll = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1741
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1742
            drop: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1743
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1744
                _allowScroll = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1745
                var res = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1746
                _(_event.originalEvent.dataTransfer.types).each(function(t) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1747
                    try {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1748
                        res[t] = _event.originalEvent.dataTransfer.getData(t);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1749
                    } catch(e) {}
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1750
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1751
                var text = _event.originalEvent.dataTransfer.getData("Text");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1752
                if (typeof text === "string") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1753
                    switch(text[0]) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1754
                    case "{":
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1755
                    case "[":
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1756
                        try {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1757
                            var data = JSON.parse(text);
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1758
                            _(res).extend(data);
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1759
                        }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1760
                        catch(e) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1761
                            if (!res["text/plain"]) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1762
                                res["text/plain"] = text;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1763
                            }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1764
                        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1765
                        break;
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1766
                    case "<":
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1767
                        if (!res["text/html"]) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1768
                            res["text/html"] = text;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1769
                        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1770
                        break;
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1771
                    default:
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1772
                        if (!res["text/plain"]) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1773
                            res["text/plain"] = text;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1774
                        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1775
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1776
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1777
                var url = _event.originalEvent.dataTransfer.getData("URL");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1778
                if (url && !res["text/uri-list"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1779
                    res["text/uri-list"] = url;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1780
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1781
                _this.dropData(res, _event.originalEvent);
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1782
            }
190
a9040a7c47d9 Some changes for standalone app compatibility
veltr
parents: 189
diff changeset
  1783
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1784
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1785
        var bindClick = function(selector, fname) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1786
            _this.$.find(selector).click(function(evt) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1787
                _this[fname](evt);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1788
                return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1789
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1790
        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1791
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1792
        bindClick(".Rk-ZoomOut", "zoomOut");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1793
        bindClick(".Rk-ZoomIn", "zoomIn");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1794
        bindClick(".Rk-ZoomFit", "autoScale");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1795
        this.$.find(".Rk-ZoomSave").click( function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1796
            _this.renkan.project.set("views", [{id:Rkns.Utils.getUID('view'), zoom_level:_this.scale, offset_x:_this.offset.x, offset_y:_this.offset.y}]); // Save scale
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1797
            _this.$.find(".Rk-ZoomSetSaved").show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1798
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1799
        this.$.find(".Rk-ZoomSetSaved").click( function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1800
            var view = _this.renkan.project.get("views")[0];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1801
            _this.setScale(view.zoom_level, new paper.Point(view.offset_x, view.offset_y));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1802
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1803
        if(this.renkan.read_only && !isNaN(parseInt(this.renkan.options.default_view))){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1804
            this.$.find(".Rk-ZoomSetSaved").show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1805
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1806
        this.$.find(".Rk-CurrentUser").mouseenter(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1807
                function() { _this.$.find(".Rk-UserList").slideDown(); }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1808
        );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1809
        this.$.find(".Rk-Users").mouseleave(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1810
                function() { _this.$.find(".Rk-UserList").slideUp(); }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1811
        );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1812
        bindClick(".Rk-FullScreen-Button", "fullScreen");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1813
        bindClick(".Rk-AddNode-Button", "addNodeBtn");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1814
        bindClick(".Rk-AddEdge-Button", "addEdgeBtn");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1815
        bindClick(".Rk-Save-Button", "save");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1816
        bindClick(".Rk-Open-Button", "open");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1817
        this.$.find(".Rk-Bookmarklet-Button")
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
  1818
        .attr("href","javascript:" + _BOOKMARKLET_CODE(_renkan))
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1819
        .click(function(){
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1820
            _this.notif_$
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1821
            .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."))
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1822
            .fadeIn()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1823
            .delay(5000)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1824
            .fadeOut();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1825
            return false;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1826
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1827
        this.$.find(".Rk-TopBar-Button").mouseover(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1828
            $(this).find(".Rk-TopBar-Tooltip").show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1829
        }).mouseout(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1830
            $(this).find(".Rk-TopBar-Tooltip").hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1831
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1832
        bindClick(".Rk-Fold-Bins", "foldBins");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1833
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1834
        paper.view.onResize = function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1835
            // Because of paper bug which does not calculate the good height (and width a fortiori)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1836
            // We have to update manually the canvas's height
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1837
            paper.view._viewSize.height =  _event.size.height = _this.canvas_$.parent().height();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1838
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1839
            if (_this.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1840
                _this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1841
                _this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4]));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1842
                _this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size);
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 57
diff changeset
  1843
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1844
            _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1845
        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1846
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1847
        var _thRedraw = _.throttle(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1848
            _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1849
        },50);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1850
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1851
        this.addRepresentations("Node", this.renkan.project.get("nodes"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1852
        this.addRepresentations("Edge", this.renkan.project.get("edges"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1853
        this.renkan.project.on("change:title", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1854
            _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1855
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1856
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1857
        this.$.find(".Rk-PadTitle").on("keyup input paste", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1858
            _renkan.project.set({"title": $(this).val()});
163
fca0475da9a7 Changes for metadataplayer compatibility
veltr
parents: 161
diff changeset
  1859
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1860
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1861
        var _thRedrawUsers = _.throttle(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1862
            _this.redrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1863
        }, 100);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1864
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1865
        _thRedrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1866
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1867
        this.renkan.project.on("add:users remove:users", _thRedrawUsers);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1868
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1869
        this.renkan.project.on("add:nodes", function(_node) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1870
            _this.addRepresentation("Node", _node);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1871
            _thRedraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1872
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1873
        this.renkan.project.on("add:edges", function(_edge) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1874
            _this.addRepresentation("Edge", _edge);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1875
            _thRedraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1876
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1877
        this.renkan.project.on("change:title", function(_model, _title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1878
            var el = _this.$.find(".Rk-PadTitle");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1879
            if (el.is("input")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1880
                if (el.val() !== _title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1881
                    el.val(_title);
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  1882
                }
196
2a2fcec209d0 Added in-graph search
veltr
parents: 195
diff changeset
  1883
            } else {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1884
                el.text(_title);
196
2a2fcec209d0 Added in-graph search
veltr
parents: 195
diff changeset
  1885
            }
2a2fcec209d0 Added in-graph search
veltr
parents: 195
diff changeset
  1886
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1887
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1888
        if (_renkan.options.size_bug_fix) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1889
            var _delay = (
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1890
                    typeof _renkan.options.size_bug_fix === "number"
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1891
                        ? _renkan.options.size_bug_fix
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1892
                                : 500
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1893
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1894
            window.setTimeout(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1895
                    function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1896
                        _this.fixSize(true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1897
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1898
                    _delay
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1899
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1900
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1901
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1902
        if (_renkan.options.force_resize) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1903
            $(window).resize(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1904
                _this.fixSize(false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1905
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1906
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1907
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1908
        if (_renkan.options.show_user_list && _renkan.options.user_color_editable) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1909
            var $cpwrapper = this.$.find(".Rk-Users .Rk-Edit-ColorPicker-Wrapper"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1910
            $cplist = this.$.find(".Rk-Users .Rk-Edit-ColorPicker");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1911
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1912
            $cpwrapper.hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1913
                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1914
                        if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1915
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1916
                            $cplist.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1917
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1918
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1919
                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1920
                        _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1921
                        $cplist.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1922
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1923
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1924
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1925
            $cplist.find("li").mouseenter(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1926
                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1927
                        if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1928
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1929
                            _this.$.find(".Rk-CurrentUser-Color").css("background", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1930
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1931
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1932
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1933
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1934
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1935
        if (_renkan.options.show_search_field) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1936
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1937
            var lastval = '';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1938
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1939
            this.$.find(".Rk-GraphSearch-Field").on("keyup change paste input", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1940
                var $this = $(this),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1941
                val = $this.val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1942
                if (val === lastval) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1943
                    return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1944
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1945
                lastval = val;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1946
                if (val.length < 2) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1947
                    _renkan.project.get("nodes").each(function(n) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1948
                        _this.getRepresentationByModel(n).unhighlight();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1949
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1950
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1951
                    var rxs = Rkns.Utils.regexpFromTextOrArray(val);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1952
                    _renkan.project.get("nodes").each(function(n) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1953
                        if (rxs.test(n.get("title")) || rxs.test(n.get("description"))) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1954
                            _this.getRepresentationByModel(n).highlight(rxs);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1955
                        } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1956
                            _this.getRepresentationByModel(n).unhighlight(); 
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1957
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1958
                    });
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
  1959
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1960
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1961
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1962
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1963
        this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1964
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1965
        window.setInterval(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1966
            var _now = new Date().valueOf();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1967
            _this.delete_list.forEach(function(d) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1968
                if (_now >= d.time) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1969
                    var el = _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1970
                    if (el) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1971
                        project.removeNode(el);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1972
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1973
                    el = _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1974
                    if (el) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1975
                        project.removeEdge(el);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1976
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1977
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1978
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1979
            _this.delete_list = _this.delete_list.filter(function(d) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1980
                return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1981
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1982
        }, 500);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1983
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1984
        if (this.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1985
            window.setInterval(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1986
                _this.rescaleMinimap();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1987
            }, 2000);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1988
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1989
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1990
    };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1991
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1992
    _(Scene.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1993
        template: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1994
                '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1995
                + '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1996
                + '<% 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>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1997
                + '<% if (options.user_color_editable) { print(colorPicker) } %></div><span class="Rk-CurrentUser-Name">&lt;unknown user&gt;</span></div><ul class="Rk-UserList"></ul></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1998
                + '<% 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">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1999
                + '<%- translate(options.home_button_title) %></div></div></a><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2000
                + '<% 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><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2001
                + '<% if (options.editor_mode) { %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2002
                + '<% if (options.show_addnode_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2003
                + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Node")%></div></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2004
                + '<% if (options.show_addedge_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2005
                + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2006
                + '<% 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><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2007
                + '<% 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><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2008
                + '<% 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">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2009
                + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2010
                + '<div class="Rk-TopBar-Separator"></div><% }; if (options.show_search_field) { %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2011
                + '<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><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2012
                + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2013
                + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2014
                + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2015
                + '<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>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2016
                + '<% if (options.editor_mode) { %><div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2017
                + '<% if (options.editor_mode || !isNaN(parseInt(options.default_view))) { %><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div><% } %></div>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2018
                + '</div></div>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2019
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2020
        fixSize: function(_autoscale) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2021
            var w = this.$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2022
            h = this.$.height();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2023
            if (this.renkan.options.show_top_bar) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2024
                h -= this.$.find(".Rk-TopBar").height();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2025
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2026
            this.canvas_$.attr({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2027
                width: w,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2028
                height: h
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2029
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2030
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2031
            paper.view.viewSize = new paper.Size([w, h]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2032
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2033
            if (_autoscale) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2034
                // If _autoscale, we get the initial view (zoom+offset) set in the project datas.
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2035
                if(this.renkan.read_only && !isNaN(parseInt(this.renkan.options.default_view))){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2036
                    this.autoScale(this.renkan.project.get("views")[parseInt(this.renkan.options.default_view)]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2037
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2038
                else{
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2039
                    this.autoScale();
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
  2040
                }
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
  2041
            }
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  2042
        },
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2043
        drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2044
            var _options = this.renkan.options,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2045
            _startRads = _startAngle * Math.PI / 180,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2046
            _endRads = _endAngle * Math.PI / 180,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2047
            _img = this.icon_cache[_imgname],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2048
            _span = _endRads - _startRads,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2049
            _startdx = - Math.sin(_startRads),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2050
            _startdy = Math.cos(_startRads),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2051
            _startXIn = Math.cos(_startRads) * _inR + _padding * _startdx,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2052
            _startYIn = Math.sin(_startRads) * _inR + _padding * _startdy,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2053
            _startXOut = Math.cos(_startRads) * _outR + _padding * _startdx,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2054
            _startYOut = Math.sin(_startRads) * _outR + _padding * _startdy,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2055
            _enddx = - Math.sin(_endRads),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2056
            _enddy = Math.cos(_endRads),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2057
            _endXIn = Math.cos(_endRads) * _inR - _padding * _enddx,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2058
            _endYIn = Math.sin(_endRads) * _inR - _padding * _enddy,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2059
            _endXOut = Math.cos(_endRads) * _outR - _padding * _enddx,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2060
            _endYOut = Math.sin(_endRads) * _outR - _padding * _enddy,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2061
            _centerR = (_inR + _outR)/2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2062
            _centerRads = (_startRads + _endRads) / 2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2063
            _centerX = Math.cos(_centerRads) * _centerR,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2064
            _centerY = Math.sin(_centerRads) * _centerR,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2065
            _centerXIn = Math.cos(_centerRads) * _inR,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2066
            _centerXOut = Math.cos(_centerRads) * _outR,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2067
            _centerYIn = Math.sin(_centerRads) * _inR,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2068
            _centerYOut = Math.sin(_centerRads) * _outR,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2069
            _textX = Math.cos(_centerRads) * (_outR + 3),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2070
            _textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2071
            _segments = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2072
            this.buttons_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2073
            var _path = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2074
            _path.add([_startXIn, _startYIn]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2075
            _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2076
            _path.lineTo([_endXOut,  _endYOut]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2077
            _path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2078
            _path.fillColor = _options.buttons_background;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2079
            _path.opacity = .5;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2080
            _path.closed = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2081
            _path.__representation = _repr;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2082
            var _text = new paper.PointText(_textX,_textY);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2083
            _text.characterStyle = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2084
                    fontSize: _options.buttons_label_font_size,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2085
                    fillColor: _options.buttons_label_color
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2086
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2087
            if (_textX > 2) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2088
                _text.paragraphStyle.justification = 'left';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2089
            } else if (_textX < -2) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2090
                _text.paragraphStyle.justification = 'right';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2091
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2092
                _text.paragraphStyle.justification = 'center';
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  2093
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2094
            _text.visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2095
            var _visible = false,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2096
            _restPos = new paper.Point(-200, -200),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2097
            _grp = new paper.Group([_path, _text]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2098
            _delta = _grp.position,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2099
            _imgdelta = new paper.Point([_centerX, _centerY]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2100
            _currentPos = new paper.Point(0,0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2101
            _text.content = _caption;
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  2102
            _grp.visible = false;
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  2103
            _grp.position = _restPos;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2104
            var _res = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2105
                    show: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2106
                        _visible = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2107
                        _grp.position = _currentPos.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2108
                        _grp.visible = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2109
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2110
                    moveTo: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2111
                        _currentPos = _point;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2112
                        if (_visible) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2113
                            _grp.position = _point.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2114
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2115
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2116
                    hide: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2117
                        _visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2118
                        _grp.visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2119
                        _grp.position = _restPos;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2120
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2121
                    select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2122
                        _path.opacity = .8;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2123
                        _text.visible = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2124
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2125
                    unselect: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2126
                        _path.opacity = .5;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2127
                        _text.visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2128
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2129
                    destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2130
                        _grp.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2131
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2132
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2133
            function showImage() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2134
                var _raster = new paper.Raster(_img);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2135
                _raster.position = _imgdelta.add(_grp.position).subtract(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2136
                _raster.locked = true; // Disable mouse events on icon
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2137
                _grp.addChild(_raster);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2138
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2139
            if (_img.width) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2140
                showImage();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2141
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2142
                $(_img).on("load",showImage);
31
5e37072ec7b7 Added multiple edges
veltr
parents: 30
diff changeset
  2143
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2144
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2145
            return _res;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2146
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2147
        addToBundles: function(_edgeRepr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2148
            var _bundle = _(this.bundles).find(function(_bundle) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2149
                return ( 
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2150
                        ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation )
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2151
                        || ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation )
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2152
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2153
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2154
            if (typeof _bundle !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2155
                _bundle.edges.push(_edgeRepr);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2156
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2157
                _bundle = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2158
                        from: _edgeRepr.from_representation,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2159
                        to: _edgeRepr.to_representation,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2160
                        edges: [ _edgeRepr ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2161
                        getPosition: function(_er) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2162
                            var _dir = (_er.from_representation === this.from) ? 1 : -1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2163
                            return _dir * ( _(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2164
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2165
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2166
                this.bundles.push(_bundle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2167
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2168
            return _bundle;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2169
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2170
        isEditable: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2171
            return (this.renkan.options.editor_mode && !this.renkan.read_only);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2172
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2173
        onStatusChange: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2174
            var savebtn = this.$.find(".Rk-Save-Button"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2175
            tip = savebtn.find(".Rk-TopBar-Tooltip-Contents");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2176
            if (this.renkan.read_only) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2177
                savebtn.removeClass("disabled Rk-Save-Online").addClass("Rk-Save-ReadOnly");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2178
                tip.text(this.renkan.translate("Connection lost"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2179
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2180
                if (this.renkan.options.snapshot_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2181
                    savebtn.removeClass("Rk-Save-ReadOnly Rk-Save-Online");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2182
                    tip.text(this.renkan.translate("Save Project"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2183
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2184
                    savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2185
                    tip.text(this.renkan.translate("Auto-save enabled"));
198
d3737b90a66b Allow user name and color editing
veltr
parents: 197
diff changeset
  2186
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2187
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2188
            this.redrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2189
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2190
        setScale: function(_newScale, _offset) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2191
            if ((_newScale/this.initialScale) > _MIN_SCALE && (_newScale/this.initialScale) < _MAX_SCALE) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2192
                this.scale = _newScale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2193
                if (_offset) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2194
                    this.offset = _offset;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2195
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2196
                this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2197
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2198
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2199
        autoScale: function(force_view) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2200
            var nodes = this.renkan.project.get("nodes");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2201
            if (nodes.length > 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2202
                var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2203
                _yy = nodes.map(function(_node) { return _node.get("position").y; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2204
                _minx = Math.min.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2205
                _miny = Math.min.apply(Math, _yy),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2206
                _maxx = Math.max.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2207
                _maxy = Math.max.apply(Math, _yy);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2208
                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));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2209
                this.initialScale = _scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2210
                // Override calculated scale if asked
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2211
                if((typeof force_view !== "undefined") && parseFloat(force_view.zoom_level)>0 && parseFloat(force_view.offset_x)>0 && parseFloat(force_view.offset_y)>0){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2212
                    this.setScale(parseFloat(force_view.zoom_level), new paper.Point(parseFloat(force_view.offset_x), parseFloat(force_view.offset_y)));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2213
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2214
                else{
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2215
                    this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)));
198
d3737b90a66b Allow user name and color editing
veltr
parents: 197
diff changeset
  2216
                }
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  2217
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2218
            if (nodes.length === 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2219
                this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2220
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2221
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2222
        redrawMiniframe: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2223
            var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2224
            bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2225
            this.minimap.miniframe.fitBounds(topleft, bottomright);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2226
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2227
        rescaleMinimap: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2228
            var nodes = this.renkan.project.get("nodes");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2229
            if (nodes.length > 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2230
                var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2231
                _yy = nodes.map(function(_node) { return _node.get("position").y; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2232
                _minx = Math.min.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2233
                _miny = Math.min.apply(Math, _yy),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2234
                _maxx = Math.max.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2235
                _maxy = Math.max.apply(Math, _yy);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2236
                var _scale = Math.min(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2237
                        this.scale * .8 * this.renkan.options.minimap_width / paper.view.bounds.width,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2238
                        this.scale * .8 * this.renkan.options.minimap_height / paper.view.bounds.height,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2239
                        ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2240
                        ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2241
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2242
                this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2243
                this.minimap.scale = _scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2244
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2245
            if (nodes.length === 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2246
                this.minimap.scale = .1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2247
                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));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2248
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2249
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2250
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2251
        toPaperCoords: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2252
            return _point.multiply(this.scale).add(this.offset);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2253
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2254
        toMinimapCoords: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2255
            return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2256
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2257
        toModelCoords: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2258
            return _point.subtract(this.offset).divide(this.scale);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2259
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2260
        addRepresentation: function(_type, _model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2261
            var _repr = new Renderer[_type](this, _model);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2262
            this.representations.push(_repr);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2263
            return _repr;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2264
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2265
        addRepresentations: function(_type, _collection) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2266
            var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2267
            _collection.forEach(function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2268
                _this.addRepresentation(_type, _model);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2269
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2270
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2271
        userTemplate: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2272
                '<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2273
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2274
        redrawUsers: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2275
            if (!this.renkan.options.show_user_list) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2276
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2277
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2278
            var allUsers = [].concat((this.renkan.project.current_user_list || {}).models || [], (this.renkan.project.get("users") || {}).models || []),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2279
            ulistHtml = '',
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2280
            $userpanel = this.$.find(".Rk-Users"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2281
            $name = $userpanel.find(".Rk-CurrentUser-Name"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2282
            $cpwrapper = $userpanel.find(".Rk-Edit-ColorPicker-Wrapper"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2283
            $cpitems = $userpanel.find(".Rk-Edit-ColorPicker li"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2284
            $colorsquare = $userpanel.find(".Rk-CurrentUser-Color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2285
            _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2286
            $name.off("click").text(this.renkan.translate("<unknown user>"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2287
            $cpitems.off("mouseleave click");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2288
            allUsers.forEach(function(_user) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2289
                if (_user.get("_id") === _this.renkan.current_user) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2290
                    $name.text(_user.get("title"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2291
                    $colorsquare.css("background", _user.get("color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2292
                    if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2293
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2294
                        if (_this.renkan.options.user_name_editable) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2295
                            $name.click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2296
                                var $this = $(this),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2297
                                $input = $('<input>').val(_user.get("title")).blur(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2298
                                    _user.set("title", $(this).val());
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2299
                                    _this.redrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2300
                                    _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2301
                                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2302
                                $this.empty().html($input);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2303
                                $input.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2304
                            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2305
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2306
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2307
                        if (_this.renkan.options.user_color_editable) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2308
                            $cpitems.click(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2309
                                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2310
                                        _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2311
                                        if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2312
                                            _user.set("color", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2313
                                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2314
                                        $(this).parent().hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2315
                                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2316
                            ).mouseleave(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2317
                                $colorsquare.css("background", _user.get("color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2318
                            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2319
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2320
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2321
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2322
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2323
                    ulistHtml += _this.userTemplate({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2324
                        name: _user.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2325
                        background: _user.get("color")
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2326
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2327
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2328
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2329
            $userpanel.find(".Rk-UserList").html(ulistHtml);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2330
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2331
        removeRepresentation: function(_representation) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2332
            _representation.destroy();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2333
            this.representations = _(this.representations).reject(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2334
                    function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2335
                        return _repr == _representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2336
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2337
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2338
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2339
        getRepresentationByModel: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2340
            if (!_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2341
                return undefined;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2342
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2343
            return _(this.representations).find(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2344
                return _repr.model === _model;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2345
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2346
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2347
        removeRepresentationsOfType: function(_type) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2348
            var _representations = _(this.representations).filter(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2349
                return _repr.type == _type;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2350
            }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2351
            _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2352
            _(_representations).each(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2353
                _this.removeRepresentation(_repr);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2354
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2355
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2356
        highlightModel: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2357
            var _repr = this.getRepresentationByModel(_model);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2358
            if (_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2359
                _repr.highlight();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2360
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2361
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2362
        unhighlightAll: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2363
            _(this.representations).each(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2364
                _repr.unhighlight();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2365
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2366
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2367
        unselectAll: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2368
            _(this.representations).each(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2369
                _repr.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2370
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2371
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2372
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2373
            _(this.representations).each(function(_representation) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2374
                _representation.redraw(true);
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  2375
            });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2376
            if (this.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2377
                this.redrawMiniframe();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2378
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2379
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2380
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2381
        addTempEdge: function(_from, _point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2382
            var _tmpEdge = this.addRepresentation("TempEdge",null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2383
            _tmpEdge.end_pos = _point;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2384
            _tmpEdge.from_representation = _from;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2385
            _tmpEdge.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2386
            this.click_target = _tmpEdge;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2387
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2388
        findTarget: function(_hitResult) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2389
            if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2390
                var _newTarget = _hitResult.item.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2391
                if (this.selected_target !== _hitResult.item.__representation) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2392
                    if (this.selected_target) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2393
                        this.selected_target.unselect(_newTarget);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2394
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2395
                    _newTarget.select(this.selected_target);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2396
                    this.selected_target = _newTarget;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2397
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2398
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2399
                if (this.selected_target) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2400
                    this.selected_target.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2401
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2402
                this.selected_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2403
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2404
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2405
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2406
            this.offset = this.offset.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2407
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2408
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2409
        onMouseMove: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2410
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2411
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2412
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2413
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2414
                                      ]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2415
                                      _delta = _point.subtract(this.last_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2416
            this.last_point = _point;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2417
            if (!this.is_dragging && this.mouse_down && _delta.length > _MIN_DRAG_DISTANCE) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2418
                this.is_dragging = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2419
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2420
            var _hitResult = paper.project.hitTest(_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2421
            if (this.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2422
                if (this.click_target && typeof this.click_target.paperShift === "function") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2423
                    this.click_target.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2424
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2425
                    this.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2426
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2427
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2428
                this.findTarget(_hitResult);
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
  2429
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2430
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2431
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2432
        onMouseDown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2433
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2434
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2435
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2436
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2437
                                      ]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2438
            this.last_point = _point;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2439
            this.mouse_down = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2440
            if (!this.click_target || this.click_target.type !== "Temp-edge") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2441
                this.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2442
                this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2443
                var _hitResult = paper.project.hitTest(_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2444
                if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2445
                    this.click_target = _hitResult.item.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2446
                    this.click_target.mousedown(_event, _isTouch);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2447
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2448
                    this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2449
                    if (this.isEditable() && this.click_mode === _CLICKMODE_ADDNODE) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2450
                        var _coords = this.toModelCoords(_point),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2451
                        _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2452
                            id: Rkns.Utils.getUID('node'),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2453
                            created_by: this.renkan.current_user,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2454
                            position: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2455
                                x: _coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2456
                                y: _coords.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2457
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2458
                        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2459
                        _node = this.renkan.project.addNode(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2460
                        this.getRepresentationByModel(_node).openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2461
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2462
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2463
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2464
            if (this.click_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2465
                if (this.isEditable() && this.click_mode === _CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2466
                    this.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2467
                    this.addTempEdge(this.click_target, _point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2468
                    this.click_mode = _CLICKMODE_ENDEDGE;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2469
                    this.notif_$.fadeOut(function() {
277
1a54f4e626df correct _renkan reference
ymh <ymh.work@gmail.com>
parents: 276
diff changeset
  2470
                        $(this).html(this.renkan.translate("Click on a second node to complete the edge")).fadeIn();
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2471
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2472
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2473
                    this.notif_$.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2474
                    this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2475
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2476
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2477
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2478
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2479
        onMouseUp: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2480
            this.mouse_down = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2481
            if (this.click_target) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2482
                var _off = this.canvas_$.offset();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2483
                this.click_target.mouseup(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2484
                        {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2485
                            point: new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2486
                                                    _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2487
                                                    _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2488
                                                    ])
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2489
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2490
                        _isTouch
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2491
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2492
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2493
                this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2494
                this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2495
                if (_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2496
                    this.unselectAll();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2497
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2498
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2499
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2500
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2501
        onScroll: function(_event, _scrolldelta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2502
            this.totalScroll += _scrolldelta;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2503
            if (Math.abs(this.totalScroll) >= 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2504
                var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2505
                _delta = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2506
                                          _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2507
                                          _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2508
                                          ]).subtract(this.offset).multiply( Math.SQRT2 - 1 );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2509
                if (this.totalScroll > 0) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2510
                    this.setScale( this.scale * Math.SQRT2, this.offset.subtract(_delta) );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2511
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2512
                    this.setScale( this.scale * Math.SQRT1_2, this.offset.add(_delta.divide(Math.SQRT2)));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2513
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2514
                this.totalScroll = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2515
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2516
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2517
        onDoubleClick: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2518
            if (!this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2519
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2520
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2521
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2522
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2523
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2524
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2525
                                      ]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2526
            var _hitResult = paper.project.hitTest(_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2527
            if (this.isEditable() && (!_hitResult || typeof _hitResult.item.__representation === "undefined")) {
153
7fcb35795ff4 Now showing images in publish tooltips
veltr
parents: 152
diff changeset
  2528
                var _coords = this.toModelCoords(_point),
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2529
                _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2530
                    id: Rkns.Utils.getUID('node'),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2531
                    created_by: this.renkan.current_user,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2532
                    position: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2533
                        x: _coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2534
                        y: _coords.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2535
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2536
                },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2537
                _node = this.renkan.project.addNode(_data);
36
d249d36ecc37 Add Edge button, French translation and various bugfixes
veltr
parents: 35
diff changeset
  2538
                this.getRepresentationByModel(_node).openEditor();
d249d36ecc37 Add Edge button, French translation and various bugfixes
veltr
parents: 35
diff changeset
  2539
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2540
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2541
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2542
        defaultDropHandler: function(_data) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2543
            var newNode = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2544
            switch(_data["text/x-iri-specific-site"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2545
            case "twitter":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2546
                var snippet = $('<div>').html(_data["text/x-iri-selected-html"]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2547
                tweetdiv = snippet.find(".tweet");
277
1a54f4e626df correct _renkan reference
ymh <ymh.work@gmail.com>
parents: 276
diff changeset
  2548
                newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name");
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2549
                newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2550
                newNode.image = tweetdiv.find(".avatar").attr("src");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2551
                newNode.description = tweetdiv.find(".js-tweet-text:first").text();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2552
                break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2553
            case "google":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2554
                var snippet = $('<div>').html(_data["text/x-iri-selected-html"]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2555
                newNode.title = snippet.find("h3:first").text().trim();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2556
                newNode.uri = snippet.find("h3 a").attr("href");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2557
                newNode.description = snippet.find(".st:first").text().trim();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2558
                break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2559
            case undefined:
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2560
            default:
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2561
                if (_data["text/x-iri-source-uri"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2562
                    newNode.uri = _data["text/x-iri-source-uri"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2563
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2564
                if (_data["text/plain"] || _data["text/x-iri-selected-text"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2565
                    newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2566
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2567
                if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2568
                    var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2569
                    var _svgimgs = snippet.find("image");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2570
                    if (_svgimgs.length) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2571
                        newNode.image = _svgimgs.attr("xlink:href");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2572
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2573
                    var _svgpaths = snippet.find("path");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2574
                    if (_svgpaths.length) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2575
                        newNode.clipPath = _svgpaths.attr("d");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2576
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2577
                    var _imgs = snippet.find("img");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2578
                    if (_imgs.length) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2579
                        newNode.image = _imgs[0].src;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2580
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2581
                    var _as = snippet.find("a");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2582
                    if (_as.length) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2583
                        newNode.uri = _as[0].href;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2584
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2585
                    newNode.title = snippet.find("[title]").attr("title") || newNode.title;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2586
                    newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2587
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2588
                if (_data["text/uri-list"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2589
                    newNode.uri = _data["text/uri-list"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2590
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2591
                if (_data["text/x-moz-url"] && !newNode.title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2592
                    newNode.title = (_data["text/x-moz-url"].split("\n")[1] || "").trim();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2593
                    if (newNode.title === newNode.uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2594
                        newNode.title = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2595
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2596
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2597
                if (_data["text/x-iri-source-title"] && !newNode.title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2598
                    newNode.title = _data["text/x-iri-source-title"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2599
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2600
                if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2601
                    var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2602
                    newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2603
                    newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2604
                    newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2605
                    newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2606
                    newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2607
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2608
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2609
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2610
            if(typeof this.renkan.options.drop_enhancer === "function"){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2611
                newNode = this.renkan.options.drop_enhancer(newNode, _data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2612
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2613
            return newNode;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2614
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2615
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2616
        dropData: function(_data, _event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2617
            if (!this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2618
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2619
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2620
            if (_data["text/json"] || _data["application/json"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2621
                try {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2622
                    var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2623
                    _(_data).extend(jsondata);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2624
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2625
                catch(e) {}
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2626
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2627
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2628
            var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2629
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2630
            if (!newNode.title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2631
                newNode.title = this.renkan.translate("Dragged resource");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2632
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2633
            var fields = ["title", "description", "uri", "image"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2634
            for (var i = 0; i < fields.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2635
                var f = fields[i];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2636
                if (_data["text/x-iri-" + f] || _data[f]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2637
                    newNode[f] = _data["text/x-iri-" + f] || _data[f];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2638
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2639
                if (newNode[f] === "none" || newNode[f] === "null") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2640
                    newNode[f] = undefined;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2641
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2642
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2643
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2644
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2645
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2646
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2647
                                      ]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2648
                                      _coords = this.toModelCoords(_point),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2649
                                      _nodedata = {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 21
diff changeset
  2650
                id: Rkns.Utils.getUID('node'),
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 21
diff changeset
  2651
                created_by: this.renkan.current_user,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2652
                uri: newNode.uri || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2653
                title: newNode.title || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2654
                description: newNode.description || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2655
                image: newNode.image || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2656
                color: newNode.color || undefined,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2657
                clip_path: newNode.clipPath || undefined,
8
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2658
                position: {
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2659
                    x: _coords.x,
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2660
                    y: _coords.y
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2661
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2662
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2663
            var _node = this.renkan.project.addNode(_nodedata),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2664
            _repr = this.getRepresentationByModel(_node);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2665
            if (_event.type === "drop") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2666
                _repr.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2667
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2668
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2669
        fullScreen: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2670
            var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2671
            _el = this.renkan.$[0],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2672
            _requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2673
            _cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2674
            if (_isFull) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2675
                for (var i = 0; i < _cancelMethods.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2676
                    if (typeof document[_cancelMethods[i]] === "function") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2677
                        document[_cancelMethods[i]]();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2678
                        break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2679
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2680
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2681
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2682
                for (var i = 0; i < _requestMethods.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2683
                    if (typeof _el[_requestMethods[i]] === "function") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2684
                        _el[_requestMethods[i]]();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2685
                        break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2686
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2687
                }
155
7d5f722d76b2 iPad compatibility
veltr
parents: 154
diff changeset
  2688
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2689
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2690
        zoomOut: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2691
            var _newScale = this.scale * Math.SQRT1_2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2692
            _offset = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2693
                                       this.canvas_$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2694
                                       this.canvas_$.height()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2695
                                       ]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 ));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2696
            this.setScale( _newScale, _offset );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2697
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2698
        zoomIn: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2699
            var _newScale = this.scale * Math.SQRT2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2700
            _offset = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2701
                                       this.canvas_$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2702
                                       this.canvas_$.height()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2703
                                       ]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 ));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2704
            this.setScale( _newScale, _offset );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2705
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2706
        addNodeBtn: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2707
            if (this.click_mode === _CLICKMODE_ADDNODE) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2708
                this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2709
                this.notif_$.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2710
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2711
                this.click_mode = _CLICKMODE_ADDNODE;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2712
                this.notif_$.text(this.renkan.translate("Click on the background canvas to add a node")).fadeIn();
190
a9040a7c47d9 Some changes for standalone app compatibility
veltr
parents: 189
diff changeset
  2713
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2714
            return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2715
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2716
        addEdgeBtn: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2717
            if (this.click_mode === _CLICKMODE_STARTEDGE || this.click_mode === _CLICKMODE_ENDEDGE) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2718
                this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2719
                this.notif_$.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2720
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2721
                this.click_mode = _CLICKMODE_STARTEDGE;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2722
                this.notif_$.text(this.renkan.translate("Click on a first node to start the edge")).fadeIn();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2723
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2724
            return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2725
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2726
        foldBins: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2727
            var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2728
            bins = this.renkan.$.find(".Rk-Bins");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2729
            if (bins.offset().left < 0) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2730
                bins.animate({left: 0},250);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2731
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2732
                this.$.animate({left: 300},250,function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2733
                    var w = _this.$.width();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2734
                    paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2735
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2736
                foldBinsButton.html("&laquo;");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2737
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2738
                bins.animate({left: -300},250);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2739
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2740
                this.$.animate({left: 0},250,function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2741
                    var w = _this.$.width();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2742
                    paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2743
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2744
                foldBinsButton.html("&raquo;");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2745
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2746
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2747
        save: function() { },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2748
        open: function() { }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2749
    });
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  2750
})(window);
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
  2751
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
  2752
/* END paper-renderer.js */