PageSourceSearch

https://khoorna.com/applications/themes/WPnio_Framework/inc/fancy/helpers/media.js

js khoorna.com collected 2026-10-03 00:29:16 UTC 5,043 bytes, 211 lines download raw bytes

1// ==========================================================================
2//
3// Media
4// Adds additional media type support
5//
6// ==========================================================================
7;(function ($) {
8
9	'use strict';
10
11	// Formats matching url to final form
12
13	var format = function (url, rez, params) {
14		if ( !url ) {
15			return;
16		}
17
18		params = params || '';
19
20		if ( $.type(params) === "object" ) {
21			params = $.param(params, true);
22		}
23
24		$.each(rez, function (key, value) {
25			url = url.replace('$' + key, value || '');
26		});
27
28		if (params.length) {
29			url += (url.indexOf('?') > 0 ? '&' : '?') + params;
30		}
31
32		return url;
33	};
34
35	// Object containing properties for each media type
36
37	var defaults = {
38		youtube : {
39			matcher : /(youtube\.com|youtu\.be|youtube\-nocookie\.com)\/(watch\?(.*&)?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*))(.*)/i,
40			params  : {
41				autoplay : 1,
42				autohide : 1,
43				fs  : 1,
44				rel : 0,
45				hd  : 1,
46				wmode : 'transparent',
47				enablejsapi : 1,
48				html5 : 1
49			},
50			paramPlace : 8,
51			type  : 'iframe',
52			url   : '//www.youtube.com/embed/$4',
53			thumb : '//img.youtube.com/vi/$4/hqdefault.jpg'
54		},
55
56		vimeo : {
57			matcher : /^.+vimeo.com\/(.*\/)?([\d]+)(.*)?/,
58			params  : {
59				autoplay : 1,
60				hd : 1,
61				show_title    : 1,
62				show_byline   : 1,
63				show_portrait : 0,
64				fullscreen    : 1,
65				api : 1
66			},
67			paramPlace : 3,
68			type : 'iframe',
69			url : '//player.vimeo.com/video/$2'
70		},
71
72		metacafe : {
73			matcher : /metacafe.com\/watch\/(\d+)\/(.*)?/,
74			type    : 'iframe',
75			url     : '//www.metacafe.com/embed/$1/?ap=1'
76		},
77
78		dailymotion : {
79			matcher : /dailymotion.com\/video\/(.*)\/?(.*)/,
80			params : {
81				additionalInfos : 0,
82				autoStart : 1
83			},
84			type : 'iframe',
85			url  : '//www.dailymotion.com/embed/video/$1'
86		},
87
88		vine : {
89			matcher : /vine.co\/v\/([a-zA-Z0-9\?\=\-]+)/,
90			type    : 'iframe',
91			url     : '//vine.co/v/$1/embed/simple'
92		},
93
94		instagram : {
95			matcher : /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
96			type    : 'image',
97			url     : '//$1/p/$2/media/?size=l'
98		},
99
100		// Examples:
101		// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
102		// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
103		// https://www.google.lv/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572
104		google_maps : {
105			matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(((maps\/(place\/(.*)\/)?\@(.*),(\d+.?\d+?)z))|(\?ll=))(.*)?/i,
106			type    : 'iframe',
107			url     : function (rez) {
108				return '//maps.google.' + rez[2] + '/?ll=' + ( rez[9] ? rez[9] + '&z=' + Math.floor(  rez[10]  ) + ( rez[12] ? rez[12].replace(/^\//, "&") : '' )  : rez[12] ) + '&output=' + ( rez[12] && rez[12].indexOf('layer=c') > 0 ? 'svembed' : 'embed' );
109			}
110		}
111	};
112
113	$(document).on('onInit.fb', function (e, instance) {
114
115		$.each(instance.group, function( i, item ) {
116
117			var url	 = item.src || '',
118				type = false,
119				media,
120				thumb,
121				rez,
122				params,
123				urlParams,
124				o,
125				provider;
126
127			// Skip items that already have content type
128			if ( item.type ) {
129				return;
130			}
131
132			media = $.extend( true, {}, defaults, item.opts.media );
133
134			// Look for any matching media type
135			$.each(media, function ( n, el ) {
136				rez = url.match(el.matcher);
137				o   = {};
138				provider = n;
139
140				if (!rez) {
141					return;
142				}
143
144				type = el.type;
145
146				if ( el.paramPlace && rez[ el.paramPlace ] ) {
147					urlParams = rez[ el.paramPlace ];
148
149					if ( urlParams[ 0 ] == '?' ) {
150						urlParams = urlParams.substring(1);
151					}
152
153					urlParams = urlParams.split('&');
154
155					for ( var m = 0; m < urlParams.length; ++m ) {
156						var p = urlParams[ m ].split('=', 2);
157
158						if ( p.length == 2 ) {
159							o[ p[0] ] = decodeURIComponent( p[1].replace(/\+/g, " ") );
160						}
161					}
162				}
163
164				params = $.extend( true, {}, el.params, item.opts[ n ], o );
165
166				url   = $.type(el.url) === "function" ? el.url.call(this, rez, params, item) : format(el.url, rez, params);
167				thumb = $.type(el.thumb) === "function" ? el.thumb.call(this, rez, params, item) : format(el.thumb, rez);
168
169				if ( provider === 'vimeo' ) {
170					url = url.replace('&%23', '#');
171				}
172
173				return false;
174			});
175
176			// If it is found, then change content type and update the url
177
178			if ( type ) {
179				item.src  = url;
180				item.type = type;
181
182				if ( !item.opts.thumb && !( item.opts.$thumb && item.opts.$thumb.length ) ) {
183					item.opts.thumb = thumb;
184				}
185
186				if ( type === 'iframe' ) {
187					$.extend(true, item.opts, {
188						iframe : {
189							preload : false,
190							attr : {
191								scrolling : "no"
192							}
193						}
194					});
195
196					item.contentProvider = provider;
197
198					item.opts.slideClass += ' fancybox-slide--' + ( provider == 'google_maps' ? 'map' : 'video' );
199				}
200
201			} else {
202
203				// If no content type is found, then set it to `image` as fallback
204				item.type = 'image';
205			}
206
207		});
208
209	});
210
211}(window.jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.