1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 12:20:44 +02:00

Ability to use bs-switch in menu-manager config modals.

This commit is contained in:
Lóna Lore
2017-03-06 22:20:56 +01:00
parent c86f8d23ad
commit 7e66f694d1
3 changed files with 44 additions and 67 deletions

View File

@@ -42,38 +42,27 @@ require_once("../class2.php");
if(e_MENUMANAGER_ACTIVE === false ) if(e_MENUMANAGER_ACTIVE === false )
{ {
e107::library('load', 'bootstrap.switch');
e107::js('footer', '{e_WEB}js/bootstrap.switch.init.js', 'jquery', 5);
if(!deftrue("e_DEBUG")) if(!deftrue("e_DEBUG"))
{ {
e107::getJs()->inlineCSS(' e107::getJs()->inlineCSS('
body { overflow:hidden }
body { overflow:hidden }
'); ');
} }
else else
{ {
e107::js('footer-inline'," e107::js('footer-inline',"
$('#menu_iframe').attr('scrolling','no'); $('#menu_iframe').attr('scrolling','no');
$('#menu_iframe').load(function() { $('#menu_iframe').load(function() {
// $('#menu_iframe').bind('load', function() { var height = this.contentWindow.document.body.offsetHeight + 400 + 'px';
var height = this.contentWindow.document.body.offsetHeight + 400 + 'px';
// $(this).css('overflow-y','visible');
$(this).css('height',height); $(this).css('height',height);
// alert(this.style.height);
}); });
"); ");
} }
e107::getJs()->inlineCSS(" e107::getJs()->inlineCSS("
.menu-manager-items { padding-right:15px} .menu-manager-items { padding-right:15px}
.menu-manager-items div.item { padding:5px; margin:5px 0; border:1px solid rgba(255,255,255,0.3); border-radius:3px; cursor: move } .menu-manager-items div.item { padding:5px; margin:5px 0; border:1px solid rgba(255,255,255,0.3); border-radius:3px; cursor: move }
.menu-manager-sticky { .menu-manager-sticky {
@@ -118,7 +107,6 @@ if(e_MENUMANAGER_ACTIVE === false )
} }
ul.dropdown-menu.e-mm-selector { padding: 10px; margin-top: -2px; margin-right:-2px; } ul.dropdown-menu.e-mm-selector { padding: 10px; margin-top: -2px; margin-right:-2px; }
"); ");
} }

View File

@@ -2391,25 +2391,25 @@ class e_form
} }
$switchName = $name.'__switch'; $switchName = $name . '__switch';
$js_options = array( $switchAttributes = array(
// Each form element has its own options. 'data-type' => 'switch',
$switchName => array( 'data-name' => $name,
'size' => $options['switch'], 'data-size' => $options['switch'],
'onText' => $labels['on'], 'data-on' => $labels['on'],
'offText' => $labels['off'], 'data-off' => $labels['off'],
'inverse' => !empty($options['inverse']), 'data-inverse' => (int) !empty($options['inverse']),
),
); );
$options += $switchAttributes;
if(e_ADMIN_AREA === true) if(e_ADMIN_AREA === true)
{ {
$js_options[$switchName]['wrapperClass'] = 'wrapper form-control'; $options['data-wrapper'] = 'wrapper form-control';
} }
e107::library('load', 'bootstrap.switch'); e107::library('load', 'bootstrap.switch');
e107::js('settings', array('bsSwitch' => $js_options));
e107::js('footer', '{e_WEB}js/bootstrap.switch.init.js', 'jquery', 5); e107::js('footer', '{e_WEB}js/bootstrap.switch.init.js', 'jquery', 5);
$text = $this->hidden($name, (int) $value); $text = $this->hidden($name, (int) $value);

View File

@@ -3,63 +3,52 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
(function ($) (function ($)
{ {
/** /**
* @type {{attach: e107.behaviors.bootstrapSwitchInit.attach}} * @type {{attach: e107.behaviors.bootstrapSwitchInit.attach}}
*/ */
e107.behaviors.bootstrapSwitchInit = { e107.behaviors.bootstrapSwitchInit = {
attach: function (context, settings) attach: function (context, settings)
{ {
if(typeof settings.bsSwitch === 'undefined' || settings.bsSwitch.length == 0) if(typeof $.fn.bootstrapSwitch === 'undefined')
{ {
return; return;
} }
$.each(settings.bsSwitch, function (name, options) $('input[data-type="switch"]', context).once('bootstrap-switch-init').each(function ()
{ {
$('input[name="' + name + '"]', context).once('bootstrap-switch-init').each(function () var $this = $(this);
if($this.attr('type') != 'hidden')
{ {
if($(this).attr('type') != 'hidden') $this.bootstrapSwitch({
size: $this.data('size') || 'mini',
onText: $this.data('on') || null,
offText: $this.data('off') || null,
wrapperClass: $this.data('wrapper') || null
});
$this.on('switchChange.bootstrapSwitch', function (event, state)
{ {
$(this).bootstrapSwitch({ var name = $this.data('name');
size: options.size || 'mini', var checked = true;
onText: options.onText || null,
offText: options.offText || null,
wrapperClass: options.wrapperClass || null,
// disabled: false
// state: $('input[type="hidden"][name="' + name + '"]').data('on')
// inverse: options.inverse // this is 'reverse' - default values but reversed order.
});
if(state === false)
{
checked = false;
}
var value = checked ? 1 : 0;
$(this).on('switchChange.bootstrapSwitch', function (event, state) { if($this.data('inverse') == 1)
{
value = checked ? 0 : 1;
}
var tmp = $(this).attr('name').split('__'); $('input[type="hidden"][name="' + name + '"]').val(value).trigger('change');
var name = tmp[0]; // $(this).attr('name'); return false;
var checked = true; });
}
if(state === false)
{
checked = false;
}
var value = checked ? 1 : 0;
if(options.inverse)
{
value = checked ? 0 : 1;
}
$('input[type="hidden"][name="' + name + '"]').val(value);
// event.preventDefault();
});
}
});
}); });
} }
}; };