From 13dda54df338f55f61b8d7616eeedafba544cc02 Mon Sep 17 00:00:00 2001 From: Matthieu Marcillaud Date: Mon, 14 Oct 2019 16:37:16 +0200 Subject: [PATCH] =?UTF-8?q?-=20Utiliser=20la=20configuration=20dans=20les?= =?UTF-8?q?=20pipelines=20et=20le=20JS=20;=20-=20Recharger=20apr=C3=A8s=20?= =?UTF-8?q?AJAX=20;=20-=20Note=20sur=20les=20identifiants=20uniques.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 1 + javascript/spip_select2.js | 22 ++++++++++++++++++++++ lang/select2_fr.php | 2 +- select2_pipelines.php | 9 ++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 6c043df..8e6b3df 100644 --- a/Readme.md +++ b/Readme.md @@ -9,6 +9,7 @@ Select2 est actif dans l’espace privé pour tous les select ayant la classe CS La configuration (Menu : Squelettes > Select2) permet de compléter les sélecteurs utilisés. Il est possible d’activer Select2 sur l’espace public depuis cette configuration. +**Important:** L’identifiant (l’attribut `id`) de la balise `select` doit être unique sur la page ; Select2 ne peut s’activer qu’une fois par identifiant (le dernier appelé). ## Compléter la configuration par défaut diff --git a/javascript/spip_select2.js b/javascript/spip_select2.js index e69de29..a301d91 100644 --- a/javascript/spip_select2.js +++ b/javascript/spip_select2.js @@ -0,0 +1,22 @@ +;jQuery(function($){ + spip_select2 = function() { + jQuery('select.select2').select2(); + if (typeof select2 !== 'undefined') { + if ((typeof select2.selector !== 'undefined') && !!select2.selector) { + jQuery(select2.selector).select2(); + } + } + jQuery('select.select2[data-sort-alpha=true]').select2({ + /*'sorter': data => data.sort((a, b) => a.text.localeCompare(b.text))*/ + sorter: function (data) { + return data.sort(function (a, b) { + return a.text.localeCompare(b.text); + }) + } + }); + } + + spip_select2(); + onAjaxLoad(spip_select2); +}); + diff --git a/lang/select2_fr.php b/lang/select2_fr.php index fb51fc9..939fc47 100644 --- a/lang/select2_fr.php +++ b/lang/select2_fr.php @@ -13,7 +13,7 @@ $GLOBALS[$GLOBALS['idx_lang']] = array( // C 'champ_active_label' => 'Activer "Select2" dans le site public', 'champ_selecteur_label' => 'Sélecteur', - 'champ_selecteur_explication' => 'Indiquez la cible des éléments qui déclencheront Select2. (Expression CSS ou étendue jQuery)', + 'champ_selecteur_explication' => 'Indiquez la cible des éléments qui déclencheront Select2, en plus de la classe CSS .select2. (Expression CSS ou étendue jQuery)', // T 'titre_page_configurer_select2' => 'Configurer Select2', diff --git a/select2_pipelines.php b/select2_pipelines.php index 63f5676..60b48c8 100644 --- a/select2_pipelines.php +++ b/select2_pipelines.php @@ -49,6 +49,10 @@ function select2_jquery_plugins($flux) { */ function select2_header_prive($flux) { include_spip('inc/config'); + $flux .= ''."\n"; return $flux; } @@ -95,7 +99,10 @@ function select2_insert_head($flux) { include_spip('inc/config'); $config = lire_config('select2', array()); if (isset($config['active']) and $config['active']=='oui') { - + $flux .= ''."\n"; } return $flux; }