Commit 23788395 authored by hy's avatar hy

增加core中clipboard事件处理,修复了mac下FF不同字体显示的一点错位,增加了通过节点导入text并生成节点的protocol兼容处理

parent 31a7b2df
......@@ -77,6 +77,28 @@ define(function(require, exports, module) {
return JSON.parse(JSON.stringify(json));
},
/**
* @method importNode()
* @description 根据纯json {data, children}数据转换成为脑图节点
* @Editor: Naixor
* @Date: 2015.9.20
*/
importNode: function(node, json) {
var data = json.data;
node.data = {};
for (var field in data) {
node.setData(field, data[field]);
}
var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = this.createNode(null, node);
this.importNode(childNode, childrenTreeData[i]);
}
return node;
},
/**
* @method importJson()
* @for Minder
......@@ -87,23 +109,6 @@ define(function(require, exports, module) {
* @param {plain} json 要导入的数据
*/
importJson: function(json) {
function importNode(node, json, km) {
var data = json.data;
node.data = {};
for (var field in data) {
node.setData(field, data[field]);
}
var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode(null, node);
importNode(childNode, childrenTreeData[i], km);
}
return node;
}
if (!json) return;
/**
......@@ -120,7 +125,7 @@ define(function(require, exports, module) {
json = compatibility(json);
importNode(this._root, json.root, this);
this.importNode(this._root, json.root);
this.setTemplate(json.template || 'default');
this.setTheme(json.theme || null);
......
......@@ -54,6 +54,27 @@ define(function(require, exports, module) {
moduleDeals.init.call(me, this._options);
}
/**
* @Desc: 判断是否支持原生clipboard事件,如果支持,则对pager添加其监听
* @Editor: Naixor
* @Date: 2015.9.20
*/
if (name === 'ClipboardModule' && this.supportClipboardEvent && !kity.Browser.gecko) {
var on = function () {
var clipBoardReceiver = this.clipBoardReceiver || document;
if (document.addEventListener) {
clipBoardReceiver.addEventListener.apply(this, arguments);
} else {
arguments[0] = 'on' + arguments[0];
clipBoardReceiver.attachEvent.apply(this, arguments);
}
}
for (var command in moduleDeals.clipBoardEvents) {
on(command, moduleDeals.clipBoardEvents[command]);
}
};
// command加入命令池子
dealCommands = moduleDeals.commands;
for (name in dealCommands) {
......@@ -88,7 +109,6 @@ define(function(require, exports, module) {
if (moduleDeals.commandShortcutKeys) {
this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys);
}
}
},
......
......@@ -135,6 +135,15 @@ define(function(require, exports, module) {
getCommandShortcutKey: function(cmd) {
var binds = this._commandShortcutKeys;
return binds && binds[cmd] || null;
}
},
/**
* @Desc: 添加一个判断是否支持原生Clipboard的变量,用于对ctrl + v和ctrl + c的处理
* @Editor: Naixor
* @Date: 2015.9.20
*/
supportClipboardEvent: (function(window) {
return !!window.ClipboardEvent;
})(window)
});
});
\ No newline at end of file
......@@ -7,11 +7,9 @@ define(function(require, exports, module) {
Module.register('ClipboardModule', function() {
var km = this,
_clipboardNodes = [],
_selectedNodes = [];
function appendChildNode(parent, child) {
_selectedNodes.push(child);
km.appendNode(child, parent);
......@@ -43,7 +41,7 @@ define(function(require, exports, module) {
_clipboardNodes = nodes.map(function(node) {
return node.clone();
});
}
}
/**
* @command Copy
......@@ -123,17 +121,51 @@ define(function(require, exports, module) {
}
});
return {
'commands': {
'copy': CopyCommand,
'cut': CutCommand,
'paste': PasteCommand
},
'commandShortcutKeys': {
'copy': 'normal::ctrl+c|',
'cut': 'normal::ctrl+x',
'paste': 'normal::ctrl+v'
/**
* @Desc: 若支持原生clipboadr事件则基于原生扩展,否则使用km的基础事件只处理节点的粘贴复制
* @Editor: Naixor
* @Date: 2015.9.20
*/
if (km.supportClipboardEvent && !kity.Browser.gecko) {
var Copy = function (e) {
this.fire('beforeCopy', e);
}
};
var Cut = function (e) {
this.fire('beforeCut', e);
}
var Paste = function (e) {
this.fire('beforePaste', e);
}
return {
'commands': {
'copy': CopyCommand,
'cut': CutCommand,
'paste': PasteCommand
},
'clipBoardEvents': {
'copy': Copy.bind(km),
'cut': Cut.bind(km),
'paste': Paste.bind(km)
},
sendToClipboard: sendToClipboard
};
} else {
return {
'commands': {
'copy': CopyCommand,
'cut': CutCommand,
'paste': PasteCommand
},
'commandShortcutKeys': {
'copy': 'normal::ctrl+c|',
'cut': 'normal::ctrl+x',
'paste': 'normal::ctrl+v'
},
sendToClipboard: sendToClipboard
};
}
});
});
\ No newline at end of file
......@@ -9,6 +9,7 @@ define(function(require, exports, module) {
var Renderer = require('../core/render');
/**
* 针对不同系统、不同浏览器、不同字体做居中兼容性处理
* 暂时未增加Linux的处理
*/
var FONT_ADJUST = {
'safari': {
......@@ -75,7 +76,7 @@ define(function(require, exports, module) {
'comic sans ms': -0.2,
'impact,chicago': -0.12,
'times new roman': -0.02,
'default': -0.15
'default': -0.15
},
'Lux': {
'andale mono': -0.05,
......@@ -89,11 +90,12 @@ define(function(require, exports, module) {
'firefox': {
'Mac': {
'微软雅黑,Microsoft YaHei': -0.2,
'宋体,SimSun': -0.15,
'宋体,SimSun': 0.05,
'comic sans ms': -0.2,
'impact,chicago': -0.15,
'arial black,avant garde': -0.17,
'default': -0.15
'times new roman': -0.1,
'default': 0.05
},
'Win': {
'微软雅黑,Microsoft YaHei': -0.16,
......@@ -104,12 +106,12 @@ define(function(require, exports, module) {
'times new roman': -0.22,
'sans-serif': -0.22,
'arial black,avant garde': -0.17,
'default': -0.16
'default': -0.16
},
'Lux': {
'宋体,SimSun': -0.02
'宋体,SimSun': -0.02
}
}
},
};
var TextRenderer = kity.createClass('TextRenderer', {
......@@ -187,7 +189,7 @@ define(function(require, exports, module) {
}
for (i = 0, text, textShape;
(text = textArr[i], textShape = textGroup.getItem(i)); i++) {
(text = textArr[i], textShape = textGroup.getItem(i)); i++) {
textShape.setContent(text);
if (kity.Browser.ie || kity.Browser.edge) {
textShape.fixPosition();
......
define(function(require, exports, module) {
var data = require('../core/data');
var Browser = require('../core/kity').Browser;
/**
* @Desc: 增加对不容浏览器下节点中文本\t匹配的处理,不同浏览器下\t无法正确匹配,导致无法使用TAB来批量导入节点
* @Editor: Naixor
* @Date: 2015.9.17
*/
var LINE_ENDING = '\r',
LINE_ENDING_SPLITER = /\r\n|\r|\n/,
TAB_CHAR = '\t';
TAB_CHAR = '\t',
TAB_CHAR = (function(Browser) {
if (Browser.gecko) {
return {
REGEXP: new RegExp('^(\t|'+ String.fromCharCode(160,160,32,160) +')'),
DELETE: new RegExp('^(\t|'+ String.fromCharCode(160,160,32,160) +')+')
}
} else if (Browser.ie || Browser.edge) {
// ie系列和edge比较特别,\t在div中会被直接转义成SPACE故只好使用SPACE来做处理
return {
REGEXP: new RegExp('^('+ String.fromCharCode(32) +'|'+ String.fromCharCode(160) +')'),
DELETE: new RegExp('^('+ String.fromCharCode(32) +'|'+ String.fromCharCode(160) +')+')
}
} else {
return {
REGEXP: /^(\t|\x20\x20\x20\x20)/,
DELETE: /^(\t|\x20\x20\x20\x20)+/
}
}
})(Browser);
function repeat(s, n) {
var result = '';
......@@ -14,7 +39,7 @@ define(function(require, exports, module) {
function encode(json, level) {
var local = '';
level = level || 0;
local += repeat(TAB_CHAR, level);
local += repeat('\t', level);
local += json.data.text + LINE_ENDING;
if (json.children) {
json.children.forEach(function(child) {
......@@ -30,14 +55,18 @@ define(function(require, exports, module) {
function getLevel(line) {
var level = 0;
while (line.charAt(level) === TAB_CHAR) level++;
while (TAB_CHAR.REGEXP.test(line)) {
line = line.replace(TAB_CHAR.REGEXP, '');
level++;
}
return level;
}
function getNode(line) {
return {
data: {
text: line.replace(new RegExp('^' + TAB_CHAR + '*'), '')
text: line.replace(TAB_CHAR.DELETE, "")
}
};
}
......
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