From 86592cecf349bd7dc3be388bd695bb55565822c6 Mon Sep 17 00:00:00 2001 From: Khanh Le Date: Mon, 27 Jul 2015 15:15:13 +0700 Subject: [PATCH] Fix frond-end edit on-off button --- source/plg_system_t3/base-bs3/js/frontend-edit.js | 14 ++++++-------- source/plg_system_t3/base/js/frontend-edit.js | 14 ++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/source/plg_system_t3/base-bs3/js/frontend-edit.js b/source/plg_system_t3/base-bs3/js/frontend-edit.js index 97bea7e7cf..a05b08e2f9 100644 --- a/source/plg_system_t3/base-bs3/js/frontend-edit.js +++ b/source/plg_system_t3/base-bs3/js/frontend-edit.js @@ -16,7 +16,7 @@ $(document).ready(function(){ //frontend edit radio on/off - auto convert on-off radio if applicable - $('fieldset.radio').filter(function(){ + var $onoff = $('fieldset.radio').filter(function(){ return $(this).find('input').length == 2 && $(this).find('input').filter(function(){ return $.inArray(this.value + '', ['0', '1']) !== -1; @@ -25,8 +25,11 @@ }).addClass('t3onoff').removeClass('btn-group'); //add class on/off - $('fieldset.t3onoff').find('label').addClass(function(){ - return $(this).hasClass('off') || $(this).prev('input').val() == '0' ? 'off' : 'on' + $onoff.find('label').addClass(function(){ + var $this = $(this), $input = $this.prev('input'), + cls = $this.hasClass('off') || $input.val() == '0' ? 'off' : 'on'; + cls += $input.prop('checked') ? ' active' : ''; + return cls; }); //listen to all @@ -41,11 +44,6 @@ } }); - //initial state - $('.radio input[checked=checked]').each(function(){ - $('label[for=' + $(this).attr('id') + ']').addClass('active'); - }); - }); }(jQuery); \ No newline at end of file diff --git a/source/plg_system_t3/base/js/frontend-edit.js b/source/plg_system_t3/base/js/frontend-edit.js index 97bea7e7cf..a05b08e2f9 100644 --- a/source/plg_system_t3/base/js/frontend-edit.js +++ b/source/plg_system_t3/base/js/frontend-edit.js @@ -16,7 +16,7 @@ $(document).ready(function(){ //frontend edit radio on/off - auto convert on-off radio if applicable - $('fieldset.radio').filter(function(){ + var $onoff = $('fieldset.radio').filter(function(){ return $(this).find('input').length == 2 && $(this).find('input').filter(function(){ return $.inArray(this.value + '', ['0', '1']) !== -1; @@ -25,8 +25,11 @@ }).addClass('t3onoff').removeClass('btn-group'); //add class on/off - $('fieldset.t3onoff').find('label').addClass(function(){ - return $(this).hasClass('off') || $(this).prev('input').val() == '0' ? 'off' : 'on' + $onoff.find('label').addClass(function(){ + var $this = $(this), $input = $this.prev('input'), + cls = $this.hasClass('off') || $input.val() == '0' ? 'off' : 'on'; + cls += $input.prop('checked') ? ' active' : ''; + return cls; }); //listen to all @@ -41,11 +44,6 @@ } }); - //initial state - $('.radio input[checked=checked]').each(function(){ - $('label[for=' + $(this).attr('id') + ']').addClass('active'); - }); - }); }(jQuery); \ No newline at end of file