Subversion-Projekte lars-tiefland.ci

Revision

Revision 47 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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