Editor.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Editor constructor executed on page load.
  6. */
  7. Editor = function(chromeless, themes, model, graph)
  8. {
  9. mxEventSource.call(this);
  10. this.chromeless = (chromeless != null) ? chromeless : this.chromeless;
  11. this.initStencilRegistry();
  12. this.graph = graph || this.createGraph(themes, model);
  13. this.undoManager = this.createUndoManager();
  14. this.status = '';
  15. this.getOrCreateFilename = function()
  16. {
  17. return this.filename || mxResources.get('drawing', [Editor.pageCounter]) + '.xml';
  18. };
  19. this.getFilename = function()
  20. {
  21. return this.filename;
  22. };
  23. // Sets the status and fires a statusChanged event
  24. this.setStatus = function(value)
  25. {
  26. this.status = value;
  27. this.fireEvent(new mxEventObject('statusChanged'));
  28. };
  29. // Returns the current status
  30. this.getStatus = function()
  31. {
  32. return this.status;
  33. };
  34. // Updates modified state if graph changes
  35. this.graphChangeListener = function(sender, eventObject)
  36. {
  37. var edit = (eventObject != null) ? eventObject.getProperty('edit') : null;
  38. if (edit == null || !edit.ignoreEdit)
  39. {
  40. this.setModified(true);
  41. }
  42. };
  43. this.graph.getModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  44. {
  45. this.graphChangeListener.apply(this, arguments);
  46. }));
  47. // Sets persistent graph state defaults
  48. this.graph.resetViewOnRootChange = false;
  49. this.init();
  50. };
  51. /**
  52. * Counts open editor tabs (must be global for cross-window access)
  53. */
  54. Editor.pageCounter = 0;
  55. // Cross-domain window access is not allowed in FF, so if we
  56. // were opened from another domain then this will fail.
  57. (function()
  58. {
  59. try
  60. {
  61. var op = window;
  62. while (op.opener != null && typeof op.opener.Editor !== 'undefined' &&
  63. !isNaN(op.opener.Editor.pageCounter) &&
  64. // Workaround for possible infinite loop in FF https://drawio.atlassian.net/browse/DS-795
  65. op.opener != op)
  66. {
  67. op = op.opener;
  68. }
  69. // Increments the counter in the first opener in the chain
  70. if (op != null)
  71. {
  72. op.Editor.pageCounter++;
  73. Editor.pageCounter = op.Editor.pageCounter;
  74. }
  75. }
  76. catch (e)
  77. {
  78. // ignore
  79. }
  80. })();
  81. /**
  82. * Specifies if local storage should be used (eg. on the iPad which has no filesystem)
  83. */
  84. Editor.useLocalStorage = typeof(Storage) != 'undefined' && mxClient.IS_IOS;
  85. /**
  86. * Images below are for lightbox and embedding toolbars.
  87. */
  88. Editor.helpImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAXVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC5BxTwAAAAH3RSTlMAlUF8boNQIE0LBgOgkGlHNSwqFIx/dGVUOjApmV9ezNACSAAAAIVJREFUGNNtjNsOgzAMQ5NeoVcKDAZs+//PXLKI8YKlWvaRU7jXuFpb9qsbdK05XILUiE8JHQox1Pv3OgFUzf1AGqWqUg+QBwLF0YAeegBlCNgRWOpB5vUfTCmeoHQ/wNdy0jLH/cM+b+wLTw4n/7ACEmHVVy8h6qy8V7MNcGowWpsNbvUFcGUEdSi1s/oAAAAASUVORK5CYII=' :
  89. IMAGE_PATH + '/help.png';
  90. /**
  91. * Sets the default font size.
  92. */
  93. Editor.checkmarkImage = (mxClient.IS_SVG) ? 'data:image/gif;base64,R0lGODlhFQAVAMQfAGxsbHx8fIqKioaGhvb29nJycvr6+sDAwJqamltbW5OTk+np6YGBgeTk5Ly8vJiYmP39/fLy8qWlpa6ursjIyOLi4vj4+N/f3+3t7fT09LCwsHZ2dubm5r6+vmZmZv///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OEY4NTZERTQ5QUFBMTFFMUE5MTVDOTM5MUZGMTE3M0QiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OEY4NTZERTU5QUFBMTFFMUE5MTVDOTM5MUZGMTE3M0QiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4Rjg1NkRFMjlBQUExMUUxQTkxNUM5MzkxRkYxMTczRCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4Rjg1NkRFMzlBQUExMUUxQTkxNUM5MzkxRkYxMTczRCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAEAAB8ALAAAAAAVABUAAAVI4CeOZGmeaKqubKtylktSgCOLRyLd3+QJEJnh4VHcMoOfYQXQLBcBD4PA6ngGlIInEHEhPOANRkaIFhq8SuHCE1Hb8Lh8LgsBADs=' :
  94. IMAGE_PATH + '/checkmark.gif';
  95. /**
  96. * Images below are for lightbox and embedding toolbars.
  97. */
  98. Editor.maximizeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAElBMVEUAAAAAAAAAAAAAAAAAAAAAAADgKxmiAAAABXRSTlMA758vX1Pw3BoAAABJSURBVAjXY8AJQkODGBhUQ0MhbAUGBiYY24CBgRnGFmZgMISwgwwDGRhEhVVBbAVmEQYGRwMmBjIAQi/CTIRd6G5AuA3dzYQBAHj0EFdHkvV4AAAAAElFTkSuQmCC';
  99. /**
  100. * Specifies the image URL to be used for the transparent background.
  101. */
  102. Editor.zoomOutImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAElBMVEUAAAAAAAAsLCxxcXEhISFgYGChjTUxAAAAAXRSTlMAQObYZgAAAEdJREFUCNdjIAMwCQrB2YKCggJQJqMwA7MglK1owMBgqABVApITgLJZXFxgbIQ4Qj3CHIT5ggoIe5kgNkM1KSDYKBKqxPkDAPo5BAZBE54hAAAAAElFTkSuQmCC';
  103. /**
  104. * Specifies the image URL to be used for the transparent background.
  105. */
  106. Editor.zoomInImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAElBMVEUAAAAAAAAsLCwhISFxcXFgYGBavKaoAAAAAXRSTlMAQObYZgAAAElJREFUCNdjIAMwCQrB2YKCggJQJqMIA4sglK3owMzgqABVwsDMwCgAZTMbG8PYCHGEeoQ5CPMFFRD2MkFshmpSQLBRJFSJ8wcAEqcEM2uhl2MAAAAASUVORK5CYII=';
  107. /**
  108. * Specifies the image URL to be used for the transparent background.
  109. */
  110. Editor.zoomFitImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAD1BMVEUAAAAAAAAwMDBwcHBgYGC1xl09AAAAAXRSTlMAQObYZgAAAEFJREFUCNdjIAMwCQrB2YKCggJQJqMwA7MglK1owMBgqABVApITwMdGqEeYgzBfUAFhLxPEZqgmBQQbRUKFOH8AAK5OA3lA+FFOAAAAAElFTkSuQmCC';
  111. /**
  112. * Specifies the image URL to be used for the transparent background.
  113. */
  114. Editor.layersImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAMAAACeyVWkAAAAaVBMVEUAAAAgICAICAgdHR0PDw8WFhYICAgLCwsXFxcvLy8ODg4uLi4iIiIqKiokJCQYGBgKCgonJycFBQUCAgIqKiocHBwcHBwODg4eHh4cHBwnJycJCQkUFBQqKiojIyMuLi4ZGRkgICAEBATOWYXAAAAAGnRSTlMAD7+fnz8/H7/ff18/77+vr5+fn39/b28fH2xSoKsAAACQSURBVBjTrYxJEsMgDARZZMAY73sgCcn/HxnhKtnk7j6oRq0psfuoyndZ/SuODkHPLzfVT6KeyPePnJ7KrnkRjWMXTn4SMnN8mXe2SSM3ts8L/ZUxxrbAULSYJJULE0Iw9pjpenoICcgcX61mGgTgtCv9Be99pzCoDhNQWQnchD1mup5++CYGcoQexajZbfwAj/0MD8ZOaUgAAAAASUVORK5CYII=';
  115. /**
  116. * Specifies the image URL to be used for the transparent background.
  117. */
  118. Editor.previousImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAAh0lEQVQ4je3UsQnCUBCA4U8hpa1NsoEjpHQJS0dxADdwEMuMIJkgA1hYChbGQgMi+JC8q4L/AB/vDu7x74cWWEZhJU44RmA1zujR5GIbXF9YNrjD/Q0bDRY4fEBZ4P4LlgTnCbAf84pUM8/9hY08tMUtEoQ1LpEgrNBFglChFXR6Q6GfwwR6AGKJMF74Vtt3AAAAAElFTkSuQmCC';
  119. /**
  120. * Specifies the image URL to be used for the transparent background.
  121. */
  122. Editor.nextImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAAi0lEQVQ4jeXUIQ7CUAwA0MeGxWI2yylwnALJUdBcgYvM7QYLmjOQIAkIPmJZghiIvypoUtX0tfnJL38X5ZfaEgUeUcManFBHgS0SLlhHggk3bCPBhCf2keCQR8wjwYTDp6YiZxJmOU1jGw7vGALescuBxsArNlOwd/CM1VSM/ut1qCIw+uOwiMJ+OF4CQzBCXm3hyAAAAABJRU5ErkJggg==';
  123. /**
  124. * Specifies the image URL to be used for the transparent background.
  125. */
  126. Editor.zoomOutLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAilBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////2N2iNAAAALXRSTlMA+vTcKMM96GRBHwXxi0YaX1HLrKWhiHpWEOnOr52Vb2xKSDcT19PKv5l/Ngdk8+viAAABJklEQVQ4y4WT2XaDMAxEvWD2nSSUNEnTJN3r//+9Sj7ILAY6L0ijC4ONYVZRpo6cByrz2YKSUGorGTpz71lPVHvT+avoB5wIkU/mxk8veceSuNoLg44IzziXjvpih72wKQnm8yc2UoiP/LAd8jQfe2Xf4Pq+2EyYIvv9wbzHHCgwxDdlBtWZOdqDfTCVgqpygQpsZaojVAVc9UjQxnAJDIBhiQv84tq3gMQCAVTxVoSibXJf8tMuc7e1TB/DCmejBNg/w1Y3c+AM5vv4w7xM59/oXamrHaLVqPQ+OTCnmMZxgz0SdL5zji0/ld6j88qGa5KIiBB6WeJGKfUKwSMKLuXgvl1TW0tm5R9UQL/efSDYsnzxD8CinhBsTTdugJatKpJwf8v+ADb8QmvW7AeAAAAAAElFTkSuQmCC';
  127. /**
  128. * Specifies the image URL to be used for the transparent background.
  129. */
  130. Editor.zoomInLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAilBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////2N2iNAAAALXRSTlMA+vTcKMM96GRBHwXxi0YaX1HLrKWhiHpWEOnOr52Vb2xKSDcT19PKv5l/Ngdk8+viAAABKElEQVQ4y4WT6WKCMBCENwkBwn2oFKvWqr3L+79es4EkQIDOH2d3Pxk2ABiJlB8JCXjqw4LikHVGLHTm3nM3UeVN5690GBBN0GwyV/3kkrUQR+WeKnREeKpzaXWd77CmJiXGfPIEI4V4yQ9TIW/ntlcMBe731Vts9w5TWG8F5j3mQI4hvrKpdGeYA7CX9qAcl650gVJartxRuhyHVghF8idQAIbFLvCLu28BsQEC6aKtCK6Pyb3JT7PmbmtNH8Ny56CotD/2qOs5cJbuffxgXmCib+xddVU5RNOhkvvkhTlFehzVWCOh3++MYElOhfdovaImnRYVmqDdsuhNp1QrBBE6uGC2+3ZNjGdg5B94oD+9uyVgWT79BwAxEBTWdOu3bWBVgsn/N/AHUD9IC01Oe40AAAAASUVORK5CYII=';
  131. /**
  132. * Specifies the image URL to be used for the transparent background.
  133. */
  134. Editor.actualSizeLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAilBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////2N2iNAAAALXRSTlMA+vTcKMM96GRBHwXxi0YaX1HLrKWhiHpWEOnOr52Vb2xKSDcT19PKv5l/Ngdk8+viAAABIUlEQVQ4y4WT2XqDIBCFBxDc9yTWNEnTJN3r+79eGT4BEbXnaubMr8dBBaM450dCQp4LWFAascGIRd48eB4cNYE7f6XjgGiCFs5c+dml6CFN6j1V6IQIlHPpdV/usKcmJcV88gQTRXjLD9Mhb+fWq8YG9/uCmTCFjeeDeY85UGKIUGUuqzN42kv7oCouq9oHamlzVR1lVfpAIu1QVRiW+sAv7r4FpAYIZZVsRXB9TP5Dfpo1d1trCgzz1iiptH/sUbdz4CzN9+mLeXHn3+hdddd4RDegsrvzwZwSs2GLPRJidAqCLTlVwaMPqpYMWjTWBB2WRW86pVkhSKyDK2bdt2tmagZG4sBD/evdLQHLEvQfAOKRoLCmG1FAB6uKmby+gz+REDn7O5+EwQAAAABJRU5ErkJggg==';
  135. /**
  136. * Specifies the image URL to be used for the transparent background.
  137. */
  138. Editor.printLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAXVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////9RKvvlAAAAHnRSTlMAydnl77qbMLT093H7K4Nd4Ktn082+lYt5bkklEgP44nQSAAAApUlEQVQ4y73P2Q6DIBRF0cOgbRHHzhP//5m9mBAQKjG1cT0Yc7ITAMu1LNQgUZiQ2DYoNQ0sCQb6qgHAfRx48opq3J9AZ6xuF7uOew8Ik1OsCZRS2UAC9V+D9a+QZYxNA45YFQftPtSkATOhw7dAc0vPBwKWiIOjP0JZ0yMuQJ27g36DipOUsqRAM0dR8KD1/ILHaHSE/w8DIx09E3g/BTce6rHUB5sAPKvfF+JdAAAAAElFTkSuQmCC';
  139. /**
  140. * Specifies the image URL to be used for the transparent background.
  141. */
  142. Editor.layersLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAmVBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+/v7///+bnZkkAAAAMnRSTlMABPr8ByiD88KsTi/rvJb272mjeUA1CuPe1M/KjVxYHxMP6KZ0S9nYzGRGGRaznpGIbzaGUf0AAAHESURBVDjLbZLZYoIwEEVDgLCjbKIgAlqXqt3m/z+uNwu1rcyDhjl3ktnYL7OY254C0VX3yWFZfzDrOClbbgKxi0YDHjwl4jbnRkXxJS/C1YP3DbBhD1n7Ex4uaAqdVDb3yJ/4J/3nJD2to/ngQz/DfUvzMp4JJ5sSCaF5oXmemgQDfDxzbi+Kq4sU+vNcuAmx94JtyOP2DD4Epz2asWSCz4Z/4fECxyNj9zC9xNLHcdPEO+awDKeSaUu0W4twZQiO2hYVisTR3RCtK/c1X6t4xMEpiGqXqVntEBLolkZZsKY4QtwH6jzq67dEHlJysB1aNOD3XT7n1UkasQN59L4yC2RELMDSeCRtz3yV22Ub3ozIUTknYx8JWqDdQxbUes98cR2kZtUSveF/bAhcedwEWmlxIkpZUy4XOCb6VBjjxHvbwo/1lBAHHi2JCr0NI570QhyHq/DhJoE2lLgyA4RVe6KmZ47O/3b86MCP0HWa73A8/C3SUc5Qc1ajt6fgpXJ+RGpMvDSchepZDOOQRcZVIKcK90x2D7etqtI+56+u6n3sPriO6nfphitR4+O2m3EbM7lh3me1FM1o+LMI887rN+s3/wZdTFlpNVJiOAAAAABJRU5ErkJggg==';
  143. /**
  144. * Specifies the image URL to be used for the transparent background.
  145. */
  146. Editor.closeLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAUVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////8IN+deAAAAGnRSTlMAuvAIg/dDM/QlOeuFhj0S5s4vKgzjxJRQNiLSey0AAADNSURBVDjLfZLbEoMgDEQjRRRs1XqX///QNmOHJSnjPkHOGR7IEmeoGtJZstnwjqbRfIsmgEdtPCqe9Ynz7ZSc07rE2QiSc+qv8TvjRXA2PDUm3dpe82iJhOEUfxJJo3aCv+jKmRmH4lcCjCjeh9GWOdL/GZZkXH3PYYDrHBnfc4D/RVZf5sjoC1was+Y6HQxwaUxFvq/a0Pv343VCTxfBSRiB+ab3M3eiQZXmMNBJ3Y8pGRZtYQ7DgHMXJEdPLTaN/qBjzJOBc3nmNcbsA16bMR0oLqf+AAAAAElFTkSuQmCC';
  147. /**
  148. * Specifies the image URL to be used for the transparent background.
  149. */
  150. Editor.editLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAACVBMVEUAAAD///////9zeKVjAAAAAnRSTlMAgJsrThgAAABcSURBVBjThc6xDcAgDATAd8MQTEPW8TRUmYCGnzLRYyOlIV+dZFtvkICTFGqiJEzAG0/Uje9oL+e5Vu4F5yUYJxxqGKhQZ0eBvmgwYQLQaARKD1hbiPyDR0QOeAC31EyNe5X/kAAAAABJRU5ErkJggg==';
  151. /**
  152. * Specifies the image URL to be used for the transparent background.
  153. */
  154. Editor.previousLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAPFBMVEUAAAD////////////////////////////////////////////////////////////////////////////YSWgTAAAAE3RSTlMA7fci493c0MW8uJ6CZks4MxQHEZL6ewAAAFZJREFUOMvdkskRgDAMA4lDwg2B7b9XOlge/KKvdsa25KFb5XlRvxXC/DNBEv8IFNjBgGdDgXtFgTyhwDXiQAUHCvwa4Uv6mR6UR+1led2mVonvl+tML45qCQNQLIx7AAAAAElFTkSuQmCC';
  155. /**
  156. * Specifies the image URL to be used for the transparent background.
  157. */
  158. Editor.nextLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAPFBMVEUAAAD////////////////////////////////////////////////////////////////////////////YSWgTAAAAE3RSTlMA7fci493c0MW8uJ6CZks4MxQHEZL6ewAAAFRJREFUOMvd0skRgCAQBVEFwQ0V7fxzNQP6wI05v6pZ/kyj1b7FNgik2gQzzLcAwiUAigHOTwDHK4A1CmB5BJANJG1hQ9qafYcqFlZP3IFc9eVGrR+iIgkDQRUXIAAAAABJRU5ErkJggg==';
  159. /**
  160. * Specifies the image URL to be used for the transparent background.
  161. */
  162. Editor.ctrlKey = (mxClient.IS_MAC) ? 'Cmd' : 'Ctrl';
  163. /**
  164. * Editor inherits from mxEventSource
  165. */
  166. mxUtils.extend(Editor, mxEventSource);
  167. /**
  168. * Stores initial state of mxClient.NO_FO.
  169. */
  170. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  171. /**
  172. * Specifies the image URL to be used for the transparent background.
  173. */
  174. Editor.prototype.transparentImage = (mxClient.IS_SVG) ? 'data:image/gif;base64,R0lGODlhMAAwAIAAAP///wAAACH5BAEAAAAALAAAAAAwADAAAAIxhI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8Si8egpAAA7' :
  175. IMAGE_PATH + '/transparent.gif';
  176. /**
  177. * Specifies if the canvas should be extended in all directions. Default is true.
  178. */
  179. Editor.prototype.extendCanvas = true;
  180. /**
  181. * Specifies if the app should run in chromeless mode. Default is false.
  182. * This default is only used if the contructor argument is null.
  183. */
  184. Editor.prototype.chromeless = false;
  185. /**
  186. * Specifies the order of OK/Cancel buttons in dialogs. Default is true.
  187. * Cancel first is used on Macs, Windows/Confluence uses cancel last.
  188. */
  189. Editor.prototype.cancelFirst = true;
  190. /**
  191. * Specifies if the editor is enabled. Default is true.
  192. */
  193. Editor.prototype.enabled = true;
  194. /**
  195. * Contains the name which was used for the last save. Default value is null.
  196. */
  197. Editor.prototype.filename = null;
  198. /**
  199. * Contains the current modified state of the diagram. This is false for
  200. * new diagrams and after the diagram was saved.
  201. */
  202. Editor.prototype.modified = false;
  203. /**
  204. * Specifies if the diagram should be saved automatically if possible. Default
  205. * is true.
  206. */
  207. Editor.prototype.autosave = true;
  208. /**
  209. * Specifies the top spacing for the initial page view. Default is 0.
  210. */
  211. Editor.prototype.initialTopSpacing = 0;
  212. /**
  213. * Specifies the app name. Default is document.title.
  214. */
  215. Editor.prototype.appName = document.title;
  216. /**
  217. *
  218. */
  219. Editor.prototype.editBlankUrl = window.location.protocol + '//' + window.location.host + '/?client=1';
  220. /**
  221. *
  222. */
  223. Editor.prototype.editBlankFallbackUrl = window.location.protocol + '//' + window.location.host + '/?create=drawdata&splash=0';
  224. /**
  225. * Initializes the environment.
  226. */
  227. Editor.prototype.init = function() { };
  228. /**
  229. * Sets the XML node for the current diagram.
  230. */
  231. Editor.prototype.setAutosave = function(value)
  232. {
  233. this.autosave = value;
  234. this.fireEvent(new mxEventObject('autosaveChanged'));
  235. };
  236. /**
  237. *
  238. */
  239. Editor.prototype.getEditBlankUrl = function(params, fallback)
  240. {
  241. return ((fallback) ? this.editBlankFallbackUrl : this.editBlankUrl) + params;
  242. }
  243. /**
  244. *
  245. */
  246. Editor.prototype.editAsNew = function(xml, title)
  247. {
  248. var p = (title != null) ? '&title=' + encodeURIComponent(title) : '';
  249. if (typeof window.postMessage !== 'undefined' && (document.documentMode == null || document.documentMode >= 10))
  250. {
  251. var wnd = null;
  252. var receive = mxUtils.bind(this, function(evt)
  253. {
  254. if (evt.data == 'ready' && evt.source == wnd)
  255. {
  256. wnd.postMessage(xml, '*');
  257. mxEvent.removeListener(window, 'message', receive);
  258. }
  259. });
  260. mxEvent.addListener(window, 'message', receive);
  261. wnd = window.open(this.getEditBlankUrl(p, false));
  262. }
  263. else
  264. {
  265. // Data is pulled from global variable after tab loads
  266. window.drawdata = xml;
  267. window.open(this.getEditBlankUrl(p, true));
  268. }
  269. };
  270. /**
  271. * Sets the XML node for the current diagram.
  272. */
  273. Editor.prototype.createGraph = function(themes, model)
  274. {
  275. var graph = new Graph(null, model, null, null, themes);
  276. graph.transparentBackground = false;
  277. // Opens all links in a new window while editing
  278. if (!this.chromeless)
  279. {
  280. graph.isBlankLink = function(href)
  281. {
  282. return !this.isExternalProtocol(href);
  283. };
  284. }
  285. return graph;
  286. };
  287. /**
  288. * Sets the XML node for the current diagram.
  289. */
  290. Editor.prototype.resetGraph = function()
  291. {
  292. this.graph.gridEnabled = !this.chromeless || urlParams['grid'] == '1';
  293. this.graph.graphHandler.guidesEnabled = true;
  294. this.graph.setTooltips(true);
  295. this.graph.setConnectable(true);
  296. this.graph.foldingEnabled = true;
  297. this.graph.scrollbars = this.graph.defaultScrollbars;
  298. this.graph.pageVisible = this.graph.defaultPageVisible;
  299. this.graph.pageBreaksVisible = this.graph.pageVisible;
  300. this.graph.preferPageSize = this.graph.pageBreaksVisible;
  301. this.graph.background = this.graph.defaultGraphBackground;
  302. this.graph.pageScale = mxGraph.prototype.pageScale;
  303. this.graph.pageFormat = mxGraph.prototype.pageFormat;
  304. this.updateGraphComponents();
  305. this.graph.view.setScale(1);
  306. };
  307. /**
  308. * Sets the XML node for the current diagram.
  309. */
  310. Editor.prototype.readGraphState = function(node)
  311. {
  312. this.graph.gridEnabled = node.getAttribute('grid') != '0' && (!this.chromeless || urlParams['grid'] == '1');
  313. this.graph.gridSize = parseFloat(node.getAttribute('gridSize')) || mxGraph.prototype.gridSize;
  314. this.graph.graphHandler.guidesEnabled = node.getAttribute('guides') != '0';
  315. this.graph.setTooltips(node.getAttribute('tooltips') != '0');
  316. this.graph.setConnectable(node.getAttribute('connect') != '0');
  317. this.graph.connectionArrowsEnabled = node.getAttribute('arrows') != '0';
  318. this.graph.foldingEnabled = node.getAttribute('fold') != '0';
  319. if (this.chromeless && this.graph.foldingEnabled)
  320. {
  321. this.graph.foldingEnabled = urlParams['nav'] == '1';
  322. this.graph.cellRenderer.forceControlClickHandler = this.graph.foldingEnabled;
  323. }
  324. var ps = node.getAttribute('pageScale');
  325. if (ps != null)
  326. {
  327. this.graph.pageScale = ps;
  328. }
  329. else
  330. {
  331. this.graph.pageScale = mxGraph.prototype.pageScale;
  332. }
  333. if (!this.graph.lightbox)
  334. {
  335. var pv = node.getAttribute('page');
  336. if (pv != null)
  337. {
  338. this.graph.pageVisible = (pv != '0');
  339. }
  340. else
  341. {
  342. this.graph.pageVisible = this.graph.defaultPageVisible;
  343. }
  344. }
  345. else
  346. {
  347. this.graph.pageVisible = false;
  348. }
  349. this.graph.pageBreaksVisible = this.graph.pageVisible;
  350. this.graph.preferPageSize = this.graph.pageBreaksVisible;
  351. var pw = node.getAttribute('pageWidth');
  352. var ph = node.getAttribute('pageHeight');
  353. if (pw != null && ph != null)
  354. {
  355. this.graph.pageFormat = new mxRectangle(0, 0, parseFloat(pw), parseFloat(ph));
  356. }
  357. // Loads the persistent state settings
  358. var bg = node.getAttribute('background');
  359. if (bg != null && bg.length > 0)
  360. {
  361. this.graph.background = bg;
  362. }
  363. else
  364. {
  365. this.graph.background = this.graph.defaultGraphBackground;
  366. }
  367. };
  368. /**
  369. * Sets the XML node for the current diagram.
  370. */
  371. Editor.prototype.setGraphXml = function(node)
  372. {
  373. if (node != null)
  374. {
  375. var dec = new mxCodec(node.ownerDocument);
  376. if (node.nodeName == 'mxGraphModel')
  377. {
  378. this.graph.model.beginUpdate();
  379. try
  380. {
  381. this.graph.model.clear();
  382. this.graph.view.scale = 1;
  383. this.readGraphState(node);
  384. this.updateGraphComponents();
  385. dec.decode(node, this.graph.getModel());
  386. }
  387. finally
  388. {
  389. this.graph.model.endUpdate();
  390. }
  391. this.fireEvent(new mxEventObject('resetGraphView'));
  392. }
  393. else if (node.nodeName == 'root')
  394. {
  395. this.resetGraph();
  396. // Workaround for invalid XML output in Firefox 20 due to bug in mxUtils.getXml
  397. var wrapper = dec.document.createElement('mxGraphModel');
  398. wrapper.appendChild(node);
  399. dec.decode(wrapper, this.graph.getModel());
  400. this.updateGraphComponents();
  401. this.fireEvent(new mxEventObject('resetGraphView'));
  402. }
  403. else
  404. {
  405. throw {
  406. message: mxResources.get('cannotOpenFile'),
  407. node: node,
  408. toString: function() { return this.message; }
  409. };
  410. }
  411. }
  412. else
  413. {
  414. this.resetGraph();
  415. this.graph.model.clear();
  416. this.fireEvent(new mxEventObject('resetGraphView'));
  417. }
  418. };
  419. /**
  420. * Returns the XML node that represents the current diagram.
  421. */
  422. Editor.prototype.getGraphXml = function(ignoreSelection)
  423. {
  424. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  425. var node = null;
  426. if (ignoreSelection)
  427. {
  428. var enc = new mxCodec(mxUtils.createXmlDocument());
  429. node = enc.encode(this.graph.getModel());
  430. }
  431. else
  432. {
  433. node = this.graph.encodeCells(mxUtils.sortCells(this.graph.model.getTopmostCells(
  434. this.graph.getSelectionCells())));
  435. }
  436. if (this.graph.view.translate.x != 0 || this.graph.view.translate.y != 0)
  437. {
  438. node.setAttribute('dx', Math.round(this.graph.view.translate.x * 100) / 100);
  439. node.setAttribute('dy', Math.round(this.graph.view.translate.y * 100) / 100);
  440. }
  441. node.setAttribute('grid', (this.graph.isGridEnabled()) ? '1' : '0');
  442. node.setAttribute('gridSize', this.graph.gridSize);
  443. node.setAttribute('guides', (this.graph.graphHandler.guidesEnabled) ? '1' : '0');
  444. node.setAttribute('tooltips', (this.graph.tooltipHandler.isEnabled()) ? '1' : '0');
  445. node.setAttribute('connect', (this.graph.connectionHandler.isEnabled()) ? '1' : '0');
  446. node.setAttribute('arrows', (this.graph.connectionArrowsEnabled) ? '1' : '0');
  447. node.setAttribute('fold', (this.graph.foldingEnabled) ? '1' : '0');
  448. node.setAttribute('page', (this.graph.pageVisible) ? '1' : '0');
  449. node.setAttribute('pageScale', this.graph.pageScale);
  450. node.setAttribute('pageWidth', this.graph.pageFormat.width);
  451. node.setAttribute('pageHeight', this.graph.pageFormat.height);
  452. if (this.graph.background != null)
  453. {
  454. node.setAttribute('background', this.graph.background);
  455. }
  456. return node;
  457. };
  458. /**
  459. * Keeps the graph container in sync with the persistent graph state
  460. */
  461. Editor.prototype.updateGraphComponents = function()
  462. {
  463. var graph = this.graph;
  464. if (graph.container != null)
  465. {
  466. graph.view.validateBackground();
  467. graph.container.style.overflow = (graph.scrollbars) ? 'auto' : 'hidden';
  468. this.fireEvent(new mxEventObject('updateGraphComponents'));
  469. }
  470. };
  471. /**
  472. * Sets the modified flag.
  473. */
  474. Editor.prototype.setModified = function(value)
  475. {
  476. this.modified = value;
  477. };
  478. /**
  479. * Sets the filename.
  480. */
  481. Editor.prototype.setFilename = function(value)
  482. {
  483. this.filename = value;
  484. };
  485. /**
  486. * Creates and returns a new undo manager.
  487. */
  488. Editor.prototype.createUndoManager = function()
  489. {
  490. var graph = this.graph;
  491. var undoMgr = new mxUndoManager();
  492. this.undoListener = function(sender, evt)
  493. {
  494. undoMgr.undoableEditHappened(evt.getProperty('edit'));
  495. };
  496. // Installs the command history
  497. var listener = mxUtils.bind(this, function(sender, evt)
  498. {
  499. this.undoListener.apply(this, arguments);
  500. });
  501. graph.getModel().addListener(mxEvent.UNDO, listener);
  502. graph.getView().addListener(mxEvent.UNDO, listener);
  503. // Keeps the selection in sync with the history
  504. var undoHandler = function(sender, evt)
  505. {
  506. var cand = graph.getSelectionCellsForChanges(evt.getProperty('edit').changes);
  507. var model = graph.getModel();
  508. var cells = [];
  509. for (var i = 0; i < cand.length; i++)
  510. {
  511. if ((model.isVertex(cand[i]) || model.isEdge(cand[i])) && graph.view.getState(cand[i]) != null)
  512. {
  513. cells.push(cand[i]);
  514. }
  515. }
  516. graph.setSelectionCells(cells);
  517. };
  518. undoMgr.addListener(mxEvent.UNDO, undoHandler);
  519. undoMgr.addListener(mxEvent.REDO, undoHandler);
  520. return undoMgr;
  521. };
  522. /**
  523. * Adds basic stencil set (no namespace).
  524. */
  525. Editor.prototype.initStencilRegistry = function() { };
  526. /**
  527. * Creates and returns a new undo manager.
  528. */
  529. Editor.prototype.destroy = function()
  530. {
  531. if (this.graph != null)
  532. {
  533. this.graph.destroy();
  534. this.graph = null;
  535. }
  536. };
  537. /**
  538. * Class for asynchronously opening a new window and loading a file at the same
  539. * time. This acts as a bridge between the open dialog and the new editor.
  540. */
  541. OpenFile = function(done)
  542. {
  543. this.producer = null;
  544. this.consumer = null;
  545. this.done = done;
  546. this.args = null;
  547. };
  548. /**
  549. * Registers the editor from the new window.
  550. */
  551. OpenFile.prototype.setConsumer = function(value)
  552. {
  553. this.consumer = value;
  554. this.execute();
  555. };
  556. /**
  557. * Sets the data from the loaded file.
  558. */
  559. OpenFile.prototype.setData = function()
  560. {
  561. this.args = arguments;
  562. this.execute();
  563. };
  564. /**
  565. * Displays an error message.
  566. */
  567. OpenFile.prototype.error = function(msg)
  568. {
  569. this.cancel(true);
  570. mxUtils.alert(msg);
  571. };
  572. /**
  573. * Consumes the data.
  574. */
  575. OpenFile.prototype.execute = function()
  576. {
  577. if (this.consumer != null && this.args != null)
  578. {
  579. this.cancel(false);
  580. this.consumer.apply(this, this.args);
  581. }
  582. };
  583. /**
  584. * Cancels the operation.
  585. */
  586. OpenFile.prototype.cancel = function(cancel)
  587. {
  588. if (this.done != null)
  589. {
  590. this.done((cancel != null) ? cancel : true);
  591. }
  592. };
  593. /**
  594. * Basic dialogs that are available in the viewer (print dialog).
  595. */
  596. function Dialog(editorUi, elt, w, h, modal, closable, onClose)
  597. {
  598. var dx = 0;
  599. if (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8))
  600. {
  601. // Adds padding as a workaround for box model in older IE versions
  602. // This needs to match the total padding of geDialog in CSS
  603. dx = 80;
  604. }
  605. w += dx;
  606. h += dx;
  607. var w0 = w;
  608. var h0 = h;
  609. var dh = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
  610. var left = Math.max(1, Math.round((document.body.clientWidth - w - 64) / 2));
  611. var top = Math.max(1, Math.round((dh - h - editorUi.footerHeight) / 3));
  612. // Keeps window size inside available space
  613. if (!mxClient.IS_QUIRKS)
  614. {
  615. elt.style.maxHeight = '100%';
  616. }
  617. w = Math.min(w, document.body.scrollWidth - 64);
  618. if (h > dh - 64)
  619. {
  620. elt.style.overflowY = 'auto';
  621. }
  622. h = Math.min(h, dh - 64);
  623. // Increments zIndex to put subdialogs and background over existing dialogs and background
  624. if (editorUi.dialogs.length > 0)
  625. {
  626. this.zIndex += editorUi.dialogs.length * 2;
  627. }
  628. if (this.bg == null)
  629. {
  630. this.bg = editorUi.createDiv('background');
  631. this.bg.style.position = 'absolute';
  632. this.bg.style.background = 'white';
  633. this.bg.style.height = dh + 'px';
  634. this.bg.style.right = '0px';
  635. this.bg.style.zIndex = this.zIndex - 2;
  636. mxUtils.setOpacity(this.bg, this.bgOpacity);
  637. if (mxClient.IS_QUIRKS)
  638. {
  639. new mxDivResizer(this.bg);
  640. }
  641. }
  642. var origin = mxUtils.getDocumentScrollOrigin(document);
  643. this.bg.style.left = origin.x + 'px';
  644. this.bg.style.top = origin.y + 'px';
  645. left += origin.x;
  646. top += origin.y;
  647. if (modal)
  648. {
  649. document.body.appendChild(this.bg);
  650. }
  651. var div = editorUi.createDiv('geDialog');
  652. div.style.width = w + 'px';
  653. div.style.height = h + 'px';
  654. div.style.left = left + 'px';
  655. div.style.top = top + 'px';
  656. div.style.zIndex = this.zIndex;
  657. div.appendChild(elt);
  658. document.body.appendChild(div);
  659. if (closable)
  660. {
  661. var img = document.createElement('img');
  662. img.setAttribute('src', Dialog.prototype.closeImage);
  663. img.setAttribute('title', mxResources.get('close'));
  664. img.className = 'geDialogClose';
  665. img.style.top = (top + 14) + 'px';
  666. img.style.left = (left + w + 38 - dx) + 'px';
  667. img.style.zIndex = this.zIndex;
  668. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  669. {
  670. editorUi.hideDialog(true);
  671. }));
  672. document.body.appendChild(img);
  673. this.dialogImg = img;
  674. mxEvent.addGestureListeners(this.bg, null, null, mxUtils.bind(this, function(evt)
  675. {
  676. editorUi.hideDialog(true);
  677. }));
  678. }
  679. this.resizeListener = mxUtils.bind(this, function()
  680. {
  681. dh = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
  682. this.bg.style.height = dh + 'px';
  683. left = Math.max(1, Math.round((document.body.clientWidth - w - 64) / 2));
  684. top = Math.max(1, Math.round((dh - h - editorUi.footerHeight) / 3));
  685. div.style.left = left + 'px';
  686. div.style.top = top + 'px';
  687. w = Math.min(w0, document.body.scrollWidth - 64);
  688. h = Math.min(h0, dh - 64);
  689. div.style.width = w + 'px';
  690. div.style.height = h + 'px';
  691. if (h0 > dh - 64)
  692. {
  693. elt.style.overflowY = 'auto';
  694. }
  695. else
  696. {
  697. elt.style.overflowY = '';
  698. }
  699. if (this.dialogImg != null)
  700. {
  701. this.dialogImg.style.top = (top + 14) + 'px';
  702. this.dialogImg.style.left = (left + w + 38 - dx) + 'px';
  703. }
  704. });
  705. mxEvent.addListener(window, 'resize', this.resizeListener);
  706. this.onDialogClose = onClose;
  707. this.container = div;
  708. editorUi.editor.fireEvent(new mxEventObject('showDialog'));
  709. };
  710. /**
  711. *
  712. */
  713. Dialog.prototype.zIndex = mxPopupMenu.prototype.zIndex - 1;
  714. /**
  715. *
  716. */
  717. Dialog.prototype.noColorImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/nocolor.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkEzRDlBMUUwODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkEzRDlBMUUxODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QTNEOUExREU4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QTNEOUExREY4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5xh3fmAAAABlBMVEX////MzMw46qqDAAAAGElEQVR42mJggAJGKGAYIIGBth8KAAIMAEUQAIElnLuQAAAAAElFTkSuQmCC';
  718. /**
  719. *
  720. */
  721. Dialog.prototype.closeImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/close.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAQMAAADaX5RTAAAABlBMVEV7mr3///+wksspAAAAAnRSTlP/AOW3MEoAAAAdSURBVAgdY9jXwCDDwNDRwHCwgeExmASygSL7GgB12QiqNHZZIwAAAABJRU5ErkJggg==';
  722. /**
  723. *
  724. */
  725. Dialog.prototype.clearImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/clear.gif' : 'data:image/gif;base64,R0lGODlhDQAKAIABAMDAwP///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OUIzOEM1NzI4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OUIzOEM1NzM4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5QjM4QzU3MDg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5QjM4QzU3MTg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAEAAAEALAAAAAANAAoAAAIXTGCJebD9jEOTqRlttXdrB32PJ2ncyRQAOw==';
  726. /**
  727. *
  728. */
  729. Dialog.prototype.lockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/locked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCODExNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCODIxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3RjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI4MDE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PvqMCFYAAAAVUExURZmZmb+/v7KysqysrMzMzLGxsf///4g8N1cAAAAHdFJOU////////wAaSwNGAAAAPElEQVR42lTMQQ4AIQgEwUa0//9kTQirOweYOgDqAMbZUr10AGlAwx4/BJ2QJ4U0L5brYjovvpv32xZgAHZaATFtMbu4AAAAAElFTkSuQmCC';
  730. /**
  731. *
  732. */
  733. Dialog.prototype.unlockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/unlocked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCN0QxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCN0UxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3QjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI3QzE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkKMpVwAAAAYUExURZmZmbKysr+/v6ysrOXl5czMzLGxsf///zHN5lwAAAAIdFJOU/////////8A3oO9WQAAADxJREFUeNpUzFESACAEBNBVsfe/cZJU+8Mzs8CIABCidtfGOndnYsT40HDSiCcbPdoJo10o9aI677cpwACRoAF3dFNlswAAAABJRU5ErkJggg==';
  734. /**
  735. * Removes the dialog from the DOM.
  736. */
  737. Dialog.prototype.bgOpacity = 80;
  738. /**
  739. * Removes the dialog from the DOM.
  740. */
  741. Dialog.prototype.close = function(cancel)
  742. {
  743. if (this.onDialogClose != null)
  744. {
  745. this.onDialogClose(cancel);
  746. this.onDialogClose = null;
  747. }
  748. if (this.dialogImg != null)
  749. {
  750. this.dialogImg.parentNode.removeChild(this.dialogImg);
  751. this.dialogImg = null;
  752. }
  753. if (this.bg != null && this.bg.parentNode != null)
  754. {
  755. this.bg.parentNode.removeChild(this.bg);
  756. }
  757. mxEvent.removeListener(window, 'resize', this.resizeListener);
  758. this.container.parentNode.removeChild(this.container);
  759. };
  760. /**
  761. * Constructs a new print dialog.
  762. */
  763. var PrintDialog = function(editorUi, title)
  764. {
  765. this.create(editorUi, title);
  766. };
  767. /**
  768. * Constructs a new print dialog.
  769. */
  770. PrintDialog.prototype.create = function(editorUi)
  771. {
  772. var graph = editorUi.editor.graph;
  773. var row, td;
  774. var table = document.createElement('table');
  775. table.style.width = '100%';
  776. table.style.height = '100%';
  777. var tbody = document.createElement('tbody');
  778. row = document.createElement('tr');
  779. var onePageCheckBox = document.createElement('input');
  780. onePageCheckBox.setAttribute('type', 'checkbox');
  781. td = document.createElement('td');
  782. td.setAttribute('colspan', '2');
  783. td.style.fontSize = '10pt';
  784. td.appendChild(onePageCheckBox);
  785. var span = document.createElement('span');
  786. mxUtils.write(span, ' ' + mxResources.get('fitPage'));
  787. td.appendChild(span);
  788. mxEvent.addListener(span, 'click', function(evt)
  789. {
  790. onePageCheckBox.checked = !onePageCheckBox.checked;
  791. pageCountCheckBox.checked = !onePageCheckBox.checked;
  792. mxEvent.consume(evt);
  793. });
  794. mxEvent.addListener(onePageCheckBox, 'change', function()
  795. {
  796. pageCountCheckBox.checked = !onePageCheckBox.checked;
  797. });
  798. row.appendChild(td);
  799. tbody.appendChild(row);
  800. row = row.cloneNode(false);
  801. var pageCountCheckBox = document.createElement('input');
  802. pageCountCheckBox.setAttribute('type', 'checkbox');
  803. td = document.createElement('td');
  804. td.style.fontSize = '10pt';
  805. td.appendChild(pageCountCheckBox);
  806. var span = document.createElement('span');
  807. mxUtils.write(span, ' ' + mxResources.get('posterPrint') + ':');
  808. td.appendChild(span);
  809. mxEvent.addListener(span, 'click', function(evt)
  810. {
  811. pageCountCheckBox.checked = !pageCountCheckBox.checked;
  812. onePageCheckBox.checked = !pageCountCheckBox.checked;
  813. mxEvent.consume(evt);
  814. });
  815. row.appendChild(td);
  816. var pageCountInput = document.createElement('input');
  817. pageCountInput.setAttribute('value', '1');
  818. pageCountInput.setAttribute('type', 'number');
  819. pageCountInput.setAttribute('min', '1');
  820. pageCountInput.setAttribute('size', '4');
  821. pageCountInput.setAttribute('disabled', 'disabled');
  822. pageCountInput.style.width = '50px';
  823. td = document.createElement('td');
  824. td.style.fontSize = '10pt';
  825. td.appendChild(pageCountInput);
  826. mxUtils.write(td, ' ' + mxResources.get('pages') + ' (max)');
  827. row.appendChild(td);
  828. tbody.appendChild(row);
  829. mxEvent.addListener(pageCountCheckBox, 'change', function()
  830. {
  831. if (pageCountCheckBox.checked)
  832. {
  833. pageCountInput.removeAttribute('disabled');
  834. }
  835. else
  836. {
  837. pageCountInput.setAttribute('disabled', 'disabled');
  838. }
  839. onePageCheckBox.checked = !pageCountCheckBox.checked;
  840. });
  841. row = row.cloneNode(false);
  842. td = document.createElement('td');
  843. mxUtils.write(td, mxResources.get('pageScale') + ':');
  844. row.appendChild(td);
  845. td = document.createElement('td');
  846. var pageScaleInput = document.createElement('input');
  847. pageScaleInput.setAttribute('value', '100 %');
  848. pageScaleInput.setAttribute('size', '5');
  849. pageScaleInput.style.width = '50px';
  850. td.appendChild(pageScaleInput);
  851. row.appendChild(td);
  852. tbody.appendChild(row);
  853. row = document.createElement('tr');
  854. td = document.createElement('td');
  855. td.colSpan = 2;
  856. td.style.paddingTop = '20px';
  857. td.setAttribute('align', 'right');
  858. // Overall scale for print-out to account for print borders in dialogs etc
  859. function preview(print)
  860. {
  861. var autoOrigin = onePageCheckBox.checked || pageCountCheckBox.checked;
  862. var printScale = parseInt(pageScaleInput.value) / 100;
  863. if (isNaN(printScale))
  864. {
  865. printScale = 1;
  866. pageScaleInput.value = '100%';
  867. }
  868. // Workaround to match available paper size in actual print output
  869. printScale *= 0.75;
  870. var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  871. var scale = 1 / graph.pageScale;
  872. if (autoOrigin)
  873. {
  874. var pageCount = (onePageCheckBox.checked) ? 1 : parseInt(pageCountInput.value);
  875. if (!isNaN(pageCount))
  876. {
  877. scale = mxUtils.getScaleForPageCount(pageCount, graph, pf);
  878. }
  879. }
  880. // Negative coordinates are cropped or shifted if page visible
  881. var gb = graph.getGraphBounds();
  882. var border = 0;
  883. var x0 = 0;
  884. var y0 = 0;
  885. // Applies print scale
  886. pf = mxRectangle.fromRectangle(pf);
  887. pf.width = Math.ceil(pf.width * printScale);
  888. pf.height = Math.ceil(pf.height * printScale);
  889. scale *= printScale;
  890. // Starts at first visible page
  891. if (!autoOrigin && graph.pageVisible)
  892. {
  893. var layout = graph.getPageLayout();
  894. x0 -= layout.x * pf.width;
  895. y0 -= layout.y * pf.height;
  896. }
  897. else
  898. {
  899. autoOrigin = true;
  900. }
  901. var preview = PrintDialog.createPrintPreview(graph, scale, pf, border, x0, y0, autoOrigin);
  902. preview.open();
  903. if (print)
  904. {
  905. PrintDialog.printPreview(preview);
  906. }
  907. };
  908. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  909. {
  910. editorUi.hideDialog();
  911. });
  912. cancelBtn.className = 'geBtn';
  913. if (editorUi.editor.cancelFirst)
  914. {
  915. td.appendChild(cancelBtn);
  916. }
  917. if (PrintDialog.previewEnabled)
  918. {
  919. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  920. {
  921. editorUi.hideDialog();
  922. preview(false);
  923. });
  924. previewBtn.className = 'geBtn';
  925. td.appendChild(previewBtn);
  926. }
  927. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  928. {
  929. editorUi.hideDialog();
  930. preview(true);
  931. });
  932. printBtn.className = 'geBtn gePrimaryBtn';
  933. td.appendChild(printBtn);
  934. if (!editorUi.editor.cancelFirst)
  935. {
  936. td.appendChild(cancelBtn);
  937. }
  938. row.appendChild(td);
  939. tbody.appendChild(row);
  940. table.appendChild(tbody);
  941. this.container = table;
  942. };
  943. /**
  944. * Constructs a new print dialog.
  945. */
  946. PrintDialog.printPreview = function(preview)
  947. {
  948. if (preview.wnd != null)
  949. {
  950. var printFn = function()
  951. {
  952. preview.wnd.focus();
  953. preview.wnd.print();
  954. preview.wnd.close();
  955. };
  956. // Workaround for Google Chrome which needs a bit of a
  957. // delay in order to render the SVG contents
  958. // Needs testing in production
  959. if (mxClient.IS_GC)
  960. {
  961. window.setTimeout(printFn, 500);
  962. }
  963. else
  964. {
  965. printFn();
  966. }
  967. }
  968. };
  969. /**
  970. * Constructs a new print dialog.
  971. */
  972. PrintDialog.createPrintPreview = function(graph, scale, pf, border, x0, y0, autoOrigin)
  973. {
  974. var preview = new mxPrintPreview(graph, scale, pf, border, x0, y0);
  975. preview.title = mxResources.get('preview');
  976. preview.printBackgroundImage = true;
  977. preview.autoOrigin = autoOrigin;
  978. var bg = graph.background;
  979. if (bg == null || bg == '' || bg == mxConstants.NONE)
  980. {
  981. bg = '#ffffff';
  982. }
  983. preview.backgroundColor = bg;
  984. var writeHead = preview.writeHead;
  985. // Adds a border in the preview
  986. preview.writeHead = function(doc)
  987. {
  988. writeHead.apply(this, arguments);
  989. doc.writeln('<style type="text/css">');
  990. doc.writeln('@media screen {');
  991. doc.writeln(' body > div { padding:30px;box-sizing:content-box; }');
  992. doc.writeln('}');
  993. doc.writeln('</style>');
  994. };
  995. return preview;
  996. };
  997. /**
  998. * Specifies if the preview button should be enabled. Default is true.
  999. */
  1000. PrintDialog.previewEnabled = true;
  1001. /**
  1002. * Constructs a new page setup dialog.
  1003. */
  1004. var PageSetupDialog = function(editorUi)
  1005. {
  1006. var graph = editorUi.editor.graph;
  1007. var row, td;
  1008. var table = document.createElement('table');
  1009. table.style.width = '100%';
  1010. table.style.height = '100%';
  1011. var tbody = document.createElement('tbody');
  1012. row = document.createElement('tr');
  1013. td = document.createElement('td');
  1014. td.style.verticalAlign = 'top';
  1015. td.style.fontSize = '10pt';
  1016. mxUtils.write(td, mxResources.get('paperSize') + ':');
  1017. row.appendChild(td);
  1018. td = document.createElement('td');
  1019. td.style.verticalAlign = 'top';
  1020. td.style.fontSize = '10pt';
  1021. var accessor = PageSetupDialog.addPageFormatPanel(td, 'pagesetupdialog', graph.pageFormat);
  1022. row.appendChild(td);
  1023. tbody.appendChild(row);
  1024. row = document.createElement('tr');
  1025. td = document.createElement('td');
  1026. mxUtils.write(td, mxResources.get('background') + ':');
  1027. row.appendChild(td);
  1028. td = document.createElement('td');
  1029. td.style.whiteSpace = 'nowrap';
  1030. var backgroundInput = document.createElement('input');
  1031. backgroundInput.setAttribute('type', 'text');
  1032. var backgroundButton = document.createElement('button');
  1033. backgroundButton.style.width = '18px';
  1034. backgroundButton.style.height = '18px';
  1035. backgroundButton.style.marginRight = '20px';
  1036. backgroundButton.style.backgroundPosition = 'center center';
  1037. backgroundButton.style.backgroundRepeat = 'no-repeat';
  1038. var newBackgroundColor = graph.background;
  1039. function updateBackgroundColor()
  1040. {
  1041. if (newBackgroundColor == null || newBackgroundColor == mxConstants.NONE)
  1042. {
  1043. backgroundButton.style.backgroundColor = '';
  1044. backgroundButton.style.backgroundImage = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  1045. }
  1046. else
  1047. {
  1048. backgroundButton.style.backgroundColor = newBackgroundColor;
  1049. backgroundButton.style.backgroundImage = '';
  1050. }
  1051. };
  1052. updateBackgroundColor();
  1053. mxEvent.addListener(backgroundButton, 'click', function(evt)
  1054. {
  1055. editorUi.pickColor(newBackgroundColor || 'none', function(color)
  1056. {
  1057. newBackgroundColor = color;
  1058. updateBackgroundColor();
  1059. });
  1060. mxEvent.consume(evt);
  1061. });
  1062. td.appendChild(backgroundButton);
  1063. mxUtils.write(td, mxResources.get('gridSize') + ':');
  1064. var gridSizeInput = document.createElement('input');
  1065. gridSizeInput.setAttribute('type', 'number');
  1066. gridSizeInput.setAttribute('min', '0');
  1067. gridSizeInput.style.width = '40px';
  1068. gridSizeInput.style.marginLeft = '6px';
  1069. gridSizeInput.value = graph.getGridSize();
  1070. td.appendChild(gridSizeInput);
  1071. mxEvent.addListener(gridSizeInput, 'change', function()
  1072. {
  1073. var value = parseInt(gridSizeInput.value);
  1074. gridSizeInput.value = Math.max(1, (isNaN(value)) ? graph.getGridSize() : value);
  1075. });
  1076. row.appendChild(td);
  1077. tbody.appendChild(row);
  1078. row = document.createElement('tr');
  1079. td = document.createElement('td');
  1080. mxUtils.write(td, mxResources.get('image') + ':');
  1081. row.appendChild(td);
  1082. td = document.createElement('td');
  1083. var changeImageLink = document.createElement('a');
  1084. changeImageLink.style.textDecoration = 'underline';
  1085. changeImageLink.style.cursor = 'pointer';
  1086. changeImageLink.style.color = '#a0a0a0';
  1087. var newBackgroundImage = graph.backgroundImage;
  1088. function updateBackgroundImage()
  1089. {
  1090. if (newBackgroundImage == null)
  1091. {
  1092. changeImageLink.removeAttribute('title');
  1093. changeImageLink.style.fontSize = '';
  1094. changeImageLink.innerHTML = mxResources.get('change') + '...';
  1095. }
  1096. else
  1097. {
  1098. changeImageLink.setAttribute('title', newBackgroundImage.src);
  1099. changeImageLink.style.fontSize = '11px';
  1100. changeImageLink.innerHTML = newBackgroundImage.src.substring(0, 42) + '...';
  1101. }
  1102. };
  1103. mxEvent.addListener(changeImageLink, 'click', function(evt)
  1104. {
  1105. editorUi.showBackgroundImageDialog(function(image)
  1106. {
  1107. newBackgroundImage = image;
  1108. updateBackgroundImage();
  1109. });
  1110. mxEvent.consume(evt);
  1111. });
  1112. updateBackgroundImage();
  1113. td.appendChild(changeImageLink);
  1114. row.appendChild(td);
  1115. tbody.appendChild(row);
  1116. row = document.createElement('tr');
  1117. td = document.createElement('td');
  1118. td.colSpan = 2;
  1119. td.style.paddingTop = '16px';
  1120. td.setAttribute('align', 'right');
  1121. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1122. {
  1123. editorUi.hideDialog();
  1124. });
  1125. cancelBtn.className = 'geBtn';
  1126. if (editorUi.editor.cancelFirst)
  1127. {
  1128. td.appendChild(cancelBtn);
  1129. }
  1130. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1131. {
  1132. editorUi.hideDialog();
  1133. if (graph.gridSize !== gridSizeInput.value)
  1134. {
  1135. graph.setGridSize(parseInt(gridSizeInput.value));
  1136. }
  1137. var change = new ChangePageSetup(editorUi, newBackgroundColor,
  1138. newBackgroundImage, accessor.get());
  1139. change.ignoreColor = graph.background == newBackgroundColor;
  1140. var oldSrc = (graph.backgroundImage != null) ? graph.backgroundImage.src : null;
  1141. var newSrc = (newBackgroundImage != null) ? newBackgroundImage.src : null;
  1142. change.ignoreImage = oldSrc === newSrc;
  1143. if (graph.pageFormat.width != change.previousFormat.width ||
  1144. graph.pageFormat.height != change.previousFormat.height ||
  1145. !change.ignoreColor || !change.ignoreImage)
  1146. {
  1147. graph.model.execute(change);
  1148. }
  1149. });
  1150. applyBtn.className = 'geBtn gePrimaryBtn';
  1151. td.appendChild(applyBtn);
  1152. if (!editorUi.editor.cancelFirst)
  1153. {
  1154. td.appendChild(cancelBtn);
  1155. }
  1156. row.appendChild(td);
  1157. tbody.appendChild(row);
  1158. table.appendChild(tbody);
  1159. this.container = table;
  1160. };
  1161. /**
  1162. *
  1163. */
  1164. PageSetupDialog.addPageFormatPanel = function(div, namePostfix, pageFormat, pageFormatListener)
  1165. {
  1166. var formatName = 'format-' + namePostfix;
  1167. var portraitCheckBox = document.createElement('input');
  1168. portraitCheckBox.setAttribute('name', formatName);
  1169. portraitCheckBox.setAttribute('type', 'radio');
  1170. portraitCheckBox.setAttribute('value', 'portrait');
  1171. var landscapeCheckBox = document.createElement('input');
  1172. landscapeCheckBox.setAttribute('name', formatName);
  1173. landscapeCheckBox.setAttribute('type', 'radio');
  1174. landscapeCheckBox.setAttribute('value', 'landscape');
  1175. var paperSizeSelect = document.createElement('select');
  1176. paperSizeSelect.style.marginBottom = '8px';
  1177. paperSizeSelect.style.width = '202px';
  1178. var formatDiv = document.createElement('div');
  1179. formatDiv.style.marginLeft = '4px';
  1180. formatDiv.style.width = '210px';
  1181. formatDiv.style.height = '24px';
  1182. portraitCheckBox.style.marginRight = '6px';
  1183. formatDiv.appendChild(portraitCheckBox);
  1184. var portraitSpan = document.createElement('span');
  1185. portraitSpan.style.maxWidth = '100px';
  1186. mxUtils.write(portraitSpan, mxResources.get('portrait'));
  1187. formatDiv.appendChild(portraitSpan);
  1188. landscapeCheckBox.style.marginLeft = '10px';
  1189. landscapeCheckBox.style.marginRight = '6px';
  1190. formatDiv.appendChild(landscapeCheckBox);
  1191. var landscapeSpan = document.createElement('span');
  1192. landscapeSpan.style.width = '100px';
  1193. mxUtils.write(landscapeSpan, mxResources.get('landscape'));
  1194. formatDiv.appendChild(landscapeSpan)
  1195. var customDiv = document.createElement('div');
  1196. customDiv.style.marginLeft = '4px';
  1197. customDiv.style.width = '210px';
  1198. customDiv.style.height = '24px';
  1199. var widthInput = document.createElement('input');
  1200. widthInput.setAttribute('size', '7');
  1201. widthInput.setAttribute('value', pageFormat.width);
  1202. widthInput.style.textAlign = 'right';
  1203. customDiv.appendChild(widthInput);
  1204. mxUtils.write(customDiv, ' in x ');
  1205. var heightInput = document.createElement('input');
  1206. heightInput.setAttribute('size', '7');
  1207. heightInput.setAttribute('value', pageFormat.height);
  1208. heightInput.style.textAlign = 'right';
  1209. customDiv.appendChild(heightInput);
  1210. mxUtils.write(customDiv, ' in');
  1211. formatDiv.style.display = 'none';
  1212. customDiv.style.display = 'none';
  1213. var pf = new Object();
  1214. var formats = PageSetupDialog.getFormats();
  1215. for (var i = 0; i < formats.length; i++)
  1216. {
  1217. var f = formats[i];
  1218. pf[f.key] = f;
  1219. var paperSizeOption = document.createElement('option');
  1220. paperSizeOption.setAttribute('value', f.key);
  1221. mxUtils.write(paperSizeOption, f.title);
  1222. paperSizeSelect.appendChild(paperSizeOption);
  1223. }
  1224. var customSize = false;
  1225. function listener(sender, evt, force)
  1226. {
  1227. if (force || (widthInput != document.activeElement && heightInput != document.activeElement))
  1228. {
  1229. var detected = false;
  1230. for (var i = 0; i < formats.length; i++)
  1231. {
  1232. var f = formats[i];
  1233. // Special case where custom was chosen
  1234. if (customSize)
  1235. {
  1236. if (f.key == 'custom')
  1237. {
  1238. paperSizeSelect.value = f.key;
  1239. customSize = false;
  1240. }
  1241. }
  1242. else if (f.format != null)
  1243. {
  1244. // Fixes wrong values for previous A4 and A5 page sizes
  1245. if (f.key == 'a4')
  1246. {
  1247. if (pageFormat.width == 826)
  1248. {
  1249. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1250. pageFormat.width = 827;
  1251. }
  1252. else if (pageFormat.height == 826)
  1253. {
  1254. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1255. pageFormat.height = 827;
  1256. }
  1257. }
  1258. else if (f.key == 'a5')
  1259. {
  1260. if (pageFormat.width == 584)
  1261. {
  1262. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1263. pageFormat.width = 583;
  1264. }
  1265. else if (pageFormat.height == 584)
  1266. {
  1267. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1268. pageFormat.height = 583;
  1269. }
  1270. }
  1271. if (pageFormat.width == f.format.width && pageFormat.height == f.format.height)
  1272. {
  1273. paperSizeSelect.value = f.key;
  1274. portraitCheckBox.setAttribute('checked', 'checked');
  1275. portraitCheckBox.defaultChecked = true;
  1276. portraitCheckBox.checked = true;
  1277. landscapeCheckBox.removeAttribute('checked');
  1278. landscapeCheckBox.defaultChecked = false;
  1279. landscapeCheckBox.checked = false;
  1280. detected = true;
  1281. }
  1282. else if (pageFormat.width == f.format.height && pageFormat.height == f.format.width)
  1283. {
  1284. paperSizeSelect.value = f.key;
  1285. portraitCheckBox.removeAttribute('checked');
  1286. portraitCheckBox.defaultChecked = false;
  1287. portraitCheckBox.checked = false;
  1288. landscapeCheckBox.setAttribute('checked', 'checked');
  1289. landscapeCheckBox.defaultChecked = true;
  1290. landscapeCheckBox.checked = true;
  1291. detected = true;
  1292. }
  1293. }
  1294. }
  1295. // Selects custom format which is last in list
  1296. if (!detected)
  1297. {
  1298. widthInput.value = pageFormat.width / 100;
  1299. heightInput.value =pageFormat.height / 100;
  1300. paperSizeOption.setAttribute('selected', 'selected');
  1301. portraitCheckBox.setAttribute('checked', 'checked');
  1302. portraitCheckBox.defaultChecked = true;
  1303. formatDiv.style.display = 'none';
  1304. customDiv.style.display = '';
  1305. }
  1306. else
  1307. {
  1308. formatDiv.style.display = '';
  1309. customDiv.style.display = 'none';
  1310. }
  1311. }
  1312. };
  1313. listener();
  1314. div.appendChild(paperSizeSelect);
  1315. mxUtils.br(div);
  1316. div.appendChild(formatDiv);
  1317. div.appendChild(customDiv);
  1318. var currentPageFormat = pageFormat;
  1319. var update = function()
  1320. {
  1321. var f = pf[paperSizeSelect.value];
  1322. if (f.format != null)
  1323. {
  1324. widthInput.value = f.format.width / 100;
  1325. heightInput.value = f.format.height / 100;
  1326. customDiv.style.display = 'none';
  1327. formatDiv.style.display = '';
  1328. }
  1329. else
  1330. {
  1331. formatDiv.style.display = 'none';
  1332. customDiv.style.display = '';
  1333. }
  1334. var newPageFormat = new mxRectangle(0, 0,
  1335. Math.floor(parseFloat(widthInput.value) * 100),
  1336. Math.floor(parseFloat(heightInput.value) * 100));
  1337. if (paperSizeSelect.value != 'custom' && landscapeCheckBox.checked)
  1338. {
  1339. newPageFormat = new mxRectangle(0, 0, newPageFormat.height, newPageFormat.width);
  1340. }
  1341. if (newPageFormat.width != currentPageFormat.width || newPageFormat.height != currentPageFormat.height)
  1342. {
  1343. currentPageFormat = newPageFormat;
  1344. if (pageFormatListener != null)
  1345. {
  1346. pageFormatListener(currentPageFormat);
  1347. }
  1348. }
  1349. };
  1350. mxEvent.addListener(portraitSpan, 'click', function(evt)
  1351. {
  1352. portraitCheckBox.checked = true;
  1353. update();
  1354. mxEvent.consume(evt);
  1355. });
  1356. mxEvent.addListener(landscapeSpan, 'click', function(evt)
  1357. {
  1358. landscapeCheckBox.checked = true;
  1359. update();
  1360. mxEvent.consume(evt);
  1361. });
  1362. mxEvent.addListener(widthInput, 'blur', update);
  1363. mxEvent.addListener(widthInput, 'click', update);
  1364. mxEvent.addListener(heightInput, 'blur', update);
  1365. mxEvent.addListener(heightInput, 'click', update);
  1366. mxEvent.addListener(landscapeCheckBox, 'change', update);
  1367. mxEvent.addListener(portraitCheckBox, 'change', update);
  1368. mxEvent.addListener(paperSizeSelect, 'change', function()
  1369. {
  1370. // Handles special case where custom was chosen
  1371. customSize = paperSizeSelect.value == 'custom';
  1372. update();
  1373. });
  1374. update();
  1375. return {set: function(value)
  1376. {
  1377. pageFormat = value;
  1378. listener(null, null, true);
  1379. },get: function()
  1380. {
  1381. return currentPageFormat;
  1382. }, widthInput: widthInput,
  1383. heightInput: heightInput};
  1384. };
  1385. /**
  1386. *
  1387. */
  1388. PageSetupDialog.getFormats = function()
  1389. {
  1390. return [{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT},
  1391. {key: 'legal', title: 'US-Legal (8,5" x 14")', format: new mxRectangle(0, 0, 850, 1400)},
  1392. {key: 'tabloid', title: 'US-Tabloid (279 mm x 432 mm)', format: new mxRectangle(0, 0, 1100, 1700)},
  1393. {key: 'a0', title: 'A0 (841 mm x 1189 mm)', format: new mxRectangle(0, 0, 3300, 4681)},
  1394. {key: 'a1', title: 'A1 (594 mm x 841 mm)', format: new mxRectangle(0, 0, 2339, 3300)},
  1395. {key: 'a2', title: 'A2 (420 mm x 594 mm)', format: new mxRectangle(0, 0, 1654, 2336)},
  1396. {key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1654)},
  1397. {key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT},
  1398. {key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 583, 827)},
  1399. {key: 'a6', title: 'A6 (105 mm x 148 mm)', format: new mxRectangle(0, 0, 413, 583)},
  1400. {key: 'a7', title: 'A7 (74 mm x 105 mm)', format: new mxRectangle(0, 0, 291, 413)},
  1401. {key: 'custom', title: mxResources.get('custom'), format: null}];
  1402. };
  1403. /**
  1404. * Static overrides
  1405. */
  1406. (function()
  1407. {
  1408. // Uses HTML for background pages (to support grid background image)
  1409. mxGraphView.prototype.validateBackgroundPage = function()
  1410. {
  1411. var graph = this.graph;
  1412. if (graph.container != null && !graph.transparentBackground)
  1413. {
  1414. if (graph.pageVisible)
  1415. {
  1416. var bounds = this.getBackgroundPageBounds();
  1417. if (this.backgroundPageShape == null)
  1418. {
  1419. // Finds first element in graph container
  1420. var firstChild = graph.container.firstChild;
  1421. while (firstChild != null && firstChild.nodeType != mxConstants.NODETYPE_ELEMENT)
  1422. {
  1423. firstChild = firstChild.nextSibling;
  1424. }
  1425. if (firstChild != null)
  1426. {
  1427. this.backgroundPageShape = this.createBackgroundPageShape(bounds);
  1428. this.backgroundPageShape.scale = 1;
  1429. // Shadow filter causes problems in outline window in quirks mode. IE8 standards
  1430. // also has known rendering issues inside mxWindow but not using shadow is worse.
  1431. this.backgroundPageShape.isShadow = !mxClient.IS_QUIRKS;
  1432. this.backgroundPageShape.dialect = mxConstants.DIALECT_STRICTHTML;
  1433. this.backgroundPageShape.init(graph.container);
  1434. // Required for the browser to render the background page in correct order
  1435. firstChild.style.position = 'absolute';
  1436. graph.container.insertBefore(this.backgroundPageShape.node, firstChild);
  1437. this.backgroundPageShape.redraw();
  1438. this.backgroundPageShape.node.className = 'geBackgroundPage';
  1439. // Adds listener for double click handling on background
  1440. mxEvent.addListener(this.backgroundPageShape.node, 'dblclick',
  1441. mxUtils.bind(this, function(evt)
  1442. {
  1443. graph.dblClick(evt);
  1444. })
  1445. );
  1446. // Adds basic listeners for graph event dispatching outside of the
  1447. // container and finishing the handling of a single gesture
  1448. mxEvent.addGestureListeners(this.backgroundPageShape.node,
  1449. mxUtils.bind(this, function(evt)
  1450. {
  1451. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt));
  1452. }),
  1453. mxUtils.bind(this, function(evt)
  1454. {
  1455. // Hides the tooltip if mouse is outside container
  1456. if (graph.tooltipHandler != null && graph.tooltipHandler.isHideOnHover())
  1457. {
  1458. graph.tooltipHandler.hide();
  1459. }
  1460. if (graph.isMouseDown && !mxEvent.isConsumed(evt))
  1461. {
  1462. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt));
  1463. }
  1464. }),
  1465. mxUtils.bind(this, function(evt)
  1466. {
  1467. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  1468. })
  1469. );
  1470. }
  1471. }
  1472. else
  1473. {
  1474. this.backgroundPageShape.scale = 1;
  1475. this.backgroundPageShape.bounds = bounds;
  1476. this.backgroundPageShape.redraw();
  1477. }
  1478. }
  1479. else if (this.backgroundPageShape != null)
  1480. {
  1481. this.backgroundPageShape.destroy();
  1482. this.backgroundPageShape = null;
  1483. }
  1484. this.validateBackgroundStyles();
  1485. }
  1486. };
  1487. // Updates the CSS of the background to draw the grid
  1488. mxGraphView.prototype.validateBackgroundStyles = function()
  1489. {
  1490. var graph = this.graph;
  1491. var color = (graph.background == null || graph.background == mxConstants.NONE) ? '#ffffff' : graph.background;
  1492. var gridColor = (this.gridColor != color.toLowerCase()) ? this.gridColor : '#ffffff';
  1493. var image = 'none';
  1494. var position = '';
  1495. if (graph.isGridEnabled())
  1496. {
  1497. var phase = 10;
  1498. if (mxClient.IS_SVG)
  1499. {
  1500. // Generates the SVG required for drawing the dynamic grid
  1501. image = unescape(encodeURIComponent(this.createSvgGrid(gridColor)));
  1502. image = (window.btoa) ? btoa(image) : Base64.encode(image, true);
  1503. image = 'url(' + 'data:image/svg+xml;base64,' + image + ')'
  1504. phase = graph.gridSize * this.scale * this.gridSteps;
  1505. }
  1506. else
  1507. {
  1508. // Fallback to grid wallpaper with fixed size
  1509. image = 'url(' + this.gridImage + ')';
  1510. }
  1511. var x0 = 0;
  1512. var y0 = 0;
  1513. if (graph.view.backgroundPageShape != null)
  1514. {
  1515. var bds = this.getBackgroundPageBounds();
  1516. x0 = 1 + bds.x;
  1517. y0 = 1 + bds.y;
  1518. }
  1519. // Computes the offset to maintain origin for grid
  1520. position = -Math.round(phase - mxUtils.mod(this.translate.x * this.scale - x0, phase)) + 'px ' +
  1521. -Math.round(phase - mxUtils.mod(this.translate.y * this.scale - y0, phase)) + 'px';
  1522. }
  1523. var canvas = graph.view.canvas;
  1524. if (canvas.ownerSVGElement != null)
  1525. {
  1526. canvas = canvas.ownerSVGElement;
  1527. }
  1528. if (graph.view.backgroundPageShape != null)
  1529. {
  1530. graph.view.backgroundPageShape.node.style.backgroundPosition = position;
  1531. graph.view.backgroundPageShape.node.style.backgroundImage = image;
  1532. graph.view.backgroundPageShape.node.style.backgroundColor = color;
  1533. graph.container.className = 'geDiagramContainer geDiagramBackdrop';
  1534. canvas.style.backgroundImage = 'none';
  1535. canvas.style.backgroundColor = '';
  1536. }
  1537. else
  1538. {
  1539. graph.container.className = 'geDiagramContainer';
  1540. canvas.style.backgroundPosition = position;
  1541. canvas.style.backgroundColor = color;
  1542. canvas.style.backgroundImage = image;
  1543. }
  1544. };
  1545. // Returns the SVG required for painting the background grid.
  1546. mxGraphView.prototype.createSvgGrid = function(color)
  1547. {
  1548. var tmp = this.graph.gridSize * this.scale;
  1549. while (tmp < this.minGridSize)
  1550. {
  1551. tmp *= 2;
  1552. }
  1553. var tmp2 = this.gridSteps * tmp;
  1554. // Small grid lines
  1555. var d = [];
  1556. for (var i = 1; i < this.gridSteps; i++)
  1557. {
  1558. var tmp3 = i * tmp;
  1559. d.push('M 0 ' + tmp3 + ' L ' + tmp2 + ' ' + tmp3 + ' M ' + tmp3 + ' 0 L ' + tmp3 + ' ' + tmp2);
  1560. }
  1561. // KNOWN: Rounding errors for certain scales (eg. 144%, 121% in Chrome, FF and Safari). Workaround
  1562. // in Chrome is to use 100% for the svg size, but this results in blurred grid for large diagrams.
  1563. var size = tmp2;
  1564. var svg = '<svg width="' + size + '" height="' + size + '" xmlns="' + mxConstants.NS_SVG + '">' +
  1565. '<defs><pattern id="grid" width="' + tmp2 + '" height="' + tmp2 + '" patternUnits="userSpaceOnUse">' +
  1566. '<path d="' + d.join(' ') + '" fill="none" stroke="' + color + '" opacity="0.2" stroke-width="1"/>' +
  1567. '<path d="M ' + tmp2 + ' 0 L 0 0 0 ' + tmp2 + '" fill="none" stroke="' + color + '" stroke-width="1"/>' +
  1568. '</pattern></defs><rect width="100%" height="100%" fill="url(#grid)"/></svg>';
  1569. return svg;
  1570. };
  1571. // Adds panning for the grid with no page view and disabled scrollbars
  1572. var mxGraphPanGraph = mxGraph.prototype.panGraph;
  1573. mxGraph.prototype.panGraph = function(dx, dy)
  1574. {
  1575. mxGraphPanGraph.apply(this, arguments);
  1576. if (this.shiftPreview1 != null)
  1577. {
  1578. var canvas = this.view.canvas;
  1579. if (canvas.ownerSVGElement != null)
  1580. {
  1581. canvas = canvas.ownerSVGElement;
  1582. }
  1583. var phase = this.gridSize * this.view.scale * this.view.gridSteps;
  1584. var position = -Math.round(phase - mxUtils.mod(this.view.translate.x * this.view.scale + dx, phase)) + 'px ' +
  1585. -Math.round(phase - mxUtils.mod(this.view.translate.y * this.view.scale + dy, phase)) + 'px';
  1586. canvas.style.backgroundPosition = position;
  1587. }
  1588. };
  1589. // Draws page breaks only within the page
  1590. mxGraph.prototype.updatePageBreaks = function(visible, width, height)
  1591. {
  1592. var scale = this.view.scale;
  1593. var tr = this.view.translate;
  1594. var fmt = this.pageFormat;
  1595. var ps = scale * this.pageScale;
  1596. var bounds2 = this.view.getBackgroundPageBounds();
  1597. width = bounds2.width;
  1598. height = bounds2.height;
  1599. var bounds = new mxRectangle(scale * tr.x, scale * tr.y, fmt.width * ps, fmt.height * ps);
  1600. // Does not show page breaks if the scale is too small
  1601. visible = visible && Math.min(bounds.width, bounds.height) > this.minPageBreakDist;
  1602. var horizontalCount = (visible) ? Math.ceil(height / bounds.height) - 1 : 0;
  1603. var verticalCount = (visible) ? Math.ceil(width / bounds.width) - 1 : 0;
  1604. var right = bounds2.x + width;
  1605. var bottom = bounds2.y + height;
  1606. if (this.horizontalPageBreaks == null && horizontalCount > 0)
  1607. {
  1608. this.horizontalPageBreaks = [];
  1609. }
  1610. if (this.verticalPageBreaks == null && verticalCount > 0)
  1611. {
  1612. this.verticalPageBreaks = [];
  1613. }
  1614. var drawPageBreaks = mxUtils.bind(this, function(breaks)
  1615. {
  1616. if (breaks != null)
  1617. {
  1618. var count = (breaks == this.horizontalPageBreaks) ? horizontalCount : verticalCount;
  1619. for (var i = 0; i <= count; i++)
  1620. {
  1621. var pts = (breaks == this.horizontalPageBreaks) ?
  1622. [new mxPoint(Math.round(bounds2.x), Math.round(bounds2.y + (i + 1) * bounds.height)),
  1623. new mxPoint(Math.round(right), Math.round(bounds2.y + (i + 1) * bounds.height))] :
  1624. [new mxPoint(Math.round(bounds2.x + (i + 1) * bounds.width), Math.round(bounds2.y)),
  1625. new mxPoint(Math.round(bounds2.x + (i + 1) * bounds.width), Math.round(bottom))];
  1626. if (breaks[i] != null)
  1627. {
  1628. breaks[i].points = pts;
  1629. breaks[i].redraw();
  1630. }
  1631. else
  1632. {
  1633. var pageBreak = new mxPolyline(pts, this.pageBreakColor);
  1634. pageBreak.dialect = this.dialect;
  1635. pageBreak.isDashed = this.pageBreakDashed;
  1636. pageBreak.pointerEvents = false;
  1637. pageBreak.init(this.view.backgroundPane);
  1638. pageBreak.redraw();
  1639. breaks[i] = pageBreak;
  1640. }
  1641. }
  1642. for (var i = count; i < breaks.length; i++)
  1643. {
  1644. breaks[i].destroy();
  1645. }
  1646. breaks.splice(count, breaks.length - count);
  1647. }
  1648. });
  1649. drawPageBreaks(this.horizontalPageBreaks);
  1650. drawPageBreaks(this.verticalPageBreaks);
  1651. };
  1652. // Disables removing relative children from parents
  1653. var mxGraphHandlerShouldRemoveCellsFromParent = mxGraphHandler.prototype.shouldRemoveCellsFromParent;
  1654. mxGraphHandler.prototype.shouldRemoveCellsFromParent = function(parent, cells, evt)
  1655. {
  1656. for (var i = 0; i < cells.length; i++)
  1657. {
  1658. if (this.graph.getModel().isVertex(cells[i]))
  1659. {
  1660. var geo = this.graph.getCellGeometry(cells[i]);
  1661. if (geo != null && geo.relative)
  1662. {
  1663. return false;
  1664. }
  1665. }
  1666. }
  1667. return mxGraphHandlerShouldRemoveCellsFromParent.apply(this, arguments);
  1668. };
  1669. // Overrides to ignore hotspot only for target terminal
  1670. var mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
  1671. mxConnectionHandler.prototype.createMarker = function()
  1672. {
  1673. var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);
  1674. marker.intersects = mxUtils.bind(this, function(state, evt)
  1675. {
  1676. if (this.isConnecting())
  1677. {
  1678. return true;
  1679. }
  1680. return mxCellMarker.prototype.intersects.apply(marker, arguments);
  1681. });
  1682. return marker;
  1683. };
  1684. // Creates background page shape
  1685. mxGraphView.prototype.createBackgroundPageShape = function(bounds)
  1686. {
  1687. return new mxRectangleShape(bounds, '#ffffff', '#cacaca');
  1688. };
  1689. // Fits the number of background pages to the graph
  1690. mxGraphView.prototype.getBackgroundPageBounds = function()
  1691. {
  1692. var gb = this.getGraphBounds();
  1693. // Computes unscaled, untranslated graph bounds
  1694. var x = (gb.width > 0) ? gb.x / this.scale - this.translate.x : 0;
  1695. var y = (gb.height > 0) ? gb.y / this.scale - this.translate.y : 0;
  1696. var w = gb.width / this.scale;
  1697. var h = gb.height / this.scale;
  1698. var fmt = this.graph.pageFormat;
  1699. var ps = this.graph.pageScale;
  1700. var pw = fmt.width * ps;
  1701. var ph = fmt.height * ps;
  1702. var x0 = Math.floor(Math.min(0, x) / pw);
  1703. var y0 = Math.floor(Math.min(0, y) / ph);
  1704. var xe = Math.ceil(Math.max(1, x + w) / pw);
  1705. var ye = Math.ceil(Math.max(1, y + h) / ph);
  1706. var rows = xe - x0;
  1707. var cols = ye - y0;
  1708. var bounds = new mxRectangle(this.scale * (this.translate.x + x0 * pw), this.scale *
  1709. (this.translate.y + y0 * ph), this.scale * rows * pw, this.scale * cols * ph);
  1710. return bounds;
  1711. };
  1712. // Add panning for background page in VML
  1713. var graphPanGraph = mxGraph.prototype.panGraph;
  1714. mxGraph.prototype.panGraph = function(dx, dy)
  1715. {
  1716. graphPanGraph.apply(this, arguments);
  1717. if ((this.dialect != mxConstants.DIALECT_SVG && this.view.backgroundPageShape != null) &&
  1718. (!this.useScrollbarsForPanning || !mxUtils.hasScrollbars(this.container)))
  1719. {
  1720. this.view.backgroundPageShape.node.style.marginLeft = dx + 'px';
  1721. this.view.backgroundPageShape.node.style.marginTop = dy + 'px';
  1722. }
  1723. };
  1724. /**
  1725. * Consumes click events for disabled menu items.
  1726. */
  1727. var mxPopupMenuAddItem = mxPopupMenu.prototype.addItem;
  1728. mxPopupMenu.prototype.addItem = function(title, image, funct, parent, iconCls, enabled)
  1729. {
  1730. var result = mxPopupMenuAddItem.apply(this, arguments);
  1731. if (enabled != null && !enabled)
  1732. {
  1733. mxEvent.addListener(result, 'mousedown', function(evt)
  1734. {
  1735. mxEvent.consume(evt);
  1736. });
  1737. }
  1738. return result;
  1739. };
  1740. // Selects ancestors before descendants
  1741. var graphHandlerGetInitialCellForEvent = mxGraphHandler.prototype.getInitialCellForEvent;
  1742. mxGraphHandler.prototype.getInitialCellForEvent = function(me)
  1743. {
  1744. var model = this.graph.getModel();
  1745. var psel = model.getParent(this.graph.getSelectionCell());
  1746. var cell = graphHandlerGetInitialCellForEvent.apply(this, arguments);
  1747. var parent = model.getParent(cell);
  1748. if (psel == null || (psel != cell && psel != parent))
  1749. {
  1750. while (!this.graph.isCellSelected(cell) && !this.graph.isCellSelected(parent) &&
  1751. model.isVertex(parent) && !this.graph.isContainer(parent))
  1752. {
  1753. cell = parent;
  1754. parent = this.graph.getModel().getParent(cell);
  1755. }
  1756. }
  1757. return cell;
  1758. };
  1759. // Selection is delayed to mouseup if ancestor is selected
  1760. var graphHandlerIsDelayedSelection = mxGraphHandler.prototype.isDelayedSelection;
  1761. mxGraphHandler.prototype.isDelayedSelection = function(cell, me)
  1762. {
  1763. var result = graphHandlerIsDelayedSelection.apply(this, arguments);
  1764. if (!result)
  1765. {
  1766. var model = this.graph.getModel();
  1767. var parent = model.getParent(cell);
  1768. while (parent != null)
  1769. {
  1770. // Inconsistency for unselected parent swimlane is intended for easier moving
  1771. // of stack layouts where the container title section is too far away
  1772. if (this.graph.isCellSelected(parent) && model.isVertex(parent))
  1773. {
  1774. result = true;
  1775. break;
  1776. }
  1777. parent = model.getParent(parent);
  1778. }
  1779. }
  1780. return result;
  1781. };
  1782. // Delayed selection of parent group
  1783. mxGraphHandler.prototype.selectDelayed = function(me)
  1784. {
  1785. if (!this.graph.popupMenuHandler.isPopupTrigger(me))
  1786. {
  1787. var cell = me.getCell();
  1788. if (cell == null)
  1789. {
  1790. cell = this.cell;
  1791. }
  1792. // Selects folded cell for hit on folding icon
  1793. var state = this.graph.view.getState(cell)
  1794. if (state != null && me.isSource(state.control))
  1795. {
  1796. this.graph.selectCellForEvent(cell, me.getEvent());
  1797. }
  1798. else
  1799. {
  1800. var model = this.graph.getModel();
  1801. var parent = model.getParent(cell);
  1802. while (!this.graph.isCellSelected(parent) && model.isVertex(parent))
  1803. {
  1804. cell = parent;
  1805. parent = model.getParent(cell);
  1806. }
  1807. this.graph.selectCellForEvent(cell, me.getEvent());
  1808. }
  1809. }
  1810. };
  1811. // Returns last selected ancestor
  1812. mxPopupMenuHandler.prototype.getCellForPopupEvent = function(me)
  1813. {
  1814. var cell = me.getCell();
  1815. var model = this.graph.getModel();
  1816. var parent = model.getParent(cell);
  1817. while (model.isVertex(parent) && !this.graph.isContainer(parent))
  1818. {
  1819. if (this.graph.isCellSelected(parent))
  1820. {
  1821. cell = parent;
  1822. }
  1823. parent = model.getParent(parent);
  1824. }
  1825. return cell;
  1826. };
  1827. })();