Minder.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. MWF.xApplication.OKR = MWF.xApplication.OKR || {};
  2. MWF.xApplication.OKR.Minder = new Class({
  3. Implements: [Options],
  4. options: {
  5. "style": "default",
  6. "template" : "default",
  7. "theme": "fresh-blue"//"fresh-blue-compat"
  8. },
  9. initialize: function (container, explorer, data, options) {
  10. this.setOptions(options);
  11. this.app = explorer.app;
  12. this.lp = this.app.lp;
  13. this.actions = this.app.actions;
  14. this.container = container;
  15. this.css = explorer.css;
  16. this.data = data;
  17. this.node = new Element("div", {
  18. "styles": {"width": "100%", "height": "100%"}
  19. //"type" : "application/kityminder",
  20. //"minder-data-type" : "json"
  21. }).inject(this.container)
  22. },
  23. destory : function(){
  24. if(this.km)delete this.km;
  25. if(this.node)this.node.destory();
  26. delete this;
  27. },
  28. load: function (callback) {
  29. this.loadResource(function () {
  30. this.loadKityMinder();
  31. if (callback)callback();
  32. }.bind(this))
  33. },
  34. loadResource: function (callback) {
  35. var kityminderPath = "/x_desktop/res/framework/kityminder/";
  36. COMMON.AjaxModule.loadCss(kityminderPath + "core/src/kityminder.css", function () {
  37. COMMON.AjaxModule.load(kityminderPath + "kity/kity.js", function () {
  38. COMMON.AjaxModule.load(kityminderPath + "core/dist/kityminder.core.js", function () {
  39. if (callback)callback();
  40. }.bind(this));
  41. }.bind(this))
  42. }.bind(this))
  43. },
  44. loadKityMinder: function () {
  45. var _self = this;
  46. // 创建 km 实例
  47. /* global kityminder */
  48. var km = this.km = new kityminder.Minder();
  49. //var target = document.querySelector('#minder-view');
  50. km.renderTo(this.node);
  51. this.data.theme = this.data.theme || this.options.theme;
  52. this.data.template = this.data.template || this.options.template;
  53. km.importJson(this.data);
  54. if( this.options.onClickKMNode ){
  55. km.on("execCommand", function (e) {
  56. if (e.commandName === "camera") {
  57. var nodes = km.getAllNode();
  58. nodes.forEach(function (node) {
  59. var container = node.getRenderContainer();
  60. container.node.addEventListener("click", function () {
  61. //alert(JSON.stringify((this.getData())))
  62. _self.options.onClickKMNode( this, this.getData() )
  63. }.bind(node));
  64. })
  65. }
  66. });
  67. }
  68. km.execCommand('camera');
  69. }
  70. })