Commit 85d41ead authored by techird's avatar techird

fix select color issue

parent 1be05c9b
( function ( utils ) {
(function(utils) {
var content = '<div class="image-content" style="padding:20px;width:360px;">';
content += '<style>';
content += '.kmui-dialog-<%= container %> input{';
......@@ -36,39 +36,39 @@
KM.registerWidget( 'image', {
KM.registerWidget('image', {
tpl: content,
initContent: function ( km ) {
var lang = km.getLang( 'dialogs.image' ),
initContent: function(km) {
var lang = km.getLang('dialogs.image'),
html;
if ( lang ) {
html = $.parseTmpl( this.tpl, utils.extend( {
if (lang) {
html = $.parseTmpl(this.tpl, utils.extend({
'container': 'image'
}, lang ) );
}, lang));
}
this.root().html( html );
this.root().html(html);
},
initEvent: function ( km, $w ) {
$w.find( '#image_insert' ).on( 'click', function () {
km.execCommand( 'image', $w.find( '#image_href' ).val() );
initEvent: function(km, $w) {
$w.find('#image_insert').on('click', function() {
km.execCommand('image', $w.find('#image_href').val());
$w.kmui().hide();
} );
$w.find( '#image_href' ).on( 'keydown', function ( e ) {
if ( e.keyCode === 13 ) {
km.execCommand( 'image', $w.find( '#image_href' ).val() );
});
$w.find('#image_href').on('keydown', function(e) {
if (e.keyCode === 13) {
km.execCommand('image', $w.find('#image_href').val());
$w.kmui().hide();
}
} ).on('input', function() {
$w.find('#image_preview').attr('src', $w.find( '#image_href' ).val());
}).on('input', function() {
$w.find('#image_preview').attr('src', $w.find('#image_href').val());
});
var url = km.queryCommandValue( 'image' );
var $input = $w.find( '#image_href' );
$input.val( url || 'http://' );
if(url) $w.find('#image_preview').attr('src', url);
setTimeout( function () {
var url = km.queryCommandValue('image');
var $input = $w.find('#image_href');
$input.val(url || 'http://');
if (url) $w.find('#image_preview').attr('src', url);
setTimeout(function() {
$input.focus();
} );
});
},
width: 400
} );
} )( KM.Utils );
\ No newline at end of file
});
})(KM.Utils);
\ No newline at end of file
Subproject commit 0d9f7dcd784436d13e45b4570ce690e186f3c686
Subproject commit 9e420efd89ba672f5389e21069eb0009e52ad7b1
......@@ -24,12 +24,6 @@ var Renderer = KityMinder.Renderer = kity.createClass('Renderer', {
}
});
kity.extendClass(MinderNode, {
getContentBox: function() {
return this._contentBox;
}
});
kity.extendClass(Minder, {
_createRendererForNode: function(node) {
......@@ -122,17 +116,7 @@ kity.extendClass(MinderNode, {
return null;
},
getContentBox: function() {
return this.parent && this.parent.isCollapsed() ? {
x: 0,
y: 0,
width: 0,
height: 0,
left: 0,
top: 0,
bottom: 0,
right: 0,
cx: 0,
cy: 0
} : this._contentBox;
//if (!this._contentBox) this.render();
return this.parent && this.parent.isCollapsed() ? new kity.Box() : this._contentBox;
}
});
\ No newline at end of file
......@@ -179,7 +179,7 @@ KityMinder.registerModule('TextEditModule', function() {
if (browser.ipad) {
receiver.container.focus();
}
}else{
} else {
//当选中节点后,输入状态准备
var node = e.getTargetNode();
if (node) {
......
......@@ -4,7 +4,10 @@ KityMinder.registerModule("fontmodule", function() {
}
KityMinder.TextRenderer.registerStyleHook(function(node, text) {
text.fill(getNodeDataOrStyle(node, 'color'));
var dataColor = node.getData('color');
var selectedColor = node.getStyle('selected-color');
var styleColor = node.getStyle('color');
text.fill(dataColor || (node.isSelected() ? selectedColor : styleColor));
text.setFont({
family: getNodeDataOrStyle(node, 'font-family'),
size: getNodeDataOrStyle(node, 'font-size')
......
KityMinder.registerModule( "image", function () {
function loadImageSize( url, callback ) {
var img = document.createElement( 'img' );
img.onload = function () {
callback( img.width, img.height );
KityMinder.registerModule('image', function() {
function loadImageSize(url, callback) {
var img = document.createElement('img');
img.onload = function() {
callback(img.width, img.height);
};
img.onerror = function () {
callback( null );
img.onerror = function() {
callback(null);
};
img.src = url;
}
function fitImageSize( width, height, maxWidth, maxHeight ) {
function fitImageSize(width, height, maxWidth, maxHeight) {
var ratio = width / height,
fitRatio = maxWidth / maxHeight;
// 宽高比大于最大尺寸的宽高比,以宽度为标准适应
if ( ratio > fitRatio && width > maxWidth ) {
if (ratio > fitRatio && width > maxWidth) {
width = maxWidth;
height = maxWidth / ratio;
} else if(height > maxHeight) {
} else if (height > maxHeight) {
height = maxHeight;
width = maxHeight / ratio;
}
......@@ -28,104 +28,110 @@ KityMinder.registerModule( "image", function () {
height: height
};
}
return {
"defaultOptions": {
"maxImageWidth": 200,
"maxImageHeight": 200
},
"commands": {
"image": kity.createClass( "ImageCommand", {
var ImageCommand = kity.createClass('ImageCommand', {
base: Command,
execute: function ( km, url ) {
execute: function(km, url) {
var nodes = km.getSelectedNodes();
loadImageSize( url, function ( width, height ) {
if ( !width ) return;
utils.each( nodes, function ( i, n ) {
n.setData( 'image', url );
n.setData( 'imageWidth', width );
n.setData( 'imageHeight', height );
km.updateLayout( n );
} );
} );
loadImageSize(url, function(width, height) {
if (!width) return;
utils.each(nodes, function(i, n) {
n.setData('image', url);
n.setData('imageWidth', width);
n.setData('imageHeight', height);
n.render();
});
km.layout();
});
},
queryState: function ( km ) {
queryState: function(km) {
var nodes = km.getSelectedNodes(),
result = 0;
if ( nodes.length === 0 ) {
if (nodes.length === 0) {
return -1;
}
utils.each( nodes, function ( i, n ) {
if ( n && n.getData( 'image' ) ) {
utils.each(nodes, function(i, n) {
if (n && n.getData('image')) {
result = 0;
return false;
}
} );
});
return result;
},
queryValue: function ( km ) {
queryValue: function(km) {
var node = km.getSelectedNode();
return node.getData( 'image' );
return node.getData('image');
}
} ),
"removeimage": kity.createClass( "RemoveImageCommand", {
});
var RemoveImageCommand = kity.createClass('RemoveImageCommand', {
base: Command,
execute: function ( km ) {
execute: function(km) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'image' );
km.updateLayout( n );
} );
utils.each(nodes, function(i, n) {
n.setData('image');
km.updateLayout(n);
});
},
queryState: function ( km ) {
queryState: function(km) {
var nodes = km.getSelectedNodes();
if ( nodes.length == 0 ) {
if (nodes.length === 0) {
return -1;
}
var image = false;
utils.each( nodes, function ( i, n ) {
if ( n.getData( 'image' ) ) {
utils.each(nodes, function(i, n) {
if (n.getData('image')) {
image = true;
return false;
}
} );
if ( image ) {
});
if (image) {
return 0;
}
return -1;
}
} )
});
return {
'defaultOptions': {
'maxImageWidth': 200,
'maxImageHeight': 200
},
'commands': {
'image': ImageCommand,
'removeimage': RemoveImageCommand
},
"events": {
"RenderNodeTop": function ( e ) {
'events': {
'RenderNodeTop': function(e) {
var node = e.node,
url = node.getData( 'image' );
url = node.getData('image');
var link, img, size, currentBox;
if ( url ) {
if (url) {
size = fitImageSize(
node.getData( 'imageWidth' ),
node.getData( 'imageHeight' ),
this.getOptions( 'maxImageWidth' ),
this.getOptions( 'maxImageHeight' ) );
node.getData('imageWidth'),
node.getData('imageHeight'),
this.getOptions('maxImageWidth'),
this.getOptions('maxImageHeight'));
img = new kity.Image( url, size.width, size.height );
img = new kity.Image(url, size.width, size.height);
link = new kity.HyperLink( url );
link.addShape( img );
link.setTarget( '_blank' );
link.setStyle( 'cursor', 'pointer' );
link = new kity.HyperLink(url);
link.addShape(img);
link.setTarget('_blank');
link.setStyle('cursor', 'pointer');
currentBox = node.getContRc().getBoundaryBox();
node.getContRc().addShape( link.setTranslate( 0, currentBox.y - size.height ) );
node.getContRc().addShape(link.setTranslate(0, currentBox.y - size.height));
}
}
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
......@@ -32,6 +32,7 @@ KityMinder.registerTheme('default', {
'connect-radius': 5,
'selected-background': 'rgb(254, 219, 0)',
'selected-color': 'black',
'drop-hint-color': 'yellow',
'sub-drop-hint-width': 2,
......
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