plugin.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * @license Copyright (c) 2003-2013, webmote - codeex.cn. All rights reserved.
  3. * For licensing, see http://codeex.cn/
  4. * 2013-2-18 v1.0
  5. */
  6. (function() {
  7. //var allMediasFilenameRegex = /\.(avi|asf|fla|flv|mov|rm|rmvb|ra|mp3|mp4|mpg|mpeg|qt|wma|wmv)(?:$|\?)/i;
  8. function isallMediasEmbed( element ) {
  9. var attributes = element.attributes;
  10. return ( attributes.mtype == 'allmedias'); // || allMediasFilenameRegex.test( attributes.src || '' ) );
  11. }
  12. function createFakeElement( editor, realElement ) {
  13. return editor.createFakeParserElement( realElement, 'cke_allMedias', 'allMedias', true );
  14. }
  15. CKEDITOR.plugins.add( 'allmedias', {
  16. requires: 'dialog,fakeobjects',
  17. lang: 'en,zh-cn,zh', // %REMOVE_LINE_CORE%
  18. icons: 'allmedias', // %REMOVE_LINE_CORE%
  19. onLoad: function() {
  20. CKEDITOR.addCss( 'img.cke_allmedias' +
  21. '{' +
  22. 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
  23. 'background-position: center center;' +
  24. 'background-repeat: no-repeat;' +
  25. 'border: 1px solid #a9a9a9;' +
  26. 'width: 80px;' +
  27. 'height: 80px;' +
  28. '}'
  29. );
  30. //CKEDITOR.scriptLoader.load( 'plugins/allmedias/jwplayer.js' );
  31. },
  32. init: function( editor ) {
  33. editor.addCommand( 'allmedias', new CKEDITOR.dialogCommand( 'allmedias' ) );
  34. editor.ui.addButton && editor.ui.addButton( 'allmedias', {
  35. label: 'Вставить различные медиа',
  36. command: 'allmedias',
  37. toolbar: 'insert,5'
  38. });
  39. CKEDITOR.dialog.add( 'allmedias', this.path + 'dialogs/allmedias.js' );
  40. // If the "menu" plugin is loaded, register the menu items.
  41. if ( editor.addMenuItems ) {
  42. editor.addMenuGroup( 'mediagroup' );
  43. editor.addMenuItems({
  44. mediamenu: {
  45. label: editor.lang.allmedias.properties,
  46. command: 'allmedias',
  47. group: 'mediagroup',
  48. icon: this.icons,
  49. }
  50. });
  51. }
  52. editor.on( 'doubleclick', function( evt ) {
  53. var element = evt.data.element;
  54. if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'allmedias' )
  55. evt.data.dialog = 'allmedias';
  56. });
  57. // If the "contextmenu" plugin is loaded, register the listeners.
  58. if ( editor.contextMenu ) {
  59. editor.contextMenu.addListener( function( element, selection ) {
  60. if ( element && element.is( 'img' ) && !element.isReadOnly() && element.data( 'cke-real-element-type' ) == 'allmedias' )
  61. return { mediamenu: CKEDITOR.TRISTATE_OFF };
  62. });
  63. }
  64. },
  65. afterInit: function( editor ) {
  66. var dataProcessor = editor.dataProcessor,
  67. dataFilter = dataProcessor && dataProcessor.dataFilter;
  68. htmlFilter = dataProcessor && dataProcessor.htmlFilter;
  69. if ( dataFilter ) {
  70. dataFilter.addRules({
  71. elements: {
  72. 'cke:object': function( element ) {
  73. var attributes = element.attributes;
  74. //classId = attributes.classid && String( attributes.classid ).toLowerCase();
  75. if ( !isallMediasEmbed( element ) ) {
  76. // Look for the inner <embed>
  77. for ( var i = 0; i < element.children.length; i++ ) {
  78. if ( element.children[ i ].name == 'cke:embed' ) {
  79. if ( !isallMediasEmbed( element.children[ i ] ) )
  80. return null;
  81. return createFakeElement( editor, element );
  82. }
  83. }
  84. return null;
  85. }
  86. else{
  87. return createFakeElement( editor, element );
  88. }
  89. },
  90. 'cke:embed': function( element ) {
  91. if ( !isallMediasEmbed( element ) )
  92. return null;
  93. return createFakeElement( editor, element );
  94. }
  95. }
  96. }, 1 );
  97. }
  98. /*
  99. if ( htmlFilter ) {
  100. htmlFilter.addRules({
  101. elements: {
  102. 'cke:object': function( element ) {
  103. if ( element.attributes && element.attributes[ 'mtype' ] )
  104. delete element.name;
  105. }
  106. }
  107. });
  108. }
  109. */
  110. }
  111. });
  112. })();
  113. CKEDITOR.tools.extend( CKEDITOR.config, {
  114. /**
  115. * Save as `<embed>` tag only. This tag is unrecommended.
  116. *
  117. * @cfg {Boolean} [allMediasEmbedTagOnly=false]
  118. * @member CKEDITOR.config
  119. */
  120. allMediasEmbedTagOnly: false,
  121. /**
  122. * Add `<embed>` tag as alternative: `<object><embed></embed></object>`.
  123. *
  124. * @cfg {Boolean} [allMediasAddEmbedTag=false]
  125. * @member CKEDITOR.config
  126. */
  127. allMediasAddEmbedTag: true,
  128. /**
  129. * Use {@link #allMediasEmbedTagOnly} and {@link #allMediasAddEmbedTag} values on edit.
  130. *
  131. * @cfg {Boolean} [allMediasConvertOnEdit=false]
  132. * @member CKEDITOR.config
  133. */
  134. allMediasConvertOnEdit: false
  135. });