diff --git a/js/Common.js b/js/Common.js index 275c0c2ecc37fc21660f04c8c5b072800562ed59..bf4273c74e0c1af82131c6b2ae151f0378416a92 100644 --- a/js/Common.js +++ b/js/Common.js @@ -464,61 +464,6 @@ function activityStatus( message ) { } } -/** - * Function to make multiselect boxes behave as fields in small screens - */ -function advmultiselectResize() { - var amswidth = cj("#crm-container form:has(table.advmultiselect)").width(); - if (amswidth < 700) { - cj("form table.advmultiselect td").each( function() { - cj(this).css('display', 'block'); - }); - } else { - cj("form table.advmultiselect td").each( function() { - cj(this).css('display', 'table-cell'); - }); - } - var contactwidth = cj('#crm-container #mainTabContainer').width(); - if (contactwidth < 600) { - cj('#crm-container #mainTabContainer').addClass('narrowpage'); - cj('#crm-container #mainTabContainer').addClass('narrowpage'); - cj('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each( function(index) { - if (index > 1) { - if (index%2 == 0) { - cj(this).parent().after('<tr class="narrowadded"></tr>'); - } - var item = cj(this); - cj(this).parent().next().append(item); - } - }); - } else { - cj('#crm-container #mainTabContainer.narrowpage').removeClass('narrowpage'); - cj('#crm-container #mainTabContainer #contactTopBar tr.narrowadded td').each( function() { - var nitem = cj(this); - var parent = cj(this).parent(); - cj(this).parent().prev().append(nitem); - if ( parent.children().size() == 0 ) { - parent.remove(); - } - }); - cj('#crm-container #mainTabContainer.narrowpage #contactTopBar tr.added').detach(); - } - var cformwidth = cj('#crm-container #Contact .contact_basic_information-section').width(); - - if (cformwidth < 720) { - cj('#crm-container .contact_basic_information-section').addClass('narrowform'); - cj('#crm-container .contact_basic_information-section table.form-layout-compressed td .helpicon').parent().addClass('hashelpicon'); - if (cformwidth < 480) { - cj('#crm-container .contact_basic_information-section').addClass('xnarrowform'); - } else { - cj('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform'); - } - } else { - cj('#crm-container .contact_basic_information-section.narrowform').removeClass('narrowform'); - cj('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform'); - } -} - CRM.strings = CRM.strings || {}; CRM.validate = CRM.validate || { params: {}, @@ -528,65 +473,107 @@ CRM.validate = CRM.validate || { (function($, undefined) { "use strict"; $(document).ready(function() { - advmultiselectResize(); $().crmtooltip(); $('.crm-container table.row-highlight').on('change', 'input.select-row, input.select-rows', function() { - var table = $(this).closest('table'); + var target, table = $(this).closest('table'); if ($(this).hasClass('select-rows')) { - var target = $('tbody tr', table); + target = $('tbody tr', table); $('input.select-row', table).prop('checked', $(this).prop('checked')); } else { - var target = $(this).closest('tr'); + target = $(this).closest('tr'); $('input.select-rows', table).prop('checked', $(".select-row:not(':checked')", table).length < 1); } target.toggleClass('crm-row-selected', $(this).is(':checked')); }); - cj('#crm-container').live('click', function(event) { - if (cj(event.target).is('.btn-slide')) { - var currentActive = cj('#crm-container .btn-slide-active'); + $('#crm-container').live('click', function(event) { + if ($(event.target).is('.btn-slide')) { + var currentActive = $('#crm-container .btn-slide-active'); currentActive.children().hide(); currentActive.removeClass('btn-slide-active'); - cj(event.target).children().show(); - cj(event.target).addClass('btn-slide-active'); + $(event.target).children().show(); + $(event.target).addClass('btn-slide-active'); } else { - cj('.btn-slide .panel').hide(); - cj('.btn-slide-active').removeClass('btn-slide-active'); + $('.btn-slide .panel').hide(); + $('.btn-slide-active').removeClass('btn-slide-active'); } }); }); + + /** + * Function to make multiselect boxes behave as fields in small screens + */ + function advmultiselectResize() { + var amswidth = $("#crm-container form:has(table.advmultiselect)").width(); + if (amswidth < 700) { + $("form table.advmultiselect td").css('display', 'block'); + } else { + $("form table.advmultiselect td").css('display', 'table-cell'); + } + var contactwidth = $('#crm-container #mainTabContainer').width(); + if (contactwidth < 600) { + $('#crm-container #mainTabContainer').addClass('narrowpage'); + $('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each( function(index) { + if (index > 1) { + if (index%2 == 0) { + $(this).parent().after('<tr class="narrowadded"></tr>'); + } + var item = $(this); + $(this).parent().next().append(item); + } + }); + } else { + $('#crm-container #mainTabContainer.narrowpage').removeClass('narrowpage'); + $('#crm-container #mainTabContainer #contactTopBar tr.narrowadded td').each( function() { + var nitem = $(this); + var parent = $(this).parent(); + $(this).parent().prev().append(nitem); + if ( parent.children().size() == 0 ) { + parent.remove(); + } + }); + $('#crm-container #mainTabContainer.narrowpage #contactTopBar tr.added').detach(); + } + var cformwidth = $('#crm-container #Contact .contact_basic_information-section').width(); + + if (cformwidth < 720) { + $('#crm-container .contact_basic_information-section').addClass('narrowform'); + $('#crm-container .contact_basic_information-section table.form-layout-compressed td .helpicon').parent().addClass('hashelpicon'); + if (cformwidth < 480) { + $('#crm-container .contact_basic_information-section').addClass('xnarrowform'); + } else { + $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform'); + } + } else { + $('#crm-container .contact_basic_information-section.narrowform').removeClass('narrowform'); + $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform'); + } + } + advmultiselectResize(); $(window).resize(function() { advmultiselectResize(); }); - $.fn.crmtooltip = function(){ - $('a.crm-summary-link') - .addClass('crm-processed') - .live('mouseover', - function(e) { - $(this).addClass('crm-tooltip-active'); - topDistance = e.pageY - $(window).scrollTop(); - if (topDistance < 300 | topDistance < $(this).children('.crm-tooltip-wrapper').height()) { - $(this).addClass('crm-tooltip-down'); - } - if ($(this).children('.crm-tooltip-wrapper').length == '') { + $.fn.crmtooltip = function() { + $('a.crm-summary-link:not(.crm-processed)') + .addClass('crm-processed') + .on('mouseover', function(e) { + $(this).addClass('crm-tooltip-active'); + var topDistance = e.pageY - $(window).scrollTop(); + if (topDistance < 300 | topDistance < $(this).children('.crm-tooltip-wrapper').height()) { + $(this).addClass('crm-tooltip-down'); + } + if (!$(this).children('.crm-tooltip-wrapper').length) { $(this).append('<div class="crm-tooltip-wrapper"><div class="crm-tooltip"></div></div>'); $(this).children().children('.crm-tooltip') .html('<div class="crm-loading-element"></div>') .load(this.href); } }) - .live('mouseout', - function(){ - $(this).removeClass('crm-tooltip-active'); - $(this).removeClass('crm-tooltip-down'); - } - ) - .live('click', - function(){ - return false; - } - ); + .on('mouseout', function() { + $(this).removeClass('crm-tooltip-active crm-tooltip-down'); + }) + .on('click', false); }; var h; @@ -602,11 +589,11 @@ CRM.validate = CRM.validate || { { data: params, dataType: 'html', - success: function(data) { + success: function (data) { $('#crm-notification-container .crm-help .notify-content:last').html(data); $('#crm-notification-container .crm-help').removeClass('crm-msg-loading').addClass('info'); }, - error: function(data) { + error: function () { $('#crm-notification-container .crm-help .notify-content:last').html('Unable to load help file.'); $('#crm-notification-container .crm-help').removeClass('crm-msg-loading').addClass('error'); } @@ -638,7 +625,7 @@ CRM.validate = CRM.validate || { unique: true }; options = $.extend(extra, options); - options.expires = options.expires === false ? 0 : parseInt(options.expires); + options.expires = options.expires === false ? 0 : parseInt(options.expires, 10); if (options.unique && options.unique !== '0') { $('#crm-notification-container .ui-notify-message').each(function() { if (title === $('h1', this).html() && text === $('.notify-content', this).html()) { @@ -655,7 +642,7 @@ CRM.validate = CRM.validate || { alert(text); return null; } - } + }; /** * Close whichever alert contains the given node @@ -664,7 +651,7 @@ CRM.validate = CRM.validate || { */ CRM.closeAlertByChild = function(node) { $(node).closest('.ui-notify-message').find('.icon.ui-notify-close').click(); - } + }; /** * Prompt the user for confirmation. @@ -696,14 +683,14 @@ CRM.validate = CRM.validate || { settings.buttons[label] = function() { callback.call(dialog); dialog.dialog('close'); - } + }; }); dialog = $('<div class="crm-container crm-confirm-dialog"></div>') .html(options.message) .appendTo('body') .dialog(settings); return dialog; - } + }; /** * Sets an error message @@ -742,22 +729,22 @@ CRM.validate = CRM.validate || { });}, 1000); } return msg; - } + }; // Display system alerts through js notifications function messagesFromMarkup() { $('div.messages:visible', this).not('.help').not('.no-popup').each(function() { + var text, title = ''; $(this).removeClass('status messages'); var type = $(this).attr('class').split(' ')[0] || 'alert'; type = type.replace('crm-', ''); $('.icon', this).remove(); - var title = ''; if ($('.msg-text', this).length > 0) { - var text = $('.msg-text', this).html(); + text = $('.msg-text', this).html(); title = $('.msg-title', this).html(); } else { - var text = $(this).html(); + text = $(this).html(); } var options = $(this).data('options') || {}; $(this).remove(); @@ -786,14 +773,12 @@ CRM.validate = CRM.validate || { }); $.fn.crmAccordions = function(speed) { + var container = $('#crm-container'); if (speed === undefined) { speed = 200; } if ($(this).length > 0) { - var container = $(this); - } - else { - var container = $('#crm-container'); + container = $(this); } if (container.length > 0 && !container.hasClass('crm-accordion-processed')) { // Allow normal clicking of links @@ -811,7 +796,7 @@ CRM.validate = CRM.validate || { return false; }); container.addClass('crm-accordion-processed'); - }; + } }; $.fn.crmAccordionToggle = function(speed) { $(this).each(function() {