plugin.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * @license Copyright (c) 2003-2015, 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,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. var allowed = 'object[classid,codebase,height,hspace,vspace,width];' +
  35. 'param[name,value];' +
  36. 'embed[height,hspace,pluginspage,src,type,vspace,width]';
  37. if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'properties' ) )
  38. allowed += ';object[align]; embed[allowscriptaccess,quality,scale,wmode]';
  39. if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'advanced' ) )
  40. allowed += ';object[id]{*}; embed[bgcolor]{*}(*)';
  41. editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash', {
  42. allowedContent: allowed,
  43. requiredContent: 'embed'
  44. } ) );
  45. editor.ui.addButton && editor.ui.addButton( 'Flash', {
  46. label:'Вствка flash объекта',
  47. command: 'flash',
  48. toolbar: 'insert,7'
  49. } );
  50. CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' );
  51. // If the "menu" plugin is loaded, register the menu items.
  52. if ( editor.addMenuItems ) {
  53. editor.addMenuItems( {
  54. flash: {
  55. label: editor.lang.flash.properties,
  56. command: 'flash',
  57. group: 'flash'
  58. }
  59. } );
  60. }
  61. editor.on( 'doubleclick', function( evt ) {
  62. var element = evt.data.element;
  63. if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'flash' )
  64. evt.data.dialog = 'flash';
  65. } );
  66. // If the "contextmenu" plugin is loaded, register the listeners.
  67. if ( editor.contextMenu ) {
  68. editor.contextMenu.addListener( function( element ) {
  69. if ( element && element.is( 'img' ) && !element.isReadOnly() && element.data( 'cke-real-element-type' ) == 'flash' )
  70. return { flash: CKEDITOR.TRISTATE_OFF };
  71. } );
  72. }
  73. },
  74. afterInit: function( editor ) {
  75. var dataProcessor = editor.dataProcessor,
  76. dataFilter = dataProcessor && dataProcessor.dataFilter;
  77. if ( dataFilter ) {
  78. dataFilter.addRules( {
  79. elements: {
  80. 'cke:object': function( element ) {
  81. var attributes = element.attributes,
  82. classId = attributes.classid && String( attributes.classid ).toLowerCase();
  83. if ( !classId && !isFlashEmbed( element ) ) {
  84. // Look for the inner <embed>
  85. for ( var i = 0; i < element.children.length; i++ ) {
  86. if ( element.children[ i ].name == 'cke:embed' ) {
  87. if ( !isFlashEmbed( element.children[ i ] ) )
  88. return null;
  89. return createFakeElement( editor, element );
  90. }
  91. }
  92. return null;
  93. }
  94. return createFakeElement( editor, element );
  95. },
  96. 'cke:embed': function( element ) {
  97. if ( !isFlashEmbed( element ) )
  98. return null;
  99. return createFakeElement( editor, element );
  100. }
  101. }
  102. }, 5 );
  103. }
  104. }
  105. } );
  106. } )();
  107. CKEDITOR.tools.extend( CKEDITOR.config, {
  108. /**
  109. * Save as `<embed>` tag only. This tag is unrecommended.
  110. *
  111. * @cfg {Boolean} [flashEmbedTagOnly=false]
  112. * @member CKEDITOR.config
  113. */
  114. flashEmbedTagOnly: false,
  115. /**
  116. * Add `<embed>` tag as alternative: `<object><embed></embed></object>`.
  117. *
  118. * @cfg {Boolean} [flashAddEmbedTag=false]
  119. * @member CKEDITOR.config
  120. */
  121. flashAddEmbedTag: true,
  122. /**
  123. * Use {@link #flashEmbedTagOnly} and {@link #flashAddEmbedTag} values on edit.
  124. *
  125. * @cfg {Boolean} [flashConvertOnEdit=false]
  126. * @member CKEDITOR.config
  127. */
  128. flashConvertOnEdit: false
  129. } );