Projet

Général

Profil

Paste
Télécharger (7,73 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / lightbox2 / js / lightbox_video.js @ 76df55b7

1
/* $Id: lightbox_video.js,v 1.1.4.20 2010/09/21 17:57:22 snpower Exp $ */
2

    
3
/**
4
 * Lightbox video
5
 * @author
6
 *   Stella Power, <http://drupal.org/user/66894>
7
 */
8
var Lightvideo;
9

    
10
// start jQuery block
11
(function ($) {
12

    
13
Lightvideo = {
14

    
15
  // startVideo()
16
  startVideo: function (href) {
17
    if (Lightvideo.checkKnownVideos(href)) {
18
      return;
19
    }
20
    else if (href.match(/\.mov$/i)) {
21
      if (navigator.plugins && navigator.plugins.length) {
22
        Lightbox.modalHTML ='<object id="qtboxMovie" type="video/quicktime" codebase="http://www.apple.com/qtactivex/qtplugin.cab" data="'+href+'" width="'+Lightbox.modalWidth+'" height="'+Lightbox.modalHeight+'"><param name="allowFullScreen" value="true"></param><param name="src" value="'+href+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
23
      } else {
24
        Lightbox.modalHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+Lightbox.modalWidth+'" height="'+Lightbox.modalHeight+'" id="qtboxMovie"><param name="allowFullScreen" value="true"></param><param name="src" value="'+href+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
25
      }
26
    }
27
    else if (href.match(/\.wmv$/i) || href.match(/\.asx$/i)) {
28
      Lightbox.modalHTML = '<object NAME="Player" WIDTH="'+Lightbox.modalWidth+'" HEIGHT="'+Lightbox.modalHeight+'" align="left" hspace="0" type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param name="allowFullScreen" value="true"></param><param NAME="URL" VALUE="'+href+'"></param><param NAME="AUTOSTART" VALUE="true"></param><param name="showControls" value="true"></param><embed WIDTH="'+Lightbox.modalWidth+'" HEIGHT="'+Lightbox.modalHeight+'" align="left" hspace="0" SRC="'+href+'" TYPE="application/x-oleobject" AUTOSTART="false"></embed></object>';
29
    }
30
    else {
31
      Lightbox.videoId = href;
32
      variables = '';
33
      if (!href.match(/\.swf$/i)) {
34
        href = Lightbox.flvPlayer + '?file=' + href;
35
        if (Lightbox.flvFlashvars.length) {
36
          variables = Lightbox.flvFlashvars;
37
        }
38
      }
39

    
40
      Lightvideo.createEmbed(href, "flvplayer", "#ffffff", variables);
41
    }
42
  },
43

    
44
  // createEmbed()
45
  createEmbed: function(href, id, color, variables) {
46
    var bgcolor = 'bgcolor="' + color + '"';
47
    var flashvars = '';
48
    if (variables) {
49
      flashvars = 'flashvars="' + variables + '"';
50

    
51
    }
52
    Lightbox.modalHTML = '<embed type="application/x-shockwave-flash" ' +
53
      'src="' + href + '" ' +
54
      'id="' + id + '" name="' + id + '" ' + bgcolor + ' ' +
55
      'quality="high" wmode="transparent" ' + flashvars + ' ' +
56
      'height="' + Lightbox.modalHeight + '" ' +
57
      'width="' + Lightbox.modalWidth + '" ' +
58
      'allowfullscreen="true" ' +
59
      '></embed>';
60
  },
61

    
62

    
63
  // checkKnownVideos()
64
  checkKnownVideos: function(href) {
65
    if (Lightvideo.checkYouTubeVideo(href) || Lightvideo.checkGoogleVideo(href) ||
66
      Lightvideo.checkMySpaceVideo(href) || Lightvideo.checkLiveVideo(href) ||
67
      Lightvideo.checkMetacafeVideo(href) ||
68
      Lightvideo.checkIFilmSpikeVideo(href)
69
      ) {
70
      return true;
71
    }
72
    return false;
73
  },
74

    
75

    
76
  // checkYouTubeVideo()
77
  checkYouTubeVideo: function(href) {
78
    var patterns = [
79
      'youtube.com/v/([^"&]+)',
80
      'youtube.com/watch\\?v=([^"&]+)',
81
      'youtube.com/\\?v=([^"&]+)'
82
      ];
83

    
84
    for (var i = 0; i < patterns.length; i++) {
85
      var pattern = new RegExp(patterns[i], "i");
86
      var results = pattern.exec(href);
87
      if (results !== null) {
88
        Lightbox.videoId = results[1];
89
        var href = "http://www.youtube.com/v/"+Lightbox.videoId;
90
        var variables = 'fs=1';
91
        if (Lightbox.flvFlashvars.length) {
92
          variables = variables + '&' + Lightbox.flvFlashvars;
93
          href = href + '&' + variables;
94
        }
95
        Lightvideo.createEmbed(href, "flvvideo", "#ffffff", variables);
96
        return true;
97
      }
98
    }
99
    return false;
100
  },
101

    
102
  // checkGoogleVideo()
103
  checkGoogleVideo: function(href) {
104
    var patterns = [
105
      'http://video.google.[a-z]{2,4}/googleplayer.swf\\?docId=(-?\\d*)',
106
      'http://video.google.[a-z]{2,4}/videoplay\\?docid=([^&]*)&',
107
      'http://video.google.[a-z]{2,4}/videoplay\\?docid=(.*)'
108
      ];
109

    
110
    for (var i = 0; i < patterns.length; i++) {
111
      var pattern = new RegExp(patterns[i], "i");
112
      var results = pattern.exec(href);
113
      if (results !== null) {
114
        Lightbox.videoId = results[1];
115
        var href = "http://video.google.com/googleplayer.swf?docId="+Lightbox.videoId+"&hl=en";
116
        var variables = 'fs=true';
117
        if (Lightbox.flvFlashvars.length) {
118
          variables = variables + '&' + Lightbox.flvFlashvars;
119
          href = href + '&' + variables;
120
        }
121
        Lightvideo.createEmbed(href, "flvvideo", "#ffffff", variables);
122
        return true;
123
      }
124
    }
125
    return false;
126
  },
127

    
128
  // checkMetacafeVideo()
129
  checkMetacafeVideo: function(href) {
130
    var patterns = [
131
      'metacafe.com/watch/(\.[^/]*)/(\.[^/]*)/',
132
      'metacafe.com/watch/(\.[^/]*)/(\.*)',
133
      'metacafe.com/fplayer/(\.[^/]*)/(\.[^.]*).'
134
      ];
135

    
136
    for (var i = 0; i < patterns.length; i++) {
137
      var pattern = new RegExp(patterns[i], "i");
138
      var results = pattern.exec(href);
139
      if (results !== null) {
140
        Lightbox.videoId = results[1];
141
        Lightvideo.createEmbed("http://www.metacafe.com/fplayer/"+Lightbox.videoId+"/.swf", "flvvideo", "#ffffff");
142
        return true;
143
      }
144
    }
145
    return false;
146
  },
147

    
148
  // checkIFilmSpikeVideo()
149
  checkIFilmSpikeVideo: function(href) {
150
    var patterns = [
151
      'spike.com/video/[^/&"]*?/(\\d+)',
152
      'ifilm.com/video/[^/&"]*?/(\\d+)',
153
      'spike.com/video/([^/&"]*)',
154
      'ifilm.com/video/([^/&"]*)'
155
      ];
156

    
157
    for (var i = 0; i < patterns.length; i++) {
158
      var pattern = new RegExp(patterns[i], "i");
159
      var results = pattern.exec(href);
160
      if (results !== null) {
161
        Lightbox.videoId = results[1];
162
        Lightvideo.createEmbed("http://www.spike.com/efp", "flvvideo", "#000", "flvbaseclip="+Lightbox.videoId+"&amp;");
163
        return true;
164
      }
165
    }
166
    return false;
167
  },
168

    
169
  // checkMySpaceVideo()
170
  checkMySpaceVideo: function(href) {
171
    var patterns = [
172
      'src="myspace.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)',
173
      'myspace.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)',
174
      'src="myspacetv.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)"',
175
      'myspacetv.com/index.cfm\\?fuseaction=vids.individual&videoid=([^&"]+)'
176
      ];
177

    
178
    for (var i = 0; i < patterns.length; i++) {
179
      var pattern = new RegExp(patterns[i], "i");
180
      var results = pattern.exec(href);
181
      if (results !== null) {
182
        Lightbox.videoId = results[1];
183
        Lightvideo.createEmbed("http://lads.myspace.com/videos/vplayer.swf", "flvvideo", "#ffffff", "m="+Lightbox.videoId);
184
        return true;
185
      }
186
    }
187
    return false;
188
  },
189

    
190
  // checkLiveVideo()
191
  checkLiveVideo: function(href) {
192
    var patterns = [
193
      'livevideo.com/flvplayer/embed/([^"]*)"',
194
      'livevideo.com/video/[^/]*?/([^/]*)/',
195
      'livevideo.com/video/([^/]*)/'
196
      ];
197

    
198
    for (var i = 0; i < patterns.length; i++) {
199
      var pattern = new RegExp(patterns[i], "i");
200
      var results = pattern.exec(href);
201
      if (results !== null) {
202
        Lightbox.videoId = results[1];
203
        Lightvideo.createEmbed("http://www.livevideo.com/flvplayer/embed/"+Lightbox.videoId, "flvvideo", "#ffffff");
204
        return true;
205
      }
206
    }
207
    return false;
208
  }
209

    
210
};
211

    
212
//End jQuery block
213
}(jQuery));