Dashboard sipadu mbip
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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. 'use strict';
  7. CKEDITOR.plugins.add( 'embedsemantic', {
  8. icons: 'embedsemantic', // %REMOVE_LINE_CORE%
  9. hidpi: true, // %REMOVE_LINE_CORE%
  10. requires: 'embedbase',
  11. onLoad: function() {
  12. this.registerOembedTag();
  13. },
  14. init: function( editor ) {
  15. var widgetDefinition = CKEDITOR.plugins.embedBase.createWidgetBaseDefinition( editor ),
  16. origInit = widgetDefinition.init;
  17. CKEDITOR.tools.extend( widgetDefinition, {
  18. // Use a dialog exposed by the embedbase plugin.
  19. dialog: 'embedBase',
  20. button: editor.lang.embedbase.button,
  21. allowedContent: 'oembed',
  22. requiredContent: 'oembed',
  23. styleableElements: 'oembed',
  24. // Share config with the embed plugin.
  25. providerUrl: new CKEDITOR.template(
  26. editor.config.embed_provider ||
  27. '//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}'
  28. ),
  29. init: function() {
  30. var that = this;
  31. origInit.call( this );
  32. // Need to wait for #ready with the initial content loading, because on #init there's no data yet.
  33. this.once( 'ready', function() {
  34. // When widget is created using dialog, the dialog's code will handle loading the content
  35. // (because it handles success and error), so do load the content only when loading data.
  36. if ( this.data.loadOnReady ) {
  37. this.loadContent( this.data.url, {
  38. callback: function() {
  39. // Do not load the content again on widget's next initialization (e.g. after undo or paste).
  40. // Plus, this is a small trick that we change loadOnReady now, inside the callback.
  41. // It guarantees that if the content was not loaded (an error occurred or someone
  42. // undid/copied sth to fast) the content will be loaded on the next initialization.
  43. that.setData( 'loadOnReady', false );
  44. editor.fire( 'updateSnapshot' );
  45. }
  46. } );
  47. }
  48. } );
  49. },
  50. upcast: function( element, data ) {
  51. if ( element.name != 'oembed' ) {
  52. return;
  53. }
  54. var text = element.children[ 0 ],
  55. div;
  56. if ( text && text.type == CKEDITOR.NODE_TEXT && text.value ) {
  57. data.url = text.value;
  58. data.loadOnReady = true;
  59. div = new CKEDITOR.htmlParser.element( 'div' );
  60. element.replaceWith( div );
  61. // Transfer widget classes from data to widget element (#13199).
  62. div.attributes[ 'class' ] = element.attributes[ 'class' ];
  63. return div;
  64. }
  65. },
  66. downcast: function( element ) {
  67. var ret = new CKEDITOR.htmlParser.element( 'oembed' );
  68. ret.add( new CKEDITOR.htmlParser.text( this.data.url ) );
  69. // Transfer widget classes from widget element back to data (#13199).
  70. if ( element.attributes[ 'class' ] ) {
  71. ret.attributes[ 'class' ] = element.attributes[ 'class' ];
  72. }
  73. return ret;
  74. }
  75. }, true );
  76. editor.widgets.add( 'embedSemantic', widgetDefinition );
  77. },
  78. // Extends CKEDITOR.dtd so editor accepts <oembed> tag.
  79. registerOembedTag: function() {
  80. var dtd = CKEDITOR.dtd,
  81. name;
  82. // The oembed tag may contain text only.
  83. dtd.oembed = { '#': 1 };
  84. // Register oembed tag as allowed child, in each tag that can contain a div.
  85. // It also registers the oembed tag in objects like $block, $blockLimit, etc.
  86. for ( name in dtd ) {
  87. if ( dtd[ name ].div ) {
  88. dtd[ name ].oembed = 1;
  89. }
  90. }
  91. }
  92. } );
  93. } )();