Dialogs.js 82 KB

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