Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
/*!
2
 * Media helper for fancyBox
3
 * version: 1.0.5 (Tue, 23 Oct 2012)
4
 * @requires fancyBox v2.0 or later
5
 *
6
 * Usage:
7
 *     $(".fancybox").fancybox({
8
 *         helpers : {
9
 *             media: true
10
 *         }
11
 *     });
12
 *
13
 * Set custom URL parameters:
14
 *     $(".fancybox").fancybox({
15
 *         helpers : {
16
 *             media: {
17
 *                 youtube : {
18
 *                     params : {
19
 *                         autoplay : 0
20
 *                     }
21
 *                 }
22
 *             }
23
 *         }
24
 *     });
25
 *
26
 * Or:
27
 *     $(".fancybox").fancybox({,
28
 *             helpers : {
29
 *             media: true
30
 *         },
31
 *         youtube : {
32
 *             autoplay: 0
33
 *         }
34
 *     });
35
 *
36
 *  Supports:
37
 *
38
 *      Youtube
39
 *          http://www.youtube.com/watch?v=opj24KnzrWo
40
 *          http://www.youtube.com/embed/opj24KnzrWo
41
 *          http://youtu.be/opj24KnzrWo
42
 *      Vimeo
43
 *          http://vimeo.com/40648169
44
 *          http://vimeo.com/channels/staffpicks/38843628
45
 *          http://vimeo.com/groups/surrealism/videos/36516384
46
 *          http://player.vimeo.com/video/45074303
47
 *      Metacafe
48
 *          http://www.metacafe.com/watch/7635964/dr_seuss_the_lorax_movie_trailer/
49
 *          http://www.metacafe.com/watch/7635964/
50
 *      Dailymotion
51
 *          http://www.dailymotion.com/video/xoytqh_dr-seuss-the-lorax-premiere_people
52
 *      Twitvid
53
 *          http://twitvid.com/QY7MD
54
 *      Twitpic
55
 *          http://twitpic.com/7p93st
56
 *      Instagram
57
 *          http://instagr.am/p/IejkuUGxQn/
58
 *          http://instagram.com/p/IejkuUGxQn/
59
 *      Google maps
60
 *          http://maps.google.com/maps?q=Eiffel+Tower,+Avenue+Gustave+Eiffel,+Paris,+France&t=h&z=17
61
 *          http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
62
 *          http://maps.google.com/?ll=48.859463,2.292626&spn=0.000965,0.002642&t=m&z=19&layer=c&cbll=48.859524,2.292532&panoid=YJ0lq28OOy3VT2IqIuVY0g&cbp=12,151.58,,0,-15.56
63
 */
64
(function ($) {
65
        "use strict";
66
 
67
        //Shortcut for fancyBox object
68
        var F = $.fancybox,
69
                format = function( url, rez, params ) {
70
                        params = params || '';
71
 
72
                        if ( $.type( params ) === "object" ) {
73
                                params = $.param(params, true);
74
                        }
75
 
76
                        $.each(rez, function(key, value) {
77
                                url = url.replace( '$' + key, value || '' );
78
                        });
79
 
80
                        if (params.length) {
81
                                url += ( url.indexOf('?') > 0 ? '&' : '?' ) + params;
82
                        }
83
 
84
                        return url;
85
                };
86
 
87
        //Add helper object
88
        F.helpers.media = {
89
                defaults : {
90
                        youtube : {
91
                                matcher : /(youtube\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*)).*/i,
92
                                params  : {
93
                                        autoplay    : 1,
94
                                        autohide    : 1,
95
                                        fs          : 1,
96
                                        rel         : 0,
97
                                        hd          : 1,
98
                                        wmode       : 'opaque',
99
                                        enablejsapi : 1
100
                                },
101
                                type : 'iframe',
102
                                url  : '//www.youtube.com/embed/$3'
103
                        },
104
                        vimeo : {
105
                                matcher : /(?:vimeo(?:pro)?.com)\/(?:[^\d]+)?(\d+)(?:.*)/,
106
                                params  : {
107
                                        autoplay      : 1,
108
                                        hd            : 1,
109
                                        show_title    : 1,
110
                                        show_byline   : 1,
111
                                        show_portrait : 0,
112
                                        fullscreen    : 1
113
                                },
114
                                type : 'iframe',
115
                                url  : '//player.vimeo.com/video/$1'
116
                        },
117
                        metacafe : {
118
                                matcher : /metacafe.com\/(?:watch|fplayer)\/([\w\-]{1,10})/,
119
                                params  : {
120
                                        autoPlay : 'yes'
121
                                },
122
                                type : 'swf',
123
                                url  : function( rez, params, obj ) {
124
                                        obj.swf.flashVars = 'playerVars=' + $.param( params, true );
125
 
126
                                        return '//www.metacafe.com/fplayer/' + rez[1] + '/.swf';
127
                                }
128
                        },
129
                        dailymotion : {
130
                                matcher : /dailymotion.com\/video\/(.*)\/?(.*)/,
131
                                params  : {
132
                                        additionalInfos : 0,
133
                                        autoStart : 1
134
                                },
135
                                type : 'swf',
136
                                url  : '//www.dailymotion.com/swf/video/$1'
137
                        },
138
                        twitvid : {
139
                                matcher : /twitvid\.com\/([a-zA-Z0-9_\-\?\=]+)/i,
140
                                params  : {
141
                                        autoplay : 0
142
                                },
143
                                type : 'iframe',
144
                                url  : '//www.twitvid.com/embed.php?guid=$1'
145
                        },
146
                        twitpic : {
147
                                matcher : /twitpic\.com\/(?!(?:place|photos|events)\/)([a-zA-Z0-9\?\=\-]+)/i,
148
                                type : 'image',
149
                                url  : '//twitpic.com/show/full/$1/'
150
                        },
151
                        instagram : {
152
                                matcher : /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
153
                                type : 'image',
154
                                url  : '//$1/p/$2/media/'
155
                        },
156
                        google_maps : {
157
                                matcher : /maps\.google\.([a-z]{2,3}(\.[a-z]{2})?)\/(\?ll=|maps\?)(.*)/i,
158
                                type : 'iframe',
159
                                url  : function( rez ) {
160
                                        return '//maps.google.' + rez[1] + '/' + rez[3] + '' + rez[4] + '&output=' + (rez[4].indexOf('layer=c') > 0 ? 'svembed' : 'embed');
161
                                }
162
                        }
163
                },
164
 
165
                beforeLoad : function(opts, obj) {
166
                        var url   = obj.href || '',
167
                                type  = false,
168
                                what,
169
                                item,
170
                                rez,
171
                                params;
172
 
173
                        for (what in opts) {
174
                                item = opts[ what ];
175
                                rez  = url.match( item.matcher );
176
 
177
                                if (rez) {
178
                                        type   = item.type;
179
                                        params = $.extend(true, {}, item.params, obj[ what ] || ($.isPlainObject(opts[ what ]) ? opts[ what ].params : null));
180
 
181
                                        url = $.type( item.url ) === "function" ? item.url.call( this, rez, params, obj ) : format( item.url, rez, params );
182
 
183
                                        break;
184
                                }
185
                        }
186
 
187
                        if (type) {
188
                                obj.href = url;
189
                                obj.type = type;
190
 
191
                                obj.autoHeight = false;
192
                        }
193
                }
194
        };
195
 
196
}(jQuery));