mirror of
https://github.com/e107inc/e107.git
synced 2025-07-29 10:50:25 +02:00
Ability to use bs-switch in menu-manager config modals.
This commit is contained in:
67
e107_web/js/bootstrap.switch.init.js
vendored
67
e107_web/js/bootstrap.switch.init.js
vendored
@@ -3,63 +3,52 @@ 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)
|
||||
if(typeof $.fn.bootstrapSwitch === 'undefined')
|
||||
{
|
||||
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({
|
||||
size: options.size || 'mini',
|
||||
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.
|
||||
});
|
||||
var name = $this.data('name');
|
||||
var checked = true;
|
||||
|
||||
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');
|
||||
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();
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user