media_youtube.fromurl.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @file
  3. * Create the 'YouTube' tab for the WYSIWYG plugins.
  4. */
  5. // (function ($) {
  6. // namespace('Drupal.media.browser.plugin');
  7. //
  8. // Drupal.media.browser.plugin.media_youtube = function(mediaBrowser, options) {
  9. // return {
  10. // init: function() {
  11. // tabset = mediaBrowser.getTabset();
  12. // tabset.tabs('add', '#media_youtube', 'YouTube');
  13. // mediaBrowser.listen('tabs.show', function (e, id) {
  14. // if (id == 'media_youtube') {
  15. // // We only need to set this once.
  16. // // We probably could set it upon load.
  17. // if (mediaBrowser.getActivePanel().html() == '') {
  18. // mediaBrowser.getActivePanel().html(options.media_youtube);
  19. // }
  20. // }
  21. // });
  22. // }
  23. // }
  24. // };
  25. //
  26. // // For now, I guess self registration makes sense.
  27. // // Really though, we should be doing it via drupal_add_js and some settings
  28. // // from the drupal variable.
  29. // //@todo: needs a review.
  30. // Drupal.media.browser.register('media_youtube', Drupal.media.browser.plugin.media_youtube, {});
  31. // })(jQuery);
  32. (function ($) {
  33. namespace('media.browser.plugin');
  34. Drupal.media.browser.plugin.youtube_library = function(mediaBrowser, options) {
  35. return {
  36. mediaFiles: [],
  37. init: function() {
  38. tabset = mediaBrowser.getTabset();
  39. tabset.tabs('add', '#youtube_library', 'YouTube');
  40. var that = this;
  41. mediaBrowser.listen('tabs.show', function (e, id) {
  42. if (id == 'youtube_library') {
  43. // This is kinda rough, I'm not sure who should delegate what here.
  44. mediaBrowser.getActivePanel().addClass('throbber');
  45. mediaBrowser.getActivePanel().html('');
  46. //mediaBrowser.getActivePanel().addClass('throbber');
  47. // Assumes we have to refresh everytime.
  48. // Remove any existing content
  49. mediaBrowser.getActivePanel().append('<ul></ul>');
  50. that.browser = $('ul', mediaBrowser.getActivePanel());
  51. that.browser.addClass('clearfix');
  52. that.getMedia();
  53. }
  54. });
  55. },
  56. getStreams: function () {
  57. return ['youtube://'];
  58. },
  59. getConditions: function () {
  60. return {};
  61. //return this.settings.conditions;
  62. },
  63. getMedia: function() {
  64. var that = this;
  65. var callback = mediaBrowser.getCallbackUrl('getMedia');
  66. var params = {
  67. conditions: JSON.stringify(this.getConditions()),
  68. streams: JSON.stringify(this.getStreams())
  69. };
  70. jQuery.get(
  71. callback,
  72. params,
  73. function(data, status) {
  74. that.mediaFiles = data.media;
  75. that.emptyMessage = data.empty;
  76. that.pager = data.pager;
  77. that.render();
  78. },
  79. 'json'
  80. );
  81. },
  82. render: function() {
  83. var that = this;
  84. mediaBrowser.getActivePanel().removeClass('throbber');
  85. if (this.mediaFiles.length < 1) {
  86. jQuery('<div id="media-empty-message" class="media-empty-message"></div>').appendTo(this.browser)
  87. .html(this.emptyMessage);
  88. return;
  89. }
  90. for (var m in this.mediaFiles) {
  91. mediaFile = this.mediaFiles[m];
  92. var listItem = jQuery('<li></li>').appendTo(this.browser)
  93. .attr('id', 'media-file-' + mediaFile.fid)
  94. .addClass('media-file');
  95. var imgLink = jQuery('<a href="#"></a>').appendTo(listItem)
  96. .html(mediaFile.preview)
  97. .bind('click', mediaFile, function(e) {
  98. // Notify the main browser
  99. //this.selectedMedia = mediaFile;
  100. $('div.media-thumbnail img').removeClass('selected');
  101. $('div.media-thumbnail img', $(this)).addClass('selected');
  102. mediaBrowser.notify('mediaSelected', {mediaFiles: [e.data]});
  103. //that.settings.onSelect(mediaFile);
  104. return false;
  105. });
  106. }
  107. jQuery('<div id="media-pager" class="media-pager"></div>').appendTo(this.browser)
  108. .html(this.pager);
  109. }
  110. };
  111. };
  112. Drupal.media.browser.register('youtube_library', Drupal.media.browser.plugin.youtube_library);
  113. })(jQuery);