PageSourceSearch

https://booksandideas.net/plugins-dist/mediabox/javascript/spip.mediabox.js?1790084230

js booksandideas.net collected 2026-09-24 17:58:30 UTC 9,071 bytes, 275 lines download raw bytes

1(function ($) {
2
3/* Options de l'API Mediabox
4 *
5 * overlayClose: 	(Boolean:true) Allow click on overlay to close the dialog?
6 * type: 		(String:undefined) inline/image/html/ajax/iframe/
7 * minHeight: 		(Number|String:200) The minimum height for the container
8 * minWidth: 		(Number|String:300) The minimum width for the container
9 * maxHeight: 		(Number|String:null) The maximum height for the container. If not specified, the window height is used.
10 * maxWidth: 		(Number|String:null) The maximum width for the container. If not specified, the window width is used.
11 * height: 		(Number|String:null) fixed height for the container
12 * width: 		(Number|String:null) fixed width for the container
13 * autoResize: 		(Boolean:false) Resize container on window resize? Use with caution - this may have undesirable side-effects.
14 * onOpen: 		(Function:null) The callback function used in place of SimpleModal's open
15 * onShow: 		(Function:null) The callback function used after the modal dialog has opened
16 * onClose: 		(Function:null) The callback function used in place of SimpleModal's close
17 * className: 		(String:null) Classes ajoutées au conteneur général
18 * sideBar: 		(String:null) Active le mode sidebar : start | end | top | bottom
19 * ajaxReloadOnClose: 	(string|null) Blocs ajax à recharger à la fermeture, identifiants ou sélecteurs CSS séparés par des virgules.
20 *
21 */
22
23// API modalbox
24	$.mediabox
25	= function (options) {
26		// autodetection du type ?
27		if (typeof(mediabox_autodetect_href) == 'function'
28			&& options.href
29			&& !options.type) {
30			options.type = mediabox_autodetect_href(options.href);
31		}
32		$.fn.mediabox(options);
33	};
34
35	$.modalboxload = $.modalbox = function (href, options) {$.mediabox($.extend({href:href,overlayClose:true},options));};
36	$.modalboxclose = $.mediaboxClose = $.fn.mediaboxClose;
37
38	$.parseMediaboxOptions = function(nameSpace, opener) {
39		var options = {};
40
41		// Attributs data-box-xx et leurs correspondances
42		var data2options = {
43			"width":"width",
44			"height":"height",
45			"min-width":"minWidth",
46			"min-height":"minHeight",
47			"max-width":"maxWidth",
48			"max-height":"maxHeight",
49			"caption-state":"defaultCaptionState",
50			"sidebar":"sideBar",
51			"class":"className",
52			"ajaxreload-on-close":"ajaxReloadOnClose",
53		};
54		var v;
55		for (var o in data2options) {
56			v = ($(opener).data(nameSpace+'-' + o) || '');
57			if (v) {
58				options[data2options[o]] = v;
59			}
60		}
61
62		// si aucun attribut data-box-xx regarder la classe pour compat avec l'ancienne box
63		// boxInline boxIframe boxWidth-xx boxHeight-xx
64		if (!options.length) {
65			var eltclass = $(opener).prop('class');
66			if (eltclass){
67				if (eltclass.indexOf("boxWidth-")!== -1){
68					var w = eltclass.match(/boxWidth-([^\s'">]*)/);
69					w = w[1].replace(/pc/, '%'); // % not allowed in html attribute ; use 100pc instead of 100%
70					options["width"] = w;
71				}
72				if (eltclass.indexOf("boxHeight-")!== -1){
73					var h = eltclass.match(/boxHeight-([^\s'">]*)/);
74					h = h[1].replace(/pc/, '%'); // % not allowed in html attribute ; use 100pc instead of 100%
75					options["height"] = h;
76				}
77				if (eltclass.indexOf("boxIframe")!== -1){
78					options["type"] = 'iframe';
79				}
80				if (eltclass.indexOf("boxInline")!== -1) {
81					options["type"] = 'inline';
82				}
83			}
84		}
85
86		// et les autres options, dont le type, qui est prioritaire ici si fourni explicitement
87		data2options = {"same-popin":"samePopin","type":"type"};
88		for (var o in data2options) {
89			v = ($(opener).data(nameSpace+'-' + o) || '');
90			if (v) {
91				options[data2options[o]] = v;
92			}
93		}
94
95		return options;
96	}
97
98})(jQuery);
99/*
100 *
101 *
102 *
103 */
104var mediaboxInit = function() {
105
106	// recuperer les préférences de l'utilisateur
107	var b = $.extend({},mediabox_settings);
108
109	// renommer le data-box-type en cas de namespace personnalisé
110	if (b.ns !== 'box') {
111		$('[data-box-type]').each(function(i,e) {
112			var $e = $(e);
113			var d = $e.attr('data-box-type');
114			$e.removeAttr('data-box-type').attr('data-'+b.ns+'-type',d);
115		});
116	}
117
118	// 1) Auto completion de data-href-popin qd on peut
119	// 2) Auto detection de type de contenu pour la popin
120	if (b.auto_detect) {
121
122		var $popins = $('[data-href-popin],[data-'+b.ns+'-type]' + (window.var_zajax_content ? ',[data-var_zajax],a.popin' : ''))
123			.add(b.sel_c)
124			.not(ajaxbloc_selecteur,'.ajaxbloc','.hasbox');
125
126		$popins.each(function(i,e) {
127			var $e = $(e);
128			var url = $e.attr('href') || "./";
129			var popin = $e.attr('data-href-popin');
130			var type = $e.attr('data-'+b.ns+'-type') || '';
131
132			if ( !popin ) {
133				// requete ajax pour recuperer un inclure
134				// ex : [data-ajax-env="(#ARRAY{fond,modele/emb,id_document,2}|encoder_contexte_ajax)"]
135				var env = $e.attr('data-ajax-env') ;
136				if ( env ) {
137					url = parametre_url( parametre_url(url,'var_ajax',1) ,'var_ajax_env',env)
138					$e.removeAttr('data-ajax-env');
139					type = 'ajax';
140				}
141				// compatibilité zbloc
142				var za = $e.attr('data-var_zajax') ;
143				if ( za !== undefined || $e.hasClass('popin') ) {
144					// content est le bloc de contenu, quel que soit son nom
145					if (za === 'content' && window.var_zajax_content) {
146						za = window.var_zajax_content;
147					}
148					url = parametre_url(url,'var_zajax', za || window.var_zajax_content);
149					$e.removeAttr('data-var_zajax');
150					type = 'ajax';
151				}
152
153				// compléter href-popin si pertinent
154				if ((url !== $e.attr('href') || (!popin && type)) && url !== "./" ) {
155					$e.attr('data-href-popin', url);
156				}
157			}
158
159			url = popin || url;
160
161			// récuperer le type sur une éventuelle variante de data-
162			// ex : data-box-image-attrs="{height:500}"
163			if ( !type ) {
164				var attrs = $e.data();
165				var types = ['inline','html','iframe','image','ajax'];
166				types.some( function(e) {
167					// box-image => boxImage
168					var k = b.ns + e.charAt(0).toUpperCase() + e.slice(1);
169					if (attrs[k]) {
170						type = e;
171						return true;
172					}
173				});
174			}
175
176			// deduire le type de contenu (regex)
177			if ( !type && typeof(mediabox_autodetect_href) == 'function' ) {
178				type = mediabox_autodetect_href(url);
179			}
180
181			// [par defaut : iframe]
182			// on en profite pour mettre à jour l'ancienne syntaxe
183			if ( !type || $e.hasClass('boxIframe')) {
184				type = "iframe";
185				$e.removeClass('boxIframe');
186			}
187			// enfin on pose le data-
188			$e.attr('data-' + b.ns + '-type',type);
189
190		});
191	}
192
193	// mode galerie
194	if (b.sel_g) {
195		// gérer les conteneurs et/ou cibles directes
196		var $items = $();
197		$(b.sel_g).each(function(i,e){
198			$items = $items.add(
199				$(this).is('a[type^=\'image\']')
200				? $(this)
201				: $(this).find('a[type^=\'image\']')
202			);
203		});
204		$items
205		.not('.hasbox')
206		.removeAttr('onclick') // se debarrasser du onclick de SPIP
207		.mediabox({rel:'galerieauto',slideshow:true,slideshowAuto:false,type:'image'})
208		.addClass('hasbox');
209	}
210
211	// box auto sur tous les liens vers des images
212	if (b.tt_img) {
213		$('a[type^="image"],a[href$=".png"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".svg"],a[href$=".webp"]')
214		.not('.hasbox')
215		.removeAttr('onclick') // se debarrasser du onclick de SPIP
216		.mediabox({type:'image'})
217		.addClass('hasbox')
218		;
219	}
220
221	// charger la box le selecteur general
222	$(b.sel_c)
223		.not('.hasbox')
224		.mediabox()
225		.addClass('hasbox') // noter qu\'on l\'a vue
226	;
227
228	$('[data-href-popin]', this)
229		.not('.hasbox')
230		.click(function(){if ($.modalbox) $.modalbox($(this).attr('data-href-popin'), $.parseMediaboxOptions(b.ns, this));return false;})
231		.addClass('hasbox');
232
233};
234
235(function($) {
236	if (typeof onAjaxLoad == 'function') onAjaxLoad(mediaboxInit);
237	$(mediaboxInit);
238})(jQuery);
239
240/**
241 * Déterminer a priori la nature d'une ressource
242 * mediabox_autodetect_href('https://contrib.spip.net/') -> "iframe"
243 * @ href [string] expression à analyser
244 * @ options [objet]
245 * return [string|array|false] type de contenu correspondant
246 */
247function mediabox_autodetect_href(href, options) {
248
249		options = $.extend({
250			breakMode : true, // retour rapide dès le premier succès, sinon un tableau complet
251			tests : {
252				image:  /\.(gif|png|jp(e|g|eg)|bmp|ico|webp|jxr|svg)((#|\?).*)?$/i,
253				inline: /^[#.]\w/,
254				html:   /^\s*<[\w!][^<]*>/,
255				ajax:   /((\?|&(amp;)?)var_z?ajax=|cache-ajaxload\/)/i,
256				iframe: /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i,
257			},
258			},options);
259
260		var matched = options.breakMode ? false : [];
261
262		$.each(options.tests, function(type, regex) {
263				// eviter de confondre les URLs /File:.....(svg|png|jpg) de wikipedia avec des images
264				if ( href.match(regex) && !href.match('/File:[^/]+(\\#|[?]|$)') ) {
265					if (options.breakMode) {
266						matched = type;
267						return false;
268					} else {
269						matched.push(type);
270					}
271				}
272		});
273
274		return matched;
275};

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.