plugin.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or http://ckeditor.com/license
  4. */
  5. ( function() {
  6. var flashFilenameRegex = /\.swf(?:$|\?)/i;
  7. function isFlashEmbed( element ) {
  8. var attributes = element.attributes;
  9. return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test( attributes.src || '' ) );
  10. }
  11. function createFakeElement( editor, realElement ) {
  12. return editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true );
  13. }
  14. CKEDITOR.plugins.add( 'flash', {
  15. requires: 'dialog,fakeobjects',
  16. // jscs:disable maximumLineLength
  17. lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
  18. // jscs:enable maximumLineLength
  19. icons: 'flash', // %REMOVE_LINE_CORE%
  20. hidpi: true, // %REMOVE_LINE_CORE%
  21. onLoad: function() {
  22. CKEDITOR.addCss( 'img.cke_flash' +
  23. '{' +
  24. 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
  25. 'background-position: center center;' +
  26. 'background-repeat: no-repeat;' +
  27. 'border: 1px solid #a9a9a9;' +
  28. 'width: 80px;' +
  29. 'height: 80px;' +
  30. '}'
  31. );
  32. },
  33. init: function( editor ) {
  34. editor.config.flash_flvPlayer = editor.config.flash_flvPlayer || (this.path + 'swf/player.swf');
  35. var allowed = 'object[classid,codebase,height,hspace,vspace,width];' +
  36. 'param[name,value];' +
  37. 'embed[height,hspace,pluginspage,src,type,vspace,width]';
  38. if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'properties' ) )
  39. allowed += ';object[align]; embed[allowscriptaccess,quality,scale,wmode]';
  40. if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'advanced' ) )
  41. allowed += ';object[id]{*}; embed[bgcolor]{*}(*)';
  42. editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash', {
  43. allowedContent: allowed,
  44. requiredContent: 'embed'
  45. } ) );
  46. editor.ui.addButton && editor.ui.addButton( 'Flash', {
  47. label: editor.lang.common.flash,
  48. command: 'flash',
  49. toolbar: 'insert,20'
  50. } );
  51. CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' );
  52. // If the "menu" plugin is loaded, register the menu items.
  53. if ( editor.addMenuItems ) {
  54. editor.addMenuItems( {
  55. flash: {
  56. label: editor.lang.flash.properties,
  57. command: 'flash',
  58. group: 'flash'
  59. }
  60. } );
  61. }
  62. editor.on( 'doubleclick', function( evt ) {
  63. var element = evt.data.element;
  64. if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'flash' )
  65. evt.data.dialog = 'flash';
  66. } );
  67. // If the "contextmenu" plugin is loaded, register the listeners.
  68. if ( editor.contextMenu ) {
  69. editor.contextMenu.addListener( function( element ) {
  70. if ( element && element.is( 'img' ) && !element.isReadOnly() && element.data( 'cke-real-element-type' ) == 'flash' )
  71. return { flash: CKEDITOR.TRISTATE_OFF };
  72. } );
  73. }
  74. },
  75. afterInit: function( editor ) {
  76. var dataProcessor = editor.dataProcessor,
  77. dataFilter = dataProcessor && dataProcessor.dataFilter;
  78. if ( dataFilter ) {
  79. dataFilter.addRules( {
  80. elements: {
  81. 'cke:object': function( element ) {
  82. var attributes = element.attributes,
  83. classId = attributes.classid && String( attributes.classid ).toLowerCase();
  84. if ( !classId && !isFlashEmbed( element ) ) {
  85. // Look for the inner <embed>
  86. for ( var i = 0; i < element.children.length; i++ ) {
  87. if ( element.children[ i ].name == 'cke:embed' ) {
  88. if ( !isFlashEmbed( element.children[ i ] ) )
  89. return null;
  90. return createFakeElement( editor, element );
  91. }
  92. }
  93. return null;
  94. }
  95. return createFakeElement( editor, element );
  96. },
  97. 'cke:embed': function( element ) {
  98. if ( !isFlashEmbed( element ) )
  99. return null;
  100. return createFakeElement( editor, element );
  101. }
  102. }
  103. }, 5 );
  104. }
  105. }
  106. } );
  107. } )();
  108. CKEDITOR.tools.extend( CKEDITOR.config, {
  109. /**
  110. * Save as `<embed>` tag only. This tag is unrecommended.
  111. *
  112. * @cfg {Boolean} [flashEmbedTagOnly=false]
  113. * @member CKEDITOR.config
  114. */
  115. flashEmbedTagOnly: false,
  116. /**
  117. * Add `<embed>` tag as alternative: `<object><embed></embed></object>`.
  118. *
  119. * @cfg {Boolean} [flashAddEmbedTag=false]
  120. * @member CKEDITOR.config
  121. */
  122. flashAddEmbedTag: true,
  123. /**
  124. * Use {@link #flashEmbedTagOnly} and {@link #flashAddEmbedTag} values on edit.
  125. *
  126. * @cfg {Boolean} [flashConvertOnEdit=false]
  127. * @member CKEDITOR.config
  128. */
  129. flashConvertOnEdit: false
  130. } );