Commit 1926eda1 authored by techird's avatar techird

animate switcher

parent 32ddd2cd
......@@ -26,7 +26,7 @@ module.exports = function(grunt) {
' * ====================================================\n' +
' */\n\n';
var expose = '\nuse(\'expose\');\n';
var expose = '\nuse(\'expose-kityminder\');\n';
// Project configuration.
grunt.initConfig({
......@@ -42,7 +42,7 @@ module.exports = function(grunt) {
dependence: {
options: {
base: 'src',
entrance: 'expose'
entrance: 'expose-kityminder'
},
merge: {
files: [{
......
/**
* @fileOverview
*
* 动画控制
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
define(function(require, exports, module) {
var Minder = require('./minder');
var animateDefaultOptions = {
layoutAnimationDuration: 300,
viewAnimationDuration: 100,
zoomAnimationDuration: 300
};
var resoredAnimationOptions = {};
Minder.registerInitHook(function() {
this.setDefaultOptions(animateDefaultOptions);
});
Minder.prototype.enableAnimation = function() {
for (var name in animateDefaultOptions) {
if (animateDefaultOptions.hasOwnProperty(name)) {
this.setOption(resoredAnimationOptions[name]);
}
}
};
Minder.prototype.disableAnimation = function() {
for (var name in animateDefaultOptions) {
if (animateDefaultOptions.hasOwnProperty(name)) {
resoredAnimationOptions[name] = this.getOption(name);
this.setOption(name, 0);
}
}
};
});
\ No newline at end of file
......@@ -10,7 +10,7 @@ define(function(require, exports, module) {
}
Minder.registerInitHook(function(option) {
this.addDefaultOption({
this.setDefaultOptions({
enableKeyReceiver: true
});
if (this.getOption('enableKeyReceiver')) {
......
......@@ -219,9 +219,9 @@ define(function(require, exports, module) {
return this;
},
layout: function(name, duration) {
layout: function(name) {
this.setLayout(name).getMinder().layout(duration);
this.setLayout(name).getMinder().layout();
return this;
},
......@@ -398,7 +398,9 @@ define(function(require, exports, module) {
*/
kity.extendClass(Minder, {
layout: function(duration) {
layout: function() {
var duration = this.getOption('layoutAnimationDuration');
this.getRoot().traverse(function(node) {
// clear last results
......@@ -428,8 +430,6 @@ define(function(require, exports, module) {
// 第二轮布局
layoutNode(this.getRoot(), 2);
duration = duration ? 300 : 0;
var minder = this;
this.applyLayoutResult(this.getRoot(), duration, function() {
minder.fire('layoutallfinish');
......@@ -438,9 +438,9 @@ define(function(require, exports, module) {
return this.fire('layout');
},
refresh: function(duration) {
refresh: function() {
this.getRoot().renderTree();
this.layout(duration).fire('contentchange')._interactChange();
this.layout().fire('contentchange')._interactChange();
return this;
},
......
......@@ -47,7 +47,7 @@ define(function(require, exports, module) {
if (!moduleDeals) continue;
if (moduleDeals.defaultOptions) {
me.addDefaultOption(moduleDeals.defaultOptions);
me.setDefaultOptions(moduleDeals.defaultOptions);
}
if (moduleDeals.init) {
......
......@@ -16,7 +16,7 @@ define(function(require, exports, module) {
});
kity.extendClass(Minder, {
addDefaultOption: function(options) {
setDefaultOptions: function(options) {
utils.extend(this._defaultOptions, options);
return this;
},
......@@ -26,6 +26,9 @@ define(function(require, exports, module) {
} else {
return utils.extend({}, this._defaultOptions, this._options);
}
},
setOption: function(key, value) {
this._options[key] = value;
}
});
});
\ No newline at end of file
define('expose', function(require, exports, module) {
define('expose-kityminder', function(require, exports, module) {
module.exports = window.kityminder = require('./kityminder');
});
\ No newline at end of file
......@@ -20,6 +20,7 @@ define(function(require, exports, module) {
kityminder.Command = require('./core/command');
kityminder.Node = require('./core/node');
require('./core/option');
require('./core/animate');
kityminder.Event = require('./core/event');
kityminder.data = require('./core/data');
require('./core/compatibility');
......
......@@ -17,7 +17,9 @@ define(function(require, exports, module) {
km.appendNode(child, parent);
child.render();
child.setLayoutOffset(null);
var children = utils.cloneArr(child.children);
var children = child.children.map(function(node) {
return node.clone();
});
for (var i = 0, ci;
(ci = children[i]); i++) {
appendChildNode(child, ci);
......
......@@ -73,7 +73,7 @@ define(function(require, exports, module) {
for (i = 0, text, textShape;
(text = textArr[i], textShape = textGroup.getItem(i)); i++) {
textShape.node.innerHTML = text.replace('<', '&lt;').replace('>', '&gt;');
textShape.setContent(text);
}
this.setTextStyle(node, textGroup);
......
......@@ -72,7 +72,7 @@ define(function(require, exports, module) {
getView: function() {
var minder = this._minder;
var c = {
var c = minder._lastClientSize || {
width: minder.getRenderTarget().clientWidth,
height: minder.getRenderTarget().clientHeight
};
......@@ -208,7 +208,7 @@ define(function(require, exports, module) {
*/
var CameraCommand = kity.createClass('CameraCommand', {
base: Command,
execute: function(km, focusNode, duration) {
execute: function(km, focusNode) {
focusNode = focusNode || km.getRoot();
var viewport = km.getPaper().getViewPort();
......@@ -217,6 +217,7 @@ define(function(require, exports, module) {
dy = viewport.center.y - offset.y;
var dragger = km._viewDragger;
var duration = km.getOption('viewAnimationDuration');
dragger.move(new kity.Point(dx, dy), duration);
this.setContentChanged(false);
},
......@@ -238,9 +239,10 @@ define(function(require, exports, module) {
var MoveCommand = kity.createClass('MoveCommand', {
base: Command,
execute: function(km, dir, duration) {
execute: function(km, dir) {
var dragger = km._viewDragger;
var size = km._lastClientSize;
var duration = km.getOption('viewAnimationDuration');
switch (dir) {
case 'up':
dragger.move(new kity.Point(0, size.height / 2), duration);
......@@ -345,7 +347,7 @@ define(function(require, exports, module) {
}
if (dx || dy) {
dragger.move(new kity.Point(dx, dy), 100);
dragger.move(new kity.Point(dx, dy));
}
}
}
......
......@@ -50,7 +50,8 @@ define(function(require, exports, module) {
setTextRendering();
if (minder.getRoot().getComplex() > 200) {
var duration = minder.getOption('zoomAnimationDuration');
if (minder.getRoot().getComplex() > 200 || !duration) {
minder._zoomValue = value;
minder.zoom(value);
minder.fire('viewchange');
......@@ -66,7 +67,7 @@ define(function(require, exports, module) {
if (timeline) {
timeline.pause();
}
timeline = animator.start(minder, 300, 'easeInOutSine');
timeline = animator.start(minder, duration, 'easeInOutSine');
timeline.on('finish', function() {
minder.fire('viewchange');
});
......@@ -148,7 +149,7 @@ define(function(require, exports, module) {
return {
init: function() {
this._zoomValue = 100;
this.addDefaultOption({
this.setDefaultOptions({
zoom: [10, 20, 50, 100, 200]
});
setTextRendering();
......
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