Projet

Général

Profil

Paste
Télécharger (4,18 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media_youtube / js / media_youtube.fromurl.js @ 13755f8d

1

    
2
/**
3
 *  @file
4
 *  Create the 'YouTube' tab for the WYSIWYG plugins.
5
 */
6

    
7
// (function ($) {
8
//   namespace('Drupal.media.browser.plugin');
9
//
10
//   Drupal.media.browser.plugin.media_youtube = function(mediaBrowser, options) {
11
//     return {
12
//       init: function() {
13
//         tabset = mediaBrowser.getTabset();
14
//         tabset.tabs('add', '#media_youtube', 'YouTube');
15
//         mediaBrowser.listen('tabs.show', function (e, id) {
16
//           if (id == 'media_youtube') {
17
//             // We only need to set this once.
18
//             // We probably could set it upon load.
19
//             if (mediaBrowser.getActivePanel().html() == '') {
20
//               mediaBrowser.getActivePanel().html(options.media_youtube);
21
//             }
22
//           }
23
//         });
24
//       }
25
//     }
26
//   };
27
//
28
//   // For now, I guess self registration makes sense.
29
//   // Really though, we should be doing it via drupal_add_js and some settings
30
//   // from the drupal variable.
31
//   //@todo: needs a review.
32
//   Drupal.media.browser.register('media_youtube', Drupal.media.browser.plugin.media_youtube, {});
33
// })(jQuery);
34

    
35
(function ($) {
36
  namespace('media.browser.plugin');
37

    
38
  Drupal.media.browser.plugin.youtube_library = function(mediaBrowser, options) {
39

    
40
    return {
41
      mediaFiles: [],
42
      init: function() {
43
        tabset = mediaBrowser.getTabset();
44
        tabset.tabs('add', '#youtube_library', 'YouTube');
45
        var that = this;
46
        mediaBrowser.listen('tabs.show', function (e, id) {
47
          if (id == 'youtube_library') {
48
            // This is kinda rough, I'm not sure who should delegate what here.
49
            mediaBrowser.getActivePanel().addClass('throbber');
50
            mediaBrowser.getActivePanel().html('');
51
            //mediaBrowser.getActivePanel().addClass('throbber');
52

    
53
            // Assumes we have to refresh everytime.
54
            // Remove any existing content
55
            mediaBrowser.getActivePanel().append('<ul></ul>');
56
            that.browser = $('ul', mediaBrowser.getActivePanel());
57
            that.browser.addClass('clearfix');
58
            that.getMedia();
59
          }
60
        });
61
      },
62

    
63
      getStreams: function () {
64
        return ['youtube://'];
65
      },
66

    
67
      getConditions: function () {
68
        return {};
69
        //return this.settings.conditions;
70
      },
71

    
72
      getMedia: function() {
73
        var that = this;
74
        var callback = mediaBrowser.getCallbackUrl('getMedia');
75
        var params = {
76
          conditions: JSON.stringify(this.getConditions()),
77
          streams: JSON.stringify(this.getStreams())
78
        };
79
        jQuery.get(
80
          callback,
81
          params,
82
          function(data, status) {
83
            that.mediaFiles = data.media;
84
            that.emptyMessage = data.empty;
85
            that.pager = data.pager;
86
            that.render();
87
          },
88
          'json'
89
        );
90
      },
91

    
92
      render: function() {
93
        var that = this;
94
        mediaBrowser.getActivePanel().removeClass('throbber');
95
        if (this.mediaFiles.length < 1) {
96
          jQuery('<div id="media-empty-message" class="media-empty-message"></div>').appendTo(this.browser)
97
            .html(this.emptyMessage);
98
          return;
99
        }
100

    
101
        for (var m in this.mediaFiles) {
102
          mediaFile = this.mediaFiles[m];
103

    
104
          var listItem = jQuery('<li></li>').appendTo(this.browser)
105
            .attr('id', 'media-file-' + mediaFile.fid)
106
            .addClass('media-file');
107

    
108
          var imgLink = jQuery('<a href="#"></a>').appendTo(listItem)
109
            .html(mediaFile.preview)
110
            .bind('click', mediaFile, function(e) {
111
              // Notify the main browser
112
              //this.selectedMedia = mediaFile;
113
              $('div.media-thumbnail img').removeClass('selected');
114
              $('div.media-thumbnail img', $(this)).addClass('selected');
115
              mediaBrowser.notify('mediaSelected', {mediaFiles: [e.data]});
116
              //that.settings.onSelect(mediaFile);
117
              return false;
118
            });
119
        }
120
        jQuery('<div id="media-pager" class="media-pager"></div>').appendTo(this.browser)
121
          .html(this.pager);
122
      }
123
  };
124
};
125

    
126
  Drupal.media.browser.register('youtube_library', Drupal.media.browser.plugin.youtube_library);
127
})(jQuery);