12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385 |
- MWF.xApplication.MinderEditor.Commands = new Class({
- Extends: MWF.widget.Common,
- Implements: [Options, Events],
- options: {
- "type": "common",
- "style": "default"
- },
- initialize: function ( editor, options) {
- this.setOptions(options);
- this.app = editor;
- this.lp = MWF.xApplication.MinderEditor.LP;
- //this.actions = this.app.restActions;
- this.editor = editor;
- this.minder = editor.minder;
- if( !editor.debug ){
- MWF.xDesktop.requireApp("MinderEditor", "Tools", null, false);
- MWF.xDesktop.requireApp("MinderEditor", "RuntimeInCommon", null, false);
- MWF.xDesktop.requireApp("MinderEditor", "WidgetInCommon", null, false);
- this.editor.debug = new MWF.xApplication.MinderEditor.Debug(true);
- }
- if( !editor.fsm ){
- this.editor.fsm = new MWF.xApplication.MinderEditor.FSM('normal');
- }
- if( !editor.key ){
- this.editor.key = new MWF.xApplication.MinderEditor.Key();
- }
- if( !editor.receiver ){
- this.editor.receiver = new MWF.xApplication.MinderEditor.Receiver(this.editor);
- }
- this.fsm = this.editor.fsm;
- this.receiver = this.editor.receiver;
- //this.input = this.editor.input;
- //this.drag = this.editor.drag;
- this.history = this.editor.history;
- //this.key = this.editor.key;
- this.path = "../x_component_MinderEditor/$Commands/";
- this.cssPath = this.path+this.options.style+"/css.wcss";
- this.commands = {
- undo: {
- icon: "undo",
- locale: "撤销",
- modle : ["edit"],
- key: "Ctrl + Z",
- disable: function () {
- return this.history.hasUndo() == false;
- }.bind(this),
- action: function () {
- this.history.hasUndo() == false || this.history.undo();
- }.bind(this)
- },
- redo: {
- icon: "redo",
- locale: "重做",
- modle : ["edit"],
- key: "Ctrl + Y",
- disable: function () {
- return this.history.hasRedo() == false;
- }.bind(this),
- action: function () {
- this.history.hasRedo() == false || this.history.redo();
- }.bind(this)
- },
- appendChild: {
- icon: "insert_sub",
- modle : ["edit"],
- locale: "插入下级主题",
- key: ["Tab", "Insert"],
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('AppendChildNode') === -1;
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('AppendChildNode') === -1 || this.minder.execCommand('AppendChildNode')
- }.bind(this)
- },
- appendParent: {
- icon: "insert_par",
- modle : ["edit"],
- locale: "插入上级主题",
- key: "Shit + Tab",
- disable: function () {
- return this.minder.queryCommandState('AppendParentNode') === -1;
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('AppendParentNode') === -1 || this.minder.execCommand('AppendParentNode')
- }.bind(this)
- },
- appendSibling: {
- icon: "insert_sibling",
- modle : ["edit"],
- locale: "插入同级主题",
- key: "Enter",
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('AppendSiblingNode') === -1;
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('AppendSiblingNode') === -1 || this.minder.execCommand('AppendSiblingNode')
- }.bind(this)
- },
- arrangeUp: {
- icon: "up",
- modle : ["edit"],
- locale: "上移",
- key: "Alt + Up",
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('ArrangeUp') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('ArrangeUp') === -1 || this.minder.execCommand('ArrangeUp')
- }.bind(this)
- },
- arrangeDown: {
- icon: "down",
- modle : ["edit"],
- locale: "下移",
- key: "Alt + Down",
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('ArrangeDown') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('ArrangeDown') === -1 || this.minder.execCommand('ArrangeDown')
- }.bind(this)
- },
- edit: {
- icon: "edit",
- modle : ["edit"],
- locale: "编辑",
- key: "F2",
- disable: function () {
- return this.minder.queryCommandState('text') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('text') === -1 || this.editNode()
- }.bind(this)
- },
- remove: {
- icon: "delete",
- modle : ["edit"],
- locale: "删除",
- key: "Delete",
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('RemoveNode') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('RemoveNode') === -1 || this.minder.execCommand('RemoveNode');
- }.bind(this)
- },
- hyperLink: {
- icon: "link",
- modle : ["edit"],
- locale: "链接",
- key: "Alt + L",
- disable: function () {
- return this.minder.queryCommandState('HyperLink') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('HyperLink') === -1 || this.openHyperLinkForm("hyperLink");
- }.bind(this)
- },
- image: {
- icon: "image",
- modle : ["edit"],
- locale: "图片",
- key: "Alt + M",
- disable: function () {
- return this.minder.queryCommandState('Image') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('Image') === -1 || this.openImageForm("image");
- }.bind(this)
- },
- note: {
- title: "备注",
- modle : ["edit"],
- disable: function () {
- return this.minder.queryCommandState('note') === -1
- }.bind(this),
- init: function (container, command) {
- this.createNoteEditor(container, "note");
- }.bind(this),
- setDisable: function () {
- this.setNoteDisable()
- }.bind(this),
- setNormal: function () {
- this.setNoteNormal()
- }.bind(this)
- },
- priority: {
- icon: "priority",
- modle : ["edit"],
- locale: "优先级",
- key: "Alt + G",
- disable: function () {
- return this.minder.queryCommandState("priority") === -1
- }.bind(this),
- keyAction: function () {
- this.prioritySelector.showTooltip()
- }.bind(this),
- init: function (container, command) {
- this.initPriority(container, command)
- }.bind(this)
- },
- progress: {
- icon: "progress",
- modle : ["edit"],
- locale: "进度",
- key: "Alt + P",
- disable: function () {
- return this.minder.queryCommandState("progress") === -1
- }.bind(this),
- keyAction: function () {
- this.progressSelector.showTooltip()
- }.bind(this),
- init: function (container, command) {
- this.initProgress(container, command)
- }.bind(this)
- },
- resource: {
- title: "标签",
- modle : ["edit"],
- disable: function () {
- return this.minder.queryCommandState('resource') === -1
- }.bind(this),
- init: function (container, command) {
- this.initResource(container, command)
- }.bind(this),
- setDisable: function () {
- this.setResourceDisable()
- }.bind(this),
- setNormal: function () {
- this.setResourceNormal()
- }.bind(this)
- },
- template: {
- icon: "template",
- modle : ["edit","read"],
- title: "模板",
- disable: function () {
- return this.minder.queryCommandState('template') === -1
- }.bind(this),
- init: function (container, command) {
- this.initTemplate(container, command)
- }.bind(this)
- },
- theme: {
- icon: "theme",
- modle : ["edit","read"],
- title: "主题",
- disable: function () {
- return this.minder.queryCommandState('theme') === -1
- }.bind(this),
- init: function (container, command) {
- this.initTheme(container, command)
- }.bind(this)
- },
- resetlayout: {
- icon: "resetlayout",
- modle : ["edit","read"],
- title: "整理布局",
- key: "Ctrl + Shift + L",
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('resetlayout') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('resetlayout') === -1 || this.minder.execCommand('resetlayout');
- }.bind(this)
- },
- clearstyle: {
- icon: "clear",
- modle : ["edit"],
- locale: "清除样式",
- disable: function () {
- return this.minder.queryCommandState('clearstyle') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('clearstyle') === -1 || this.minder.execCommand('clearstyle');
- }.bind(this)
- },
- copystyle: {
- icon: "copystyle",
- modle : ["edit"],
- locale: "拷贝样式",
- disable: function () {
- return this.minder.queryCommandState('copystyle') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('copystyle') === -1 || this.minder.execCommand('copystyle');
- }.bind(this)
- },
- pastestyle: {
- icon: "pastestyle",
- modle : ["edit"],
- locale: "粘贴样式",
- disable: function () {
- return this.minder.queryCommandState('pastestyle') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('pastestyle') === -1 || this.minder.execCommand('pastestyle');
- }.bind(this)
- },
- fontfamily: {
- title: "字体",
- modle : ["edit"],
- //key : "Alt + T",
- disable: function () {
- return this.minder.queryCommandState('fontfamily') === -1
- }.bind(this),
- keyAction: function () {
- this.fontfamilySelector.showTooltip()
- }.bind(this),
- init: function (container, command) {
- this.initFontFamily(container, command)
- }.bind(this)
- },
- fontsize: {
- title: "字号",
- modle : ["edit"],
- //key : "Alt + H",
- disable: function () {
- return this.minder.queryCommandState('fontsize') === -1
- }.bind(this),
- keyAction: function () {
- this.fontsizeSelector.showTooltip()
- }.bind(this),
- init: function (container, command) {
- this.initFontSize(container, command)
- }.bind(this)
- },
- italic: {
- icon: "italic",
- modle : ["edit"],
- title: "斜体",
- key: "Ctrl + I",
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('italic') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('italic') === -1 || this.minder.execCommand('italic');
- }.bind(this)
- },
- bold: {
- icon: "bold",
- modle : ["edit"],
- title: "加粗",
- key: "Ctrl + B",
- isDefaultKey: true,
- disable: function () {
- return this.minder.queryCommandState('bold') === -1
- }.bind(this),
- action: function () {
- this.minder.queryCommandState('bold') === -1 || this.minder.execCommand('bold');
- }.bind(this)
- },
- forecolor: {
- icon: "forecolor",
- modle : ["edit"],
- title: "字体颜色",
- action: function () {
- ( this.minder.queryCommandState('forecolor') === -1 || !this.currentForecolor ) || this.minder.execCommand('forecolor', this.currentForecolor);
- }.bind(this),
- disable: function () {
- return this.minder.queryCommandState('forecolor') === -1
- }.bind(this),
- init: function (container, command) {
- this.initFontColor(container, command)
- }.bind(this)
- },
- background: {
- icon: "background",
- modle : ["edit"],
- title: "背景颜色",
- action: function () {
- ( this.minder.queryCommandState('background') === -1 || !this.currentBackgroundcolor ) || this.minder.execCommand('background', this.currentBackgroundcolor);
- }.bind(this),
- disable: function () {
- return this.minder.queryCommandState('background') === -1
- }.bind(this),
- init: function (container, command) {
- this.initBackground(container, command)
- }.bind(this)
- },
- expandLevel: {
- icon: "expand",
- modle : ["edit","read"],
- title: "展开节点",
- //key : "Alt + N",
- disable: function () {
- return false;
- }.bind(this),
- keyAction: function () {
- this.expandlevelSelector.showTooltip()
- }.bind(this),
- init: function (container, command) {
- this.initExpandLevel(container, command)
- }.bind(this)
- },
- selectAll: {
- icon: "select",
- modle : ["edit","read"],
- title: "选择",
- //key : "Alt + S",
- disable: function () {
- return false;
- }.bind(this),
- keyAction: function () {
- this.selectallSelector.showTooltip()
- }.bind(this),
- init: function (container, command) {
- this.initSelectAll(container, command)
- }.bind(this)
- },
- zoom : {
- module : ["edit","read"],
- title : "缩放",
- disable : function(){ return false },
- init : function( container, command ){
- this.initZoomArea(container, command);
- }.bind(this)
- },
- camera : {
- icon: "camera",
- module : ["edit","read"],
- title : "根节点居中",
- disable: function () {
- return false;
- }.bind(this),
- action: function () {
- this.minder.execCommand('camera', this.minder.getRoot(), 600);
- }.bind(this)
- },
- preview : {
- icon: "preview",
- module : ["edit","read"],
- title : "预览",
- active : true,
- disable: function () {
- return false;
- }.bind(this),
- action: function () {
- this.toggleOpenPreViewer();
- }.bind(this),
- setDisable: function () {
- }.bind(this),
- setNormal: function () {
- }.bind(this),
- init: function (container, command) {
- this.initPreViewer(container)
- }.bind(this)
- },
- move : {
- icon: "move",
- module : ["edit","read"],
- title : "允许拖拽",
- disable: function () {
- return false;
- }.bind(this),
- active : false,
- setDisable: function () {
- }.bind(this),
- setNormal: function () {
- }.bind(this),
- action: function () {
- this.minder.execCommand('hand');
- }.bind(this)
- },
- search: {
- icon: "search",
- module : ["edit","read"],
- title : "搜索",
- key : "Ctrl + F",
- active : false,
- setDisable: function () {
- }.bind(this),
- setNormal: function () {
- }.bind(this),
- disable: function () {
- return false;
- }.bind(this),
- action : function(){
- this.toggerSearch();
- }.bind(this),
- init: function ( container ) {
- this.initSearch( container );
- }.bind(this)
- },
- help : {
- icon: "help",
- modle : ["edit","read"],
- title: "帮助",
- key : "Ctrl + Alt + H",
- disable: function () {
- return false;
- }.bind(this),
- keyAction: function () {
- this.helpTootips.load()
- }.bind(this),
- init: function (container, command) {
- this.initHelp(container, command)
- }.bind(this)
- },
- save : {
- icon: "save",
- modle : ["edit"],
- locale: "保存",
- key : "Ctrl + S",
- disable: function () {
- return false;
- }.bind(this),
- action: function () {
- this.save()
- }.bind(this),
- init: function (container, command) {
- this.initSaveTooltip(container, command)
- }.bind(this)
- },
- export : {
- icon: "export",
- modle : ["edit"],
- locale: "导出",
- disable: function () {
- return false;
- }.bind(this),
- init: function (container, command) {
- this.initExportTooltip(container, command)
- }.bind(this)
- },
- menu : {
- icon: "menu",
- modle : ["edit"],
- locale: "菜单",
- disable: function () {
- return false;
- }.bind(this),
- action: function (ev, node, command) {
- this.initMainMenu( node, command)
- }.bind(this),
- init: function (container, command) {
- if( this.app.options.menuAction ){
- this.initMainMenu(container, command)
- }
- }.bind(this)
- }
- };
- for (var name in this.commands) {
- this.commands[name].name = name;
- }
- this.setKeyCommand();
- this.tooltipOptions = {
- displayDelay : 300,
- "onPostCreate": function (tooltips) {
- tooltips.node.addEvents({
- mouseenter : function(){
- var command = tooltips.command;
- if (!command.disable()) {
- this.setActiveStye(tooltips.target, command)
- } else {
- this.setDisableStye(tooltips.target, command)
- }
- }.bind(this)
- })
- }.bind(this),
- "onHide": function (tooltips) {
- var command = tooltips.command;
- if (!command.disable()) {
- this.setNormalStye(tooltips.target, command)
- } else {
- this.setDisableStye(tooltips.target, command)
- }
- }.bind(this)
- };
- this.selectOptions = {
- "tooltipsOptions": {
- displayDelay : 300,
- "onPostCreate": function (tooltips) {
- var selector = tooltips.selector;
- tooltips.node.addEvents({
- mouseenter : function(){
- var command = selector.command;
- if (!command.disable()) {
- this.setActiveStye(selector.container, command)
- } else {
- this.setDisableStye(selector.container, command)
- }
- }.bind(this)
- })
- }.bind(this),
- "onQueryLoad": function (tooltips) {
- var selector = tooltips.selector;
- if ( selector.command ) {
- tooltips.disable = selector.command.disable();
- }
- }.bind(this),
- "onPostLoad": function (tooltips) {
- var selector = tooltips.selector;
- if (selector.selectArrowNode)selector.selectArrowNode.setStyles(selector.css.selectArrowNode_up);
- this.activeTooltip = tooltips;
- }.bind(this),
- "onHide": function (tooltips) {
- var selector = tooltips.selector;
- if (this.activeTooltip == tooltips)this.activeTooltip = null;
- if (selector.selectArrowNode) selector.selectArrowNode.setStyles(selector.css.selectArrowNode);
- var command = selector.command;
- if (!command.disable()) {
- this.setNormalStye(selector.container, command)
- } else {
- this.setDisableStye(selector.container, command)
- }
- }.bind(this),
- event: "mouseenter" //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
- }
- }
- },
- load: function () {
- this._loadCss();
- this.containerObject = {};
- this.cssObject = {};
- this.itemNodeObject = {};
- this.fsm.when('normal -> normal', function (exit, enter, reason, e) {
- if (reason == 'shortcut-handle') {
- var handleResult = this.dispatchKey(e);
- if (handleResult) {
- e.preventDefault();
- } else {
- this.minder.dispatchKeyEvent(e);
- }
- }
- }.bind(this));
- this.minder.on('interactchange', function () {
- if (this.queryInteractchange()) {
- if (this.activeTooltip)this.activeTooltip.hide();
- this.checkStatus();
- }
- }.bind(this));
- },
- addContainer : function( name, container, css ){
- this.containerObject[name] = container;
- this.cssObject[ name ] = css;
- this.loadItemsByContainer( name );
- },
- loadItemsByContainer : function( name ){
- var container = this.containerObject[name];
- var css = this.cssObject[ name ];
- container.getElements("[item]").each(function (node) {
- if (node.get("lazyLoading") == "true" )return;
- this.loadItemNode(node, css);
- }.bind(this));
- },
- loadItemsByNameList : function(nameList,containerName ){
- var container = this.containerObject[containerName];
- var css = this.cssObject[ containerName ];
- container.getElements("[item]").each(function (node) {
- var name = node.get("item");
- if( nameList.contains( name ) ){
- this.loadItemNode( node, css);
- }
- }.bind(this));
- },
- loadItemByName: function (name , containerName ) {
- var container = this.containerObject[containerName];
- var css = this.cssObject[ containerName ];
- var node = container.getElement("[item='" + name + "']");
- this.loadItemNode( node, css);
- },
- getItemNode : function( name, containerName ){
- var container = this.containerObject[containerName];
- var node = container.getElement("[item='" + name + "']");
- return node;
- },
- loadItemNode: function (node, css) {
- var _self = this;
- node.store( "css", css );
- var name = node.get("item");
- var subtype = node.get("subtype");
- var event = node.get("itemevent");
- if (this.commands[name]) {
- var command = this.commands[name];
- if( !subtype || subtype=="button" ){
- this.itemNodeObject[name] = node;
- if( command.active ){
- node.setStyles( css[node.get("styles") ]);
- this.setActiveStye(node, command);
- node.store("active",true);
- }else if (command.disable()) {
- node.setStyles( css[node.get("styles") ]);
- this.setDisableStye(node, command)
- } else {
- this.setNormalStye(node, command)
- }
- var title = (command.title || ""); //+ ( command.key ? (" 快捷键:" + command.key) : "" );
- node.set("title", title);
- if( !event || event=="mouseover" ){
- node.addEvents({
- mouseover : function () {
- if (!command.disable()) {
- this.setActiveStye(node, command)
- } else {
- this.setDisableStye(node, command)
- }
- }.bind(this),
- mouseleave : function () {
- if (!command.disable()) {
- this.setNormalStye(node, command)
- } else {
- this.setDisableStye(node, command)
- }
- }.bind(this)
- });
- }else{
- node.addEvents({
- click: function () {
- if ( !node.retrieve("active")) {
- this.setActiveStye(node, command);
- node.store("active",true)
- } else {
- this.setNormalStye(node, command);
- node.store("active",false)
- }
- }.bind(this)
- });
- }
- var div = new Element("div", {
- "text": command.locale || null
- }).inject(node);
- if (command.action) {
- node.addEvent("click", function (ev) {
- if (!command.disable()) {
- command.action( ev, node, command );
- _self.fireEvent("postExecCommand", [_self, this])
- }
- }.bind(name))
- }
- }
- if( !subtype || subtype=="container" ){
- if (command.init) {
- command.init(node, command);
- if( command.active === false ){
- node.setStyle("display","none")
- }
- }
- }
- }
- },
- setDisableStye: function (node, command) {
- var css = node.retrieve("css");
- node.setStyles(css[node.get("styles") + "_disable"]);
- if (command.icon) {
- node.setStyle("background-image", "url(../x_component_MinderEditor/$Main/" + this.options.style + "/icon/" + command.icon + "_disable.png)");
- }
- },
- setActiveStye: function (node, command) {
- var css = node.retrieve("css");
- node.setStyles(css[node.get("styles") + "_over"]);
- if (command.icon) {
- node.setStyle("background-image", "url(../x_component_MinderEditor/$Main/" + this.options.style + "/icon/" + command.icon + "_active.png)")
- }
- },
- setNormalStye: function (node, command) {
- var css = node.retrieve("css");
- node.setStyles(css[node.get("styles")]);
- if (command.icon) {
- node.setStyle("background-image", "url(../x_component_MinderEditor/$Main/" + this.options.style + "/icon/" + command.icon + "_normal.png)")
- }
- },
- checkStatus: function () {
- for (var name in this.itemNodeObject) {
- var node = this.itemNodeObject[name];
- var name = node.get("item");
- if (this.commands[name]) {
- var command = this.commands[name];
- if (command.disable()) {
- command.setDisable ? command.setDisable() : this.setDisableStye(node, command);
- } else {
- command.setNormal ? command.setNormal() : this.setNormalStye(node, command)
- }
- }
- }
- },
- setKeyCommand: function () {
- this.keyCommands = {};
- this.defaultKeyCommands = {};
- for (var name in this.commands) {
- var command = this.commands[name];
- if (command.key) {
- var commands = command.isDefaultKey ? this.defaultKeyCommands : this.keyCommands;
- if (typeOf(command.key) == "array") {
- for (var i = 0; i < command.key.length; i++) {
- commands[command.key[i]] = command;
- }
- } else {
- commands[command.key] = command;
- }
- }
- }
- },
- getKey: function (e) {
- var controlKeys = [];
- if (e.ctrlKey)controlKeys.push("Ctrl");
- if (e.shiftKey)controlKeys.push("Shift");
- if (e.altKey)controlKeys.push("Alt");
- if (![16, 17, 18].contains(e.keyCode)) { //16 是 Shift, 17 是 Ctrl, 18 是Alt
- return controlKeys.length == 0 ? e.key.capitalize() : ( controlKeys.join(" + ") + " + " + e.key.capitalize() );
- } else {
- return controlKeys.join(" + ");
- }
- },
- dispatchKey: function (e, callback) {
- var key = this.getKey(e);
- var command = this.keyCommands[key];
- if (command && !command.disable() && this.itemNodeObject[command.name]) {
- if (command.action) {
- command.action();
- if (callback)callback(e, true);
- return true;
- } else if (command.keyAction) {
- if (this.activeTooltip)this.activeTooltip.hide();
- command.keyAction();
- if (callback)callback(e, true);
- return true;
- } else {
- if (callback)callback(e, true);
- return false;
- }
- } else {
- if (callback)callback(e, false);
- return false;
- }
- },
- save : function(){
- this.editor.save();
- },
- initSelectAll: function (container, command) {
- var selector = this.selectallSelector = new MWF.xApplication.MinderEditor.SelectAll(container, Object.merge(Object.clone(this.selectOptions), {
- "onSelectItem": function (itemNode, itemData) {
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- },
- initExpandLevel: function (container, command) {
- var selector = this.expandlevelSelector = new MWF.xApplication.MinderEditor.ExpandLevel(container, Object.merge(Object.clone(this.selectOptions), {
- "onSelectItem": function (itemNode, itemData) {
- this.minder.execCommand('ExpandToLevel', itemData.value);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- },
- initBackground: function (container, command) {
- var selector = this.backgroundSelector = new MWF.xApplication.Template.widget.ColorPicker(this.app.node, container, this.app, {},
- Object.merge( this.tooltipOptions, {
- "onQueryLoad": function (tooltips) {
- tooltips.disable = this.commands.background.disable();
- }.bind(this),
- "onSelect": function (color) {
- this.currentBackgroundcolor = color;
- this.minder.queryCommandState('background') === -1 || this.minder.execCommand('background', color);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- } ));
- selector.command = command;
- },
- initFontColor: function (container, command) {
- var selector = this.forecolorSelector = new MWF.xApplication.Template.widget.ColorPicker(this.app.node, container, this.app, {},
- Object.merge( this.tooltipOptions, {
- "onQueryLoad": function (tooltips) {
- tooltips.disable = this.commands.forecolor.disable();
- }.bind(this),
- "onSelect": function (forecolor) {
- this.currentForecolor = forecolor;
- this.minder.queryCommandState('forecolor') === -1 || this.minder.execCommand('forecolor', forecolor);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- })
- );
- selector.command = command;
- },
- initFontFamily: function (container, command) {
- var selector = this.fontfamilySelector = new MWF.xApplication.MinderEditor.FontFamily(container, Object.merge(Object.clone(this.selectOptions), {
- "containerIsTarget": false,
- "onPostLoad" : function( selector ){
- selector.selectValueNode.addEvent( "click", function(){
- if( selector.currentItemData ){
- this.minder.queryCommandState('fontfamily') === -1 || this.minder.execCommand('fontfamily', selector.currentItemData.val);
- }
- }.bind(this))
- }.bind(this),
- "onSelectItem": function (itemNode, itemData) {
- this.minder.queryCommandState('fontfamily') === -1 || this.minder.execCommand('fontfamily', itemData.val);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- },
- initFontSize: function (container, command) {
- var selector = this.fontsizeSelector = new MWF.xApplication.MinderEditor.FontSize(container, Object.merge(Object.clone(this.selectOptions), {
- "containerIsTarget": false,
- "onPostLoad" : function( selector ){
- selector.selectValueNode.addEvent( "click", function(){
- if( selector.currentItemData ){
- this.minder.queryCommandState('fontsize') === -1 || this.minder.execCommand('fontsize', selector.currentItemData.value);
- }
- }.bind(this))
- }.bind(this),
- "onSelectItem": function (itemNode, itemData) {
- this.minder.queryCommandState('fontsize') === -1 || this.minder.execCommand('fontsize', itemData.value);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- },
- initTheme: function (container, command) {
- var _self = this;
- var selector = this.themeSelector = new MWF.xApplication.MinderEditor.Theme(container, Object.merge(Object.clone(this.selectOptions), {
- "style": "minderTheme",
- "containerIsTarget": true,
- "onPostCreateItem": function (itemNode, itemData) {
- itemNode.setStyles(_self.getThemeThumbStyle(itemData.command));
- },
- "onSelectItem": function (itemNode, itemData) {
- this.minder.queryCommandState('theme') === -1 || this.minder.execCommand('theme', itemData.command);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- },
- initTemplate: function (container, command) {
- var _self = this;
- var selector = this.templateSelector = new MWF.xApplication.MinderEditor.Template(container, Object.merge(Object.clone(this.selectOptions), {
- "style": "minderTemplate",
- "containerIsTarget": true,
- "onSelectItem": function (itemNode, itemData) {
- this.minder.execCommand('template', itemData.command);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- },
- initPriority: function (container, command) {
- var _self = this;
- var selector = this.prioritySelector = new MWF.xApplication.MinderEditor.PriorityImage(container, Object.merge(Object.clone(this.selectOptions), {
- "containerIsTarget": true,
- "onSelectItem": function (itemNode, itemData) {
- var val = itemData.command == "0" ? null : parseInt(itemData.command);
- this.minder.execCommand('priority', val);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- this.minder.on('interactchange', function () {
- if (this.queryInteractchange()) {
- var enabled = this.minder.queryCommandState('priority') != -1;
- if (enabled) {
- var priority = this.minder.queryCommandValue('priority') || "0";
- selector.setValue(priority);
- }
- }
- }.bind(this));
- },
- initProgress: function (container, command) {
- var _self = this;
- var selector = this.progressSelector = new MWF.xApplication.MinderEditor.ProgressImage(container, Object.merge(Object.clone(this.selectOptions), {
- "containerIsTarget": true,
- "onSelectItem": function (itemNode, itemData) {
- var val = itemData.command == "0" ? null : parseInt(itemData.command);
- this.minder.execCommand('progress', val);
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }), this.app, null, this.app.node);
- selector.command = command;
- selector.load();
- this.minder.on('interactchange', function () {
- if (this.queryInteractchange()) {
- var enabled = this.minder.queryCommandState('progress') != -1;
- if (enabled) {
- var progress = this.minder.queryCommandValue('progress') || "0";
- selector.setValue(progress);
- }
- }
- }.bind(this));
- },
- getThemeThumbStyle: function (theme) {
- var themeList = this.themeList = this.themeList || kityminder.Minder.getThemeList();
- var themeObj = themeList[theme];
- if (!themeObj) {
- return;
- }
- var style = {
- 'color': themeObj['root-color'],
- 'border-radius': themeObj['root-radius'] / 2
- };
- if (themeObj['root-background']) {
- style['background'] = themeObj['root-background'].toString();
- }
- return style;
- },
- toggerSearch : function(){
- if( !this.isSearchbarActive ){
- this.searchBar.show();
- //this.isSearchbarActive = true;
- }else{
- this.searchBar.hide();
- //this.isSearchbarActive = false;
- }
- },
- initSearch : function(container){
- this.minder.on('searchNode', function() {
- this.itemNodeObject.search.click();
- }.bind(this));
- this.searchBar = new MWF.xApplication.MinderEditor.SearchBar( container, this.minder, this.app, this.css, {
- onShow : function(){
- this.setActiveStye( this.itemNodeObject.search, "search" );
- this.isSearchbarActive = true;
- }.bind(this),
- onHide : function(){
- this.setNormalStye( this.itemNodeObject.search, "search" );
- this.isSearchbarActive = false;
- }.bind(this)
- } );
- this.isSearchbarActive = false;
- this.searchBar.load();
- },
- initHelp: function (container, command) {
- var _self = this;
- this.helpTootips = new MWF.xApplication.MinderEditor.Help(this.app.node, container, this.app, {},
- this.tooltipOptions );
- this.helpTootips.commands = this;
- this.helpTootips.command = command;
- },
- initSaveTooltip : function( container, command ){
- this.savetooltip = new MWF.xApplication.MinderEditor.SaveTooltips(this.app.node, container, this.app, {},
- this.tooltipOptions);
- this.savetooltip.command = command;
- },
- initExportTooltip : function( container, command ){
- this.exporttooltip = new MWF.xApplication.MinderEditor.ExportTooltips(this.app.node, container, this.app, {},
- this.tooltipOptions);
- this.exporttooltip.command = command;
- },
- initMainMenu : function( container, command ){
- var _self = this;
- if( !this.mainMenu ){
- MWF.xDesktop.requireApp("MinderEditor", "MainMenu", null, false);
- this.mainMenu = new MWF.xApplication.MinderEditor.MainMenu(this.app.content, this.app, {
- "onShow": function () {
- if (!this.command.disable()) {
- _self.setActiveStye(this.container, this.command)
- } else {
- _self.setDisableStye(this.container, this.command)
- }
- }.bind({ container : container, command : command }),
- "onHide": function () {
- if (!this.command.disable()) {
- _self.setNormalStye(this.container, this.command)
- } else {
- _self.setDisableStye(this.container, this.command)
- }
- }.bind({ container : container, command : command })
- });
- this.mainMenu.command = command;
- }else{
- if( this.mainMenu.isHidden ){
- this.mainMenu.show();
- }else{
- this.mainMenu.hide();
- }
- }
- },
- setResourceDisable: function () {
- if (!this.resourceMaskNode) {
- this.resourceMaskNode = new Element("div.maskNode", {
- "styles": this.css.resourceMaskNode
- }).inject(this.resourceNode);
- } else {
- this.resourceMaskNode.setStyle("display", "");
- }
- this.addResourceInput.placeholder = "选择节点编辑标签";
- },
- setResourceNormal: function () {
- if (this.resourceMaskNode)this.resourceMaskNode.setStyle("display", "none");
- this.addResourceInput.placeholder = "输入文字添加标签";
- },
- initResource: function (container, command) {
- this.resourceNode = new Element("div.resourceNode", {
- styles: this.css.resourceNode
- }).inject(container);
- var inputContainer = new Element("div", {styles: {overflow: "hidden"}}).inject(this.resourceNode);
- this.addResourceInput = new Element("input", {
- placeholder: "输入文字添加标签", styles: this.css.addResourceInput
- }).inject(inputContainer);
- this.addResourceBotton = new Element("div", {
- text: "添加",
- styles: this.css.addResourceBotton,
- events: {
- click: function () {
- var resourceName = this.addResourceInput.get("value");
- var origin = this.minder.queryCommandValue('resource');
- if (!resourceName || !/\S/.test(resourceName)) return;
- if (origin.indexOf(resourceName) == -1) {
- origin.push(resourceName);
- this.minder.execCommand('resource', origin);
- this.addResourceCheckbox(resourceName)
- }
- this.addResourceInput.set("value", "");
- this.fireEvent("postExecCommand", [this, command])
- }.bind(this)
- }
- }).inject(inputContainer);
- this.resourceUsedContainer = new Element("div", {
- styles: this.css.resourceUsedContainer
- }).inject(this.resourceNode);
- this.setScrollBar(this.resourceUsedContainer);
- this.usedResource = this.minder.getUsedResource() || [];
- this.usedResource.each(function (resource) {
- this.addResourceCheckbox(resource)
- }.bind(this));
- this.minder.on('interactchange', function () {
- if (this.queryInteractchange()) {
- this.setResourceCheckbox();
- }
- }.bind(this));
- if( this.minder.queryCommandState('resource') === -1 ){
- this.setResourceDisable();
- }
- },
- setResourceCheckbox: function () {
- var enabled = this.minder.queryCommandState('resource') != -1;
- var origin = enabled ? this.minder.queryCommandValue('resource') : [];
- ( this.resourceCheckbox || [] ).each(function (c) {
- if (origin.contains(c.get("value"))) {
- c.set("checked", true);
- } else {
- c.set("checked", false);
- }
- });
- },
- addResourceCheckbox: function (resourceName) {
- this.resourceCheckbox = this.resourceCheckbox || [];
- var lable = new Element("lable", {
- text: resourceName,
- styles: {
- "float": "left",
- "margin-right": "5px",
- "padding": "5px",
- "background-color": this.minder.getResourceColor(resourceName).toHEX()
- }
- }).inject(this.resourceUsedContainer);
- var checkbox = new Element("input", {
- type: "checkbox",
- value: resourceName,
- checked: true,
- events: {
- change: function () {
- var checked = [];
- this.resourceCheckbox.each(function (c) {
- if (c.get("checked")) {
- checked.push(c.get("value"))
- }
- }.bind({resourceName: resourceName}));
- this.minder.execCommand('resource', checked);
- }.bind(this)
- }
- }).inject(lable, "top");
- this.resourceCheckbox.push(checkbox);
- },
- editNode: function () {
- this.receiver.element.innerText = this.minder.queryCommandValue('text') || "";
- this.fsm.jump('input', 'input-request');
- this.receiver.selectAll();
- },
- openHyperLinkForm: function (command) {
- var form = new MWF.xApplication.MinderEditor.HyperLinkForm(this, {}, {}, {
- app: this.app
- });
- form.edit();
- this.fireEvent("postExecCommand", [this, command])
- },
- openImageForm: function (command) {
- var form = new MWF.xApplication.MinderEditor.ImageForm(this, {}, {}, {
- app: this.app
- });
- form.edit();
- this.fireEvent("postExecCommand", [this, command])
- },
- openNoteForm: function (command) {
- var form = new MWF.xApplication.MinderEditor.NoteForm(this, {}, {}, {
- app: this.app
- });
- form.edit();
- this.fireEvent("postExecCommand", [this, command])
- },
- setNoteDisable: function () {
- if (this.noteTextNode)this.noteTextNode.setStyle("display", "");
- },
- setNoteNormal: function () {
- if (this.noteTextNode)this.noteTextNode.setStyle("display", "none");
- if (!this.codeMirrorEditor)this.createNoteEditor();
- },
- createNoteEditor: function (container) {
- if (container) {
- this.noteContainer = container;
- } else {
- container = this.noteContainer;
- }
- var command = this.commands["note"];
- if (!this.noteTextNode) {
- var titleNode = new Element("div", {
- "text": "备注",
- "styles": this.css.noteTitleNode
- }).inject(container);
- new Element("a", {
- text: "支持GFM语法",
- href: "../x_component_MinderEditor/$Commands/GFMDescription.html",
- "target": "_blank",
- "styles": this.css.noteLinkNode
- }).inject(titleNode);
- this.noteTextNode = new Element("div", {
- text: "请选择节点添加备注",
- "styles": this.css.noteTextNode
- }).inject(container);
- }
- if (this.minder.queryCommandState('note') === -1)return;
- this.noteTextNode.setStyle("display", "none");
- var contentNode = this.noteContentNode = new Element("div", {
- "overflow": "hidden"
- }).inject(container);
- this.isNoteEditing = false;
- this.editor.loadCodeMirror(function () {
- this.noteTextarea = new Element("textarea").inject(contentNode);
- this.codeMirrorEditor = CodeMirror.fromTextArea(this.noteTextarea, {
- value: (this.minder.queryCommandState('note') === -1 || this.minder.queryCommandValue('note')),
- theme: "default",
- gfm: true,
- breaks: true,
- lineWrapping: true,
- mode: 'gfm',
- dragDrop: false,
- lineNumbers: true
- });
- this.codeMirrorEditor.on("change", function () {
- var enabled = this.minder.queryCommandState('note') != -1;
- var content = this.codeMirrorEditor.getValue();
- if (enabled) {
- this.isNoteEditing = true;
- this.minder.execCommand('note', content);
- if (this.noteTimeout)clearTimeout(this.noteTimeout);
- this.noteTimeout = setTimeout(function () {
- this.isNoteEditing = false;
- }.bind(this), 100);
- }
- }.bind(this));
- this.codeMirrorEditor.setSize("100%", container.getSize().y - 30 - 3);
- //this.previewer = new Element("div").inject(container);
- this.minder.on('interactchange', function () {
- if (this.queryInteractchange()) {
- var enabled = this.minder.queryCommandState('note') != -1;
- var noteValue = this.minder.queryCommandValue('note') || '';
- if (enabled) {
- this.codeMirrorEditor.setValue(noteValue);
- }
- }
- }.bind(this));
- //var str = "月份|收入|支出\n"+
- // "----|----|---\n"+
- // "8 |1000|500\n"+
- // "9 |1200|600\n"+
- // "10 |1400|650\n";
- //this.previewer.set("html",marked(str));
- }.bind(this));
- this.fireEvent("postExecCommand", [this, command])
- },
- toggleOpenPreViewer: function(){
- this.previewOpened = !this.previewOpened;
- this.preview.toggleOpen( this.previewOpened );
- },
- initPreViewer: function( container ){
- this.preview = new MWF.xApplication.MinderEditor.Preview( container, this.minder, this.app, this.css );
- this.preview.load();
- this.previewOpened = true;
- },
- initZoomArea : function( container ){
- this.editor.contentNode.addEvent("mousewheel", function (ev) { //鼠标滚轮事件
- if (ev.wheel > 0) { //向上滚动,放大
- this.minder.execCommand('zoomIn');
- if ( this.zoompanIndicator) {
- var marginTop = parseInt(this.zoompanIndicator.getStyle("margin-top"));
- if (marginTop > 0) {
- this.zoompanIndicator.setStyle("margin-top", (marginTop - 10) + "px");
- }
- }
- } else if(ev.wheel < 0) { //向下滚动,缩小
- this.minder.execCommand('zoomOut');
- if ( this.zoompanIndicator) {
- var totalHeight = parseInt(this.zoompan.getStyle("height"));
- var marginTop = parseInt(this.zoompanIndicator.getStyle("margin-top"));
- if (marginTop < totalHeight) {
- this.zoompanIndicator.setStyle("margin-top", (marginTop + 10 ) + "px");
- }
- }
- }
- }.bind(this));
- this.zoomIn = new Element("div",{ "styles" : this.css.zoomButton , "title" : this.lp.zoomin }).inject(container);
- new Element("div",{ "styles" : this.css.zoominIcon }).inject(this.zoomIn);
- this.zoomIn.addEvent("click",function(){
- this.minder.execCommand('zoomIn');
- var marginTop = parseInt( this.zoompanIndicator.getStyle("margin-top"));
- if( marginTop > 0 ){
- this.zoompanIndicator.setStyle( "margin-top", (marginTop - 10) + "px" );
- }
- }.bind(this));
- this.zoompan = new Element("div",{ "styles" : this.css.zoompan }).inject(container);
- this.zoompanOrigin = new Element("div",{ "styles" : this.css.zoompanOrigin }).inject(this.zoompan);
- this.zoompanOrigin.addEvent("click",function(){
- this.minder.execCommand('zoom', 100);
- this.zoompanIndicator.setStyle( "margin-top", "30px" );
- }.bind(this));
- this.zoompanIndicator = new Element("div",{ "styles" : this.css.zoompanIndicator }).inject(this.zoompan);
- this.zoomout = new Element("div",{ "styles" : this.css.zoomButton , "title" : this.lp.zoomout }).inject(container);
- new Element("div",{ "styles" : this.css.zoomoutIcon }).inject(this.zoomout);
- this.zoomout.addEvent("click",function(){
- this.minder.execCommand('zoomOut');
- var totalHeight = parseInt( this.zoompan.getStyle("height") );
- var marginTop = parseInt( this.zoompanIndicator.getStyle("margin-top"));
- if( marginTop < totalHeight ){
- this.zoompanIndicator.setStyle( "margin-top", (marginTop + 10 ) + "px" );
- }
- }.bind(this));
- },
- queryInteractchange: function () {
- return !this.isNoteEditing;
- },
- setSizes : function(){
- if( this.codeMirrorEditor && this.noteContainer ){
- this.codeMirrorEditor.setSize("100%", this.noteContainer.getSize().y - 30 - 3 );
- }
- }
- });
|