Pages.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201
  1. /**
  2. * Copyright (c) 2006-2016, JGraph Ltd
  3. * Copyright (c) 2006-2016, Gaudenz Alder
  4. */
  5. /**
  6. * Constructs a new point for the optional x and y coordinates. If no
  7. * coordinates are given, then the default values for <x> and <y> are used.
  8. * @constructor
  9. * @class Implements a basic 2D point. Known subclassers = {@link mxRectangle}.
  10. * @param {number} x X-coordinate of the point.
  11. * @param {number} y Y-coordinate of the point.
  12. */
  13. /**
  14. * Global types
  15. */
  16. function DiagramPage(node, id)
  17. {
  18. this.node = node;
  19. if (id != null)
  20. {
  21. this.node.setAttribute('id', id);
  22. }
  23. else if (this.getId() == null)
  24. {
  25. this.node.setAttribute('id', Editor.guid());
  26. }
  27. };
  28. /**
  29. * Holds the diagram node for the page.
  30. */
  31. DiagramPage.prototype.node = null;
  32. /**
  33. * Holds the root cell for the page.
  34. */
  35. DiagramPage.prototype.root = null;
  36. /**
  37. * Holds the view state for the page.
  38. */
  39. DiagramPage.prototype.viewState = null;
  40. /**
  41. * Specifies if the diagram in the page was been modified
  42. * and the cached XML data needs to be updated.
  43. */
  44. DiagramPage.prototype.diagramModified = false;
  45. /**
  46. *
  47. */
  48. DiagramPage.prototype.getId = function()
  49. {
  50. return this.node.getAttribute('id');
  51. };
  52. /**
  53. *
  54. */
  55. DiagramPage.prototype.getName = function()
  56. {
  57. return this.node.getAttribute('name');
  58. };
  59. /**
  60. *
  61. */
  62. DiagramPage.prototype.setName = function(value)
  63. {
  64. if (value == null)
  65. {
  66. this.node.removeAttribute('name');
  67. }
  68. else
  69. {
  70. this.node.setAttribute('name', value);
  71. }
  72. };
  73. /**
  74. * Sets the diagram modified flag.
  75. */
  76. DiagramPage.prototype.setDiagramModified = function(value)
  77. {
  78. this.diagramModified = value;
  79. };
  80. /**
  81. * Returns the diagram modified flag.
  82. */
  83. DiagramPage.prototype.isDiagramModified = function()
  84. {
  85. return this.diagramModified;
  86. };
  87. /**
  88. * Change types
  89. */
  90. function RenamePage(ui, page, name)
  91. {
  92. this.ui = ui;
  93. this.page = page;
  94. this.name = name;
  95. this.previous = name;
  96. }
  97. /**
  98. * Implementation of the undoable page rename.
  99. */
  100. RenamePage.prototype.execute = function()
  101. {
  102. var tmp = this.page.getName();
  103. this.page.setName(this.previous);
  104. this.name = this.previous;
  105. this.previous = tmp;
  106. // Required to update page name in placeholders
  107. this.ui.editor.graph.updatePlaceholders();
  108. this.ui.editor.fireEvent(new mxEventObject('pageRenamed'));
  109. };
  110. /**
  111. * Undoable change of page title.
  112. */
  113. function MovePage(ui, oldIndex, newIndex)
  114. {
  115. this.ui = ui;
  116. this.oldIndex = oldIndex;
  117. this.newIndex = newIndex;
  118. }
  119. /**
  120. * Implementation of the undoable page rename.
  121. */
  122. MovePage.prototype.execute = function()
  123. {
  124. this.ui.pages.splice(this.newIndex, 0, this.ui.pages.splice(this.oldIndex, 1)[0]);
  125. var tmp = this.oldIndex;
  126. this.oldIndex = this.newIndex;
  127. this.newIndex = tmp;
  128. // Required to update page numbers in placeholders
  129. this.ui.editor.graph.updatePlaceholders();
  130. this.ui.editor.fireEvent(new mxEventObject('pageMoved'));
  131. };
  132. /**
  133. * Class: mxCurrentRootChange
  134. *
  135. * Action to change the current root in a view.
  136. *
  137. * Constructor: mxCurrentRootChange
  138. *
  139. * Constructs a change of the current root in the given view.
  140. */
  141. function SelectPage(ui, page, viewState)
  142. {
  143. this.ui = ui;
  144. this.page = page;
  145. this.previousPage = page;
  146. if (page != null)
  147. {
  148. this.ui.updatePageRoot(page);
  149. if (viewState != null)
  150. {
  151. page.viewState = viewState;
  152. }
  153. }
  154. };
  155. /**
  156. * Executes selection of a new page.
  157. */
  158. SelectPage.prototype.execute = function()
  159. {
  160. var prevIndex = mxUtils.indexOf(this.ui.pages, this.previousPage);
  161. if (this.page != null && prevIndex >= 0)
  162. {
  163. var page = this.ui.currentPage;
  164. var editor = this.ui.editor;
  165. var graph = editor.graph;
  166. if (page.isDiagramModified())
  167. {
  168. page.setDiagramModified(false);
  169. // Updates cached diagram data
  170. EditorUi.removeChildNodes(page.node);
  171. page.node.appendChild(editor.getGraphXml(true));
  172. }
  173. page.viewState = graph.getViewState();
  174. page.root = graph.model.root;
  175. if (page.model != null)
  176. {
  177. // Updates internal structures of offpage model
  178. page.model.rootChanged(page.root);
  179. }
  180. // Removes the previous cells and clears selection
  181. graph.view.clear(page.root, true);
  182. graph.clearSelection();
  183. // Switches the current page
  184. this.ui.currentPage = this.previousPage;
  185. this.previousPage = page;
  186. page = this.ui.currentPage;
  187. // Switches the root cell and sets the view state
  188. graph.model.prefix = Editor.guid() + '-';
  189. graph.model.rootChanged(page.root);
  190. graph.setViewState(page.viewState);
  191. // Handles grid state in chromeless mode which is stored in Editor instance
  192. graph.gridEnabled = graph.gridEnabled && (!this.ui.editor.isChromelessView() ||
  193. urlParams['grid'] == '1');
  194. // Fires events
  195. editor.graph.fireEvent(new mxEventObject(mxEvent.ROOT));
  196. editor.fireEvent(new mxEventObject('pageSelected', 'change', this));
  197. }
  198. };
  199. /**
  200. *
  201. */
  202. function ChangePage(ui, page, select, index, noSelect)
  203. {
  204. SelectPage.call(this, ui, select);
  205. this.relatedPage = page;
  206. this.index = index;
  207. this.previousIndex = null;
  208. this.noSelect = noSelect;
  209. };
  210. mxUtils.extend(ChangePage, SelectPage);
  211. /**
  212. * Function: execute
  213. *
  214. * Changes the current root of the view.
  215. */
  216. ChangePage.prototype.execute = function()
  217. {
  218. // Fires event to setting view state from realtime
  219. this.ui.editor.fireEvent(new mxEventObject('beforePageChange', 'change', this));
  220. this.previousIndex = this.index;
  221. if (this.index == null)
  222. {
  223. var tmp = mxUtils.indexOf(this.ui.pages, this.relatedPage);
  224. this.ui.pages.splice(tmp, 1);
  225. this.index = tmp;
  226. }
  227. else
  228. {
  229. this.ui.pages.splice(this.index, 0, this.relatedPage);
  230. this.index = null;
  231. }
  232. if (!this.noSelect)
  233. {
  234. SelectPage.prototype.execute.apply(this, arguments);
  235. }
  236. };
  237. /**
  238. *
  239. */
  240. function ReplaceDiagram(ui, data)
  241. {
  242. this.ui = ui;
  243. this.data = data;
  244. };
  245. /**
  246. * Function: execute
  247. *
  248. * Changes the current root of the view.
  249. */
  250. ReplaceDiagram.prototype.execute = function()
  251. {
  252. var graph = this.ui.editor.graph;
  253. var data = this.ui.editor.getGraphXml();
  254. this.ui.editor.readGraphState(this.data);
  255. this.ui.editor.updateGraphComponents();
  256. var dec = new mxCodec(this.data.ownerDocument);
  257. var model = new mxGraphModel();
  258. dec.decode(this.data, model);
  259. this.data = data;
  260. if (this.ui.currentPage)
  261. {
  262. this.ui.currentPage.viewState = graph.getViewState();
  263. this.ui.currentPage.root = model.root;
  264. if (this.ui.currentPage.model != null)
  265. {
  266. // Updates internal structures of offpage model
  267. this.ui.currentPage.model.rootChanged(this.ui.currentPage.model.root);
  268. }
  269. }
  270. graph.view.clear(graph.model.root, true);
  271. graph.model.rootChanged(model.root);
  272. graph.fireEvent(new mxEventObject(mxEvent.ROOT));
  273. };
  274. /**
  275. * Specifies the height of the tab container. Default is 36.
  276. */
  277. EditorUi.prototype.tabContainerHeight = 36;
  278. /**
  279. * Returns the index of the selected page.
  280. */
  281. EditorUi.prototype.setTabContainerVisible = function(visible)
  282. {
  283. if (visible)
  284. {
  285. this.tabContainerHeight = EditorUi.prototype.tabContainerHeight;
  286. }
  287. else
  288. {
  289. this.tabContainerHeight = 0;
  290. }
  291. if (isLocalStorage)
  292. {
  293. mxSettings.settings.pages = this.tabContainerHeight > 0;
  294. mxSettings.save();
  295. }
  296. this.editor.updateGraphComponents();
  297. this.refresh();
  298. };
  299. /**
  300. * Returns the index of the selected page.
  301. */
  302. EditorUi.prototype.isTabContainerVisible = function()
  303. {
  304. return this.tabContainerHeight > 0;
  305. };
  306. /**
  307. * Returns the index of the selected page.
  308. */
  309. EditorUi.prototype.getSelectedPageIndex = function()
  310. {
  311. return this.getPageIndex(this.currentPage);
  312. };
  313. /**
  314. * Returns the index of the given page.
  315. */
  316. EditorUi.prototype.getPageIndex = function(page)
  317. {
  318. var result = null;
  319. if (this.pages != null && page != null)
  320. {
  321. for (var i = 0; i < this.pages.length; i++)
  322. {
  323. if (this.pages[i] == page)
  324. {
  325. result = i;
  326. break;
  327. }
  328. }
  329. }
  330. return result;
  331. };
  332. /**
  333. * Returns the page with the given ID from the optional array of pages.
  334. */
  335. EditorUi.prototype.getPageById = function(id, pages)
  336. {
  337. pages = (pages != null) ? pages : this.pages;
  338. if (pages != null)
  339. {
  340. for (var i = 0; i < pages.length; i++)
  341. {
  342. if (pages[i].getId() == id)
  343. {
  344. return pages[i];
  345. }
  346. }
  347. }
  348. return null;
  349. };
  350. /**
  351. * Returns the background image for the given page link.
  352. */
  353. EditorUi.prototype.createImageForPageLink = function(src, sourcePage, sourceGraph, addFonts)
  354. {
  355. var comma = src.indexOf(',');
  356. var result = null;
  357. if (comma > 0)
  358. {
  359. var page = this.getPageById(src.substring(comma + 1));
  360. if (page != null && page != sourcePage)
  361. {
  362. result = this.getImageForPage(page, sourcePage, sourceGraph, addFonts);
  363. result.originalSrc = src;
  364. }
  365. }
  366. if (result == null)
  367. {
  368. result = {originalSrc: src};
  369. }
  370. return result;
  371. };
  372. /**
  373. * Returns true if the given string contains an mxfile.
  374. */
  375. EditorUi.prototype.pageSelected = function()
  376. {
  377. var graph = this.editor.graph;
  378. var page = this.currentPage;
  379. if (page != null)
  380. {
  381. graph.tooltipHandler.hide();
  382. if (page.viewState == null ||
  383. page.viewState.scrollTop == null ||
  384. page.viewState.scrollLeft == null)
  385. {
  386. // Selects unlocked layer if page was never shown
  387. graph.selectUnlockedLayer();
  388. this.resetScrollbars();
  389. if (graph.isLightboxView())
  390. {
  391. this.lightboxFit();
  392. }
  393. if (this.chromelessResize != null)
  394. {
  395. graph.container.scrollleft = 0;
  396. graph.container.scrollTop = 0;
  397. this.chromelessResize();
  398. }
  399. }
  400. else
  401. {
  402. // Restores scrollbar positions
  403. graph.setScrollbarPositions(page.viewState,
  404. graph.view.translate.x, graph.view.translate.y);
  405. }
  406. this.updateTabContainer();
  407. this.scrollToPage();
  408. }
  409. };
  410. /**
  411. * Returns true if the given string contains an mxfile.
  412. */
  413. EditorUi.prototype.getImageForPage = function(page, sourcePage, sourceGraph, addFonts)
  414. {
  415. sourceGraph = (sourceGraph != null) ? sourceGraph : this.editor.graph;
  416. var graphGetGlobalVariable = sourceGraph.getGlobalVariable;
  417. var graph = this.createTemporaryGraph(sourceGraph.getStylesheet());
  418. graph.defaultPageBackgroundColor = sourceGraph.defaultPageBackgroundColor;
  419. graph.shapeBackgroundColor = sourceGraph.shapeBackgroundColor;
  420. graph.shapeForegroundColor = sourceGraph.shapeForegroundColor;
  421. var index = this.getPageIndex((sourcePage != null) ?
  422. sourcePage : this.currentPage);
  423. graph.getGlobalVariable = function(name)
  424. {
  425. if (name == 'pagenumber')
  426. {
  427. return index + 1;
  428. }
  429. else if (name == 'page' && sourcePage != null)
  430. {
  431. return sourcePage.getName();
  432. }
  433. else
  434. {
  435. return graphGetGlobalVariable.apply(this, arguments);
  436. }
  437. };
  438. document.body.appendChild(graph.container);
  439. this.updatePageRoot(page);
  440. graph.model.setRoot(page.root);
  441. var temp = Graph.foreignObjectWarningText;
  442. Graph.foreignObjectWarningText = '';
  443. var theme = (Editor.cssDarkMode || Editor.isDarkMode()) ?
  444. 'dark' : 'light';
  445. var svgRoot = graph.getSvg(null, null, null, null, null, null, null,
  446. null, null, null, addFonts, theme, null, null, true, true);
  447. var bounds = graph.getGraphBounds();
  448. document.body.removeChild(graph.container);
  449. Graph.foreignObjectWarningText = temp;
  450. return new mxImage(Editor.createSvgDataUri(mxUtils.getXml(svgRoot)),
  451. bounds.width, bounds.height, bounds.x, bounds.y);
  452. };
  453. /**
  454. * Returns true if the given string contains an mxfile.
  455. */
  456. EditorUi.prototype.initPages = function()
  457. {
  458. if (!this.editor.graph.standalone)
  459. {
  460. this.actions.addAction('previousPage', mxUtils.bind(this, function()
  461. {
  462. this.selectNextPage(false);
  463. }));
  464. this.actions.addAction('nextPage', mxUtils.bind(this, function()
  465. {
  466. this.selectNextPage(true);
  467. }));
  468. if (this.isPagesEnabled())
  469. {
  470. this.keyHandler.bindAction(33, true, 'previousPage', true); // Ctrl+Shift+PageUp
  471. this.keyHandler.bindAction(34, true, 'nextPage', true); // Ctrl+Shift+PageDown
  472. }
  473. // Updates the tabs after loading the diagram
  474. var graph = this.editor.graph;
  475. var graphViewValidateBackground = graph.view.validateBackground;
  476. graph.view.validateBackground = mxUtils.bind(this, function()
  477. {
  478. if (this.tabContainer != null)
  479. {
  480. var prevHeight = this.tabContainer.style.height;
  481. if (this.fileNode == null || this.pages == null ||
  482. (this.pages.length == 1 && urlParams['pages'] == '0'))
  483. {
  484. this.tabContainer.style.height = '0px';
  485. }
  486. else
  487. {
  488. this.tabContainer.style.height = this.tabContainerHeight + 'px';
  489. }
  490. if (prevHeight != this.tabContainer.style.height)
  491. {
  492. this.refresh(false);
  493. }
  494. }
  495. graphViewValidateBackground.apply(graph.view, arguments);
  496. // Uses SVG subtree to support custom fonts and images
  497. if (graph.view.backgroundImage != null)
  498. {
  499. EditorUi.embedSvgImages(graph.view.backgroundImage.node);
  500. }
  501. });
  502. // Adds a graph model listener to update the view and diagram modified flag
  503. this.editor.graph.model.addListener(mxEvent.CHANGE, mxUtils.bind(this, function(sender, evt)
  504. {
  505. var edit = evt.getProperty('edit');
  506. var changes = edit.changes;
  507. for (var i = 0; i < changes.length; i++)
  508. {
  509. if (changes[i] instanceof RenamePage ||
  510. changes[i] instanceof ChangePage ||
  511. changes[i] instanceof mxRootChange)
  512. {
  513. this.updateTabContainer();
  514. break;
  515. }
  516. }
  517. if (this.currentPage != null && !(changes.length == 1 &&
  518. changes[0] instanceof SelectPage))
  519. {
  520. this.currentPage.setDiagramModified(true);
  521. }
  522. }));
  523. // Invokes pageSelected to reset/restore view state
  524. var graphSizeDidChange = graph.sizeDidChange;
  525. var lastPage = null;
  526. var ui = this;
  527. graph.sizeDidChange = function()
  528. {
  529. var result = graphSizeDidChange.apply(this, arguments);
  530. if (ui.currentPage != null &&
  531. lastPage != ui.currentPage)
  532. {
  533. lastPage = ui.currentPage;
  534. ui.pageSelected();
  535. }
  536. return result;
  537. };
  538. // Selects new default parent if root changes
  539. graph.addListener(mxEvent.ROOT, mxUtils.bind(this, function()
  540. {
  541. graph.checkDefaultParent();
  542. }));
  543. var pagesChanged = mxUtils.bind(this, function()
  544. {
  545. this.updateDocumentTitle();
  546. this.updateTabContainer();
  547. });
  548. this.addListener('currentThemeChanged', pagesChanged);
  549. this.editor.addListener('pagesPatched', pagesChanged);
  550. this.editor.addListener('pageRenamed', pagesChanged);
  551. this.editor.addListener('pageMoved', pagesChanged);
  552. this.editor.addListener('fileLoaded', pagesChanged);
  553. this.editor.addListener('pageSelected', mxUtils.bind(this, function(sender, evt)
  554. {
  555. this.scrollToPage();
  556. this.updateHashObject();
  557. this.updateTabContainer();
  558. this.updateDocumentTitle();
  559. if (this.toolbar != null)
  560. {
  561. this.toolbar.updateZoom();
  562. }
  563. }));
  564. this.editor.addListener('pageMoved', mxUtils.bind(this, function(sender, evt)
  565. {
  566. this.scrollToPage();
  567. this.updateHashObject();
  568. }));
  569. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  570. {
  571. this.checkTabScrollerOverflow();
  572. }));
  573. }
  574. };
  575. /**
  576. * Adds the listener for automatically saving the diagram for local changes.
  577. */
  578. EditorUi.prototype.scrollToPage = function(page, force)
  579. {
  580. var index = (page != null) ? this.getPageIndex(page) :
  581. this.getSelectedPageIndex();
  582. var scrollPage = (page != null) ?
  583. page : this.currentPage;
  584. if (index != null && this.tabScroller != null &&
  585. this.tabScroller.children.length > index &&
  586. this.tabScroller.children[index] != null &&
  587. (scrollPage != this.lastScrollPage || force))
  588. {
  589. this.tabScroller.children[index].scrollIntoView(
  590. {block: 'nearest', inline: (page != null) ?
  591. 'nearest' : 'center'});
  592. this.tabScroller.children[index].className =
  593. 'geTab gePageTab geActivePage';
  594. this.lastScrollPage = scrollPage;
  595. }
  596. };
  597. /**
  598. * Adds the listener for automatically saving the diagram for local changes.
  599. */
  600. EditorUi.prototype.restoreViewState = function(page, viewState, selection)
  601. {
  602. var newPage = (page != null) ? this.getPageById(page.getId()) : null;
  603. var graph = this.editor.graph;
  604. if (newPage != null && this.currentPage != null && this.pages != null)
  605. {
  606. if (newPage != this.currentPage)
  607. {
  608. this.selectPage(newPage, true, viewState);
  609. }
  610. else
  611. {
  612. // TODO: Pass viewState to setGraphXml
  613. graph.setViewState(viewState);
  614. this.editor.updateGraphComponents();
  615. graph.view.revalidate();
  616. graph.sizeDidChange();
  617. }
  618. graph.container.scrollLeft = graph.view.translate.x * graph.view.scale + viewState.scrollLeft;
  619. graph.container.scrollTop = graph.view.translate.y * graph.view.scale + viewState.scrollTop;
  620. graph.restoreSelection(selection);
  621. }
  622. };
  623. /**
  624. * Overrides setDefaultParent
  625. */
  626. Graph.prototype.createViewState = function(node)
  627. {
  628. var pv = node.getAttribute('page');
  629. var ps = parseFloat(node.getAttribute('pageScale'));
  630. var pw = parseFloat(node.getAttribute('pageWidth'));
  631. var ph = parseFloat(node.getAttribute('pageHeight'));
  632. var bg = node.getAttribute('background');
  633. var bgImg = this.parseBackgroundImage(node.getAttribute('backgroundImage'));
  634. var extFonts = node.getAttribute('extFonts');
  635. if (extFonts)
  636. {
  637. try
  638. {
  639. extFonts = extFonts.split('|').map(function(ef)
  640. {
  641. var parts = ef.split('^');
  642. return {name: parts[0], url: parts[1]};
  643. });
  644. }
  645. catch(e)
  646. {
  647. console.log('ExtFonts format error: ' + e.message);
  648. }
  649. }
  650. return {
  651. gridEnabled: node.getAttribute('grid') != '0',
  652. //gridColor: node.getAttribute('gridColor') || mxSettings.getGridColor(Editor.isDarkMode()),
  653. gridSize: parseFloat(node.getAttribute('gridSize')) || mxGraph.prototype.gridSize,
  654. guidesEnabled: node.getAttribute('guides') != '0',
  655. foldingEnabled: node.getAttribute('fold') != '0',
  656. shadowVisible: node.getAttribute('shadow') == '1',
  657. pageVisible: (this.isLightboxView()) ? false : ((pv != null) ? (pv != '0') : this.defaultPageVisible),
  658. background: (bg != null && bg.length > 0) ? bg : null,
  659. backgroundImage: bgImg,
  660. pageScale: (!isNaN(ps)) ? ps : mxGraph.prototype.pageScale,
  661. pageFormat: (!isNaN(pw) && !isNaN(ph)) ? new mxRectangle(0, 0, pw, ph) :
  662. ((typeof mxSettings === 'undefined' || this.defaultPageFormat != null) ?
  663. mxGraph.prototype.pageFormat : mxSettings.getPageFormat()),
  664. tooltips: node.getAttribute('tooltips') != '0',
  665. connect: node.getAttribute('connect') != '0',
  666. arrows: node.getAttribute('arrows') != '0',
  667. mathEnabled: node.getAttribute('math') == '1',
  668. selectionCells: null,
  669. defaultParent: null,
  670. scrollbars: this.defaultScrollbars,
  671. scale: 1,
  672. hiddenTags: [],
  673. extFonts: extFonts || []
  674. };
  675. };
  676. /**
  677. * Writes the graph properties from the realtime model to the given mxGraphModel node.
  678. */
  679. Graph.prototype.saveViewState = function(vs, node, ignoreTransient, resolveReferences)
  680. {
  681. if (!ignoreTransient)
  682. {
  683. node.setAttribute('grid', ((vs == null) ? this.defaultGridEnabled : vs.gridEnabled) ? '1' : '0');
  684. node.setAttribute('page', ((vs == null) ? this.defaultPageVisible : vs.pageVisible) ? '1' : '0');
  685. node.setAttribute('gridSize', (vs != null) ? vs.gridSize : mxGraph.prototype.gridSize);
  686. node.setAttribute('guides', (vs == null || vs.guidesEnabled) ? '1' : '0');
  687. node.setAttribute('tooltips', (vs == null || vs.tooltips) ? '1' : '0');
  688. node.setAttribute('connect', (vs == null || vs.connect) ? '1' : '0');
  689. node.setAttribute('arrows', (vs == null || vs.arrows) ? '1' : '0');
  690. // Ignores fold to avoid checksum errors for lightbox mode
  691. node.setAttribute('fold', (vs == null || vs.foldingEnabled) ? '1' : '0');
  692. }
  693. node.setAttribute('pageScale', (vs != null && vs.pageScale != null) ?
  694. vs.pageScale : mxGraph.prototype.pageScale);
  695. var pf = (vs != null) ? vs.pageFormat : (typeof mxSettings === 'undefined' ||
  696. this.defaultPageFormat != null) ? mxGraph.prototype.pageFormat :
  697. mxSettings.getPageFormat();
  698. if (pf != null)
  699. {
  700. node.setAttribute('pageWidth', pf.width);
  701. node.setAttribute('pageHeight', pf.height);
  702. }
  703. if (vs != null)
  704. {
  705. if (vs.background != null)
  706. {
  707. node.setAttribute('background', vs.background);
  708. }
  709. var bgImg = this.getBackgroundImageObject(vs.backgroundImage, resolveReferences);
  710. if (bgImg != null)
  711. {
  712. node.setAttribute('backgroundImage', JSON.stringify(bgImg));
  713. }
  714. }
  715. node.setAttribute('math', ((vs == null) ? this.defaultMathEnabled : vs.mathEnabled) ? '1' : '0');
  716. node.setAttribute('shadow', (vs != null && vs.shadowVisible) ? '1' : '0');
  717. if (vs != null && vs.extFonts != null && vs.extFonts.length > 0)
  718. {
  719. node.setAttribute('extFonts', vs.extFonts.map(function(ef)
  720. {
  721. return ef.name + '^' + ef.url;
  722. }).join('|'));
  723. }
  724. };
  725. /**
  726. * Overrides setDefaultParent
  727. */
  728. Graph.prototype.getViewState = function()
  729. {
  730. return {
  731. defaultParent: this.defaultParent,
  732. currentRoot: this.view.currentRoot,
  733. gridEnabled: this.gridEnabled,
  734. //gridColor: this.view.gridColor,
  735. gridSize: this.gridSize,
  736. guidesEnabled: this.graphHandler.guidesEnabled,
  737. foldingEnabled: this.foldingEnabled,
  738. shadowVisible: this.shadowVisible,
  739. scrollbars: this.scrollbars,
  740. pageVisible: this.pageVisible,
  741. background: this.background,
  742. backgroundImage: this.backgroundImage,
  743. pageScale: this.pageScale,
  744. pageFormat: this.pageFormat,
  745. tooltips: this.tooltipHandler.isEnabled(),
  746. connect: this.connectionHandler.isEnabled(),
  747. arrows: this.connectionArrowsEnabled,
  748. scale: this.view.scale,
  749. scrollLeft: this.container.scrollLeft - this.view.translate.x * this.view.scale,
  750. scrollTop: this.container.scrollTop - this.view.translate.y * this.view.scale,
  751. translate: this.view.translate.clone(),
  752. lastPasteXml: this.lastPasteXml,
  753. pasteCounter: this.pasteCounter,
  754. mathEnabled: this.mathEnabled,
  755. hiddenTags: this.hiddenTags,
  756. extFonts: this.extFonts
  757. };
  758. };
  759. /**
  760. * Overrides setDefaultParent
  761. */
  762. Graph.prototype.setViewState = function(state, removeOldExtFonts)
  763. {
  764. if (state != null)
  765. {
  766. this.lastPasteXml = state.lastPasteXml;
  767. this.pasteCounter = state.pasteCounter || 0;
  768. this.mathEnabled = state.mathEnabled;
  769. this.gridEnabled = state.gridEnabled;
  770. //this.view.gridColor = state.gridColor;
  771. this.gridSize = state.gridSize;
  772. this.graphHandler.guidesEnabled = state.guidesEnabled;
  773. this.foldingEnabled = state.foldingEnabled;
  774. this.setShadowVisible(state.shadowVisible, false);
  775. this.scrollbars = state.scrollbars;
  776. this.pageVisible = !this.isViewer() && state.pageVisible;
  777. this.background = state.background;
  778. this.pageScale = state.pageScale;
  779. this.pageFormat = state.pageFormat;
  780. this.view.currentRoot = state.currentRoot;
  781. this.defaultParent = state.defaultParent;
  782. this.connectionArrowsEnabled = state.arrows;
  783. this.setTooltips(state.tooltips);
  784. this.setConnectable(state.connect);
  785. this.setBackgroundImage(state.backgroundImage);
  786. this.hiddenTags = state.hiddenTags;
  787. var oldExtFonts = this.extFonts;
  788. this.extFonts = state.extFonts || [];
  789. // Removing old fonts is important for real-time synchronization
  790. // But, for page change, it results in undesirable font flicker
  791. if (removeOldExtFonts && oldExtFonts != null)
  792. {
  793. for (var i = 0; i < oldExtFonts.length; i++)
  794. {
  795. var fontElem = document.getElementById('extFont_' + oldExtFonts[i].name);
  796. if (fontElem != null)
  797. {
  798. fontElem.parentNode.removeChild(fontElem);
  799. }
  800. }
  801. }
  802. for (var i = 0; i < this.extFonts.length; i++)
  803. {
  804. this.addExtFont(this.extFonts[i].name, this.extFonts[i].url, true);
  805. }
  806. if (state.scale != null)
  807. {
  808. this.view.scale = state.scale;
  809. }
  810. else
  811. {
  812. this.view.scale = 1;
  813. }
  814. // Checks if current root or default parent have been removed
  815. if (this.view.currentRoot != null &&
  816. !this.model.contains(this.view.currentRoot))
  817. {
  818. this.view.currentRoot = null;
  819. }
  820. if (this.defaultParent != null &&
  821. !this.model.contains(this.defaultParent))
  822. {
  823. this.setDefaultParent(null);
  824. this.selectUnlockedLayer();
  825. }
  826. if (state.translate != null)
  827. {
  828. this.view.translate = state.translate;
  829. }
  830. }
  831. else
  832. {
  833. this.view.currentRoot = null;
  834. this.view.scale = 1;
  835. this.gridEnabled = this.defaultGridEnabled;
  836. this.gridSize = mxGraph.prototype.gridSize;
  837. this.pageScale = mxGraph.prototype.pageScale;
  838. this.pageFormat = (typeof mxSettings === 'undefined' || this.defaultPageFormat != null) ?
  839. mxGraph.prototype.pageFormat : mxSettings.getPageFormat();
  840. this.pageVisible = this.defaultPageVisible;
  841. this.background = null;
  842. this.backgroundImage = null;
  843. this.scrollbars = this.defaultScrollbars;
  844. this.graphHandler.guidesEnabled = true;
  845. this.foldingEnabled = true;
  846. this.setShadowVisible(false, false);
  847. this.defaultParent = null;
  848. this.setTooltips(true);
  849. this.setConnectable(true);
  850. this.lastPasteXml = null;
  851. this.pasteCounter = 0;
  852. this.mathEnabled = this.defaultMathEnabled;
  853. this.connectionArrowsEnabled = true;
  854. this.hiddenTags = [];
  855. this.extFonts = [];
  856. }
  857. // Implicit settings
  858. this.pageBreaksVisible = this.pageVisible;
  859. this.preferPageSize = this.pageVisible;
  860. this.fireEvent(new mxEventObject('viewStateChanged', 'state', state));
  861. };
  862. /**
  863. * Sets the scrollbar positions from the given view state.
  864. */
  865. Graph.prototype.setScrollbarPositions = function(state, dx, dy)
  866. {
  867. if (state != null &&
  868. state.scrollLeft != null &&
  869. state.scrollTop != null)
  870. {
  871. this.container.scrollLeft = dx *
  872. this.view.scale + state.scrollLeft;
  873. this.container.scrollTop = dy *
  874. this.view.scale + state.scrollTop;
  875. }
  876. };
  877. /**
  878. * Executes selection of a new page.
  879. */
  880. Graph.prototype.addExtFont = function(fontName, fontUrl, dontRemember)
  881. {
  882. // KNOWN: Font not added when pasting cells with custom fonts
  883. if (fontName && fontUrl)
  884. {
  885. var fontId = 'extFont_' + fontName;
  886. if (document.getElementById(fontId) == null)
  887. {
  888. if (fontUrl.indexOf(Editor.GOOGLE_FONTS) == 0)
  889. {
  890. mxClient.link('stylesheet', fontUrl, null, fontId);
  891. }
  892. else
  893. {
  894. var head = document.getElementsByTagName('head')[0];
  895. // KNOWN: Should load fonts synchronously
  896. var style = document.createElement('style');
  897. style.appendChild(document.createTextNode('@font-face {\n' +
  898. '\tfont-family: "'+ fontName +'";\n' +
  899. '\tsrc: url("'+ fontUrl +'");\n}'));
  900. style.setAttribute('id', fontId);
  901. var head = document.getElementsByTagName('head')[0];
  902. head.appendChild(style);
  903. }
  904. }
  905. if (!dontRemember)
  906. {
  907. if (this.extFonts == null)
  908. {
  909. this.extFonts = [];
  910. }
  911. var extFonts = this.extFonts, notFound = true;
  912. for (var i = 0; i < extFonts.length; i++)
  913. {
  914. if (extFonts[i].name == fontName)
  915. {
  916. notFound = false;
  917. break;
  918. }
  919. }
  920. if (notFound)
  921. {
  922. this.extFonts.push({name: fontName, url: fontUrl});
  923. }
  924. }
  925. }
  926. };
  927. /**
  928. * Executes selection of a new page.
  929. */
  930. EditorUi.prototype.updatePageRoot = function(page, checked)
  931. {
  932. if (page.root == null)
  933. {
  934. var node = this.editor.extractGraphModel(page.node, null, checked);
  935. var cause = Editor.extractParserError(node);
  936. if (cause)
  937. {
  938. throw new Error(cause);
  939. }
  940. else if (node != null)
  941. {
  942. page.graphModelNode = node;
  943. // Converts model XML into page object with root cell
  944. page.viewState = this.editor.graph.createViewState(node);
  945. var codec = new mxCodec(node.ownerDocument);
  946. page.root = codec.decode(node).root;
  947. }
  948. else
  949. {
  950. // Initializes page object with new empty root
  951. page.root = this.editor.graph.model.createRoot();
  952. // Sets default cell IDs
  953. page.root.setId('0');
  954. page.root.children[0].setId('1');
  955. // Marks the page as needing an update
  956. page.needsUpdate = true;
  957. }
  958. }
  959. else if (page.viewState == null)
  960. {
  961. if (page.graphModelNode == null)
  962. {
  963. var node = this.editor.extractGraphModel(page.node);
  964. var cause = Editor.extractParserError(node);
  965. if (cause)
  966. {
  967. throw new Error(cause);
  968. }
  969. else if (node != null)
  970. {
  971. page.graphModelNode = node;
  972. }
  973. }
  974. if (page.graphModelNode != null)
  975. {
  976. page.viewState = this.editor.graph.createViewState(page.graphModelNode);
  977. }
  978. }
  979. // Ensures the root has a default layer
  980. if (page.root.children == null || page.root.children.length == 0)
  981. {
  982. var layer = new mxCell();
  983. layer.setId('1');
  984. page.root.insert(layer);
  985. // Marks the page as needing an update
  986. page.needsUpdate = true;
  987. }
  988. return page;
  989. };
  990. /**
  991. * Returns the current page and XML for the given page.
  992. */
  993. EditorUi.prototype.getDiagramSnapshot = function()
  994. {
  995. return {node: this.editor.getGraphXml(), page: this.currentPage};
  996. };
  997. /**
  998. *
  999. */
  1000. EditorUi.prototype.updateDiagramData = function(snapshot, node)
  1001. {
  1002. if (this.getPageIndex(snapshot.page) == null)
  1003. {
  1004. this.insertPage(null, null, node);
  1005. }
  1006. else
  1007. {
  1008. var dec = new mxCodec(snapshot.node.ownerDocument);
  1009. var oldModel = new mxGraphModel();
  1010. dec.decode(snapshot.node, oldModel);
  1011. dec = new mxCodec(node.ownerDocument);
  1012. var newModel = new mxGraphModel();
  1013. dec.decode(node, newModel);
  1014. this.selectPage(snapshot.page);
  1015. var patch = this.diffCells(oldModel.root, newModel.root);
  1016. this.patchPage(snapshot.page, patch, null, true);
  1017. }
  1018. };
  1019. /**
  1020. * Adds keyboard shortcuts for page handling.
  1021. */
  1022. EditorUi.prototype.replaceDiagramData = function(data)
  1023. {
  1024. this.editor.graph.model.execute(new ReplaceDiagram(
  1025. this, mxUtils.parseXml(data).documentElement));
  1026. };
  1027. /**
  1028. * Returns true if the given string contains an mxfile.
  1029. */
  1030. EditorUi.prototype.selectPage = function(page, quiet, viewState)
  1031. {
  1032. try
  1033. {
  1034. if (page != this.currentPage)
  1035. {
  1036. var graph = this.editor.graph;
  1037. if (graph.isEditing())
  1038. {
  1039. graph.stopEditing(false);
  1040. }
  1041. quiet = (quiet != null) ? quiet : false;
  1042. graph.isMouseDown = false;
  1043. graph.reset();
  1044. var edit = graph.model.createUndoableEdit();
  1045. // Special flag to bypass autosave for this edit
  1046. edit.ignoreEdit = true;
  1047. var change = new SelectPage(this, page, viewState);
  1048. change.execute();
  1049. edit.add(change);
  1050. edit.notify();
  1051. if (!quiet)
  1052. {
  1053. graph.model.fireEvent(new mxEventObject(
  1054. mxEvent.UNDO, 'edit', edit));
  1055. }
  1056. }
  1057. }
  1058. catch (e)
  1059. {
  1060. this.handleError(e);
  1061. }
  1062. };
  1063. /**
  1064. *
  1065. */
  1066. EditorUi.prototype.selectNextPage = function(forward)
  1067. {
  1068. var next = this.currentPage;
  1069. if (next != null && this.pages != null)
  1070. {
  1071. var tmp = mxUtils.indexOf(this.pages, next);
  1072. if (forward)
  1073. {
  1074. this.selectPage(this.pages[mxUtils.mod(tmp + 1, this.pages.length)]);
  1075. }
  1076. else if (!forward)
  1077. {
  1078. this.selectPage(this.pages[mxUtils.mod(tmp - 1, this.pages.length)]);
  1079. }
  1080. }
  1081. };
  1082. /**
  1083. * Returns true if the given string contains an mxfile.
  1084. */
  1085. EditorUi.prototype.insertPage = function(page, index, node)
  1086. {
  1087. if (this.editor.graph.isEnabled())
  1088. {
  1089. if (this.editor.graph.isEditing())
  1090. {
  1091. this.editor.graph.stopEditing(false);
  1092. }
  1093. page = (page != null) ? page : this.createPage(
  1094. null, this.createPageId(), node);
  1095. index = (index != null) ? index : this.pages.length;
  1096. // Uses model to fire event and trigger autosave
  1097. var change = new ChangePage(this, page, page, index);
  1098. this.editor.graph.model.execute(change);
  1099. }
  1100. return page;
  1101. };
  1102. /**
  1103. * Returns a unique page ID.
  1104. */
  1105. EditorUi.prototype.createPageId = function()
  1106. {
  1107. var id = null;
  1108. do
  1109. {
  1110. id = Editor.guid();
  1111. } while (this.getPageById(id) != null)
  1112. return id;
  1113. };
  1114. /**
  1115. * Returns a new DiagramPage instance.
  1116. */
  1117. EditorUi.prototype.createPage = function(name, id, node)
  1118. {
  1119. var doc = (this.fileNode != null) ? this.fileNode.ownerDocument : document;
  1120. var page = new DiagramPage(doc.createElement('diagram'), id);
  1121. page.setName((name != null) ? name : this.createPageName());
  1122. this.initDiagramNode(page, node);
  1123. return page;
  1124. };
  1125. /**
  1126. * Returns a page name.
  1127. */
  1128. EditorUi.prototype.createPageName = function()
  1129. {
  1130. // Creates a lookup with names
  1131. var existing = {};
  1132. for (var i = 0; i < this.pages.length; i++)
  1133. {
  1134. var tmp = this.pages[i].getName();
  1135. if (tmp != null && tmp.length > 0)
  1136. {
  1137. existing[tmp] = tmp;
  1138. }
  1139. }
  1140. // Avoids existing names
  1141. var nr = this.pages.length;
  1142. var name = null;
  1143. do
  1144. {
  1145. name = mxResources.get('pageWithNumber', [++nr]);
  1146. }
  1147. while (existing[name] != null);
  1148. return name;
  1149. };
  1150. /**
  1151. * Removes the given page.
  1152. */
  1153. EditorUi.prototype.removePage = function(page)
  1154. {
  1155. try
  1156. {
  1157. var graph = this.editor.graph;
  1158. var tmp = mxUtils.indexOf(this.pages, page);
  1159. if (graph.isEnabled() && tmp >= 0)
  1160. {
  1161. if (this.editor.graph.isEditing())
  1162. {
  1163. this.editor.graph.stopEditing(false);
  1164. }
  1165. graph.model.beginUpdate();
  1166. try
  1167. {
  1168. var next = this.currentPage;
  1169. if (next == page && this.pages.length > 1)
  1170. {
  1171. if (tmp == this.pages.length - 1)
  1172. {
  1173. tmp--;
  1174. }
  1175. else
  1176. {
  1177. tmp++;
  1178. }
  1179. next = this.pages[tmp];
  1180. }
  1181. else if (this.pages.length <= 1)
  1182. {
  1183. // Removes label with incorrect page number to force
  1184. // default page name which is OK for a single page
  1185. next = this.insertPage();
  1186. graph.model.execute(new RenamePage(this, next,
  1187. mxResources.get('pageWithNumber', [1])));
  1188. }
  1189. // Uses model to fire event to trigger autosave
  1190. graph.model.execute(new ChangePage(this, page, next));
  1191. }
  1192. finally
  1193. {
  1194. graph.model.endUpdate();
  1195. }
  1196. }
  1197. }
  1198. catch (e)
  1199. {
  1200. this.handleError(e);
  1201. }
  1202. return page;
  1203. };
  1204. /**
  1205. * Duplicates the given page.
  1206. */
  1207. EditorUi.prototype.duplicatePage = function(page, name)
  1208. {
  1209. var newPage = null;
  1210. try
  1211. {
  1212. var graph = this.editor.graph;
  1213. if (graph.isEnabled())
  1214. {
  1215. if (graph.isEditing())
  1216. {
  1217. graph.stopEditing();
  1218. }
  1219. // Clones the current page and takes a snapshot of the graph model and view state
  1220. var node = page.node.cloneNode(false);
  1221. node.removeAttribute('id');
  1222. var cloneMap = new Object();
  1223. var lookup = graph.createCellLookup([graph.model.root]);
  1224. var newPage = new DiagramPage(node);
  1225. newPage.root = graph.cloneCell(graph.model.root,
  1226. null, cloneMap);
  1227. // Updates cell IDs
  1228. var model = new mxGraphModel();
  1229. model.prefix = Editor.guid() + '-';
  1230. model.setRoot(newPage.root);
  1231. // Updates custom links
  1232. graph.updateCustomLinks(graph.createCellMapping(
  1233. cloneMap, lookup), [newPage.root]);
  1234. // Initializes diagram node
  1235. newPage.viewState = (page == this.currentPage) ?
  1236. graph.getViewState() : page.viewState;
  1237. this.initDiagramNode(newPage);
  1238. // Resets zoom and scrollbar positions
  1239. newPage.viewState.scale = 1;
  1240. delete newPage.viewState.scrollLeft;
  1241. delete newPage.viewState.scrollTop;
  1242. delete newPage.viewState.currentRoot
  1243. delete newPage.viewState.defaultParent;
  1244. newPage.setName(name);
  1245. // Inserts new page after duplicated page
  1246. newPage = this.insertPage(newPage,
  1247. mxUtils.indexOf(this.pages,
  1248. page) + 1);
  1249. }
  1250. }
  1251. catch (e)
  1252. {
  1253. this.handleError(e);
  1254. }
  1255. return newPage;
  1256. };
  1257. /**
  1258. * Duplicates the given page.
  1259. */
  1260. EditorUi.prototype.initDiagramNode = function(page, node)
  1261. {
  1262. if (node == null)
  1263. {
  1264. var enc = new mxCodec(mxUtils.createXmlDocument());
  1265. node = enc.encode(new mxGraphModel(page.root));
  1266. }
  1267. this.editor.graph.saveViewState(page.viewState, node);
  1268. EditorUi.removeChildNodes(page.node);
  1269. page.node.appendChild(node);
  1270. };
  1271. /**
  1272. * Duplicates the given page.
  1273. */
  1274. EditorUi.prototype.clonePages = function(pages)
  1275. {
  1276. var errors = [];
  1277. var result = [];
  1278. for (var i = 0; i < pages.length; i++)
  1279. {
  1280. try
  1281. {
  1282. result.push(this.clonePage(pages[i]));
  1283. }
  1284. catch (e)
  1285. {
  1286. errors.push(mxResources.get('pageWithNumber',
  1287. [i + 1]) + ': ' + e.message);
  1288. }
  1289. }
  1290. if (errors.length > 0)
  1291. {
  1292. throw new Error(errors.join('\n'));
  1293. }
  1294. return result;
  1295. };
  1296. /**
  1297. * Duplicates the given page.
  1298. */
  1299. EditorUi.prototype.clonePage = function(page)
  1300. {
  1301. this.updatePageRoot(page);
  1302. var result = new DiagramPage(page.node.cloneNode(true));
  1303. var viewState = (page == this.currentPage) ?
  1304. this.editor.graph.getViewState() :
  1305. page.viewState;
  1306. result.viewState = mxUtils.clone(viewState,
  1307. EditorUi.transientViewStateProperties)
  1308. result.root = this.editor.graph.model.cloneCell(
  1309. page.root, null, true);
  1310. result.diagramModified = page.diagramModified;
  1311. return result;
  1312. };
  1313. /**
  1314. * Renames the given page using a dialog.
  1315. */
  1316. EditorUi.prototype.renamePage = function(page)
  1317. {
  1318. var graph = this.editor.graph;
  1319. if (graph.isEnabled())
  1320. {
  1321. var dlg = new FilenameDialog(this, page.getName(), mxResources.get('rename'),
  1322. mxUtils.bind(this, function(name)
  1323. {
  1324. if (name != null && name.length > 0)
  1325. {
  1326. this.editor.graph.model.execute(new RenamePage(this, page, name));
  1327. }
  1328. }), mxResources.get('rename'));
  1329. this.showDialog(dlg.container, 300, 80, true, true);
  1330. dlg.init();
  1331. }
  1332. return page;
  1333. }
  1334. /**
  1335. * Returns true if the given string contains an mxfile.
  1336. */
  1337. EditorUi.prototype.movePage = function(oldIndex, newIndex)
  1338. {
  1339. this.editor.graph.model.execute(new MovePage(this, oldIndex, newIndex));
  1340. }
  1341. /**
  1342. * Returns true if the given string contains an mxfile.
  1343. */
  1344. EditorUi.prototype.createTabContainer = function()
  1345. {
  1346. var div = document.createElement('div');
  1347. div.className = 'geTabContainer geTabItem';
  1348. return div;
  1349. };
  1350. /**
  1351. * Returns true if the given string contains an mxfile.
  1352. */
  1353. EditorUi.prototype.updateTabContainer = function()
  1354. {
  1355. if (this.tabContainer != null && this.pages != null)
  1356. {
  1357. var graph = this.editor.graph;
  1358. var wrapper = document.createElement('div');
  1359. wrapper.className = 'geTabScroller';
  1360. var startIndex = null;
  1361. for (var i = 0; i < this.pages.length; i++)
  1362. {
  1363. // Install drag and drop for page reorder
  1364. (mxUtils.bind(this, function(index, tab)
  1365. {
  1366. if (this.pages[index] == this.currentPage)
  1367. {
  1368. tab.className = 'geTab gePageTab geActivePage';
  1369. }
  1370. else
  1371. {
  1372. tab.className = 'geTab gePageTab geInactivePage';
  1373. }
  1374. tab.setAttribute('draggable', 'true');
  1375. mxEvent.addListener(tab, 'dragstart', mxUtils.bind(this, function(evt)
  1376. {
  1377. if (graph.isEnabled())
  1378. {
  1379. // Workaround for no DnD on DIV in FF
  1380. if (mxClient.IS_FF)
  1381. {
  1382. // LATER: Check what triggers a parse as XML on this in FF after drop
  1383. evt.dataTransfer.setData('Text', '<diagram/>');
  1384. }
  1385. startIndex = index;
  1386. }
  1387. else
  1388. {
  1389. // Blocks event
  1390. mxEvent.consume(evt);
  1391. }
  1392. }));
  1393. mxEvent.addListener(tab, 'dragend', mxUtils.bind(this, function(evt)
  1394. {
  1395. startIndex = null;
  1396. evt.stopPropagation();
  1397. evt.preventDefault();
  1398. }));
  1399. mxEvent.addListener(tab, 'dragover', mxUtils.bind(this, function(evt)
  1400. {
  1401. if (startIndex != null)
  1402. {
  1403. evt.dataTransfer.dropEffect = 'move';
  1404. }
  1405. evt.stopPropagation();
  1406. evt.preventDefault();
  1407. }));
  1408. mxEvent.addListener(tab, 'drop', mxUtils.bind(this, function(evt)
  1409. {
  1410. if (startIndex != null && index != startIndex)
  1411. {
  1412. // LATER: Shift+drag for merge, ctrl+drag for clone
  1413. this.movePage(startIndex, index);
  1414. }
  1415. evt.stopPropagation();
  1416. evt.preventDefault();
  1417. }));
  1418. wrapper.appendChild(tab);
  1419. }))(i, this.createTabForPage(this.pages[i], i + 1));
  1420. }
  1421. var sl = (this.tabScroller != null) ? this.tabScroller.scrollLeft : 0;
  1422. this.tabContainer.innerText = '';
  1423. if (Editor.currentTheme != 'simple')
  1424. {
  1425. this.pageMenuTab = this.createPageMenuTab();
  1426. this.tabContainer.appendChild(this.pageMenuTab);
  1427. }
  1428. this.tabContainer.appendChild(wrapper);
  1429. // Not chromeless and not read-only file
  1430. if (this.isPageInsertTabVisible())
  1431. {
  1432. this.tabContainer.appendChild(this.createPageInsertTab());
  1433. }
  1434. this.leftScrollTab = this.createLeftScrollTab();
  1435. this.tabContainer.appendChild(this.leftScrollTab);
  1436. this.rightScrollTab = this.createRightScrollTab();
  1437. this.tabContainer.appendChild(this.rightScrollTab);
  1438. this.tabScroller = wrapper;
  1439. this.tabScroller.scrollLeft = sl;
  1440. this.checkTabScrollerOverflow();
  1441. mxEvent.addListener(this.tabScroller, 'scroll', mxUtils.bind(this, function(evt)
  1442. {
  1443. this.checkTabScrollerOverflow();
  1444. }));
  1445. window.setTimeout(mxUtils.bind(this, function()
  1446. {
  1447. mxUtils.setPrefixedStyle(this.leftScrollTab.style, 'transition', 'all 0.2s linear');
  1448. mxUtils.setPrefixedStyle(this.rightScrollTab.style, 'transition', 'all 0.2s linear');
  1449. }), 0);
  1450. }
  1451. };
  1452. /**
  1453. * Returns true if the given string contains an mxfile.
  1454. */
  1455. EditorUi.prototype.checkTabScrollerOverflow = function()
  1456. {
  1457. if (this.tabScroller != null && this.tabContainer != null &&
  1458. this.tabContainer.children.length > 2)
  1459. {
  1460. var overflow = this.tabScroller.scrollWidth > this.tabScroller.offsetWidth;
  1461. if (!overflow)
  1462. {
  1463. this.leftScrollTab.style.display = 'none';
  1464. this.rightScrollTab.style.display = 'none';
  1465. }
  1466. else
  1467. {
  1468. this.leftScrollTab.style.display = '';
  1469. this.rightScrollTab.style.display = '';
  1470. if (this.tabScroller.scrollLeft == 0)
  1471. {
  1472. this.leftScrollTab.classList.add('geDisabledControlTab');
  1473. }
  1474. else
  1475. {
  1476. this.leftScrollTab.classList.remove('geDisabledControlTab');
  1477. }
  1478. if (Math.ceil(this.tabScroller.scrollLeft) + this.tabScroller.offsetWidth >=
  1479. this.tabScroller.scrollWidth)
  1480. {
  1481. this.rightScrollTab.classList.add('geDisabledControlTab');
  1482. }
  1483. else
  1484. {
  1485. this.rightScrollTab.classList.remove('geDisabledControlTab');
  1486. }
  1487. }
  1488. }
  1489. };
  1490. /**
  1491. * Returns true if the given string contains an mxfile.
  1492. */
  1493. EditorUi.prototype.isPageInsertTabVisible = function()
  1494. {
  1495. return urlParams['embed'] == 1 || (this.getCurrentFile() != null &&
  1496. this.getCurrentFile().isEditable());
  1497. };
  1498. /**
  1499. * Returns true if the given string contains an mxfile.
  1500. */
  1501. EditorUi.prototype.createTab = function()
  1502. {
  1503. var tab = document.createElement('div');
  1504. tab.className = 'geTab';
  1505. return tab;
  1506. };
  1507. /**
  1508. * Returns a shortened page name.
  1509. */
  1510. EditorUi.prototype.getShortPageName = function(page)
  1511. {
  1512. var short = null;
  1513. if (page != null)
  1514. {
  1515. short = page.getName();
  1516. if (short != null && short.length > 36)
  1517. {
  1518. short = short.substring(0, 34) + '...';
  1519. }
  1520. }
  1521. return short;
  1522. };
  1523. /**
  1524. * Returns true if the given string contains an mxfile.
  1525. */
  1526. EditorUi.prototype.createControlTab = function(title, image, fn)
  1527. {
  1528. var tab = this.createTab();
  1529. tab.className = 'geTab geControlTab';
  1530. tab.style.width = '30px';
  1531. if (title != null)
  1532. {
  1533. tab.setAttribute('title', title);
  1534. }
  1535. var inner = document.createElement('div');
  1536. inner.className = 'geAdaptiveAsset';
  1537. inner.style.backgroundImage = 'url(' + image + ')';
  1538. inner.style.backgroundRepeat = 'no-repeat';
  1539. inner.style.backgroundPosition = 'center';
  1540. inner.style.backgroundSize = '24px';
  1541. inner.style.position = 'relative';
  1542. inner.style.width = '100%';
  1543. inner.style.height = '100%';
  1544. tab.appendChild(inner);
  1545. mxEvent.addListener(tab, 'click', fn);
  1546. return tab;
  1547. };
  1548. /**
  1549. * Returns true if the given string contains an mxfile.
  1550. */
  1551. EditorUi.prototype.createPageInsertTab = function()
  1552. {
  1553. return this.createControlTab(mxResources.get('insertPage'),
  1554. Editor.plusImage, mxUtils.bind(this, function(evt)
  1555. {
  1556. try
  1557. {
  1558. this.insertPage();
  1559. }
  1560. catch (e)
  1561. {
  1562. this.handleError(e);
  1563. }
  1564. mxEvent.consume(evt);
  1565. }));
  1566. };
  1567. /**
  1568. * Returns true if the given string contains an mxfile.
  1569. */
  1570. EditorUi.prototype.createLeftScrollTab = function()
  1571. {
  1572. return this.createControlTab(null, Editor.thinArrowLeftImage, mxUtils.bind(this, function(evt)
  1573. {
  1574. var dx = Math.max(60, this.tabScroller.clientWidth / 2);
  1575. if (this.tabScroller.scrollBy != null)
  1576. {
  1577. this.tabScroller.scrollBy({left: -dx, top: 0, behavior: 'smooth'});
  1578. }
  1579. else
  1580. {
  1581. this.tabScroller.scrollLeft -= dx;
  1582. }
  1583. mxEvent.consume(evt);
  1584. }));
  1585. };
  1586. /**
  1587. * Returns true if the given string contains an mxfile.
  1588. */
  1589. EditorUi.prototype.createRightScrollTab = function()
  1590. {
  1591. return this.createControlTab(null, Editor.thinArrowRightImage, mxUtils.bind(this, function(evt)
  1592. {
  1593. var dx = Math.max(60, this.tabScroller.clientWidth / 2);
  1594. if (this.tabScroller.scrollBy != null)
  1595. {
  1596. this.tabScroller.scrollBy({left: dx, top: 0, behavior: 'smooth'});
  1597. }
  1598. else
  1599. {
  1600. this.tabScroller.scrollLeft += dx;
  1601. }
  1602. mxEvent.consume(evt);
  1603. }));
  1604. };
  1605. /**
  1606. * Returns true if the given string contains an mxfile.
  1607. */
  1608. EditorUi.prototype.createPageMenuTab = function()
  1609. {
  1610. return this.createControlTab(mxResources.get('pages'),
  1611. Editor.verticalDotsImage, mxUtils.bind(this, function(evt)
  1612. {
  1613. this.editor.graph.popupMenuHandler.hideMenu();
  1614. var menu = new mxPopupMenu(mxUtils.bind(this, function(menu, parent)
  1615. {
  1616. this.menus.get('pages').funct(menu, parent);
  1617. }));
  1618. menu.div.className += ' geMenubarMenu';
  1619. menu.smartSeparators = true;
  1620. menu.showDisabled = true;
  1621. menu.autoExpand = true;
  1622. // Disables autoexpand and destroys menu when hidden
  1623. menu.hideMenu = mxUtils.bind(this, function()
  1624. {
  1625. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  1626. menu.destroy();
  1627. });
  1628. var x = mxEvent.getClientX(evt);
  1629. var y = mxEvent.getClientY(evt);
  1630. menu.popup(x, y, null, evt);
  1631. // Allows hiding by clicking on document
  1632. this.setCurrentMenu(menu);
  1633. mxEvent.consume(evt);
  1634. }));
  1635. };
  1636. /**
  1637. * Returns true if the given string contains an mxfile.
  1638. */
  1639. EditorUi.prototype.createTabForPage = function(page, pageNumber)
  1640. {
  1641. var tab = this.createTab();
  1642. var name = page.getName() || mxResources.get('untitled');
  1643. var id = page.getId();
  1644. tab.setAttribute('title', name + ((id != null) ?
  1645. ' (' + id + ')' : '') + ' [' + pageNumber + ']');
  1646. var label = document.createElement('span');
  1647. label.style.maxWidth = '160px';
  1648. label.style.textOverflow = 'ellipsis';
  1649. label.style.overflow = 'hidden';
  1650. mxUtils.write(label, name);
  1651. tab.appendChild(label);
  1652. this.addTabListeners(page, tab);
  1653. return tab;
  1654. };
  1655. /**
  1656. * Translates this point by the given vector.
  1657. *
  1658. * @param {number} dx X-coordinate of the translation.
  1659. * @param {number} dy Y-coordinate of the translation.
  1660. */
  1661. EditorUi.prototype.addTabListeners = function(page, tab)
  1662. {
  1663. mxEvent.disableContextMenu(tab);
  1664. var graph = this.editor.graph;
  1665. mxEvent.addListener(tab, 'dblclick', mxUtils.bind(this, function(evt)
  1666. {
  1667. this.renamePage(page)
  1668. mxEvent.consume(evt);
  1669. }));
  1670. var elt = document.createElement('div');
  1671. elt.className = 'geTabMenuButton';
  1672. elt.style.backgroundImage = 'url(' + mxWindow.prototype.minimizeImage + ')';
  1673. elt.style.backgroundPosition = 'center center';
  1674. elt.style.backgroundRepeat = 'no-repeat';
  1675. elt.style.backgroundSize = '10px';
  1676. tab.appendChild(elt);
  1677. var menuWasVisible = false;
  1678. var pageWasActive = false;
  1679. var onMouseDown = mxUtils.bind(this, function(evt)
  1680. {
  1681. // Do not consume event here to allow for drag and drop of tabs
  1682. menuWasVisible = this.currentMenu != null;
  1683. pageWasActive = page == this.currentPage;
  1684. this.scrollToPage(page);
  1685. if (!graph.isMouseDown && !pageWasActive)
  1686. {
  1687. this.selectPage(page);
  1688. }
  1689. });
  1690. var onMouseUp = mxUtils.bind(this, function(evt)
  1691. {
  1692. if (graph.isEnabled() && !graph.isMouseDown &&
  1693. ((pageWasActive && (mxEvent.isTouchEvent(evt) ||
  1694. mxEvent.getSource(evt) == elt)) ||
  1695. mxEvent.isPopupTrigger(evt)))
  1696. {
  1697. graph.popupMenuHandler.hideMenu();
  1698. this.hideCurrentMenu();
  1699. if (!mxEvent.isTouchEvent(evt) || !menuWasVisible)
  1700. {
  1701. var menu = new mxPopupMenu(this.createPageMenu(page));
  1702. menu.div.className += ' geMenubarMenu';
  1703. menu.smartSeparators = true;
  1704. menu.showDisabled = true;
  1705. menu.autoExpand = true;
  1706. // Disables autoexpand and destroys menu when hidden
  1707. menu.hideMenu = mxUtils.bind(this, function()
  1708. {
  1709. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  1710. this.resetCurrentMenu();
  1711. menu.destroy();
  1712. });
  1713. var x = mxEvent.getClientX(evt);
  1714. var y = mxEvent.getClientY(evt);
  1715. menu.popup(x, y, null, evt);
  1716. this.setCurrentMenu(menu, tab);
  1717. }
  1718. }
  1719. mxEvent.consume(evt);
  1720. });
  1721. mxEvent.addGestureListeners(elt, onMouseDown, null, onMouseUp);
  1722. mxEvent.addGestureListeners(tab, onMouseDown, null, onMouseUp);
  1723. };
  1724. /**
  1725. * Returns true if the given string contains an mxfile.
  1726. */
  1727. EditorUi.prototype.createPageMenu = function(page, label)
  1728. {
  1729. return mxUtils.bind(this, function(menu, parent)
  1730. {
  1731. if (urlParams['embed'] != 1)
  1732. {
  1733. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp && this.getServiceName() == 'draw.io')
  1734. {
  1735. menu.addItem(mxResources.get('openInNewWindow'), null, mxUtils.bind(this, function()
  1736. {
  1737. this.editor.editAsNew(this.getFileData(true, null, null, null, true, true));
  1738. }), parent);
  1739. }
  1740. }
  1741. menu.addItem(mxResources.get('duplicate'), null, mxUtils.bind(this, function()
  1742. {
  1743. this.duplicatePage(page, mxResources.get('copyOf', [page.getName()]));
  1744. }), parent);
  1745. menu.addSeparator(parent);
  1746. if (this.currentPage == page && this.pages.length > 1)
  1747. {
  1748. this.menus.addSubmenu('movePage', menu, parent, mxResources.get('move'));
  1749. }
  1750. menu.addItem(mxResources.get('delete'), null, mxUtils.bind(this, function()
  1751. {
  1752. this.removePage(page);
  1753. }), parent);
  1754. menu.addItem(mxResources.get('rename') + '...', null, mxUtils.bind(this, function()
  1755. {
  1756. this.renamePage(page, label);
  1757. }), parent);
  1758. });
  1759. };
  1760. //Overrides ChangePageSetup codec to exclude page
  1761. (function()
  1762. {
  1763. var codec = mxCodecRegistry.getCodec(ChangePageSetup);
  1764. codec.exclude.push('page');
  1765. })();
  1766. //Registers codec for MovePage
  1767. (function()
  1768. {
  1769. var codec = new mxObjectCodec(new MovePage(), ['ui']);
  1770. codec.beforeDecode = function(dec, node, obj)
  1771. {
  1772. obj.ui = dec.ui;
  1773. return node;
  1774. };
  1775. codec.afterDecode = function(dec, node, obj)
  1776. {
  1777. var tmp = obj.oldIndex;
  1778. obj.oldIndex = obj.newIndex;
  1779. obj.newIndex = tmp;
  1780. return obj;
  1781. };
  1782. mxCodecRegistry.register(codec);
  1783. })();
  1784. //Registers codec for RenamePage
  1785. (function()
  1786. {
  1787. var codec = new mxObjectCodec(new RenamePage(), ['ui', 'page']);
  1788. codec.beforeDecode = function(dec, node, obj)
  1789. {
  1790. obj.ui = dec.ui;
  1791. return node;
  1792. };
  1793. codec.afterDecode = function(dec, node, obj)
  1794. {
  1795. var tmp = obj.previous;
  1796. obj.previous = obj.name;
  1797. obj.name = tmp;
  1798. return obj;
  1799. };
  1800. mxCodecRegistry.register(codec);
  1801. })();
  1802. //Registers codec for ChangePage
  1803. (function()
  1804. {
  1805. var codec = new mxObjectCodec(new ChangePage(), ['ui',
  1806. 'relatedPage', 'index', 'page', 'previousPage']);
  1807. codec.afterEncode = function(enc, obj, node)
  1808. {
  1809. node.setAttribute('relatedPage', obj.relatedPage.getId())
  1810. if (obj.index == null)
  1811. {
  1812. node.setAttribute('name', obj.relatedPage.getName());
  1813. if (obj.relatedPage.viewState != null)
  1814. {
  1815. node.setAttribute('viewState', JSON.stringify(
  1816. obj.relatedPage.viewState, function(key, value)
  1817. {
  1818. return (mxUtils.indexOf(EditorUi.transientViewStateProperties, key) < 0) ? value : undefined;
  1819. }));
  1820. }
  1821. if (obj.relatedPage.root != null)
  1822. {
  1823. enc.encodeCell(obj.relatedPage.root, node);
  1824. }
  1825. }
  1826. return node;
  1827. };
  1828. codec.beforeDecode = function(dec, node, obj)
  1829. {
  1830. obj.ui = dec.ui;
  1831. obj.relatedPage = obj.ui.getPageById(node.getAttribute('relatedPage'));
  1832. if (obj.relatedPage == null)
  1833. {
  1834. var temp = node.ownerDocument.createElement('diagram');
  1835. temp.setAttribute('id', node.getAttribute('relatedPage'));
  1836. temp.setAttribute('name', node.getAttribute('name'));
  1837. obj.relatedPage = new DiagramPage(temp);
  1838. var vs = node.getAttribute('viewState');
  1839. if (vs != null)
  1840. {
  1841. obj.relatedPage.viewState = JSON.parse(vs);
  1842. node.removeAttribute('viewState');
  1843. }
  1844. // Makes sure the original node isn't modified
  1845. node = node.cloneNode(true);
  1846. var tmp = node.firstChild;
  1847. if (tmp != null)
  1848. {
  1849. obj.relatedPage.root = dec.decodeCell(tmp, false);
  1850. var tmp2 = tmp.nextSibling;
  1851. tmp.parentNode.removeChild(tmp);
  1852. tmp = tmp2;
  1853. while (tmp != null)
  1854. {
  1855. tmp2 = tmp.nextSibling;
  1856. if (tmp.nodeType == mxConstants.NODETYPE_ELEMENT)
  1857. {
  1858. // Ignores all existing cells because those do not need to
  1859. // be re-inserted into the model. Since the encoded version
  1860. // of these cells contains the new parent, this would leave
  1861. // to an inconsistent state on the model (ie. a parent
  1862. // change without a call to parentForCellChanged).
  1863. var id = tmp.getAttribute('id');
  1864. if (dec.lookup(id) == null)
  1865. {
  1866. dec.decodeCell(tmp);
  1867. }
  1868. }
  1869. tmp.parentNode.removeChild(tmp);
  1870. tmp = tmp2;
  1871. }
  1872. }
  1873. }
  1874. return node;
  1875. };
  1876. codec.afterDecode = function(dec, node, obj)
  1877. {
  1878. obj.index = obj.previousIndex;
  1879. return obj;
  1880. };
  1881. mxCodecRegistry.register(codec);
  1882. })();