diff --git a/administrator/templates/isis/js/template.js b/administrator/templates/isis/js/template.js index 731e6895a0be6..950aa7110a53e 100644 --- a/administrator/templates/isis/js/template.js +++ b/administrator/templates/isis/js/template.js @@ -6,404 +6,365 @@ * @since 3.0 */ -(function($) +jQuery(function($) { - $(document).ready(function() - { - var $w = $(window); - - $('*[rel=tooltip]').tooltip(); + 'use strict'; - // Turn radios into btn-group - $('.radio.btn-group label').addClass('btn'); + var $w = $(window); - $('.btn-group label:not(.active)').click(function() - { - var label = $(this); - var input = $('#' + label.attr('for')); + $('*[rel=tooltip]').tooltip(); - if (!input.prop('checked')) - { - label.closest('.btn-group').find('label').removeClass('active btn-success btn-danger btn-primary'); + // Turn radios into btn-group + $('.radio.btn-group label').addClass('btn'); - if (label.closest('.btn-group').hasClass('btn-group-reversed')) - { - if (input.val() == '') - { - label.addClass('active btn-primary'); - } - else if (input.val() == 0) - { - label.addClass('active btn-success'); - } - else - { - label.addClass('active btn-danger'); - } - } - else - { - if (input.val() == '') - { - label.addClass('active btn-primary'); - } - else if (input.val() == 0) - { - label.addClass('active btn-danger'); - } - else - { - label.addClass('active btn-success'); - } + $('fieldset.btn-group').each(function() { + // Handle disabled, prevent clicks on the container, and add disabled style to each button + if ($(this).prop('disabled')) { + $(this).css('pointer-events', 'none').off('click'); + $(this).find('.btn').addClass('disabled'); + } + }); - } - input.prop('checked', true); - input.trigger('change'); + $('.btn-group label:not(.active)').click(function() + { + var label = $(this); + var input = $('#' + label.attr('for')); + var reversed = false; + + if (!input.prop('checked')) { + label.closest('.btn-group').find('label').removeClass('active btn-success btn-danger btn-primary'); + reversed = label.closest('.btn-group').hasClass('btn-group-reversed'); + + if (input.val() == '') { + label.addClass('active btn-primary'); + } else if (input.val() == 0) { + label.addClass('active btn-danger' + (reversed ? 'danger' : 'success')); + } else { + label.addClass('active btn-success' + (reversed ? 'success' : 'danger')); } - }); - $('.btn-group input[checked=checked]').each(function() + + input.prop('checked', true); + input.trigger('change'); + } + }); + $('.btn-group input[checked=checked]').each(function() + { + var $self = $(this); + var $label = $('label[for=' + $self.attr('id') + ']'); + var reversed = $self.parent().hasClass('btn-group-reversed'); + + if ($self.val() == '') { + $label.addClass('active btn-primary'); + } else if ($self.val() == 0) { + $label.addClass('active btn-' + (reversed ? 'danger' : 'success')); + } else { + $label.addClass('active btn-' + (reversed ? 'success' : 'danger')); + } + }); + // add color classes to chosen field based on value + $('select[class^="chzn-color"], select[class*=" chzn-color"]').on('liszt:ready', function(){ + var select = $(this); + var cls = this.className.replace(/^.(chzn-color[a-z0-9-_]*)$.*/, '\1'); + var container = select.next('.chzn-container').find('.chzn-single'); + container.addClass(cls).attr('rel', 'value_' + select.val()); + select.on('change click', function() { - var $self = $(this); - var attrId = $self.attr('id'); + container.attr('rel', 'value_' + select.val()); + }); - if ($self.parent().hasClass('btn-group-reversed')) + }); + + /** + * Append submenu items to empty UL on hover allowing a scrollable dropdown + */ + if ($w.width() > 767) + { + var menuScroll = $('#menu > li > ul'), + emptyMenu = $('#nav-empty'); + + $('#menu > li').on('click mouseenter', function() { + + // Set max-height (and width if scroll) for dropdown menu, depending of window height + var $dropdownMenu = $(this).children('ul'), + windowHeight = $w.height(), + linkHeight = $(this).outerHeight(true), + statusHeight = $('#status').outerHeight(true), + menuHeight = $dropdownMenu.height(), + menuOuterHeight = $dropdownMenu.outerHeight(true), + scrollMenuWidth = $dropdownMenu.width() + 15, + maxHeight = windowHeight - (linkHeight + statusHeight + (menuOuterHeight - menuHeight) + 20); + + if (maxHeight < menuHeight) { - if ($self.val() == '') - { - $('label[for=' + attrId + ']').addClass('active btn-primary'); - } - else if ($self.val() == 0) - { - $('label[for=' + attrId + ']').addClass('active btn-success'); - } - else - { - $('label[for=' + attrId + ']').addClass('active btn-danger'); - } + $dropdownMenu.css('width', scrollMenuWidth); } - else + else if (maxHeight > menuHeight) { - if ($self.val() == '') - { - $('label[for=' + attrId + ']').addClass('active btn-primary'); - } - else if ($self.val() == 0) - { - $('label[for=' + attrId + ']').addClass('active btn-danger'); - } - else - { - $('label[for=' + attrId + ']').addClass('active btn-success'); - } + $dropdownMenu.css('width', 'auto'); } - }); - // add color classes to chosen field based on value - $('select[class^="chzn-color"], select[class*=" chzn-color"]').on('liszt:ready', function(){ - var select = $(this); - var cls = this.className.replace(/^.(chzn-color[a-z0-9-_]*)$.*/, '\1'); - var container = select.next('.chzn-container').find('.chzn-single'); - container.addClass(cls).attr('rel', 'value_' + select.val()); - select.on('change click', function() - { - container.attr('rel', 'value_' + select.val()); - }); + + $dropdownMenu.css('max-height', maxHeight); + + // Get the submenu position + linkWidth = $(this).outerWidth(true); + menuWidth = $dropdownMenu.width(); + linkPaddingLeft = $(this).children('a').css('padding-left'); + offsetLeft = Math.round($(this).offset().left) - parseInt(linkPaddingLeft); + + emptyMenu.empty().hide(); }); - /** - * Append submenu items to empty UL on hover allowing a scrollable dropdown - */ - if ($w.width() > 767) - { - var menuScroll = $('#menu > li > ul'), - emptyMenu = $('#nav-empty'); - - $('#menu > li').on('click mouseenter', function() { - - // Set max-height (and width if scroll) for dropdown menu, depending of window height - var $dropdownMenu = $(this).children('ul'), - windowHeight = $w.height(), - linkHeight = $(this).outerHeight(true), - statusHeight = $('#status').outerHeight(true), - menuHeight = $dropdownMenu.height(), - menuOuterHeight = $dropdownMenu.outerHeight(true), - scrollMenuWidth = $dropdownMenu.width() + 15, - maxHeight = windowHeight - (linkHeight + statusHeight + (menuOuterHeight - menuHeight) + 20); - - if (maxHeight < menuHeight) - { - $dropdownMenu.css('width', scrollMenuWidth); - } - else if (maxHeight > menuHeight) - { - $dropdownMenu.css('width', 'auto'); - } + menuScroll.find('.dropdown-submenu > a').on('mouseover', function() { - $dropdownMenu.css('max-height', maxHeight); + var $self = $(this), + dropdown = $self.next('ul'), + submenuWidth = dropdown.outerWidth(), + offsetTop = $self.offset().top, + linkPaddingTop = parseInt(dropdown.css('padding-top')) + parseInt($(this).css('padding-top')), + scroll = $w.scrollTop() + linkPaddingTop; - // Get the submenu position - linkWidth = $(this).outerWidth(true); - menuWidth = $dropdownMenu.width(); - linkPaddingLeft = $(this).children('a').css('padding-left'); - offsetLeft = Math.round($(this).offset().left) - parseInt(linkPaddingLeft); + // Set the submenu position + if ($('html').attr('dir') == 'rtl') + { + emptyMenu.css({ + top : offsetTop - scroll, + left: offsetLeft - (menuWidth - linkWidth) - submenuWidth + }); + } + else + { + emptyMenu.css({ + top : offsetTop - scroll, + left: offsetLeft + menuWidth + }); + } - emptyMenu.empty().hide(); + // Append items to empty