diff --git a/e107_admin/eurl.php b/e107_admin/eurl.php
index b95c3253a..80595e2a6 100644
--- a/e107_admin/eurl.php
+++ b/e107_admin/eurl.php
@@ -262,7 +262,12 @@ class eurl_admin_ui extends e_admin_controller_ui
";
$name = 'urlstatus['.$plug.']';
- $text .= "
".$plug." | ".$frm->radio_switch($name,$active)." |
";
+
+ $switch = $frm->radio_switch($name, $active, LAN_ON, LAN_OFF, array(
+ 'switch' => 'mini',
+ ));
+
+ $text .= "" . $plug . " | " . $switch . " |
";
$text .= "Key | Regular Expression |
diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php
index 5198a7bd6..2970a3e1c 100644
--- a/e107_handlers/form_handler.php
+++ b/e107_handlers/form_handler.php
@@ -2243,54 +2243,85 @@ class e_form
}
/**
- * Boolean Radio Buttons.
- * @param name string
- * @param check_enabled boolean
- * @param label_enabled default is LAN_ENABLED
- * @param label_disabled default is LAN_DISABLED
- * @param options array - inverse=1 (invert values) or reverse=1 (switch display order)
+ * Boolean Radio Buttons / Checkbox (with Bootstrap Switch).
+ *
+ * @param string $name
+ * Form element name.
+ * @param bool $checked_enabled
+ * Use the checked attribute or not.
+ * @param string $label_enabled
+ * Default is LAN_ENABLED
+ * @param string $label_disabled
+ * Default is LAN_DISABLED
+ * @param array $options
+ * - 'inverse' => 1 (invert values)
+ * - 'reverse' => 1 (switch display order)
+ * - 'switch' => 'normal' (size for Bootstrap Switch... mini, small, normal, large)
+ *
+ * @return string $text
*/
- function radio_switch($name, $checked_enabled = false, $label_enabled = '', $label_disabled = '',$options=array())
+ function radio_switch($name, $checked_enabled = false, $label_enabled = '', $label_disabled = '', $options = array())
{
- if(!is_array($options)) parse_str($options, $options);
-
- $options_on = varset($options['enabled'],array());
- $options_off = varset($options['disabled'],array());
+ if(!is_array($options))
+ {
+ parse_str($options, $options);
+ }
- unset($options['enabled'],$options['disabled']);
+ $options_on = varset($options['enabled'], array());
+ $options_off = varset($options['disabled'], array());
+
+ unset($options['enabled'], $options['disabled']);
$options_on = array_merge($options_on, $options);
$options_off = array_merge($options_off, $options);
-
+
if(vartrue($options['class']) == 'e-expandit' || vartrue($options['expandit'])) // See admin->prefs 'Single Login' for an example.
{
$options_on = array_merge($options, array('class' => 'e-expandit-on'));
- $options_off = array_merge($options, array('class' => 'e-expandit-off'));
+ $options_off = array_merge($options, array('class' => 'e-expandit-off'));
}
-
- $options_on['label'] = $label_enabled ? defset($label_enabled,$label_enabled) : LAN_ENABLED;
- $options_off['label'] = $label_disabled ? defset($label_disabled,$label_disabled) : LAN_DISABLED;
-
- if(!empty($options['inverse'])) // Same as 'writeParms'=>'reverse=1&enabled=LAN_DISABLED&disabled=LAN_ENABLED'
+
+ $options_on['label'] = $label_enabled ? defset($label_enabled, $label_enabled) : LAN_ENABLED;
+ $options_off['label'] = $label_disabled ? defset($label_disabled, $label_disabled) : LAN_DISABLED;
+
+ if(!empty($options['switch']))
{
- $text = $this->radio($name, 0, !$checked_enabled, $options_on)." ".$this->radio($name, 1, $checked_enabled, $options_off);
-
+ if(!empty($options['inverse']))
+ {
+ $checked_enabled = !$checked_enabled;
+ }
+
+ $js_options = array(
+ // Each form element has its own options.
+ $name => array(
+ 'size' => $options['switch'],
+ 'onText' => $options_on['label'],
+ 'offText' => $options_off['label'],
+ ),
+ );
+
+ e107::library('load', 'bootstrap.switch');
+ e107::js('settings', array('bsSwitch' => $js_options));
+ e107::js('footer', '{e_WEB}js/bootstrap.switch.init.js', 'jquery', 5);
+
+ $text = $this->checkbox($name, 1, $checked_enabled);
+ }
+ elseif(!empty($options['inverse'])) // Same as 'writeParms'=>'reverse=1&enabled=LAN_DISABLED&disabled=LAN_ENABLED'
+ {
+ $text = $this->radio($name, 0, !$checked_enabled, $options_on) . " " . $this->radio($name, 1, $checked_enabled, $options_off);
+
}
elseif(!empty($options['reverse'])) // reverse display order.
{
- $text = $this->radio($name, 0, !$checked_enabled, $options_off)." ".$this->radio($name, 1, $checked_enabled, $options_on);
+ $text = $this->radio($name, 0, !$checked_enabled, $options_off) . " " . $this->radio($name, 1, $checked_enabled, $options_on);
}
else
{
-
- $text = $this->radio($name, 1, $checked_enabled, $options_on)." ".$this->radio($name, 0, !$checked_enabled, $options_off);
+ $text = $this->radio($name, 1, $checked_enabled, $options_on) . " " . $this->radio($name, 0, !$checked_enabled, $options_off);
}
-
-
return $text;
-
}
diff --git a/e107_handlers/library_manager.php b/e107_handlers/library_manager.php
index 70392b5cb..1bc910f4e 100644
--- a/e107_handlers/library_manager.php
+++ b/e107_handlers/library_manager.php
@@ -412,7 +412,7 @@ class core_library
// Bootstrap Editable (local).
$libraries['bootstrap.editable'] = array(
- 'name' => 'Bootstrap Editable (Local)',
+ 'name' => 'Bootstrap Editable (local)',
'vendor_url' => 'https://vitalets.github.io/bootstrap-editable/',
'version_arguments' => array(
'file' => 'js/bootstrap-editable.min.js',
@@ -454,6 +454,95 @@ class core_library
'library_path' => '{e_WEB}js/bootstrap3-editable',
);
+ // Bootstrap Switch (CDN).
+ $libraries['cdn.bootstrap.switch'] = array(
+ 'name' => 'Bootstrap Switch (CDN)',
+ 'vendor_url' => 'http://www.bootstrap-switch.org',
+ 'version_arguments' => array(
+ 'file' => 'js/bootstrap-switch.min.js',
+ 'pattern' => '/v(\d\.\d\.\d)/',
+ 'lines' => 5,
+ ),
+ 'files' => array(
+ 'js' => array(
+ 'js/bootstrap-switch.min.js' => array(
+ 'zone' => 2,
+ 'type' => 'footer',
+ ),
+ ),
+ 'css' => array(
+ 'css/bootstrap3/bootstrap-switch.min.css' => array(
+ 'zone' => 2,
+ ),
+ ),
+ ),
+ 'variants' => array(
+ // 'unminified' version for debugging.
+ 'dev' => array(
+ 'files' => array(
+ 'js' => array(
+ 'js/bootstrap-switch.js' => array(
+ 'zone' => 2,
+ 'type' => 'footer',
+ ),
+ ),
+ 'css' => array(
+ 'css/bootstrap3/bootstrap-switch.css' => array(
+ 'zone' => 2,
+ ),
+ ),
+ ),
+ ),
+ ),
+ // Override library path to CDN.
+ 'library_path' => 'https://cdn.jsdelivr.net/bootstrap.switch',
+ 'path' => '3.3.2',
+ );
+
+ // Bootstrap Switch (local).
+ $libraries['bootstrap.switch'] = array(
+ 'name' => 'Bootstrap Switch (local)',
+ 'vendor_url' => 'http://www.bootstrap-switch.org',
+ 'version_arguments' => array(
+ 'file' => 'dist/js/bootstrap-switch.min.js',
+ 'pattern' => '/v(\d\.\d\.\d)/',
+ 'lines' => 5,
+ ),
+ 'files' => array(
+ 'js' => array(
+ 'dist/js/bootstrap-switch.min.js' => array(
+ 'zone' => 2,
+ 'type' => 'footer',
+ ),
+ ),
+ 'css' => array(
+ 'dist/css/bootstrap3/bootstrap-switch.min.css' => array(
+ 'zone' => 2,
+ ),
+ ),
+ ),
+ 'variants' => array(
+ // 'unminified' version for debugging.
+ 'dev' => array(
+ 'files' => array(
+ 'js' => array(
+ 'dist/js/bootstrap-switch.js' => array(
+ 'zone' => 2,
+ 'type' => 'footer',
+ ),
+ ),
+ 'css' => array(
+ 'dist/css/bootstrap3/bootstrap-switch.css' => array(
+ 'zone' => 2,
+ ),
+ ),
+ ),
+ ),
+ ),
+ // Override library path.
+ 'library_path' => '{e_WEB}lib/bootstrap-switch',
+ );
+
// Font-Awesome (CDN).
$libraries['cdn.fontawesome'] = array(
'name' => 'Font-Awesome (CDN)',
@@ -542,6 +631,7 @@ class core_library
$libraries['cdn.bootstrap.editable']['library_path'] = str_replace('https://cdn.jsdelivr.net/bootstrap.editable', 'https://cdnjs.cloudflare.com/ajax/libs/x-editable', $libraries['cdn.bootstrap.editable']['library_path']);
$libraries['cdn.bootstrap.editable']['path'] .= '/bootstrap-editable';
+ $libraries['cdn.bootstrap.switch']['library_path'] = str_replace('https://cdn.jsdelivr.net/bootstrap.switch', 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch', $libraries['cdn.bootstrap.switch']['library_path']);
$libraries['cdn.fontawesome']['library_path'] = str_replace('https://cdn.jsdelivr.net/fontawesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome', $libraries['cdn.fontawesome']['library_path']);
}
}
diff --git a/e107_languages/English/admin/lan_admin.php b/e107_languages/English/admin/lan_admin.php
index 653349e0b..dfdde8ff1 100644
--- a/e107_languages/English/admin/lan_admin.php
+++ b/e107_languages/English/admin/lan_admin.php
@@ -340,6 +340,8 @@ define("LAN_UPLOAD_777","Folder is missing or not writable, you need to CHMOD 77
define("LAN_UPLOAD_SERVEROFF", "This option is disabled as file uploading is not enabled on your server");
define("LAN_WIDTH","Width");
+define("LAN_ON","On");
+define("LAN_OFF", "Off");
define("LAN_DISABLED","Disabled");
define("LAN_ENABLED", "Enabled");
define("LAN_BOOL_REVERSE", "Invert");
diff --git a/e107_web/js/bootstrap.switch.init.js b/e107_web/js/bootstrap.switch.init.js
new file mode 100644
index 000000000..2d82c2adb
--- /dev/null
+++ b/e107_web/js/bootstrap.switch.init.js
@@ -0,0 +1,31 @@
+var e107 = e107 || {'settings': {}, 'behaviors': {}};
+
+(function ($)
+{
+
+ /**
+ * @type {{attach: e107.behaviors.bootstrapSwitchInit.attach}}
+ */
+ e107.behaviors.bootstrapSwitchInit = {
+ attach: function (context, settings)
+ {
+ if(typeof settings.bsSwitch === 'undefined' || settings.bsSwitch.length == 0)
+ {
+ return;
+ }
+
+ $.each(settings.bsSwitch, function (name, options)
+ {
+ $('input[name="' + name + '"]', context).once('bootstrap-switch-init').each(function ()
+ {
+ $(this).bootstrapSwitch({
+ size: options.size || 'mini',
+ onText: options.onText || null,
+ offText: options.offText || null
+ });
+ });
+ });
+ }
+ };
+
+})(jQuery);
---|