video_filter-4.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @file
  3. * Video Filter plugin for TinyMCE 4.x
  4. */
  5. var video_filter_dialog = {};
  6. (function ($) {
  7. video_filter_dialog = {
  8. insert : function() {
  9. var ed = top.tinymce.activeEditor, e;
  10. var file_url = $('#edit-file-url').val();
  11. if (file_url == "") {
  12. // File url is empty, we have nothing to insert, close the window
  13. top.tinymce.activeEditor.windowManager.close();
  14. }
  15. else {
  16. var str = '[video:' + file_url;
  17. // If field is present (ie. not unset by the admin theme) and if value is not empty: insert value.
  18. if (typeof $('#edit-width').val() != 'undefined' && $('#edit-width').val() !== '') {
  19. str += ' width:' + $('#edit-width').val();
  20. }
  21. if (typeof $('#edit-height').val() != 'undefined' && $('#edit-height').val() !== '') {
  22. str += ' height:' + $('#edit-height').val();
  23. }
  24. if (typeof $('#edit-align').val() != 'undefined' && $('#edit-align').val() !== 'none') {
  25. str += ' align:' + $('#edit-align').val();
  26. }
  27. if ($('#edit-autoplay').is(':checked')) {
  28. str += ' autoplay:' + $('#edit-autoplay').val();
  29. }
  30. str += ']';
  31. ed.execCommand('mceInsertContent', false, str);
  32. top.tinymce.activeEditor.windowManager.close();
  33. }
  34. }
  35. };
  36. Drupal.behaviors.video_filter_tinymce = {
  37. attach: function(context, settings) {
  38. $('#edit-insert').click(function() {
  39. video_filter_dialog.insert();
  40. });
  41. $('#edit-cancel').click(function() {
  42. top.tinymce.activeEditor.windowManager.close();
  43. });
  44. }
  45. }
  46. })(jQuery);