editor.tinymce.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaCore UNA Core
  6. * @{
  7. */
  8. function bx_editor_insert_html (sEditorId, sImgId, sHtml) {
  9. var eEditor = 'object' == typeof(tinymce) ? tinymce.get(sEditorId) : undefined;
  10. if ('undefined' == typeof(eEditor))
  11. return;
  12. if (eEditor.dom && eEditor.dom.doc && eEditor.dom.doc.getElementById(sImgId))
  13. return;
  14. eEditor.execCommand('mceInsertContent', false, sHtml);
  15. }
  16. function bx_editor_insert_img (sEditorId, sImgId, sImgUrl, sClasses) {
  17. if ('undefined' == typeof(sClasses))
  18. sClasses = '';
  19. bx_editor_insert_html(sEditorId, sImgId, '<img id="' + sImgId + '" class="' + sClasses + '" src="' + sImgUrl + '" />')
  20. }
  21. function bx_editor_on_init (sEditorId)
  22. {
  23. if (typeof glOnInitEditor !== 'undefined' && glOnInitEditor instanceof Array) {
  24. for (var i = 0; i < glOnInitEditor.length; i++)
  25. if (typeof glOnInitEditor[i] === "function")
  26. glOnInitEditor[i](sEditorId);
  27. }
  28. }
  29. function bx_editor_on_space_enter (sEditorId)
  30. {
  31. // TODO:
  32. }
  33. function bx_editor_remove_img (aEditorIds, aMarkers) {
  34. if ('object' != typeof(tinymce))
  35. return;
  36. var aEditors = [];
  37. for (var i = 0; i < aEditorIds.length; i++)
  38. aEditors.push(tinymce.get(aEditorIds[i]));
  39. for (var j = 0; j < aEditors.length; j++) {
  40. var eEditor = aEditors[j];
  41. if (typeof(eEditor) != 'object' || null === eEditor || typeof(eEditor.dom) != 'object' || typeof(eEditor.dom.doc) != 'object')
  42. continue;
  43. // delete images in html editor
  44. for (var k = 0; k < aMarkers.length; k++) {
  45. var jFiles = $(eEditor.dom.doc).find(aMarkers[k]);
  46. jFiles.each(function () {
  47. eEditor.execCommand('mceRemoveNode', false, this);
  48. });
  49. }
  50. }
  51. }
  52. function bx_editor_get_htmleditable (sEditorSelector)
  53. {
  54. if (!$(sEditorSelector).size())
  55. return false;
  56. var sId = $(sEditorSelector).attr('id');
  57. var eEditor = 'object' == typeof(tinymce) ? tinymce.get(sId) : undefined;
  58. if ('undefined' == typeof(eEditor) || !eEditor.dom)
  59. return false;
  60. return $(eEditor.dom.doc).find('body').get(0);
  61. }
  62. function bx_editor_remove_all (oElement)
  63. {
  64. if ('undefined' == typeof(oElement))
  65. oElement = window;
  66. oElement = $(oElement);
  67. if ('undefined' == typeof(tinymce) || !tinymce.editors.length)
  68. return;
  69. $.each(tinymce.editors, function () {
  70. if ($(this.getElement()).parents().filter(oElement).length)
  71. this.remove();
  72. });
  73. }
  74. /** @} */