Commands.js 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. MWF.xApplication.MinderEditor.Commands = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "type": "common",
  6. "style": "default"
  7. },
  8. initialize: function ( editor, options) {
  9. this.setOptions(options);
  10. this.app = editor;
  11. this.lp = MWF.xApplication.MinderEditor.LP;
  12. //this.actions = this.app.restActions;
  13. this.editor = editor;
  14. this.minder = editor.minder;
  15. if( !editor.debug ){
  16. MWF.xDesktop.requireApp("MinderEditor", "Tools", null, false);
  17. MWF.xDesktop.requireApp("MinderEditor", "RuntimeInCommon", null, false);
  18. MWF.xDesktop.requireApp("MinderEditor", "WidgetInCommon", null, false);
  19. this.editor.debug = new MWF.xApplication.MinderEditor.Debug(true);
  20. }
  21. if( !editor.fsm ){
  22. this.editor.fsm = new MWF.xApplication.MinderEditor.FSM('normal');
  23. }
  24. if( !editor.key ){
  25. this.editor.key = new MWF.xApplication.MinderEditor.Key();
  26. }
  27. if( !editor.receiver ){
  28. this.editor.receiver = new MWF.xApplication.MinderEditor.Receiver(this.editor);
  29. }
  30. this.fsm = this.editor.fsm;
  31. this.receiver = this.editor.receiver;
  32. //this.input = this.editor.input;
  33. //this.drag = this.editor.drag;
  34. this.history = this.editor.history;
  35. //this.key = this.editor.key;
  36. this.path = "../x_component_MinderEditor/$Commands/";
  37. this.cssPath = this.path+this.options.style+"/css.wcss";
  38. this.commands = {
  39. undo: {
  40. icon: "undo",
  41. locale: "撤销",
  42. modle : ["edit"],
  43. key: "Ctrl + Z",
  44. disable: function () {
  45. return this.history.hasUndo() == false;
  46. }.bind(this),
  47. action: function () {
  48. this.history.hasUndo() == false || this.history.undo();
  49. }.bind(this)
  50. },
  51. redo: {
  52. icon: "redo",
  53. locale: "重做",
  54. modle : ["edit"],
  55. key: "Ctrl + Y",
  56. disable: function () {
  57. return this.history.hasRedo() == false;
  58. }.bind(this),
  59. action: function () {
  60. this.history.hasRedo() == false || this.history.redo();
  61. }.bind(this)
  62. },
  63. appendChild: {
  64. icon: "insert_sub",
  65. modle : ["edit"],
  66. locale: "插入下级主题",
  67. key: ["Tab", "Insert"],
  68. isDefaultKey: true,
  69. disable: function () {
  70. return this.minder.queryCommandState('AppendChildNode') === -1;
  71. }.bind(this),
  72. action: function () {
  73. this.minder.queryCommandState('AppendChildNode') === -1 || this.minder.execCommand('AppendChildNode')
  74. }.bind(this)
  75. },
  76. appendParent: {
  77. icon: "insert_par",
  78. modle : ["edit"],
  79. locale: "插入上级主题",
  80. key: "Shit + Tab",
  81. disable: function () {
  82. return this.minder.queryCommandState('AppendParentNode') === -1;
  83. }.bind(this),
  84. action: function () {
  85. this.minder.queryCommandState('AppendParentNode') === -1 || this.minder.execCommand('AppendParentNode')
  86. }.bind(this)
  87. },
  88. appendSibling: {
  89. icon: "insert_sibling",
  90. modle : ["edit"],
  91. locale: "插入同级主题",
  92. key: "Enter",
  93. isDefaultKey: true,
  94. disable: function () {
  95. return this.minder.queryCommandState('AppendSiblingNode') === -1;
  96. }.bind(this),
  97. action: function () {
  98. this.minder.queryCommandState('AppendSiblingNode') === -1 || this.minder.execCommand('AppendSiblingNode')
  99. }.bind(this)
  100. },
  101. arrangeUp: {
  102. icon: "up",
  103. modle : ["edit"],
  104. locale: "上移",
  105. key: "Alt + Up",
  106. isDefaultKey: true,
  107. disable: function () {
  108. return this.minder.queryCommandState('ArrangeUp') === -1
  109. }.bind(this),
  110. action: function () {
  111. this.minder.queryCommandState('ArrangeUp') === -1 || this.minder.execCommand('ArrangeUp')
  112. }.bind(this)
  113. },
  114. arrangeDown: {
  115. icon: "down",
  116. modle : ["edit"],
  117. locale: "下移",
  118. key: "Alt + Down",
  119. isDefaultKey: true,
  120. disable: function () {
  121. return this.minder.queryCommandState('ArrangeDown') === -1
  122. }.bind(this),
  123. action: function () {
  124. this.minder.queryCommandState('ArrangeDown') === -1 || this.minder.execCommand('ArrangeDown')
  125. }.bind(this)
  126. },
  127. edit: {
  128. icon: "edit",
  129. modle : ["edit"],
  130. locale: "编辑",
  131. key: "F2",
  132. disable: function () {
  133. return this.minder.queryCommandState('text') === -1
  134. }.bind(this),
  135. action: function () {
  136. this.minder.queryCommandState('text') === -1 || this.editNode()
  137. }.bind(this)
  138. },
  139. remove: {
  140. icon: "delete",
  141. modle : ["edit"],
  142. locale: "删除",
  143. key: "Delete",
  144. isDefaultKey: true,
  145. disable: function () {
  146. return this.minder.queryCommandState('RemoveNode') === -1
  147. }.bind(this),
  148. action: function () {
  149. this.minder.queryCommandState('RemoveNode') === -1 || this.minder.execCommand('RemoveNode');
  150. }.bind(this)
  151. },
  152. hyperLink: {
  153. icon: "link",
  154. modle : ["edit"],
  155. locale: "链接",
  156. key: "Alt + L",
  157. disable: function () {
  158. return this.minder.queryCommandState('HyperLink') === -1
  159. }.bind(this),
  160. action: function () {
  161. this.minder.queryCommandState('HyperLink') === -1 || this.openHyperLinkForm("hyperLink");
  162. }.bind(this)
  163. },
  164. image: {
  165. icon: "image",
  166. modle : ["edit"],
  167. locale: "图片",
  168. key: "Alt + M",
  169. disable: function () {
  170. return this.minder.queryCommandState('Image') === -1
  171. }.bind(this),
  172. action: function () {
  173. this.minder.queryCommandState('Image') === -1 || this.openImageForm("image");
  174. }.bind(this)
  175. },
  176. note: {
  177. title: "备注",
  178. modle : ["edit"],
  179. disable: function () {
  180. return this.minder.queryCommandState('note') === -1
  181. }.bind(this),
  182. init: function (container, command) {
  183. this.createNoteEditor(container, "note");
  184. }.bind(this),
  185. setDisable: function () {
  186. this.setNoteDisable()
  187. }.bind(this),
  188. setNormal: function () {
  189. this.setNoteNormal()
  190. }.bind(this)
  191. },
  192. priority: {
  193. icon: "priority",
  194. modle : ["edit"],
  195. locale: "优先级",
  196. key: "Alt + G",
  197. disable: function () {
  198. return this.minder.queryCommandState("priority") === -1
  199. }.bind(this),
  200. keyAction: function () {
  201. this.prioritySelector.showTooltip()
  202. }.bind(this),
  203. init: function (container, command) {
  204. this.initPriority(container, command)
  205. }.bind(this)
  206. },
  207. progress: {
  208. icon: "progress",
  209. modle : ["edit"],
  210. locale: "进度",
  211. key: "Alt + P",
  212. disable: function () {
  213. return this.minder.queryCommandState("progress") === -1
  214. }.bind(this),
  215. keyAction: function () {
  216. this.progressSelector.showTooltip()
  217. }.bind(this),
  218. init: function (container, command) {
  219. this.initProgress(container, command)
  220. }.bind(this)
  221. },
  222. resource: {
  223. title: "标签",
  224. modle : ["edit"],
  225. disable: function () {
  226. return this.minder.queryCommandState('resource') === -1
  227. }.bind(this),
  228. init: function (container, command) {
  229. this.initResource(container, command)
  230. }.bind(this),
  231. setDisable: function () {
  232. this.setResourceDisable()
  233. }.bind(this),
  234. setNormal: function () {
  235. this.setResourceNormal()
  236. }.bind(this)
  237. },
  238. template: {
  239. icon: "template",
  240. modle : ["edit","read"],
  241. title: "模板",
  242. disable: function () {
  243. return this.minder.queryCommandState('template') === -1
  244. }.bind(this),
  245. init: function (container, command) {
  246. this.initTemplate(container, command)
  247. }.bind(this)
  248. },
  249. theme: {
  250. icon: "theme",
  251. modle : ["edit","read"],
  252. title: "主题",
  253. disable: function () {
  254. return this.minder.queryCommandState('theme') === -1
  255. }.bind(this),
  256. init: function (container, command) {
  257. this.initTheme(container, command)
  258. }.bind(this)
  259. },
  260. resetlayout: {
  261. icon: "resetlayout",
  262. modle : ["edit","read"],
  263. title: "整理布局",
  264. key: "Ctrl + Shift + L",
  265. isDefaultKey: true,
  266. disable: function () {
  267. return this.minder.queryCommandState('resetlayout') === -1
  268. }.bind(this),
  269. action: function () {
  270. this.minder.queryCommandState('resetlayout') === -1 || this.minder.execCommand('resetlayout');
  271. }.bind(this)
  272. },
  273. clearstyle: {
  274. icon: "clear",
  275. modle : ["edit"],
  276. locale: "清除样式",
  277. disable: function () {
  278. return this.minder.queryCommandState('clearstyle') === -1
  279. }.bind(this),
  280. action: function () {
  281. this.minder.queryCommandState('clearstyle') === -1 || this.minder.execCommand('clearstyle');
  282. }.bind(this)
  283. },
  284. copystyle: {
  285. icon: "copystyle",
  286. modle : ["edit"],
  287. locale: "拷贝样式",
  288. disable: function () {
  289. return this.minder.queryCommandState('copystyle') === -1
  290. }.bind(this),
  291. action: function () {
  292. this.minder.queryCommandState('copystyle') === -1 || this.minder.execCommand('copystyle');
  293. }.bind(this)
  294. },
  295. pastestyle: {
  296. icon: "pastestyle",
  297. modle : ["edit"],
  298. locale: "粘贴样式",
  299. disable: function () {
  300. return this.minder.queryCommandState('pastestyle') === -1
  301. }.bind(this),
  302. action: function () {
  303. this.minder.queryCommandState('pastestyle') === -1 || this.minder.execCommand('pastestyle');
  304. }.bind(this)
  305. },
  306. fontfamily: {
  307. title: "字体",
  308. modle : ["edit"],
  309. //key : "Alt + T",
  310. disable: function () {
  311. return this.minder.queryCommandState('fontfamily') === -1
  312. }.bind(this),
  313. keyAction: function () {
  314. this.fontfamilySelector.showTooltip()
  315. }.bind(this),
  316. init: function (container, command) {
  317. this.initFontFamily(container, command)
  318. }.bind(this)
  319. },
  320. fontsize: {
  321. title: "字号",
  322. modle : ["edit"],
  323. //key : "Alt + H",
  324. disable: function () {
  325. return this.minder.queryCommandState('fontsize') === -1
  326. }.bind(this),
  327. keyAction: function () {
  328. this.fontsizeSelector.showTooltip()
  329. }.bind(this),
  330. init: function (container, command) {
  331. this.initFontSize(container, command)
  332. }.bind(this)
  333. },
  334. italic: {
  335. icon: "italic",
  336. modle : ["edit"],
  337. title: "斜体",
  338. key: "Ctrl + I",
  339. isDefaultKey: true,
  340. disable: function () {
  341. return this.minder.queryCommandState('italic') === -1
  342. }.bind(this),
  343. action: function () {
  344. this.minder.queryCommandState('italic') === -1 || this.minder.execCommand('italic');
  345. }.bind(this)
  346. },
  347. bold: {
  348. icon: "bold",
  349. modle : ["edit"],
  350. title: "加粗",
  351. key: "Ctrl + B",
  352. isDefaultKey: true,
  353. disable: function () {
  354. return this.minder.queryCommandState('bold') === -1
  355. }.bind(this),
  356. action: function () {
  357. this.minder.queryCommandState('bold') === -1 || this.minder.execCommand('bold');
  358. }.bind(this)
  359. },
  360. forecolor: {
  361. icon: "forecolor",
  362. modle : ["edit"],
  363. title: "字体颜色",
  364. action: function () {
  365. ( this.minder.queryCommandState('forecolor') === -1 || !this.currentForecolor ) || this.minder.execCommand('forecolor', this.currentForecolor);
  366. }.bind(this),
  367. disable: function () {
  368. return this.minder.queryCommandState('forecolor') === -1
  369. }.bind(this),
  370. init: function (container, command) {
  371. this.initFontColor(container, command)
  372. }.bind(this)
  373. },
  374. background: {
  375. icon: "background",
  376. modle : ["edit"],
  377. title: "背景颜色",
  378. action: function () {
  379. ( this.minder.queryCommandState('background') === -1 || !this.currentBackgroundcolor ) || this.minder.execCommand('background', this.currentBackgroundcolor);
  380. }.bind(this),
  381. disable: function () {
  382. return this.minder.queryCommandState('background') === -1
  383. }.bind(this),
  384. init: function (container, command) {
  385. this.initBackground(container, command)
  386. }.bind(this)
  387. },
  388. expandLevel: {
  389. icon: "expand",
  390. modle : ["edit","read"],
  391. title: "展开节点",
  392. //key : "Alt + N",
  393. disable: function () {
  394. return false;
  395. }.bind(this),
  396. keyAction: function () {
  397. this.expandlevelSelector.showTooltip()
  398. }.bind(this),
  399. init: function (container, command) {
  400. this.initExpandLevel(container, command)
  401. }.bind(this)
  402. },
  403. selectAll: {
  404. icon: "select",
  405. modle : ["edit","read"],
  406. title: "选择",
  407. //key : "Alt + S",
  408. disable: function () {
  409. return false;
  410. }.bind(this),
  411. keyAction: function () {
  412. this.selectallSelector.showTooltip()
  413. }.bind(this),
  414. init: function (container, command) {
  415. this.initSelectAll(container, command)
  416. }.bind(this)
  417. },
  418. zoom : {
  419. module : ["edit","read"],
  420. title : "缩放",
  421. disable : function(){ return false },
  422. init : function( container, command ){
  423. this.initZoomArea(container, command);
  424. }.bind(this)
  425. },
  426. camera : {
  427. icon: "camera",
  428. module : ["edit","read"],
  429. title : "根节点居中",
  430. disable: function () {
  431. return false;
  432. }.bind(this),
  433. action: function () {
  434. this.minder.execCommand('camera', this.minder.getRoot(), 600);
  435. }.bind(this)
  436. },
  437. preview : {
  438. icon: "preview",
  439. module : ["edit","read"],
  440. title : "预览",
  441. active : true,
  442. disable: function () {
  443. return false;
  444. }.bind(this),
  445. action: function () {
  446. this.toggleOpenPreViewer();
  447. }.bind(this),
  448. setDisable: function () {
  449. }.bind(this),
  450. setNormal: function () {
  451. }.bind(this),
  452. init: function (container, command) {
  453. this.initPreViewer(container)
  454. }.bind(this)
  455. },
  456. move : {
  457. icon: "move",
  458. module : ["edit","read"],
  459. title : "允许拖拽",
  460. disable: function () {
  461. return false;
  462. }.bind(this),
  463. active : false,
  464. setDisable: function () {
  465. }.bind(this),
  466. setNormal: function () {
  467. }.bind(this),
  468. action: function () {
  469. this.minder.execCommand('hand');
  470. }.bind(this)
  471. },
  472. search: {
  473. icon: "search",
  474. module : ["edit","read"],
  475. title : "搜索",
  476. key : "Ctrl + F",
  477. active : false,
  478. setDisable: function () {
  479. }.bind(this),
  480. setNormal: function () {
  481. }.bind(this),
  482. disable: function () {
  483. return false;
  484. }.bind(this),
  485. action : function(){
  486. this.toggerSearch();
  487. }.bind(this),
  488. init: function ( container ) {
  489. this.initSearch( container );
  490. }.bind(this)
  491. },
  492. help : {
  493. icon: "help",
  494. modle : ["edit","read"],
  495. title: "帮助",
  496. key : "Ctrl + Alt + H",
  497. disable: function () {
  498. return false;
  499. }.bind(this),
  500. keyAction: function () {
  501. this.helpTootips.load()
  502. }.bind(this),
  503. init: function (container, command) {
  504. this.initHelp(container, command)
  505. }.bind(this)
  506. },
  507. save : {
  508. icon: "save",
  509. modle : ["edit"],
  510. locale: "保存",
  511. key : "Ctrl + S",
  512. disable: function () {
  513. return false;
  514. }.bind(this),
  515. action: function () {
  516. this.save()
  517. }.bind(this),
  518. init: function (container, command) {
  519. this.initSaveTooltip(container, command)
  520. }.bind(this)
  521. },
  522. export : {
  523. icon: "export",
  524. modle : ["edit"],
  525. locale: "导出",
  526. disable: function () {
  527. return false;
  528. }.bind(this),
  529. init: function (container, command) {
  530. this.initExportTooltip(container, command)
  531. }.bind(this)
  532. },
  533. menu : {
  534. icon: "menu",
  535. modle : ["edit"],
  536. locale: "菜单",
  537. disable: function () {
  538. return false;
  539. }.bind(this),
  540. action: function (ev, node, command) {
  541. this.initMainMenu( node, command)
  542. }.bind(this),
  543. init: function (container, command) {
  544. if( this.app.options.menuAction ){
  545. this.initMainMenu(container, command)
  546. }
  547. }.bind(this)
  548. }
  549. };
  550. for (var name in this.commands) {
  551. this.commands[name].name = name;
  552. }
  553. this.setKeyCommand();
  554. this.tooltipOptions = {
  555. displayDelay : 300,
  556. "onPostCreate": function (tooltips) {
  557. tooltips.node.addEvents({
  558. mouseenter : function(){
  559. var command = tooltips.command;
  560. if (!command.disable()) {
  561. this.setActiveStye(tooltips.target, command)
  562. } else {
  563. this.setDisableStye(tooltips.target, command)
  564. }
  565. }.bind(this)
  566. })
  567. }.bind(this),
  568. "onHide": function (tooltips) {
  569. var command = tooltips.command;
  570. if (!command.disable()) {
  571. this.setNormalStye(tooltips.target, command)
  572. } else {
  573. this.setDisableStye(tooltips.target, command)
  574. }
  575. }.bind(this)
  576. };
  577. this.selectOptions = {
  578. "tooltipsOptions": {
  579. displayDelay : 300,
  580. "onPostCreate": function (tooltips) {
  581. var selector = tooltips.selector;
  582. tooltips.node.addEvents({
  583. mouseenter : function(){
  584. var command = selector.command;
  585. if (!command.disable()) {
  586. this.setActiveStye(selector.container, command)
  587. } else {
  588. this.setDisableStye(selector.container, command)
  589. }
  590. }.bind(this)
  591. })
  592. }.bind(this),
  593. "onQueryLoad": function (tooltips) {
  594. var selector = tooltips.selector;
  595. if ( selector.command ) {
  596. tooltips.disable = selector.command.disable();
  597. }
  598. }.bind(this),
  599. "onPostLoad": function (tooltips) {
  600. var selector = tooltips.selector;
  601. if (selector.selectArrowNode)selector.selectArrowNode.setStyles(selector.css.selectArrowNode_up);
  602. this.activeTooltip = tooltips;
  603. }.bind(this),
  604. "onHide": function (tooltips) {
  605. var selector = tooltips.selector;
  606. if (this.activeTooltip == tooltips)this.activeTooltip = null;
  607. if (selector.selectArrowNode) selector.selectArrowNode.setStyles(selector.css.selectArrowNode);
  608. var command = selector.command;
  609. if (!command.disable()) {
  610. this.setNormalStye(selector.container, command)
  611. } else {
  612. this.setDisableStye(selector.container, command)
  613. }
  614. }.bind(this),
  615. event: "mouseenter" //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  616. }
  617. }
  618. },
  619. load: function () {
  620. this._loadCss();
  621. this.containerObject = {};
  622. this.cssObject = {};
  623. this.itemNodeObject = {};
  624. this.fsm.when('normal -> normal', function (exit, enter, reason, e) {
  625. if (reason == 'shortcut-handle') {
  626. var handleResult = this.dispatchKey(e);
  627. if (handleResult) {
  628. e.preventDefault();
  629. } else {
  630. this.minder.dispatchKeyEvent(e);
  631. }
  632. }
  633. }.bind(this));
  634. this.minder.on('interactchange', function () {
  635. if (this.queryInteractchange()) {
  636. if (this.activeTooltip)this.activeTooltip.hide();
  637. this.checkStatus();
  638. }
  639. }.bind(this));
  640. },
  641. addContainer : function( name, container, css ){
  642. this.containerObject[name] = container;
  643. this.cssObject[ name ] = css;
  644. this.loadItemsByContainer( name );
  645. },
  646. loadItemsByContainer : function( name ){
  647. var container = this.containerObject[name];
  648. var css = this.cssObject[ name ];
  649. container.getElements("[item]").each(function (node) {
  650. if (node.get("lazyLoading") == "true" )return;
  651. this.loadItemNode(node, css);
  652. }.bind(this));
  653. },
  654. loadItemsByNameList : function(nameList,containerName ){
  655. var container = this.containerObject[containerName];
  656. var css = this.cssObject[ containerName ];
  657. container.getElements("[item]").each(function (node) {
  658. var name = node.get("item");
  659. if( nameList.contains( name ) ){
  660. this.loadItemNode( node, css);
  661. }
  662. }.bind(this));
  663. },
  664. loadItemByName: function (name , containerName ) {
  665. var container = this.containerObject[containerName];
  666. var css = this.cssObject[ containerName ];
  667. var node = container.getElement("[item='" + name + "']");
  668. this.loadItemNode( node, css);
  669. },
  670. getItemNode : function( name, containerName ){
  671. var container = this.containerObject[containerName];
  672. var node = container.getElement("[item='" + name + "']");
  673. return node;
  674. },
  675. loadItemNode: function (node, css) {
  676. var _self = this;
  677. node.store( "css", css );
  678. var name = node.get("item");
  679. var subtype = node.get("subtype");
  680. var event = node.get("itemevent");
  681. if (this.commands[name]) {
  682. var command = this.commands[name];
  683. if( !subtype || subtype=="button" ){
  684. this.itemNodeObject[name] = node;
  685. if( command.active ){
  686. node.setStyles( css[node.get("styles") ]);
  687. this.setActiveStye(node, command);
  688. node.store("active",true);
  689. }else if (command.disable()) {
  690. node.setStyles( css[node.get("styles") ]);
  691. this.setDisableStye(node, command)
  692. } else {
  693. this.setNormalStye(node, command)
  694. }
  695. var title = (command.title || ""); //+ ( command.key ? (" 快捷键:" + command.key) : "" );
  696. node.set("title", title);
  697. if( !event || event=="mouseover" ){
  698. node.addEvents({
  699. mouseover : function () {
  700. if (!command.disable()) {
  701. this.setActiveStye(node, command)
  702. } else {
  703. this.setDisableStye(node, command)
  704. }
  705. }.bind(this),
  706. mouseleave : function () {
  707. if (!command.disable()) {
  708. this.setNormalStye(node, command)
  709. } else {
  710. this.setDisableStye(node, command)
  711. }
  712. }.bind(this)
  713. });
  714. }else{
  715. node.addEvents({
  716. click: function () {
  717. if ( !node.retrieve("active")) {
  718. this.setActiveStye(node, command);
  719. node.store("active",true)
  720. } else {
  721. this.setNormalStye(node, command);
  722. node.store("active",false)
  723. }
  724. }.bind(this)
  725. });
  726. }
  727. var div = new Element("div", {
  728. "text": command.locale || null
  729. }).inject(node);
  730. if (command.action) {
  731. node.addEvent("click", function (ev) {
  732. if (!command.disable()) {
  733. command.action( ev, node, command );
  734. _self.fireEvent("postExecCommand", [_self, this])
  735. }
  736. }.bind(name))
  737. }
  738. }
  739. if( !subtype || subtype=="container" ){
  740. if (command.init) {
  741. command.init(node, command);
  742. if( command.active === false ){
  743. node.setStyle("display","none")
  744. }
  745. }
  746. }
  747. }
  748. },
  749. setDisableStye: function (node, command) {
  750. var css = node.retrieve("css");
  751. node.setStyles(css[node.get("styles") + "_disable"]);
  752. if (command.icon) {
  753. node.setStyle("background-image", "url(../x_component_MinderEditor/$Main/" + this.options.style + "/icon/" + command.icon + "_disable.png)");
  754. }
  755. },
  756. setActiveStye: function (node, command) {
  757. var css = node.retrieve("css");
  758. node.setStyles(css[node.get("styles") + "_over"]);
  759. if (command.icon) {
  760. node.setStyle("background-image", "url(../x_component_MinderEditor/$Main/" + this.options.style + "/icon/" + command.icon + "_active.png)")
  761. }
  762. },
  763. setNormalStye: function (node, command) {
  764. var css = node.retrieve("css");
  765. node.setStyles(css[node.get("styles")]);
  766. if (command.icon) {
  767. node.setStyle("background-image", "url(../x_component_MinderEditor/$Main/" + this.options.style + "/icon/" + command.icon + "_normal.png)")
  768. }
  769. },
  770. checkStatus: function () {
  771. for (var name in this.itemNodeObject) {
  772. var node = this.itemNodeObject[name];
  773. var name = node.get("item");
  774. if (this.commands[name]) {
  775. var command = this.commands[name];
  776. if (command.disable()) {
  777. command.setDisable ? command.setDisable() : this.setDisableStye(node, command);
  778. } else {
  779. command.setNormal ? command.setNormal() : this.setNormalStye(node, command)
  780. }
  781. }
  782. }
  783. },
  784. setKeyCommand: function () {
  785. this.keyCommands = {};
  786. this.defaultKeyCommands = {};
  787. for (var name in this.commands) {
  788. var command = this.commands[name];
  789. if (command.key) {
  790. var commands = command.isDefaultKey ? this.defaultKeyCommands : this.keyCommands;
  791. if (typeOf(command.key) == "array") {
  792. for (var i = 0; i < command.key.length; i++) {
  793. commands[command.key[i]] = command;
  794. }
  795. } else {
  796. commands[command.key] = command;
  797. }
  798. }
  799. }
  800. },
  801. getKey: function (e) {
  802. var controlKeys = [];
  803. if (e.ctrlKey)controlKeys.push("Ctrl");
  804. if (e.shiftKey)controlKeys.push("Shift");
  805. if (e.altKey)controlKeys.push("Alt");
  806. if (![16, 17, 18].contains(e.keyCode)) { //16 是 Shift, 17 是 Ctrl, 18 是Alt
  807. return controlKeys.length == 0 ? e.key.capitalize() : ( controlKeys.join(" + ") + " + " + e.key.capitalize() );
  808. } else {
  809. return controlKeys.join(" + ");
  810. }
  811. },
  812. dispatchKey: function (e, callback) {
  813. var key = this.getKey(e);
  814. var command = this.keyCommands[key];
  815. if (command && !command.disable() && this.itemNodeObject[command.name]) {
  816. if (command.action) {
  817. command.action();
  818. if (callback)callback(e, true);
  819. return true;
  820. } else if (command.keyAction) {
  821. if (this.activeTooltip)this.activeTooltip.hide();
  822. command.keyAction();
  823. if (callback)callback(e, true);
  824. return true;
  825. } else {
  826. if (callback)callback(e, true);
  827. return false;
  828. }
  829. } else {
  830. if (callback)callback(e, false);
  831. return false;
  832. }
  833. },
  834. save : function(){
  835. this.editor.save();
  836. },
  837. initSelectAll: function (container, command) {
  838. var selector = this.selectallSelector = new MWF.xApplication.MinderEditor.SelectAll(container, Object.merge(Object.clone(this.selectOptions), {
  839. "onSelectItem": function (itemNode, itemData) {
  840. this.fireEvent("postExecCommand", [this, command])
  841. }.bind(this)
  842. }), this.app, null, this.app.node);
  843. selector.command = command;
  844. selector.load();
  845. },
  846. initExpandLevel: function (container, command) {
  847. var selector = this.expandlevelSelector = new MWF.xApplication.MinderEditor.ExpandLevel(container, Object.merge(Object.clone(this.selectOptions), {
  848. "onSelectItem": function (itemNode, itemData) {
  849. this.minder.execCommand('ExpandToLevel', itemData.value);
  850. this.fireEvent("postExecCommand", [this, command])
  851. }.bind(this)
  852. }), this.app, null, this.app.node);
  853. selector.command = command;
  854. selector.load();
  855. },
  856. initBackground: function (container, command) {
  857. var selector = this.backgroundSelector = new MWF.xApplication.Template.widget.ColorPicker(this.app.node, container, this.app, {},
  858. Object.merge( this.tooltipOptions, {
  859. "onQueryLoad": function (tooltips) {
  860. tooltips.disable = this.commands.background.disable();
  861. }.bind(this),
  862. "onSelect": function (color) {
  863. this.currentBackgroundcolor = color;
  864. this.minder.queryCommandState('background') === -1 || this.minder.execCommand('background', color);
  865. this.fireEvent("postExecCommand", [this, command])
  866. }.bind(this)
  867. } ));
  868. selector.command = command;
  869. },
  870. initFontColor: function (container, command) {
  871. var selector = this.forecolorSelector = new MWF.xApplication.Template.widget.ColorPicker(this.app.node, container, this.app, {},
  872. Object.merge( this.tooltipOptions, {
  873. "onQueryLoad": function (tooltips) {
  874. tooltips.disable = this.commands.forecolor.disable();
  875. }.bind(this),
  876. "onSelect": function (forecolor) {
  877. this.currentForecolor = forecolor;
  878. this.minder.queryCommandState('forecolor') === -1 || this.minder.execCommand('forecolor', forecolor);
  879. this.fireEvent("postExecCommand", [this, command])
  880. }.bind(this)
  881. })
  882. );
  883. selector.command = command;
  884. },
  885. initFontFamily: function (container, command) {
  886. var selector = this.fontfamilySelector = new MWF.xApplication.MinderEditor.FontFamily(container, Object.merge(Object.clone(this.selectOptions), {
  887. "containerIsTarget": false,
  888. "onPostLoad" : function( selector ){
  889. selector.selectValueNode.addEvent( "click", function(){
  890. if( selector.currentItemData ){
  891. this.minder.queryCommandState('fontfamily') === -1 || this.minder.execCommand('fontfamily', selector.currentItemData.val);
  892. }
  893. }.bind(this))
  894. }.bind(this),
  895. "onSelectItem": function (itemNode, itemData) {
  896. this.minder.queryCommandState('fontfamily') === -1 || this.minder.execCommand('fontfamily', itemData.val);
  897. this.fireEvent("postExecCommand", [this, command])
  898. }.bind(this)
  899. }), this.app, null, this.app.node);
  900. selector.command = command;
  901. selector.load();
  902. },
  903. initFontSize: function (container, command) {
  904. var selector = this.fontsizeSelector = new MWF.xApplication.MinderEditor.FontSize(container, Object.merge(Object.clone(this.selectOptions), {
  905. "containerIsTarget": false,
  906. "onPostLoad" : function( selector ){
  907. selector.selectValueNode.addEvent( "click", function(){
  908. if( selector.currentItemData ){
  909. this.minder.queryCommandState('fontsize') === -1 || this.minder.execCommand('fontsize', selector.currentItemData.value);
  910. }
  911. }.bind(this))
  912. }.bind(this),
  913. "onSelectItem": function (itemNode, itemData) {
  914. this.minder.queryCommandState('fontsize') === -1 || this.minder.execCommand('fontsize', itemData.value);
  915. this.fireEvent("postExecCommand", [this, command])
  916. }.bind(this)
  917. }), this.app, null, this.app.node);
  918. selector.command = command;
  919. selector.load();
  920. },
  921. initTheme: function (container, command) {
  922. var _self = this;
  923. var selector = this.themeSelector = new MWF.xApplication.MinderEditor.Theme(container, Object.merge(Object.clone(this.selectOptions), {
  924. "style": "minderTheme",
  925. "containerIsTarget": true,
  926. "onPostCreateItem": function (itemNode, itemData) {
  927. itemNode.setStyles(_self.getThemeThumbStyle(itemData.command));
  928. },
  929. "onSelectItem": function (itemNode, itemData) {
  930. this.minder.queryCommandState('theme') === -1 || this.minder.execCommand('theme', itemData.command);
  931. this.fireEvent("postExecCommand", [this, command])
  932. }.bind(this)
  933. }), this.app, null, this.app.node);
  934. selector.command = command;
  935. selector.load();
  936. },
  937. initTemplate: function (container, command) {
  938. var _self = this;
  939. var selector = this.templateSelector = new MWF.xApplication.MinderEditor.Template(container, Object.merge(Object.clone(this.selectOptions), {
  940. "style": "minderTemplate",
  941. "containerIsTarget": true,
  942. "onSelectItem": function (itemNode, itemData) {
  943. this.minder.execCommand('template', itemData.command);
  944. this.fireEvent("postExecCommand", [this, command])
  945. }.bind(this)
  946. }), this.app, null, this.app.node);
  947. selector.command = command;
  948. selector.load();
  949. },
  950. initPriority: function (container, command) {
  951. var _self = this;
  952. var selector = this.prioritySelector = new MWF.xApplication.MinderEditor.PriorityImage(container, Object.merge(Object.clone(this.selectOptions), {
  953. "containerIsTarget": true,
  954. "onSelectItem": function (itemNode, itemData) {
  955. var val = itemData.command == "0" ? null : parseInt(itemData.command);
  956. this.minder.execCommand('priority', val);
  957. this.fireEvent("postExecCommand", [this, command])
  958. }.bind(this)
  959. }), this.app, null, this.app.node);
  960. selector.command = command;
  961. selector.load();
  962. this.minder.on('interactchange', function () {
  963. if (this.queryInteractchange()) {
  964. var enabled = this.minder.queryCommandState('priority') != -1;
  965. if (enabled) {
  966. var priority = this.minder.queryCommandValue('priority') || "0";
  967. selector.setValue(priority);
  968. }
  969. }
  970. }.bind(this));
  971. },
  972. initProgress: function (container, command) {
  973. var _self = this;
  974. var selector = this.progressSelector = new MWF.xApplication.MinderEditor.ProgressImage(container, Object.merge(Object.clone(this.selectOptions), {
  975. "containerIsTarget": true,
  976. "onSelectItem": function (itemNode, itemData) {
  977. var val = itemData.command == "0" ? null : parseInt(itemData.command);
  978. this.minder.execCommand('progress', val);
  979. this.fireEvent("postExecCommand", [this, command])
  980. }.bind(this)
  981. }), this.app, null, this.app.node);
  982. selector.command = command;
  983. selector.load();
  984. this.minder.on('interactchange', function () {
  985. if (this.queryInteractchange()) {
  986. var enabled = this.minder.queryCommandState('progress') != -1;
  987. if (enabled) {
  988. var progress = this.minder.queryCommandValue('progress') || "0";
  989. selector.setValue(progress);
  990. }
  991. }
  992. }.bind(this));
  993. },
  994. getThemeThumbStyle: function (theme) {
  995. var themeList = this.themeList = this.themeList || kityminder.Minder.getThemeList();
  996. var themeObj = themeList[theme];
  997. if (!themeObj) {
  998. return;
  999. }
  1000. var style = {
  1001. 'color': themeObj['root-color'],
  1002. 'border-radius': themeObj['root-radius'] / 2
  1003. };
  1004. if (themeObj['root-background']) {
  1005. style['background'] = themeObj['root-background'].toString();
  1006. }
  1007. return style;
  1008. },
  1009. toggerSearch : function(){
  1010. if( !this.isSearchbarActive ){
  1011. this.searchBar.show();
  1012. //this.isSearchbarActive = true;
  1013. }else{
  1014. this.searchBar.hide();
  1015. //this.isSearchbarActive = false;
  1016. }
  1017. },
  1018. initSearch : function(container){
  1019. this.minder.on('searchNode', function() {
  1020. this.itemNodeObject.search.click();
  1021. }.bind(this));
  1022. this.searchBar = new MWF.xApplication.MinderEditor.SearchBar( container, this.minder, this.app, this.css, {
  1023. onShow : function(){
  1024. this.setActiveStye( this.itemNodeObject.search, "search" );
  1025. this.isSearchbarActive = true;
  1026. }.bind(this),
  1027. onHide : function(){
  1028. this.setNormalStye( this.itemNodeObject.search, "search" );
  1029. this.isSearchbarActive = false;
  1030. }.bind(this)
  1031. } );
  1032. this.isSearchbarActive = false;
  1033. this.searchBar.load();
  1034. },
  1035. initHelp: function (container, command) {
  1036. var _self = this;
  1037. this.helpTootips = new MWF.xApplication.MinderEditor.Help(this.app.node, container, this.app, {},
  1038. this.tooltipOptions );
  1039. this.helpTootips.commands = this;
  1040. this.helpTootips.command = command;
  1041. },
  1042. initSaveTooltip : function( container, command ){
  1043. this.savetooltip = new MWF.xApplication.MinderEditor.SaveTooltips(this.app.node, container, this.app, {},
  1044. this.tooltipOptions);
  1045. this.savetooltip.command = command;
  1046. },
  1047. initExportTooltip : function( container, command ){
  1048. this.exporttooltip = new MWF.xApplication.MinderEditor.ExportTooltips(this.app.node, container, this.app, {},
  1049. this.tooltipOptions);
  1050. this.exporttooltip.command = command;
  1051. },
  1052. initMainMenu : function( container, command ){
  1053. var _self = this;
  1054. if( !this.mainMenu ){
  1055. MWF.xDesktop.requireApp("MinderEditor", "MainMenu", null, false);
  1056. this.mainMenu = new MWF.xApplication.MinderEditor.MainMenu(this.app.content, this.app, {
  1057. "onShow": function () {
  1058. if (!this.command.disable()) {
  1059. _self.setActiveStye(this.container, this.command)
  1060. } else {
  1061. _self.setDisableStye(this.container, this.command)
  1062. }
  1063. }.bind({ container : container, command : command }),
  1064. "onHide": function () {
  1065. if (!this.command.disable()) {
  1066. _self.setNormalStye(this.container, this.command)
  1067. } else {
  1068. _self.setDisableStye(this.container, this.command)
  1069. }
  1070. }.bind({ container : container, command : command })
  1071. });
  1072. this.mainMenu.command = command;
  1073. }else{
  1074. if( this.mainMenu.isHidden ){
  1075. this.mainMenu.show();
  1076. }else{
  1077. this.mainMenu.hide();
  1078. }
  1079. }
  1080. },
  1081. setResourceDisable: function () {
  1082. if (!this.resourceMaskNode) {
  1083. this.resourceMaskNode = new Element("div.maskNode", {
  1084. "styles": this.css.resourceMaskNode
  1085. }).inject(this.resourceNode);
  1086. } else {
  1087. this.resourceMaskNode.setStyle("display", "");
  1088. }
  1089. this.addResourceInput.placeholder = "选择节点编辑标签";
  1090. },
  1091. setResourceNormal: function () {
  1092. if (this.resourceMaskNode)this.resourceMaskNode.setStyle("display", "none");
  1093. this.addResourceInput.placeholder = "输入文字添加标签";
  1094. },
  1095. initResource: function (container, command) {
  1096. this.resourceNode = new Element("div.resourceNode", {
  1097. styles: this.css.resourceNode
  1098. }).inject(container);
  1099. var inputContainer = new Element("div", {styles: {overflow: "hidden"}}).inject(this.resourceNode);
  1100. this.addResourceInput = new Element("input", {
  1101. placeholder: "输入文字添加标签", styles: this.css.addResourceInput
  1102. }).inject(inputContainer);
  1103. this.addResourceBotton = new Element("div", {
  1104. text: "添加",
  1105. styles: this.css.addResourceBotton,
  1106. events: {
  1107. click: function () {
  1108. var resourceName = this.addResourceInput.get("value");
  1109. var origin = this.minder.queryCommandValue('resource');
  1110. if (!resourceName || !/\S/.test(resourceName)) return;
  1111. if (origin.indexOf(resourceName) == -1) {
  1112. origin.push(resourceName);
  1113. this.minder.execCommand('resource', origin);
  1114. this.addResourceCheckbox(resourceName)
  1115. }
  1116. this.addResourceInput.set("value", "");
  1117. this.fireEvent("postExecCommand", [this, command])
  1118. }.bind(this)
  1119. }
  1120. }).inject(inputContainer);
  1121. this.resourceUsedContainer = new Element("div", {
  1122. styles: this.css.resourceUsedContainer
  1123. }).inject(this.resourceNode);
  1124. this.setScrollBar(this.resourceUsedContainer);
  1125. this.usedResource = this.minder.getUsedResource() || [];
  1126. this.usedResource.each(function (resource) {
  1127. this.addResourceCheckbox(resource)
  1128. }.bind(this));
  1129. this.minder.on('interactchange', function () {
  1130. if (this.queryInteractchange()) {
  1131. this.setResourceCheckbox();
  1132. }
  1133. }.bind(this));
  1134. if( this.minder.queryCommandState('resource') === -1 ){
  1135. this.setResourceDisable();
  1136. }
  1137. },
  1138. setResourceCheckbox: function () {
  1139. var enabled = this.minder.queryCommandState('resource') != -1;
  1140. var origin = enabled ? this.minder.queryCommandValue('resource') : [];
  1141. ( this.resourceCheckbox || [] ).each(function (c) {
  1142. if (origin.contains(c.get("value"))) {
  1143. c.set("checked", true);
  1144. } else {
  1145. c.set("checked", false);
  1146. }
  1147. });
  1148. },
  1149. addResourceCheckbox: function (resourceName) {
  1150. this.resourceCheckbox = this.resourceCheckbox || [];
  1151. var lable = new Element("lable", {
  1152. text: resourceName,
  1153. styles: {
  1154. "float": "left",
  1155. "margin-right": "5px",
  1156. "padding": "5px",
  1157. "background-color": this.minder.getResourceColor(resourceName).toHEX()
  1158. }
  1159. }).inject(this.resourceUsedContainer);
  1160. var checkbox = new Element("input", {
  1161. type: "checkbox",
  1162. value: resourceName,
  1163. checked: true,
  1164. events: {
  1165. change: function () {
  1166. var checked = [];
  1167. this.resourceCheckbox.each(function (c) {
  1168. if (c.get("checked")) {
  1169. checked.push(c.get("value"))
  1170. }
  1171. }.bind({resourceName: resourceName}));
  1172. this.minder.execCommand('resource', checked);
  1173. }.bind(this)
  1174. }
  1175. }).inject(lable, "top");
  1176. this.resourceCheckbox.push(checkbox);
  1177. },
  1178. editNode: function () {
  1179. this.receiver.element.innerText = this.minder.queryCommandValue('text') || "";
  1180. this.fsm.jump('input', 'input-request');
  1181. this.receiver.selectAll();
  1182. },
  1183. openHyperLinkForm: function (command) {
  1184. var form = new MWF.xApplication.MinderEditor.HyperLinkForm(this, {}, {}, {
  1185. app: this.app
  1186. });
  1187. form.edit();
  1188. this.fireEvent("postExecCommand", [this, command])
  1189. },
  1190. openImageForm: function (command) {
  1191. var form = new MWF.xApplication.MinderEditor.ImageForm(this, {}, {}, {
  1192. app: this.app
  1193. });
  1194. form.edit();
  1195. this.fireEvent("postExecCommand", [this, command])
  1196. },
  1197. openNoteForm: function (command) {
  1198. var form = new MWF.xApplication.MinderEditor.NoteForm(this, {}, {}, {
  1199. app: this.app
  1200. });
  1201. form.edit();
  1202. this.fireEvent("postExecCommand", [this, command])
  1203. },
  1204. setNoteDisable: function () {
  1205. if (this.noteTextNode)this.noteTextNode.setStyle("display", "");
  1206. },
  1207. setNoteNormal: function () {
  1208. if (this.noteTextNode)this.noteTextNode.setStyle("display", "none");
  1209. if (!this.codeMirrorEditor)this.createNoteEditor();
  1210. },
  1211. createNoteEditor: function (container) {
  1212. if (container) {
  1213. this.noteContainer = container;
  1214. } else {
  1215. container = this.noteContainer;
  1216. }
  1217. var command = this.commands["note"];
  1218. if (!this.noteTextNode) {
  1219. var titleNode = new Element("div", {
  1220. "text": "备注",
  1221. "styles": this.css.noteTitleNode
  1222. }).inject(container);
  1223. new Element("a", {
  1224. text: "支持GFM语法",
  1225. href: "../x_component_MinderEditor/$Commands/GFMDescription.html",
  1226. "target": "_blank",
  1227. "styles": this.css.noteLinkNode
  1228. }).inject(titleNode);
  1229. this.noteTextNode = new Element("div", {
  1230. text: "请选择节点添加备注",
  1231. "styles": this.css.noteTextNode
  1232. }).inject(container);
  1233. }
  1234. if (this.minder.queryCommandState('note') === -1)return;
  1235. this.noteTextNode.setStyle("display", "none");
  1236. var contentNode = this.noteContentNode = new Element("div", {
  1237. "overflow": "hidden"
  1238. }).inject(container);
  1239. this.isNoteEditing = false;
  1240. this.editor.loadCodeMirror(function () {
  1241. this.noteTextarea = new Element("textarea").inject(contentNode);
  1242. this.codeMirrorEditor = CodeMirror.fromTextArea(this.noteTextarea, {
  1243. value: (this.minder.queryCommandState('note') === -1 || this.minder.queryCommandValue('note')),
  1244. theme: "default",
  1245. gfm: true,
  1246. breaks: true,
  1247. lineWrapping: true,
  1248. mode: 'gfm',
  1249. dragDrop: false,
  1250. lineNumbers: true
  1251. });
  1252. this.codeMirrorEditor.on("change", function () {
  1253. var enabled = this.minder.queryCommandState('note') != -1;
  1254. var content = this.codeMirrorEditor.getValue();
  1255. if (enabled) {
  1256. this.isNoteEditing = true;
  1257. this.minder.execCommand('note', content);
  1258. if (this.noteTimeout)clearTimeout(this.noteTimeout);
  1259. this.noteTimeout = setTimeout(function () {
  1260. this.isNoteEditing = false;
  1261. }.bind(this), 100);
  1262. }
  1263. }.bind(this));
  1264. this.codeMirrorEditor.setSize("100%", container.getSize().y - 30 - 3);
  1265. //this.previewer = new Element("div").inject(container);
  1266. this.minder.on('interactchange', function () {
  1267. if (this.queryInteractchange()) {
  1268. var enabled = this.minder.queryCommandState('note') != -1;
  1269. var noteValue = this.minder.queryCommandValue('note') || '';
  1270. if (enabled) {
  1271. this.codeMirrorEditor.setValue(noteValue);
  1272. }
  1273. }
  1274. }.bind(this));
  1275. //var str = "月份|收入|支出\n"+
  1276. // "----|----|---\n"+
  1277. // "8 |1000|500\n"+
  1278. // "9 |1200|600\n"+
  1279. // "10 |1400|650\n";
  1280. //this.previewer.set("html",marked(str));
  1281. }.bind(this));
  1282. this.fireEvent("postExecCommand", [this, command])
  1283. },
  1284. toggleOpenPreViewer: function(){
  1285. this.previewOpened = !this.previewOpened;
  1286. this.preview.toggleOpen( this.previewOpened );
  1287. },
  1288. initPreViewer: function( container ){
  1289. this.preview = new MWF.xApplication.MinderEditor.Preview( container, this.minder, this.app, this.css );
  1290. this.preview.load();
  1291. this.previewOpened = true;
  1292. },
  1293. initZoomArea : function( container ){
  1294. this.editor.contentNode.addEvent("mousewheel", function (ev) { //鼠标滚轮事件
  1295. if (ev.wheel > 0) { //向上滚动,放大
  1296. this.minder.execCommand('zoomIn');
  1297. if ( this.zoompanIndicator) {
  1298. var marginTop = parseInt(this.zoompanIndicator.getStyle("margin-top"));
  1299. if (marginTop > 0) {
  1300. this.zoompanIndicator.setStyle("margin-top", (marginTop - 10) + "px");
  1301. }
  1302. }
  1303. } else if(ev.wheel < 0) { //向下滚动,缩小
  1304. this.minder.execCommand('zoomOut');
  1305. if ( this.zoompanIndicator) {
  1306. var totalHeight = parseInt(this.zoompan.getStyle("height"));
  1307. var marginTop = parseInt(this.zoompanIndicator.getStyle("margin-top"));
  1308. if (marginTop < totalHeight) {
  1309. this.zoompanIndicator.setStyle("margin-top", (marginTop + 10 ) + "px");
  1310. }
  1311. }
  1312. }
  1313. }.bind(this));
  1314. this.zoomIn = new Element("div",{ "styles" : this.css.zoomButton , "title" : this.lp.zoomin }).inject(container);
  1315. new Element("div",{ "styles" : this.css.zoominIcon }).inject(this.zoomIn);
  1316. this.zoomIn.addEvent("click",function(){
  1317. this.minder.execCommand('zoomIn');
  1318. var marginTop = parseInt( this.zoompanIndicator.getStyle("margin-top"));
  1319. if( marginTop > 0 ){
  1320. this.zoompanIndicator.setStyle( "margin-top", (marginTop - 10) + "px" );
  1321. }
  1322. }.bind(this));
  1323. this.zoompan = new Element("div",{ "styles" : this.css.zoompan }).inject(container);
  1324. this.zoompanOrigin = new Element("div",{ "styles" : this.css.zoompanOrigin }).inject(this.zoompan);
  1325. this.zoompanOrigin.addEvent("click",function(){
  1326. this.minder.execCommand('zoom', 100);
  1327. this.zoompanIndicator.setStyle( "margin-top", "30px" );
  1328. }.bind(this));
  1329. this.zoompanIndicator = new Element("div",{ "styles" : this.css.zoompanIndicator }).inject(this.zoompan);
  1330. this.zoomout = new Element("div",{ "styles" : this.css.zoomButton , "title" : this.lp.zoomout }).inject(container);
  1331. new Element("div",{ "styles" : this.css.zoomoutIcon }).inject(this.zoomout);
  1332. this.zoomout.addEvent("click",function(){
  1333. this.minder.execCommand('zoomOut');
  1334. var totalHeight = parseInt( this.zoompan.getStyle("height") );
  1335. var marginTop = parseInt( this.zoompanIndicator.getStyle("margin-top"));
  1336. if( marginTop < totalHeight ){
  1337. this.zoompanIndicator.setStyle( "margin-top", (marginTop + 10 ) + "px" );
  1338. }
  1339. }.bind(this));
  1340. },
  1341. queryInteractchange: function () {
  1342. return !this.isNoteEditing;
  1343. },
  1344. setSizes : function(){
  1345. if( this.codeMirrorEditor && this.noteContainer ){
  1346. this.codeMirrorEditor.setSize("100%", this.noteContainer.getSize().y - 30 - 3 );
  1347. }
  1348. }
  1349. });