trello.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Explore plugin.
  3. */
  4. Draw.loadPlugin(function(editorUi)
  5. {
  6. // Trello plugin only works in embed mode
  7. if (editorUi.actions.get('exit') == null)
  8. {
  9. return;
  10. }
  11. // Overridden to redirect modified check to file
  12. editorUi.actions.get('exit').funct = function()
  13. {
  14. var fn = function()
  15. {
  16. var parent = window.opener || window.parent;
  17. parent.postMessage(JSON.stringify({event: 'exit'}), '*');
  18. }
  19. var file = editorUi.getCurrentFile();
  20. if (file == null || !file.isModified())
  21. {
  22. fn();
  23. }
  24. else
  25. {
  26. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  27. mxResources.get('cancel'), mxResources.get('discardChanges'));
  28. }
  29. };
  30. editorUi.showSplash = function()
  31. {
  32. this.actions.get('exit').funct();
  33. };
  34. function main()
  35. {
  36. var name = (urlParams['filename'] != null) ? decodeURIComponent(urlParams['filename']) : null;
  37. var card = (urlParams['card'] != null) ? decodeURIComponent(urlParams['card']) : null;
  38. var template = (urlParams['template'] != null) ? decodeURIComponent(urlParams['template']) : null;
  39. if (name != null && card != null)
  40. {
  41. var doCreateFile = function(templateData)
  42. {
  43. editorUi.createFile(name, templateData ||
  44. editorUi.getFileData(/(\.xml)$/i.test(name) ||
  45. name.indexOf('.') < 0, /(\.svg)$/i.test(name),
  46. /(\.html)$/i.test(name)), null, 'trello',
  47. null, true, card);
  48. };
  49. if (template != null)
  50. {
  51. editorUi.trello.getFile(card + editorUi.trello.SEPARATOR +
  52. template, function(file)
  53. {
  54. doCreateFile(file.getData());
  55. }, function()
  56. {
  57. doCreateFile();
  58. });
  59. }
  60. else
  61. {
  62. doCreateFile();
  63. }
  64. }
  65. else if (window.location.hash.substring(0, 2) == '#T')
  66. {
  67. editorUi.loadFile(editorUi.getDiagramId(), true);
  68. }
  69. editorUi.addEmbedButtons();
  70. };
  71. // Waits for Trello client
  72. if (editorUi.trello == null)
  73. {
  74. var waitForTrello = function()
  75. {
  76. if (editorUi.trello != null)
  77. {
  78. editorUi.removeListener(waitForTrello);
  79. main();
  80. }
  81. };
  82. // Waits for Trello client to load
  83. editorUi.addListener('clientLoaded', waitForTrello);
  84. }
  85. else
  86. {
  87. main();
  88. }
  89. });