WidgetInEditMode.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  2. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  3. MWF.xDesktop.requireApp("Template", "widget.ColorPicker", null, false);
  4. MWF.xDesktop.requireApp("Template", "MSelector", null, false);
  5. MWF.xApplication.MinderEditor.FontFamily = new Class({
  6. Extends: MSelector,
  7. options : {
  8. "style": "minderFont",
  9. "width": "240px",
  10. "height": "28px",
  11. "defaultOptionLp" : "字体",
  12. "textField" : "name",
  13. "valueField" : "val",
  14. "event" : "mouseenter",
  15. "isSetSelectedValue" : true,
  16. "isChangeOptionStyle" : true,
  17. "emptyOptionEnable" : false
  18. },
  19. _selectItem : function( itemNode, itemData ){
  20. },
  21. _loadData : function( callback ){
  22. var fontFamilyList = [{
  23. name: '宋体',
  24. val: '宋体,SimSun'
  25. }, {
  26. name: 'Microsoft YaHei',
  27. val: 'Microsoft YaHei,Microsoft YaHei'
  28. }, {
  29. name: '楷体',
  30. val: '楷体,楷体_GB2312,SimKai'
  31. }, {
  32. name: '黑体',
  33. val: '黑体, SimHei'
  34. }, {
  35. name: '隶书',
  36. val: '隶书, SimLi'
  37. }, {
  38. name: 'Andale Mono',
  39. val: 'andale mono'
  40. }, {
  41. name: 'Arial',
  42. val: 'arial,helvetica,sans-serif'
  43. }, {
  44. name: 'arialBlack',
  45. val: 'arial black,avant garde'
  46. }, {
  47. name: 'Comic Sans Ms',
  48. val: 'comic sans ms'
  49. }, {
  50. name: 'Impact',
  51. val: 'impact,chicago'
  52. }, {
  53. name: 'Times New Roman',
  54. val: 'times new roman'
  55. }, {
  56. name: 'Sans-Serif',
  57. val: 'sans-serif'
  58. }];
  59. if(callback)callback( fontFamilyList );
  60. },
  61. _postCreateItem: function( itemNode, data ){
  62. itemNode.setStyles( {
  63. "font-family": data.val,
  64. "font-size" : "14px",
  65. "min-height" : "30px",
  66. "line-height" : "30px"
  67. } );
  68. }
  69. });
  70. MWF.xApplication.MinderEditor.FontSize = new Class({
  71. Extends: MSelector,
  72. options : {
  73. "style": "minderFont",
  74. "width": "80px",
  75. "height": "28px",
  76. "defaultOptionLp" : "字号",
  77. "isSetSelectedValue" : true,
  78. "isChangeOptionStyle" : true,
  79. "emptyOptionEnable" : false,
  80. "event" : "mouseenter"
  81. },
  82. _selectItem : function( itemNode, itemData ){
  83. },
  84. _loadData : function( callback ){
  85. var fontSizeList = ["10", "12", "16", "18", "24", "32", "48"];
  86. if(callback)callback( fontSizeList );
  87. },
  88. _postCreateItem: function( itemNode, data ){
  89. itemNode.setStyles( {
  90. "font-size" : data.value +"px",
  91. "min-height" : ( parseInt(data.value) + 6) +"px",
  92. "line-height" : ( parseInt(data.value) + 6) +"px"
  93. } );
  94. }
  95. });
  96. MWF.xApplication.MinderEditor.PriorityImage = new Class({
  97. Extends: MSelector,
  98. options : {
  99. "style": "minderProgress",
  100. "width": "130px",
  101. "defaultOptionLp" : "",
  102. "valueField" : "command",
  103. "isSetSelectedValue" : false,
  104. "isChangeOptionStyle" : true,
  105. "emptyOptionEnable" : false,
  106. "event" : "mouseenter"
  107. },
  108. _selectItem : function( itemNode, itemData ){
  109. },
  110. _loadData : function( callback ){
  111. var list = [
  112. {
  113. command : "0",
  114. position : "0 -180px",
  115. title : "移除优先级"
  116. },
  117. {
  118. command : "1",
  119. position : "0 0px",
  120. title : "优先级1"
  121. },
  122. {
  123. command : "2",
  124. position : "0 -20px",
  125. title : "优先级2"
  126. },
  127. {
  128. command : "3",
  129. position : "0 -40px",
  130. title : "优先级3"
  131. },
  132. {
  133. command : "4",
  134. position : "0 -60px",
  135. title : "优先级4"
  136. },
  137. {
  138. command : "5",
  139. position : "0 -80px",
  140. title : "优先级5"
  141. },
  142. {
  143. command : "6",
  144. position : "0 -100px",
  145. title : "优先级6"
  146. },
  147. {
  148. command : "7",
  149. position : "0 -120px",
  150. title : "优先级7"
  151. },
  152. {
  153. command : "8",
  154. position : "0 -140px",
  155. title : "优先级8"
  156. },
  157. {
  158. command : "9",
  159. position : "0 -160px",
  160. title : "优先级9"
  161. }
  162. ];
  163. if(callback)callback( list );
  164. },
  165. _postCreateItem: function( itemNode, data ){
  166. },
  167. loadContent : function( data ){
  168. if( !this.contentTooltip ){
  169. var width = parseInt(this.options.width)+"px";
  170. this.css.tooltipNode.width = width;
  171. this.css.tooltipNode["max-width"] = width;
  172. var options = Object.merge({
  173. nodeStyles : this.css.tooltipNode,
  174. onPostInitialize : function(){
  175. if(this.options.trigger == "immediately" ){
  176. this.contentTooltip.load();
  177. }
  178. }.bind(this),
  179. onHide : function(){
  180. this.status = "hidden";
  181. }.bind(this)
  182. }, this.options.tooltipsOptions );
  183. this.contentTooltip = new MWF.xApplication.MinderEditor.PriorityImage.Tootips( this.dropdownContainer || this.app.content, this.node, this.app, data, options );
  184. this.contentTooltip.selector = this;
  185. }
  186. }
  187. });
  188. MWF.xApplication.MinderEditor.PriorityImage.Tootips = new Class({
  189. Extends: MSelector.Tootips,
  190. options : {
  191. axis: "y", //箭头在x轴还是y轴上展现
  192. position : { //node 固定的位置
  193. x : "center", //x轴上left center right, auto 系统自动计算
  194. y : "bottom" //y 轴上top middle bottom, auto 系统自动计算
  195. },
  196. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  197. hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  198. displayDelay : 0, //ms , 有target 且事件类型为 mouseenter 时有效
  199. hasArrow : true
  200. },
  201. _customNode : function( node, contentNode ){
  202. //var width = ( parseInt( this.selector.options.width ) )+ "px";
  203. //node.setStyles({
  204. // "width": width,
  205. // "max-width": width
  206. //});
  207. this.createItemList( this.data, contentNode )
  208. },
  209. createItemList:function(data, node){
  210. data = data || [];
  211. var _selector = this.selector;
  212. this.css = _selector.css;
  213. _selector.listContentNode = new Element("div.listContentNode",{
  214. "styles":this.css.listContentNode
  215. }).inject( node );
  216. //_selector.listContentNode.setStyles({
  217. // "width": node.getSize().x+"px"
  218. //});
  219. _selector.listNode = new Element("div.listNode",{
  220. "styles":this.css.listNode
  221. }).inject(_selector.listContentNode);
  222. _selector.setScrollBar(_selector.listNode);
  223. data.each(function(d){
  224. this.createItem( d );
  225. }.bind(this));
  226. },
  227. createItem: function( data ){
  228. var _selector = this.selector;
  229. var listItemNode = new Element("div.listItemNode",{
  230. "styles":this.css.listItemNode,
  231. "title" : data.title
  232. }).inject(_selector.listNode);
  233. listItemNode.setStyles({
  234. "background": "url("+ _selector.path + _selector.options.style + "/icon/priority.png) no-repeat "+ data.position
  235. });
  236. if(data)listItemNode.store("data",data);
  237. listItemNode.addEvents({
  238. "click":function(ev){
  239. var _self = this.obj;
  240. var data = this.itemNode.retrieve( "data" );
  241. _self.selector.setCurrentItem( this.itemNode );
  242. _self.selector._selectItem( this.itemNode, data );
  243. _self.selector.fireEvent("selectItem", [ this.itemNode, data ] );
  244. _self.hide();
  245. ev.stopPropagation();
  246. }.bind({ obj : this, itemNode : listItemNode }),
  247. "mouseover":function(){
  248. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  249. this.itemNode.setStyles( this.obj.selector.css.listItemNode_over );
  250. }
  251. }.bind( {obj : this, itemNode : listItemNode }),
  252. "mouseout":function(){
  253. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  254. this.itemNode.setStyles( this.obj.selector.css.listItemNode );
  255. }
  256. }.bind( {obj : this, itemNode : listItemNode })
  257. });
  258. _selector.itemNodeList.push( listItemNode );
  259. _selector.itemNodeObject[ data[ _selector.valueField ] ] = listItemNode;
  260. var isCurrent = false;
  261. if( _selector.currentItemData ){
  262. isCurrent = data[ _selector.valueField ] == _selector.currentItemData[ _selector.valueField ];
  263. }else if( _selector.value ){
  264. isCurrent = data[ _selector.valueField ] == _selector.value;
  265. }else if( _selector.text ){
  266. isCurrent = data[ _selector.textField ] == _selector.text;
  267. }
  268. if( isCurrent )_selector.setCurrentItem( listItemNode );
  269. _selector._postCreateItem(listItemNode, data)
  270. }
  271. });
  272. MWF.xApplication.MinderEditor.ProgressImage = new Class({
  273. Extends: MSelector,
  274. options : {
  275. "style": "minderProgress",
  276. "width": "130px",
  277. "defaultOptionLp" : "",
  278. "valueField" : "command",
  279. "isSetSelectedValue" : false,
  280. "isChangeOptionStyle" : true,
  281. "emptyOptionEnable" : false,
  282. "event" : "mouseenter"
  283. },
  284. _selectItem : function( itemNode, itemData ){
  285. },
  286. _loadData : function( callback ){
  287. var list = [
  288. {
  289. command : "0",
  290. position : "0 -180px",
  291. title : "移除进度"
  292. },
  293. {
  294. command : "1",
  295. position : "0 0px",
  296. title : "未开始"
  297. },
  298. {
  299. command : "2",
  300. position : "0 -20px",
  301. title : "完成1/8"
  302. },
  303. {
  304. command : "3",
  305. position : "0 -40px",
  306. title : "完成2/8"
  307. },
  308. {
  309. command : "4",
  310. position : "0 -60px",
  311. title : "完成3/8"
  312. },
  313. {
  314. command : "5",
  315. position : "0 -80px",
  316. title : "完成4/8"
  317. },
  318. {
  319. command : "6",
  320. position : "0 -100px",
  321. title : "完成5/8"
  322. },
  323. {
  324. command : "7",
  325. position : "0 -120px",
  326. title : "完成6/8"
  327. },
  328. {
  329. command : "8",
  330. position : "0 -140px",
  331. title : "完成7/8"
  332. },
  333. {
  334. command : "9",
  335. position : "0 -160px",
  336. title : "全部完成"
  337. }
  338. ];
  339. if(callback)callback( list );
  340. },
  341. _postCreateItem: function( itemNode, data ){
  342. },
  343. loadContent : function( data ){
  344. if( !this.contentTooltip ){
  345. var width = parseInt(this.options.width)+"px";
  346. this.css.tooltipNode.width = width;
  347. this.css.tooltipNode["max-width"] = width;
  348. var options = Object.merge({
  349. nodeStyles : this.css.tooltipNode,
  350. onPostInitialize : function(){
  351. if(this.options.trigger == "immediately" ){
  352. this.contentTooltip.load();
  353. }
  354. }.bind(this),
  355. onHide : function(){
  356. this.status = "hidden";
  357. }.bind(this)
  358. }, this.options.tooltipsOptions );
  359. this.contentTooltip = new MWF.xApplication.MinderEditor.ProgressImage.Tootips( this.dropdownContainer || this.app.content, this.node, this.app, data, options );
  360. this.contentTooltip.selector = this;
  361. }
  362. }
  363. });
  364. MWF.xApplication.MinderEditor.ProgressImage.Tootips = new Class({
  365. Extends: MSelector.Tootips,
  366. options : {
  367. axis: "y", //箭头在x轴还是y轴上展现
  368. position : { //node 固定的位置
  369. x : "center", //x轴上left center right, auto 系统自动计算
  370. y : "bottom" //y 轴上top middle bottom, auto 系统自动计算
  371. },
  372. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  373. hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  374. displayDelay : 0, //ms , 有target 且事件类型为 mouseenter 时有效
  375. hasArrow : true
  376. },
  377. _customNode : function( node, contentNode ){
  378. //var width = ( parseInt( this.selector.options.width ) )+ "px";
  379. //node.setStyles({
  380. // "width": width,
  381. // "max-width": width
  382. //});
  383. this.createItemList( this.data, contentNode )
  384. },
  385. createItemList:function(data, node){
  386. data = data || [];
  387. var _selector = this.selector;
  388. this.css = _selector.css;
  389. _selector.listContentNode = new Element("div.listContentNode",{
  390. "styles":this.css.listContentNode
  391. }).inject( node );
  392. //_selector.listContentNode.setStyles({
  393. // "width": node.getSize().x+"px"
  394. //});
  395. _selector.listNode = new Element("div.listNode",{
  396. "styles":this.css.listNode
  397. }).inject(_selector.listContentNode);
  398. _selector.setScrollBar(_selector.listNode);
  399. data.each(function(d){
  400. this.createItem( d );
  401. }.bind(this));
  402. },
  403. createItem: function( data ){
  404. var _selector = this.selector;
  405. var listItemNode = new Element("div.listItemNode",{
  406. "styles":this.css.listItemNode,
  407. "title" : data.title
  408. }).inject(_selector.listNode);
  409. listItemNode.setStyles({
  410. "background": "url("+ _selector.path + _selector.options.style + "/icon/progress.png) no-repeat "+ data.position
  411. });
  412. if(data)listItemNode.store("data",data);
  413. listItemNode.addEvents({
  414. "click":function(ev){
  415. var _self = this.obj;
  416. var data = this.itemNode.retrieve( "data" );
  417. _self.selector.setCurrentItem( this.itemNode );
  418. _self.selector._selectItem( this.itemNode, data );
  419. _self.selector.fireEvent("selectItem", [ this.itemNode, data ] );
  420. _self.hide();
  421. ev.stopPropagation();
  422. }.bind({ obj : this, itemNode : listItemNode }),
  423. "mouseover":function(){
  424. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  425. this.itemNode.setStyles( this.obj.selector.css.listItemNode_over );
  426. }
  427. }.bind( {obj : this, itemNode : listItemNode }),
  428. "mouseout":function(){
  429. if( this.obj.selector.currentItemNode != this.itemNode || !this.obj.selector.options.isChangeOptionStyle ){
  430. this.itemNode.setStyles( this.obj.selector.css.listItemNode );
  431. }
  432. }.bind( {obj : this, itemNode : listItemNode })
  433. });
  434. _selector.itemNodeList.push( listItemNode );
  435. _selector.itemNodeObject[ data[ _selector.valueField ] ] = listItemNode;
  436. var isCurrent = false;
  437. if( _selector.currentItemData ){
  438. isCurrent = data[ _selector.valueField ] == _selector.currentItemData[ _selector.valueField ];
  439. }else if( _selector.value ){
  440. isCurrent = data[ _selector.valueField ] == _selector.value;
  441. }else if( _selector.text ){
  442. isCurrent = data[ _selector.textField ] == _selector.text;
  443. }
  444. if( isCurrent )_selector.setCurrentItem( listItemNode );
  445. _selector._postCreateItem(listItemNode, data)
  446. }
  447. });
  448. MWF.xApplication.MinderEditor.SaveTooltips = new Class({
  449. Implements: [Options, Events],
  450. Extends: MTooltips,
  451. options: {
  452. style : "default",
  453. axis: "y", //箭头在x轴还是y轴上展现
  454. position : { //node 固定的位置
  455. x : "auto", //x 轴上left center right, auto 系统自动计算
  456. y : "auto" //y轴上top middle bottom, auto 系统自动计算
  457. },
  458. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  459. nodeStyles : {
  460. "min-width" : "50px",
  461. "padding" : "0px",
  462. "border-radius" : "3px"
  463. }
  464. },
  465. _customNode : function( node, contentNode ){
  466. var div = new Element("div", {
  467. "text" : (this.app.autoSaveInter / 60000) + "分钟自动保存一次",
  468. "styles" : { "margin" : "10px" }
  469. }).inject( contentNode );
  470. new Element("input",{
  471. type : "checkbox",
  472. value : "true",
  473. checked : this.app.autoSave,
  474. events : {
  475. change : function( el ){
  476. if( el.target.get("checked") ){
  477. this.app.startAutoSave();
  478. }else{
  479. this.app.stopAutoSave();
  480. }
  481. }.bind(this)
  482. }
  483. }).inject( div, "top" );
  484. //var list = new Element("div", { styles : this.app.css.selectorListNode }).inject( contentNode );
  485. //var saveAsDiv = new Element("div", { "text": "另存为",
  486. // styles : this.app.css.selectorListItemNode,
  487. // events : {
  488. // mouseover : function(el){
  489. // el.target.setStyles( this.app.css.selectorListItemNode_over )
  490. // }.bind(this),
  491. // mouseleave : function(el){
  492. // el.target.setStyles( this.app.css.selectorListItemNode )
  493. // }.bind(this),
  494. // click : function(){
  495. // this.app.openSaveAsDialog();
  496. // }.bind(this)
  497. // }
  498. //}).inject( list );
  499. //
  500. //var renameDiv = new Element("div", { "text": "重命名",
  501. // styles : this.app.css.selectorListItemNode,
  502. // events : {
  503. // mouseover : function(el){
  504. // el.target.setStyles( this.app.css.selectorListItemNode_over )
  505. // }.bind(this),
  506. // mouseleave : function(el){
  507. // el.target.setStyles( this.app.css.selectorListItemNode )
  508. // }.bind(this),
  509. // click : function(){
  510. // this.app.openRenameDialog();
  511. // }.bind(this)
  512. // }
  513. //}).inject( list );
  514. }
  515. });
  516. MWF.require("MWF.widget.ImageClipper", null, false);
  517. MWF.xApplication.MinderEditor.HyperLinkForm = new Class({
  518. Extends: MPopupForm,
  519. Implements: [Options, Events],
  520. options: {
  521. "style": "minder",
  522. "width": 700,
  523. //"height": 300,
  524. "height": "300",
  525. "hasTop": true,
  526. "hasIcon": false,
  527. "draggable": true,
  528. "title" : "链接"
  529. },
  530. _createTableContent: function () {
  531. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  532. "<tr><td styles='formTableTitle' lable='url' width='20%'></td>" +
  533. " <td styles='formTableValue14' item='url' colspan='3'></td></tr>" +
  534. "<tr><td styles='formTableTitle' lable='title'></td>" +
  535. " <td styles='formTableValue14' item='title' colspan='3'></td></tr>" +
  536. "</table>";
  537. this.formTableArea.set("html", html);
  538. var data = this.app.minder.queryCommandValue('HyperLink');
  539. this.form = new MForm(this.formTableArea, data, {
  540. isEdited: true,
  541. style : "minder",
  542. hasColon : true,
  543. itemTemplate: {
  544. url: { text : "链接地址", notEmpty : true,
  545. validRule : { isInvalid : function( value, it ){
  546. var urlRegex = '^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$';
  547. var R_URL = new RegExp(urlRegex, 'i');
  548. return R_URL.test( value )
  549. }.bind(this)},
  550. validMessage : { isInvalid : "请输入正确的链接" },
  551. attr : { placeholder : "必填:以 http(s):// 或 ftp:// 开头" }
  552. },
  553. title: { text : "提示文本", attr : { placeholder : "选填:鼠标在链接上悬停时提示的文本" } }
  554. }
  555. }, this.app);
  556. this.form.load();
  557. },
  558. _createBottomContent: function () {
  559. if (this.isNew || this.isEdited) {
  560. this.okActionNode = new Element("button.inputOkButton", {
  561. "styles": this.css.inputOkButton,
  562. "text": "确定"
  563. }).inject(this.formBottomNode);
  564. this.okActionNode.addEvent("click", function (e) {
  565. this.save(e);
  566. }.bind(this));
  567. }
  568. this.removeAction = new Element("button.inputCancelButton", {
  569. "styles": this.css.inputCancelButton,
  570. "text": "删除链接"
  571. }).inject(this.formBottomNode);
  572. this.removeAction.addEvent("click", function (e) {
  573. this.remove(e);
  574. }.bind(this));
  575. this.cancelActionNode = new Element("button.inputCancelButton", {
  576. "styles": (this.isEdited || this.isNew || this.getEditPermission() ) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  577. "text": "关闭"
  578. }).inject(this.formBottomNode);
  579. this.cancelActionNode.addEvent("click", function (e) {
  580. this.close(e);
  581. }.bind(this));
  582. },
  583. save: function(){
  584. var data = this.form.getResult(true,null,true,false,true);
  585. if( data ){
  586. this.app.minder.execCommand('HyperLink', data.url, data.title || '');
  587. this.close();
  588. }
  589. },
  590. remove: function( ev ){
  591. this.app.minder.execCommand('HyperLink', null );
  592. this.close();
  593. }
  594. });
  595. MWF.xApplication.MinderEditor.ImageForm = new Class({
  596. Extends: MPopupForm,
  597. Implements: [Options, Events],
  598. options: {
  599. "style": "minder",
  600. "width": 800,
  601. "height": 640,
  602. "hasTop": true,
  603. "hasIcon": false,
  604. "draggable": true,
  605. "title" : "图片"
  606. },
  607. createContent: function () {
  608. this.createTab();
  609. this.formContentNode = new Element("div.formContentNode", {
  610. "styles": this.css.formContentNode
  611. }).inject(this.formNode);
  612. this.formTableContainer = new Element("div.formTableContainer", {
  613. "styles": this.css.formTableContainer
  614. }).inject(this.formContentNode);
  615. this.formTableArea = new Element("div.formTableArea", {
  616. "styles": this.css.formTableArea
  617. }).inject(this.formTableContainer);
  618. this._createTableContent();
  619. },
  620. _createTableContent: function () {
  621. this.linkContainer = new Element("div.linkContainer").inject(this.formTableArea);
  622. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  623. "<tr><td styles='formTableTitle' lable='url' width='20%'></td>" +
  624. " <td styles='formTableValue14' item='url' colspan='3'></td></tr>" +
  625. "<tr><td styles='formTableTitle' lable='title'></td>" +
  626. " <td styles='formTableValue14' item='title' colspan='3'></td></tr>" +
  627. "<tr><td styles='formTableTitle'>预览:</td>" +
  628. " <td styles='formTableValue14' item='preview' colspan='3'></td></tr>" +
  629. "</table>";
  630. this.linkContainer.set("html", html);
  631. var data = this.app.minder.queryCommandValue('image');
  632. this.linkform = new MForm(this.linkContainer, data, {
  633. isEdited: true,
  634. style : "minder",
  635. hasColon : true,
  636. itemTemplate: {
  637. url: { text : "图片地址", notEmpty : true,
  638. validRule : { isInvalid : function( value, it ){
  639. var R_URL = /^https?\:\/\/\w+/;
  640. return R_URL.test( value )
  641. }.bind(this)},
  642. validMessage : { isInvalid : "请输入正确的链接" },
  643. attr : { placeholder : "必填:以 http(s):// 开始" },
  644. event : { blur : function( it ){
  645. if( it.getValue() )it.form.getItem("preview").setValue( it.getValue() )
  646. }.bind(this)}
  647. },
  648. title: { text : "提示文本", attr : { placeholder : "选填:鼠标在图片上悬停时提示的文本" } },
  649. preview : { type : "img", defaultValue : data.url || "", style : { "max-width" : "400px", "max-height" : "260px" } }
  650. }
  651. }, this.app);
  652. this.linkform.load();
  653. this.uploadContainer = new Element("div.uploadContainer", { styles : {"display":"none"} }).inject( this.formTableArea );
  654. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  655. "<tr><td item='image' colspan='4' style='padding-bottom: 10px;'></td></tr>" +
  656. "<tr><td styles='formTableTitle' lable='title2' width='20%'></td>" +
  657. " <td styles='formTableValue14' item='title2' colspan='3'></td></tr>" +
  658. "</table>";
  659. this.uploadContainer.set("html", html);
  660. var data = this.app.minder.queryCommandValue('image');
  661. this.uploadform = new MForm(this.uploadContainer, data, {
  662. isEdited: true,
  663. style : "minder",
  664. hasColon : true,
  665. itemTemplate: {
  666. title2: { text : "提示文本", attr : { placeholder : "选填:鼠标在图片上悬停时提示的文本" } }
  667. }
  668. }, this.app);
  669. this.uploadform.load();
  670. this.image = new MWF.widget.ImageClipper(this.uploadContainer.getElement("[item='image']"), {
  671. "aspectRatio": 0,
  672. "description" : "",
  673. "imageUrl" : "",
  674. "ratioAdjustedEnable" : true,
  675. "reference" : this.app.data.id || "1111",
  676. "referenceType": "mindInfo",
  677. "fromFileEnable" : false,
  678. "resetEnable" : true
  679. });
  680. this.image.load();
  681. },
  682. createTab: function(){
  683. var _self = this;
  684. this.tabContainer = new Element("div.formTabContainer",{
  685. styles : this.css.formTabContainer
  686. }).inject(this.formNode);
  687. var tabNode = new Element("div.formTabNode", {
  688. "styles": this.css.formTabNode,
  689. "text" : "外链图片"
  690. }).inject(this.tabContainer);
  691. tabNode.addEvents({
  692. "mouseover" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode_over) }.bind({node : tabNode }),
  693. "mouseout" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode) }.bind({node : tabNode }),
  694. "click":function(){
  695. if( _self.currentTabNode )_self.currentTabNode.setStyles(_self.css.formTabNode);
  696. _self.currentTabNode = this.node;
  697. this.node.setStyles(_self.css.formTabNode_current);
  698. _self.linkContainer.setStyle("display","");
  699. _self.uploadContainer.setStyle("display","none");
  700. }.bind({ node : tabNode })
  701. });
  702. tabNode.setStyles( this.css.formTabNode_current );
  703. _self.currentTabNode = tabNode;
  704. var tabNode = new Element("div.tabNode", {
  705. "styles": this.css.formTabNode,
  706. "text" : "上传图片"
  707. }).inject(this.tabContainer);
  708. tabNode.addEvents({
  709. "mouseover" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode_over) }.bind({node : tabNode }),
  710. "mouseout" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode) }.bind({node : tabNode }),
  711. "click":function(){
  712. if( _self.currentTabNode )_self.currentTabNode.setStyles(_self.css.formTabNode);
  713. _self.currentTabNode = this.node;
  714. this.node.setStyles(_self.css.formTabNode_current);
  715. _self.linkContainer.setStyle("display","none");
  716. _self.uploadContainer.setStyle("display","");
  717. }.bind({ node : tabNode })
  718. })
  719. },
  720. _createBottomContent: function () {
  721. if (this.isNew || this.isEdited) {
  722. this.okActionNode = new Element("button.inputOkButton", {
  723. "styles": this.css.inputOkButton,
  724. "text": "确定"
  725. }).inject(this.formBottomNode);
  726. this.okActionNode.addEvent("click", function (e) {
  727. this.save(e);
  728. }.bind(this));
  729. }
  730. this.removeAction = new Element("button.inputCancelButton", {
  731. "styles": this.css.inputCancelButton,
  732. "text": "删除图片"
  733. }).inject(this.formBottomNode);
  734. this.removeAction.addEvent("click", function (e) {
  735. this.remove(e);
  736. }.bind(this));
  737. this.cancelActionNode = new Element("button.inputCancelButton", {
  738. "styles": (this.isEdited || this.isNew || this.getEditPermission() ) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  739. "text": "关闭"
  740. }).inject(this.formBottomNode);
  741. this.cancelActionNode.addEvent("click", function (e) {
  742. this.close(e);
  743. }.bind(this));
  744. },
  745. save: function(){
  746. if( this.image.getResizedImage() ){
  747. this.image.uploadImage( function( json ){
  748. var data = {
  749. url : MWF.xDesktop.getImageSrc( json.id ),
  750. title : this.uploadform.getResult(true,null,true,false,true)["title2"]
  751. };
  752. this.app.minder.execCommand('image', data.url, data.title || '', json.id );
  753. this.close();
  754. }.bind(this));
  755. }else{
  756. var data = this.linkform.getResult(true,null,true,false,true);
  757. if( data ){
  758. this.app.minder.execCommand('image', data.url, data.title || '', '');
  759. this.close();
  760. }
  761. }
  762. },
  763. remove: function( ev ){
  764. this.app.minder.execCommand('image', '' );
  765. this.close();
  766. },
  767. setFormNodeSize: function (width, height, top, left) {
  768. if (!width)width = this.options.width ? this.options.width : "50%";
  769. if (!height)height = this.options.height ? this.options.height : "50%";
  770. if (!top) top = this.options.top ? this.options.top : 0;
  771. if (!left) left = this.options.left ? this.options.left : 0;
  772. var containerSize = this.container.getSize();
  773. if( containerSize.x < width )width = containerSize.x;
  774. if( containerSize.y < height )height = containerSize.y;
  775. var allSize = this.app.content.getSize();
  776. var limitWidth = allSize.x; //window.screen.width
  777. var limitHeight = allSize.y; //window.screen.height
  778. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  779. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  780. 300 > width && (width = 300);
  781. 220 > height && (height = 220);
  782. top = top || parseInt((limitHeight - height) / 2, 10); //+appTitleSize.y);
  783. left = left || parseInt((limitWidth - width) / 2, 10);
  784. this.formAreaNode.setStyles({
  785. "width": "" + width + "px",
  786. "height": "" + height + "px",
  787. "top": "" + top + "px",
  788. "left": "" + left + "px"
  789. });
  790. this.formNode.setStyles({
  791. "width": "" + width + "px",
  792. "height": "" + height + "px"
  793. });
  794. var iconSize = this.formIconNode ? this.formIconNode.getSize() : {x: 0, y: 0};
  795. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  796. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  797. var tabSize = this.tabContainer ? this.tabContainer.getSize() : {x: 0, y: 0};
  798. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y - tabSize.y;
  799. //var formMargin = formHeight -iconSize.y;
  800. this.formContentNode.setStyles({
  801. "height": "" + contentHeight + "px"
  802. });
  803. this.formTableContainer.setStyles({
  804. "height": "" + contentHeight + "px"
  805. });
  806. }
  807. });
  808. MWF.xApplication.MinderEditor.SaveAsForm = new Class({
  809. Extends: MPopupForm,
  810. Implements: [Options, Events],
  811. options: {
  812. "style": "minder",
  813. "width": 800,
  814. //"height": 300,
  815. "height": "300",
  816. "hasTop": true,
  817. "hasIcon": false,
  818. "draggable": true,
  819. "title" : "另存为"
  820. },
  821. _createTableContent: function () {
  822. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  823. "<tr><td styles='formTableTitle' lable='folder' width='25%'></td>" +
  824. " <td styles='formTableValue14' item='folder' colspan='3'></td></tr>" +
  825. "<tr><td styles='formTableTitle' lable='newname'></td>" +
  826. " <td styles='formTableValue14' item='newname' colspan='3'></td></tr>" +
  827. "</table>";
  828. this.formTableArea.set("html", html);
  829. this.form = new MForm(this.formTableArea, this.data || {}, {
  830. isEdited: true,
  831. style : "minder",
  832. hasColon : true,
  833. itemTemplate: {
  834. folder: { text : "选择文件夹", notEmpty : true, attr : { readonly : true }, defaultValue : "根目录" },
  835. newname: { text : "新文件名称" }
  836. }
  837. }, this.app);
  838. this.form.load();
  839. this.loadFolderSelect();
  840. },
  841. _createBottomContent: function () {
  842. if (this.isNew || this.isEdited) {
  843. this.okActionNode = new Element("button.inputOkButton", {
  844. "styles": this.css.inputOkButton,
  845. "text": "确定"
  846. }).inject(this.formBottomNode);
  847. this.okActionNode.addEvent("click", function (e) {
  848. this.save(e);
  849. }.bind(this));
  850. }
  851. this.cancelActionNode = new Element("button.inputCancelButton", {
  852. "styles": (this.isEdited || this.isNew || this.getEditPermission() ) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  853. "text": "关闭"
  854. }).inject(this.formBottomNode);
  855. this.cancelActionNode.addEvent("click", function (e) {
  856. this.close(e);
  857. }.bind(this));
  858. },
  859. save: function(){
  860. var data = this.form.getResult(true,null,true,false,true);
  861. if( data ){
  862. this.app.saveAs( this.folderId || "root", data.newname );
  863. this.close();
  864. }
  865. },
  866. loadFolderSelect: function() {
  867. MWF.xDesktop.requireApp("Minder", "Common", null, false);
  868. this.folderSelect = new MWF.xApplication.Minder.FolderSelector( this.app.content, this.form.getItem("folder").getElements()[0], this.app, {}, {
  869. onSelect : function( folderData ){
  870. this.form.getItem("folder").setValue( folderData.name );
  871. this.folderId = folderData.id;
  872. }.bind(this)
  873. } );
  874. }
  875. });
  876. MWF.xApplication.MinderEditor.NewNameForm = new Class({
  877. Extends: MPopupForm,
  878. Implements: [Options, Events],
  879. options: {
  880. "style": "minder",
  881. "width": 700,
  882. //"height": 300,
  883. "height": "200",
  884. "hasTop": true,
  885. "hasIcon": false,
  886. "draggable": true,
  887. "title" : "重命名"
  888. },
  889. _createTableContent: function () {
  890. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  891. "<tr><td styles='formTableTitle' lable='newname' width='25%'></td>" +
  892. " <td styles='formTableValue14' item='newname' colspan='3'></td></tr>" +
  893. "</table>";
  894. this.formTableArea.set("html", html);
  895. this.form = new MForm(this.formTableArea, this.data || {}, {
  896. isEdited: true,
  897. style : "minder",
  898. hasColon : true,
  899. itemTemplate: {
  900. newname: { text : "新文件名称", notEmpty : true }
  901. }
  902. }, this.app);
  903. this.form.load();
  904. },
  905. _createBottomContent: function () {
  906. if (this.isNew || this.isEdited) {
  907. this.okActionNode = new Element("button.inputOkButton", {
  908. "styles": this.css.inputOkButton,
  909. "text": "确定"
  910. }).inject(this.formBottomNode);
  911. this.okActionNode.addEvent("click", function (e) {
  912. this.save(e);
  913. }.bind(this));
  914. }
  915. this.cancelActionNode = new Element("button.inputCancelButton", {
  916. "styles": (this.isEdited || this.isNew || this.getEditPermission() ) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  917. "text": "关闭"
  918. }).inject(this.formBottomNode);
  919. this.cancelActionNode.addEvent("click", function (e) {
  920. this.close(e);
  921. }.bind(this));
  922. },
  923. save: function(){
  924. var data = this.form.getResult(true,null,true,false,true);
  925. if( data ){
  926. this.app.setNewName( data.newname );
  927. this.close();
  928. }
  929. }
  930. });
  931. MWF.xApplication.MinderEditor.ExportTooltips = new Class({
  932. Implements: [Options, Events],
  933. Extends: MTooltips,
  934. options: {
  935. style : "default",
  936. axis: "y", //箭头在x轴还是y轴上展现
  937. position : { //node 固定的位置
  938. x : "auto", //x 轴上left center right, auto 系统自动计算
  939. y : "auto" //y轴上top middle bottom, auto 系统自动计算
  940. },
  941. event : "mouseenter", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  942. nodeStyles : {
  943. "padding-top" : "5px",
  944. "min-width" : "210px",
  945. "padding" : "0px",
  946. "border-radius" : "5px"
  947. }
  948. },
  949. _loadCustom : function( callback ){
  950. this.css = this.app.css;
  951. if( document.id( "km-csrf" ) ){
  952. document.id( "km-csrf").set( "value", this.app.data.id );
  953. }else{
  954. new Element("input", {
  955. id : "km-csrf",
  956. "styles" : { display : "none" }
  957. }).inject( this.contentNode )
  958. }
  959. this.app.loadExtentResource( function(){
  960. var contentNode = this.contentNode;
  961. var list = new Element("div", { styles : this.css.selectorListNode }).inject( contentNode );
  962. var protocols = [];
  963. var pool = kityminder.data.getRegisterProtocol();
  964. for(var name in pool) {
  965. if (pool.hasOwnProperty(name) && pool[name].encode) {
  966. protocols.push(pool[name]);
  967. }
  968. }
  969. protocols.each(function( p ) {
  970. new Element("div", { "text": (p.fileDescription + "("+ p.fileExtension +")"),
  971. styles : this.css.selectorListItemNode,
  972. events : {
  973. mouseover : function(el){
  974. el.target.setStyles( this.css.selectorListItemNode_over )
  975. }.bind(this),
  976. mouseleave : function(el){
  977. el.target.setStyles( this.css.selectorListItemNode )
  978. }.bind(this),
  979. click : function(){
  980. this.exportFile(p);
  981. }.bind(this)
  982. }
  983. }).inject( list );
  984. }.bind(this));
  985. if(callback)callback();
  986. }.bind(this))
  987. },
  988. exportFile : function( protocol ){
  989. this.createProgressBar();
  990. this.minder = this.app.minder;
  991. var fileName = this.app.data.name || this.minder.getRoot().getText();
  992. filename = fileName + protocol.fileExtension;
  993. var mineType = protocol.mineType || 'text/plain';
  994. var options = {
  995. download: true,
  996. filename: filename
  997. };
  998. if( protocol.name == "png" ){
  999. var converter = new MWF.xApplication.MinderEditor.Converter(this.app, this.minder);
  1000. converter.toPng(null, null, function( img ){
  1001. var link = new Element("a", {"text": filename}).inject(this.progressBarTextNode);
  1002. link.download = fileName;
  1003. link.href = URL.createObjectURL(img);
  1004. //link.href = "data:text/plain," + content;
  1005. var evt = document.createEvent("HTMLEvents");
  1006. evt.initEvent("click", false, false);
  1007. link.dispatchEvent(evt);
  1008. link.click();
  1009. this.progressBarNode.destroy();
  1010. this.progressBarNode = null;
  1011. this.progressBarTextNode = null;
  1012. this.progressBar = null;
  1013. this.progressBarPercent = null;
  1014. }.bind(this));
  1015. }else{
  1016. this.minder.exportData(protocol.name, options).then(function(data) {
  1017. if (protocol.name == 'freemind') {
  1018. return;
  1019. }
  1020. switch (protocol.dataType) {
  1021. case 'text':
  1022. return this.doDownload(this.buildDataUrl(mineType, data), filename, 'text');
  1023. case 'base64':
  1024. return this.doDownload(data, filename, 'base64');
  1025. case 'blob':
  1026. return null;
  1027. }
  1028. return null;
  1029. }.bind(this));
  1030. }
  1031. },
  1032. doDownload : function (url, filename, type) {
  1033. var Promise = kityminder.Promise;
  1034. var stamp = +new Date() * 1e5 + Math.floor(Math.random() * (1e5 - 1));
  1035. stamp = stamp.toString(36);
  1036. var ret = new Promise(function(resolve, reject) {
  1037. var ticker = 0;
  1038. var MAX_TICK = 30;
  1039. var interval = 1000;
  1040. //function check() {
  1041. // if (document.cookie.indexOf(stamp + '=1') != -1) return resolve([stamp, ticker]);
  1042. // if (++ticker > MAX_TICK) {
  1043. // resolve([stamp, ticker]);
  1044. // }
  1045. // setTimeout(check, interval);
  1046. //}
  1047. //
  1048. //setTimeout(check, interval);
  1049. var content = url.split(',')[1];
  1050. this.saveToLocal( content, filename );
  1051. return resolve([stamp, ticker]);
  1052. }.bind(this));
  1053. //var form = new Element("form",{
  1054. // 'action': 'home/download',
  1055. // 'method': 'POST',
  1056. // 'accept-charset': 'utf-8'
  1057. //});
  1058. //var $content = new Element("input",{
  1059. // name: 'content',
  1060. // type: 'hidden',
  1061. // value: decodeURIComponent(content)
  1062. //}).inject( from );
  1063. //
  1064. //var $type = new Element("input",{
  1065. // name: 'type',
  1066. // type: 'hidden',
  1067. // value: type
  1068. //}).inject( from );
  1069. //
  1070. //var $filename = new Element("input",{
  1071. // name: 'filename',
  1072. // type: 'hidden',
  1073. // value: filename
  1074. //}).inject( from );
  1075. //
  1076. //var $csrfToken = new Element("input",{
  1077. // name: 'csrf_token',
  1078. // type: 'hidden',
  1079. // value: $('#km-csrf').val()
  1080. //}).inject( from );
  1081. //
  1082. //
  1083. //if (kity.Browser.ie) {
  1084. // new Element("input",{
  1085. // name : "iehack",
  1086. // value : "1"
  1087. // }).inject( form );
  1088. //}
  1089. //
  1090. //new Element("input",{
  1091. // name : "stamp",
  1092. // value : stamp
  1093. //}).inject( form );
  1094. //
  1095. //form.inject('body');
  1096. //form.submit();
  1097. //form.destroy();
  1098. return ret;
  1099. },
  1100. buildDataUrl: function (mineType, data) {
  1101. return 'data:' + mineType + '; utf-8,' + encodeURIComponent(data);
  1102. },
  1103. saveToLocal: function( data, filename ){
  1104. if (window.hasOwnProperty("ActiveXObject")){
  1105. var win = window.open("", "_blank");
  1106. win.document.write(decodeURIComponent(data));
  1107. }else{
  1108. this.downloadFile(filename, decodeURIComponent(data));
  1109. }
  1110. this.progressBarNode.destroy();
  1111. this.progressBarNode = null;
  1112. this.progressBarTextNode = null;
  1113. this.progressBar = null;
  1114. this.progressBarPercent = null;
  1115. this.close();
  1116. },
  1117. downloadFile: function(fileName, content){
  1118. var link = new Element("a", {"text": this.data.name}).inject(this.progressBarTextNode);
  1119. var blob = new Blob([content]);
  1120. link.download = fileName;
  1121. link.href = URL.createObjectURL(blob);
  1122. //link.href = "data:text/plain," + content;
  1123. var evt = document.createEvent("HTMLEvents");
  1124. evt.initEvent("click", false, false);
  1125. link.dispatchEvent(evt);
  1126. link.click();
  1127. },
  1128. createProgressBar: function(){
  1129. this.node.hide();
  1130. this.progressBarNode = new Element("div", {"styles": this.css.progressBarNode});
  1131. this.progressBarNode.inject(this.container);
  1132. this.progressBarNode.position({
  1133. relativeTo: this.container,
  1134. position: 'center',
  1135. edge: 'center'
  1136. });
  1137. this.progressBarTextNode = new Element("div", {"styles": this.css.progressBarTextNode}).inject(this.progressBarNode);
  1138. this.progressBar = new Element("div", {"styles": this.css.progressBar}).inject(this.progressBarNode);
  1139. this.progressBarPercent = new Element("div", {"styles": this.css.progressBarPercent}).inject(this.progressBar);
  1140. }
  1141. });
  1142. MWF.xApplication.MinderEditor.ExportForm = new Class({
  1143. Extends: MPopupForm,
  1144. Implements: [Options, Events],
  1145. options: {
  1146. "style": "minder",
  1147. "width": 400,
  1148. //"height": 300,
  1149. "height": "300",
  1150. "hasTop": true,
  1151. "hasIcon": false,
  1152. "draggable": true,
  1153. "hasBottom" : false,
  1154. "title" : "选择导出的文件类型"
  1155. },
  1156. _createTableContent : function( callback ){
  1157. this.css = this.app.css;
  1158. if( document.id( "km-csrf" ) ){
  1159. document.id( "km-csrf").set( "value", this.app.data.id );
  1160. }else{
  1161. new Element("input", {
  1162. id : "km-csrf",
  1163. "styles" : { display : "none" }
  1164. }).inject( this.formTableArea )
  1165. }
  1166. this.app.loadExtentResource( function(){
  1167. var contentNode = this.formTableArea;
  1168. var list = new Element("div", { styles : this.css.selectorListNode }).inject( contentNode );
  1169. var protocols = [];
  1170. debugger;
  1171. var pool = kityminder.data.getRegisterProtocol();
  1172. for(var name in pool) {
  1173. if (pool.hasOwnProperty(name) && pool[name].encode) {
  1174. protocols.push(pool[name]);
  1175. }
  1176. }
  1177. protocols.each(function( p ) {
  1178. new Element("div", { "text": (p.fileDescription + "("+ p.fileExtension +")"),
  1179. styles : this.css.selectorListItemNode,
  1180. events : {
  1181. mouseover : function(el){
  1182. el.target.setStyles( this.css.selectorListItemNode_over )
  1183. }.bind(this),
  1184. mouseleave : function(el){
  1185. el.target.setStyles( this.css.selectorListItemNode )
  1186. }.bind(this),
  1187. click : function(){
  1188. this.exportFile(p);
  1189. }.bind(this)
  1190. }
  1191. }).inject( list );
  1192. }.bind(this));
  1193. if(callback)callback();
  1194. }.bind(this))
  1195. },
  1196. exportFile : function( protocol ){
  1197. this.createProgressBar();
  1198. this.minder = this.app.minder;
  1199. var fileName = this.app.data.name || this.minder.getRoot().getText();
  1200. filename = fileName + protocol.fileExtension;
  1201. var mineType = protocol.mineType || 'text/plain';
  1202. var options = {
  1203. download: true,
  1204. filename: filename
  1205. };
  1206. if( protocol.name == "png" ){
  1207. var converter = new MWF.xApplication.MinderEditor.Converter(this.app, this.minder);
  1208. converter.toPng(null, null, function( img ){
  1209. var link = new Element("a", {"text": filename}).inject(this.progressBarTextNode);
  1210. link.download = fileName;
  1211. link.href = URL.createObjectURL(img);
  1212. //link.href = "data:text/plain," + content;
  1213. var evt = document.createEvent("HTMLEvents");
  1214. evt.initEvent("click", false, false);
  1215. link.dispatchEvent(evt);
  1216. link.click();
  1217. this.progressBarNode.destroy();
  1218. this.progressBarNode = null;
  1219. this.progressBarTextNode = null;
  1220. this.progressBar = null;
  1221. this.progressBarPercent = null;
  1222. }.bind(this));
  1223. }else{
  1224. this.minder.exportData(protocol.name, options).then(function(data) {
  1225. if (protocol.name == 'freemind') {
  1226. return;
  1227. }
  1228. switch (protocol.dataType) {
  1229. case 'text':
  1230. return this.doDownload(this.buildDataUrl(mineType, data), filename, 'text');
  1231. case 'base64':
  1232. return this.doDownload(data, filename, 'base64');
  1233. case 'blob':
  1234. return null;
  1235. }
  1236. return null;
  1237. }.bind(this));
  1238. }
  1239. },
  1240. doDownload : function (url, filename, type) {
  1241. var Promise = kityminder.Promise;
  1242. var stamp = +new Date() * 1e5 + Math.floor(Math.random() * (1e5 - 1));
  1243. stamp = stamp.toString(36);
  1244. var ret = new Promise(function(resolve, reject) {
  1245. var ticker = 0;
  1246. var MAX_TICK = 30;
  1247. var interval = 1000;
  1248. //function check() {
  1249. // if (document.cookie.indexOf(stamp + '=1') != -1) return resolve([stamp, ticker]);
  1250. // if (++ticker > MAX_TICK) {
  1251. // resolve([stamp, ticker]);
  1252. // }
  1253. // setTimeout(check, interval);
  1254. //}
  1255. //
  1256. //setTimeout(check, interval);
  1257. var content = url.split(',')[1];
  1258. this.saveToLocal( content, filename );
  1259. return resolve([stamp, ticker]);
  1260. }.bind(this));
  1261. //var form = new Element("form",{
  1262. // 'action': 'home/download',
  1263. // 'method': 'POST',
  1264. // 'accept-charset': 'utf-8'
  1265. //});
  1266. //var $content = new Element("input",{
  1267. // name: 'content',
  1268. // type: 'hidden',
  1269. // value: decodeURIComponent(content)
  1270. //}).inject( from );
  1271. //
  1272. //var $type = new Element("input",{
  1273. // name: 'type',
  1274. // type: 'hidden',
  1275. // value: type
  1276. //}).inject( from );
  1277. //
  1278. //var $filename = new Element("input",{
  1279. // name: 'filename',
  1280. // type: 'hidden',
  1281. // value: filename
  1282. //}).inject( from );
  1283. //
  1284. //var $csrfToken = new Element("input",{
  1285. // name: 'csrf_token',
  1286. // type: 'hidden',
  1287. // value: $('#km-csrf').val()
  1288. //}).inject( from );
  1289. //
  1290. //
  1291. //if (kity.Browser.ie) {
  1292. // new Element("input",{
  1293. // name : "iehack",
  1294. // value : "1"
  1295. // }).inject( form );
  1296. //}
  1297. //
  1298. //new Element("input",{
  1299. // name : "stamp",
  1300. // value : stamp
  1301. //}).inject( form );
  1302. //
  1303. //form.inject('body');
  1304. //form.submit();
  1305. //form.destroy();
  1306. return ret;
  1307. },
  1308. buildDataUrl: function (mineType, data) {
  1309. return 'data:' + mineType + '; utf-8,' + encodeURIComponent(data);
  1310. },
  1311. saveToLocal: function( data, filename ){
  1312. if (window.hasOwnProperty("ActiveXObject")){
  1313. var win = window.open("", "_blank");
  1314. win.document.write(decodeURIComponent(data));
  1315. }else{
  1316. this.downloadFile(filename, decodeURIComponent(data));
  1317. }
  1318. this.progressBarNode.destroy();
  1319. this.progressBarNode = null;
  1320. this.progressBarTextNode = null;
  1321. this.progressBar = null;
  1322. this.progressBarPercent = null;
  1323. this.close();
  1324. },
  1325. downloadFile: function(fileName, content){
  1326. var link = new Element("a", {"text": this.data.name}).inject(this.progressBarTextNode);
  1327. var blob = new Blob([content]);
  1328. link.download = fileName;
  1329. link.href = URL.createObjectURL(blob);
  1330. //link.href = "data:text/plain," + content;
  1331. var evt = document.createEvent("HTMLEvents");
  1332. evt.initEvent("click", false, false);
  1333. link.dispatchEvent(evt);
  1334. link.click();
  1335. },
  1336. createProgressBar: function(){
  1337. this.progressBarNode = new Element("div", {"styles": this.css.progressBarNode});
  1338. this.progressBarNode.inject(this.container);
  1339. this.progressBarNode.position({
  1340. relativeTo: this.container,
  1341. position: 'center',
  1342. edge: 'center'
  1343. });
  1344. this.progressBarTextNode = new Element("div", {"styles": this.css.progressBarTextNode}).inject(this.progressBarNode);
  1345. this.progressBar = new Element("div", {"styles": this.css.progressBar}).inject(this.progressBarNode);
  1346. this.progressBarPercent = new Element("div", {"styles": this.css.progressBarPercent}).inject(this.progressBar);
  1347. this.close();
  1348. }
  1349. });