Browse Source

Normaliser les nommages et ranger toutes les config specifiques colorbox dans un sous-casier de la config

pull/1/head
Cerdic 3 years ago
parent
commit
d3f311ce80
  1. 9
      colorbox/fancybox/mediabox_config_theme.php
  2. 1
      formulaires/configurer_mediabox.html
  3. 79
      formulaires/inc-colorbox-configurer_mediabox.html
  4. 22
      javascript/colorbox.mediabox.js
  5. 2
      javascript/spip.mediabox.js
  6. 24
      javascript/splash.mediabox.js
  7. 128
      mediabox_pipelines.php

9
colorbox/fancybox/mediabox_config_theme.php

@ -4,11 +4,10 @@ if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function mediabox_config_theme() {
$config = array(
'minHeight' => false,
'minWidth' => false
);
function mediabox_config_colorbox_fancybox($config) {
$config['colorbox']['minHeight'] = false;
$config['colorbox']['minWidth'] = false;
return $config;
}

1
formulaires/configurer_mediabox.html

@ -43,6 +43,7 @@
</div>
</div>
<input type="hidden" name="box_type" value="colorbox" />
<INCLURE{fond=formulaires/inc-colorbox-configurer_mediabox,env} />

79
formulaires/inc-colorbox-configurer_mediabox.html

@ -2,45 +2,54 @@
<div class="fieldset"><fieldset><legend><:mediabox:label_apparence:></legend>
<div class="editer-groupe">
[<div class="editer editer_skin[ (#ENV**{erreurs}|table_valeur{skin}|oui)erreur]">
#SET{name,colorbox/skin}#SET{obli,''}#SET{defaut,black-striped}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
[<div class="editer editer_skin editer_colorbox_skin[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label><:mediabox:label_skin:></label>
(#REM|colorbox_lister_skins|mediabox_presenter_selection_skins{#ENV{skin},'skin'})
(#REM|colorbox_lister_skins|mediabox_presenter_selection_skins{#ENV{colorbox/skin,#GET{defaut}},'colorbox\[skin\]'})
</div>]
<div class="editer editer_transition[ (#ENV**{erreurs}|table_valeur{transition}|oui)erreur]">
<label for='transition'><:mediabox:label_transition:></label>
<select name="transition" id="transition">
<option value="elastic"[(#ENV{transition}|=={elastic}|oui)selected="selected"]><:mediabox:label_choix_transition_elastic:></option>
<option value="fade"[(#ENV{transition}|=={fade}|oui)selected="selected"]><:mediabox:label_choix_transition_fade:></option>
<option value="none"[(#ENV{transition}|=={none}|oui)selected="selected"]><:mediabox:label_choix_transition_none:></option>
#SET{name,colorbox/transition}#SET{obli,''}#SET{defaut,elastic}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_transition[ (#ENV**{erreurs}|table_valeur{transition}|oui)erreur]">
<label for='colorbox_transition'><:mediabox:label_transition:></label>
<select name="colorbox[transition]" id="colorbox_transition">
<option value="elastic"[(#ENV{#GET{name},#GET{defaut}}|=={elastic}|oui)selected="selected"]><:mediabox:label_choix_transition_elastic:></option>
<option value="fade"[(#ENV{#GET{name},#GET{defaut}}|=={fade}|oui)selected="selected"]><:mediabox:label_choix_transition_fade:></option>
<option value="none"[(#ENV{#GET{name},#GET{defaut}}|=={none}|oui)selected="selected"]><:mediabox:label_choix_transition_none:></option>
</select>
</div>
<div class="editer editer_speed[ (#ENV**{erreurs}|table_valeur{speed}|oui)erreur]">
<label for='speed'><:mediabox:label_speed:></label>
<input type="text" name="speed" class="text" id="speed" size="10" value="#ENV*{speed}" />
</div>
<div class="editer minWidth[ (#ENV**{erreurs}|table_valeur{minWidth}|oui)erreur]">
<label for='minWidth'><:mediabox:label_minwidth:></label>
<input type="text" name="minWidth" class="text" id="minWidth" size="10" value="#ENV*{minWidth}" />
</div>
<div class="editer maxWidth[ (#ENV**{erreurs}|table_valeur{maxWidth}|oui)erreur]">
<label for='maxWidth'><:mediabox:label_maxwidth:></label>
<input type="text" name="maxWidth" class="text" id="maxWidth" size="10" value="#ENV*{maxWidth}" />
</div>
<div class="editer minHeight[ (#ENV**{erreurs}|table_valeur{minHeight}|oui)erreur]">
<label for='minHeight'><:mediabox:label_minheight:></label>
<input type="text" name="minHeight" class="text" id="minHeight" size="10" value="#ENV*{minHeight}" />
</div>
<div class="editer maxHeight[ (#ENV**{erreurs}|table_valeur{maxHeight}|oui)erreur]">
<label for='maxHeight'><:mediabox:label_maxheight:></label>
<input type="text" name="maxHeight" class="text" id="maxHeight" size="10" value="#ENV*{maxHeight}" />
</div>
<div class="editer editer_slideshow_speed[ (#ENV**{erreurs}|table_valeur{slideshow_speed}|oui)erreur]">
<label for='slideshow_speed'><:mediabox:label_slideshow_speed:></label>
<input type="text" name="slideshow_speed" class="text" id="slideshow_speed" size="10" value="#ENV*{slideshow_speed}" />
</div>
<div class="editer editer_opacite[ (#ENV**{erreurs}|table_valeur{opacite}|oui)erreur]">
<label for='opacite'><:mediabox:label_opacite:></label>
<input type="text" name="opacite" class="text" id="opacite" size="10" value="#ENV*{opacite}" />
#SET{name,colorbox/speed}#SET{obli,''}#SET{defaut,200}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_speed[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label for='colorbox_speed'><:mediabox:label_speed:></label>
<input type="text" name="colorbox[speed]" class="text" id="colorbox_speed" size="10" value="#ENV{#GET{name},#GET{defaut}}" />
</div>
#SET{name,colorbox/minWidth}#SET{obli,''}#SET{defaut,400px}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_minWidth[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label for='colorbox_minWidth'><:mediabox:label_minwidth:></label>
<input type="text" name="colorbox[minWidth]" class="text" id="colorbox_minWidth" size="10" value="#ENV{#GET{name},#GET{defaut}}" />
</div>
#SET{name,colorbox/maxWidth}#SET{obli,''}#SET{defaut,90%}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_maxWidth[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label for='colorbox_maxWidth'><:mediabox:label_maxwidth:></label>
<input type="text" name="colorbox[maxWidth]" class="text" id="colorbox_maxWidth" size="10" value="#ENV{#GET{name},#GET{defaut}}" />
</div>
#SET{name,colorbox/minHeight}#SET{obli,''}#SET{defaut,''}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_minHeight[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label for='colorbox_minHeight'><:mediabox:label_minheight:></label>
<input type="text" name="colorbox[minHeight]" class="text" id="colorbox_minHeight" size="10" value="#ENV{#GET{name},#GET{defaut}}" />
</div>
#SET{name,colorbox/maxHeight}#SET{obli,''}#SET{defaut,90%}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_maxHeight[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label for='colorbox_maxHeight'><:mediabox:label_maxheight:></label>
<input type="text" name="colorbox[maxHeight]" class="text" id="colorbox_maxHeight" size="10" value="#ENV{#GET{name},#GET{defaut}}" />
</div>
#SET{name,colorbox/slideshow_speed}#SET{obli,''}#SET{defaut,2500}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_slideshow_speed[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label for='colorbox_slideshow_speed'><:mediabox:label_slideshow_speed:></label>
<input type="text" name="colorbox[slideshow_speed]" class="text" id="colorbox_slideshow_speed" size="10" value="#ENV{#GET{name},#GET{defaut}}" />
</div>
#SET{name,colorbox/opacite}#SET{obli,''}#SET{defaut,0.9}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
<div class="editer editer_colorbox_opacite[ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
<label for='colorbox_opacite'><:mediabox:label_opacite:></label>
<input type="text" name="colorbox[opacite]" class="text" id="colorbox_opacite" size="10" value="#ENV{#GET{name},#GET{defaut}}" />
</div>
</div></fieldset>
</div>

22
javascript/colorbox.mediabox.js

@ -7,7 +7,7 @@
mediabox: function(options) {
var cfg = $.extend(options,{});
var b = typeof(box_settings) == 'object' ? box_settings : {};
var b = typeof(mediabox_settings) == 'object' ? mediabox_settings : {};
// completer le type
var type = (this === jQuery.fn) ? cfg.type : this.data(b.ns+'-type');
@ -49,18 +49,18 @@
var initConfig = function() {
var b = typeof(box_settings) == 'object' ? box_settings : {};
var b = typeof(mediabox_settings) == 'object' ? mediabox_settings : {};
console.log(b.colorbox);
var cbox_options = {
overlayClose: true,
iframe: false,
transition:b.trans || 'elastic',
speed:b.speed || 350,
maxWidth:b.maxW || false,
maxHeight:b.maxH || false,
minWidth:b.minW || false,
minHeight:b.minH || false,
opacity:b.opa || '0.85',
transition:b.colorbox.transition || 'elastic',
speed:b.colorbox.speed || 350,
maxWidth:b.colorbox.maxWidth || false,
maxHeight:b.colorbox.maxHeight || false,
minWidth:b.colorbox.minWidth || false,
minHeight:b.colorbox.minHeight || false,
opacity:b.colorbox.opacity || '0.85',
slideshowStart:b.str_ssStart,
slideshowStop:b.str_ssStop,
current:b.str_current,
@ -75,7 +75,7 @@
//onCleanup:|| $.noop(), // hors API
onClosed:b.onClose || $.noop(),
};
console.log(cbox_options);
if (typeof($.colorbox) == 'function') {
$.colorbox.settings = $.extend($.colorbox.settings,cbox_options);
}

2
javascript/spip.mediabox.js

@ -43,7 +43,7 @@
var mediaboxInit = function() {
// recuperer les préférences de l'utilisateur
var b = $.extend({ns: 'box'},box_settings);
var b = $.extend({},mediabox_settings);
// renommer le data-box-type en cas de namespace personnalisé
if (b.ns != 'box') {

24
javascript/splash.mediabox.js

@ -1,26 +1,18 @@
jQuery(function($){
// poser le cookie au callback de la box chargee
var set_cookie = function() {
Cookies.set("modalsplash", box_settings.splash_url, { expires: 7 });
Cookies.set("modalsplash", mediabox_settings.splash_url, { expires: 7 });
}
$.modalboxsplash = function(href, options) {
if (box_settings_iframe) {
$.fn.mediabox($.extend({
href:href,
onComplete:set_cookie,
overlayClose:true,
iframe: true,
width: box_settings_splash_width,
height: box_settings_splash_height
},options));
} else {
$.fn.mediabox($.extend({
href:href,
onComplete:set_cookie,
overlayClose:true
},options));
if (mediabox_settings.splash_iframe) {
options = $.extend({
type: 'iframe',
width: mediabox_settings.splash_width || '',
height: mediabox_settings.splash_height || ''
});
}
$.modalbox(href,$.extend({onShow:set_cookie},options));
};
// ouvrir la splash page si pas deja vue
if (Cookies.get("modalsplash") != box_settings.splash_url) {

128
mediabox_pipelines.php

@ -9,6 +9,19 @@ function mediabox_config($public = null) {
include_spip('inc/config');
$config = lire_config('mediabox', array());
// conversion a la volee de l'ancienne config toute melangee
if (empty($config['box_type']) and empty($config['colorbox']) and !empty($config['transition'])) {
$config['box_type'] = 'colorbox';
$config['colorbox'] = [];
foreach (['skin', 'transition', 'speed', 'maxWidth', 'maxHeight', 'minWidth', 'minHeight', 'slideshow_speed', 'opacite'] as $k) {
if (!empty($config[$k])) {
$config['colorbox'][$k] = $config[$k];
unset($config[$k]);
}
}
ecrire_config('mediabox', $config);
}
$config = array_merge(array(
'active' => 'oui',
'traiter_toutes_images' => 'oui',
@ -17,15 +30,18 @@ function mediabox_config($public = null) {
'splash_url' => '',
'splash_width' => '600px',
'splash_height' => '90%',
'skin' => 'black-striped',
'transition' => 'elastic',
'speed' => '200',
'maxWidth' => '90%',
'maxHeight' => '90%',
'minWidth' => '400px',
'minHeight' => '',
'slideshow_speed' => '2500',
'opacite' => '0.9',
'box_type' => 'colorbox',
'colorbox' => [
'skin' => 'black-striped',
'transition' => 'elastic',
'speed' => '200',
'maxWidth' => '90%',
'maxHeight' => '90%',
'minWidth' => '400px',
'minHeight' => '',
'slideshow_speed' => '2500',
'opacite' => '0.9',
]
), $config);
if ((is_null($public) and test_espace_prive()) or $public === false) {
@ -34,12 +50,15 @@ function mediabox_config($public = null) {
'selecteur_galerie' => '#portfolios a[type^=\'image/\']',
'selecteur_commun' => '.mediabox, .iconifier a[href$=jpg],.iconifier a[href$=png],.iconifier a[href$=gif]',
'splash_url' => '',
'skin' => 'white-shadow',
'maxWidth' => '90%',
'maxHeight' => '95%',
'minWidth' => '600px',
'minHeight' => '300px',
'opacite' => '0.9',
'box_type' => 'colorbox',
'colorbox' => [
'skin' => 'white-shadow',
'maxWidth' => '90%',
'maxHeight' => '95%',
'minWidth' => '600px',
'minHeight' => '300px',
'opacite' => '0.9',
]
));
}
@ -50,9 +69,14 @@ function mediabox_config($public = null) {
}
// charger la config du theme uniquement dans le public
if (!test_espace_prive() and include_spip('colorbox/' . $config['skin'] . '/mediabox_config_theme')) {
$config_theme = mediabox_config_theme();
$config = array_merge($config, $config_theme);
if (!test_espace_prive()
and $box_type = $config['box_type']
and !empty($config[$box_type]['skin'])
and $box_skin = $config[$box_type]['skin']
and include_spip("$box_type/$box_skin/mediabox_config_theme")
and function_exists($f = "mediabox_config_{$box_type}_$box_skin")
and $config_theme = $f($config)) {
$config = $config_theme;
}
return $config;
@ -61,9 +85,14 @@ function mediabox_config($public = null) {
function mediabox_insert_head_css($flux) {
$config = mediabox_config();
if ($config['active'] == 'oui') {
$css_files = [
(test_espace_prive() ? 'prive/' : '') . 'colorbox/' . $config['skin'] . '/colorbox.css',
];
$css_files = [];
if ($box_type = $config['box_type']
and !empty($config[$box_type]['skin'])
and $box_skin = $config[$box_type]['skin']) {
$css_files[] = (test_espace_prive() ? 'prive/' : '') . "{$box_type}/{$box_skin}/{$box_type}.css";
}
foreach($css_files as $file) {
if ($f = find_in_path($file)) {
@ -74,37 +103,38 @@ function mediabox_insert_head_css($flux) {
/**
* Initialiser la config de la mediabox
*/
$configmediabox = '<script type="text/javascript">/* <![CDATA[ */
var box_settings = {auto_detect: true'
. ',tt_img:' . ($config['traiter_toutes_images'] == 'oui' ? 'true' : 'false')
. ',sel_g:"' . $config['selecteur_galerie']
. '",sel_c:"' . $config['selecteur_commun']
. '",trans:"' . $config['transition']
. '",speed:"' . $config['speed']
. '",ssSpeed:"' . $config['slideshow_speed']
. '",maxW:"' . $config['maxWidth']
. '",maxH:"' . $config['maxHeight']
. '",minW:"' . $config['minWidth']
. '",minH:"' . $config['minHeight']
. '",opa:"' . $config['opacite']
. '",str_ssStart:"' . unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStart')))
. '",str_ssStop:"' . unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStop')))
. '",str_cur:"' . _T('mediabox:boxstr_current', array('current' => '{current}', 'total' => '{total}'))
. '",str_prev:"' . _T('mediabox:boxstr_previous')
. '",str_next:"' . _T('mediabox:boxstr_next')
. '",str_close:"' . _T('mediabox:boxstr_close')
. '",splash_url:"' . $config['splash_url']
. '"};' . "\n";
$js_config = [
'auto_detect' => true,
'ns' => 'box',
'tt_img' => ($config['traiter_toutes_images'] == 'oui' ? 'true' : 'false'),
'sel_g' => $config['selecteur_galerie'],
'sel_c' => $config['selecteur_commun'],
'str_ssStart' => unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStart'))),
'str_ssStop' => unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStop'))),
'str_cur' => unicode2charset(html2unicode(_T('mediabox:boxstr_current', array('current' => '{current}', 'total' => '{total}')))),
'str_prev' => unicode2charset(html2unicode(_T('mediabox:boxstr_previous'))),
'str_next' => unicode2charset(html2unicode(_T('mediabox:boxstr_next'))),
'str_close' => unicode2charset(html2unicode(_T('mediabox:boxstr_close'))),
'splash_url' => $config['splash_url'],
];
// plus la config specifique de la box selectionnee
if (!empty($config['box_type']) and !empty($config[$config['box_type']])) {
$js_config[$config['box_type']] = $config[$config['box_type']];
}
// Si c'est une image, on la chargera avec une redimentionnement automatique
// Sinon, chargement dans une iframe
$extension = pathinfo($config['splash_url'], PATHINFO_EXTENSION);
if (in_array($extension, ['gif', 'png', 'jpg', 'jpeg'])) {
$configmediabox .= 'var box_settings_iframe = false;' . "\n";
} else {
$configmediabox .= 'var box_settings_splash_width = "' . $config['splash_width'] . '";
var box_settings_splash_height = "' . $config['splash_height'] . '";' . "\n";
$configmediabox .= 'var box_settings_iframe = true;' . "\n";
if ($config['splash_url']) {
$extension = pathinfo($config['splash_url'], PATHINFO_EXTENSION);
if (in_array($extension, ['gif', 'png', 'jpg', 'jpeg'])) {
$js_config['splash_iframe'] = false;
} else {
$js_config['splash_iframe'] = true;
$js_config['splash_width'] = $config['splash_width'];
$js_config['splash_height'] = $config['splash_height'];
}
}
$configmediabox = '<script type="text/javascript">/* <![CDATA[ */
var mediabox_settings=' . json_encode($js_config) . ';' . "\n";
$flux = $configmediabox . '/* ]]> */</script>' . "\n" . $flux;
}

Loading…
Cancel
Save