国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
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 8.4KB

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