mediaembed.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. CKEDITOR.dialog.add( 'mediaembedDialog', function( editor ) {
  6. var numberRegex = /^\d+(?:\.\d+)?$/;
  7. var cssifyLength = function( length )
  8. {
  9. if ( numberRegex.test( length ) )
  10. return length + 'px';
  11. return length;
  12. }
  13. return {
  14. title : Drupal.t('Embed Media Dialog'),
  15. minWidth : 400,
  16. minHeight : 200,
  17. contents : [
  18. {
  19. id : 'mediaTab',
  20. label : Drupal.t('Embed media code'),
  21. title : Drupal.t('Embed media code'),
  22. elements :
  23. [
  24. {
  25. id : 'embed',
  26. type : 'textarea',
  27. rows : 9,
  28. label : Drupal.t('Paste embed code here')
  29. }
  30. ]
  31. }
  32. ],
  33. onOk : function() {
  34. var editor = this.getParentEditor();
  35. var content = this.getValueOf( 'mediaTab', 'embed' );
  36. if ( content.length>0 ) {
  37. var realElement = CKEDITOR.dom.element.createFromHtml('<div class="media_embed"></div>');
  38. realElement.setHtml(content);
  39. var fakeElement = editor.createFakeElement( realElement , 'cke_mediaembed', 'div', true);
  40. var matches = content.match(/width=(["']?)(\d+)\1/i);
  41. if (matches && matches.length == 3) {
  42. fakeElement.setStyle('width', cssifyLength(matches[2]));
  43. }
  44. matches = content.match(/height=([\"\']?)(\d+)\1/i);
  45. if (matches && matches.length == 3) {
  46. fakeElement.setStyle('height', cssifyLength(matches[2]));
  47. }
  48. editor.insertElement(fakeElement);
  49. }
  50. }
  51. };
  52. });