星火管控前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. CKEDITOR.plugins.add("html5video", {
  2. requires: "widget",
  3. lang: "bg,ca,de,en,eu,es,ru,uk,fr,ko,pt,pt-br,pl,zh-cn",
  4. icons: "html5video",
  5. hidpi: true,
  6. init: function(editor) {
  7. editor.widgets.add("html5video", {
  8. button: editor.lang.html5video.button,
  9. template: '<div class="ckeditor-html5-video"></div>',
  10. /*
  11. * Allowed content rules (http://docs.ckeditor.com/#!/guide/dev_allowed_content_rules):
  12. * - div-s with text-align,float,margin-left,margin-right inline style rules and required ckeditor-html5-video class.
  13. * - video tags with src, controls, width and height attributes.
  14. */
  15. allowedContent:
  16. "div[data-responsive](!ckeditor-html5-video){text-align,float,margin-left,margin-right}; video[src,poster,controls,autoplay,width, height,loop]{max-width,height};",
  17. requiredContent: "div(ckeditor-html5-video); video[src];",
  18. upcast: function(element) {
  19. return (
  20. element.name === "div" && element.hasClass("ckeditor-html5-video")
  21. );
  22. },
  23. dialog: "html5video",
  24. init: function() {
  25. var src = "";
  26. var autoplay = "";
  27. var loop = "";
  28. var controls = "controls";
  29. var align = this.element.getStyle("text-align");
  30. var width = "100%";
  31. var height = "";
  32. var poster = "";
  33. // If there's a child (the video element)
  34. if (this.element.getChild(0)) {
  35. // get it's attributes.
  36. src = this.element.getChild(0).getAttribute("src");
  37. width = this.element.getChild(0).getAttribute("width");
  38. height = this.element.getChild(0).getAttribute("height");
  39. autoplay = this.element.getChild(0).getAttribute("autoplay");
  40. allowdownload = !this.element
  41. .getChild(0)
  42. .getAttribute("controlslist");
  43. loop = this.element.getChild(0).getAttribute("loop");
  44. advisorytitle = this.element.getChild(0).getAttribute("title");
  45. controls = this.element.getChild(0).getAttribute("controls");
  46. responsive = this.element.getAttribute("data-responsive");
  47. poster = this.element.getChild(0).getAttribute("poster");
  48. }
  49. if (src) {
  50. this.setData("src", src);
  51. if (align) {
  52. this.setData("align", align);
  53. } else {
  54. this.setData("align", "none");
  55. }
  56. if (width) {
  57. this.setData("width", width);
  58. }
  59. if (height) {
  60. this.setData("height", height);
  61. }
  62. if (autoplay) {
  63. this.setData("autoplay", "yes");
  64. }
  65. if (allowdownload) {
  66. this.setData("allowdownload", "yes");
  67. }
  68. if (loop) {
  69. this.setData("loop", "yes");
  70. }
  71. if (advisorytitle) {
  72. this.setData("advisorytitle", advisorytitle);
  73. }
  74. if (responsive) {
  75. this.setData("responsive", responsive);
  76. }
  77. if (controls) {
  78. this.setData("controls", controls);
  79. }
  80. if (poster) {
  81. this.setData("poster", poster);
  82. }
  83. } else {
  84. if (controls) {
  85. this.setData("controls", controls);
  86. }
  87. if (width) {
  88. this.setData("width", width);
  89. }
  90. if (height) {
  91. this.setData("height", height);
  92. }
  93. }
  94. },
  95. data: function() {
  96. // If there is an video source
  97. if (this.data.src) {
  98. // and there isn't a child (the video element)
  99. if (!this.element.getChild(0)) {
  100. // Create a new <video> element.
  101. var videoElement = new CKEDITOR.dom.element("video");
  102. // Set the controls attribute.
  103. if (this.data.controls) {
  104. videoElement.setAttribute("controls", "controls");
  105. }
  106. // Append it to the container of the plugin.
  107. this.element.append(videoElement);
  108. }
  109. this.element.getChild(0).setAttribute("src", this.data.src);
  110. if (this.data.width)
  111. this.element.getChild(0).setAttribute("width", this.data.width);
  112. if (this.data.height)
  113. this.element.getChild(0).setAttribute("height", this.data.height);
  114. if (this.data.responsive) {
  115. this.element.setAttribute("data-responsive", this.data.responsive);
  116. this.element.getChild(0).setStyle("max-width", "100%");
  117. this.element.getChild(0).setStyle("height", "auto");
  118. } else {
  119. this.element.removeAttribute("data-responsive");
  120. this.element.getChild(0).removeStyle("max-width");
  121. this.element.getChild(0).removeStyle("height");
  122. }
  123. if (this.data.poster)
  124. this.element.getChild(0).setAttribute("poster", this.data.poster);
  125. }
  126. this.element.removeStyle("float");
  127. this.element.removeStyle("margin-left");
  128. this.element.removeStyle("margin-right");
  129. if (this.data.align === "none") {
  130. this.element.removeStyle("text-align");
  131. } else {
  132. this.element.setStyle("text-align", this.data.align);
  133. }
  134. if (this.data.align === "left") {
  135. this.element.setStyle("float", this.data.align);
  136. this.element.setStyle("margin-right", "10px");
  137. } else if (this.data.align === "right") {
  138. this.element.setStyle("float", this.data.align);
  139. this.element.setStyle("margin-left", "10px");
  140. }
  141. if (this.element.getChild(0)) {
  142. if (this.data.autoplay === "yes") {
  143. this.element.getChild(0).setAttribute("autoplay", "autoplay");
  144. } else {
  145. this.element.getChild(0).removeAttribute("autoplay");
  146. }
  147. if (this.data.loop === "yes") {
  148. this.element.getChild(0).setAttribute("loop", "loop");
  149. } else {
  150. this.element.getChild(0).removeAttribute("loop");
  151. }
  152. if (this.data.allowdownload === "yes") {
  153. this.element.getChild(0).removeAttribute("controlslist");
  154. } else {
  155. this.element.getChild(0).setAttribute("controlslist", "nodownload");
  156. }
  157. if (this.data.advisorytitle) {
  158. this.element
  159. .getChild(0)
  160. .setAttribute("title", this.data.advisorytitle);
  161. } else {
  162. this.element.getChild(0).removeAttribute("title");
  163. }
  164. if (this.data.controls) {
  165. this.element.getChild(0).setAttribute("controls", "controls");
  166. } else {
  167. this.element.getChild(0).removeAttribute("controls");
  168. }
  169. }
  170. }
  171. });
  172. if (editor.contextMenu) {
  173. editor.addMenuGroup("html5videoGroup");
  174. editor.addMenuItem("html5videoPropertiesItem", {
  175. label: editor.lang.html5video.videoProperties,
  176. icon: "html5video",
  177. command: "html5video",
  178. group: "html5videoGroup"
  179. });
  180. editor.contextMenu.addListener(function(element) {
  181. if (
  182. element &&
  183. element.getChild(0) &&
  184. element.getChild(0).hasClass &&
  185. element.getChild(0).hasClass("ckeditor-html5-video")
  186. ) {
  187. return { html5videoPropertiesItem: CKEDITOR.TRISTATE_OFF };
  188. }
  189. });
  190. }
  191. CKEDITOR.dialog.add("html5video", this.path + "dialogs/html5video.js");
  192. }
  193. });