embeder.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. TrexMessage.addMsg({
  2. '@embeder.alert': "에디터 상태에서만 삽입할 수 있습니다."
  3. });
  4. /**
  5. * Trex.EmbedBox
  6. * 본문에 삽입한 embed들이 저장되는 class
  7. *
  8. * @class
  9. * @extends Trex.EntryBox
  10. * @param {Object} config
  11. * @param {Object} canvas
  12. * @param {Object} editor
  13. */
  14. Trex.EmbedBox = Trex.Class.create({
  15. /** @ignore */
  16. $extend: Trex.EntryBox,
  17. initialize: function() {
  18. }
  19. });
  20. Trex.install("editor.getEmbedBox & sidebar.getEmbeder & sidebar.getEmbeddedData",
  21. function(editor, toolbar, sidebar, canvas, config){
  22. var _embedBox = new Trex.EmbedBox(config, canvas, editor);
  23. sidebar.entryboxRegistry['embedbox'] = _embedBox;
  24. editor.getEmbedBox = function() {
  25. return _embedBox;
  26. };
  27. sidebar.getEmbeddedData = _embedBox.getEntries.bind(_embedBox);
  28. var _embeders = sidebar.embeders = {};
  29. sidebar.getEmbeder = function(name) {
  30. if(_embeders[name] != _NULL) {
  31. return _embeders[name];
  32. } else if(arguments.length == 0){
  33. return _embeders;
  34. }else{
  35. return _NULL;
  36. }
  37. };
  38. }
  39. );
  40. Trex.register("new embeders",
  41. function(editor, toolbar, sidebar, canvas, config){
  42. var _embedBox = editor.getEmbedBox();
  43. var _embeders = sidebar.embeders;
  44. for(var i in Trex.Embeder) {
  45. var _name = Trex.Embeder[i]['__Identity'];
  46. if (_name) {
  47. if(!toolbar.tools[_name]){
  48. // console.log(["No tool '",_name,"', but Embeder '", _name,"' is initialized."].join(""));
  49. }
  50. _embeders[_name] = new Trex.Embeder[i](editor, _embedBox, config);
  51. }
  52. }
  53. }
  54. );
  55. Trex.Embeder = Trex.Class.draft({
  56. $extend: Trex.Actor,
  57. canResized: _FALSE,
  58. initialize: function(editor, entryBox, config) {
  59. this.editor = editor;
  60. this.canvas = editor.getCanvas();
  61. var _config = this.config = TrexConfig.getEmbeder(this.constructor.__Identity, config);
  62. if(config.pvpage && !!_config.usepvpage) {
  63. this.pvUrl = TrexConfig.getUrl(config.pvpage, { "pvname": this.name });
  64. }
  65. this.wysiwygonly = ((_config.wysiwygonly != _NULL)? _config.wysiwygonly: _TRUE);
  66. this.pastescope = _config.pastescope;
  67. this.embedHandler = this.embedHandler.bind(this);
  68. //NOTE: Cuz Specific Case
  69. if (this.oninitialized) {
  70. this.oninitialized.bind(this)(config);
  71. }
  72. },
  73. execute: function() {
  74. if(this.wysiwygonly && !this.canvas.isWYSIWYG()) {
  75. alert(TXMSG("@embeder.alert"));
  76. return;
  77. }
  78. if(this.clickHandler) {
  79. this.clickHandler();
  80. } else {
  81. try {
  82. var _url = this.config.popPageUrl;
  83. var isDocumentDomainDeclaredExplicitly = (document.location.hostname != document.domain);
  84. if (isDocumentDomainDeclaredExplicitly) {
  85. _url = _url + ((_url.indexOf("?") > -1) ? "&" : "?") + "xssDomain=" + document.domain;
  86. }
  87. _url = (this.pvUrl? this.pvUrl + ((this.pvUrl.indexOf("?") > -1) ? "&" : "?") + "u="+escape(_url): _url);
  88. var win = _WIN.open(_url, "at" + this.name, this.config.features);
  89. win.focus();
  90. } catch (e) {}
  91. }
  92. },
  93. embedHandler: function(data) {
  94. this.execAttach(data);
  95. },
  96. createEntry: function(data, type) {
  97. var _embeddedItemType = this.constructor.__Identity;
  98. if(type){
  99. _embeddedItemType = type;
  100. }
  101. return new Trex.EmbedEntry[_embeddedItemType.capitalize()](this, data);
  102. },
  103. execAttach: function(data) {
  104. var _pastescope = this.pastescope;
  105. var _html = this.getCreatedHtml(data);
  106. var _style = this.config.parastyle || this.config.defaultstyle || {};
  107. this.canvas.execute(function(processor) {
  108. processor.moveCaretWith(_pastescope);
  109. processor.pasteContent(_html, _TRUE, _style);
  110. });
  111. },
  112. execReattach: function(/*data, type*/) {
  113. },
  114. execReload: function(/*data, type*/) {
  115. },
  116. getReloadContent: function(data, content) {
  117. if(!data.dispElId) {
  118. return content;
  119. }
  120. var _html = this.getCreatedHtml(data);
  121. var _reg = new RegExp("<(?:img|IMG)[^>]*id=\"?" + data.dispElId + "\"?[^>]*\/?>", "gm");
  122. if(content.search(_reg) > -1) {
  123. return content.replace(_reg, _html);
  124. }
  125. return content;
  126. }
  127. });