EditorUi.js 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Constructs a new graph editor
  6. */
  7. EditorUi = function(editor, container, lightbox)
  8. {
  9. mxEventSource.call(this);
  10. this.destroyFunctions = [];
  11. this.editor = editor || new Editor();
  12. this.container = container || document.body;
  13. var graph = this.editor.graph;
  14. graph.lightbox = lightbox;
  15. // Pre-fetches submenu image or replaces with embedded image if supported
  16. if (mxClient.IS_SVG)
  17. {
  18. mxPopupMenu.prototype.submenuImage = 'data:image/gif;base64,R0lGODlhCQAJAIAAAP///zMzMyH5BAEAAAAALAAAAAAJAAkAAAIPhI8WebHsHopSOVgb26AAADs=';
  19. }
  20. else
  21. {
  22. new Image().src = mxPopupMenu.prototype.submenuImage;
  23. }
  24. // Pre-fetches connect image
  25. if (!mxClient.IS_SVG && mxConnectionHandler.prototype.connectImage != null)
  26. {
  27. new Image().src = mxConnectionHandler.prototype.connectImage.src;
  28. }
  29. // Disables graph and forced panning in chromeless mode
  30. if (this.editor.chromeless)
  31. {
  32. this.footerHeight = 0;
  33. graph.isEnabled = function() { return false; };
  34. graph.panningHandler.isForcePanningEvent = function(me)
  35. {
  36. return !mxEvent.isPopupTrigger(me.getEvent());
  37. };
  38. }
  39. // Creates the user interface
  40. this.actions = new Actions(this);
  41. this.menus = this.createMenus();
  42. this.createDivs();
  43. this.createUi();
  44. this.refresh();
  45. // Disables HTML and text selection
  46. var textEditing = mxUtils.bind(this, function(evt)
  47. {
  48. if (evt == null)
  49. {
  50. evt = window.event;
  51. }
  52. return this.isSelectionAllowed(evt) || graph.isEditing();
  53. });
  54. // Disables text selection while not editing and no dialog visible
  55. if (this.container == document.body)
  56. {
  57. this.menubarContainer.onselectstart = textEditing;
  58. this.menubarContainer.onmousedown = textEditing;
  59. this.toolbarContainer.onselectstart = textEditing;
  60. this.toolbarContainer.onmousedown = textEditing;
  61. this.diagramContainer.onselectstart = textEditing;
  62. this.diagramContainer.onmousedown = textEditing;
  63. this.sidebarContainer.onselectstart = textEditing;
  64. this.sidebarContainer.onmousedown = textEditing;
  65. this.formatContainer.onselectstart = textEditing;
  66. this.formatContainer.onmousedown = textEditing;
  67. this.footerContainer.onselectstart = textEditing;
  68. this.footerContainer.onmousedown = textEditing;
  69. if (this.tabContainer != null)
  70. {
  71. // Mouse down is needed for drag and drop
  72. this.tabContainer.onselectstart = textEditing;
  73. }
  74. }
  75. // And uses built-in context menu while editing
  76. if (!this.editor.chromeless)
  77. {
  78. if (mxClient.IS_IE && (typeof(document.documentMode) === 'undefined' || document.documentMode < 9))
  79. {
  80. mxEvent.addListener(this.diagramContainer, 'contextmenu', textEditing);
  81. }
  82. else
  83. {
  84. // Allows browser context menu outside of diagram and sidebar
  85. this.diagramContainer.oncontextmenu = textEditing;
  86. }
  87. }
  88. else
  89. {
  90. graph.panningHandler.usePopupTrigger = false;
  91. }
  92. // Contains the main graph instance inside the given panel
  93. graph.init(this.diagramContainer);
  94. // Creates hover icons
  95. this.hoverIcons = this.createHoverIcons();
  96. // Adds tooltip when mouse is over scrollbars to show space-drag panning option
  97. mxEvent.addListener(this.diagramContainer, 'mousemove', mxUtils.bind(this, function(evt)
  98. {
  99. var off = mxUtils.getOffset(this.diagramContainer);
  100. if (mxEvent.getClientX(evt) - off.x - this.diagramContainer.clientWidth > 0 ||
  101. mxEvent.getClientY(evt) - off.y - this.diagramContainer.clientHeight > 0)
  102. {
  103. this.diagramContainer.setAttribute('title', mxResources.get('panTooltip'));
  104. }
  105. else
  106. {
  107. this.diagramContainer.removeAttribute('title');
  108. }
  109. }));
  110. // Escape key hides dialogs, adds space+drag panning
  111. var spaceKeyPressed = false;
  112. // Overrides hovericons to disable while space key is pressed
  113. var hoverIconsIsResetEvent = this.hoverIcons.isResetEvent;
  114. this.hoverIcons.isResetEvent = function(evt, allowShift)
  115. {
  116. return spaceKeyPressed || hoverIconsIsResetEvent.apply(this, arguments);
  117. };
  118. this.keydownHandler = mxUtils.bind(this, function(evt)
  119. {
  120. if (evt.which == 32 /* Space */)
  121. {
  122. spaceKeyPressed = true;
  123. this.hoverIcons.reset();
  124. graph.container.style.cursor = 'move';
  125. // Disables scroll after space keystroke with scrollbars
  126. if (!graph.isEditing() && mxEvent.getSource(evt) == graph.container)
  127. {
  128. mxEvent.consume(evt);
  129. }
  130. }
  131. else if (!mxEvent.isConsumed(evt) && evt.keyCode == 27 /* Escape */)
  132. {
  133. this.hideDialog();
  134. }
  135. });
  136. mxEvent.addListener(document, 'keydown', this.keydownHandler);
  137. this.keyupHandler = mxUtils.bind(this, function(evt)
  138. {
  139. graph.container.style.cursor = '';
  140. spaceKeyPressed = false;
  141. });
  142. mxEvent.addListener(document, 'keyup', this.keyupHandler);
  143. // Forces panning for middle and right mouse buttons
  144. var panningHandlerIsForcePanningEvent = graph.panningHandler.isForcePanningEvent;
  145. graph.panningHandler.isForcePanningEvent = function(me)
  146. {
  147. // Ctrl+left button is reported as right button in FF on Mac
  148. return panningHandlerIsForcePanningEvent.apply(this, arguments) ||
  149. spaceKeyPressed || (mxEvent.isMouseEvent(me.getEvent()) &&
  150. (this.usePopupTrigger || !mxEvent.isPopupTrigger(me.getEvent())) &&
  151. ((!mxEvent.isControlDown(me.getEvent()) &&
  152. mxEvent.isRightMouseButton(me.getEvent())) ||
  153. mxEvent.isMiddleMouseButton(me.getEvent())));
  154. };
  155. // Ctrl/Cmd+Enter applies editing value except in Safari where Ctrl+Enter creates
  156. // a new line (while Enter creates a new paragraph and Shift+Enter stops)
  157. var cellEditorIsStopEditingEvent = graph.cellEditor.isStopEditingEvent;
  158. graph.cellEditor.isStopEditingEvent = function(evt)
  159. {
  160. return cellEditorIsStopEditingEvent.apply(this, arguments) ||
  161. (evt.keyCode == 13 && ((!mxClient.IS_SF && mxEvent.isControlDown(evt)) ||
  162. (mxClient.IS_MAC && mxEvent.isMetaDown(evt)) ||
  163. (mxClient.IS_SF && mxEvent.isShiftDown(evt))));
  164. };
  165. // Switches toolbar for text editing
  166. var textMode = false;
  167. var fontMenu = null;
  168. var sizeMenu = null;
  169. var nodes = null;
  170. var updateToolbar = mxUtils.bind(this, function()
  171. {
  172. if (textMode != graph.cellEditor.isContentEditing())
  173. {
  174. var node = this.toolbar.container.firstChild;
  175. var newNodes = [];
  176. while (node != null)
  177. {
  178. var tmp = node.nextSibling;
  179. if (mxUtils.indexOf(this.toolbar.staticElements, node) < 0)
  180. {
  181. node.parentNode.removeChild(node);
  182. newNodes.push(node);
  183. }
  184. node = tmp;
  185. }
  186. // Saves references to special items
  187. var tmp1 = this.toolbar.fontMenu;
  188. var tmp2 = this.toolbar.sizeMenu;
  189. if (nodes == null)
  190. {
  191. this.toolbar.createTextToolbar();
  192. }
  193. else
  194. {
  195. for (var i = 0; i < nodes.length; i++)
  196. {
  197. this.toolbar.container.appendChild(nodes[i]);
  198. }
  199. // Restores references to special items
  200. this.toolbar.fontMenu = fontMenu;
  201. this.toolbar.sizeMenu = sizeMenu;
  202. }
  203. textMode = graph.cellEditor.isContentEditing();
  204. fontMenu = tmp1;
  205. sizeMenu = tmp2;
  206. nodes = newNodes;
  207. }
  208. });
  209. var ui = this;
  210. // Overrides cell editor to update toolbar
  211. var cellEditorStartEditing = graph.cellEditor.startEditing;
  212. graph.cellEditor.startEditing = function()
  213. {
  214. cellEditorStartEditing.apply(this, arguments);
  215. updateToolbar();
  216. if (graph.cellEditor.isContentEditing())
  217. {
  218. var updating = false;
  219. var updateCssHandler = function()
  220. {
  221. if (!updating)
  222. {
  223. updating = true;
  224. window.setTimeout(function()
  225. {
  226. var selectedElement = graph.getSelectedElement();
  227. var node = selectedElement;
  228. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  229. {
  230. node = node.parentNode;
  231. }
  232. if (node != null)
  233. {
  234. var css = mxUtils.getCurrentStyle(node);
  235. if (css != null && ui.toolbar != null)
  236. {
  237. // Strips leading and trailing quotes
  238. var ff = css.fontFamily;
  239. if (ff.charAt(0) == '\'')
  240. {
  241. ff = ff.substring(1);
  242. }
  243. if (ff.charAt(ff.length - 1) == '\'')
  244. {
  245. ff = ff.substring(0, ff.length - 1);
  246. }
  247. ui.toolbar.setFontName(ff);
  248. ui.toolbar.setFontSize(parseInt(css.fontSize));
  249. }
  250. }
  251. updating = false;
  252. }, 0);
  253. }
  254. };
  255. mxEvent.addListener(graph.cellEditor.textarea, 'input', updateCssHandler)
  256. mxEvent.addListener(graph.cellEditor.textarea, 'touchend', updateCssHandler);
  257. mxEvent.addListener(graph.cellEditor.textarea, 'mouseup', updateCssHandler);
  258. mxEvent.addListener(graph.cellEditor.textarea, 'keyup', updateCssHandler);
  259. updateCssHandler();
  260. }
  261. };
  262. var cellEditorStopEditing = graph.cellEditor.stopEditing;
  263. graph.cellEditor.stopEditing = function(cell, trigger)
  264. {
  265. cellEditorStopEditing.apply(this, arguments);
  266. updateToolbar();
  267. };
  268. // Enables scrollbars and sets cursor style for the container
  269. graph.container.setAttribute('tabindex', '0');
  270. graph.container.style.cursor = 'default';
  271. // Workaround for page scroll if embedded via iframe
  272. if (window.self === window.top && graph.container.parentNode != null)
  273. {
  274. graph.container.focus();
  275. }
  276. // Keeps graph container focused on mouse down
  277. var graphFireMouseEvent = graph.fireMouseEvent;
  278. graph.fireMouseEvent = function(evtName, me, sender)
  279. {
  280. if (evtName == mxEvent.MOUSE_DOWN)
  281. {
  282. this.container.focus();
  283. }
  284. graphFireMouseEvent.apply(this, arguments);
  285. };
  286. // Configures automatic expand on mouseover
  287. graph.popupMenuHandler.autoExpand = true;
  288. // Installs context menu
  289. if (this.menus != null)
  290. {
  291. graph.popupMenuHandler.factoryMethod = mxUtils.bind(this, function(menu, cell, evt)
  292. {
  293. this.menus.createPopupMenu(menu, cell, evt);
  294. });
  295. }
  296. // Hides context menu
  297. mxEvent.addGestureListeners(document, mxUtils.bind(this, function(evt)
  298. {
  299. graph.popupMenuHandler.hideMenu();
  300. }));
  301. // Create handler for key events
  302. this.keyHandler = this.createKeyHandler(editor);
  303. // Getter for key handler
  304. this.getKeyHandler = function()
  305. {
  306. return keyHandler;
  307. };
  308. // Stores the current style and assigns it to new cells
  309. var styles = ['rounded', 'shadow', 'glass', 'dashed', 'dashPattern', 'comic', 'labelBackgroundColor'];
  310. var connectStyles = ['shape', 'edgeStyle', 'curved', 'rounded', 'elbow', 'comic'];
  311. // Note: Everything that is not in styles is ignored (styles is augmented below)
  312. this.setDefaultStyle = function(cell)
  313. {
  314. var state = graph.view.getState(cell);
  315. if (state != null)
  316. {
  317. // Ignores default styles
  318. var clone = cell.clone();
  319. clone.style = ''
  320. var defaultStyle = graph.getCellStyle(clone);
  321. var values = [];
  322. var keys = [];
  323. for (var key in state.style)
  324. {
  325. if (defaultStyle[key] != state.style[key])
  326. {
  327. values.push(state.style[key]);
  328. keys.push(key);
  329. }
  330. }
  331. // Handles special case for value "none"
  332. var cellStyle = graph.getModel().getStyle(state.cell);
  333. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  334. for (var i = 0; i < tokens.length; i++)
  335. {
  336. var tmp = tokens[i];
  337. var pos = tmp.indexOf('=');
  338. if (pos >= 0)
  339. {
  340. var key = tmp.substring(0, pos);
  341. var value = tmp.substring(pos + 1);
  342. if (defaultStyle[key] != null && value == 'none')
  343. {
  344. values.push(value);
  345. keys.push(key);
  346. }
  347. }
  348. }
  349. // Resets current style
  350. if (graph.getModel().isEdge(state.cell))
  351. {
  352. graph.currentEdgeStyle = {};
  353. }
  354. else
  355. {
  356. graph.currentVertexStyle = {}
  357. }
  358. this.fireEvent(new mxEventObject('styleChanged', 'keys', keys, 'values', values, 'cells', [state.cell]));
  359. }
  360. };
  361. this.clearDefaultStyle = function()
  362. {
  363. graph.currentEdgeStyle = graph.defaultEdgeStyle;
  364. graph.currentVertexStyle = {};
  365. // Updates UI
  366. this.fireEvent(new mxEventObject('styleChanged', 'keys', [], 'values', [], 'cells', []));
  367. };
  368. // Keys that should be ignored if the cell has a value (known: new default for all cells is html=1 so
  369. // for the html key this effecticely only works for edges inserted via the connection handler)
  370. var valueStyles = ['fontFamily', 'fontSize', 'fontColor'];
  371. // Keys that always update the current edge style regardless of selection
  372. var alwaysEdgeStyles = ['edgeStyle', 'startArrow', 'startFill', 'startSize', 'endArrow', 'endFill', 'endSize', 'jettySize', 'orthogonalLoop'];
  373. // Keys that are ignored together (if one appears all are ignored)
  374. var keyGroups = [['startArrow', 'startFill', 'startSize', 'endArrow', 'endFill', 'endSize', 'jettySize', 'orthogonalLoop'],
  375. ['strokeColor', 'strokeWidth'],
  376. ['fillColor', 'gradientColor'],
  377. valueStyles,
  378. ['align'],
  379. ['html']];
  380. // Adds all keys used above to the styles array
  381. for (var i = 0; i < keyGroups.length; i++)
  382. {
  383. for (var j = 0; j < keyGroups[i].length; j++)
  384. {
  385. styles.push(keyGroups[i][j]);
  386. }
  387. }
  388. for (var i = 0; i < connectStyles.length; i++)
  389. {
  390. styles.push(connectStyles[i]);
  391. }
  392. // Implements a global current style for edges and vertices that is applied to new cells
  393. var insertHandler = function(cells, asText)
  394. {
  395. graph.getModel().beginUpdate();
  396. try
  397. {
  398. // Applies only basic text styles
  399. if (asText)
  400. {
  401. var edge = graph.getModel().isEdge(cell);
  402. var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
  403. var textStyles = ['fontSize', 'fontFamily', 'fontColor'];
  404. for (var j = 0; j < textStyles.length; j++)
  405. {
  406. var value = current[textStyles[j]];
  407. if (value != null)
  408. {
  409. graph.setCellStyles(textStyles[j], value, cells);
  410. }
  411. }
  412. }
  413. else
  414. {
  415. for (var i = 0; i < cells.length; i++)
  416. {
  417. var cell = cells[i];
  418. // Removes styles defined in the cell style from the styles to be applied
  419. var cellStyle = graph.getModel().getStyle(cell);
  420. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  421. var appliedStyles = styles.slice();
  422. for (var j = 0; j < tokens.length; j++)
  423. {
  424. var tmp = tokens[j];
  425. var pos = tmp.indexOf('=');
  426. if (pos >= 0)
  427. {
  428. var key = tmp.substring(0, pos);
  429. var index = mxUtils.indexOf(appliedStyles, key);
  430. if (index >= 0)
  431. {
  432. appliedStyles.splice(index, 1);
  433. }
  434. // Handles special cases where one defined style ignores other styles
  435. for (var k = 0; k < keyGroups.length; k++)
  436. {
  437. var group = keyGroups[k];
  438. if (mxUtils.indexOf(group, key) >= 0)
  439. {
  440. for (var l = 0; l < group.length; l++)
  441. {
  442. var index2 = mxUtils.indexOf(appliedStyles, group[l]);
  443. if (index2 >= 0)
  444. {
  445. appliedStyles.splice(index2, 1);
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. // Applies the current style to the cell
  453. var edge = graph.getModel().isEdge(cell);
  454. var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
  455. for (var j = 0; j < appliedStyles.length; j++)
  456. {
  457. var key = appliedStyles[j];
  458. var styleValue = current[key];
  459. if (styleValue != null && (key != 'shape' || edge))
  460. {
  461. // Special case: Connect styles are not applied here but in the connection handler
  462. if (!edge || mxUtils.indexOf(connectStyles, key) < 0)
  463. {
  464. graph.setCellStyles(key, styleValue, [cell]);
  465. }
  466. }
  467. }
  468. }
  469. }
  470. }
  471. finally
  472. {
  473. graph.getModel().endUpdate();
  474. }
  475. };
  476. graph.addListener('cellsInserted', function(sender, evt)
  477. {
  478. insertHandler(evt.getProperty('cells'));
  479. });
  480. graph.addListener('textInserted', function(sender, evt)
  481. {
  482. insertHandler(evt.getProperty('cells'), true);
  483. });
  484. graph.connectionHandler.addListener(mxEvent.CONNECT, function(sender, evt)
  485. {
  486. var cells = [evt.getProperty('cell')];
  487. if (evt.getProperty('terminalInserted'))
  488. {
  489. cells.push(evt.getProperty('terminal'));
  490. }
  491. insertHandler(cells);
  492. });
  493. this.addListener('styleChanged', mxUtils.bind(this, function(sender, evt)
  494. {
  495. // Checks if edges and/or vertices were modified
  496. var cells = evt.getProperty('cells');
  497. var vertex = false;
  498. var edge = false;
  499. if (cells.length > 0)
  500. {
  501. for (var i = 0; i < cells.length; i++)
  502. {
  503. vertex = graph.getModel().isVertex(cells[i]) || vertex;
  504. edge = graph.getModel().isEdge(cells[i]) || edge;
  505. if (edge && vertex)
  506. {
  507. break;
  508. }
  509. }
  510. }
  511. else
  512. {
  513. vertex = true;
  514. edge = true;
  515. }
  516. var keys = evt.getProperty('keys');
  517. var values = evt.getProperty('values');
  518. for (var i = 0; i < keys.length; i++)
  519. {
  520. var common = mxUtils.indexOf(valueStyles, keys[i]) >= 0;
  521. // Ignores transparent stroke colors
  522. if (keys[i] != 'strokeColor' || (values[i] != null && values[i] != 'none'))
  523. {
  524. // Special case: Edge style and shape
  525. if (mxUtils.indexOf(connectStyles, keys[i]) >= 0)
  526. {
  527. if (edge || mxUtils.indexOf(alwaysEdgeStyles, keys[i]) >= 0)
  528. {
  529. if (values[i] == null)
  530. {
  531. delete graph.currentEdgeStyle[keys[i]];
  532. }
  533. else
  534. {
  535. graph.currentEdgeStyle[keys[i]] = values[i];
  536. }
  537. }
  538. // Uses style for vertex if defined in styles
  539. else if (vertex && mxUtils.indexOf(styles, keys[i]) >= 0)
  540. {
  541. if (values[i] == null)
  542. {
  543. delete graph.currentVertexStyle[keys[i]];
  544. }
  545. else
  546. {
  547. graph.currentVertexStyle[keys[i]] = values[i];
  548. }
  549. }
  550. }
  551. else if (mxUtils.indexOf(styles, keys[i]) >= 0)
  552. {
  553. if (vertex || common)
  554. {
  555. if (values[i] == null)
  556. {
  557. delete graph.currentVertexStyle[keys[i]];
  558. }
  559. else
  560. {
  561. graph.currentVertexStyle[keys[i]] = values[i];
  562. }
  563. }
  564. if (edge || common || mxUtils.indexOf(alwaysEdgeStyles, keys[i]) >= 0)
  565. {
  566. if (values[i] == null)
  567. {
  568. delete graph.currentEdgeStyle[keys[i]];
  569. }
  570. else
  571. {
  572. graph.currentEdgeStyle[keys[i]] = values[i];
  573. }
  574. }
  575. }
  576. }
  577. }
  578. if (this.toolbar != null)
  579. {
  580. this.toolbar.setFontName(graph.currentVertexStyle['fontFamily'] || Menus.prototype.defaultFont);
  581. this.toolbar.setFontSize(graph.currentVertexStyle['fontSize'] || Menus.prototype.defaultFontSize);
  582. if (this.toolbar.edgeStyleMenu != null)
  583. {
  584. // Updates toolbar icon for edge style
  585. var edgeStyleDiv = this.toolbar.edgeStyleMenu.getElementsByTagName('div')[0];
  586. if (graph.currentEdgeStyle['edgeStyle'] == 'orthogonalEdgeStyle' && graph.currentEdgeStyle['curved'] == '1')
  587. {
  588. edgeStyleDiv.className = 'geSprite geSprite-curved';
  589. }
  590. else if (graph.currentEdgeStyle['edgeStyle'] == 'straight' || graph.currentEdgeStyle['edgeStyle'] == 'none' ||
  591. graph.currentEdgeStyle['edgeStyle'] == null)
  592. {
  593. edgeStyleDiv.className = 'geSprite geSprite-straight';
  594. }
  595. else if (graph.currentEdgeStyle['edgeStyle'] == 'entityRelationEdgeStyle')
  596. {
  597. edgeStyleDiv.className = 'geSprite geSprite-entity';
  598. }
  599. else if (graph.currentEdgeStyle['edgeStyle'] == 'elbowEdgeStyle')
  600. {
  601. edgeStyleDiv.className = 'geSprite geSprite-' + ((graph.currentEdgeStyle['elbow'] == 'vertical') ?
  602. 'verticalelbow' : 'horizontalelbow');
  603. }
  604. else if (graph.currentEdgeStyle['edgeStyle'] == 'isometricEdgeStyle')
  605. {
  606. edgeStyleDiv.className = 'geSprite geSprite-' + ((graph.currentEdgeStyle['elbow'] == 'vertical') ?
  607. 'verticalisometric' : 'horizontalisometric');
  608. }
  609. else
  610. {
  611. edgeStyleDiv.className = 'geSprite geSprite-orthogonal';
  612. }
  613. }
  614. if (this.toolbar.edgeShapeMenu != null)
  615. {
  616. // Updates icon for edge shape
  617. var edgeShapeDiv = this.toolbar.edgeShapeMenu.getElementsByTagName('div')[0];
  618. if (graph.currentEdgeStyle['shape'] == 'link')
  619. {
  620. edgeShapeDiv.className = 'geSprite geSprite-linkedge';
  621. }
  622. else if (graph.currentEdgeStyle['shape'] == 'flexArrow')
  623. {
  624. edgeShapeDiv.className = 'geSprite geSprite-arrow';
  625. }
  626. else if (graph.currentEdgeStyle['shape'] == 'arrow')
  627. {
  628. edgeShapeDiv.className = 'geSprite geSprite-simplearrow';
  629. }
  630. else
  631. {
  632. edgeShapeDiv.className = 'geSprite geSprite-connection';
  633. }
  634. }
  635. // Updates icon for optinal line start shape
  636. if (this.toolbar.lineStartMenu != null)
  637. {
  638. var lineStartDiv = this.toolbar.lineStartMenu.getElementsByTagName('div')[0];
  639. lineStartDiv.className = this.getCssClassForMarker('start',
  640. graph.currentEdgeStyle['shape'], graph.currentEdgeStyle[mxConstants.STYLE_STARTARROW],
  641. mxUtils.getValue(graph.currentEdgeStyle, 'startFill', '1'));
  642. }
  643. // Updates icon for optinal line end shape
  644. if (this.toolbar.lineEndMenu != null)
  645. {
  646. var lineEndDiv = this.toolbar.lineEndMenu.getElementsByTagName('div')[0];
  647. lineEndDiv.className = this.getCssClassForMarker('end',
  648. graph.currentEdgeStyle['shape'], graph.currentEdgeStyle[mxConstants.STYLE_ENDARROW],
  649. mxUtils.getValue(graph.currentEdgeStyle, 'endFill', '1'));
  650. }
  651. }
  652. }));
  653. // Update font size and font family labels
  654. if (this.toolbar != null)
  655. {
  656. var update = mxUtils.bind(this, function()
  657. {
  658. var ff = graph.currentVertexStyle['fontFamily'] || 'Helvetica';
  659. var fs = String(graph.currentVertexStyle['fontSize'] || '12');
  660. var state = graph.getView().getState(graph.getSelectionCell());
  661. if (state != null)
  662. {
  663. ff = state.style[mxConstants.STYLE_FONTFAMILY] || ff;
  664. fs = state.style[mxConstants.STYLE_FONTSIZE] || fs;
  665. if (ff.length > 10)
  666. {
  667. ff = ff.substring(0, 8) + '...';
  668. }
  669. }
  670. this.toolbar.setFontName(ff);
  671. this.toolbar.setFontSize(fs);
  672. });
  673. graph.getSelectionModel().addListener(mxEvent.CHANGE, update);
  674. graph.getModel().addListener(mxEvent.CHANGE, update);
  675. }
  676. // Makes sure the current layer is visible when cells are added
  677. graph.addListener(mxEvent.CELLS_ADDED, function(sender, evt)
  678. {
  679. var cells = evt.getProperty('cells');
  680. var parent = evt.getProperty('parent');
  681. if (graph.getModel().isLayer(parent) && !graph.isCellVisible(parent) && cells != null && cells.length > 0)
  682. {
  683. graph.getModel().setVisible(parent, true);
  684. }
  685. });
  686. // Global handler to hide the current menu
  687. this.gestureHandler = mxUtils.bind(this, function(evt)
  688. {
  689. if (this.currentMenu != null && mxEvent.getSource(evt) != this.currentMenu.div)
  690. {
  691. this.hideCurrentMenu();
  692. }
  693. });
  694. mxEvent.addGestureListeners(document, this.gestureHandler);
  695. // Updates the editor UI after the window has been resized or the orientation changes
  696. // Timeout is workaround for old IE versions which have a delay for DOM client sizes.
  697. // Should not use delay > 0 to avoid handle multiple repaints during window resize
  698. this.resizeHandler = mxUtils.bind(this, function()
  699. {
  700. window.setTimeout(mxUtils.bind(this, function()
  701. {
  702. this.refresh();
  703. }), 0);
  704. });
  705. mxEvent.addListener(window, 'resize', this.resizeHandler);
  706. this.orientationChangeHandler = mxUtils.bind(this, function()
  707. {
  708. this.refresh();
  709. });
  710. mxEvent.addListener(window, 'orientationchange', this.orientationChangeHandler);
  711. // Workaround for bug on iOS see
  712. // http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
  713. if (mxClient.IS_IOS && !window.navigator.standalone)
  714. {
  715. this.scrollHandler = mxUtils.bind(this, function()
  716. {
  717. window.scrollTo(0, 0);
  718. });
  719. mxEvent.addListener(window, 'scroll', this.scrollHandler);
  720. }
  721. /**
  722. * Sets the initial scrollbar locations after a file was loaded.
  723. */
  724. this.editor.addListener('resetGraphView', mxUtils.bind(this, function()
  725. {
  726. this.resetScrollbars();
  727. }));
  728. /**
  729. * Repaints the grid.
  730. */
  731. this.addListener('gridEnabledChanged', mxUtils.bind(this, function()
  732. {
  733. graph.view.validateBackground();
  734. }));
  735. this.addListener('backgroundColorChanged', mxUtils.bind(this, function()
  736. {
  737. graph.view.validateBackground();
  738. }));
  739. /**
  740. * Repaints the grid.
  741. */
  742. graph.addListener('gridSizeChanged', mxUtils.bind(this, function()
  743. {
  744. if (graph.isGridEnabled())
  745. {
  746. graph.view.validateBackground();
  747. }
  748. }));
  749. // Resets UI, updates action and menu states
  750. this.editor.resetGraph();
  751. this.init();
  752. this.open();
  753. };
  754. // Extends mxEventSource
  755. mxUtils.extend(EditorUi, mxEventSource);
  756. /**
  757. * Global config that specifies if the compact UI elements should be used.
  758. */
  759. EditorUi.compactUi = true;
  760. /**
  761. * Specifies the size of the split bar.
  762. */
  763. EditorUi.prototype.splitSize = (mxClient.IS_TOUCH || mxClient.IS_POINTER) ? 12 : 8;
  764. /**
  765. * Specifies the height of the menubar. Default is 34.
  766. */
  767. EditorUi.prototype.menubarHeight = 30;
  768. /**
  769. * Specifies the width of the format panel should be enabled. Default is true.
  770. */
  771. EditorUi.prototype.formatEnabled = true;
  772. /**
  773. * Specifies the width of the format panel. Default is 240.
  774. */
  775. EditorUi.prototype.formatWidth = 240;
  776. /**
  777. * Specifies the height of the toolbar. Default is 36.
  778. */
  779. EditorUi.prototype.toolbarHeight = 34;
  780. /**
  781. * Specifies the height of the footer. Default is 28.
  782. */
  783. EditorUi.prototype.footerHeight = 28;
  784. /**
  785. * Specifies the height of the optional sidebarFooterContainer. Default is 34.
  786. */
  787. EditorUi.prototype.sidebarFooterHeight = 34;
  788. /**
  789. * Specifies the link for the edit button in chromeless mode.
  790. */
  791. EditorUi.prototype.editButtonLink = null;
  792. /**
  793. * Specifies the position of the horizontal split bar. Default is 204 or 120 for
  794. * screen widths <= 500px.
  795. */
  796. EditorUi.prototype.hsplitPosition = (screen.width <= 500) ? 116 : 208;
  797. /**
  798. * Specifies if animations are allowed in <executeLayout>. Default is true.
  799. */
  800. EditorUi.prototype.allowAnimation = true;
  801. /**
  802. * Installs the listeners to update the action states.
  803. */
  804. EditorUi.prototype.init = function()
  805. {
  806. /**
  807. * Keypress starts immediate editing on selection cell
  808. */
  809. var graph = this.editor.graph;
  810. mxEvent.addListener(graph.container, 'keydown', mxUtils.bind(this, function(evt)
  811. {
  812. // Tab selects next cell
  813. if (evt.which == 9 && graph.isEnabled() && !mxEvent.isAltDown(evt))
  814. {
  815. if (graph.isEditing())
  816. {
  817. graph.stopEditing(false);
  818. }
  819. else
  820. {
  821. graph.selectCell(!mxEvent.isShiftDown(evt));
  822. }
  823. mxEvent.consume(evt);
  824. }
  825. }));
  826. mxEvent.addListener(graph.container, 'keypress', mxUtils.bind(this, function(evt)
  827. {
  828. // KNOWN: Focus does not work if label is empty in quirks mode
  829. if (this.isImmediateEditingEvent(evt) && !graph.isEditing() && !graph.isSelectionEmpty() && evt.which !== 0 &&
  830. !mxEvent.isAltDown(evt) && !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt))
  831. {
  832. graph.escape();
  833. graph.startEditing();
  834. // Workaround for FF where char is lost if cursor is placed before char
  835. if (mxClient.IS_FF)
  836. {
  837. var ce = graph.cellEditor;
  838. ce.textarea.innerHTML = String.fromCharCode(evt.which);
  839. // Moves cursor to end of textarea
  840. var range = document.createRange();
  841. range.selectNodeContents(ce.textarea);
  842. range.collapse(false);
  843. var sel = window.getSelection();
  844. sel.removeAllRanges();
  845. sel.addRange(range);
  846. }
  847. }
  848. }));
  849. // Updates action states
  850. this.addUndoListener();
  851. this.addBeforeUnloadListener();
  852. graph.getSelectionModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  853. {
  854. this.updateActionStates();
  855. }));
  856. graph.getModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  857. {
  858. this.updateActionStates();
  859. }));
  860. // Changes action states after change of default parent
  861. var graphSetDefaultParent = graph.setDefaultParent;
  862. var ui = this;
  863. this.editor.graph.setDefaultParent = function()
  864. {
  865. graphSetDefaultParent.apply(this, arguments);
  866. ui.updateActionStates();
  867. };
  868. // Hack to make editLink available in vertex handler
  869. graph.editLink = ui.actions.get('editLink').funct;
  870. this.updateActionStates();
  871. this.initClipboard();
  872. this.initCanvas();
  873. if (this.format != null)
  874. {
  875. this.format.init();
  876. }
  877. };
  878. /**
  879. * Returns true if the given event should start editing. This implementation returns true.
  880. */
  881. EditorUi.prototype.isImmediateEditingEvent = function(evt)
  882. {
  883. return true;
  884. };
  885. /**
  886. * Private helper method.
  887. */
  888. EditorUi.prototype.getCssClassForMarker = function(prefix, shape, marker, fill)
  889. {
  890. var result = '';
  891. if (shape == 'flexArrow')
  892. {
  893. result = (marker != null && marker != mxConstants.NONE) ?
  894. 'geSprite geSprite-' + prefix + 'blocktrans' : 'geSprite geSprite-noarrow';
  895. }
  896. else
  897. {
  898. if (marker == mxConstants.ARROW_CLASSIC)
  899. {
  900. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'classic' : 'geSprite geSprite-' + prefix + 'classictrans';
  901. }
  902. else if (marker == mxConstants.ARROW_CLASSIC_THIN)
  903. {
  904. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'classicthin' : 'geSprite geSprite-' + prefix + 'classicthintrans';
  905. }
  906. else if (marker == mxConstants.ARROW_OPEN)
  907. {
  908. result = 'geSprite geSprite-' + prefix + 'open';
  909. }
  910. else if (marker == mxConstants.ARROW_OPEN_THIN)
  911. {
  912. result = 'geSprite geSprite-' + prefix + 'openthin';
  913. }
  914. else if (marker == mxConstants.ARROW_BLOCK)
  915. {
  916. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'block' : 'geSprite geSprite-' + prefix + 'blocktrans';
  917. }
  918. else if (marker == mxConstants.ARROW_BLOCK_THIN)
  919. {
  920. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'blockthin' : 'geSprite geSprite-' + prefix + 'blockthintrans';
  921. }
  922. else if (marker == mxConstants.ARROW_OVAL)
  923. {
  924. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'oval' : 'geSprite geSprite-' + prefix + 'ovaltrans';
  925. }
  926. else if (marker == mxConstants.ARROW_DIAMOND)
  927. {
  928. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'diamond' : 'geSprite geSprite-' + prefix + 'diamondtrans';
  929. }
  930. else if (marker == mxConstants.ARROW_DIAMOND_THIN)
  931. {
  932. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'thindiamond' : 'geSprite geSprite-' + prefix + 'thindiamondtrans';
  933. }
  934. else if (marker == 'openAsync')
  935. {
  936. result = 'geSprite geSprite-' + prefix + 'openasync';
  937. }
  938. else if (marker == 'dash')
  939. {
  940. result = 'geSprite geSprite-' + prefix + 'dash';
  941. }
  942. else if (marker == 'cross')
  943. {
  944. result = 'geSprite geSprite-' + prefix + 'cross';
  945. }
  946. else if (marker == 'async')
  947. {
  948. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'async' : 'geSprite geSprite-' + prefix + 'asynctrans';
  949. }
  950. else if (marker == 'circle' || marker == 'circlePlus')
  951. {
  952. result = (fill == '1' || marker == 'circle') ? 'geSprite geSprite-' + prefix + 'circle' : 'geSprite geSprite-' + prefix + 'circleplus';
  953. }
  954. else if (marker == 'ERone')
  955. {
  956. result = 'geSprite geSprite-' + prefix + 'erone';
  957. }
  958. else if (marker == 'ERmandOne')
  959. {
  960. result = 'geSprite geSprite-' + prefix + 'eronetoone';
  961. }
  962. else if (marker == 'ERmany')
  963. {
  964. result = 'geSprite geSprite-' + prefix + 'ermany';
  965. }
  966. else if (marker == 'ERoneToMany')
  967. {
  968. result = 'geSprite geSprite-' + prefix + 'eronetomany';
  969. }
  970. else if (marker == 'ERzeroToOne')
  971. {
  972. result = 'geSprite geSprite-' + prefix + 'eroneopt';
  973. }
  974. else if (marker == 'ERzeroToMany')
  975. {
  976. result = 'geSprite geSprite-' + prefix + 'ermanyopt';
  977. }
  978. else
  979. {
  980. result = 'geSprite geSprite-noarrow';
  981. }
  982. }
  983. return result;
  984. };
  985. /**
  986. * Overridden in Menus.js
  987. */
  988. EditorUi.prototype.createMenus = function()
  989. {
  990. return null;
  991. };
  992. /**
  993. * Hook for allowing selection and context menu for certain events.
  994. */
  995. EditorUi.prototype.updatePasteActionStates = function()
  996. {
  997. var graph = this.editor.graph;
  998. var paste = this.actions.get('paste');
  999. var pasteHere = this.actions.get('pasteHere');
  1000. paste.setEnabled(this.editor.graph.cellEditor.isContentEditing() || (!mxClipboard.isEmpty() &&
  1001. graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent())));
  1002. pasteHere.setEnabled(paste.isEnabled());
  1003. };
  1004. /**
  1005. * Hook for allowing selection and context menu for certain events.
  1006. */
  1007. EditorUi.prototype.initClipboard = function()
  1008. {
  1009. var ui = this;
  1010. var mxClipboardCut = mxClipboard.cut;
  1011. mxClipboard.cut = function(graph)
  1012. {
  1013. if (graph.cellEditor.isContentEditing())
  1014. {
  1015. document.execCommand('cut', false, null);
  1016. }
  1017. else
  1018. {
  1019. mxClipboardCut.apply(this, arguments);
  1020. }
  1021. ui.updatePasteActionStates();
  1022. };
  1023. var mxClipboardCopy = mxClipboard.copy;
  1024. mxClipboard.copy = function(graph)
  1025. {
  1026. if (graph.cellEditor.isContentEditing())
  1027. {
  1028. document.execCommand('copy', false, null);
  1029. }
  1030. else
  1031. {
  1032. mxClipboardCopy.apply(this, arguments);
  1033. }
  1034. ui.updatePasteActionStates();
  1035. };
  1036. var mxClipboardPaste = mxClipboard.paste;
  1037. mxClipboard.paste = function(graph)
  1038. {
  1039. var result = null;
  1040. if (graph.cellEditor.isContentEditing())
  1041. {
  1042. document.execCommand('paste', false, null);
  1043. }
  1044. else
  1045. {
  1046. result = mxClipboardPaste.apply(this, arguments);
  1047. }
  1048. ui.updatePasteActionStates();
  1049. return result;
  1050. };
  1051. // Overrides cell editor to update paste action state
  1052. var cellEditorStartEditing = this.editor.graph.cellEditor.startEditing;
  1053. this.editor.graph.cellEditor.startEditing = function()
  1054. {
  1055. cellEditorStartEditing.apply(this, arguments);
  1056. ui.updatePasteActionStates();
  1057. };
  1058. var cellEditorStopEditing = this.editor.graph.cellEditor.stopEditing;
  1059. this.editor.graph.cellEditor.stopEditing = function(cell, trigger)
  1060. {
  1061. cellEditorStopEditing.apply(this, arguments);
  1062. ui.updatePasteActionStates();
  1063. };
  1064. this.updatePasteActionStates();
  1065. };
  1066. /**
  1067. * Initializes the infinite canvas.
  1068. */
  1069. EditorUi.prototype.initCanvas = function()
  1070. {
  1071. var graph = this.editor.graph;
  1072. // Initial page layout view, scrollBuffer and timer-based scrolling
  1073. var graph = this.editor.graph;
  1074. graph.timerAutoScroll = true;
  1075. /**
  1076. * Returns the padding for pages in page view with scrollbars.
  1077. */
  1078. graph.getPagePadding = function()
  1079. {
  1080. return new mxPoint(Math.max(0, Math.round((graph.container.offsetWidth - 34) / graph.view.scale)),
  1081. Math.max(0, Math.round((graph.container.offsetHeight - 34) / graph.view.scale)));
  1082. };
  1083. // Fits the number of background pages to the graph
  1084. graph.view.getBackgroundPageBounds = function()
  1085. {
  1086. var layout = this.graph.getPageLayout();
  1087. var page = this.graph.getPageSize();
  1088. return new mxRectangle(this.scale * (this.translate.x + layout.x * page.width),
  1089. this.scale * (this.translate.y + layout.y * page.height),
  1090. this.scale * layout.width * page.width,
  1091. this.scale * layout.height * page.height);
  1092. };
  1093. graph.getPreferredPageSize = function(bounds, width, height)
  1094. {
  1095. var pages = this.getPageLayout();
  1096. var size = this.getPageSize();
  1097. return new mxRectangle(0, 0, pages.width * size.width, pages.height * size.height);
  1098. };
  1099. // Scales pages/graph to fit available size
  1100. var resize = null;
  1101. if (this.editor.chromeless)
  1102. {
  1103. resize = mxUtils.bind(this, function(autoscale)
  1104. {
  1105. if (graph.container != null)
  1106. {
  1107. var b = (graph.pageVisible) ? graph.view.getBackgroundPageBounds() : graph.getGraphBounds();
  1108. var tr = graph.view.translate;
  1109. var s = graph.view.scale;
  1110. // Normalizes the bounds
  1111. b = mxRectangle.fromRectangle(b);
  1112. b.x = b.x / s - tr.x;
  1113. b.y = b.y / s - tr.y;
  1114. b.width /= s;
  1115. b.height /= s;
  1116. var st = graph.container.scrollTop;
  1117. var sl = graph.container.scrollLeft;
  1118. var sb = (mxClient.IS_QUIRKS || document.documentMode >= 8) ? 20 : 14;
  1119. if (document.documentMode == 8 || document.documentMode == 9)
  1120. {
  1121. sb += 3;
  1122. }
  1123. var cw = graph.container.offsetWidth - sb;
  1124. var ch = graph.container.offsetHeight - sb;
  1125. var ns = (autoscale) ? Math.max(0.3, Math.min(1, cw / b.width)) : s;
  1126. var dx = Math.max((cw - ns * b.width) / 2, 0) / ns;
  1127. var dy = Math.max((ch - ns * b.height) / 4, 0) / ns;
  1128. graph.view.scaleAndTranslate(ns, dx - b.x, dy - b.y);
  1129. graph.container.scrollTop = st * ns / s;
  1130. graph.container.scrollLeft = sl * ns/ s;
  1131. }
  1132. });
  1133. // Hack to make function available to subclassers
  1134. this.chromelessResize = resize;
  1135. // Removable resize listener
  1136. var autoscaleResize = mxUtils.bind(this, function()
  1137. {
  1138. resize(false);
  1139. });
  1140. mxEvent.addListener(window, 'resize', autoscaleResize);
  1141. this.destroyFunctions.push(function()
  1142. {
  1143. mxEvent.removeListener(window, 'resize', autoscaleResize);
  1144. });
  1145. this.editor.addListener('resetGraphView', mxUtils.bind(this, function()
  1146. {
  1147. resize(true);
  1148. }));
  1149. this.actions.get('zoomIn').funct = function(evt) { graph.zoomIn(); resize(false); };
  1150. this.actions.get('zoomOut').funct = function(evt) { graph.zoomOut(); resize(false); };
  1151. // Creates toolbar for viewer - do not use CSS here
  1152. // as this may be used in a viewer that has no CSS
  1153. this.chromelessToolbar = document.createElement('div');
  1154. this.chromelessToolbar.style.position = 'fixed';
  1155. this.chromelessToolbar.style.overflow = 'hidden';
  1156. this.chromelessToolbar.style.boxSizing = 'border-box';
  1157. this.chromelessToolbar.style.whiteSpace = 'nowrap';
  1158. this.chromelessToolbar.style.backgroundColor = '#000000';
  1159. this.chromelessToolbar.style.padding = '10px 10px 8px 10px';
  1160. this.chromelessToolbar.style.left = '50%';
  1161. mxUtils.setPrefixedStyle(this.chromelessToolbar.style, 'borderRadius', '20px');
  1162. mxUtils.setPrefixedStyle(this.chromelessToolbar.style, 'transition', 'opacity 600ms ease-in-out');
  1163. var updateChromelessToolbarPosition = mxUtils.bind(this, function()
  1164. {
  1165. var css = mxUtils.getCurrentStyle(graph.container);
  1166. this.chromelessToolbar.style.bottom = ((css != null) ? parseInt(css['margin-bottom'] || 0) : 0) +
  1167. ((this.tabContainer != null) ? (20 + parseInt(this.tabContainer.style.height)) : 20) + 'px';
  1168. });
  1169. this.editor.addListener('resetGraphView', updateChromelessToolbarPosition);
  1170. updateChromelessToolbarPosition();
  1171. var btnCount = 0;
  1172. var addButton = mxUtils.bind(this, function(fn, imgSrc, tip)
  1173. {
  1174. btnCount++;
  1175. var a = document.createElement('span');
  1176. a.style.paddingLeft = '8px';
  1177. a.style.paddingRight = '8px';
  1178. a.style.cursor = 'pointer';
  1179. mxEvent.addListener(a, 'click', fn);
  1180. if (tip != null)
  1181. {
  1182. a.setAttribute('title', tip);
  1183. }
  1184. var img = document.createElement('img');
  1185. img.setAttribute('border', '0');
  1186. img.setAttribute('src', imgSrc);
  1187. a.appendChild(img);
  1188. this.chromelessToolbar.appendChild(a);
  1189. return a;
  1190. });
  1191. var prevButton = addButton(mxUtils.bind(this, function(evt)
  1192. {
  1193. this.actions.get('previousPage').funct();
  1194. mxEvent.consume(evt);
  1195. }), Editor.previousLargeImage, mxResources.get('previousPage') || 'Previous Page');
  1196. var pageInfo = document.createElement('div');
  1197. pageInfo.style.display = 'inline-block';
  1198. pageInfo.style.verticalAlign = 'top';
  1199. pageInfo.style.fontFamily = 'Helvetica,Arial';
  1200. pageInfo.style.marginTop = '8px';
  1201. pageInfo.style.color = '#ffffff';
  1202. this.chromelessToolbar.appendChild(pageInfo);
  1203. var nextButton = addButton(mxUtils.bind(this, function(evt)
  1204. {
  1205. this.actions.get('nextPage').funct();
  1206. mxEvent.consume(evt);
  1207. }), Editor.nextLargeImage, mxResources.get('nextPage') || 'Next Page');
  1208. var updatePageInfo = mxUtils.bind(this, function()
  1209. {
  1210. if (this.pages != null && this.pages.length > 1 && this.currentPage != null)
  1211. {
  1212. pageInfo.innerHTML = '';
  1213. mxUtils.write(pageInfo, (mxUtils.indexOf(this.pages, this.currentPage) + 1) + ' / ' + this.pages.length);
  1214. }
  1215. });
  1216. prevButton.style.paddingLeft = '0px';
  1217. prevButton.style.paddingRight = '4px';
  1218. nextButton.style.paddingLeft = '4px';
  1219. nextButton.style.paddingRight = '0px';
  1220. var updatePageButtons = mxUtils.bind(this, function()
  1221. {
  1222. if (this.pages != null && this.pages.length > 1 && this.currentPage != null)
  1223. {
  1224. nextButton.style.display = '';
  1225. prevButton.style.display = '';
  1226. pageInfo.style.display = 'inline-block';
  1227. }
  1228. else
  1229. {
  1230. nextButton.style.display = 'none';
  1231. prevButton.style.display = 'none';
  1232. pageInfo.style.display = 'none';
  1233. }
  1234. updatePageInfo();
  1235. });
  1236. this.editor.addListener('resetGraphView', updatePageButtons);
  1237. this.editor.addListener('pageSelected', updatePageInfo);
  1238. addButton(mxUtils.bind(this, function(evt)
  1239. {
  1240. this.actions.get('zoomOut').funct();
  1241. mxEvent.consume(evt);
  1242. }), Editor.zoomOutLargeImage, (mxResources.get('zoomOut') || 'Zoom Out') + ' (Alt+Mousewheel)');
  1243. addButton(mxUtils.bind(this, function(evt)
  1244. {
  1245. this.actions.get('zoomIn').funct();
  1246. mxEvent.consume(evt);
  1247. }), Editor.zoomInLargeImage, (mxResources.get('zoomIn') || 'Zoom In') + ' (Alt+Mousewheel)');
  1248. addButton(mxUtils.bind(this, function(evt)
  1249. {
  1250. if (graph.lightbox)
  1251. {
  1252. if (graph.view.scale == 1)
  1253. {
  1254. this.lightboxFit();
  1255. }
  1256. else
  1257. {
  1258. graph.zoomTo(1);
  1259. }
  1260. resize(false);
  1261. }
  1262. else
  1263. {
  1264. resize(true);
  1265. }
  1266. mxEvent.consume(evt);
  1267. }), Editor.actualSizeLargeImage, mxResources.get('fit') || 'Fit');
  1268. // Changes toolbar opacity on hover
  1269. var fadeThread = null;
  1270. var fadeThread2 = null;
  1271. var fadeOut = mxUtils.bind(this, function(delay)
  1272. {
  1273. if (fadeThread != null)
  1274. {
  1275. window.clearTimeout(fadeThread);
  1276. fadeThead = null;
  1277. }
  1278. if (fadeThread2 != null)
  1279. {
  1280. window.clearTimeout(fadeThread2);
  1281. fadeThead2 = null;
  1282. }
  1283. fadeThread = window.setTimeout(mxUtils.bind(this, function()
  1284. {
  1285. mxUtils.setOpacity(this.chromelessToolbar, 0);
  1286. fadeThread = null;
  1287. fadeThread2 = window.setTimeout(mxUtils.bind(this, function()
  1288. {
  1289. this.chromelessToolbar.style.display = 'none';
  1290. fadeThread2 = null;
  1291. }), 600);
  1292. }), delay || 200);
  1293. });
  1294. var fadeIn = mxUtils.bind(this, function(opacity)
  1295. {
  1296. if (fadeThread != null)
  1297. {
  1298. window.clearTimeout(fadeThread);
  1299. fadeThead = null;
  1300. }
  1301. if (fadeThread2 != null)
  1302. {
  1303. window.clearTimeout(fadeThread2);
  1304. fadeThead2 = null;
  1305. }
  1306. this.chromelessToolbar.style.display = '';
  1307. mxUtils.setOpacity(this.chromelessToolbar, opacity || 30);
  1308. });
  1309. if (urlParams['layers'] == '1')
  1310. {
  1311. this.layersDialog = null;
  1312. var layersButton = addButton(mxUtils.bind(this, function(evt)
  1313. {
  1314. if (this.layersDialog != null)
  1315. {
  1316. this.layersDialog.parentNode.removeChild(this.layersDialog);
  1317. this.layersDialog = null;
  1318. }
  1319. else
  1320. {
  1321. this.layersDialog = graph.createLayersDialog();
  1322. mxEvent.addListener(this.layersDialog, 'mouseleave', mxUtils.bind(this, function()
  1323. {
  1324. this.layersDialog.parentNode.removeChild(this.layersDialog);
  1325. this.layersDialog = null;
  1326. }));
  1327. var r = layersButton.getBoundingClientRect();
  1328. mxUtils.setPrefixedStyle(this.layersDialog.style, 'borderRadius', '5px');
  1329. this.layersDialog.style.position = 'fixed';
  1330. this.layersDialog.style.fontFamily = 'Helvetica,Arial';
  1331. this.layersDialog.style.backgroundColor = '#000000';
  1332. this.layersDialog.style.width = '160px';
  1333. this.layersDialog.style.padding = '4px 2px 4px 2px';
  1334. this.layersDialog.style.color = '#ffffff';
  1335. mxUtils.setOpacity(this.layersDialog, 70);
  1336. this.layersDialog.style.left = r.left + 'px';
  1337. this.layersDialog.style.bottom = parseInt(this.chromelessToolbar.style.bottom) +
  1338. this.chromelessToolbar.offsetHeight + 4 + 'px';
  1339. // Puts the dialog on top of the container z-index
  1340. var style = mxUtils.getCurrentStyle(this.editor.graph.container);
  1341. this.layersDialog.style.zIndex = style.zIndex;
  1342. document.body.appendChild(this.layersDialog);
  1343. }
  1344. mxEvent.consume(evt);
  1345. }), Editor.layersLargeImage, mxResources.get('layers') || 'Layers');
  1346. // Shows/hides layers button depending on content
  1347. var model = graph.getModel();
  1348. model.addListener(mxEvent.CHANGE, function()
  1349. {
  1350. layersButton.style.display = (model.getChildCount(model.root) > 1) ? '' : 'none';
  1351. });
  1352. }
  1353. if (this.editor.editButtonLink != null)
  1354. {
  1355. addButton(mxUtils.bind(this, function(evt)
  1356. {
  1357. if (this.editor.editButtonLink == '_blank')
  1358. {
  1359. this.editor.editAsNew(this.getEditBlankXml(), null, true);
  1360. }
  1361. else
  1362. {
  1363. window.open(this.editor.editButtonLink, 'editWindow');
  1364. }
  1365. mxEvent.consume(evt);
  1366. }), Editor.editLargeImage, mxResources.get('openInNewWindow') || 'Open in New Window');
  1367. }
  1368. if (graph.lightbox && this.container != document.body)
  1369. {
  1370. addButton(mxUtils.bind(this, function(evt)
  1371. {
  1372. if (urlParams['close'] == '1')
  1373. {
  1374. window.close();
  1375. }
  1376. else
  1377. {
  1378. this.destroy();
  1379. mxEvent.consume(evt);
  1380. }
  1381. }), Editor.closeLargeImage, (mxResources.get('close') || 'Close') + ' (Escape)');
  1382. }
  1383. // Initial state invisible
  1384. this.chromelessToolbar.style.display = 'none';
  1385. graph.container.appendChild(this.chromelessToolbar);
  1386. this.chromelessToolbar.style.marginLeft = -(btnCount * 24 + 10) + 'px';
  1387. // Installs handling of hightligh and handling links to relative links and anchors
  1388. this.addChromelessClickHandler();
  1389. mxEvent.addListener(graph.container, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', mxUtils.bind(this, function(evt)
  1390. {
  1391. if (!mxEvent.isTouchEvent(evt))
  1392. {
  1393. if (!mxEvent.isShiftDown(evt))
  1394. {
  1395. fadeIn(30);
  1396. }
  1397. fadeOut();
  1398. }
  1399. }));
  1400. mxEvent.addListener(this.chromelessToolbar, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', function(evt)
  1401. {
  1402. mxEvent.consume(evt);
  1403. });
  1404. mxEvent.addListener(this.chromelessToolbar, 'mouseenter', mxUtils.bind(this, function(evt)
  1405. {
  1406. if (!mxEvent.isShiftDown(evt))
  1407. {
  1408. fadeIn(100);
  1409. }
  1410. else
  1411. {
  1412. fadeOut();
  1413. }
  1414. }));
  1415. mxEvent.addListener(this.chromelessToolbar, 'mousemove', mxUtils.bind(this, function(evt)
  1416. {
  1417. if (!mxEvent.isShiftDown(evt))
  1418. {
  1419. fadeIn(100);
  1420. }
  1421. else
  1422. {
  1423. fadeOut();
  1424. }
  1425. mxEvent.consume(evt);
  1426. }));
  1427. mxEvent.addListener(this.chromelessToolbar, 'mouseleave', mxUtils.bind(this, function(evt)
  1428. {
  1429. if (!mxEvent.isTouchEvent(evt))
  1430. {
  1431. fadeIn(30);
  1432. }
  1433. }));
  1434. // Shows/hides toolbar for touch devices
  1435. var tol = graph.getTolerance();
  1436. var ui = this;
  1437. graph.addMouseListener(
  1438. {
  1439. startX: 0,
  1440. startY: 0,
  1441. scrollLeft: 0,
  1442. scrollTop: 0,
  1443. mouseDown: function(sender, me)
  1444. {
  1445. this.startX = me.getGraphX();
  1446. this.startY = me.getGraphY();
  1447. this.scrollLeft = graph.container.scrollLeft;
  1448. this.scrollTop = graph.container.scrollTop;
  1449. },
  1450. mouseMove: function(sender, me) {},
  1451. mouseUp: function(sender, me)
  1452. {
  1453. if (mxEvent.isTouchEvent(me.getEvent()))
  1454. {
  1455. if ((Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  1456. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  1457. (Math.abs(this.startX - me.getGraphX()) < tol &&
  1458. Math.abs(this.startY - me.getGraphY()) < tol))
  1459. {
  1460. if (parseFloat(ui.chromelessToolbar.style.opacity || 0) > 0)
  1461. {
  1462. fadeOut();
  1463. }
  1464. else
  1465. {
  1466. fadeIn(30);
  1467. }
  1468. }
  1469. }
  1470. }
  1471. });
  1472. }
  1473. else if (this.editor.extendCanvas)
  1474. {
  1475. /**
  1476. * Guesses autoTranslate to avoid another repaint (see below).
  1477. * Works if only the scale of the graph changes or if pages
  1478. * are visible and the visible pages do not change.
  1479. */
  1480. var graphViewValidate = graph.view.validate;
  1481. graph.view.validate = function()
  1482. {
  1483. if (this.graph.container != null && mxUtils.hasScrollbars(this.graph.container))
  1484. {
  1485. var pad = this.graph.getPagePadding();
  1486. var size = this.graph.getPageSize();
  1487. // Updating scrollbars here causes flickering in quirks and is not needed
  1488. // if zoom method is always used to set the current scale on the graph.
  1489. var tx = this.translate.x;
  1490. var ty = this.translate.y;
  1491. this.translate.x = pad.x - (this.x0 || 0) * size.width;
  1492. this.translate.y = pad.y - (this.y0 || 0) * size.height;
  1493. }
  1494. graphViewValidate.apply(this, arguments);
  1495. };
  1496. var graphSizeDidChange = graph.sizeDidChange;
  1497. graph.sizeDidChange = function()
  1498. {
  1499. if (this.container != null && mxUtils.hasScrollbars(this.container))
  1500. {
  1501. var pages = this.getPageLayout();
  1502. var pad = this.getPagePadding();
  1503. var size = this.getPageSize();
  1504. // Updates the minimum graph size
  1505. var minw = Math.ceil(2 * pad.x + pages.width * size.width);
  1506. var minh = Math.ceil(2 * pad.y + pages.height * size.height);
  1507. var min = graph.minimumGraphSize;
  1508. // LATER: Fix flicker of scrollbar size in IE quirks mode
  1509. // after delayed call in window.resize event handler
  1510. if (min == null || min.width != minw || min.height != minh)
  1511. {
  1512. graph.minimumGraphSize = new mxRectangle(0, 0, minw, minh);
  1513. }
  1514. // Updates auto-translate to include padding and graph size
  1515. var dx = pad.x - pages.x * size.width;
  1516. var dy = pad.y - pages.y * size.height;
  1517. if (!this.autoTranslate && (this.view.translate.x != dx || this.view.translate.y != dy))
  1518. {
  1519. this.autoTranslate = true;
  1520. this.view.x0 = pages.x;
  1521. this.view.y0 = pages.y;
  1522. // NOTE: THIS INVOKES THIS METHOD AGAIN. UNFORTUNATELY THERE IS NO WAY AROUND THIS SINCE THE
  1523. // BOUNDS ARE KNOWN AFTER THE VALIDATION AND SETTING THE TRANSLATE TRIGGERS A REVALIDATION.
  1524. // SHOULD MOVE TRANSLATE/SCALE TO VIEW.
  1525. var tx = graph.view.translate.x;
  1526. var ty = graph.view.translate.y;
  1527. graph.view.setTranslate(dx, dy);
  1528. // LATER: Fix rounding errors for small zoom
  1529. graph.container.scrollLeft += Math.round((dx - tx) * graph.view.scale);
  1530. graph.container.scrollTop += Math.round((dy - ty) * graph.view.scale);
  1531. this.autoTranslate = false;
  1532. return;
  1533. }
  1534. graphSizeDidChange.apply(this, arguments);
  1535. }
  1536. };
  1537. }
  1538. // Accumulates the zoom factor while the rendering is taking place
  1539. // so that not the complete sequence of zoom steps must be painted
  1540. graph.updateZoomTimeout = null;
  1541. graph.cumulativeZoomFactor = 1;
  1542. var cursorPosition = null;
  1543. graph.lazyZoom = function(zoomIn)
  1544. {
  1545. if (this.updateZoomTimeout != null)
  1546. {
  1547. window.clearTimeout(this.updateZoomTimeout);
  1548. }
  1549. // Switches to 1% zoom steps below 15%
  1550. // Lower bound depdends on rounding below
  1551. if (zoomIn)
  1552. {
  1553. if (this.view.scale * this.cumulativeZoomFactor < 0.15)
  1554. {
  1555. this.cumulativeZoomFactor = (this.view.scale + 0.01) / this.view.scale;
  1556. }
  1557. else
  1558. {
  1559. // Uses to 5% zoom steps for better grid rendering in webkit
  1560. // and to avoid rounding errors for zoom steps
  1561. this.cumulativeZoomFactor *= this.zoomFactor;
  1562. this.cumulativeZoomFactor = Math.round(this.view.scale * this.cumulativeZoomFactor * 20) / 20 / this.view.scale;
  1563. }
  1564. }
  1565. else
  1566. {
  1567. if (this.view.scale * this.cumulativeZoomFactor <= 0.15)
  1568. {
  1569. this.cumulativeZoomFactor = (this.view.scale - 0.01) / this.view.scale;
  1570. }
  1571. else
  1572. {
  1573. // Uses to 5% zoom steps for better grid rendering in webkit
  1574. // and to avoid rounding errors for zoom steps
  1575. this.cumulativeZoomFactor /= this.zoomFactor;
  1576. this.cumulativeZoomFactor = Math.round(this.view.scale * this.cumulativeZoomFactor * 20) / 20 / this.view.scale;
  1577. }
  1578. }
  1579. this.cumulativeZoomFactor = Math.max(0.01, Math.min(this.view.scale * this.cumulativeZoomFactor, 160) / this.view.scale);
  1580. this.updateZoomTimeout = window.setTimeout(mxUtils.bind(this, function()
  1581. {
  1582. this.zoom(this.cumulativeZoomFactor);
  1583. if (resize != null)
  1584. {
  1585. resize(false);
  1586. }
  1587. // Zooms to mouse position if scrollbars enabled
  1588. if (cursorPosition != null && mxUtils.hasScrollbars(graph.container))
  1589. {
  1590. var offset = mxUtils.getOffset(graph.container);
  1591. var dx = graph.container.offsetWidth / 2 - cursorPosition.x + offset.x;
  1592. var dy = graph.container.offsetHeight / 2 - cursorPosition.y + offset.y;
  1593. graph.container.scrollLeft -= dx * (this.cumulativeZoomFactor - 1);
  1594. graph.container.scrollTop -= dy * (this.cumulativeZoomFactor - 1);
  1595. }
  1596. this.cumulativeZoomFactor = 1;
  1597. this.updateZoomTimeout = null;
  1598. }), 20);
  1599. };
  1600. mxEvent.addMouseWheelListener(mxUtils.bind(this, function(evt, up)
  1601. {
  1602. // Ctrl+wheel (or pinch on touchpad) is a native browser zoom event is OS X
  1603. // LATER: Add support for zoom via pinch on trackpad for Chrome in OS X
  1604. if ((mxEvent.isAltDown(evt) || (mxEvent.isControlDown(evt) && !mxClient.IS_MAC) ||
  1605. graph.panningHandler.isActive()) && (this.dialogs == null || this.dialogs.length == 0))
  1606. {
  1607. var source = mxEvent.getSource(evt);
  1608. while (source != null)
  1609. {
  1610. if (source == graph.container)
  1611. {
  1612. cursorPosition = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  1613. graph.lazyZoom(up);
  1614. mxEvent.consume(evt);
  1615. return;
  1616. }
  1617. source = source.parentNode;
  1618. }
  1619. }
  1620. }));
  1621. };
  1622. /**
  1623. * Creates a temporary graph instance for rendering off-screen content.
  1624. */
  1625. EditorUi.prototype.createTemporaryGraph = function(stylesheet)
  1626. {
  1627. var graph = new Graph(document.createElement('div'), null, null, stylesheet);
  1628. graph.resetViewOnRootChange = false;
  1629. graph.setConnectable(false);
  1630. graph.gridEnabled = false;
  1631. graph.autoScroll = false;
  1632. graph.setTooltips(false);
  1633. graph.setEnabled(false);
  1634. // Container must be in the DOM for correct HTML rendering
  1635. graph.container.style.visibility = 'hidden';
  1636. graph.container.style.position = 'absolute';
  1637. graph.container.style.overflow = 'hidden';
  1638. graph.container.style.height = '1px';
  1639. graph.container.style.width = '1px';
  1640. return graph;
  1641. };
  1642. /**
  1643. *
  1644. */
  1645. EditorUi.prototype.addChromelessClickHandler = function()
  1646. {
  1647. var hl = urlParams['highlight'];
  1648. // Adds leading # for highlight color code
  1649. if (hl != null && hl.length > 0)
  1650. {
  1651. hl = '#' + hl;
  1652. }
  1653. this.editor.graph.addClickHandler(hl);
  1654. };
  1655. /**
  1656. *
  1657. */
  1658. EditorUi.prototype.toggleFormatPanel = function(forceHide)
  1659. {
  1660. this.formatWidth = (forceHide || this.formatWidth > 0) ? 0 : 240;
  1661. this.formatContainer.style.display = (forceHide || this.formatWidth > 0) ? '' : 'none';
  1662. this.refresh();
  1663. this.format.refresh();
  1664. this.fireEvent(new mxEventObject('formatWidthChanged'));
  1665. };
  1666. /**
  1667. * Adds support for placeholders in labels.
  1668. */
  1669. EditorUi.prototype.lightboxFit = function()
  1670. {
  1671. // LATER: Use initial graph bounds to avoid rounding errors
  1672. this.editor.graph.maxFitScale = 2;
  1673. this.editor.graph.fit(60);
  1674. this.editor.graph.maxFitScale = null;
  1675. };
  1676. /**
  1677. * Hook for allowing selection and context menu for certain events.
  1678. */
  1679. EditorUi.prototype.isSelectionAllowed = function(evt)
  1680. {
  1681. return mxEvent.getSource(evt).nodeName == 'SELECT' || (mxEvent.getSource(evt).nodeName == 'INPUT' &&
  1682. mxUtils.isAncestorNode(this.formatContainer, mxEvent.getSource(evt)));
  1683. };
  1684. /**
  1685. * Installs dialog if browser window is closed without saving
  1686. * This must be disabled during save and image export.
  1687. */
  1688. EditorUi.prototype.addBeforeUnloadListener = function()
  1689. {
  1690. // Installs dialog if browser window is closed without saving
  1691. // This must be disabled during save and image export
  1692. window.onbeforeunload = mxUtils.bind(this, function()
  1693. {
  1694. if (!this.editor.chromeless)
  1695. {
  1696. return this.onBeforeUnload();
  1697. }
  1698. });
  1699. };
  1700. /**
  1701. * Sets the onbeforeunload for the application
  1702. */
  1703. EditorUi.prototype.onBeforeUnload = function()
  1704. {
  1705. if (this.editor.modified)
  1706. {
  1707. return mxResources.get('allChangesLost');
  1708. }
  1709. };
  1710. /**
  1711. * Opens the current diagram via the window.opener if one exists.
  1712. */
  1713. EditorUi.prototype.open = function()
  1714. {
  1715. // Cross-domain window access is not allowed in FF, so if we
  1716. // were opened from another domain then this will fail.
  1717. try
  1718. {
  1719. if (window.opener != null && window.opener.openFile != null)
  1720. {
  1721. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  1722. {
  1723. try
  1724. {
  1725. var doc = mxUtils.parseXml(xml);
  1726. this.editor.setGraphXml(doc.documentElement);
  1727. this.editor.setModified(false);
  1728. this.editor.undoManager.clear();
  1729. if (filename != null)
  1730. {
  1731. this.editor.setFilename(filename);
  1732. this.updateDocumentTitle();
  1733. }
  1734. return;
  1735. }
  1736. catch (e)
  1737. {
  1738. mxUtils.alert(mxResources.get('invalidOrMissingFile') + ': ' + e.message);
  1739. }
  1740. }));
  1741. }
  1742. }
  1743. catch(e)
  1744. {
  1745. // ignore
  1746. }
  1747. // Fires as the last step if no file was loaded
  1748. this.editor.graph.view.validate();
  1749. // Required only in special cases where an initial file is opened
  1750. // and the minimumGraphSize changes and CSS must be updated.
  1751. this.editor.graph.sizeDidChange();
  1752. this.editor.fireEvent(new mxEventObject('resetGraphView'));
  1753. };
  1754. /**
  1755. * Sets the current menu and element.
  1756. */
  1757. EditorUi.prototype.setCurrentMenu = function(menu, elt)
  1758. {
  1759. this.currentMenuElt = elt;
  1760. this.currentMenu = menu;
  1761. };
  1762. /**
  1763. * Resets the current menu and element.
  1764. */
  1765. EditorUi.prototype.resetCurrentMenu = function()
  1766. {
  1767. this.currentMenuElt = null;
  1768. this.currentMenu = null;
  1769. };
  1770. /**
  1771. * Hides and destroys the current menu.
  1772. */
  1773. EditorUi.prototype.hideCurrentMenu = function(menu, elt)
  1774. {
  1775. if (this.currentMenu != null)
  1776. {
  1777. this.currentMenu.hideMenu();
  1778. this.resetCurrentMenu();
  1779. }
  1780. };
  1781. /**
  1782. * Updates the document title.
  1783. */
  1784. EditorUi.prototype.updateDocumentTitle = function()
  1785. {
  1786. var title = this.editor.getOrCreateFilename();
  1787. if (this.editor.appName != null)
  1788. {
  1789. title += ' - ' + this.editor.appName;
  1790. }
  1791. document.title = title;
  1792. };
  1793. /**
  1794. * Updates the document title.
  1795. */
  1796. EditorUi.prototype.createHoverIcons = function()
  1797. {
  1798. return new HoverIcons(this.editor.graph);
  1799. };
  1800. /**
  1801. * Returns the URL for a copy of this editor with no state.
  1802. */
  1803. EditorUi.prototype.redo = function()
  1804. {
  1805. try
  1806. {
  1807. var graph = this.editor.graph;
  1808. if (graph.isEditing())
  1809. {
  1810. document.execCommand('redo', false, null);
  1811. }
  1812. else
  1813. {
  1814. this.editor.undoManager.redo();
  1815. }
  1816. }
  1817. catch (e)
  1818. {
  1819. // ignore all errors
  1820. }
  1821. };
  1822. /**
  1823. * Returns the URL for a copy of this editor with no state.
  1824. */
  1825. EditorUi.prototype.undo = function()
  1826. {
  1827. try
  1828. {
  1829. var graph = this.editor.graph;
  1830. if (graph.isEditing())
  1831. {
  1832. // Stops editing and executes undo on graph if native undo
  1833. // does not affect current editing value
  1834. var value = graph.cellEditor.textarea.innerHTML;
  1835. document.execCommand('undo', false, null);
  1836. if (value == graph.cellEditor.textarea.innerHTML)
  1837. {
  1838. graph.stopEditing(true);
  1839. this.editor.undoManager.undo();
  1840. }
  1841. }
  1842. else
  1843. {
  1844. this.editor.undoManager.undo();
  1845. }
  1846. }
  1847. catch (e)
  1848. {
  1849. // ignore all errors
  1850. }
  1851. };
  1852. /**
  1853. * Returns the URL for a copy of this editor with no state.
  1854. */
  1855. EditorUi.prototype.canRedo = function()
  1856. {
  1857. return this.editor.graph.isEditing() || this.editor.undoManager.canRedo();
  1858. };
  1859. /**
  1860. * Returns the URL for a copy of this editor with no state.
  1861. */
  1862. EditorUi.prototype.canUndo = function()
  1863. {
  1864. return this.editor.graph.isEditing() || this.editor.undoManager.canUndo();
  1865. };
  1866. /**
  1867. *
  1868. */
  1869. EditorUi.prototype.getEditBlankXml = function()
  1870. {
  1871. return mxUtils.getXml(this.getGraphXml());
  1872. };
  1873. /**
  1874. * Returns the URL for a copy of this editor with no state.
  1875. */
  1876. EditorUi.prototype.getUrl = function(pathname)
  1877. {
  1878. var href = (pathname != null) ? pathname : window.location.pathname;
  1879. var parms = (href.indexOf('?') > 0) ? 1 : 0;
  1880. // Removes template URL parameter for new blank diagram
  1881. for (var key in urlParams)
  1882. {
  1883. if (parms == 0)
  1884. {
  1885. href += '?';
  1886. }
  1887. else
  1888. {
  1889. href += '&';
  1890. }
  1891. href += key + '=' + urlParams[key];
  1892. parms++;
  1893. }
  1894. return href;
  1895. };
  1896. /**
  1897. * Specifies if the graph has scrollbars.
  1898. */
  1899. EditorUi.prototype.setScrollbars = function(value)
  1900. {
  1901. var graph = this.editor.graph;
  1902. var prev = graph.container.style.overflow;
  1903. graph.scrollbars = value;
  1904. this.editor.updateGraphComponents();
  1905. if (prev != graph.container.style.overflow)
  1906. {
  1907. if (graph.container.style.overflow == 'hidden')
  1908. {
  1909. var t = graph.view.translate;
  1910. graph.view.setTranslate(t.x - graph.container.scrollLeft / graph.view.scale, t.y - graph.container.scrollTop / graph.view.scale);
  1911. graph.container.scrollLeft = 0;
  1912. graph.container.scrollTop = 0;
  1913. graph.minimumGraphSize = null;
  1914. graph.sizeDidChange();
  1915. }
  1916. else
  1917. {
  1918. var dx = graph.view.translate.x;
  1919. var dy = graph.view.translate.y;
  1920. graph.view.translate.x = 0;
  1921. graph.view.translate.y = 0;
  1922. graph.sizeDidChange();
  1923. graph.container.scrollLeft -= Math.round(dx * graph.view.scale);
  1924. graph.container.scrollTop -= Math.round(dy * graph.view.scale);
  1925. }
  1926. }
  1927. this.fireEvent(new mxEventObject('scrollbarsChanged'));
  1928. };
  1929. /**
  1930. * Returns true if the graph has scrollbars.
  1931. */
  1932. EditorUi.prototype.hasScrollbars = function()
  1933. {
  1934. return this.editor.graph.scrollbars;
  1935. };
  1936. /**
  1937. * Resets the state of the scrollbars.
  1938. */
  1939. EditorUi.prototype.resetScrollbars = function()
  1940. {
  1941. var graph = this.editor.graph;
  1942. if (!this.editor.extendCanvas)
  1943. {
  1944. graph.container.scrollTop = 0;
  1945. graph.container.scrollLeft = 0;
  1946. if (!mxUtils.hasScrollbars(graph.container))
  1947. {
  1948. graph.view.setTranslate(0, 0);
  1949. }
  1950. }
  1951. else if (!this.editor.chromeless)
  1952. {
  1953. if (mxUtils.hasScrollbars(graph.container))
  1954. {
  1955. if (graph.pageVisible)
  1956. {
  1957. var pad = graph.getPagePadding();
  1958. graph.container.scrollTop = Math.floor(pad.y - this.editor.initialTopSpacing);
  1959. graph.container.scrollLeft = Math.floor(Math.min(pad.x, (graph.container.scrollWidth - graph.container.clientWidth) / 2));
  1960. // Scrolls graph to visible area
  1961. var bounds = graph.getGraphBounds();
  1962. if (bounds.width > 0 && bounds.height > 0)
  1963. {
  1964. if (bounds.x > graph.container.scrollLeft + graph.container.clientWidth * 0.9)
  1965. {
  1966. graph.container.scrollLeft = Math.min(bounds.x + bounds.width - graph.container.clientWidth, bounds.x - 10);
  1967. }
  1968. if (bounds.y > graph.container.scrollTop + graph.container.clientHeight * 0.9)
  1969. {
  1970. graph.container.scrollTop = Math.min(bounds.y + bounds.height - graph.container.clientHeight, bounds.y - 10);
  1971. }
  1972. }
  1973. }
  1974. else
  1975. {
  1976. var bounds = graph.getGraphBounds();
  1977. var width = Math.max(bounds.width, graph.scrollTileSize.width * graph.view.scale);
  1978. var height = Math.max(bounds.height, graph.scrollTileSize.height * graph.view.scale);
  1979. graph.container.scrollTop = Math.floor(Math.max(0, bounds.y - Math.max(20, (graph.container.clientHeight - height) / 4)));
  1980. graph.container.scrollLeft = Math.floor(Math.max(0, bounds.x - Math.max(0, (graph.container.clientWidth - width) / 2)));
  1981. }
  1982. }
  1983. else
  1984. {
  1985. // This code is not actively used since the default for scrollbars is always true
  1986. if (graph.pageVisible)
  1987. {
  1988. var b = graph.view.getBackgroundPageBounds();
  1989. graph.view.setTranslate(Math.floor(Math.max(0, (graph.container.clientWidth - b.width) / 2) - b.x),
  1990. Math.floor(Math.max(0, (graph.container.clientHeight - b.height) / 2) - b.y));
  1991. }
  1992. else
  1993. {
  1994. var bounds = graph.getGraphBounds();
  1995. graph.view.setTranslate(Math.floor(Math.max(0, Math.max(0, (graph.container.clientWidth - bounds.width) / 2) - bounds.x)),
  1996. Math.floor(Math.max(0, Math.max(20, (graph.container.clientHeight - bounds.height) / 4)) - bounds.y));
  1997. }
  1998. }
  1999. }
  2000. };
  2001. /**
  2002. * Loads the stylesheet for this graph.
  2003. */
  2004. EditorUi.prototype.setPageVisible = function(value)
  2005. {
  2006. var graph = this.editor.graph;
  2007. var hasScrollbars = mxUtils.hasScrollbars(graph.container);
  2008. var tx = 0;
  2009. var ty = 0;
  2010. if (hasScrollbars)
  2011. {
  2012. tx = graph.view.translate.x * graph.view.scale - graph.container.scrollLeft;
  2013. ty = graph.view.translate.y * graph.view.scale - graph.container.scrollTop;
  2014. }
  2015. graph.pageVisible = value;
  2016. graph.pageBreaksVisible = value;
  2017. graph.preferPageSize = value;
  2018. graph.view.validateBackground();
  2019. // Workaround for possible handle offset
  2020. if (hasScrollbars)
  2021. {
  2022. var cells = graph.getSelectionCells();
  2023. graph.clearSelection();
  2024. graph.setSelectionCells(cells);
  2025. }
  2026. // Calls updatePageBreaks
  2027. graph.sizeDidChange();
  2028. if (hasScrollbars)
  2029. {
  2030. graph.container.scrollLeft = graph.view.translate.x * graph.view.scale - tx;
  2031. graph.container.scrollTop = graph.view.translate.y * graph.view.scale - ty;
  2032. }
  2033. this.fireEvent(new mxEventObject('pageViewChanged'));
  2034. };
  2035. /**
  2036. * Loads the stylesheet for this graph.
  2037. */
  2038. EditorUi.prototype.setBackgroundColor = function(value)
  2039. {
  2040. this.editor.graph.background = value;
  2041. this.editor.graph.view.validateBackground();
  2042. this.fireEvent(new mxEventObject('backgroundColorChanged'));
  2043. };
  2044. /**
  2045. * Loads the stylesheet for this graph.
  2046. */
  2047. EditorUi.prototype.setFoldingEnabled = function(value)
  2048. {
  2049. this.editor.graph.foldingEnabled = value;
  2050. this.editor.graph.view.revalidate();
  2051. this.fireEvent(new mxEventObject('foldingEnabledChanged'));
  2052. };
  2053. /**
  2054. * Loads the stylesheet for this graph.
  2055. */
  2056. EditorUi.prototype.setPageFormat = function(value)
  2057. {
  2058. this.editor.graph.pageFormat = value;
  2059. if (!this.editor.graph.pageVisible)
  2060. {
  2061. this.actions.get('pageView').funct();
  2062. }
  2063. else
  2064. {
  2065. this.editor.graph.view.validateBackground();
  2066. this.editor.graph.sizeDidChange();
  2067. }
  2068. this.fireEvent(new mxEventObject('pageFormatChanged'));
  2069. };
  2070. /**
  2071. * Loads the stylesheet for this graph.
  2072. */
  2073. EditorUi.prototype.setPageScale = function(value)
  2074. {
  2075. this.editor.graph.pageScale = value;
  2076. if (!this.editor.graph.pageVisible)
  2077. {
  2078. this.actions.get('pageView').funct();
  2079. }
  2080. else
  2081. {
  2082. this.editor.graph.view.validateBackground();
  2083. this.editor.graph.sizeDidChange();
  2084. }
  2085. this.fireEvent(new mxEventObject('pageScaleChanged'));
  2086. };
  2087. /**
  2088. * Loads the stylesheet for this graph.
  2089. */
  2090. EditorUi.prototype.setGridColor = function(value)
  2091. {
  2092. this.editor.graph.view.gridColor = value;
  2093. this.editor.graph.view.validateBackground();
  2094. this.fireEvent(new mxEventObject('gridColorChanged'));
  2095. };
  2096. /**
  2097. * Updates the states of the given undo/redo items.
  2098. */
  2099. EditorUi.prototype.addUndoListener = function()
  2100. {
  2101. var undo = this.actions.get('undo');
  2102. var redo = this.actions.get('redo');
  2103. var undoMgr = this.editor.undoManager;
  2104. var undoListener = mxUtils.bind(this, function()
  2105. {
  2106. undo.setEnabled(this.canUndo());
  2107. redo.setEnabled(this.canRedo());
  2108. });
  2109. undoMgr.addListener(mxEvent.ADD, undoListener);
  2110. undoMgr.addListener(mxEvent.UNDO, undoListener);
  2111. undoMgr.addListener(mxEvent.REDO, undoListener);
  2112. undoMgr.addListener(mxEvent.CLEAR, undoListener);
  2113. // Overrides cell editor to update action states
  2114. var cellEditorStartEditing = this.editor.graph.cellEditor.startEditing;
  2115. this.editor.graph.cellEditor.startEditing = function()
  2116. {
  2117. cellEditorStartEditing.apply(this, arguments);
  2118. undoListener();
  2119. };
  2120. var cellEditorStopEditing = this.editor.graph.cellEditor.stopEditing;
  2121. this.editor.graph.cellEditor.stopEditing = function(cell, trigger)
  2122. {
  2123. cellEditorStopEditing.apply(this, arguments);
  2124. undoListener();
  2125. };
  2126. // Updates the button states once
  2127. undoListener();
  2128. };
  2129. /**
  2130. * Updates the states of the given toolbar items based on the selection.
  2131. */
  2132. EditorUi.prototype.updateActionStates = function()
  2133. {
  2134. var graph = this.editor.graph;
  2135. var selected = !graph.isSelectionEmpty();
  2136. var vertexSelected = false;
  2137. var edgeSelected = false;
  2138. var cells = graph.getSelectionCells();
  2139. if (cells != null)
  2140. {
  2141. for (var i = 0; i < cells.length; i++)
  2142. {
  2143. var cell = cells[i];
  2144. if (graph.getModel().isEdge(cell))
  2145. {
  2146. edgeSelected = true;
  2147. }
  2148. if (graph.getModel().isVertex(cell))
  2149. {
  2150. vertexSelected = true;
  2151. }
  2152. if (edgeSelected && vertexSelected)
  2153. {
  2154. break;
  2155. }
  2156. }
  2157. }
  2158. // Updates action states
  2159. var actions = ['cut', 'copy', 'bold', 'italic', 'underline', 'delete', 'duplicate',
  2160. 'editStyle', 'editTooltip', 'editLink', 'backgroundColor', 'borderColor',
  2161. 'edit', 'toFront', 'toBack', 'lockUnlock', 'solid', 'dashed',
  2162. 'dotted', 'fillColor', 'gradientColor', 'shadow', 'fontColor',
  2163. 'formattedText', 'rounded', 'toggleRounded', 'sharp', 'strokeColor'];
  2164. for (var i = 0; i < actions.length; i++)
  2165. {
  2166. this.actions.get(actions[i]).setEnabled(selected);
  2167. }
  2168. this.actions.get('setAsDefaultStyle').setEnabled(graph.getSelectionCount() == 1);
  2169. this.actions.get('clearWaypoints').setEnabled(!graph.isSelectionEmpty());
  2170. this.actions.get('turn').setEnabled(!graph.isSelectionEmpty());
  2171. this.actions.get('curved').setEnabled(edgeSelected);
  2172. this.actions.get('rotation').setEnabled(vertexSelected);
  2173. this.actions.get('wordWrap').setEnabled(vertexSelected);
  2174. this.actions.get('autosize').setEnabled(vertexSelected);
  2175. this.actions.get('collapsible').setEnabled(vertexSelected);
  2176. var oneVertexSelected = vertexSelected && graph.getSelectionCount() == 1;
  2177. this.actions.get('group').setEnabled(graph.getSelectionCount() > 1 ||
  2178. (oneVertexSelected && !graph.isContainer(graph.getSelectionCell())));
  2179. this.actions.get('ungroup').setEnabled(graph.getSelectionCount() == 1 &&
  2180. (graph.getModel().getChildCount(graph.getSelectionCell()) > 0 ||
  2181. (oneVertexSelected && graph.isContainer(graph.getSelectionCell()))));
  2182. this.actions.get('removeFromGroup').setEnabled(oneVertexSelected &&
  2183. graph.getModel().isVertex(graph.getModel().getParent(graph.getSelectionCell())));
  2184. // Updates menu states
  2185. var state = graph.view.getState(graph.getSelectionCell());
  2186. this.menus.get('navigation').setEnabled(selected || graph.view.currentRoot != null);
  2187. this.actions.get('collapsible').setEnabled(vertexSelected && graph.getSelectionCount() == 1 &&
  2188. (graph.isContainer(graph.getSelectionCell()) || graph.model.getChildCount(graph.getSelectionCell()) > 0));
  2189. this.actions.get('home').setEnabled(graph.view.currentRoot != null);
  2190. this.actions.get('exitGroup').setEnabled(graph.view.currentRoot != null);
  2191. this.actions.get('enterGroup').setEnabled(graph.getSelectionCount() == 1 && graph.isValidRoot(graph.getSelectionCell()));
  2192. var foldable = graph.getSelectionCount() == 1 && graph.isCellFoldable(graph.getSelectionCell())
  2193. this.actions.get('expand').setEnabled(foldable);
  2194. this.actions.get('collapse').setEnabled(foldable);
  2195. this.actions.get('editLink').setEnabled(graph.getSelectionCount() == 1);
  2196. this.actions.get('openLink').setEnabled(graph.getSelectionCount() == 1 &&
  2197. graph.getLinkForCell(graph.getSelectionCell()) != null);
  2198. this.actions.get('guides').setEnabled(graph.isEnabled());
  2199. this.actions.get('grid').setEnabled(!this.editor.chromeless);
  2200. var unlocked = graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent());
  2201. this.menus.get('layout').setEnabled(unlocked);
  2202. this.menus.get('insert').setEnabled(unlocked);
  2203. this.menus.get('direction').setEnabled(unlocked && vertexSelected);
  2204. this.menus.get('align').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2205. this.menus.get('distribute').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2206. this.actions.get('selectVertices').setEnabled(unlocked);
  2207. this.actions.get('selectEdges').setEnabled(unlocked);
  2208. this.actions.get('selectAll').setEnabled(unlocked);
  2209. this.actions.get('selectNone').setEnabled(unlocked);
  2210. this.updatePasteActionStates();
  2211. };
  2212. /**
  2213. * Refreshes the viewport.
  2214. */
  2215. EditorUi.prototype.refresh = function(sizeDidChange)
  2216. {
  2217. sizeDidChange = (sizeDidChange != null) ? sizeDidChange : true;
  2218. var quirks = mxClient.IS_IE && (document.documentMode == null || document.documentMode == 5);
  2219. var w = this.container.clientWidth;
  2220. var h = this.container.clientHeight;
  2221. if (this.container == document.body)
  2222. {
  2223. w = document.body.clientWidth || document.documentElement.clientWidth;
  2224. h = (quirks) ? document.body.clientHeight || document.documentElement.clientHeight : document.documentElement.clientHeight;
  2225. }
  2226. // Workaround for bug on iOS see
  2227. // http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
  2228. // FIXME: Fix if footer visible
  2229. var off = 0;
  2230. if (mxClient.IS_IOS && !window.navigator.standalone)
  2231. {
  2232. if (window.innerHeight != document.documentElement.clientHeight)
  2233. {
  2234. off = document.documentElement.clientHeight - window.innerHeight;
  2235. window.scrollTo(0, 0);
  2236. }
  2237. }
  2238. var effHsplitPosition = Math.max(0, Math.min(this.hsplitPosition, w - this.splitSize - 20));
  2239. var tmp = 0;
  2240. if (this.menubar != null)
  2241. {
  2242. this.menubarContainer.style.height = this.menubarHeight + 'px';
  2243. tmp += this.menubarHeight;
  2244. }
  2245. if (this.toolbar != null)
  2246. {
  2247. this.toolbarContainer.style.top = this.menubarHeight + 'px';
  2248. this.toolbarContainer.style.height = this.toolbarHeight + 'px';
  2249. tmp += this.toolbarHeight;
  2250. }
  2251. if (tmp > 0 && !mxClient.IS_QUIRKS)
  2252. {
  2253. tmp += 1;
  2254. }
  2255. var sidebarFooterHeight = 0;
  2256. if (this.sidebarFooterContainer != null)
  2257. {
  2258. var bottom = this.footerHeight + off;
  2259. sidebarFooterHeight = Math.max(0, Math.min(h - tmp - bottom, this.sidebarFooterHeight));
  2260. this.sidebarFooterContainer.style.width = effHsplitPosition + 'px';
  2261. this.sidebarFooterContainer.style.height = sidebarFooterHeight + 'px';
  2262. this.sidebarFooterContainer.style.bottom = bottom + 'px';
  2263. }
  2264. var fw = (this.format != null) ? this.formatWidth : 0;
  2265. this.sidebarContainer.style.top = tmp + 'px';
  2266. this.sidebarContainer.style.width = effHsplitPosition + 'px';
  2267. this.formatContainer.style.top = tmp + 'px';
  2268. this.formatContainer.style.width = fw + 'px';
  2269. this.formatContainer.style.display = (this.format != null) ? '' : 'none';
  2270. this.diagramContainer.style.left = (this.hsplit.parentNode != null) ? (effHsplitPosition + this.splitSize) + 'px' : '0px';
  2271. this.diagramContainer.style.top = this.sidebarContainer.style.top;
  2272. this.footerContainer.style.height = this.footerHeight + 'px';
  2273. this.hsplit.style.top = this.sidebarContainer.style.top;
  2274. this.hsplit.style.bottom = (this.footerHeight + off) + 'px';
  2275. this.hsplit.style.left = effHsplitPosition + 'px';
  2276. if (this.tabContainer != null)
  2277. {
  2278. this.tabContainer.style.left = this.diagramContainer.style.left;
  2279. }
  2280. if (quirks)
  2281. {
  2282. this.menubarContainer.style.width = w + 'px';
  2283. this.toolbarContainer.style.width = this.menubarContainer.style.width;
  2284. var sidebarHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2285. this.sidebarContainer.style.height = (sidebarHeight - sidebarFooterHeight) + 'px';
  2286. this.formatContainer.style.height = sidebarHeight + 'px';
  2287. this.diagramContainer.style.width = (this.hsplit.parentNode != null) ? Math.max(0, w - effHsplitPosition - this.splitSize - fw) + 'px' : w + 'px';
  2288. this.footerContainer.style.width = this.menubarContainer.style.width;
  2289. var diagramHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2290. if (this.tabContainer != null)
  2291. {
  2292. this.tabContainer.style.width = this.diagramContainer.style.width;
  2293. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2294. diagramHeight -= this.tabContainer.clientHeight;
  2295. }
  2296. this.diagramContainer.style.height = diagramHeight + 'px';
  2297. this.hsplit.style.height = diagramHeight + 'px';
  2298. }
  2299. else
  2300. {
  2301. if (this.footerHeight > 0)
  2302. {
  2303. this.footerContainer.style.bottom = off + 'px';
  2304. }
  2305. this.diagramContainer.style.right = fw + 'px';
  2306. var th = 0;
  2307. if (this.tabContainer != null)
  2308. {
  2309. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2310. this.tabContainer.style.right = this.diagramContainer.style.right;
  2311. th = this.tabContainer.clientHeight;
  2312. }
  2313. this.sidebarContainer.style.bottom = (this.footerHeight + sidebarFooterHeight + off) + 'px';
  2314. this.formatContainer.style.bottom = (this.footerHeight + off) + 'px';
  2315. this.diagramContainer.style.bottom = (this.footerHeight + off + th) + 'px';
  2316. }
  2317. if (sizeDidChange)
  2318. {
  2319. this.editor.graph.sizeDidChange();
  2320. }
  2321. };
  2322. /**
  2323. * Creates the required containers.
  2324. */
  2325. EditorUi.prototype.createTabContainer = function()
  2326. {
  2327. return null;
  2328. };
  2329. /**
  2330. * Creates the required containers.
  2331. */
  2332. EditorUi.prototype.createDivs = function()
  2333. {
  2334. this.menubarContainer = this.createDiv('geMenubarContainer');
  2335. this.toolbarContainer = this.createDiv('geToolbarContainer');
  2336. this.sidebarContainer = this.createDiv('geSidebarContainer');
  2337. this.formatContainer = this.createDiv('geSidebarContainer');
  2338. this.diagramContainer = this.createDiv('geDiagramContainer');
  2339. this.footerContainer = this.createDiv('geFooterContainer');
  2340. this.hsplit = this.createDiv('geHsplit');
  2341. this.hsplit.setAttribute('title', mxResources.get('collapseExpand'));
  2342. // Sets static style for containers
  2343. this.menubarContainer.style.top = '0px';
  2344. this.menubarContainer.style.left = '0px';
  2345. this.menubarContainer.style.right = '0px';
  2346. this.toolbarContainer.style.left = '0px';
  2347. this.toolbarContainer.style.right = '0px';
  2348. this.sidebarContainer.style.left = '0px';
  2349. this.formatContainer.style.right = '0px';
  2350. this.formatContainer.style.zIndex = '1';
  2351. this.diagramContainer.style.right = ((this.format != null) ? this.formatWidth : 0) + 'px';
  2352. this.footerContainer.style.left = '0px';
  2353. this.footerContainer.style.right = '0px';
  2354. this.footerContainer.style.bottom = '0px';
  2355. this.footerContainer.style.zIndex = mxPopupMenu.prototype.zIndex - 2;
  2356. this.hsplit.style.width = this.splitSize + 'px';
  2357. // Only vertical scrollbars, no background in format sidebar
  2358. this.formatContainer.style.backgroundColor = 'whiteSmoke';
  2359. this.formatContainer.style.overflowX = 'hidden';
  2360. this.formatContainer.style.overflowY = 'auto';
  2361. this.formatContainer.style.fontSize = '12px';
  2362. this.sidebarFooterContainer = this.createSidebarFooterContainer();
  2363. if (this.sidebarFooterContainer)
  2364. {
  2365. this.sidebarFooterContainer.style.left = '0px';
  2366. }
  2367. if (!this.editor.chromeless)
  2368. {
  2369. this.tabContainer = this.createTabContainer();
  2370. }
  2371. };
  2372. /**
  2373. * Hook for sidebar footer container. This implementation returns null.
  2374. */
  2375. EditorUi.prototype.createSidebarFooterContainer = function()
  2376. {
  2377. return null;
  2378. };
  2379. /**
  2380. * Creates the required containers.
  2381. */
  2382. EditorUi.prototype.createUi = function()
  2383. {
  2384. // Creates menubar
  2385. this.menubar = (this.editor.chromeless) ? null : this.menus.createMenubar(this.createDiv('geMenubar'));
  2386. if (this.menubar != null)
  2387. {
  2388. this.menubarContainer.appendChild(this.menubar.container);
  2389. }
  2390. // Adds status bar in menubar
  2391. if (this.menubar != null)
  2392. {
  2393. this.statusContainer = this.createStatusContainer();
  2394. // Connects the status bar to the editor status
  2395. this.editor.addListener('statusChanged', mxUtils.bind(this, function()
  2396. {
  2397. this.setStatusText(this.editor.getStatus());
  2398. }));
  2399. this.setStatusText(this.editor.getStatus());
  2400. this.menubar.container.appendChild(this.statusContainer);
  2401. // Inserts into DOM
  2402. this.container.appendChild(this.menubarContainer);
  2403. }
  2404. // Creates the sidebar
  2405. this.sidebar = (this.editor.chromeless) ? null : this.createSidebar(this.sidebarContainer);
  2406. if (this.sidebar != null)
  2407. {
  2408. this.container.appendChild(this.sidebarContainer);
  2409. }
  2410. // Creates the format sidebar
  2411. this.format = (this.editor.chromeless || !this.formatEnabled) ? null : this.createFormat(this.formatContainer);
  2412. if (this.format != null)
  2413. {
  2414. this.container.appendChild(this.formatContainer);
  2415. }
  2416. // Creates the footer
  2417. var footer = (this.editor.chromeless) ? null : this.createFooter();
  2418. if (footer != null)
  2419. {
  2420. this.footerContainer.appendChild(footer);
  2421. this.container.appendChild(this.footerContainer);
  2422. }
  2423. if (this.sidebar != null && this.sidebarFooterContainer)
  2424. {
  2425. this.container.appendChild(this.sidebarFooterContainer);
  2426. }
  2427. this.container.appendChild(this.diagramContainer);
  2428. if (this.container != null && this.tabContainer != null)
  2429. {
  2430. this.container.appendChild(this.tabContainer);
  2431. }
  2432. // Creates toolbar
  2433. this.toolbar = (this.editor.chromeless) ? null : this.createToolbar(this.createDiv('geToolbar'));
  2434. if (this.toolbar != null)
  2435. {
  2436. this.toolbarContainer.appendChild(this.toolbar.container);
  2437. this.container.appendChild(this.toolbarContainer);
  2438. }
  2439. // HSplit
  2440. if (this.sidebar != null)
  2441. {
  2442. this.container.appendChild(this.hsplit);
  2443. this.addSplitHandler(this.hsplit, true, 0, mxUtils.bind(this, function(value)
  2444. {
  2445. this.hsplitPosition = value;
  2446. this.refresh();
  2447. }));
  2448. }
  2449. };
  2450. /**
  2451. * Creates a new toolbar for the given container.
  2452. */
  2453. EditorUi.prototype.createStatusContainer = function()
  2454. {
  2455. var container = document.createElement('a');
  2456. container.className = 'geItem geStatus';
  2457. return container;
  2458. };
  2459. /**
  2460. * Creates a new toolbar for the given container.
  2461. */
  2462. EditorUi.prototype.setStatusText = function(value)
  2463. {
  2464. this.statusContainer.innerHTML = value;
  2465. };
  2466. /**
  2467. * Creates a new toolbar for the given container.
  2468. */
  2469. EditorUi.prototype.createToolbar = function(container)
  2470. {
  2471. return new Toolbar(this, container);
  2472. };
  2473. /**
  2474. * Creates a new sidebar for the given container.
  2475. */
  2476. EditorUi.prototype.createSidebar = function(container)
  2477. {
  2478. return new Sidebar(this, container);
  2479. };
  2480. /**
  2481. * Creates a new sidebar for the given container.
  2482. */
  2483. EditorUi.prototype.createFormat = function(container)
  2484. {
  2485. return new Format(this, container);
  2486. };
  2487. /**
  2488. * Creates and returns a new footer.
  2489. */
  2490. EditorUi.prototype.createFooter = function()
  2491. {
  2492. return this.createDiv('geFooter');
  2493. };
  2494. /**
  2495. * Creates the actual toolbar for the toolbar container.
  2496. */
  2497. EditorUi.prototype.createDiv = function(classname)
  2498. {
  2499. var elt = document.createElement('div');
  2500. elt.className = classname;
  2501. return elt;
  2502. };
  2503. /**
  2504. * Updates the states of the given undo/redo items.
  2505. */
  2506. EditorUi.prototype.addSplitHandler = function(elt, horizontal, dx, onChange)
  2507. {
  2508. var start = null;
  2509. var initial = null;
  2510. var ignoreClick = true;
  2511. var last = null;
  2512. // Disables built-in pan and zoom in IE10 and later
  2513. if (mxClient.IS_POINTER)
  2514. {
  2515. elt.style.touchAction = 'none';
  2516. }
  2517. var getValue = mxUtils.bind(this, function()
  2518. {
  2519. var result = parseInt(((horizontal) ? elt.style.left : elt.style.bottom));
  2520. // Takes into account hidden footer
  2521. if (!horizontal)
  2522. {
  2523. result = result + dx - this.footerHeight;
  2524. }
  2525. return result;
  2526. });
  2527. function moveHandler(evt)
  2528. {
  2529. if (start != null)
  2530. {
  2531. var pt = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2532. onChange(Math.max(0, initial + ((horizontal) ? (pt.x - start.x) : (start.y - pt.y)) - dx));
  2533. mxEvent.consume(evt);
  2534. if (initial != getValue())
  2535. {
  2536. ignoreClick = true;
  2537. last = null;
  2538. }
  2539. }
  2540. };
  2541. function dropHandler(evt)
  2542. {
  2543. moveHandler(evt);
  2544. initial = null;
  2545. start = null;
  2546. };
  2547. mxEvent.addGestureListeners(elt, function(evt)
  2548. {
  2549. start = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2550. initial = getValue();
  2551. ignoreClick = false;
  2552. mxEvent.consume(evt);
  2553. });
  2554. mxEvent.addListener(elt, 'click', function(evt)
  2555. {
  2556. if (!ignoreClick)
  2557. {
  2558. var next = (last != null) ? last - dx : 0;
  2559. last = getValue();
  2560. onChange(next);
  2561. mxEvent.consume(evt);
  2562. }
  2563. });
  2564. mxEvent.addGestureListeners(document, null, moveHandler, dropHandler);
  2565. this.destroyFunctions.push(function()
  2566. {
  2567. mxEvent.removeGestureListeners(document, null, moveHandler, dropHandler);
  2568. });
  2569. };
  2570. /**
  2571. * Displays a print dialog.
  2572. */
  2573. EditorUi.prototype.showDialog = function(elt, w, h, modal, closable, onClose)
  2574. {
  2575. this.editor.graph.tooltipHandler.hideTooltip();
  2576. if (this.dialogs == null)
  2577. {
  2578. this.dialogs = [];
  2579. }
  2580. this.dialog = new Dialog(this, elt, w, h, modal, closable, onClose);
  2581. this.dialogs.push(this.dialog);
  2582. };
  2583. /**
  2584. * Displays a print dialog.
  2585. */
  2586. EditorUi.prototype.hideDialog = function(cancel)
  2587. {
  2588. if (this.dialogs != null && this.dialogs.length > 0)
  2589. {
  2590. var dlg = this.dialogs.pop();
  2591. dlg.close(cancel);
  2592. this.dialog = (this.dialogs.length > 0) ? this.dialogs[this.dialogs.length - 1] : null;
  2593. if (this.dialog == null && this.editor.graph.container.style.visibility != 'hidden')
  2594. {
  2595. this.editor.graph.container.focus();
  2596. }
  2597. this.editor.fireEvent(new mxEventObject('hideDialog'));
  2598. }
  2599. };
  2600. /**
  2601. * Display a color dialog.
  2602. */
  2603. EditorUi.prototype.pickColor = function(color, apply)
  2604. {
  2605. var graph = this.editor.graph;
  2606. var selState = graph.cellEditor.saveSelection();
  2607. var dlg = new ColorDialog(this, color || 'none', function(color)
  2608. {
  2609. graph.cellEditor.restoreSelection(selState);
  2610. apply(color);
  2611. }, function()
  2612. {
  2613. graph.cellEditor.restoreSelection(selState);
  2614. });
  2615. this.showDialog(dlg.container, 220, 430, true, false);
  2616. dlg.init();
  2617. };
  2618. /**
  2619. * Adds the label menu items to the given menu and parent.
  2620. */
  2621. EditorUi.prototype.openFile = function()
  2622. {
  2623. // Closes dialog after open
  2624. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2625. {
  2626. this.hideDialog(cancel);
  2627. }));
  2628. // Removes openFile if dialog is closed
  2629. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 320,
  2630. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2631. {
  2632. window.openFile = null;
  2633. });
  2634. };
  2635. /**
  2636. * Extracs the graph model from the given HTML data from a data transfer event.
  2637. */
  2638. EditorUi.prototype.extractGraphModelFromHtml = function(data)
  2639. {
  2640. var result = null;
  2641. try
  2642. {
  2643. var idx = data.indexOf('&lt;mxGraphModel ');
  2644. if (idx >= 0)
  2645. {
  2646. var idx2 = data.lastIndexOf('&lt;/mxGraphModel&gt;');
  2647. if (idx2 > idx)
  2648. {
  2649. result = data.substring(idx, idx2 + 21).replace(/&gt;/g, '>').
  2650. replace(/&lt;/g, '<').replace(/\\&quot;/g, '"').replace(/\n/g, '');
  2651. }
  2652. }
  2653. }
  2654. catch (e)
  2655. {
  2656. // ignore
  2657. }
  2658. return result;
  2659. };
  2660. /**
  2661. * Opens the given files in the editor.
  2662. */
  2663. EditorUi.prototype.extractGraphModelFromEvent = function(evt)
  2664. {
  2665. var result = null;
  2666. var data = null;
  2667. if (evt != null)
  2668. {
  2669. var provider = (evt.dataTransfer != null) ? evt.dataTransfer : evt.clipboardData;
  2670. if (provider != null)
  2671. {
  2672. if (document.documentMode == 10 || document.documentMode == 11)
  2673. {
  2674. data = provider.getData('Text');
  2675. }
  2676. else
  2677. {
  2678. data = (mxUtils.indexOf(provider.types, 'text/html') >= 0) ? provider.getData('text/html') : null;
  2679. if (mxUtils.indexOf(provider.types, 'text/plain' && (data == null || data.length == 0)))
  2680. {
  2681. data = provider.getData('text/plain');
  2682. }
  2683. }
  2684. if (data != null)
  2685. {
  2686. data = this.editor.graph.zapGremlins(mxUtils.trim(data));
  2687. // Tries parsing as HTML document with embedded XML
  2688. var xml = this.extractGraphModelFromHtml(data);
  2689. if (xml != null)
  2690. {
  2691. data = xml;
  2692. }
  2693. }
  2694. }
  2695. }
  2696. if (data != null && this.isCompatibleString(data))
  2697. {
  2698. result = data;
  2699. }
  2700. return result;
  2701. };
  2702. /**
  2703. * Hook for subclassers to return true if event data is a supported format.
  2704. * This implementation always returns false.
  2705. */
  2706. EditorUi.prototype.isCompatibleString = function(data)
  2707. {
  2708. return false;
  2709. };
  2710. /**
  2711. * Adds the label menu items to the given menu and parent.
  2712. */
  2713. EditorUi.prototype.saveFile = function(forceDialog)
  2714. {
  2715. if (!forceDialog && this.editor.filename != null)
  2716. {
  2717. this.save(this.editor.getOrCreateFilename());
  2718. }
  2719. else
  2720. {
  2721. var dlg = new FilenameDialog(this, this.editor.getOrCreateFilename(), mxResources.get('save'), mxUtils.bind(this, function(name)
  2722. {
  2723. this.save(name);
  2724. }), null, mxUtils.bind(this, function(name)
  2725. {
  2726. if (name != null && name.length > 0)
  2727. {
  2728. return true;
  2729. }
  2730. mxUtils.confirm(mxResources.get('invalidName'));
  2731. return false;
  2732. }));
  2733. this.showDialog(dlg.container, 300, 100, true, true);
  2734. dlg.init();
  2735. }
  2736. };
  2737. /**
  2738. * Saves the current graph under the given filename.
  2739. */
  2740. EditorUi.prototype.save = function(name)
  2741. {
  2742. if (name != null)
  2743. {
  2744. if (this.editor.graph.isEditing())
  2745. {
  2746. this.editor.graph.stopEditing();
  2747. }
  2748. var xml = mxUtils.getXml(this.editor.getGraphXml());
  2749. try
  2750. {
  2751. if (Editor.useLocalStorage)
  2752. {
  2753. if (localStorage.getItem(name) != null &&
  2754. !mxUtils.confirm(mxResources.get('replaceIt', [name])))
  2755. {
  2756. return;
  2757. }
  2758. localStorage.setItem(name, xml);
  2759. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('saved')) + ' ' + new Date());
  2760. }
  2761. else
  2762. {
  2763. if (xml.length < MAX_REQUEST_SIZE)
  2764. {
  2765. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(name) +
  2766. '&xml=' + encodeURIComponent(xml)).simulate(document, '_blank');
  2767. }
  2768. else
  2769. {
  2770. mxUtils.alert(mxResources.get('drawingTooLarge'));
  2771. mxUtils.popup(xml);
  2772. return;
  2773. }
  2774. }
  2775. this.editor.setModified(false);
  2776. this.editor.setFilename(name);
  2777. this.updateDocumentTitle();
  2778. }
  2779. catch (e)
  2780. {
  2781. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('errorSavingFile')));
  2782. }
  2783. }
  2784. };
  2785. /**
  2786. * Executes the given layout.
  2787. */
  2788. EditorUi.prototype.executeLayout = function(exec, animate, post)
  2789. {
  2790. var graph = this.editor.graph;
  2791. if (graph.isEnabled())
  2792. {
  2793. graph.getModel().beginUpdate();
  2794. try
  2795. {
  2796. exec();
  2797. }
  2798. catch (e)
  2799. {
  2800. throw e;
  2801. }
  2802. finally
  2803. {
  2804. // Animates the changes in the graph model except
  2805. // for Camino, where animation is too slow
  2806. if (this.allowAnimation && animate && navigator.userAgent.indexOf('Camino') < 0)
  2807. {
  2808. // New API for animating graph layout results asynchronously
  2809. var morph = new mxMorphing(graph);
  2810. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  2811. {
  2812. graph.getModel().endUpdate();
  2813. if (post != null)
  2814. {
  2815. post();
  2816. }
  2817. }));
  2818. morph.startAnimation();
  2819. }
  2820. else
  2821. {
  2822. graph.getModel().endUpdate();
  2823. if (post != null)
  2824. {
  2825. post();
  2826. }
  2827. }
  2828. }
  2829. }
  2830. };
  2831. /**
  2832. * Hides the current menu.
  2833. */
  2834. EditorUi.prototype.showImageDialog = function(title, value, fn, ignoreExisting)
  2835. {
  2836. var cellEditor = this.editor.graph.cellEditor;
  2837. var selState = cellEditor.saveSelection();
  2838. var newValue = mxUtils.prompt(title, value);
  2839. cellEditor.restoreSelection(selState);
  2840. if (newValue != null && newValue.length > 0)
  2841. {
  2842. var img = new Image();
  2843. img.onload = function()
  2844. {
  2845. fn(newValue, img.width, img.height);
  2846. };
  2847. img.onerror = function()
  2848. {
  2849. fn(null);
  2850. mxUtils.alert(mxResources.get('fileNotFound'));
  2851. };
  2852. img.src = newValue;
  2853. }
  2854. else
  2855. {
  2856. fn(null);
  2857. }
  2858. };
  2859. /**
  2860. * Hides the current menu.
  2861. */
  2862. EditorUi.prototype.showLinkDialog = function(value, btnLabel, fn)
  2863. {
  2864. var dlg = new LinkDialog(this, value, btnLabel, fn);
  2865. this.showDialog(dlg.container, 420, 90, true, true);
  2866. dlg.init();
  2867. };
  2868. /**
  2869. * Hides the current menu.
  2870. */
  2871. EditorUi.prototype.showBackgroundImageDialog = function(apply)
  2872. {
  2873. apply = (apply != null) ? apply : mxUtils.bind(this, function(image)
  2874. {
  2875. this.setBackgroundImage(image);
  2876. });
  2877. var newValue = mxUtils.prompt(mxResources.get('backgroundImage'), '');
  2878. if (newValue != null && newValue.length > 0)
  2879. {
  2880. var img = new Image();
  2881. img.onload = function()
  2882. {
  2883. apply(new mxImage(newValue, img.width, img.height));
  2884. };
  2885. img.onerror = function()
  2886. {
  2887. apply(null);
  2888. mxUtils.alert(mxResources.get('fileNotFound'));
  2889. };
  2890. img.src = newValue;
  2891. }
  2892. else
  2893. {
  2894. apply(null);
  2895. }
  2896. };
  2897. /**
  2898. * Loads the stylesheet for this graph.
  2899. */
  2900. EditorUi.prototype.setBackgroundImage = function(image)
  2901. {
  2902. this.editor.graph.setBackgroundImage(image);
  2903. this.editor.graph.view.validateBackgroundImage();
  2904. this.fireEvent(new mxEventObject('backgroundImageChanged'));
  2905. };
  2906. /**
  2907. * Creates the keyboard event handler for the current graph and history.
  2908. */
  2909. EditorUi.prototype.confirm = function(msg, okFn, cancelFn)
  2910. {
  2911. if (mxUtils.confirm(msg))
  2912. {
  2913. if (okFn != null)
  2914. {
  2915. okFn();
  2916. }
  2917. }
  2918. else if (cancelFn != null)
  2919. {
  2920. cancelFn();
  2921. }
  2922. };
  2923. /**
  2924. * Creates the keyboard event handler for the current graph and history.
  2925. */
  2926. EditorUi.prototype.createOutline = function(wnd)
  2927. {
  2928. var outline = new mxOutline(this.editor.graph);
  2929. outline.border = 20;
  2930. mxEvent.addListener(window, 'resize', function()
  2931. {
  2932. outline.update();
  2933. });
  2934. this.addListener('pageFormatChanged', function()
  2935. {
  2936. outline.update();
  2937. });
  2938. return outline;
  2939. };
  2940. /**
  2941. * Creates the keyboard event handler for the current graph and history.
  2942. */
  2943. EditorUi.prototype.createKeyHandler = function(editor)
  2944. {
  2945. var editorUi = this;
  2946. var graph = this.editor.graph;
  2947. var keyHandler = new mxKeyHandler(graph);
  2948. var isEventIgnored = keyHandler.isEventIgnored;
  2949. keyHandler.isEventIgnored = function(evt)
  2950. {
  2951. // Handles undo/redo/ctrl+./,/u via action and allows ctrl+b/i only if editing value is HTML (except for FF and Safari)
  2952. return (!this.isControlDown(evt) || mxEvent.isShiftDown(evt) || (evt.keyCode != 90 && evt.keyCode != 89 &&
  2953. evt.keyCode != 188 && evt.keyCode != 190 && evt.keyCode != 85)) && ((evt.keyCode != 66 && evt.keyCode != 73) ||
  2954. !this.isControlDown(evt) || (this.graph.cellEditor.isContentEditing() && !mxClient.IS_FF && !mxClient.IS_SF)) &&
  2955. isEventIgnored.apply(this, arguments);
  2956. };
  2957. // Ignores graph enabled state but not chromeless state
  2958. keyHandler.isEnabledForEvent = function(evt)
  2959. {
  2960. return (!mxEvent.isConsumed(evt) && this.isGraphEvent(evt) && this.isEnabled());
  2961. };
  2962. // Routes command-key to control-key on Mac
  2963. keyHandler.isControlDown = function(evt)
  2964. {
  2965. return mxEvent.isControlDown(evt) || (mxClient.IS_MAC && evt.metaKey);
  2966. };
  2967. var queue = [];
  2968. var thread = null;
  2969. // Helper function to move cells with the cursor keys
  2970. function nudge(keyCode, stepSize, resize)
  2971. {
  2972. queue.push(function()
  2973. {
  2974. if (!graph.isSelectionEmpty() && graph.isEnabled())
  2975. {
  2976. stepSize = (stepSize != null) ? stepSize : 1;
  2977. if (resize)
  2978. {
  2979. // Resizes all selected vertices
  2980. graph.getModel().beginUpdate();
  2981. try
  2982. {
  2983. var cells = graph.getSelectionCells();
  2984. for (var i = 0; i < cells.length; i++)
  2985. {
  2986. if (graph.getModel().isVertex(cells[i]) && graph.isCellResizable(cells[i]))
  2987. {
  2988. var geo = graph.getCellGeometry(cells[i]);
  2989. if (geo != null)
  2990. {
  2991. geo = geo.clone();
  2992. if (keyCode == 37)
  2993. {
  2994. geo.width = Math.max(0, geo.width - stepSize);
  2995. }
  2996. else if (keyCode == 38)
  2997. {
  2998. geo.height = Math.max(0, geo.height - stepSize);
  2999. }
  3000. else if (keyCode == 39)
  3001. {
  3002. geo.width += stepSize;
  3003. }
  3004. else if (keyCode == 40)
  3005. {
  3006. geo.height += stepSize;
  3007. }
  3008. graph.getModel().setGeometry(cells[i], geo);
  3009. }
  3010. }
  3011. }
  3012. }
  3013. finally
  3014. {
  3015. graph.getModel().endUpdate();
  3016. }
  3017. }
  3018. else
  3019. {
  3020. // Moves vertices up/down in a stack layout
  3021. var cell = graph.getSelectionCell();
  3022. var parent = graph.model.getParent(cell);
  3023. var layout = null;
  3024. if (graph.getSelectionCount() == 1 && graph.model.isVertex(cell) &&
  3025. graph.layoutManager != null && !graph.isCellLocked(cell))
  3026. {
  3027. layout = graph.layoutManager.getLayout(parent);
  3028. }
  3029. if (layout != null && layout.constructor == mxStackLayout)
  3030. {
  3031. var index = parent.getIndex(cell);
  3032. if (keyCode == 37 || keyCode == 38)
  3033. {
  3034. graph.model.add(parent, cell, Math.max(0, index - 1));
  3035. }
  3036. else if (keyCode == 39 ||keyCode == 40)
  3037. {
  3038. graph.model.add(parent, cell, Math.min(graph.model.getChildCount(parent), index + 1));
  3039. }
  3040. }
  3041. else
  3042. {
  3043. var dx = 0;
  3044. var dy = 0;
  3045. if (keyCode == 37)
  3046. {
  3047. dx = -stepSize;
  3048. }
  3049. else if (keyCode == 38)
  3050. {
  3051. dy = -stepSize;
  3052. }
  3053. else if (keyCode == 39)
  3054. {
  3055. dx = stepSize;
  3056. }
  3057. else if (keyCode == 40)
  3058. {
  3059. dy = stepSize;
  3060. }
  3061. graph.moveCells(graph.getMovableCells(graph.getSelectionCells()), dx, dy);
  3062. }
  3063. }
  3064. }
  3065. });
  3066. if (thread != null)
  3067. {
  3068. window.clearTimeout(thread);
  3069. }
  3070. thread = window.setTimeout(function()
  3071. {
  3072. if (queue.length > 0)
  3073. {
  3074. graph.getModel().beginUpdate();
  3075. try
  3076. {
  3077. for (var i = 0; i < queue.length; i++)
  3078. {
  3079. queue[i]();
  3080. }
  3081. queue = [];
  3082. }
  3083. finally
  3084. {
  3085. graph.getModel().endUpdate();
  3086. }
  3087. graph.scrollCellToVisible(graph.getSelectionCell());
  3088. }
  3089. }, 200);
  3090. };
  3091. // Overridden to handle special alt+shift+cursor keyboard shortcuts
  3092. var directions = {37: mxConstants.DIRECTION_WEST, 38: mxConstants.DIRECTION_NORTH,
  3093. 39: mxConstants.DIRECTION_EAST, 40: mxConstants.DIRECTION_SOUTH};
  3094. var keyHandlerGetFunction = keyHandler.getFunction;
  3095. // Alt+Shift+Keycode mapping to action
  3096. var altShiftActions = {67: this.actions.get('clearWaypoints')}; // Alt+Shift+C
  3097. mxKeyHandler.prototype.getFunction = function(evt)
  3098. {
  3099. if (graph.isEnabled())
  3100. {
  3101. // TODO: Add alt modified state in core API, here are some specific cases
  3102. if (!graph.isSelectionEmpty() && mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3103. {
  3104. var action = altShiftActions[evt.keyCode];
  3105. if (action != null)
  3106. {
  3107. return action.funct;
  3108. }
  3109. }
  3110. if (evt.keyCode == 9 && mxEvent.isAltDown(evt))
  3111. {
  3112. if (mxEvent.isShiftDown(evt))
  3113. {
  3114. // Alt+Shift+Tab
  3115. return function()
  3116. {
  3117. graph.selectParentCell();
  3118. };
  3119. }
  3120. else
  3121. {
  3122. // Alt+Tab
  3123. return function()
  3124. {
  3125. graph.selectChildCell();
  3126. };
  3127. }
  3128. }
  3129. else if (directions[evt.keyCode] != null && !graph.isSelectionEmpty())
  3130. {
  3131. if (mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3132. {
  3133. if (graph.model.isVertex(graph.getSelectionCell()))
  3134. {
  3135. return function()
  3136. {
  3137. var cells = graph.connectVertex(graph.getSelectionCell(), directions[evt.keyCode],
  3138. graph.defaultEdgeLength, evt, true);
  3139. if (cells != null && cells.length > 0)
  3140. {
  3141. if (cells.length == 1 && graph.model.isEdge(cells[0]))
  3142. {
  3143. graph.setSelectionCell(graph.model.getTerminal(cells[0], false));
  3144. }
  3145. else
  3146. {
  3147. graph.setSelectionCell(cells[cells.length - 1]);
  3148. }
  3149. if (editorUi.hoverIcons != null)
  3150. {
  3151. editorUi.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  3152. }
  3153. }
  3154. };
  3155. }
  3156. }
  3157. else
  3158. {
  3159. // Avoids consuming event if no vertex is selected by returning null below
  3160. // Cursor keys move and resize (ctrl) cells
  3161. if (this.isControlDown(evt))
  3162. {
  3163. return function()
  3164. {
  3165. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null, true);
  3166. };
  3167. }
  3168. else
  3169. {
  3170. return function()
  3171. {
  3172. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null);
  3173. };
  3174. }
  3175. }
  3176. }
  3177. }
  3178. return keyHandlerGetFunction.apply(this, arguments);
  3179. };
  3180. // Binds keystrokes to actions
  3181. keyHandler.bindAction = mxUtils.bind(this, function(code, control, key, shift)
  3182. {
  3183. var action = this.actions.get(key);
  3184. if (action != null)
  3185. {
  3186. var f = function()
  3187. {
  3188. if (action.isEnabled())
  3189. {
  3190. action.funct();
  3191. }
  3192. };
  3193. if (control)
  3194. {
  3195. if (shift)
  3196. {
  3197. keyHandler.bindControlShiftKey(code, f);
  3198. }
  3199. else
  3200. {
  3201. keyHandler.bindControlKey(code, f);
  3202. }
  3203. }
  3204. else
  3205. {
  3206. if (shift)
  3207. {
  3208. keyHandler.bindShiftKey(code, f);
  3209. }
  3210. else
  3211. {
  3212. keyHandler.bindKey(code, f);
  3213. }
  3214. }
  3215. }
  3216. });
  3217. var ui = this;
  3218. var keyHandlerEscape = keyHandler.escape;
  3219. keyHandler.escape = function(evt)
  3220. {
  3221. keyHandlerEscape.apply(this, arguments);
  3222. };
  3223. // Ignores enter keystroke. Remove this line if you want the
  3224. // enter keystroke to stop editing. N, W, T are reserved.
  3225. keyHandler.enter = function() {};
  3226. keyHandler.bindControlShiftKey(36, function() { graph.exitGroup(); }); // Ctrl+Shift+Home
  3227. keyHandler.bindControlShiftKey(35, function() { graph.enterGroup(); }); // Ctrl+Shift+End
  3228. keyHandler.bindKey(36, function() { graph.home(); }); // Home
  3229. keyHandler.bindKey(35, function() { graph.refresh(); }); // End
  3230. keyHandler.bindAction(107, true, 'zoomIn'); // Ctrl+Plus
  3231. keyHandler.bindAction(109, true, 'zoomOut'); // Ctrl+Minus
  3232. keyHandler.bindAction(80, true, 'print'); // Ctrl+P
  3233. keyHandler.bindAction(79, true, 'outline', true); // Ctrl+Shift+O
  3234. keyHandler.bindAction(112, false, 'about'); // F1
  3235. if (!this.editor.chromeless)
  3236. {
  3237. keyHandler.bindControlKey(36, function() { if (graph.isEnabled()) { graph.foldCells(true); }}); // Ctrl+Home
  3238. keyHandler.bindControlKey(35, function() { if (graph.isEnabled()) { graph.foldCells(false); }}); // Ctrl+End
  3239. keyHandler.bindControlKey(13, function() { if (graph.isEnabled()) { graph.setSelectionCells(graph.duplicateCells(graph.getSelectionCells(), false)); }}); // Ctrl+Enter
  3240. keyHandler.bindAction(8, false, 'delete'); // Backspace
  3241. keyHandler.bindAction(8, true, 'deleteAll'); // Backspace
  3242. keyHandler.bindAction(46, false, 'delete'); // Delete
  3243. keyHandler.bindAction(46, true, 'deleteAll'); // Ctrl+Delete
  3244. keyHandler.bindAction(72, true, 'resetView'); // Ctrl+H
  3245. keyHandler.bindAction(72, true, 'fitWindow', true); // Ctrl+Shift+H
  3246. keyHandler.bindAction(74, true, 'fitPage'); // Ctrl+J
  3247. keyHandler.bindAction(74, true, 'fitTwoPages', true); // Ctrl+Shift+J
  3248. keyHandler.bindAction(48, true, 'customZoom'); // Ctrl+0
  3249. keyHandler.bindAction(82, true, 'turn'); // Ctrl+R
  3250. keyHandler.bindAction(82, true, 'clearDefaultStyle', true); // Ctrl+Shift+R
  3251. keyHandler.bindAction(83, true, 'save'); // Ctrl+S
  3252. keyHandler.bindAction(83, true, 'saveAs', true); // Ctrl+Shift+S
  3253. keyHandler.bindAction(65, true, 'selectAll'); // Ctrl+A
  3254. keyHandler.bindAction(65, true, 'selectNone', true); // Ctrl+A
  3255. keyHandler.bindAction(73, true, 'selectVertices', true); // Ctrl+Shift+I
  3256. keyHandler.bindAction(69, true, 'selectEdges', true); // Ctrl+Shift+E
  3257. keyHandler.bindAction(69, true, 'editStyle'); // Ctrl+E
  3258. keyHandler.bindAction(66, true, 'bold'); // Ctrl+B
  3259. keyHandler.bindAction(66, true, 'toBack', true); // Ctrl+Shift+B
  3260. keyHandler.bindAction(70, true, 'toFront', true); // Ctrl+Shift+F
  3261. keyHandler.bindAction(68, true, 'duplicate'); // Ctrl+D
  3262. keyHandler.bindAction(68, true, 'setAsDefaultStyle', true); // Ctrl+Shift+D
  3263. keyHandler.bindAction(90, true, 'undo'); // Ctrl+Z
  3264. keyHandler.bindAction(89, true, 'autosize', true); // Ctrl+Shift+Y
  3265. keyHandler.bindAction(88, true, 'cut'); // Ctrl+X
  3266. keyHandler.bindAction(67, true, 'copy'); // Ctrl+C
  3267. keyHandler.bindAction(81, true, 'connectionArrows'); // Ctrl+Q
  3268. keyHandler.bindAction(81, true, 'connectionPoints', true); // Ctrl+Shift+Q
  3269. keyHandler.bindAction(86, true, 'paste'); // Ctrl+V
  3270. keyHandler.bindAction(71, true, 'group'); // Ctrl+G
  3271. keyHandler.bindAction(77, true, 'editData'); // Ctrl+M
  3272. keyHandler.bindAction(71, true, 'grid', true); // Ctrl+Shift+G
  3273. keyHandler.bindAction(73, true, 'italic'); // Ctrl+I
  3274. keyHandler.bindAction(76, true, 'lockUnlock'); // Ctrl+L
  3275. keyHandler.bindAction(76, true, 'layers', true); // Ctrl+Shift+L
  3276. keyHandler.bindAction(80, true, 'formatPanel', true); // Ctrl+Shift+P
  3277. keyHandler.bindAction(85, true, 'underline'); // Ctrl+U
  3278. keyHandler.bindAction(85, true, 'ungroup', true); // Ctrl+Shift+U
  3279. keyHandler.bindAction(190, true, 'superscript'); // Ctrl+.
  3280. keyHandler.bindAction(188, true, 'subscript'); // Ctrl+,
  3281. keyHandler.bindKey(13, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // Enter
  3282. keyHandler.bindKey(113, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // F2
  3283. }
  3284. if (!mxClient.IS_WIN)
  3285. {
  3286. keyHandler.bindAction(90, true, 'redo', true); // Ctrl+Shift+Z
  3287. }
  3288. else
  3289. {
  3290. keyHandler.bindAction(89, true, 'redo'); // Ctrl+Y
  3291. }
  3292. return keyHandler;
  3293. };
  3294. /**
  3295. * Creates the keyboard event handler for the current graph and history.
  3296. */
  3297. EditorUi.prototype.destroy = function()
  3298. {
  3299. if (this.editor != null)
  3300. {
  3301. this.editor.destroy();
  3302. this.editor = null;
  3303. }
  3304. if (this.menubar != null)
  3305. {
  3306. this.menubar.destroy();
  3307. this.menubar = null;
  3308. }
  3309. if (this.toolbar != null)
  3310. {
  3311. this.toolbar.destroy();
  3312. this.toolbar = null;
  3313. }
  3314. if (this.sidebar != null)
  3315. {
  3316. this.sidebar.destroy();
  3317. this.sidebar = null;
  3318. }
  3319. if (this.keyHandler != null)
  3320. {
  3321. this.keyHandler.destroy();
  3322. this.keyHandler = null;
  3323. }
  3324. if (this.keydownHandler != null)
  3325. {
  3326. mxEvent.removeListener(document, 'keydown', this.keydownHandler);
  3327. this.keydownHandler = null;
  3328. }
  3329. if (this.keyupHandler != null)
  3330. {
  3331. mxEvent.removeListener(document, 'keyup', this.keyupHandler);
  3332. this.keyupHandler = null;
  3333. }
  3334. if (this.resizeHandler != null)
  3335. {
  3336. mxEvent.removeListener(window, 'resize', this.resizeHandler);
  3337. this.resizeHandler = null;
  3338. }
  3339. if (this.gestureHandler != null)
  3340. {
  3341. mxEvent.removeGestureListeners(document, this.gestureHandler);
  3342. this.gestureHandler = null;
  3343. }
  3344. if (this.orientationChangeHandler != null)
  3345. {
  3346. mxEvent.removeListener(window, 'orientationchange', this.orientationChangeHandler);
  3347. this.orientationChangeHandler = null;
  3348. }
  3349. if (this.scrollHandler != null)
  3350. {
  3351. mxEvent.removeListener(window, 'scroll', this.scrollHandler);
  3352. this.scrollHandler = null;
  3353. }
  3354. if (this.destroyFunctions != null)
  3355. {
  3356. for (var i = 0; i < this.destroyFunctions.length; i++)
  3357. {
  3358. this.destroyFunctions[i]();
  3359. }
  3360. this.destroyFunctions = null;
  3361. }
  3362. var c = [this.menubarContainer, this.toolbarContainer, this.sidebarContainer,
  3363. this.formatContainer, this.diagramContainer, this.footerContainer,
  3364. this.chromelessToolbar, this.hsplit, this.sidebarFooterContainer,
  3365. this.layersDialog];
  3366. for (var i = 0; i < c.length; i++)
  3367. {
  3368. if (c[i] != null && c[i].parentNode != null)
  3369. {
  3370. c[i].parentNode.removeChild(c[i]);
  3371. }
  3372. }
  3373. };