1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

Merge pull request #2337 from lonalore/lib

Added Bootstrap Switch.
This commit is contained in:
Cameron 2017-01-28 07:55:57 -08:00 committed by GitHub
commit af96a45fbf
5 changed files with 191 additions and 32 deletions

View File

@ -262,7 +262,12 @@ class eurl_admin_ui extends e_admin_controller_ui
</colgroup>";
$name = 'urlstatus['.$plug.']';
$text .= "<tr class='active'><td ><h4>".$plug."</h4></td><td colspan='2'>".$frm->radio_switch($name,$active)."</td></tr>";
$switch = $frm->radio_switch($name, $active, LAN_ON, LAN_OFF, array(
'switch' => 'mini',
));
$text .= "<tr class='active'><td ><h4>" . $plug . "</h4></td><td colspan='2'>" . $switch . "</td></tr>";
$text .= "<tr><th>Key</th><th>Regular Expression</th>

View File

@ -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;
}

View File

@ -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']);
}
}
@ -864,18 +954,18 @@ class e_library_manager
if(!isset($loaded[$name]))
{
$cache = e107::getCache();
$cacheID = 'Library_' . e107::getParser()->filter($name,'file');
$cacheID = 'Library_' . e107::getParser()->filter($name, 'file');
$cached = $cache->retrieve($cacheID, false, true, true);
if($cached)
{
$library = unserialize($cached);
$library = e107::unserialize($cached);
}
if(!varset($library, false))
{
$library = $this->detect($name);
$cacheData = e107::serialize($library,'json');
$cacheData = e107::serialize($library, 'json');
$cache->set($cacheID, $cacheData, true, true, true);
}

View File

@ -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");

31
e107_web/js/bootstrap.switch.init.js vendored Normal file
View File

@ -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);