diff --git a/e107_admin/menus.php b/e107_admin/menus.php index 2e316c8d4..d385e5bde 100644 --- a/e107_admin/menus.php +++ b/e107_admin/menus.php @@ -42,38 +42,27 @@ require_once("../class2.php"); 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")) { e107::getJs()->inlineCSS(' - - body { overflow:hidden } - - + body { overflow:hidden } '); } else { e107::js('footer-inline'," - $('#menu_iframe').attr('scrolling','no'); $('#menu_iframe').load(function() { - // $('#menu_iframe').bind('load', function() { - - var height = this.contentWindow.document.body.offsetHeight + 400 + 'px'; - - // $(this).css('overflow-y','visible'); + var height = this.contentWindow.document.body.offsetHeight + 400 + 'px'; $(this).css('height',height); - // alert(this.style.height); - }); - - "); - } e107::getJs()->inlineCSS(" - .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-sticky { @@ -118,7 +107,6 @@ if(e_MENUMANAGER_ACTIVE === false ) } ul.dropdown-menu.e-mm-selector { padding: 10px; margin-top: -2px; margin-right:-2px; } - "); } diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 1549038cf..9e0259750 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -2391,25 +2391,25 @@ class e_form } - $switchName = $name.'__switch'; + $switchName = $name . '__switch'; - $js_options = array( - // Each form element has its own options. - $switchName => array( - 'size' => $options['switch'], - 'onText' => $labels['on'], - 'offText' => $labels['off'], - 'inverse' => !empty($options['inverse']), - ), + $switchAttributes = array( + 'data-type' => 'switch', + 'data-name' => $name, + 'data-size' => $options['switch'], + 'data-on' => $labels['on'], + 'data-off' => $labels['off'], + 'data-inverse' => (int) !empty($options['inverse']), ); + $options += $switchAttributes; + if(e_ADMIN_AREA === true) { - $js_options[$switchName]['wrapperClass'] = 'wrapper form-control'; + $options['data-wrapper'] = 'wrapper form-control'; } 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->hidden($name, (int) $value); diff --git a/e107_web/js/bootstrap.switch.init.js b/e107_web/js/bootstrap.switch.init.js index 00b4f45d8..684e870bc 100644 --- a/e107_web/js/bootstrap.switch.init.js +++ b/e107_web/js/bootstrap.switch.init.js @@ -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; + }); + } }); } };