Commit 1926eda1 authored by techird's avatar techird

animate switcher

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