Dialogs.js 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Constructs a new dialog.
  6. */
  7. function Dialog(editorUi, elt, w, h, modal, closable, onClose)
  8. {
  9. var dx = 0;
  10. if (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8))
  11. {
  12. // Adds padding as a workaround for box model in older IE versions
  13. // This needs to match the total padding of geDialog in CSS
  14. dx = 80;
  15. }
  16. w += dx;
  17. h += dx;
  18. var left = Math.max(0, Math.round((document.body.scrollWidth - w) / 2));
  19. var top = Math.max(0, Math.round((Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) - h - editorUi.footerHeight) / 3));
  20. // Increments zIndex to put subdialogs and background over existing dialogs and background
  21. if (editorUi.dialogs.length > 0)
  22. {
  23. this.zIndex += editorUi.dialogs.length * 2;
  24. }
  25. var div = editorUi.createDiv('geDialog');
  26. div.style.width = w + 'px';
  27. div.style.height = h + 'px';
  28. div.style.left = left + 'px';
  29. div.style.top = top + 'px';
  30. div.style.zIndex = this.zIndex;
  31. if (this.bg == null)
  32. {
  33. this.bg = editorUi.createDiv('background');
  34. this.bg.style.position = 'absolute';
  35. this.bg.style.background = 'white';
  36. this.bg.style.left = '0px';
  37. this.bg.style.top = '0px';
  38. this.bg.style.bottom = '0px';
  39. this.bg.style.right = '0px';
  40. this.bg.style.zIndex = this.zIndex - 2;
  41. mxUtils.setOpacity(this.bg, this.bgOpacity);
  42. if (mxClient.IS_QUIRKS)
  43. {
  44. new mxDivResizer(this.bg);
  45. }
  46. }
  47. if (modal)
  48. {
  49. document.body.appendChild(this.bg);
  50. }
  51. div.appendChild(elt);
  52. document.body.appendChild(div);
  53. if (closable)
  54. {
  55. var img = document.createElement('img');
  56. img.setAttribute('src', Dialog.prototype.closeImage);
  57. img.setAttribute('title', mxResources.get('close'));
  58. img.className = 'geDialogClose';
  59. img.style.top = (top + 14) + 'px';
  60. img.style.left = (left + w + 38 - dx) + 'px';
  61. img.style.zIndex = this.zIndex;
  62. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  63. {
  64. editorUi.hideDialog(true);
  65. }));
  66. document.body.appendChild(img);
  67. this.dialogImg = img;
  68. mxEvent.addListener(this.bg, 'click', mxUtils.bind(this, function()
  69. {
  70. editorUi.hideDialog(true);
  71. }));
  72. }
  73. this.onDialogClose = onClose;
  74. this.container = div;
  75. editorUi.editor.fireEvent(new mxEventObject('showDialog'));
  76. };
  77. /**
  78. *
  79. */
  80. Dialog.prototype.zIndex = mxPopupMenu.prototype.zIndex - 1;
  81. /**
  82. *
  83. */
  84. Dialog.prototype.noColorImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/nocolor.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkEzRDlBMUUwODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkEzRDlBMUUxODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QTNEOUExREU4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QTNEOUExREY4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5xh3fmAAAABlBMVEX////MzMw46qqDAAAAGElEQVR42mJggAJGKGAYIIGBth8KAAIMAEUQAIElnLuQAAAAAElFTkSuQmCC';
  85. /**
  86. *
  87. */
  88. Dialog.prototype.closeImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/close.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAQMAAADaX5RTAAAABlBMVEV7mr3///+wksspAAAAAnRSTlP/AOW3MEoAAAAdSURBVAgdY9jXwCDDwNDRwHCwgeExmASygSL7GgB12QiqNHZZIwAAAABJRU5ErkJggg==';
  89. /**
  90. *
  91. */
  92. Dialog.prototype.clearImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/clear.gif' : 'data:image/gif;base64,R0lGODlhDQAKAIABAMDAwP///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OUIzOEM1NzI4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OUIzOEM1NzM4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5QjM4QzU3MDg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5QjM4QzU3MTg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAEAAAEALAAAAAANAAoAAAIXTGCJebD9jEOTqRlttXdrB32PJ2ncyRQAOw==';
  93. /**
  94. *
  95. */
  96. Dialog.prototype.lockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/locked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCODExNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCODIxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3RjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI4MDE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PvqMCFYAAAAVUExURZmZmb+/v7KysqysrMzMzLGxsf///4g8N1cAAAAHdFJOU////////wAaSwNGAAAAPElEQVR42lTMQQ4AIQgEwUa0//9kTQirOweYOgDqAMbZUr10AGlAwx4/BJ2QJ4U0L5brYjovvpv32xZgAHZaATFtMbu4AAAAAElFTkSuQmCC';
  97. /**
  98. *
  99. */
  100. Dialog.prototype.unlockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/unlocked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCN0QxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCN0UxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3QjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI3QzE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkKMpVwAAAAYUExURZmZmbKysr+/v6ysrOXl5czMzLGxsf///zHN5lwAAAAIdFJOU/////////8A3oO9WQAAADxJREFUeNpUzFESACAEBNBVsfe/cZJU+8Mzs8CIABCidtfGOndnYsT40HDSiCcbPdoJo10o9aI677cpwACRoAF3dFNlswAAAABJRU5ErkJggg==';
  101. /**
  102. * Removes the dialog from the DOM.
  103. */
  104. Dialog.prototype.bgOpacity = 80;
  105. /**
  106. * Removes the dialog from the DOM.
  107. */
  108. Dialog.prototype.close = function(cancel)
  109. {
  110. if (this.onDialogClose != null)
  111. {
  112. this.onDialogClose(cancel);
  113. this.onDialogClose = null;
  114. }
  115. if (this.dialogImg != null)
  116. {
  117. this.dialogImg.parentNode.removeChild(this.dialogImg);
  118. this.dialogImg = null;
  119. }
  120. if (this.bg != null && this.bg.parentNode != null)
  121. {
  122. this.bg.parentNode.removeChild(this.bg);
  123. }
  124. this.container.parentNode.removeChild(this.container);
  125. };
  126. /**
  127. * Constructs a new open dialog.
  128. */
  129. var OpenDialog = function()
  130. {
  131. var iframe = document.createElement('iframe');
  132. iframe.style.backgroundColor = 'transparent';
  133. iframe.allowTransparency = 'true';
  134. iframe.style.borderStyle = 'none';
  135. iframe.style.borderWidth = '0px';
  136. iframe.style.overflow = 'hidden';
  137. iframe.frameBorder = '0';
  138. // Adds padding as a workaround for box model in older IE versions
  139. var dx = (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8)) ? 20 : 0;
  140. iframe.setAttribute('width', (((Editor.useLocalStorage) ? 640 : 320) + dx) + 'px');
  141. iframe.setAttribute('height', (((Editor.useLocalStorage) ? 480 : 220) + dx) + 'px');
  142. iframe.setAttribute('src', OPEN_FORM);
  143. this.container = iframe;
  144. };
  145. /**
  146. * Constructs a new color dialog.
  147. */
  148. var ColorDialog = function(editorUi, color, apply, cancelFn)
  149. {
  150. this.editorUi = editorUi;
  151. var input = document.createElement('input');
  152. input.style.marginBottom = '10px';
  153. input.style.width = '216px';
  154. // Required for picker to render in IE
  155. if (mxClient.IS_IE)
  156. {
  157. input.style.marginTop = '10px';
  158. document.body.appendChild(input);
  159. }
  160. this.init = function()
  161. {
  162. if (!mxClient.IS_TOUCH)
  163. {
  164. input.focus();
  165. }
  166. };
  167. var picker = new jscolor.color(input);
  168. picker.pickerOnfocus = false;
  169. picker.showPicker();
  170. var div = document.createElement('div');
  171. jscolor.picker.box.style.position = 'relative';
  172. jscolor.picker.box.style.width = '230px';
  173. jscolor.picker.box.style.height = '100px';
  174. jscolor.picker.box.style.paddingBottom = '10px';
  175. div.appendChild(jscolor.picker.box);
  176. var center = document.createElement('center');
  177. function addPresets(presets, rowLength, defaultColor)
  178. {
  179. rowLength = (rowLength != null) ? rowLength : 12;
  180. var table = document.createElement('table');
  181. table.style.borderCollapse = 'collapse';
  182. table.setAttribute('cellspacing', '0');
  183. table.style.marginBottom = '20px';
  184. table.style.cellSpacing = '0px';
  185. var tbody = document.createElement('tbody');
  186. table.appendChild(tbody);
  187. var rows = presets.length / rowLength;
  188. for (var row = 0; row < rows; row++)
  189. {
  190. var tr = document.createElement('tr');
  191. for (var i = 0; i < rowLength; i++)
  192. {
  193. (function(clr)
  194. {
  195. var td = document.createElement('td');
  196. td.style.border = '1px solid black';
  197. td.style.padding = '0px';
  198. td.style.width = '16px';
  199. td.style.height = '16px';
  200. if (clr == null)
  201. {
  202. clr = defaultColor;
  203. }
  204. if (clr == 'none')
  205. {
  206. td.style.background = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  207. }
  208. else
  209. {
  210. td.style.backgroundColor = '#' + clr;
  211. }
  212. tr.appendChild(td);
  213. if (clr != null)
  214. {
  215. td.style.cursor = 'pointer';
  216. mxEvent.addListener(td, 'click', function()
  217. {
  218. if (clr == 'none')
  219. {
  220. picker.fromString('ffffff');
  221. input.value = 'none';
  222. }
  223. else
  224. {
  225. picker.fromString(clr);
  226. }
  227. });
  228. }
  229. })(presets[row * rowLength + i]);
  230. }
  231. tbody.appendChild(tr);
  232. }
  233. center.appendChild(table);
  234. return table;
  235. };
  236. div.appendChild(input);
  237. mxUtils.br(div);
  238. // Adds recent colors
  239. var table = addPresets((ColorDialog.recentColors.length == 0) ? ['FFFFFF'] : ColorDialog.recentColors, 12, 'FFFFFF');
  240. table.style.marginBottom = '8px';
  241. // Adds presets
  242. var table = addPresets(['E6D0DE', 'CDA2BE', 'B5739D', 'E1D5E7', 'C3ABD0', 'A680B8', 'D4E1F5', 'A9C4EB', '7EA6E0', 'D5E8D4', '9AC7BF', '67AB9F', 'D5E8D4', 'B9E0A5', '97D077', 'FFF2CC', 'FFE599', 'FFD966', 'FFF4C3', 'FFCE9F', 'FFB570', 'F8CECC', 'F19C99', 'EA6B66'], 12);
  243. table.style.marginBottom = '8px';
  244. table = addPresets(['none', 'FFFFFF', 'E6E6E6', 'CCCCCC', 'B3B3B3', '999999', '808080', '666666', '4D4D4D', '333333', '1A1A1A', '000000', 'FFCCCC', 'FFE6CC', 'FFFFCC', 'E6FFCC', 'CCFFCC', 'CCFFE6', 'CCFFFF', 'CCE5FF', 'CCCCFF', 'E5CCFF', 'FFCCFF', 'FFCCE6', 'FF9999', 'FFCC99', 'FFFF99', 'CCFF99', '99FF99', '99FFCC', '99FFFF', '99CCFF', '9999FF', 'CC99FF', 'FF99FF', 'FF99CC', 'FF6666', 'FFB366', 'FFFF66', 'B3FF66', '66FF66', '66FFB3', '66FFFF', '66B2FF', '6666FF', 'B266FF', 'FF66FF', 'FF66B3', 'FF3333', 'FF9933', 'FFFF33', '99FF33', '33FF33', '33FF99', '33FFFF', '3399FF', '3333FF', '9933FF', 'FF33FF', 'FF3399', 'FF0000', 'FF8000', 'FFFF00', '80FF00', '00FF00', '00FF80', '00FFFF', '007FFF', '0000FF', '7F00FF', 'FF00FF', 'FF0080', 'CC0000', 'CC6600', 'CCCC00', '66CC00', '00CC00', '00CC66', '00CCCC', '0066CC', '0000CC', '6600CC', 'CC00CC', 'CC0066', '990000', '994C00', '999900', '4D9900', '009900', '00994D', '009999', '004C99', '000099', '4C0099', '990099', '99004D', '660000', '663300', '666600', '336600', '006600', '006633', '006666', '003366', '000066', '330066', '660066', '660033', '330000', '331A00', '333300', '1A3300', '003300', '00331A', '003333', '001933', '000033', '190033', '330033', '33001A']);
  245. table.style.marginBottom = '16px';
  246. div.appendChild(center);
  247. var buttons = document.createElement('div');
  248. buttons.style.textAlign = 'right';
  249. buttons.style.whiteSpace = 'nowrap';
  250. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  251. {
  252. editorUi.hideDialog();
  253. if (cancelFn != null)
  254. {
  255. cancelFn();
  256. }
  257. });
  258. cancelBtn.className = 'geBtn';
  259. if (editorUi.editor.cancelFirst)
  260. {
  261. buttons.appendChild(cancelBtn);
  262. }
  263. var applyFunction = (apply != null) ? apply : this.createApplyFunction();
  264. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  265. {
  266. var color = input.value;
  267. ColorDialog.addRecentColor(color, 12);
  268. if (color != 'none' && color.charAt(0) != '#')
  269. {
  270. color = '#' + color;
  271. }
  272. applyFunction(color);
  273. editorUi.hideDialog();
  274. });
  275. applyBtn.className = 'geBtn gePrimaryBtn';
  276. buttons.appendChild(applyBtn);
  277. if (!editorUi.editor.cancelFirst)
  278. {
  279. buttons.appendChild(cancelBtn);
  280. }
  281. if (color != null)
  282. {
  283. if (color == 'none')
  284. {
  285. picker.fromString('ffffff');
  286. input.value = 'none';
  287. }
  288. else
  289. {
  290. picker.fromString(color);
  291. }
  292. }
  293. div.appendChild(buttons);
  294. this.picker = picker;
  295. this.colorInput = input;
  296. // LATER: Only fires if input if focused, should always
  297. // fire if this dialog is showing.
  298. mxEvent.addListener(div, 'keydown', function(e)
  299. {
  300. if (e.keyCode == 27)
  301. {
  302. editorUi.hideDialog();
  303. if (cancelFn != null)
  304. {
  305. cancelFn();
  306. }
  307. mxEvent.consume(e);
  308. }
  309. });
  310. this.container = div;
  311. };
  312. /* Creates function to apply value */
  313. ColorDialog.prototype.createApplyFunction = function()
  314. {
  315. return mxUtils.bind(this, function(color)
  316. {
  317. var graph = this.editorUi.editor.graph;
  318. graph.getModel().beginUpdate();
  319. try
  320. {
  321. graph.setCellStyles(this.currentColorKey, color);
  322. this.editorUi.fireEvent(new mxEventObject('styleChanged', 'keys', [this.currentColorKey],
  323. 'values', [color], 'cells', graph.getSelectionCells()));
  324. }
  325. finally
  326. {
  327. graph.getModel().endUpdate();
  328. }
  329. });
  330. };
  331. /**
  332. *
  333. */
  334. ColorDialog.recentColors = [];
  335. /**
  336. * Adds recent color for later use.
  337. */
  338. ColorDialog.addRecentColor = function(color, max)
  339. {
  340. if (color != null)
  341. {
  342. mxUtils.remove(color, ColorDialog.recentColors);
  343. ColorDialog.recentColors.splice(0, 0, color);
  344. if (ColorDialog.recentColors.length > max)
  345. {
  346. ColorDialog.recentColors.pop();
  347. }
  348. }
  349. };
  350. /**
  351. * Constructs a new about dialog.
  352. */
  353. var AboutDialog = function(editorUi)
  354. {
  355. var div = document.createElement('div');
  356. div.setAttribute('align', 'center');
  357. var h3 = document.createElement('h3');
  358. mxUtils.write(h3, mxResources.get('about') + ' GraphEditor');
  359. div.appendChild(h3);
  360. var img = document.createElement('img');
  361. img.style.border = '0px';
  362. img.setAttribute('width', '176');
  363. img.setAttribute('width', '151');
  364. img.setAttribute('src', IMAGE_PATH + '/logo.png');
  365. div.appendChild(img);
  366. mxUtils.br(div);
  367. mxUtils.write(div, 'Powered by mxGraph ' + mxClient.VERSION);
  368. mxUtils.br(div);
  369. var link = document.createElement('a');
  370. link.setAttribute('href', 'http://www.jgraph.com/');
  371. link.setAttribute('target', '_blank');
  372. mxUtils.write(link, 'www.jgraph.com');
  373. div.appendChild(link);
  374. mxUtils.br(div);
  375. mxUtils.br(div);
  376. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  377. {
  378. editorUi.hideDialog();
  379. });
  380. closeBtn.className = 'geBtn gePrimaryBtn';
  381. div.appendChild(closeBtn);
  382. this.container = div;
  383. };
  384. /**
  385. * Constructs a new page setup dialog.
  386. */
  387. var PageSetupDialog = function(editorUi)
  388. {
  389. var graph = editorUi.editor.graph;
  390. var row, td;
  391. var table = document.createElement('table');
  392. table.style.width = '100%';
  393. table.style.height = '100%';
  394. var tbody = document.createElement('tbody');
  395. row = document.createElement('tr');
  396. td = document.createElement('td');
  397. td.style.verticalAlign = 'top';
  398. td.style.fontSize = '10pt';
  399. mxUtils.write(td, mxResources.get('paperSize') + ':');
  400. row.appendChild(td);
  401. td = document.createElement('td');
  402. td.style.verticalAlign = 'top';
  403. td.style.fontSize = '10pt';
  404. var accessor = PageSetupDialog.addPageFormatPanel(td, 'pagesetupdialog', graph.pageFormat);
  405. row.appendChild(td);
  406. tbody.appendChild(row);
  407. row = document.createElement('tr');
  408. td = document.createElement('td');
  409. mxUtils.write(td, mxResources.get('background') + ':');
  410. row.appendChild(td);
  411. td = document.createElement('td');
  412. td.style.whiteSpace = 'nowrap';
  413. var backgroundInput = document.createElement('input');
  414. backgroundInput.setAttribute('type', 'text');
  415. var backgroundButton = document.createElement('button');
  416. backgroundButton.style.width = '18px';
  417. backgroundButton.style.height = '18px';
  418. backgroundButton.style.marginRight = '20px';
  419. backgroundButton.style.backgroundPosition = 'center center';
  420. backgroundButton.style.backgroundRepeat = 'no-repeat';
  421. var newBackgroundColor = graph.background;
  422. function updateBackgroundColor()
  423. {
  424. if (newBackgroundColor == null || newBackgroundColor == mxConstants.NONE)
  425. {
  426. backgroundButton.style.backgroundColor = '';
  427. backgroundButton.style.backgroundImage = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  428. }
  429. else
  430. {
  431. backgroundButton.style.backgroundColor = newBackgroundColor;
  432. backgroundButton.style.backgroundImage = '';
  433. }
  434. };
  435. updateBackgroundColor();
  436. mxEvent.addListener(backgroundButton, 'click', function(evt)
  437. {
  438. editorUi.pickColor(newBackgroundColor || 'none', function(color)
  439. {
  440. newBackgroundColor = color;
  441. updateBackgroundColor();
  442. });
  443. mxEvent.consume(evt);
  444. });
  445. td.appendChild(backgroundButton);
  446. mxUtils.write(td, mxResources.get('gridSize') + ':');
  447. var gridSizeInput = document.createElement('input');
  448. gridSizeInput.setAttribute('type', 'number');
  449. gridSizeInput.setAttribute('min', '0');
  450. gridSizeInput.style.width = '40px';
  451. gridSizeInput.style.marginLeft = '6px';
  452. gridSizeInput.value = graph.getGridSize();
  453. td.appendChild(gridSizeInput);
  454. mxEvent.addListener(gridSizeInput, 'change', function()
  455. {
  456. var value = parseInt(gridSizeInput.value);
  457. gridSizeInput.value = Math.max(1, (isNaN(value)) ? graph.getGridSize() : value);
  458. });
  459. row.appendChild(td);
  460. tbody.appendChild(row);
  461. row = document.createElement('tr');
  462. td = document.createElement('td');
  463. mxUtils.write(td, mxResources.get('image') + ':');
  464. row.appendChild(td);
  465. td = document.createElement('td');
  466. var changeImageLink = document.createElement('a');
  467. changeImageLink.style.textDecoration = 'underline';
  468. changeImageLink.style.cursor = 'pointer';
  469. changeImageLink.style.color = '#a0a0a0';
  470. var newBackgroundImage = graph.backgroundImage;
  471. function updateBackgroundImage()
  472. {
  473. if (newBackgroundImage == null)
  474. {
  475. changeImageLink.removeAttribute('title');
  476. changeImageLink.style.fontSize = '';
  477. changeImageLink.innerHTML = mxResources.get('change') + '...';
  478. }
  479. else
  480. {
  481. changeImageLink.setAttribute('title', newBackgroundImage.src);
  482. changeImageLink.style.fontSize = '11px';
  483. changeImageLink.innerHTML = newBackgroundImage.src.substring(0, 42) + '...';
  484. }
  485. };
  486. mxEvent.addListener(changeImageLink, 'click', function(evt)
  487. {
  488. editorUi.showBackgroundImageDialog(function(image)
  489. {
  490. newBackgroundImage = image;
  491. updateBackgroundImage();
  492. });
  493. mxEvent.consume(evt);
  494. });
  495. updateBackgroundImage();
  496. td.appendChild(changeImageLink);
  497. row.appendChild(td);
  498. tbody.appendChild(row);
  499. row = document.createElement('tr');
  500. td = document.createElement('td');
  501. td.colSpan = 2;
  502. td.style.paddingTop = '16px';
  503. td.setAttribute('align', 'right');
  504. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  505. {
  506. editorUi.hideDialog();
  507. });
  508. cancelBtn.className = 'geBtn';
  509. if (editorUi.editor.cancelFirst)
  510. {
  511. td.appendChild(cancelBtn);
  512. }
  513. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  514. {
  515. editorUi.hideDialog();
  516. editorUi.setPageFormat(accessor.get());
  517. if (graph.background != newBackgroundColor)
  518. {
  519. editorUi.setBackgroundColor(newBackgroundColor);
  520. }
  521. if (graph.backgroundImage !== newBackgroundImage)
  522. {
  523. editorUi.setBackgroundImage(newBackgroundImage);
  524. }
  525. if (graph.gridSize !== gridSizeInput.value)
  526. {
  527. graph.setGridSize(parseInt(gridSizeInput.value));
  528. }
  529. });
  530. applyBtn.className = 'geBtn gePrimaryBtn';
  531. td.appendChild(applyBtn);
  532. if (!editorUi.editor.cancelFirst)
  533. {
  534. td.appendChild(cancelBtn);
  535. }
  536. row.appendChild(td);
  537. tbody.appendChild(row);
  538. table.appendChild(tbody);
  539. this.container = table;
  540. };
  541. /**
  542. *
  543. */
  544. PageSetupDialog.addPageFormatPanel = function(div, namePostfix, pageFormat, pageFormatListener)
  545. {
  546. var formatName = 'format-' + namePostfix;
  547. var portraitCheckBox = document.createElement('input');
  548. portraitCheckBox.setAttribute('name', formatName);
  549. portraitCheckBox.setAttribute('type', 'radio');
  550. portraitCheckBox.setAttribute('value', 'portrait');
  551. var landscapeCheckBox = document.createElement('input');
  552. landscapeCheckBox.setAttribute('name', formatName);
  553. landscapeCheckBox.setAttribute('type', 'radio');
  554. landscapeCheckBox.setAttribute('value', 'landscape');
  555. var paperSizeSelect = document.createElement('select');
  556. paperSizeSelect.style.marginBottom = '8px';
  557. paperSizeSelect.style.width = '202px';
  558. var formatDiv = document.createElement('div');
  559. formatDiv.style.marginLeft = '4px';
  560. formatDiv.style.width = '210px';
  561. formatDiv.style.height = '24px';
  562. portraitCheckBox.style.marginRight = '6px';
  563. formatDiv.appendChild(portraitCheckBox);
  564. var portraitSpan = document.createElement('span');
  565. portraitSpan.style.maxWidth = '100px';
  566. mxUtils.write(portraitSpan, mxResources.get('portrait'));
  567. formatDiv.appendChild(portraitSpan);
  568. landscapeCheckBox.style.marginLeft = '10px';
  569. landscapeCheckBox.style.marginRight = '6px';
  570. formatDiv.appendChild(landscapeCheckBox);
  571. var landscapeSpan = document.createElement('span');
  572. landscapeSpan.style.width = '100px';
  573. mxUtils.write(landscapeSpan, mxResources.get('landscape'));
  574. formatDiv.appendChild(landscapeSpan)
  575. var customDiv = document.createElement('div');
  576. customDiv.style.marginLeft = '4px';
  577. customDiv.style.width = '210px';
  578. customDiv.style.height = '24px';
  579. var widthInput = document.createElement('input');
  580. widthInput.setAttribute('size', '6');
  581. widthInput.setAttribute('value', pageFormat.width);
  582. customDiv.appendChild(widthInput);
  583. mxUtils.write(customDiv, ' x ');
  584. var heightInput = document.createElement('input');
  585. heightInput.setAttribute('size', '6');
  586. heightInput.setAttribute('value', pageFormat.height);
  587. customDiv.appendChild(heightInput);
  588. mxUtils.write(customDiv, ' pt');
  589. formatDiv.style.display = 'none';
  590. customDiv.style.display = 'none';
  591. var pf = new Object();
  592. var formats = PageSetupDialog.getFormats();
  593. for (var i = 0; i < formats.length; i++)
  594. {
  595. var f = formats[i];
  596. pf[f.key] = f;
  597. var paperSizeOption = document.createElement('option');
  598. paperSizeOption.setAttribute('value', f.key);
  599. mxUtils.write(paperSizeOption, f.title);
  600. paperSizeSelect.appendChild(paperSizeOption);
  601. }
  602. var customSize = false;
  603. function listener(sender, evt, force)
  604. {
  605. if (force || (widthInput != document.activeElement && heightInput != document.activeElement))
  606. {
  607. var detected = false;
  608. for (var i = 0; i < formats.length; i++)
  609. {
  610. var f = formats[i];
  611. // Special case where custom was chosen
  612. if (customSize)
  613. {
  614. if (f.key == 'custom')
  615. {
  616. paperSizeSelect.value = f.key;
  617. customSize = false;
  618. }
  619. }
  620. else if (f.format != null)
  621. {
  622. if (pageFormat.width == f.format.width && pageFormat.height == f.format.height)
  623. {
  624. paperSizeSelect.value = f.key;
  625. portraitCheckBox.setAttribute('checked', 'checked');
  626. portraitCheckBox.defaultChecked = true;
  627. portraitCheckBox.checked = true;
  628. landscapeCheckBox.removeAttribute('checked');
  629. landscapeCheckBox.defaultChecked = false;
  630. landscapeCheckBox.checked = false;
  631. detected = true;
  632. }
  633. else if (pageFormat.width == f.format.height && pageFormat.height == f.format.width)
  634. {
  635. paperSizeSelect.value = f.key;
  636. portraitCheckBox.removeAttribute('checked');
  637. portraitCheckBox.defaultChecked = false;
  638. portraitCheckBox.checked = false;
  639. landscapeCheckBox.setAttribute('checked', 'checked');
  640. landscapeCheckBox.defaultChecked = true;
  641. landscapeCheckBox.checked = true;
  642. detected = true;
  643. }
  644. }
  645. }
  646. // Selects custom format which is last in list
  647. if (!detected)
  648. {
  649. widthInput.value = pageFormat.width;
  650. heightInput.value = pageFormat.height;
  651. paperSizeOption.setAttribute('selected', 'selected');
  652. portraitCheckBox.setAttribute('checked', 'checked');
  653. portraitCheckBox.defaultChecked = true;
  654. formatDiv.style.display = 'none';
  655. customDiv.style.display = '';
  656. }
  657. else
  658. {
  659. formatDiv.style.display = '';
  660. customDiv.style.display = 'none';
  661. }
  662. }
  663. };
  664. listener();
  665. div.appendChild(paperSizeSelect);
  666. mxUtils.br(div);
  667. div.appendChild(formatDiv);
  668. div.appendChild(customDiv);
  669. var currentPageFormat = pageFormat;
  670. var update = function()
  671. {
  672. var f = pf[paperSizeSelect.value];
  673. if (f.format != null)
  674. {
  675. widthInput.value = f.format.width;
  676. heightInput.value = f.format.height;
  677. customDiv.style.display = 'none';
  678. formatDiv.style.display = '';
  679. }
  680. else
  681. {
  682. formatDiv.style.display = 'none';
  683. customDiv.style.display = '';
  684. }
  685. var newPageFormat = new mxRectangle(0, 0, parseInt(widthInput.value), parseInt(heightInput.value));
  686. if (paperSizeSelect.value != 'custom' && landscapeCheckBox.checked)
  687. {
  688. newPageFormat = new mxRectangle(0, 0, newPageFormat.height, newPageFormat.width);
  689. }
  690. if (newPageFormat.width != currentPageFormat.width || newPageFormat.height != currentPageFormat.height)
  691. {
  692. currentPageFormat = newPageFormat;
  693. if (pageFormatListener != null)
  694. {
  695. pageFormatListener(currentPageFormat);
  696. }
  697. }
  698. };
  699. mxEvent.addListener(portraitSpan, 'click', function(evt)
  700. {
  701. portraitCheckBox.checked = true;
  702. update();
  703. mxEvent.consume(evt);
  704. });
  705. mxEvent.addListener(landscapeSpan, 'click', function(evt)
  706. {
  707. landscapeCheckBox.checked = true;
  708. update();
  709. mxEvent.consume(evt);
  710. });
  711. mxEvent.addListener(widthInput, 'blur', update);
  712. mxEvent.addListener(widthInput, 'click', update);
  713. mxEvent.addListener(heightInput, 'blur', update);
  714. mxEvent.addListener(heightInput, 'click', update);
  715. mxEvent.addListener(landscapeCheckBox, 'change', update);
  716. mxEvent.addListener(portraitCheckBox, 'change', update);
  717. mxEvent.addListener(paperSizeSelect, 'change', function()
  718. {
  719. // Handles special case where custom was chosen
  720. customSize = paperSizeSelect.value == 'custom';
  721. update();
  722. });
  723. update();
  724. return {set: function(value)
  725. {
  726. pageFormat = value;
  727. listener(null, null, true);
  728. },get: function()
  729. {
  730. return currentPageFormat;
  731. }, widthInput: widthInput,
  732. heightInput: heightInput};
  733. };
  734. /**
  735. *
  736. */
  737. PageSetupDialog.getFormats = function()
  738. {
  739. return [{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT},
  740. {key: 'legal', title: 'US-Legal (8,5" x 14")', format: new mxRectangle(0, 0, 850, 1400)},
  741. {key: 'tabloid', title: 'US-Tabloid (279 mm x 432 mm)', format: new mxRectangle(0, 0, 1100, 1700)},
  742. {key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1652)},
  743. {key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT},
  744. {key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 584, 826)},
  745. {key: 'custom', title: mxResources.get('custom'), format: null}];
  746. };
  747. /**
  748. * Constructs a new print dialog.
  749. */
  750. var PrintDialog = function(editorUi)
  751. {
  752. this.create(editorUi);
  753. };
  754. /**
  755. * Constructs a new print dialog.
  756. */
  757. PrintDialog.prototype.create = function(editorUi)
  758. {
  759. var graph = editorUi.editor.graph;
  760. var row, td;
  761. var table = document.createElement('table');
  762. table.style.width = '100%';
  763. table.style.height = '100%';
  764. var tbody = document.createElement('tbody');
  765. row = document.createElement('tr');
  766. var onePageCheckBox = document.createElement('input');
  767. onePageCheckBox.setAttribute('type', 'checkbox');
  768. td = document.createElement('td');
  769. td.setAttribute('colspan', '2');
  770. td.style.fontSize = '10pt';
  771. td.appendChild(onePageCheckBox);
  772. var span = document.createElement('span');
  773. mxUtils.write(span, ' ' + mxResources.get('fitPage'));
  774. td.appendChild(span);
  775. mxEvent.addListener(span, 'click', function(evt)
  776. {
  777. onePageCheckBox.checked = !onePageCheckBox.checked;
  778. pageCountCheckBox.checked = !onePageCheckBox.checked;
  779. mxEvent.consume(evt);
  780. });
  781. mxEvent.addListener(onePageCheckBox, 'change', function()
  782. {
  783. pageCountCheckBox.checked = !onePageCheckBox.checked;
  784. });
  785. row.appendChild(td);
  786. tbody.appendChild(row);
  787. row = row.cloneNode(false);
  788. var pageCountCheckBox = document.createElement('input');
  789. pageCountCheckBox.setAttribute('type', 'checkbox');
  790. td = document.createElement('td');
  791. td.style.fontSize = '10pt';
  792. td.appendChild(pageCountCheckBox);
  793. var span = document.createElement('span');
  794. mxUtils.write(span, ' ' + mxResources.get('posterPrint') + ':');
  795. td.appendChild(span);
  796. mxEvent.addListener(span, 'click', function(evt)
  797. {
  798. pageCountCheckBox.checked = !pageCountCheckBox.checked;
  799. onePageCheckBox.checked = !pageCountCheckBox.checked;
  800. mxEvent.consume(evt);
  801. });
  802. row.appendChild(td);
  803. var pageCountInput = document.createElement('input');
  804. pageCountInput.setAttribute('value', '1');
  805. pageCountInput.setAttribute('type', 'number');
  806. pageCountInput.setAttribute('min', '1');
  807. pageCountInput.setAttribute('size', '4');
  808. pageCountInput.setAttribute('disabled', 'disabled');
  809. pageCountInput.style.width = '50px';
  810. td = document.createElement('td');
  811. td.style.fontSize = '10pt';
  812. td.appendChild(pageCountInput);
  813. mxUtils.write(td, ' ' + mxResources.get('pages') + ' (max)');
  814. row.appendChild(td);
  815. tbody.appendChild(row);
  816. mxEvent.addListener(pageCountCheckBox, 'change', function()
  817. {
  818. if (pageCountCheckBox.checked)
  819. {
  820. pageCountInput.removeAttribute('disabled');
  821. }
  822. else
  823. {
  824. pageCountInput.setAttribute('disabled', 'disabled');
  825. }
  826. onePageCheckBox.checked = !pageCountCheckBox.checked;
  827. });
  828. row = row.cloneNode(false);
  829. td = document.createElement('td');
  830. mxUtils.write(td, mxResources.get('pageScale') + ':');
  831. row.appendChild(td);
  832. td = document.createElement('td');
  833. var pageScaleInput = document.createElement('input');
  834. pageScaleInput.setAttribute('value', '100 %');
  835. pageScaleInput.setAttribute('size', '5');
  836. pageScaleInput.style.width = '50px';
  837. td.appendChild(pageScaleInput);
  838. row.appendChild(td);
  839. tbody.appendChild(row);
  840. row = document.createElement('tr');
  841. td = document.createElement('td');
  842. td.colSpan = 2;
  843. td.style.paddingTop = '20px';
  844. td.setAttribute('align', 'right');
  845. // Overall scale for print-out to account for print borders in dialogs etc
  846. function preview(print)
  847. {
  848. var autoOrigin = onePageCheckBox.checked || pageCountCheckBox.checked;
  849. var printScale = parseInt(pageScaleInput.value) / 100;
  850. if (isNaN(printScale))
  851. {
  852. printScale = 1;
  853. pageScaleInput.value = '100%';
  854. }
  855. // Workaround to match available paper size in actual print output
  856. printScale *= 0.75;
  857. var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  858. var scale = 1 / graph.pageScale;
  859. if (autoOrigin)
  860. {
  861. var pageCount = (onePageCheckBox.checked) ? 1 : parseInt(pageCountInput.value);
  862. if (!isNaN(pageCount))
  863. {
  864. scale = mxUtils.getScaleForPageCount(pageCount, graph, pf);
  865. }
  866. }
  867. // Negative coordinates are cropped or shifted if page visible
  868. var gb = graph.getGraphBounds();
  869. var border = 0;
  870. var x0 = 0;
  871. var y0 = 0;
  872. // Applies print scale
  873. pf = mxRectangle.fromRectangle(pf);
  874. pf.width = Math.ceil(pf.width * printScale);
  875. pf.height = Math.ceil(pf.height * printScale);
  876. scale *= printScale;
  877. // Starts at first visible page
  878. if (!autoOrigin && graph.pageVisible)
  879. {
  880. var layout = graph.getPageLayout();
  881. x0 -= layout.x * pf.width;
  882. y0 -= layout.y * pf.height;
  883. }
  884. else
  885. {
  886. autoOrigin = true;
  887. }
  888. var preview = PrintDialog.createPrintPreview(graph, scale, pf, border, x0, y0, autoOrigin);
  889. preview.open();
  890. if (print)
  891. {
  892. PrintDialog.printPreview(preview);
  893. }
  894. };
  895. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  896. {
  897. editorUi.hideDialog();
  898. });
  899. cancelBtn.className = 'geBtn';
  900. if (editorUi.editor.cancelFirst)
  901. {
  902. td.appendChild(cancelBtn);
  903. }
  904. if (!mxClient.IS_CHROMEAPP)
  905. {
  906. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  907. {
  908. editorUi.hideDialog();
  909. preview(false);
  910. });
  911. previewBtn.className = 'geBtn';
  912. td.appendChild(previewBtn);
  913. }
  914. var printBtn = mxUtils.button(mxResources.get((mxClient.IS_CHROMEAPP) ? 'ok' : 'print'), function()
  915. {
  916. editorUi.hideDialog();
  917. preview(true);
  918. });
  919. printBtn.className = 'geBtn gePrimaryBtn';
  920. td.appendChild(printBtn);
  921. if (!editorUi.editor.cancelFirst)
  922. {
  923. td.appendChild(cancelBtn);
  924. }
  925. row.appendChild(td);
  926. tbody.appendChild(row);
  927. table.appendChild(tbody);
  928. this.container = table;
  929. };
  930. /**
  931. * Constructs a new print dialog.
  932. */
  933. PrintDialog.printPreview = function(preview)
  934. {
  935. if (preview.wnd != null)
  936. {
  937. var printFn = function()
  938. {
  939. preview.wnd.focus();
  940. preview.wnd.print();
  941. preview.wnd.close();
  942. };
  943. // Workaround for Google Chrome which needs a bit of a
  944. // delay in order to render the SVG contents
  945. // Needs testing in production
  946. if (mxClient.IS_GC)
  947. {
  948. window.setTimeout(printFn, 500);
  949. }
  950. else
  951. {
  952. printFn();
  953. }
  954. }
  955. };
  956. /**
  957. * Constructs a new print dialog.
  958. */
  959. PrintDialog.createPrintPreview = function(graph, scale, pf, border, x0, y0, autoOrigin)
  960. {
  961. var preview = new mxPrintPreview(graph, scale, pf, border, x0, y0);
  962. preview.title = mxResources.get('preview');
  963. preview.printBackgroundImage = true;
  964. preview.autoOrigin = autoOrigin;
  965. var bg = graph.background;
  966. if (bg == null || bg == '' || bg == mxConstants.NONE)
  967. {
  968. bg = '#ffffff';
  969. }
  970. preview.backgroundColor = bg;
  971. var writeHead = preview.writeHead;
  972. // Adds a border in the preview
  973. preview.writeHead = function(doc)
  974. {
  975. writeHead.apply(this, arguments);
  976. doc.writeln('<style type="text/css">');
  977. doc.writeln('@media screen {');
  978. doc.writeln(' body > div { padding:30px;box-sizing:content-box; }');
  979. doc.writeln('}');
  980. doc.writeln('</style>');
  981. };
  982. return preview;
  983. };
  984. /**
  985. * Constructs a new filename dialog.
  986. */
  987. var FilenameDialog = function(editorUi, filename, buttonText, fn, label, validateFn, content, helpLink, closeOnBtn)
  988. {
  989. closeOnBtn = (closeOnBtn != null) ? closeOnBtn : true;
  990. var row, td;
  991. var table = document.createElement('table');
  992. var tbody = document.createElement('tbody');
  993. table.style.marginTop = '8px';
  994. row = document.createElement('tr');
  995. td = document.createElement('td');
  996. td.style.fontSize = '10pt';
  997. td.style.width = '120px';
  998. mxUtils.write(td, (label || mxResources.get('filename')) + ':');
  999. row.appendChild(td);
  1000. var nameInput = document.createElement('input');
  1001. nameInput.setAttribute('value', filename || '');
  1002. nameInput.style.width = '180px';
  1003. var genericBtn = mxUtils.button(buttonText, function()
  1004. {
  1005. if (validateFn == null || validateFn(nameInput.value))
  1006. {
  1007. if (closeOnBtn)
  1008. {
  1009. editorUi.hideDialog();
  1010. }
  1011. fn(nameInput.value);
  1012. }
  1013. });
  1014. genericBtn.className = 'geBtn gePrimaryBtn';
  1015. this.init = function()
  1016. {
  1017. if (label == null && content != null)
  1018. {
  1019. return;
  1020. }
  1021. nameInput.focus();
  1022. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1023. {
  1024. nameInput.select();
  1025. }
  1026. else
  1027. {
  1028. document.execCommand('selectAll', false, null);
  1029. }
  1030. // Installs drag and drop handler for links
  1031. if (Graph.fileSupport)
  1032. {
  1033. // Setup the dnd listeners
  1034. var dlg = table.parentNode;
  1035. var graph = editorUi.editor.graph;
  1036. var dropElt = null;
  1037. mxEvent.addListener(dlg, 'dragleave', function(evt)
  1038. {
  1039. if (dropElt != null)
  1040. {
  1041. dropElt.style.backgroundColor = '';
  1042. dropElt = null;
  1043. }
  1044. evt.stopPropagation();
  1045. evt.preventDefault();
  1046. });
  1047. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  1048. {
  1049. // IE 10 does not implement pointer-events so it can't have a drop highlight
  1050. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  1051. {
  1052. dropElt = nameInput;
  1053. dropElt.style.backgroundColor = '#ebf2f9';
  1054. }
  1055. evt.stopPropagation();
  1056. evt.preventDefault();
  1057. }));
  1058. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  1059. {
  1060. if (dropElt != null)
  1061. {
  1062. dropElt.style.backgroundColor = '';
  1063. dropElt = null;
  1064. }
  1065. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  1066. {
  1067. nameInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  1068. genericBtn.click();
  1069. }
  1070. evt.stopPropagation();
  1071. evt.preventDefault();
  1072. }));
  1073. }
  1074. };
  1075. td = document.createElement('td');
  1076. td.appendChild(nameInput);
  1077. row.appendChild(td);
  1078. if (label != null || content == null)
  1079. {
  1080. tbody.appendChild(row);
  1081. }
  1082. if (content != null)
  1083. {
  1084. row = document.createElement('tr');
  1085. td = document.createElement('td');
  1086. td.colSpan = 2;
  1087. td.appendChild(content);
  1088. row.appendChild(td);
  1089. tbody.appendChild(row);
  1090. }
  1091. row = document.createElement('tr');
  1092. td = document.createElement('td');
  1093. td.colSpan = 2;
  1094. td.style.paddingTop = '20px';
  1095. td.style.whiteSpace = 'nowrap';
  1096. td.setAttribute('align', 'right');
  1097. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1098. {
  1099. editorUi.hideDialog();
  1100. });
  1101. cancelBtn.className = 'geBtn';
  1102. if (editorUi.editor.cancelFirst)
  1103. {
  1104. td.appendChild(cancelBtn);
  1105. }
  1106. if (helpLink != null)
  1107. {
  1108. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  1109. {
  1110. window.open(helpLink);
  1111. });
  1112. helpBtn.className = 'geBtn';
  1113. td.appendChild(helpBtn);
  1114. }
  1115. mxEvent.addListener(nameInput, 'keypress', function(e)
  1116. {
  1117. if (e.keyCode == 13)
  1118. {
  1119. genericBtn.click();
  1120. }
  1121. });
  1122. td.appendChild(genericBtn);
  1123. if (!editorUi.editor.cancelFirst)
  1124. {
  1125. td.appendChild(cancelBtn);
  1126. }
  1127. row.appendChild(td);
  1128. tbody.appendChild(row);
  1129. table.appendChild(tbody);
  1130. this.container = table;
  1131. };
  1132. /**
  1133. * Constructs a new textarea dialog.
  1134. */
  1135. var TextareaDialog = function(editorUi, title, url, fn, cancelFn, cancelTitle, w, h, addButtons, noHide)
  1136. {
  1137. w = (w != null) ? w : 300;
  1138. h = (h != null) ? h : 120;
  1139. noHide = (noHide != null) ? noHide : false;
  1140. var row, td;
  1141. var table = document.createElement('table');
  1142. var tbody = document.createElement('tbody');
  1143. row = document.createElement('tr');
  1144. td = document.createElement('td');
  1145. td.style.fontSize = '10pt';
  1146. td.style.width = '100px';
  1147. mxUtils.write(td, title);
  1148. row.appendChild(td);
  1149. tbody.appendChild(row);
  1150. row = document.createElement('tr');
  1151. td = document.createElement('td');
  1152. var nameInput = document.createElement('textarea');
  1153. mxUtils.write(nameInput, url || '');
  1154. nameInput.style.resize = 'none';
  1155. nameInput.style.width = w + 'px';
  1156. nameInput.style.height = h + 'px';
  1157. this.textarea = nameInput;
  1158. this.init = function()
  1159. {
  1160. nameInput.focus();
  1161. nameInput.scrollTop = 0;
  1162. };
  1163. td.appendChild(nameInput);
  1164. row.appendChild(td);
  1165. tbody.appendChild(row);
  1166. row = document.createElement('tr');
  1167. td = document.createElement('td');
  1168. td.style.paddingTop = '14px';
  1169. td.style.whiteSpace = 'nowrap';
  1170. td.setAttribute('align', 'right');
  1171. var cancelBtn = mxUtils.button(cancelTitle || mxResources.get('cancel'), function()
  1172. {
  1173. editorUi.hideDialog();
  1174. if (cancelFn != null)
  1175. {
  1176. cancelFn();
  1177. }
  1178. });
  1179. cancelBtn.className = 'geBtn';
  1180. if (editorUi.editor.cancelFirst)
  1181. {
  1182. td.appendChild(cancelBtn);
  1183. }
  1184. if (addButtons != null)
  1185. {
  1186. addButtons(td);
  1187. }
  1188. if (fn != null)
  1189. {
  1190. var genericBtn = mxUtils.button(mxResources.get('apply'), function()
  1191. {
  1192. if (!noHide)
  1193. {
  1194. editorUi.hideDialog();
  1195. }
  1196. fn(nameInput.value);
  1197. });
  1198. genericBtn.className = 'geBtn gePrimaryBtn';
  1199. td.appendChild(genericBtn);
  1200. }
  1201. if (!editorUi.editor.cancelFirst)
  1202. {
  1203. td.appendChild(cancelBtn);
  1204. }
  1205. row.appendChild(td);
  1206. tbody.appendChild(row);
  1207. table.appendChild(tbody);
  1208. this.container = table;
  1209. };
  1210. /**
  1211. * Constructs a new edit file dialog.
  1212. */
  1213. var EditDiagramDialog = function(editorUi)
  1214. {
  1215. var div = document.createElement('div');
  1216. div.style.textAlign = 'right';
  1217. var textarea = document.createElement('textarea');
  1218. textarea.setAttribute('wrap', 'off');
  1219. textarea.style.overflow = 'auto';
  1220. textarea.style.resize = 'none';
  1221. textarea.style.width = '600px';
  1222. textarea.style.height = '370px';
  1223. textarea.style.marginBottom = '16px';
  1224. textarea.value = mxUtils.getPrettyXml(editorUi.editor.getGraphXml());
  1225. div.appendChild(textarea);
  1226. this.init = function()
  1227. {
  1228. textarea.focus();
  1229. };
  1230. // Enables dropping files
  1231. if (Graph.fileSupport)
  1232. {
  1233. function handleDrop(evt)
  1234. {
  1235. evt.stopPropagation();
  1236. evt.preventDefault();
  1237. if (evt.dataTransfer.files.length > 0)
  1238. {
  1239. var file = evt.dataTransfer.files[0];
  1240. var reader = new FileReader();
  1241. reader.onload = function(e)
  1242. {
  1243. textarea.value = e.target.result;
  1244. };
  1245. reader.readAsText(file);
  1246. }
  1247. else
  1248. {
  1249. textarea.value = editorUi.extractGraphModelFromEvent(evt);
  1250. }
  1251. };
  1252. function handleDragOver(evt)
  1253. {
  1254. evt.stopPropagation();
  1255. evt.preventDefault();
  1256. };
  1257. // Setup the dnd listeners.
  1258. textarea.addEventListener('dragover', handleDragOver, false);
  1259. textarea.addEventListener('drop', handleDrop, false);
  1260. }
  1261. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1262. {
  1263. editorUi.hideDialog();
  1264. });
  1265. cancelBtn.className = 'geBtn';
  1266. if (editorUi.editor.cancelFirst)
  1267. {
  1268. div.appendChild(cancelBtn);
  1269. }
  1270. var select = document.createElement('select');
  1271. select.style.width = '180px';
  1272. select.className = 'geBtn';
  1273. if (editorUi.editor.graph.isEnabled())
  1274. {
  1275. var replaceOption = document.createElement('option');
  1276. replaceOption.setAttribute('value', 'replace');
  1277. mxUtils.write(replaceOption, mxResources.get('replaceExistingDrawing'));
  1278. select.appendChild(replaceOption);
  1279. }
  1280. var newOption = document.createElement('option');
  1281. newOption.setAttribute('value', 'new');
  1282. mxUtils.write(newOption, mxResources.get('openInNewWindow'));
  1283. var chromeApp = window.chrome != null && chrome.app != null && chrome.app.runtime != null;
  1284. if (!chromeApp)
  1285. {
  1286. select.appendChild(newOption);
  1287. }
  1288. if (editorUi.editor.graph.isEnabled())
  1289. {
  1290. var importOption = document.createElement('option');
  1291. importOption.setAttribute('value', 'import');
  1292. mxUtils.write(importOption, mxResources.get('addToExistingDrawing'));
  1293. select.appendChild(importOption);
  1294. }
  1295. div.appendChild(select);
  1296. var okBtn = mxUtils.button(mxResources.get('ok'), function()
  1297. {
  1298. // Removes all illegal control characters before parsing
  1299. var data = editorUi.editor.graph.zapGremlins(mxUtils.trim(textarea.value));
  1300. var error = null;
  1301. if (select.value == 'new')
  1302. {
  1303. window.openFile = new OpenFile(function()
  1304. {
  1305. editorUi.hideDialog();
  1306. window.openFile = null;
  1307. });
  1308. window.openFile.setData(data, null);
  1309. window.open(editorUi.getUrl());
  1310. }
  1311. else if (select.value == 'replace')
  1312. {
  1313. editorUi.editor.graph.model.beginUpdate();
  1314. try
  1315. {
  1316. editorUi.editor.setGraphXml(mxUtils.parseXml(data).documentElement);
  1317. // LATER: Why is hideDialog between begin-/endUpdate faster?
  1318. editorUi.hideDialog();
  1319. }
  1320. catch (e)
  1321. {
  1322. error = e;
  1323. }
  1324. finally
  1325. {
  1326. editorUi.editor.graph.model.endUpdate();
  1327. }
  1328. }
  1329. else if (select.value == 'import')
  1330. {
  1331. editorUi.editor.graph.model.beginUpdate();
  1332. try
  1333. {
  1334. var doc = mxUtils.parseXml(data);
  1335. var model = new mxGraphModel();
  1336. var codec = new mxCodec(doc);
  1337. codec.decode(doc.documentElement, model);
  1338. var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
  1339. editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(children));
  1340. // LATER: Why is hideDialog between begin-/endUpdate faster?
  1341. editorUi.hideDialog();
  1342. }
  1343. catch (e)
  1344. {
  1345. error = e;
  1346. }
  1347. finally
  1348. {
  1349. editorUi.editor.graph.model.endUpdate();
  1350. }
  1351. }
  1352. if (error != null)
  1353. {
  1354. mxUtils.alert(error.message);
  1355. }
  1356. });
  1357. okBtn.className = 'geBtn gePrimaryBtn';
  1358. div.appendChild(okBtn);
  1359. if (!editorUi.editor.cancelFirst)
  1360. {
  1361. div.appendChild(cancelBtn);
  1362. }
  1363. this.container = div;
  1364. };
  1365. /**
  1366. * Constructs a new export dialog.
  1367. */
  1368. var ExportDialog = function(editorUi)
  1369. {
  1370. var graph = editorUi.editor.graph;
  1371. var bounds = graph.getGraphBounds();
  1372. var scale = graph.view.scale;
  1373. var width = Math.ceil(bounds.width / scale);
  1374. var height = Math.ceil(bounds.height / scale);
  1375. var row, td;
  1376. var table = document.createElement('table');
  1377. var tbody = document.createElement('tbody');
  1378. row = document.createElement('tr');
  1379. td = document.createElement('td');
  1380. td.style.fontSize = '10pt';
  1381. td.style.width = '100px';
  1382. mxUtils.write(td, mxResources.get('filename') + ':');
  1383. row.appendChild(td);
  1384. var nameInput = document.createElement('input');
  1385. nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
  1386. nameInput.style.width = '180px';
  1387. td = document.createElement('td');
  1388. td.appendChild(nameInput);
  1389. row.appendChild(td);
  1390. tbody.appendChild(row);
  1391. row = document.createElement('tr');
  1392. td = document.createElement('td');
  1393. td.style.fontSize = '10pt';
  1394. mxUtils.write(td, mxResources.get('format') + ':');
  1395. row.appendChild(td);
  1396. var imageFormatSelect = document.createElement('select');
  1397. imageFormatSelect.style.width = '180px';
  1398. var pngOption = document.createElement('option');
  1399. pngOption.setAttribute('value', 'png');
  1400. mxUtils.write(pngOption, mxResources.get('formatPng'));
  1401. imageFormatSelect.appendChild(pngOption);
  1402. var gifOption = document.createElement('option');
  1403. if (ExportDialog.showGifOption)
  1404. {
  1405. gifOption.setAttribute('value', 'gif');
  1406. mxUtils.write(gifOption, mxResources.get('formatGif'));
  1407. imageFormatSelect.appendChild(gifOption);
  1408. }
  1409. var jpgOption = document.createElement('option');
  1410. jpgOption.setAttribute('value', 'jpg');
  1411. mxUtils.write(jpgOption, mxResources.get('formatJpg'));
  1412. imageFormatSelect.appendChild(jpgOption);
  1413. var pdfOption = document.createElement('option');
  1414. pdfOption.setAttribute('value', 'pdf');
  1415. mxUtils.write(pdfOption, mxResources.get('formatPdf'));
  1416. imageFormatSelect.appendChild(pdfOption);
  1417. var svgOption = document.createElement('option');
  1418. svgOption.setAttribute('value', 'svg');
  1419. mxUtils.write(svgOption, mxResources.get('formatSvg'));
  1420. imageFormatSelect.appendChild(svgOption);
  1421. if (ExportDialog.showXmlOption)
  1422. {
  1423. var xmlOption = document.createElement('option');
  1424. xmlOption.setAttribute('value', 'xml');
  1425. mxUtils.write(xmlOption, mxResources.get('formatXml'));
  1426. imageFormatSelect.appendChild(xmlOption);
  1427. }
  1428. td = document.createElement('td');
  1429. td.appendChild(imageFormatSelect);
  1430. row.appendChild(td);
  1431. tbody.appendChild(row);
  1432. row = document.createElement('tr');
  1433. td = document.createElement('td');
  1434. td.style.fontSize = '10pt';
  1435. mxUtils.write(td, mxResources.get('backgroundColor') + ':');
  1436. row.appendChild(td);
  1437. var backgroundInput = document.createElement('input');
  1438. var tmp = (graph.background == null || graph.background == mxConstants.NONE) ? '#ffffff' : graph.background;
  1439. backgroundInput.setAttribute('value', tmp);
  1440. backgroundInput.style.width = '80px';
  1441. var backgroundCheckbox = document.createElement('input');
  1442. backgroundCheckbox.setAttribute('type', 'checkbox');
  1443. backgroundCheckbox.checked = graph.background == null || graph.background == mxConstants.NONE;
  1444. td = document.createElement('td');
  1445. td.appendChild(backgroundInput);
  1446. td.appendChild(backgroundCheckbox);
  1447. mxUtils.write(td, mxResources.get('transparent'));
  1448. row.appendChild(td);
  1449. tbody.appendChild(row);
  1450. row = document.createElement('tr');
  1451. td = document.createElement('td');
  1452. td.style.fontSize = '10pt';
  1453. mxUtils.write(td, mxResources.get('width') + ':');
  1454. row.appendChild(td);
  1455. var widthInput = document.createElement('input');
  1456. widthInput.setAttribute('value', width);
  1457. widthInput.style.width = '180px';
  1458. td = document.createElement('td');
  1459. td.appendChild(widthInput);
  1460. row.appendChild(td);
  1461. tbody.appendChild(row);
  1462. row = document.createElement('tr');
  1463. td = document.createElement('td');
  1464. td.style.fontSize = '10pt';
  1465. mxUtils.write(td, mxResources.get('height') + ':');
  1466. row.appendChild(td);
  1467. var heightInput = document.createElement('input');
  1468. heightInput.setAttribute('value', height);
  1469. heightInput.style.width = '180px';
  1470. td = document.createElement('td');
  1471. td.appendChild(heightInput);
  1472. row.appendChild(td);
  1473. tbody.appendChild(row);
  1474. row = document.createElement('tr');
  1475. td = document.createElement('td');
  1476. td.style.fontSize = '10pt';
  1477. mxUtils.write(td, mxResources.get('borderWidth') + ':');
  1478. row.appendChild(td);
  1479. var borderInput = document.createElement('input');
  1480. borderInput.setAttribute('value', width);
  1481. borderInput.style.width = '180px';
  1482. borderInput.value = '0';
  1483. td = document.createElement('td');
  1484. td.appendChild(borderInput);
  1485. row.appendChild(td);
  1486. tbody.appendChild(row);
  1487. table.appendChild(tbody);
  1488. // Handles changes in the export format
  1489. function formatChanged()
  1490. {
  1491. var name = nameInput.value;
  1492. var dot = name.lastIndexOf('.');
  1493. if (dot > 0)
  1494. {
  1495. nameInput.value = name.substring(0, dot + 1) + imageFormatSelect.value;
  1496. }
  1497. else
  1498. {
  1499. nameInput.value = name + '.' + imageFormatSelect.value;
  1500. }
  1501. if (imageFormatSelect.value === 'xml')
  1502. {
  1503. widthInput.setAttribute('disabled', 'true');
  1504. heightInput.setAttribute('disabled', 'true');
  1505. borderInput.setAttribute('disabled', 'true');
  1506. }
  1507. else
  1508. {
  1509. widthInput.removeAttribute('disabled');
  1510. heightInput.removeAttribute('disabled');
  1511. borderInput.removeAttribute('disabled');
  1512. }
  1513. if (imageFormatSelect.value === 'png' || imageFormatSelect.value === 'svg')
  1514. {
  1515. backgroundCheckbox.removeAttribute('disabled');
  1516. }
  1517. else
  1518. {
  1519. backgroundCheckbox.setAttribute('disabled', 'disabled');
  1520. }
  1521. };
  1522. mxEvent.addListener(imageFormatSelect, 'change', formatChanged);
  1523. formatChanged();
  1524. function checkValues()
  1525. {
  1526. if (widthInput.value * heightInput.value > MAX_AREA || widthInput.value <= 0)
  1527. {
  1528. widthInput.style.backgroundColor = 'red';
  1529. }
  1530. else
  1531. {
  1532. widthInput.style.backgroundColor = '';
  1533. }
  1534. if (widthInput.value * heightInput.value > MAX_AREA || heightInput.value <= 0)
  1535. {
  1536. heightInput.style.backgroundColor = 'red';
  1537. }
  1538. else
  1539. {
  1540. heightInput.style.backgroundColor = '';
  1541. }
  1542. };
  1543. mxEvent.addListener(widthInput, 'change', function()
  1544. {
  1545. if (width > 0)
  1546. {
  1547. heightInput.value = Math.ceil(parseInt(widthInput.value) * height / width);
  1548. }
  1549. else
  1550. {
  1551. heightInput.value = '0';
  1552. }
  1553. checkValues();
  1554. });
  1555. mxEvent.addListener(heightInput, 'change', function()
  1556. {
  1557. if (height > 0)
  1558. {
  1559. widthInput.value = Math.ceil(parseInt(heightInput.value) * width / height);
  1560. }
  1561. else
  1562. {
  1563. widthInput.value = '0';
  1564. }
  1565. checkValues();
  1566. });
  1567. // Resuable image export instance
  1568. var imgExport = new mxImageExport();
  1569. function getSvg()
  1570. {
  1571. var b = Math.max(0, parseInt(borderInput.value)) + 1;
  1572. var scale = parseInt(widthInput.value) / width;
  1573. var bg = null;
  1574. if (backgroundInput.value != '' && backgroundInput.value != mxConstants.NONE && !backgroundCheckbox.checked)
  1575. {
  1576. bg = backgroundInput.value;
  1577. }
  1578. return graph.getSvg(bg, scale, b);
  1579. };
  1580. function getXml()
  1581. {
  1582. return mxUtils.getXml(editorUi.editor.getGraphXml());
  1583. };
  1584. row = document.createElement('tr');
  1585. td = document.createElement('td');
  1586. td.setAttribute('align', 'right');
  1587. td.style.paddingTop = '24px';
  1588. td.colSpan = 2;
  1589. var saveBtn = mxUtils.button(mxResources.get('export'), mxUtils.bind(this, function()
  1590. {
  1591. if (parseInt(widthInput.value) <= 0 && parseInt(heightInput.value) <= 0)
  1592. {
  1593. mxUtils.alert(mxResources.get('drawingEmpty'));
  1594. }
  1595. else
  1596. {
  1597. var format = imageFormatSelect.value;
  1598. var name = nameInput.value;
  1599. if (format == 'xml')
  1600. {
  1601. editorUi.hideDialog();
  1602. ExportDialog.saveLocalFile(getXml(), name, format);
  1603. }
  1604. else if (format == 'svg')
  1605. {
  1606. var xml = mxUtils.getXml(getSvg());
  1607. if (xml.length < MAX_REQUEST_SIZE)
  1608. {
  1609. editorUi.hideDialog();
  1610. ExportDialog.saveLocalFile(xml, name, format);
  1611. }
  1612. else
  1613. {
  1614. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1615. mxUtils.popup(xml);
  1616. }
  1617. }
  1618. else
  1619. {
  1620. var param = null;
  1621. var w = parseInt(widthInput.value) || 0;
  1622. var h = parseInt(heightInput.value) || 0;
  1623. var b = Math.max(0, parseInt(borderInput.value)) + 1;
  1624. var exp = ExportDialog.getExportParameter(editorUi, format);
  1625. if (typeof exp == 'function')
  1626. {
  1627. param = exp();
  1628. }
  1629. else
  1630. {
  1631. var scale = parseInt(widthInput.value) / width;
  1632. var bounds = graph.getGraphBounds();
  1633. var vs = graph.view.scale;
  1634. // New image export
  1635. var xmlDoc = mxUtils.createXmlDocument();
  1636. var root = xmlDoc.createElement('output');
  1637. xmlDoc.appendChild(root);
  1638. // Renders graph. Offset will be multiplied with state's scale when painting state.
  1639. var xmlCanvas = new mxXmlCanvas2D(root);
  1640. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  1641. xmlCanvas.scale(scale / vs);
  1642. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1643. // Puts request data together
  1644. w = Math.ceil(bounds.width * scale / vs + 2 * b);
  1645. h = Math.ceil(bounds.height * scale / vs + 2 * b);
  1646. param = 'xml=' + encodeURIComponent(mxUtils.getXml(root));
  1647. }
  1648. // Requests image if request is valid
  1649. if (param != null && param.length <= MAX_REQUEST_SIZE && w * h < MAX_AREA)
  1650. {
  1651. var bg = '&bg=none';
  1652. if (backgroundInput.value != '' && backgroundInput.value != mxConstants.NONE &&
  1653. (format != 'png' || !backgroundCheckbox.checked))
  1654. {
  1655. bg = '&bg=' + backgroundInput.value;
  1656. }
  1657. editorUi.hideDialog();
  1658. var data = decodeURIComponent(param.substring(param.indexOf('=') + 1));
  1659. ExportDialog.saveRequest(data, name, format,
  1660. function(newTitle, base64)
  1661. {
  1662. // Base64 not used in this example
  1663. return new mxXmlRequest(EXPORT_URL, 'format=' + format + '&base64=' + (base64 || '0') +
  1664. ((newTitle != null) ? '&filename=' + encodeURIComponent(newTitle) : '') +
  1665. bg + '&w=' + w + '&h=' + h + '&border=' + b + '&' + param);
  1666. });
  1667. }
  1668. else
  1669. {
  1670. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1671. }
  1672. }
  1673. }
  1674. }));
  1675. saveBtn.className = 'geBtn gePrimaryBtn';
  1676. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1677. {
  1678. editorUi.hideDialog();
  1679. });
  1680. cancelBtn.className = 'geBtn';
  1681. if (editorUi.editor.cancelFirst)
  1682. {
  1683. td.appendChild(cancelBtn);
  1684. td.appendChild(saveBtn);
  1685. }
  1686. else
  1687. {
  1688. td.appendChild(saveBtn);
  1689. td.appendChild(cancelBtn);
  1690. }
  1691. row.appendChild(td);
  1692. tbody.appendChild(row);
  1693. table.appendChild(tbody);
  1694. this.container = table;
  1695. };
  1696. /**
  1697. * Global switches for the export dialog.
  1698. */
  1699. ExportDialog.showGifOption = true;
  1700. /**
  1701. * Global switches for the export dialog.
  1702. */
  1703. ExportDialog.showXmlOption = true;
  1704. /**
  1705. * Hook for getting the export format. Returns null for the default
  1706. * intermediate XML export format or a function that returns the
  1707. * parameter and value to be used in the request in the form
  1708. * key=value, where value should be URL encoded.
  1709. */
  1710. ExportDialog.saveLocalFile = function(data, filename, format)
  1711. {
  1712. new mxXmlRequest(SAVE_URL, 'xml=' + encodeURIComponent(data) + '&filename=' +
  1713. encodeURIComponent(filename) + '&format=' + format).simulate(document, '_blank');
  1714. };
  1715. /**
  1716. * Hook for getting the export format. Returns null for the default
  1717. * intermediate XML export format or a function that returns the
  1718. * parameter and value to be used in the request in the form
  1719. * key=value, where value should be URL encoded.
  1720. */
  1721. ExportDialog.saveRequest = function(data, filename, format, fn)
  1722. {
  1723. fn(filename).simulate(document, '_blank');
  1724. };
  1725. /**
  1726. * Hook for getting the export format. Returns null for the default
  1727. * intermediate XML export format or a function that returns the
  1728. * parameter and value to be used in the request in the form
  1729. * key=value, where value should be URL encoded.
  1730. */
  1731. ExportDialog.getExportParameter = function(ui, format)
  1732. {
  1733. return null;
  1734. };
  1735. /**
  1736. * Constructs a new metadata dialog.
  1737. */
  1738. var EditDataDialog = function(ui, cell)
  1739. {
  1740. var div = document.createElement('div');
  1741. var graph = ui.editor.graph;
  1742. div.style.height = '310px';
  1743. div.style.overflow = 'auto';
  1744. var value = graph.getModel().getValue(cell);
  1745. // Converts the value to an XML node
  1746. if (!mxUtils.isNode(value))
  1747. {
  1748. var doc = mxUtils.createXmlDocument();
  1749. var obj = doc.createElement('object');
  1750. obj.setAttribute('label', value || '');
  1751. value = obj;
  1752. }
  1753. // Creates the dialog contents
  1754. var form = new mxForm('properties');
  1755. form.table.style.width = '100%';
  1756. form.table.style.paddingRight = '20px';
  1757. var attrs = value.attributes;
  1758. var names = [];
  1759. var texts = [];
  1760. var count = 0;
  1761. // FIXME: Fix remove button for quirks mode
  1762. var addRemoveButton = function(text, name)
  1763. {
  1764. text.parentNode.style.marginRight = '12px';
  1765. var removeAttr = document.createElement('a');
  1766. var img = mxUtils.createImage(Dialog.prototype.closeImage);
  1767. img.style.height = '9px';
  1768. img.style.fontSize = '9px';
  1769. img.style.marginBottom = '7px';
  1770. removeAttr.className = 'geButton';
  1771. removeAttr.setAttribute('title', mxResources.get('delete'));
  1772. removeAttr.style.margin = '0px';
  1773. removeAttr.style.width = '14px';
  1774. removeAttr.style.height = '14px';
  1775. removeAttr.style.fontSize = '14px';
  1776. removeAttr.style.cursor = 'pointer';
  1777. removeAttr.style.marginLeft = '6px';
  1778. removeAttr.appendChild(img);
  1779. var removeAttrFn = (function(name)
  1780. {
  1781. return function()
  1782. {
  1783. var count = 0;
  1784. for (var j = 0; j < names.length; j++)
  1785. {
  1786. if (names[j] == name)
  1787. {
  1788. texts[j] = null;
  1789. form.table.deleteRow(count);
  1790. break;
  1791. }
  1792. if (texts[j] != null)
  1793. {
  1794. count++;
  1795. }
  1796. }
  1797. };
  1798. })(name);
  1799. mxEvent.addListener(removeAttr, 'click', removeAttrFn);
  1800. text.parentNode.style.whiteSpace = 'nowrap';
  1801. text.parentNode.appendChild(removeAttr);
  1802. };
  1803. var addTextArea = function(index, name, value)
  1804. {
  1805. names[index] = name;
  1806. texts[index] = form.addTextarea(names[count] + ':', value, 2);
  1807. texts[index].style.width = '100%';
  1808. addRemoveButton(texts[index], name);
  1809. };
  1810. for (var i = 0; i < attrs.length; i++)
  1811. {
  1812. if (attrs[i].nodeName != 'label' && attrs[i].nodeName != 'placeholders')
  1813. {
  1814. addTextArea(count, attrs[i].nodeName, attrs[i].nodeValue);
  1815. count++;
  1816. }
  1817. }
  1818. div.appendChild(form.table);
  1819. var newProp = document.createElement('div');
  1820. newProp.style.whiteSpace = 'nowrap';
  1821. newProp.style.marginTop = '6px';
  1822. var nameInput = document.createElement('input');
  1823. nameInput.setAttribute('placeholder', mxResources.get('enterPropertyName'));
  1824. nameInput.setAttribute('type', 'text');
  1825. nameInput.setAttribute('size', (mxClient.IS_QUIRKS) ? '18' : '22');
  1826. nameInput.style.marginLeft = '2px';
  1827. newProp.appendChild(nameInput);
  1828. div.appendChild(newProp);
  1829. var addBtn = mxUtils.button(mxResources.get('addProperty'), function()
  1830. {
  1831. if (nameInput.value.length > 0)
  1832. {
  1833. var name = nameInput.value;
  1834. if (name != null && name.length > 0 && name != 'label' && name != 'placeholders')
  1835. {
  1836. try
  1837. {
  1838. var idx = mxUtils.indexOf(names, name);
  1839. if (idx >= 0 && texts[idx] != null)
  1840. {
  1841. texts[idx].focus();
  1842. }
  1843. else
  1844. {
  1845. // Checks if the name is valid
  1846. var clone = value.cloneNode(false);
  1847. clone.setAttribute(name, '');
  1848. if (idx >= 0)
  1849. {
  1850. names.splice(idx, 1);
  1851. texts.splice(idx, 1);
  1852. }
  1853. names.push(name);
  1854. var text = form.addTextarea(name + ':', '', 2);
  1855. text.style.width = '100%';
  1856. texts.push(text);
  1857. addRemoveButton(text, name);
  1858. text.focus();
  1859. }
  1860. nameInput.value = '';
  1861. }
  1862. catch (e)
  1863. {
  1864. mxUtils.alert(e);
  1865. }
  1866. }
  1867. }
  1868. else
  1869. {
  1870. mxUtils.alert(mxResources.get('invalidName'));
  1871. }
  1872. });
  1873. this.init = function()
  1874. {
  1875. if (texts.length > 0)
  1876. {
  1877. texts[0].focus();
  1878. }
  1879. else
  1880. {
  1881. nameInput.focus();
  1882. }
  1883. };
  1884. addBtn.setAttribute('disabled', 'disabled');
  1885. addBtn.style.marginLeft = '10px';
  1886. addBtn.style.width = '144px';
  1887. newProp.appendChild(addBtn);
  1888. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1889. {
  1890. ui.hideDialog.apply(ui, arguments);
  1891. });
  1892. cancelBtn.className = 'geBtn';
  1893. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1894. {
  1895. try
  1896. {
  1897. ui.hideDialog.apply(ui, arguments);
  1898. // Clones and updates the value
  1899. value = value.cloneNode(true);
  1900. for (var i = 0; i < names.length; i++)
  1901. {
  1902. if (texts[i] == null)
  1903. {
  1904. value.removeAttribute(names[i]);
  1905. }
  1906. else
  1907. {
  1908. value.setAttribute(names[i], texts[i].value);
  1909. }
  1910. }
  1911. // Updates the value of the cell (undoable)
  1912. graph.getModel().setValue(cell, value);
  1913. }
  1914. catch (e)
  1915. {
  1916. mxUtils.alert(e);
  1917. }
  1918. });
  1919. applyBtn.className = 'geBtn gePrimaryBtn';
  1920. function updateAddBtn()
  1921. {
  1922. if (nameInput.value.length > 0)
  1923. {
  1924. addBtn.removeAttribute('disabled');
  1925. }
  1926. else
  1927. {
  1928. addBtn.setAttribute('disabled', 'disabled');
  1929. }
  1930. };
  1931. mxEvent.addListener(nameInput, 'keyup', updateAddBtn);
  1932. // Catches all changes that don't fire a keyup (such as paste via mouse)
  1933. mxEvent.addListener(nameInput, 'change', updateAddBtn);
  1934. var buttons = document.createElement('div');
  1935. buttons.style.marginTop = '18px';
  1936. buttons.style.textAlign = 'right';
  1937. if (ui.editor.graph.getModel().isVertex(cell) || ui.editor.graph.getModel().isEdge(cell))
  1938. {
  1939. var replace = document.createElement('span');
  1940. replace.style.marginRight = '10px';
  1941. var input = document.createElement('input');
  1942. input.setAttribute('type', 'checkbox');
  1943. input.style.marginRight = '6px';
  1944. if (value.getAttribute('placeholders') == '1')
  1945. {
  1946. input.setAttribute('checked', 'checked');
  1947. input.defaultChecked = true;
  1948. }
  1949. mxEvent.addListener(input, 'click', function()
  1950. {
  1951. if (value.getAttribute('placeholders') == '1')
  1952. {
  1953. value.removeAttribute('placeholders');
  1954. }
  1955. else
  1956. {
  1957. value.setAttribute('placeholders', '1');
  1958. }
  1959. });
  1960. replace.appendChild(input);
  1961. mxUtils.write(replace, mxResources.get('placeholders'));
  1962. if (EditDataDialog.placeholderHelpLink != null)
  1963. {
  1964. var link = document.createElement('a');
  1965. link.setAttribute('href', EditDataDialog.placeholderHelpLink);
  1966. link.setAttribute('title', mxResources.get('help'));
  1967. link.setAttribute('target', '_blank');
  1968. link.style.marginLeft = '10px';
  1969. link.style.cursor = 'help';
  1970. var icon = document.createElement('img');
  1971. icon.setAttribute('border', '0');
  1972. icon.setAttribute('valign', 'middle');
  1973. icon.style.marginTop = '-4px';
  1974. icon.setAttribute('src', Editor.helpImage);
  1975. link.appendChild(icon);
  1976. replace.appendChild(link);
  1977. }
  1978. buttons.appendChild(replace);
  1979. }
  1980. if (ui.editor.cancelFirst)
  1981. {
  1982. buttons.appendChild(cancelBtn);
  1983. buttons.appendChild(applyBtn);
  1984. }
  1985. else
  1986. {
  1987. buttons.appendChild(applyBtn);
  1988. buttons.appendChild(cancelBtn);
  1989. }
  1990. div.appendChild(buttons);
  1991. this.container = div;
  1992. };
  1993. /**
  1994. * Optional help link.
  1995. */
  1996. EditDataDialog.placeholderHelpLink = null;
  1997. /**
  1998. * Constructs a new link dialog.
  1999. */
  2000. var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
  2001. {
  2002. var div = document.createElement('div');
  2003. mxUtils.write(div, mxResources.get('editLink') + ':');
  2004. var inner = document.createElement('div');
  2005. inner.className = 'geTitle';
  2006. inner.style.backgroundColor = 'transparent';
  2007. inner.style.borderColor = 'transparent';
  2008. inner.style.whiteSpace = 'nowrap';
  2009. inner.style.textOverflow = 'clip';
  2010. inner.style.cursor = 'default';
  2011. if (!mxClient.IS_VML)
  2012. {
  2013. inner.style.paddingRight = '20px';
  2014. }
  2015. var linkInput = document.createElement('input');
  2016. linkInput.setAttribute('value', initialValue);
  2017. linkInput.setAttribute('placeholder', 'http://www.example.com/');
  2018. linkInput.setAttribute('type', 'text');
  2019. linkInput.style.marginTop = '6px';
  2020. linkInput.style.width = '400px';
  2021. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  2022. linkInput.style.backgroundRepeat = 'no-repeat';
  2023. linkInput.style.backgroundPosition = '100% 50%';
  2024. linkInput.style.paddingRight = '14px';
  2025. var cross = document.createElement('div');
  2026. cross.setAttribute('title', mxResources.get('reset'));
  2027. cross.style.position = 'relative';
  2028. cross.style.left = '-16px';
  2029. cross.style.width = '12px';
  2030. cross.style.height = '14px';
  2031. cross.style.cursor = 'pointer';
  2032. // Workaround for inline-block not supported in IE
  2033. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  2034. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  2035. // Needed to block event transparency in IE
  2036. cross.style.background = 'url(' + IMAGE_PATH + '/transparent.gif)';
  2037. mxEvent.addListener(cross, 'click', function()
  2038. {
  2039. linkInput.value = '';
  2040. linkInput.focus();
  2041. });
  2042. inner.appendChild(linkInput);
  2043. inner.appendChild(cross);
  2044. div.appendChild(inner);
  2045. this.init = function()
  2046. {
  2047. linkInput.focus();
  2048. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2049. {
  2050. linkInput.select();
  2051. }
  2052. else
  2053. {
  2054. document.execCommand('selectAll', false, null);
  2055. }
  2056. };
  2057. var btns = document.createElement('div');
  2058. btns.style.marginTop = '18px';
  2059. btns.style.textAlign = 'right';
  2060. mxEvent.addListener(linkInput, 'keypress', function(e)
  2061. {
  2062. if (e.keyCode == 13)
  2063. {
  2064. editorUi.hideDialog();
  2065. fn(linkInput.value);
  2066. }
  2067. });
  2068. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2069. {
  2070. editorUi.hideDialog();
  2071. });
  2072. cancelBtn.className = 'geBtn';
  2073. if (editorUi.editor.cancelFirst)
  2074. {
  2075. btns.appendChild(cancelBtn);
  2076. }
  2077. var mainBtn = mxUtils.button(btnLabel, function()
  2078. {
  2079. editorUi.hideDialog();
  2080. fn(linkInput.value);
  2081. });
  2082. mainBtn.className = 'geBtn gePrimaryBtn';
  2083. btns.appendChild(mainBtn);
  2084. if (!editorUi.editor.cancelFirst)
  2085. {
  2086. btns.appendChild(cancelBtn);
  2087. }
  2088. div.appendChild(btns);
  2089. this.container = div;
  2090. };
  2091. /**
  2092. *
  2093. */
  2094. var OutlineWindow = function(editorUi, x, y, w, h)
  2095. {
  2096. var graph = editorUi.editor.graph;
  2097. var div = document.createElement('div');
  2098. div.style.position = 'absolute';
  2099. div.style.width = '100%';
  2100. div.style.height = '100%';
  2101. div.style.border = '1px solid whiteSmoke';
  2102. div.style.overflow = 'hidden';
  2103. this.window = new mxWindow(mxResources.get('outline'), div, x, y, w, h, true, true);
  2104. this.window.destroyOnClose = false;
  2105. this.window.setMaximizable(false);
  2106. this.window.setResizable(true);
  2107. this.window.setClosable(true);
  2108. this.window.setVisible(true);
  2109. this.window.setLocation = function(x, y)
  2110. {
  2111. x = Math.max(0, x);
  2112. y = Math.max(0, y);
  2113. mxWindow.prototype.setLocation.apply(this, arguments);
  2114. };
  2115. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2116. {
  2117. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2118. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2119. var x = this.window.getX();
  2120. var y = this.window.getY();
  2121. if (x + this.window.table.clientWidth > iw)
  2122. {
  2123. x = Math.max(0, iw - this.window.table.clientWidth);
  2124. }
  2125. if (y + this.window.table.clientHeight > ih)
  2126. {
  2127. y = Math.max(0, ih - this.window.table.clientHeight);
  2128. }
  2129. if (this.window.getX() != x || this.window.getY() != y)
  2130. {
  2131. this.window.setLocation(x, y);
  2132. }
  2133. }));
  2134. var outline = editorUi.createOutline(this.window);
  2135. this.window.addListener(mxEvent.RESIZE, mxUtils.bind(this, function()
  2136. {
  2137. outline.update(false);
  2138. outline.outline.sizeDidChange();
  2139. }));
  2140. this.window.addListener(mxEvent.SHOW, mxUtils.bind(this, function()
  2141. {
  2142. outline.suspended = false;
  2143. outline.outline.refresh();
  2144. outline.update();
  2145. }));
  2146. this.window.addListener(mxEvent.HIDE, mxUtils.bind(this, function()
  2147. {
  2148. outline.suspended = true;
  2149. }));
  2150. this.window.addListener(mxEvent.NORMALIZE, mxUtils.bind(this, function()
  2151. {
  2152. outline.suspended = false;
  2153. outline.update();
  2154. }));
  2155. this.window.addListener(mxEvent.MINIMIZE, mxUtils.bind(this, function()
  2156. {
  2157. outline.suspended = true;
  2158. }));
  2159. var outlineCreateGraph = outline.createGraph;
  2160. outline.createGraph = function(container)
  2161. {
  2162. var g = outlineCreateGraph.apply(this, arguments);
  2163. g.gridEnabled = false;
  2164. g.pageScale = graph.pageScale;
  2165. g.pageFormat = graph.pageFormat;
  2166. g.background = graph.background;
  2167. g.pageVisible = graph.pageVisible;
  2168. var current = mxUtils.getCurrentStyle(graph.container);
  2169. div.style.backgroundColor = current.backgroundColor;
  2170. return g;
  2171. };
  2172. function update()
  2173. {
  2174. outline.outline.pageScale = graph.pageScale;
  2175. outline.outline.pageFormat = graph.pageFormat;
  2176. outline.outline.pageVisible = graph.pageVisible;
  2177. outline.outline.background = graph.background;
  2178. var current = mxUtils.getCurrentStyle(graph.container);
  2179. div.style.backgroundColor = current.backgroundColor;
  2180. if (graph.view.backgroundPageShape != null && outline.outline.view.backgroundPageShape != null)
  2181. {
  2182. outline.outline.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  2183. }
  2184. outline.outline.refresh();
  2185. };
  2186. outline.init(div);
  2187. editorUi.editor.addListener('resetGraphView', update);
  2188. editorUi.addListener('pageFormatChanged', update);
  2189. editorUi.addListener('backgroundColorChanged', update);
  2190. editorUi.addListener('backgroundImageChanged', update);
  2191. editorUi.addListener('pageViewChanged', function()
  2192. {
  2193. update();
  2194. outline.update(true);
  2195. });
  2196. if (outline.outline.dialect == mxConstants.DIALECT_SVG)
  2197. {
  2198. var zoomInAction = editorUi.actions.get('zoomIn');
  2199. var zoomOutAction = editorUi.actions.get('zoomOut');
  2200. mxEvent.addMouseWheelListener(function(evt, up)
  2201. {
  2202. var outlineWheel = false;
  2203. var source = mxEvent.getSource(evt);
  2204. while (source != null)
  2205. {
  2206. if (source == outline.outline.view.canvas.ownerSVGElement)
  2207. {
  2208. outlineWheel = true;
  2209. break;
  2210. }
  2211. source = source.parentNode;
  2212. }
  2213. if (outlineWheel)
  2214. {
  2215. if (up)
  2216. {
  2217. zoomInAction.funct();
  2218. }
  2219. else
  2220. {
  2221. zoomOutAction.funct();
  2222. }
  2223. mxEvent.consume(evt);
  2224. }
  2225. });
  2226. }
  2227. };
  2228. /**
  2229. *
  2230. */
  2231. var LayersWindow = function(editorUi, x, y, w, h)
  2232. {
  2233. var graph = editorUi.editor.graph;
  2234. var div = document.createElement('div');
  2235. div.style.userSelect = 'none';
  2236. div.style.background = 'whiteSmoke';
  2237. div.style.border = '1px solid whiteSmoke';
  2238. div.style.height = '100%';
  2239. div.style.marginBottom = '10px';
  2240. div.style.overflow = 'auto';
  2241. var tbarHeight = (!EditorUi.compactUi) ? '30px' : '26px';
  2242. var listDiv = document.createElement('div')
  2243. listDiv.style.backgroundColor = '#e5e5e5';
  2244. listDiv.style.position = 'absolute';
  2245. listDiv.style.overflow = 'auto';
  2246. listDiv.style.left = '0px';
  2247. listDiv.style.right = '0px';
  2248. listDiv.style.top = '0px';
  2249. listDiv.style.bottom = tbarHeight;
  2250. div.appendChild(listDiv);
  2251. var dragSource = null;
  2252. var dropIndex = null;
  2253. mxEvent.addListener(div, 'dragover', function(evt)
  2254. {
  2255. evt.dataTransfer.dropEffect = 'move';
  2256. dropIndex = null;
  2257. evt.stopPropagation();
  2258. evt.preventDefault();
  2259. });
  2260. var layerCount = null;
  2261. var selectionLayer = null;
  2262. var ldiv = document.createElement('div');
  2263. ldiv.className = 'geToolbarContainer';
  2264. ldiv.style.position = 'absolute';
  2265. ldiv.style.bottom = '0px';
  2266. ldiv.style.left = '0px';
  2267. ldiv.style.right = '0px';
  2268. ldiv.style.height = tbarHeight;
  2269. ldiv.style.overflow = 'hidden';
  2270. ldiv.style.padding = (!EditorUi.compactUi) ? '1px' : '4px 0px 3px 0px';
  2271. ldiv.style.backgroundColor = 'whiteSmoke';
  2272. ldiv.style.borderWidth = '1px 0px 0px 0px';
  2273. ldiv.style.borderColor = '#c3c3c3';
  2274. ldiv.style.borderStyle = 'solid';
  2275. ldiv.style.display = 'block';
  2276. ldiv.style.whiteSpace = 'nowrap';
  2277. if (mxClient.IS_QUIRKS)
  2278. {
  2279. ldiv.style.filter = 'none';
  2280. }
  2281. var link = document.createElement('a');
  2282. link.className = 'geButton';
  2283. if (mxClient.IS_QUIRKS)
  2284. {
  2285. link.style.filter = 'none';
  2286. }
  2287. var removeLink = link.cloneNode();
  2288. removeLink.innerHTML = '<div class="geSprite geSprite-delete" style="display:inline-block;"></div>';
  2289. mxEvent.addListener(removeLink, 'click', function(evt)
  2290. {
  2291. if (graph.isEnabled())
  2292. {
  2293. graph.model.beginUpdate();
  2294. try
  2295. {
  2296. var index = graph.model.root.getIndex(selectionLayer);
  2297. graph.removeCells([selectionLayer], false);
  2298. // Creates default layer if no layer exists
  2299. if (graph.model.getChildCount(graph.model.root) == 0)
  2300. {
  2301. graph.model.add(graph.model.root, new mxCell());
  2302. graph.setDefaultParent(null);
  2303. }
  2304. else if (index > 0 && index <= graph.model.getChildCount(graph.model.root))
  2305. {
  2306. graph.setDefaultParent(graph.model.getChildAt(graph.model.root, index - 1));
  2307. }
  2308. else
  2309. {
  2310. graph.setDefaultParent(null);
  2311. }
  2312. }
  2313. finally
  2314. {
  2315. graph.model.endUpdate();
  2316. }
  2317. }
  2318. mxEvent.consume(evt);
  2319. });
  2320. if (!graph.isEnabled())
  2321. {
  2322. removeLink.className = 'geButton mxDisabled';
  2323. }
  2324. ldiv.appendChild(removeLink);
  2325. var insertLink = link.cloneNode();
  2326. insertLink.innerHTML = '<div class="geSprite geSprite-insert" style="display:inline-block;"></div>';
  2327. mxEvent.addListener(insertLink, 'click', function(evt)
  2328. {
  2329. if (graph.isEnabled() && !graph.isSelectionEmpty())
  2330. {
  2331. graph.moveCells(graph.getSelectionCells(), 0, 0, false, selectionLayer);
  2332. }
  2333. });
  2334. ldiv.appendChild(insertLink);
  2335. var renameLink = link.cloneNode();
  2336. renameLink.innerHTML = '<div class="geSprite geSprite-dots" style="display:inline-block;"></div>';
  2337. renameLink.setAttribute('title', mxResources.get('rename'));
  2338. function renameLayer(layer)
  2339. {
  2340. if (graph.isEnabled() && layer != null)
  2341. {
  2342. var dlg = new FilenameDialog(editorUi, layer.value || mxResources.get('background'), mxResources.get('rename'), mxUtils.bind(this, function(newValue)
  2343. {
  2344. if (newValue != null)
  2345. {
  2346. graph.getModel().setValue(layer, newValue);
  2347. }
  2348. }), mxResources.get('enterName'));
  2349. editorUi.showDialog(dlg.container, 300, 100, true, true);
  2350. dlg.init();
  2351. }
  2352. };
  2353. mxEvent.addListener(renameLink, 'click', function(evt)
  2354. {
  2355. if (graph.isEnabled())
  2356. {
  2357. renameLayer(selectionLayer);
  2358. }
  2359. mxEvent.consume(evt);
  2360. });
  2361. if (!graph.isEnabled())
  2362. {
  2363. renameLink.className = 'geButton mxDisabled';
  2364. }
  2365. ldiv.appendChild(renameLink);
  2366. var duplicateLink = link.cloneNode();
  2367. duplicateLink.innerHTML = '<div class="geSprite geSprite-duplicate" style="display:inline-block;"></div>';
  2368. mxEvent.addListener(duplicateLink, 'click', function(evt)
  2369. {
  2370. if (graph.isEnabled())
  2371. {
  2372. var newCell = null;
  2373. graph.model.beginUpdate();
  2374. try
  2375. {
  2376. newCell = graph.cloneCells([selectionLayer])[0];
  2377. newCell.value = mxResources.get('untitledLayer');
  2378. newCell.setVisible(true);
  2379. newCell = graph.addCell(newCell, graph.model.root);
  2380. graph.setDefaultParent(newCell);
  2381. }
  2382. finally
  2383. {
  2384. graph.model.endUpdate();
  2385. }
  2386. if (newCell != null && !graph.isCellLocked(newCell))
  2387. {
  2388. graph.selectAll(newCell);
  2389. }
  2390. }
  2391. });
  2392. if (!graph.isEnabled())
  2393. {
  2394. duplicateLink.className = 'geButton mxDisabled';
  2395. }
  2396. ldiv.appendChild(duplicateLink);
  2397. var addLink = link.cloneNode();
  2398. addLink.innerHTML = '<div class="geSprite geSprite-plus" style="display:inline-block;"></div>';
  2399. addLink.setAttribute('title', mxResources.get('addLayer'));
  2400. mxEvent.addListener(addLink, 'click', function(evt)
  2401. {
  2402. if (graph.isEnabled())
  2403. {
  2404. graph.model.beginUpdate();
  2405. try
  2406. {
  2407. var cell = graph.addCell(new mxCell(mxResources.get('untitledLayer')), graph.model.root);
  2408. graph.setDefaultParent(cell);
  2409. }
  2410. finally
  2411. {
  2412. graph.model.endUpdate();
  2413. }
  2414. }
  2415. mxEvent.consume(evt);
  2416. });
  2417. if (!graph.isEnabled())
  2418. {
  2419. addLink.className = 'geButton mxDisabled';
  2420. }
  2421. ldiv.appendChild(addLink);
  2422. div.appendChild(ldiv);
  2423. function refresh()
  2424. {
  2425. layerCount = graph.model.getChildCount(graph.model.root)
  2426. listDiv.innerHTML = '';
  2427. function addLayer(index, label, child, defaultParent)
  2428. {
  2429. var ldiv = document.createElement('div');
  2430. ldiv.className = 'geToolbarContainer';
  2431. ldiv.style.overflow = 'hidden';
  2432. ldiv.style.position = 'relative';
  2433. ldiv.style.padding = '4px';
  2434. ldiv.style.height = '22px';
  2435. ldiv.style.display = 'block';
  2436. ldiv.style.backgroundColor = 'whiteSmoke';
  2437. ldiv.style.borderWidth = '0px 0px 1px 0px';
  2438. ldiv.style.borderColor = '#c3c3c3';
  2439. ldiv.style.borderStyle = 'solid';
  2440. ldiv.style.whiteSpace = 'nowrap';
  2441. var left = document.createElement('div');
  2442. left.style.display = 'inline-block';
  2443. left.style.width = '100%';
  2444. left.style.textOverflow = 'ellipsis';
  2445. left.style.overflow = 'hidden';
  2446. mxEvent.addListener(ldiv, 'dragover', function(evt)
  2447. {
  2448. evt.dataTransfer.dropEffect = 'move';
  2449. dropIndex = index;
  2450. evt.stopPropagation();
  2451. evt.preventDefault();
  2452. });
  2453. mxEvent.addListener(ldiv, 'dragstart', function(evt)
  2454. {
  2455. dragSource = ldiv;
  2456. // Workaround for no DnD on DIV in FF
  2457. if (mxClient.IS_FF)
  2458. {
  2459. // LATER: Check what triggers a parse as XML on this in FF after drop
  2460. evt.dataTransfer.setData('Text', '<layer/>');
  2461. }
  2462. });
  2463. mxEvent.addListener(ldiv, 'dragend', function(evt)
  2464. {
  2465. if (dragSource != null)
  2466. {
  2467. graph.addCell(child, graph.model.root, dropIndex);
  2468. dragSource = null;
  2469. dropIndex = null;
  2470. }
  2471. evt.stopPropagation();
  2472. evt.preventDefault();
  2473. });
  2474. var btn = document.createElement('img');
  2475. btn.setAttribute('draggable', 'false');
  2476. btn.setAttribute('align', 'top');
  2477. btn.setAttribute('border', '0');
  2478. btn.style.cursor = 'pointer';
  2479. btn.style.padding = '4px';
  2480. btn.setAttribute('title', mxResources.get('lockUnlock'));
  2481. var state = graph.view.getState(child);
  2482. var style = (state != null) ? state.style : graph.getCellStyle(child);
  2483. if (mxUtils.getValue(style, 'locked', '0') == '1')
  2484. {
  2485. btn.setAttribute('src', Dialog.prototype.lockedImage);
  2486. }
  2487. else
  2488. {
  2489. btn.setAttribute('src', Dialog.prototype.unlockedImage);
  2490. }
  2491. mxEvent.addListener(btn, 'click', function(evt)
  2492. {
  2493. if (graph.isEnabled())
  2494. {
  2495. var value = null;
  2496. graph.getModel().beginUpdate();
  2497. try
  2498. {
  2499. value = (mxUtils.getValue(style, 'locked', '0') == '1') ? null : '1';
  2500. graph.setCellStyles('locked', value, [child]);
  2501. }
  2502. finally
  2503. {
  2504. graph.getModel().endUpdate();
  2505. }
  2506. if (value == '1')
  2507. {
  2508. graph.removeSelectionCells(graph.getModel().getDescendants(child));
  2509. }
  2510. mxEvent.consume(evt);
  2511. }
  2512. });
  2513. left.appendChild(btn);
  2514. var inp = document.createElement('input');
  2515. inp.setAttribute('type', 'checkbox');
  2516. inp.setAttribute('title', mxResources.get('hideIt', [child.value || mxResources.get('background')]));
  2517. inp.style.marginLeft = '4px';
  2518. inp.style.marginRight = '6px';
  2519. inp.style.marginTop = '4px';
  2520. left.appendChild(inp);
  2521. if (!graph.isEnabled())
  2522. {
  2523. inp.setAttribute('disabled', 'disabled');
  2524. }
  2525. if (graph.model.isVisible(child))
  2526. {
  2527. inp.setAttribute('checked', 'checked');
  2528. inp.defaultChecked = true;
  2529. }
  2530. mxEvent.addListener(inp, 'click', function(evt)
  2531. {
  2532. if (graph.isEnabled())
  2533. {
  2534. graph.model.setVisible(child, !graph.model.isVisible(child));
  2535. mxEvent.consume(evt);
  2536. }
  2537. });
  2538. mxUtils.write(left, label);
  2539. ldiv.appendChild(left);
  2540. if (graph.isEnabled())
  2541. {
  2542. // Fallback if no drag and drop is available
  2543. if (mxClient.IS_TOUCH || mxClient.IS_POINTER || mxClient.IS_VML ||
  2544. (mxClient.IS_IE && document.documentMode < 10))
  2545. {
  2546. var right = document.createElement('div');
  2547. right.style.display = 'block';
  2548. right.style.textAlign = 'right';
  2549. right.style.whiteSpace = 'nowrap';
  2550. right.style.position = 'absolute';
  2551. right.style.right = '6px';
  2552. right.style.top = '6px';
  2553. // Poor man's change layer order
  2554. if (index > 0)
  2555. {
  2556. var img2 = document.createElement('a');
  2557. img2.setAttribute('title', mxResources.get('toBack'));
  2558. img2.className = 'geButton';
  2559. img2.style.cssFloat = 'none';
  2560. img2.innerHTML = '&#9650;';
  2561. img2.style.width = '14px';
  2562. img2.style.height = '14px';
  2563. img2.style.fontSize = '14px';
  2564. img2.style.margin = '0px';
  2565. img2.style.marginTop = '-1px';
  2566. right.appendChild(img2);
  2567. mxEvent.addListener(img2, 'click', function(evt)
  2568. {
  2569. if (graph.isEnabled())
  2570. {
  2571. graph.addCell(child, graph.model.root, index - 1);
  2572. }
  2573. mxEvent.consume(evt);
  2574. });
  2575. }
  2576. if (index >= 0 && index < layerCount - 1)
  2577. {
  2578. var img1 = document.createElement('a');
  2579. img1.setAttribute('title', mxResources.get('toFront'));
  2580. img1.className = 'geButton';
  2581. img1.style.cssFloat = 'none';
  2582. img1.innerHTML = '&#9660;';
  2583. img1.style.width = '14px';
  2584. img1.style.height = '14px';
  2585. img1.style.fontSize = '14px';
  2586. img1.style.margin = '0px';
  2587. img1.style.marginTop = '-1px';
  2588. right.appendChild(img1);
  2589. mxEvent.addListener(img1, 'click', function(evt)
  2590. {
  2591. if (graph.isEnabled())
  2592. {
  2593. graph.addCell(child, graph.model.root, index + 1);
  2594. }
  2595. mxEvent.consume(evt);
  2596. });
  2597. }
  2598. ldiv.appendChild(right);
  2599. }
  2600. if (mxClient.IS_SVG && (!mxClient.IS_IE || document.documentMode >= 10))
  2601. {
  2602. ldiv.setAttribute('draggable', 'true');
  2603. ldiv.style.cursor = 'move';
  2604. }
  2605. }
  2606. mxEvent.addListener(ldiv, 'dblclick', function(evt)
  2607. {
  2608. var nodeName = mxEvent.getSource(evt).nodeName;
  2609. if (nodeName != 'INPUT' && nodeName != 'IMG')
  2610. {
  2611. renameLayer(child);
  2612. mxEvent.consume(evt);
  2613. }
  2614. });
  2615. if (graph.getDefaultParent() == child)
  2616. {
  2617. ldiv.style.background = '#e6eff8';
  2618. selectionLayer = child;
  2619. }
  2620. else
  2621. {
  2622. mxEvent.addListener(ldiv, 'click', function(evt)
  2623. {
  2624. if (graph.isEnabled())
  2625. {
  2626. graph.setDefaultParent(defaultParent);
  2627. graph.view.setCurrentRoot(null);
  2628. refresh();
  2629. }
  2630. });
  2631. }
  2632. listDiv.appendChild(ldiv);
  2633. };
  2634. // Cannot be moved or deleted
  2635. for (var i = 0; i < layerCount; i++)
  2636. {
  2637. (mxUtils.bind(this, function(child)
  2638. {
  2639. addLayer(i, child.value || mxResources.get('background'), child, child);
  2640. }))(graph.model.getChildAt(graph.model.root, i));
  2641. }
  2642. removeLink.setAttribute('title', mxResources.get('removeIt', [selectionLayer.value || mxResources.get('background')]));
  2643. insertLink.setAttribute('title', mxResources.get('moveSelectionTo', [selectionLayer.value || mxResources.get('background')]));
  2644. duplicateLink.setAttribute('title', mxResources.get('duplicateIt', [selectionLayer.value || mxResources.get('background')]));
  2645. renameLink.setAttribute('title', mxResources.get('renameIt', [selectionLayer.value || mxResources.get('background')]));
  2646. if (graph.isSelectionEmpty())
  2647. {
  2648. insertLink.className = 'geButton mxDisabled';
  2649. }
  2650. };
  2651. refresh();
  2652. graph.model.addListener(mxEvent.CHANGE, function()
  2653. {
  2654. refresh();
  2655. });
  2656. graph.selectionModel.addListener(mxEvent.CHANGE, function()
  2657. {
  2658. if (graph.isSelectionEmpty())
  2659. {
  2660. insertLink.className = 'geButton mxDisabled';
  2661. }
  2662. else
  2663. {
  2664. insertLink.className = 'geButton';
  2665. }
  2666. });
  2667. this.window = new mxWindow(mxResources.get('layers'), div, x, y, w, h, true, true);
  2668. this.window.destroyOnClose = false;
  2669. this.window.setMaximizable(false);
  2670. this.window.setResizable(true);
  2671. this.window.setClosable(true);
  2672. this.window.setVisible(true);
  2673. // Make refresh available via instance
  2674. this.refreshLayers = refresh;
  2675. this.window.setLocation = function(x, y)
  2676. {
  2677. x = Math.max(0, x);
  2678. y = Math.max(0, y);
  2679. mxWindow.prototype.setLocation.apply(this, arguments);
  2680. };
  2681. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2682. {
  2683. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2684. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2685. var x = this.window.getX();
  2686. var y = this.window.getY();
  2687. if (x + this.window.table.clientWidth > iw)
  2688. {
  2689. x = Math.max(0, iw - this.window.table.clientWidth);
  2690. }
  2691. if (y + this.window.table.clientHeight > ih)
  2692. {
  2693. y = Math.max(0, ih - this.window.table.clientHeight);
  2694. }
  2695. if (this.window.getX() != x || this.window.getY() != y)
  2696. {
  2697. this.window.setLocation(x, y);
  2698. }
  2699. }));
  2700. };