WidgetInCommon.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. MWF.xDesktop.requireApp("Template", "MSelector", null, false);
  2. MWF.xApplication.MinderEditor.ExpandLevel = new Class({
  3. Extends: MSelector,
  4. options : {
  5. "style": "arrow",
  6. "width": "150px",
  7. "height": "30px",
  8. "textField" : "text",
  9. "valueField" : "value",
  10. "defaultOptionLp" : "展开节点",
  11. "isSetSelectedValue" : false,
  12. "isChangeOptionStyle" : false,
  13. "emptyOptionEnable" : false,
  14. "event" : "mouseenter",
  15. "containerIsTarget" : true,
  16. "tooltipsOptions" : {
  17. axis : "x",
  18. hasArrow : true
  19. }
  20. },
  21. _selectItem : function( itemNode, itemData ){
  22. },
  23. _loadData : function( callback ){
  24. var levelList = [
  25. {
  26. value : '1',
  27. text : "展开到一级节点"
  28. },{
  29. value : '2',
  30. text : "展开到二级节点"
  31. },{
  32. value : '3',
  33. text : "展开到三级节点"
  34. },{
  35. value : '4',
  36. text : "展开到四级节点"
  37. },{
  38. value : '5',
  39. text : "展开到五级节点"
  40. },{
  41. value : '6',
  42. text : "展开到六级节点"
  43. },{
  44. value : '999',
  45. text : "展开全部"
  46. }
  47. ];
  48. if(callback)callback( levelList );
  49. },
  50. _postCreateItem: function( itemNode, data ){
  51. itemNode.setStyles( {
  52. "font-size" : "14px",
  53. "min-height" : "26px",
  54. "line-height" : "26px"
  55. } );
  56. }
  57. });
  58. MWF.xApplication.MinderEditor.SelectAll = new Class({
  59. Extends: MSelector,
  60. options : {
  61. "style": "arrow",
  62. "width": "150px",
  63. "height": "30px",
  64. "textField" : "text",
  65. "valueField" : "value",
  66. "defaultOptionLp" : "选择节点",
  67. "isSetSelectedValue" : false,
  68. "isChangeOptionStyle" : false,
  69. "emptyOptionEnable" : false,
  70. "event" : "mouseenter",
  71. "containerIsTarget" : true,
  72. "tooltipsOptions" : {
  73. axis : "x",
  74. hasArrow : true
  75. }
  76. },
  77. _selectItem : function( itemNode, itemData ){
  78. },
  79. _loadData : function( callback ){
  80. var levelList = [
  81. {
  82. value : 'all',
  83. text : "全选"
  84. },{
  85. value : 'revert',
  86. text : "反选"
  87. },{
  88. value : 'siblings',
  89. text : "选择兄弟节点"
  90. },{
  91. value : 'level',
  92. text : "选择同级节点"
  93. },{
  94. value : 'path_',
  95. text : "选择路径"
  96. },{
  97. value : 'tree',
  98. text : "选择子树"
  99. }
  100. ];
  101. if(callback)callback( levelList );
  102. },
  103. _postCreateItem: function( itemNode, data ){
  104. itemNode.setStyles( {
  105. "font-size" : "14px",
  106. "min-height" : "26px",
  107. "line-height" : "26px"
  108. } );
  109. },
  110. _selectItem : function( itemNode, itemData ){
  111. this[ itemData.value ]();
  112. },
  113. all: function() {
  114. var selection = [];
  115. this.app.minder.getRoot().traverse(function(node) {
  116. selection.push(node);
  117. });
  118. this.app.minder.select(selection, true);
  119. this.app.minder.fire('receiverfocus');
  120. },
  121. revert: function() {
  122. var selected = this.app.minder.getSelectedNodes();
  123. var selection = [];
  124. this.app.minder.getRoot().traverse(function(node) {
  125. if (selected.indexOf(node) == -1) {
  126. selection.push(node);
  127. }
  128. });
  129. this.app.minder.select(selection, true);
  130. this.app.minder.fire('receiverfocus');
  131. },
  132. siblings: function() {
  133. var selected = this.app.minder.getSelectedNodes();
  134. var selection = [];
  135. selected.forEach(function(node) {
  136. if (!node.parent) return;
  137. node.parent.children.forEach(function(sibling) {
  138. if (selection.indexOf(sibling) == -1) selection.push(sibling);
  139. });
  140. });
  141. this.app.minder.select(selection, true);
  142. this.app.minder.fire('receiverfocus');
  143. },
  144. level: function() {
  145. var selectedLevel = this.app.minder.getSelectedNodes().map(function(node) {
  146. return node.getLevel();
  147. });
  148. var selection = [];
  149. this.app.minder.getRoot().traverse(function(node) {
  150. if (selectedLevel.indexOf(node.getLevel()) != -1) {
  151. selection.push(node);
  152. }
  153. });
  154. this.app.minder.select(selection, true);
  155. this.app.minder.fire('receiverfocus');
  156. },
  157. path_: function() {
  158. var selected = this.app.minder.getSelectedNodes();
  159. var selection = [];
  160. selected.forEach(function(node) {
  161. while(node && selection.indexOf(node) == -1) {
  162. selection.push(node);
  163. node = node.parent;
  164. }
  165. });
  166. this.app.minder.select(selection, true);
  167. this.app.minder.fire('receiverfocus');
  168. },
  169. tree: function() {
  170. var selected = this.app.minder.getSelectedNodes();
  171. var selection = [];
  172. selected.forEach(function(parent) {
  173. parent.traverse(function(node) {
  174. if (selection.indexOf(node) == -1) selection.push(node);
  175. });
  176. });
  177. this.app.minder.select(selection, true);
  178. this.app.minder.fire('receiverfocus');
  179. }
  180. });
  181. MWF.xApplication.MinderEditor.Template = new Class({
  182. Extends: MSelector,
  183. options : {
  184. "style": "minderTemplate",
  185. "width": "195px",
  186. "height": "30px",
  187. "defaultOptionLp" : "",
  188. "isSetSelectedValue" : false,
  189. "isChangeOptionStyle" : true,
  190. "emptyOptionEnable" : false,
  191. "event" : "mouseenter"
  192. },
  193. _selectItem : function( itemNode, itemData ){
  194. },
  195. _loadData : function( callback ){
  196. var list = [
  197. {
  198. command : "default",
  199. picture : "default.png",
  200. title : "思维导图"
  201. },
  202. {
  203. command : "structure",
  204. picture : "structure.png",
  205. title : "目录组织图"
  206. },
  207. {
  208. command : "filetree",
  209. picture : "filetree.png",
  210. title : "组织结构图"
  211. },
  212. {
  213. command : "right",
  214. picture : "right.png",
  215. title : "逻辑结构图"
  216. },
  217. {
  218. command : "fish-bone",
  219. picture : "fish-bone.png",
  220. title : "鱼骨图"
  221. },
  222. {
  223. command : "tianpan",
  224. picture : "tianpan.png",
  225. title : "天盘"
  226. }
  227. ];
  228. var template = this.app.options.template;
  229. if( template && template.length > 0 ){
  230. for( var i = 0; i< list.length; i++){
  231. if( !template.contains(list[i].command) ){
  232. list[i] = null;
  233. }
  234. }
  235. }
  236. list = list.clean();
  237. if(callback)callback( list );
  238. },
  239. _postCreateItem: function( itemNode, data ){
  240. },
  241. loadContent : function( data ){
  242. if( !this.contentTooltip ){
  243. var width = parseInt(this.options.width)+"px";
  244. this.css.tooltipNode.width = width;
  245. this.css.tooltipNode["max-width"] = width;
  246. this.options.tooltipsOptions.axis = "x";
  247. var options = Object.merge({
  248. nodeStyles : this.css.tooltipNode,
  249. onPostInitialize : function(){
  250. if(this.options.trigger == "immediately" ){
  251. this.contentTooltip.load();
  252. }
  253. }.bind(this),
  254. onHide : function(){
  255. this.status = "hidden";
  256. }.bind(this)
  257. }, this.options.tooltipsOptions );
  258. this.contentTooltip = new MWF.xApplication.MinderEditor.Template.Tootips( this.dropdownContainer || this.app.content, this.node, this.app, data, options );
  259. this.contentTooltip.selector = this;
  260. }
  261. }
  262. });
  263. MWF.xApplication.MinderEditor.Template.Tootips = new Class({
  264. Extends: MSelector.Tootips,
  265. options : {
  266. axis: "x", //箭头在x轴还是y轴上展现
  267. position : { //node 固定的位置
  268. x : "center", //x轴上left center right, auto 系统自动计算
  269. y : "auto" //y 轴上top middle bottom, auto 系统自动计算
  270. },
  271. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  272. hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  273. displayDelay : 0, //ms , 有target 且事件类型为 mouseenter 时有效
  274. hasArrow : true
  275. },
  276. _customNode : function( node, contentNode ){
  277. //var width = ( parseInt( this.selector.options.width ) )+ "px";
  278. //node.setStyles({
  279. // "width": width,
  280. // "max-width": width
  281. //});
  282. this.createItemList( this.data, contentNode )
  283. },
  284. createItemList:function(data, node){
  285. data = data || [];
  286. var _selector = this.selector;
  287. this.css = _selector.css;
  288. _selector.listContentNode = new Element("div.listContentNode",{
  289. "styles":this.css.listContentNode
  290. }).inject( node );
  291. //_selector.listContentNode.setStyles({
  292. // "width": node.getSize().x+"px"
  293. //});
  294. _selector.listNode = new Element("div.listNode",{
  295. "styles":this.css.listNode
  296. }).inject(_selector.listContentNode);
  297. _selector.setScrollBar(_selector.listNode);
  298. data.each(function(d){
  299. this.createItem( d );
  300. }.bind(this));
  301. },
  302. createItem: function( data ){
  303. var _selector = this.selector;
  304. var listItemNode = new Element("div.listItemNode",{
  305. "styles":this.css.listItemNode,
  306. "title" : data.title
  307. }).inject(_selector.listNode);
  308. listItemNode.setStyles({
  309. "background": "url("+ _selector.path + _selector.options.style + "/icon/"+data.picture + ") no-repeat center center"
  310. });
  311. if(data)listItemNode.store("data",data);
  312. listItemNode.addEvents({
  313. "click":function(ev){
  314. var _self = this.obj;
  315. var data = this.itemNode.retrieve( "data" );
  316. _self.selector.setCurrentItem( this.itemNode );
  317. _self.selector._selectItem( this.itemNode, data );
  318. _self.selector.fireEvent("selectItem", [ this.itemNode, data ] );
  319. _self.hide();
  320. ev.stopPropagation();
  321. }.bind({ obj : this, itemNode : listItemNode }),
  322. "mouseover":function(){
  323. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  324. this.itemNode.setStyles( this.obj.selector.css.listItemNode_over );
  325. }
  326. }.bind( {obj : this, itemNode : listItemNode }),
  327. "mouseout":function(){
  328. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  329. this.itemNode.setStyles( this.obj.selector.css.listItemNode );
  330. }
  331. }.bind( {obj : this, itemNode : listItemNode })
  332. });
  333. _selector.itemNodeList.push( listItemNode );
  334. _selector.itemNodeObject[ data[ _selector.valueField ] ] = listItemNode;
  335. var isCurrent = false;
  336. if( _selector.currentItemData ){
  337. isCurrent = data[ _selector.valueField ] == _selector.currentItemData[ _selector.valueField ];
  338. }else if( _selector.value ){
  339. isCurrent = data[ _selector.valueField ] == _selector.value;
  340. }else if( _selector.text ){
  341. isCurrent = data[ _selector.textField ] == _selector.text;
  342. }
  343. if( isCurrent )_selector.setCurrentItem( listItemNode );
  344. _selector._postCreateItem(listItemNode, data)
  345. }
  346. });
  347. MWF.xApplication.MinderEditor.Theme = new Class({
  348. Extends: MSelector,
  349. options : {
  350. "style": "minderTheme",
  351. "width": "195px",
  352. "height": "30px",
  353. "defaultOptionLp" : "",
  354. "isSetSelectedValue" : false,
  355. "isChangeOptionStyle" : false,
  356. "emptyOptionEnable" : false,
  357. "event" : "mouseenter"
  358. },
  359. _selectItem : function( itemNode, itemData ){
  360. },
  361. _loadData : function( callback ){
  362. var list = [
  363. {
  364. command : 'classic',
  365. text : "经典"
  366. },
  367. {
  368. command : 'classic-compact',
  369. text : "经典紧凑"
  370. },
  371. {
  372. command : 'fresh-blue',
  373. text : "蓝色"
  374. },
  375. {
  376. command : 'fresh-blue-compat',
  377. text : "蓝色紧凑"
  378. },
  379. {
  380. command : 'fresh-green',
  381. text : "绿色"
  382. },
  383. {
  384. command : 'fresh-green-compat',
  385. text : "绿色紧凑"
  386. },
  387. {
  388. command : 'fresh-pink',
  389. text : "粉色"
  390. },
  391. {
  392. command : 'fresh-pink-compat',
  393. text : "粉色紧凑"
  394. },
  395. {
  396. command : 'fresh-purple',
  397. text : "紫色"
  398. },
  399. {
  400. command : 'fresh-purple-compat',
  401. text : "紫色紧凑"
  402. },
  403. {
  404. command : 'fresh-red',
  405. text : "红色"
  406. },
  407. {
  408. command : 'fresh-red-compat',
  409. text : "红色紧凑"
  410. },
  411. {
  412. command : 'fresh-soil',
  413. text : "黄色"
  414. },
  415. {
  416. command : 'fresh-soil-compat',
  417. text : "黄色紧凑"
  418. },
  419. {
  420. command : 'snow',
  421. text : "冷光"
  422. },
  423. {
  424. command : 'snow-compact',
  425. text : "冷光紧凑"
  426. },
  427. {
  428. command : 'tianpan',
  429. text : "天盘"
  430. },
  431. {
  432. command : 'tianpan-compact',
  433. text : "天盘紧凑"
  434. },
  435. {
  436. command : 'fish',
  437. text : "鱼骨图"
  438. },
  439. {
  440. command : 'wire',
  441. text : "线条"
  442. }
  443. ];
  444. var theme = this.app.options.theme;
  445. if( theme && theme.length > 0 ){
  446. for( var i = 0; i< list.length; i++){
  447. if( !theme.contains(list[i].command) ){
  448. list[i] = null;
  449. }
  450. }
  451. }
  452. list = list.clean();
  453. if(callback)callback( list );
  454. },
  455. _postCreateItem: function( itemNode, data ){
  456. },
  457. loadContent : function( data ){
  458. this.options.tooltipsOptions.axis = "x";
  459. if( !this.contentTooltip ){
  460. var width = parseInt(this.options.width)+"px";
  461. this.css.tooltipNode.width = width;
  462. this.css.tooltipNode["max-width"] = width;
  463. var options = Object.merge({
  464. nodeStyles : this.css.tooltipNode,
  465. onPostInitialize : function(){
  466. if(this.options.trigger == "immediately" ){
  467. this.contentTooltip.load();
  468. }
  469. }.bind(this),
  470. onHide : function(){
  471. this.status = "hidden";
  472. }.bind(this)
  473. }, this.options.tooltipsOptions );
  474. this.contentTooltip = new MWF.xApplication.MinderEditor.Theme.Tootips( this.dropdownContainer || this.app.content, this.node, this.app, data, options );
  475. this.contentTooltip.selector = this;
  476. }
  477. }
  478. });
  479. MWF.xApplication.MinderEditor.Theme.Tootips = new Class({
  480. Extends: MSelector.Tootips,
  481. options : {
  482. axis: "x", //箭头在x轴还是y轴上展现
  483. position : { //node 固定的位置
  484. x : "center", //x轴上left center right, auto 系统自动计算
  485. y : "bottom" //y 轴上top middle bottom, auto 系统自动计算
  486. },
  487. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  488. hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  489. displayDelay : 0, //ms , 有target 且事件类型为 mouseenter 时有效
  490. hasArrow : true
  491. },
  492. _customNode : function( node, contentNode ){
  493. //var width = ( parseInt( this.selector.options.width ) )+ "px";
  494. //node.setStyles({
  495. // "width": width,
  496. // "max-width": width
  497. //});
  498. this.createItemList( this.data, contentNode )
  499. },
  500. createItemList:function(data, node){
  501. data = data || [];
  502. var _selector = this.selector;
  503. this.css = _selector.css;
  504. _selector.listContentNode = new Element("div.listContentNode",{
  505. "styles":this.css.listContentNode
  506. }).inject( node );
  507. //_selector.listContentNode.setStyles({
  508. // "width": node.getSize().x+"px"
  509. //});
  510. _selector.listNode = new Element("div.listNode",{
  511. "styles":this.css.listNode
  512. }).inject(_selector.listContentNode);
  513. _selector.setScrollBar(_selector.listNode);
  514. data.each(function(d){
  515. this.createItem( d );
  516. }.bind(this));
  517. },
  518. createItem: function( data ){
  519. var _selector = this.selector;
  520. var listItemNode = new Element("div.listItemNode",{
  521. "styles":this.css.listItemNode,
  522. "text" : data.text
  523. }).inject(_selector.listNode);
  524. if(data)listItemNode.store("data",data);
  525. listItemNode.addEvents({
  526. "click":function(ev){
  527. var _self = this.obj;
  528. var data = this.itemNode.retrieve( "data" );
  529. _self.selector.setCurrentItem( this.itemNode );
  530. _self.selector._selectItem( this.itemNode, data );
  531. _self.selector.fireEvent("selectItem", [ this.itemNode, data ] );
  532. _self.hide();
  533. ev.stopPropagation();
  534. }.bind({ obj : this, itemNode : listItemNode }),
  535. "mouseover":function(){
  536. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  537. this.itemNode.setStyles( this.obj.selector.css.listItemNode_over );
  538. }
  539. }.bind( {obj : this, itemNode : listItemNode }),
  540. "mouseout":function(){
  541. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  542. this.itemNode.setStyles( this.obj.selector.css.listItemNode );
  543. }
  544. }.bind( {obj : this, itemNode : listItemNode })
  545. });
  546. _selector.itemNodeList.push( listItemNode );
  547. _selector.itemNodeObject[ data[ _selector.valueField ] ] = listItemNode;
  548. var isCurrent = false;
  549. if( _selector.currentItemData ){
  550. isCurrent = data[ _selector.valueField ] == _selector.currentItemData[ _selector.valueField ];
  551. }else if( _selector.value ){
  552. isCurrent = data[ _selector.valueField ] == _selector.value;
  553. }else if( _selector.text ){
  554. isCurrent = data[ _selector.textField ] == _selector.text;
  555. }
  556. if( isCurrent )_selector.setCurrentItem( listItemNode );
  557. _selector.fireEvent("postCreateItem", [ listItemNode, data ] );
  558. _selector._postCreateItem(listItemNode, data)
  559. }
  560. });
  561. MWF.xApplication.MinderEditor.NotePrviewer = new Class({
  562. Implements: [Options, Events],
  563. Extends: MTooltips,
  564. options: {
  565. style : "default",
  566. axis: "y", //箭头在x轴还是y轴上展现
  567. position : { //node 固定的位置
  568. x : "auto", //x 轴上left center right, auto 系统自动计算
  569. y : "auto" //y轴上top middle bottom, auto 系统自动计算
  570. },
  571. overflow : "scroll",
  572. //event : "click", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  573. nodeStyles : {
  574. "font-size" : "12px",
  575. "position" : "absolute",
  576. "max-width" : "500px",
  577. "min-width" : "50px",
  578. "z-index" : "11",
  579. "background-color" : "#fff",
  580. "padding" : "10px",
  581. "border-radius" : "5px",
  582. "word-break" : "break-all",
  583. "box-shadow": "0 0 8px 0 #999999",
  584. "-webkit-user-select": "text",
  585. "-moz-user-select": "text"
  586. }
  587. },
  588. initialize : function( editor, options ){
  589. //可以传入target 或者 targetCoordinates,两种选一
  590. //传入target,表示触发tooltip的节点,本类根据 this.options.event 自动绑定target的事件
  591. //传入targetCoordinates,表示 出发tooltip的位置,本类不绑定触发事件
  592. if( options ){
  593. this.setOptions(options);
  594. }
  595. this.editor = editor;
  596. this.app = editor;
  597. this.lp = editor.lp;
  598. this.container = editor.content;
  599. this.minder = editor.minder;
  600. this.minder.on('shownoterequest', function(e) {
  601. this.previewTimer = setTimeout(function() {
  602. this.load(e.node, e.keyword);
  603. }.bind(this), 300);
  604. }.bind(this));
  605. this.minder.on('hidenoterequest', function( e ) {
  606. if(this.previewTimer)clearTimeout(this.previewTimer);
  607. if( e && e.forceflag )this.hide();
  608. }.bind(this));
  609. this.hideFun = this.hide.bind(this);
  610. this.container.addEvents( {
  611. 'mousedown': this.hideFun,
  612. 'mousewheel': this.hideFun,
  613. 'DOMMouseScroll': this.hideFun
  614. });
  615. this.editor.addEvent("resize",this.hideFun );
  616. this.fireEvent("postInitialize",[this]);
  617. },
  618. load: function( node, keyword ){
  619. this.fireEvent("queryLoad",[this]);
  620. if( this.isEnable() ){
  621. if( this.node ){
  622. this.show( node, keyword );
  623. }else{
  624. this.create( node, keyword );
  625. }
  626. }
  627. this.fireEvent("postLoad",[this]);
  628. },
  629. show: function(node, keyword){
  630. this.status = "display";
  631. this.node.setStyle("display","");
  632. this.setContent(node, keyword);
  633. this.fireEvent("show",[this]);
  634. },
  635. create: function(node, keyword){
  636. this.status = "display";
  637. this.fireEvent("queryCreate",[this]);
  638. this.node = new Element("div.tooltipNode", {
  639. styles : this.options.nodeStyles
  640. }).inject( this.container );
  641. this.node.addEvents( {
  642. 'mousedown': function(e) { e.stopPropagation(); },
  643. 'mousewheel': function(e) { e.stopPropagation(); },
  644. 'DOMMouseScroll': function(e) { e.stopPropagation(); }
  645. });
  646. this.contentNode = new Element("div",{
  647. styles : {
  648. width : "100%",
  649. "height" : "100%"
  650. }
  651. }).inject( this.node );
  652. if( this.options.hasArrow ){
  653. this.arrowNode = new Element("div.arrowNode", {
  654. "styles": {
  655. "width": this.options.axis == "x" ? "9px" : "17px",
  656. "height" : this.options.axis == "x" ? "17px" : "9px",
  657. "position":"absolute",
  658. "background" : "no-repeat url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAlCAYAAACgc9J8AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAP9JREFUeNq01oENhCAMBdCWuIgTuP8WOoGj9GhSDaeUfjiuCSEm+iKFVllESGNdVzrPk55xHIfewHnItm1MrVDMG/u+i0aeyWZp3R9CJRaBIWRB5YUHItAL80AEqmI1EIFcrAQ1rwjUxEoQgULsAue+2ayc/W83p5+z6RXggOO1WQGhrsFXP/Oip58tAaQTZ4QMbEbyEB2GCKEBdtpmru4NsC4aHg8PLJ/3lim2xDv02jYDz1kNQsGEQgiYeqAQBPuZQF1jFKqBYTn1RLK1D4+v3E3NGfgNkJlfdKi0XrUZgc1OWyt0Dwz/z37tGhA20s+WR4t+1iBbzTJyaD8CDAB7WgNSzh/AnwAAAABJRU5ErkJggg==)"
  659. }
  660. }
  661. ).inject(this.node);
  662. }
  663. this.setContent(node, keyword);
  664. this.fireEvent("postCreate",[this]);
  665. },
  666. setContent : function( node, keyword ){
  667. this.editor.loadCodeMirror(
  668. function(){
  669. //var icon = node.getRenderer('NoteIconRenderer').getRenderShape();
  670. var b = node.getRenderBox('screen');
  671. var t = this.editor.Content_Offset_Top;
  672. b.bottom += t;
  673. b.cy += t;
  674. b.top += t;
  675. b.y += t;
  676. this.targetCoordinates = b;
  677. var note = node.getData('note');
  678. //$previewer[0].scrollTop = 0;
  679. var html = marked(note);
  680. if (keyword) {
  681. html = html.replace(new RegExp('(' + keyword + ')', 'ig'), '<span class="highlight">$1</span>');
  682. }
  683. this.contentNode.set("html", html);
  684. this.setCoondinates();
  685. }.bind(this)
  686. )
  687. }
  688. });
  689. MWF.xApplication.MinderEditor.Help = new Class({
  690. Implements: [Options, Events],
  691. Extends: MTooltips,
  692. options: {
  693. style : "default",
  694. axis: "y", //箭头在x轴还是y轴上展现
  695. position : { //node 固定的位置
  696. x : "auto", //x 轴上left center right, auto 系统自动计算
  697. y : "auto" //y轴上top middle bottom, auto 系统自动计算
  698. },
  699. overflow : "scroll",
  700. hasCloseAction : true,
  701. event : "click" //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  702. //nodeStyles : {
  703. // "font-size" : "12px",
  704. // "position" : "absolute",
  705. // "max-width" : "500px",
  706. // "min-width" : "50px",
  707. // "z-index" : "11",
  708. // "background-color" : "#fff",
  709. // "padding" : "10px",
  710. // "border-radius" : "5px",
  711. // "word-break" : "break-all",
  712. // "box-shadow": "0 0 8px 0 #999999",
  713. // "-webkit-user-select": "text",
  714. // "-moz-user-select": "text"
  715. //}
  716. },
  717. _customNode : function( node, contentNode ){
  718. var table = new Element("table").inject(contentNode);
  719. var commands = this.commands.commands;
  720. for( var name in commands ){
  721. var command = commands[name];
  722. if( command.key ){
  723. var tr = new Element("tr").inject( table );
  724. new Element("td",{ text : command.locale || command.title }).inject( tr );
  725. new Element("td",{ text : command.key }).inject( tr );
  726. }
  727. }
  728. }
  729. });
  730. MWF.xApplication.MinderEditor.Preview = new Class({
  731. options : {
  732. "show" : "true"
  733. },
  734. Implements: [Options, Events],
  735. initialize: function (container, minder, app, css) {
  736. this.container = container;
  737. this.app = app;
  738. this.lp = MWF.xApplication.MinderEditor.LP;
  739. this.css = css;
  740. this.minder = minder;
  741. },
  742. load: function (callback) {
  743. this.previewer = new Element("div",{ "styles" : this.css.previewer }).inject(this.container);
  744. this.initPreViewer();
  745. if( this.options.show ){
  746. this.toggleOpen( true );
  747. }
  748. },
  749. initPreViewer: function(){
  750. // 画布,渲染缩略图
  751. var paper = this.paper = new kity.Paper( this.previewer );
  752. // 用两个路径来挥之节点和连线的缩略图
  753. this.nodeThumb = paper.put(new kity.Path());
  754. this.connectionThumb = paper.put(new kity.Path());
  755. // 表示可视区域的矩形
  756. this.visibleRect = paper.put(new kity.Rect(100, 100).stroke('red', '1%'));
  757. this.contentView = new kity.Box();
  758. this.visibleView = new kity.Box();
  759. /**
  760. * 增加一个对天盘图情况缩略图的处理,
  761. * @Editor: Naixor line 104~129
  762. * @Date: 2015.11.3
  763. */
  764. this.pathHandler = this.getPathHandler(this.minder.getTheme());
  765. this.navigate();
  766. },
  767. getPathHandler: function (theme) {
  768. switch (theme) {
  769. case "tianpan":
  770. case "tianpan-compact":
  771. return function(nodePathData, x, y, width, height) {
  772. var r = width >> 1;
  773. nodePathData.push('M', x, y + r,
  774. 'a', r, r, 0, 1, 1, 0, 0.01,
  775. 'z');
  776. };
  777. default: {
  778. return function(nodePathData, x, y, width, height) {
  779. nodePathData.push('M', x, y,
  780. 'h', width, 'v', height,
  781. 'h', -width, 'z');
  782. }
  783. }
  784. }
  785. },
  786. toggleOpen : function( open ) {
  787. if (open) {
  788. this.previewer.setStyle("display","block");
  789. this.bindPreviewerEvent();
  790. this.updateContentView();
  791. this.updateVisibleView();
  792. } else{
  793. this.previewer.setStyle("display","none");
  794. this.unbindPreviewerEvent();
  795. }
  796. },
  797. bindPreviewerEvent : function(){
  798. this.updateContentViewFun = this.updateContentViewFun || this.updateContentView.bind(this);
  799. this.updateVisibleViewFun = this.updateVisibleViewFun || this.updateVisibleView.bind(this);
  800. this.minder.on('layout layoutallfinish', this.updateContentViewFun );
  801. this.minder.on('viewchange', this.updateVisibleViewFun );
  802. },
  803. unbindPreviewerEvent : function(){
  804. this.minder.off('layout layoutallfinish', this.updateContentViewFun );
  805. this.minder.off('viewchange', this.updateVisibleViewFun );
  806. },
  807. moveView: function(center, duration) {
  808. var box = this.visibleView;
  809. center.x = -center.x;
  810. center.y = -center.y;
  811. var viewMatrix = this.minder.getPaper().getViewPortMatrix();
  812. box = viewMatrix.transformBox(box);
  813. var targetPosition = center.offset(box.width / 2, box.height / 2);
  814. this.minder.getViewDragger().moveTo(targetPosition, duration);
  815. },
  816. navigate: function() {
  817. var _self = this;
  818. this.dragging = false;
  819. this.paper.on('mousedown', function(e) {
  820. _self.dragging = true;
  821. _self.moveView(e.getPosition('top'), 200);
  822. _self.previewer.setStyles( _self.css.previewerGrab );
  823. });
  824. this.paper.on('mousemove', function(e) {
  825. if (_self.dragging) {
  826. _self.moveView(e.getPosition('top'));
  827. }
  828. });
  829. this.paper.on('mouseup', function() {
  830. _self.dragging = false;
  831. if(_self.previewer)_self.previewer.setStyles( _self.css.previewerNoGrab );
  832. });
  833. this.app.contentNode.addEvent('mouseup', function() {
  834. _self.dragging = false;
  835. if(_self.previewer)_self.previewer.setStyles( _self.css.previewerNoGrab );
  836. });
  837. },
  838. updateContentView: function(){
  839. var view = this.minder.getRenderContainer().getBoundaryBox();
  840. this.contentView = view;
  841. var padding = 30;
  842. this.paper.setViewBox(
  843. view.x - padding - 0.5,
  844. view.y - padding - 0.5,
  845. view.width + padding * 2 + 1,
  846. view.height + padding * 2 + 1);
  847. var nodePathData = [];
  848. var connectionThumbData = [];
  849. this.minder.getRoot().traverse(function(node) {
  850. var box = node.getLayoutBox();
  851. this.pathHandler(nodePathData, box.x, box.y, box.width, box.height);
  852. if (node.getConnection() && node.parent && node.parent.isExpanded()) {
  853. connectionThumbData.push(node.getConnection().getPathData());
  854. }
  855. }.bind(this));
  856. this.paper.setStyle('background', this.minder.getStyle('background'));
  857. if (nodePathData.length) {
  858. this.nodeThumb
  859. .fill(this.minder.getStyle('root-background'))
  860. .setPathData(nodePathData);
  861. } else {
  862. this.nodeThumb.setPathData(null);
  863. }
  864. if (connectionThumbData.length) {
  865. this.connectionThumb
  866. .stroke(this.minder.getStyle('connect-color'), '0.5%')
  867. .setPathData(connectionThumbData);
  868. } else {
  869. this.connectionThumb.setPathData(null);
  870. }
  871. this.updateVisibleView();
  872. },
  873. updateVisibleView: function(){
  874. this.visibleView = this.minder.getViewDragger().getView();
  875. this.visibleRect.setBox(this.visibleView.intersect(this.contentView));
  876. }
  877. });
  878. MWF.xApplication.MinderEditor.SearchBar = new Class({
  879. Implements: [Options, Events],
  880. options : {},
  881. initialize: function ( container, minder, app, css, options) {
  882. this.setOptions(options);
  883. this.container = container;
  884. this.app = app;
  885. this.lp = MWF.xApplication.MinderEditor.LP;
  886. this.css = css;
  887. this.minder = minder;
  888. },
  889. enterSearch : function(){
  890. if( !this.nodeSequence ){
  891. this.load();
  892. }else{
  893. this.show();
  894. this.searchInput.focus();
  895. }
  896. },
  897. load: function (callback) {
  898. this.createSearchBar();
  899. this.nodeSequence = [];
  900. this.searchSequence = [];
  901. //this.minder.on('contentchange', this.makeNodeSequence.bind(this));
  902. //
  903. //this.makeNodeSequence();
  904. },
  905. show : function(){
  906. this.container.setStyle("display","block");
  907. this.node.setStyle("display","block");
  908. this.fireEvent("show");
  909. },
  910. hide: function(){
  911. this.container.setStyle("display","none");
  912. //this.minder.execCommand('camera');
  913. this.node.setStyle("display","none");
  914. this.fireEvent("hide");
  915. },
  916. createSearchBar : function(){
  917. this.node = new Element("div", { "styles" : this.css.searchBar }).inject(this.container);
  918. this.searchInput = new Element("input" , {
  919. "type" : "text",
  920. "styles" : this.css.searchInput,
  921. "value" : this.lp.searchText
  922. }).inject(this.node);
  923. this.searchInput.addEvents({
  924. "focus" : function( ev ){
  925. if( this.searchInput.get("value")==this.lp.searchText){
  926. this.searchInput.set("value","")
  927. }
  928. this.makeNodeSequence();
  929. }.bind(this),
  930. "blur" : function( ev ){
  931. if( this.searchInput.get("value").trim()==""){
  932. this.searchInput.set("value", this.lp.searchText);
  933. }
  934. }.bind(this),
  935. "keyup" : function(){
  936. this.doSearch(this.searchInput.get("value"),"next");
  937. }.bind(this)
  938. });
  939. //this.searchButton = new Element("div", {"styles" : this.css.searchButton, "text" : this.lp.search } ).inject(this.node);
  940. this.resultInforNode = new Element("div", {
  941. "styles" : this.css.resultInforNode,
  942. "text" : "0/0"
  943. } ).inject(this.node);
  944. this.prevButton = new Element("div", {"styles" : this.css.prevButton , "title" : this.lp.prev} ).inject(this.node);
  945. this.prevButton.addEvent("click",function(){
  946. this.goPrev();
  947. }.bind(this));
  948. this.nextButton = new Element("div", {"styles" : this.css.nextButton , "title" : this.lp.next } ).inject(this.node);
  949. this.nextButton.addEvent("click",function(){
  950. this.goNext();
  951. }.bind(this));
  952. this.closeButton = new Element("div", {"styles" : this.css.closeButton , "title" : this.lp.close } ).inject(this.node);
  953. this.closeButton.addEvent("click",function(){
  954. this.close();
  955. }.bind(this))
  956. },
  957. goNext : function(){
  958. this.doSearch( this.searchInput.get("value"),"next" );
  959. },
  960. goPrev : function(){
  961. this.doSearch( this.searchInput.get("value"),"prev" );
  962. },
  963. close : function(){
  964. this.hide();
  965. },
  966. makeNodeSequence: function() {
  967. //console.log( "makeNodeSequence" );
  968. this.nodeSequence = [];
  969. this.minder.getRoot().traverse(function(node) {
  970. this.nodeSequence.push(node);
  971. }.bind(this));
  972. },
  973. makeSearchSequence: function(keyword) {
  974. this.searchSequence = [];
  975. for (var i = 0; i < this.nodeSequence.length; i++) {
  976. var node = this.nodeSequence[i];
  977. var text = (node.getText() || "").toLowerCase();
  978. if (text.indexOf(keyword) != -1) {
  979. this.searchSequence.push({node:node});
  980. }
  981. var note = node.getData('note') || "";
  982. if (note && note.toLowerCase().indexOf(keyword) != -1) {
  983. this.searchSequence.push({node: node, keyword: keyword});
  984. }
  985. }
  986. },
  987. doSearch : function(keyword, direction) {
  988. this.minder.fire('hidenoterequest', { forceflag : true } );
  989. if (!keyword || !/\S/.exec(keyword)) {
  990. this.searchInput.focus();
  991. this.resultInforNode.set("text", 0+"/"+0);
  992. return;
  993. }
  994. // 当搜索不到节点时候默认的选项
  995. //this.curIndex = 0;
  996. this.resultNum = 0;
  997. keyword = keyword.toLowerCase();
  998. var newSearch = this.lastKeyword != keyword;
  999. this.lastKeyword = keyword;
  1000. if (newSearch) {
  1001. this.makeSearchSequence(keyword);
  1002. }else if( !this.curIndex ){
  1003. this.makeSearchSequence(keyword);
  1004. }
  1005. this.resultNum = this.searchSequence.length;
  1006. if (this.searchSequence.length) {
  1007. var curIndex = newSearch ? 0 : (direction === 'next' ? this.lastIndex + 1 : this.lastIndex - 1) || 0;
  1008. curIndex = (this.searchSequence.length + curIndex) % this.searchSequence.length;
  1009. if( curIndex == 0 && !newSearch ){
  1010. //this.makeNodeSequence();
  1011. this.makeSearchSequence(keyword);
  1012. }
  1013. this.setSearchResult(this.searchSequence[curIndex].node, this.searchSequence[curIndex].keyword);
  1014. this.lastIndex = curIndex;
  1015. this.curIndex = curIndex + 1;
  1016. this.resultInforNode.set("text", this.curIndex+"/"+this.searchSequence.length);
  1017. }else{
  1018. this.resultInforNode.set("text", 0+"/"+0);
  1019. }
  1020. },
  1021. setSearchResult : function(node, previewKeyword) {
  1022. setTimeout(function () {
  1023. if (previewKeyword) {
  1024. this.minder.fire('shownoterequest', {node: node, keyword: previewKeyword});
  1025. }
  1026. if (!node.isExpanded()){
  1027. this.minder.select(node, true);
  1028. this.minder.execCommand('expand', true);
  1029. }else{
  1030. this.minder.select(node, true);
  1031. this.minder.execCommand('camera', node, 50);
  1032. }
  1033. }.bind(this), 60);
  1034. }
  1035. });