Commit 3a14ba9e authored by campaign's avatar campaign

重构hyperlink

parent aa0c2a52
...@@ -9,9 +9,9 @@ KityMinder.registerModule( "hyperlink", function () { ...@@ -9,9 +9,9 @@ KityMinder.registerModule( "hyperlink", function () {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) { utils.each( nodes, function ( i, n ) {
n.setData( 'hyperlink', url ); n.setData( 'hyperlink', url );
km.updateLayout( n ); n.render();
} ); } );
km.layout();
}, },
queryState: function ( km ) { queryState: function ( km ) {
var nodes = km.getSelectedNodes(), var nodes = km.getSelectedNodes(),
...@@ -39,8 +39,9 @@ KityMinder.registerModule( "hyperlink", function () { ...@@ -39,8 +39,9 @@ KityMinder.registerModule( "hyperlink", function () {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) { utils.each( nodes, function ( i, n ) {
n.setData( 'hyperlink' ); n.setData( 'hyperlink' );
km.updateLayout( n ); n.render();
} ); } );
km.layout();
}, },
queryState: function ( km ) { queryState: function ( km ) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
...@@ -62,33 +63,54 @@ KityMinder.registerModule( "hyperlink", function () { ...@@ -62,33 +63,54 @@ KityMinder.registerModule( "hyperlink", function () {
} }
} ) } )
}, },
"events": { 'renderers': {
"RenderNodeRight": function ( e ) { right: kity.createClass('hyperlinkrender', {
var node = e.node, base: KityMinder.Renderer,
url = node.getData( 'hyperlink' );
if ( url ) { create: function(node) {
var link = new kity.HyperLink( url );
var link = new kity.HyperLink();
var linkshape = new kity.Path(); var linkshape = new kity.Path();
var outline = new kity.Rect(24, 22, -2, -6, 4).fill('rgba(255, 255, 255, 0)'); var outline = new kity.Rect(24, 22, -2, -6, 4).fill('rgba(255, 255, 255, 0)');
var box = node.getContRc().getBoundaryBox();
var style = this.getCurrentLayoutStyle()[ node.getType() ];
linkshape.setPathData( linkShapePath ).fill( '#666' ); linkshape.setPathData( linkShapePath ).fill( '#666' );
link.setAttr('xlink:title', url);
link.addShape( outline ); link.addShape( outline );
link.addShape( linkshape ); link.addShape( linkshape );
link.setTarget( '_blank' ); link.setTarget( '_blank' );
link.setStyle( 'cursor', 'pointer' ); link.setStyle( 'cursor', 'pointer' );
node.getContRc().addShape( link.setTranslate( box.x + box.width + style.spaceLeft + 5, -5 ) );
link.on('mouseover', function() { link.on('mouseover', function() {
outline.fill('rgba(255, 255, 200, .8)'); outline.fill('rgba(255, 255, 200, .8)');
}).on('mouseout', function() { }).on('mouseout', function() {
outline.fill('rgba(255, 255, 255, 0)'); outline.fill('rgba(255, 255, 255, 0)');
}); });
return link;
},
shouldRender: function(node) {
return node.getData( 'hyperlink' );
},
update: function(link, node, box) {
var href = node.getData('hyperlink');
link.setHref(href);
link.setAttr('xlink:title', href);
var spaceRight = node.getStyle('space-right');
link.setTranslate(box.right + spaceRight + 2, -5);
return {
x: box.right + spaceRight,
y: -11,
width: 24,
height: 22
};
} }
} })
} }
}; };
} ); } );
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment