EditorUi.js 102 KB

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