Commit 536daed8 authored by techird's avatar techird

merge

parents bfad6015 c658355d
......@@ -61,6 +61,7 @@ $dependency = Array(
,'src/adapter/saveto.js'
,'src/adapter/view.js'
,'src/adapter/dialog.js'
,'src/adapter/tooltips.js'
,'src/protocal/plain.js'
,'src/protocal/json.js'
);
......
utils.extend( KityMinder, function () {
var _kityminderUI = {},
_kityminderToolbarUI ={},
_activeWidget = null,
_widgetData = {},
_widgetCallBack = {};
......@@ -9,6 +10,16 @@ utils.extend( KityMinder, function () {
_kityminderUI[ name ] = fn;
} )
},
registerToolbarUI: function ( uiname, fn ) {
utils.each( uiname.split( /\s+/ ), function ( i, name ) {
_kityminderToolbarUI[ name ] = fn;
} )
},
loadUI:function(km){
utils.each( _kityminderUI, function ( i, fn ) {
fn.call(km)
} )
},
_createUI: function ( id ) {
var $cont = $( '<div class="kmui-container"></div>' ),
$toolbar = $.kmuitoolbar(),
......@@ -17,6 +28,7 @@ utils.extend( KityMinder, function () {
$cont.append( $toolbar ).append( $kmbody ).append( $statusbar );
$( utils.isString( id ) ? '#' + id : id ).append( $cont );
return {
'$container': $cont,
'$toolbar': $toolbar,
......@@ -33,8 +45,8 @@ utils.extend( KityMinder, function () {
if ( name == '|' ) {
$.kmuiseparator && btns.push( $.kmuiseparator() );
} else {
if ( _kityminderUI[ name ] ) {
var ui = _kityminderUI[ name ].call( km, name );
if ( _kityminderToolbarUI[ name ] ) {
var ui = _kityminderToolbarUI[ name ].call( km, name );
ui && btns.push( ui );
}
......@@ -55,6 +67,8 @@ utils.extend( KityMinder, function () {
this._createToolbar( containers.$toolbar, km );
this._createStatusbar( containers.$statusbar, km );
km.$container = containers.$container;
this.loadUI(km);
return km.fire( 'interactchange' );
},
registerWidget: function ( name, pro, cb ) {
......
KM.registerUI( 'bold italic redo undo',
KM.registerToolbarUI( 'bold italic redo undo',
function ( name ) {
var me = this;
var $btn = $.kmuibutton( {
......
KM.registerUI( 'layoutstyle fontfamily fontsize', function ( name ) {
KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
......@@ -130,7 +130,7 @@ KM.registerUI( 'layoutstyle fontfamily fontsize', function ( name ) {
} );
KM.registerUI( 'forecolor', function ( name ) {
KM.registerToolbarUI( 'forecolor', function ( name ) {
function getCurrentColor() {
return $colorLabel.css( 'background-color' );
}
......
KM.registerUI( 'markers', function ( name ) {
KM.registerToolbarUI( 'markers', function ( name ) {
var me = this,
currentRange, $dialog,
......
function zoom( paper, rate ) {
var viewbox = paper.getViewBox();
var zoomValue = paper._zoom || 1;
var w = viewbox.width,
h = viewbox.height,
x = viewbox.x,
y = viewbox.y;
var ww = w * rate,
hh = h * rate,
xx = x + ( w - ww ) / 2,
yy = y + ( h - hh ) / 2;
var animator = new kity.Animator( {
beginValue: viewbox,
finishValue: {
width: ww,
height: hh,
x: xx,
y: yy
},
setter: function ( target, value ) {
target.setViewBox( value.x, value.y, value.width, value.height );
}
} );
animator.start( paper, 100, 'ease' );
paper._zoom = zoomValue *= rate;
return zoomValue;
}
KM.registerToolbarUI( 'hand zoom-in zoom-out',
function ( name ) {
var me = this;
var $btn = $.kmuibutton( {
icon: name,
click: {
'hand': function ( e ) {
var drag = me._onDragMode = !me._onDragMode;
me._paper.setStyle( 'cursor', drag ? 'pointer' : 'default' );
me._paper.setStyle( 'cursor', drag ? '-webkit-grab' : 'default' );
$btn.kmui().active( drag );
if ( drag ) {
me._paper.drag();
} else {
me._paper.undrag();
}
},
'zoom-in': function ( e ) {
var value = zoom( me.getPaper(), 0.707 );
me.fire( 'zoom', {
zoom: value
} );
},
'zoom-out': function ( e ) {
var value = zoom( me.getPaper(), 1 / 0.707 );
me.fire( 'zoom', {
zoom: value
} );
}
}[ name ],
title: this.getLang( 'tooltips.' )[ name ] || ''
} );
switch ( name ) {
case 'hand':
me.on( 'beforemousemove', function ( e ) {
if ( this._onDragMode ) {
e.stopPropagation();
}
} );
me.on('keyup', function(e) {
if(e.keyCode == keymap.Space && me.getSelectedNodes().length == 0) {
$btn.click();
e.preventDefault();
}
});
kity.extendClass( kity.Paper, kity.Draggable );
break;
case 'zoom-in':
me.on( 'zoom', function ( e ) {
$btn.kmui().disabled( e.zoom <= 0.5 );
} );
break;
case 'zoom-out':
me.on( 'zoom', function ( e ) {
$btn.kmui().disabled( e.zoom >= 2 );
} );
me.on( 'mousewheel', function ( e ) {
var delta = e.originEvent.wheelDelta;
if ( Math.abs( delta ) > 100 ) {
clearTimeout( me._wheelZoomTimeout );
} else {
return;
}
me._wheelZoomTimeout = setTimeout( function () {
var value;
var lastValue = me.getPaper()._zoom || 1;
if ( delta < 0 && lastValue > 0.5 ) {
value = zoom( me.getPaper(), 0.707 );
me.fire( 'zoom', {
zoom: value
} );
} else if ( delta > 0 && lastValue < 2 ) {
value = zoom( me.getPaper(), 1 / 0.707 );
me.fire( 'zoom', {
zoom: value
} );
}
}, 100 );
e.originEvent.preventDefault();
} );
}
return $btn;
}
);
\ No newline at end of file
KM.registerUI( 'saveto', function ( name ) {
KM.registerToolbarUI( 'saveto', function ( name ) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
......
KM.registerUI( 'tooltips',
function ( name ) {
var km = this;
//添加tooltip;
if($.kmuitooltip){
$("[data-original-title]",km.$container).each(function(i,n){
var tooltips = km.getLang('tooltips');
var tooltip = $(n).data('original-title');
utils.each(tooltips,function(v,k){
if(k == tooltip && km.getShortcutKey(v)){
$(n).attr('data-original-title',tooltip + ' (' + km.getShortcutKey(v).toUpperCase() + ')');
}
})
});
$.kmuitooltip('attachTo', $("[data-original-title]",km.$container)).css('z-index',km.getOptions('zIndex')+1);
}
km.$container.find('a').click(function(evt){
evt.preventDefault()
});
}
);
\ No newline at end of file
......@@ -70,13 +70,19 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._bindshortcutKeys();
},
addShortcutKeys: function ( cmd, keys ) {
var obj = {};
var obj = {},km = this;
if ( keys ) {
obj[ cmd ] = keys
} else {
obj = cmd;
}
utils.extend( this._shortcutkeys, obj )
utils.each(obj,function(k,v){
km._shortcutkeys[k.toLowerCase()] = v;
});
},
getShortcutKey : function(cmdName){
return this._shortcutkeys[cmdName]
},
_bindshortcutKeys: function () {
var me = this,
......
......@@ -134,6 +134,9 @@ KityMinder.registerModule( "TextEditModule", function () {
}
},
'selectionclear':function(){
receiver.setTextEditStatus(false).clear()
}
}
};
......
......@@ -2,7 +2,7 @@
Minder.Receiver = kity.createClass('Receiver',{
clear : function(){
this.container.innerHTML = '';
this.selection.setHide();
this.selection && this.selection.setHide();
this.index = 0;
return this;
},
......@@ -127,16 +127,24 @@ Minder.Receiver = kity.createClass('Receiver',{
//更新模拟选区的范围
this.selection.setStartOffset(this.index).collapse(true);
if(this.index == this.textData.length){
if(this.index == 0){
this.selection.setPosition(this.getBaseOffset())
}else{
this.selection.setPosition({
x : this.textData[this.index-1].x + this.textData[this.index-1].width,
y : this.textData[this.index-1].y
})
}
}else{
this.selection.setPosition(this.textData[this.index])
}
return this;
},
getBaseOffset:function(){
return this.textShape.getRenderBox('top');
},
setBaseOffset :function(){
this.offset = this.textShape.getRenderBox('top');
return this;
......
......@@ -224,7 +224,7 @@ KityMinder.registerModule( "LayoutBottom", function () {
return ( selfWidth > childWidth ? selfWidth : childWidth );
};
if ( nodeType === "root" ) {
Layout.x = getMinderSize().width / 2;
Layout.x = getMinderSize().width / 2 - node.getRenderContainer().getWidth() / 2;
effectSet.push( node );
} else {
if ( action === "append" || action === "contract" ) {
......@@ -427,6 +427,8 @@ KityMinder.registerModule( "LayoutBottom", function () {
}
},
appendChildNode: function ( parent, node, sibling ) {
minder.handelNodeInsert( node );
node.clearLayout();
//设置分支类型
if ( parent.getType() === "root" ) {
node.setType( "main" );
......@@ -443,8 +445,8 @@ KityMinder.registerModule( "LayoutBottom", function () {
node: node
}, false ) );
updateShapeByCont( node );
var set1 = updateLayoutVertical( node, parent, "append" );
var set2 = updateLayoutHorizon( node );
var set2 = updateLayoutHorizon( node, parent, "append" );
var set1 = updateLayoutVertical( node );
var set = uSet( set1, set2 );
for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] );
......
......@@ -53,9 +53,10 @@ KityMinder.registerModule( "LayoutDefault", function () {
var nodeShape = node.getRenderContainer();
var nodeX, nodeY = ( node.getType() === "main" ? Layout.y : ( Layout.y + nodeShape.getHeight() / 2 - 5 ) );
if ( Layout.appendside === "left" ) {
nodeX = nodeShape.getRenderBox().closurePoints[ 1 ].x - 6;
nodeX = nodeShape.getRenderBox().closurePoints[ 1 ].x - 5;
} else {
nodeX = nodeShape.getRenderBox().closurePoints[ 0 ].x + 6;
if ( node.getType() === "main" ) nodeX -= 3;
}
this.shape.setTransform( new kity.Matrix().translate( nodeX, nodeY ) );
},
......@@ -340,7 +341,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
var endPosV = endPos.getVertex();
sPos.setVertex( rootX, rootY );
connect.bezier.setPoints( [ sPos, endPos ] ).stroke( nodeStyle.stroke );
connect.circle.setCenter( endPosV.x + ( Layout.appendside === "left" ? 1 : -1.5 ), endPosV.y ).fill( "white" ).setRadius( 4 );
connect.circle.setCenter( endPosV.x + ( Layout.appendside === "left" ? -0.5 : -1.5 ), endPosV.y ).fill( "white" ).setRadius( 4 );
} else if ( nodeType === "sub" ) {
if ( !Layout.connect ) {
connect = Layout.connect = new kity.Path();
......
......@@ -44,9 +44,11 @@ KM.ui.define( 'modal', {
$( this ).toggleClass( 'kmui-hover' )
} );
setTimeout(function() {
$('.kmui-modal').draggable({ handle: '.kmui-modal-header' });
}, 100);
setTimeout( function () {
$( '.kmui-modal' ).draggable( {
handle: '.kmui-modal-header'
} );
}, 100 );
},
toggle: function () {
var me = this;
......@@ -71,7 +73,9 @@ KM.ui.define( 'modal', {
.trigger( 'aftershow' );
} );
$('.kmui-modal').draggable({ handle: '.kmui-modal-header' });
$( '.kmui-modal' ).draggable( {
handle: '.kmui-modal-header'
} );
},
showTip: function ( text ) {
$( '.kmui-modal-tip', this.root() ).html( text ).fadeIn();
......
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