Commit 23788395 authored by hy's avatar hy

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

parent 31a7b2df
...@@ -78,17 +78,12 @@ define(function(require, exports, module) { ...@@ -78,17 +78,12 @@ define(function(require, exports, module) {
}, },
/** /**
* @method importJson() * @method importNode()
* @for Minder * @description 根据纯json {data, children}数据转换成为脑图节点
* @description 导入脑图数据,数据为 JSON 对象,具体的数据字段形式请参考 [Data](data) 章节。 * @Editor: Naixor
* * @Date: 2015.9.20
* @grammar importJson(json) => {this}
*
* @param {plain} json 要导入的数据
*/ */
importJson: function(json) { importNode: function(node, json) {
function importNode(node, json, km) {
var data = json.data; var data = json.data;
node.data = {}; node.data = {};
...@@ -98,12 +93,22 @@ define(function(require, exports, module) { ...@@ -98,12 +93,22 @@ define(function(require, exports, module) {
var childrenTreeData = json.children || []; var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) { for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode(null, node); var childNode = this.createNode(null, node);
importNode(childNode, childrenTreeData[i], km); this.importNode(childNode, childrenTreeData[i]);
} }
return node; return node;
} },
/**
* @method importJson()
* @for Minder
* @description 导入脑图数据,数据为 JSON 对象,具体的数据字段形式请参考 [Data](data) 章节。
*
* @grammar importJson(json) => {this}
*
* @param {plain} json 要导入的数据
*/
importJson: function(json) {
if (!json) return; if (!json) return;
/** /**
...@@ -120,7 +125,7 @@ define(function(require, exports, module) { ...@@ -120,7 +125,7 @@ define(function(require, exports, module) {
json = compatibility(json); json = compatibility(json);
importNode(this._root, json.root, this); this.importNode(this._root, json.root);
this.setTemplate(json.template || 'default'); this.setTemplate(json.template || 'default');
this.setTheme(json.theme || null); this.setTheme(json.theme || null);
......
...@@ -54,6 +54,27 @@ define(function(require, exports, module) { ...@@ -54,6 +54,27 @@ define(function(require, exports, module) {
moduleDeals.init.call(me, this._options); 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加入命令池子 // command加入命令池子
dealCommands = moduleDeals.commands; dealCommands = moduleDeals.commands;
for (name in dealCommands) { for (name in dealCommands) {
...@@ -88,7 +109,6 @@ define(function(require, exports, module) { ...@@ -88,7 +109,6 @@ define(function(require, exports, module) {
if (moduleDeals.commandShortcutKeys) { if (moduleDeals.commandShortcutKeys) {
this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys); this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys);
} }
} }
}, },
......
...@@ -135,6 +135,15 @@ define(function(require, exports, module) { ...@@ -135,6 +135,15 @@ define(function(require, exports, module) {
getCommandShortcutKey: function(cmd) { getCommandShortcutKey: function(cmd) {
var binds = this._commandShortcutKeys; var binds = this._commandShortcutKeys;
return binds && binds[cmd] || null; 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,9 +7,7 @@ define(function(require, exports, module) { ...@@ -7,9 +7,7 @@ define(function(require, exports, module) {
Module.register('ClipboardModule', function() { Module.register('ClipboardModule', function() {
var km = this, var km = this,
_clipboardNodes = [], _clipboardNodes = [],
_selectedNodes = []; _selectedNodes = [];
function appendChildNode(parent, child) { function appendChildNode(parent, child) {
...@@ -123,6 +121,38 @@ define(function(require, exports, module) { ...@@ -123,6 +121,38 @@ define(function(require, exports, module) {
} }
}); });
/**
* @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 { return {
'commands': { 'commands': {
'copy': CopyCommand, 'copy': CopyCommand,
...@@ -133,7 +163,9 @@ define(function(require, exports, module) { ...@@ -133,7 +163,9 @@ define(function(require, exports, module) {
'copy': 'normal::ctrl+c|', 'copy': 'normal::ctrl+c|',
'cut': 'normal::ctrl+x', 'cut': 'normal::ctrl+x',
'paste': 'normal::ctrl+v' 'paste': 'normal::ctrl+v'
} },
sendToClipboard: sendToClipboard
}; };
}
}); });
}); });
\ No newline at end of file
...@@ -9,6 +9,7 @@ define(function(require, exports, module) { ...@@ -9,6 +9,7 @@ define(function(require, exports, module) {
var Renderer = require('../core/render'); var Renderer = require('../core/render');
/** /**
* 针对不同系统、不同浏览器、不同字体做居中兼容性处理 * 针对不同系统、不同浏览器、不同字体做居中兼容性处理
* 暂时未增加Linux的处理
*/ */
var FONT_ADJUST = { var FONT_ADJUST = {
'safari': { 'safari': {
...@@ -89,11 +90,12 @@ define(function(require, exports, module) { ...@@ -89,11 +90,12 @@ define(function(require, exports, module) {
'firefox': { 'firefox': {
'Mac': { 'Mac': {
'微软雅黑,Microsoft YaHei': -0.2, '微软雅黑,Microsoft YaHei': -0.2,
'宋体,SimSun': -0.15, '宋体,SimSun': 0.05,
'comic sans ms': -0.2, 'comic sans ms': -0.2,
'impact,chicago': -0.15, 'impact,chicago': -0.15,
'arial black,avant garde': -0.17, 'arial black,avant garde': -0.17,
'default': -0.15 'times new roman': -0.1,
'default': 0.05
}, },
'Win': { 'Win': {
'微软雅黑,Microsoft YaHei': -0.16, '微软雅黑,Microsoft YaHei': -0.16,
...@@ -109,7 +111,7 @@ define(function(require, exports, module) { ...@@ -109,7 +111,7 @@ define(function(require, exports, module) {
'Lux': { 'Lux': {
'宋体,SimSun': -0.02 '宋体,SimSun': -0.02
} }
} },
}; };
var TextRenderer = kity.createClass('TextRenderer', { var TextRenderer = kity.createClass('TextRenderer', {
......
define(function(require, exports, module) { define(function(require, exports, module) {
var data = require('../core/data'); 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', var LINE_ENDING = '\r',
LINE_ENDING_SPLITER = /\r\n|\r|\n/, 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) { function repeat(s, n) {
var result = ''; var result = '';
...@@ -14,7 +39,7 @@ define(function(require, exports, module) { ...@@ -14,7 +39,7 @@ define(function(require, exports, module) {
function encode(json, level) { function encode(json, level) {
var local = ''; var local = '';
level = level || 0; level = level || 0;
local += repeat(TAB_CHAR, level); local += repeat('\t', level);
local += json.data.text + LINE_ENDING; local += json.data.text + LINE_ENDING;
if (json.children) { if (json.children) {
json.children.forEach(function(child) { json.children.forEach(function(child) {
...@@ -30,14 +55,18 @@ define(function(require, exports, module) { ...@@ -30,14 +55,18 @@ define(function(require, exports, module) {
function getLevel(line) { function getLevel(line) {
var level = 0; 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; return level;
} }
function getNode(line) { function getNode(line) {
return { return {
data: { 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