From f54254d81b07355356fc478f806bc0da585bd30f Mon Sep 17 00:00:00 2001 From: Tim Otten <totten@civicrm.org> Date: Sat, 3 Jan 2015 14:59:12 -0800 Subject: [PATCH] INFRA-132 - Fix jshint warnings in js/*.js --- js/Audit/audit.js | 4 ++-- js/Common.js | 29 +++++++++++++++++------------ js/crm.ajax.js | 35 ++++++++++++++++++----------------- js/crm.drupal.js | 2 +- js/crm.joomla.js | 2 +- js/crm.searchForm.js | 2 +- js/noconflict.js | 2 +- 7 files changed, 41 insertions(+), 35 deletions(-) diff --git a/js/Audit/audit.js b/js/Audit/audit.js index 96a4e2fdb1..3388c6fee0 100644 --- a/js/Audit/audit.js +++ b/js/Audit/audit.js @@ -27,7 +27,7 @@ function selectActivity(i) { // deselect current selection - j = document.forms["Report"].currentSelection.value; + j = document.forms.Report.currentSelection.value; ele = document.getElementById("civicase-audit-activity-" + j); ele.className = "activity"; ele = document.getElementById("civicase-audit-header-" + j); @@ -49,5 +49,5 @@ function selectActivity(i) ele.style.display = "block"; ele = document.getElementById("civicase-audit-body-" + i); ele.style.display = "block"; - document.forms["Report"].currentSelection.value = i; + document.forms.Report.currentSelection.value = i; } diff --git a/js/Common.js b/js/Common.js index 6bdaf36eb0..f5d2989174 100644 --- a/js/Common.js +++ b/js/Common.js @@ -39,12 +39,14 @@ function ts(text, params) { */ function on_load_init_blocks(showBlocks, hideBlocks, elementType) { if (elementType == null) { - var elementType = 'block'; + elementType = 'block'; } + var myElement, i; + /* This loop is used to display the blocks whose IDs are present within the showBlocks array */ - for (var i = 0; i < showBlocks.length; i++) { - var myElement = document.getElementById(showBlocks[i]); + for (i = 0; i < showBlocks.length; i++) { + myElement = document.getElementById(showBlocks[i]); /* getElementById returns null if element id doesn't exist in the document */ if (myElement != null) { myElement.style.display = elementType; @@ -55,8 +57,8 @@ function on_load_init_blocks(showBlocks, hideBlocks, elementType) { } /* This loop is used to hide the blocks whose IDs are present within the hideBlocks array */ - for (var i = 0; i < hideBlocks.length; i++) { - var myElement = document.getElementById(hideBlocks[i]); + for (i = 0; i < hideBlocks.length; i++) { + myElement = document.getElementById(hideBlocks[i]); /* getElementById returns null if element id doesn't exist in the document */ if (myElement != null) { myElement.style.display = 'none'; @@ -80,13 +82,14 @@ function on_load_init_blocks(showBlocks, hideBlocks, elementType) { * @param invert Boolean - if true, we HIDE target on value match; if false, we SHOW target on value match */ function showHideByValue(trigger_field_id, trigger_value, target_element_id, target_element_type, field_type, invert) { + var target, j; if (field_type == 'select') { var trigger = trigger_value.split("|"); var selectedOptionValue = cj('#' + trigger_field_id).val(); - var target = target_element_id.split("|"); - for (var j = 0; j < target.length; j++) { + target = target_element_id.split("|"); + for (j = 0; j < target.length; j++) { if (invert) { cj('#' + target[j]).show(); } @@ -108,8 +111,8 @@ function showHideByValue(trigger_field_id, trigger_value, target_element_id, tar } else { if (field_type == 'radio') { - var target = target_element_id.split("|"); - for (var j = 0; j < target.length; j++) { + target = target_element_id.split("|"); + for (j = 0; j < target.length; j++) { if (cj('[name="' + trigger_field_id + '"]:first').is(':checked')) { if (invert) { cj('#' + target[j]).hide(); @@ -854,7 +857,9 @@ CRM.strings = CRM.strings || {}; if (endMsg) { $msg.removeClass('status-start').addClass('status-' + status).find('.crm-status-box-msg').html(endMsg); window.setTimeout(function() { - $msg.fadeOut('slow', function() {$msg.remove()}); + $msg.fadeOut('slow', function() { + $msg.remove(); + }); }, 2000); } else { $msg.remove(); @@ -1037,7 +1042,7 @@ CRM.strings = CRM.strings || {}; var ele = $(this); setTimeout(function () { ele.one('change', function () { - msg && msg.close && msg.close(); + if (msg && msg.close) msg.close(); ele.removeClass('error'); label.removeClass('crm-error'); }); @@ -1107,7 +1112,7 @@ CRM.strings = CRM.strings || {}; if (typeof(response.crmMessages) == 'object') { $.each(response.crmMessages, function(n, msg) { CRM.alert(msg.text, msg.title, msg.type, msg.options); - }) + }); } if (response.backtrace) { CRM.console('log', response.backtrace); diff --git a/js/crm.ajax.js b/js/crm.ajax.js index c492f21b9e..fc7610ccef 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -12,7 +12,8 @@ var tplURL; CRM.url = function (path, query, mode) { if (typeof path === 'object') { - return tplURL = path; + tplURL = path; + return path; } if (!tplURL) { CRM.console('error', 'Error: CRM.url called before initialization'); @@ -206,7 +207,7 @@ }, _onFailure: function(data, status) { var msg, title = ts('Network Error'); - this.options.block && this.element.unblock(); + if (this.options.block) this.element.unblock(); this.element.trigger('crmAjaxFail', data); switch (status) { case 'Forbidden': @@ -239,7 +240,7 @@ _handleOrderLinks: function() { var that = this; $('a.crm-weight-arrow', that.element).click(function(e) { - that.options.block && that.element.block(); + if (that.options.block) that.element.block(); $.getJSON(that._formatUrl(this.href)).done(function() { that.refresh(); }); @@ -250,13 +251,13 @@ refresh: function() { var that = this; var url = this._formatUrl(this.options.url); - this.options.crmForm && $('form', this.element).ajaxFormUnbind(); + if (this.options.crmForm) $('form', this.element).ajaxFormUnbind(); if (this._originalContent === null) { this._originalContent = this.element.contents().detach(); } - this.options.block && this.element.block(); + if (this.options.block) this.element.block(); $.getJSON(url, function(data) { - that.options.block && that.element.unblock(); + if (that.options.block) that.element.unblock(); if (!$.isPlainObject(data)) { that._onFailure(data); return; @@ -271,7 +272,7 @@ that.element.html(data.content); that._handleOrderLinks(); that.element.trigger('crmLoad', data); - that.options.crmForm && that.element.trigger('crmFormLoad', data); + if (that.options.crmForm) that.element.trigger('crmFormLoad', data); }).fail(function(data, msg, status) { that._onFailure(data, status); }); @@ -286,7 +287,7 @@ } }); } - this.options.crmForm && $('form', this.element).ajaxFormUnbind(); + if (this.options.crmForm) $('form', this.element).ajaxFormUnbind(); }, _destroy: function() { this.element.removeClass('crm-ajax-container').trigger('crmUnload'); @@ -312,7 +313,7 @@ height: '75%' }; } - options && $.extend(true, settings, options); + if (options) $.extend(true, settings, options); settings.url = url; // Create new dialog if (settings.dialog) { @@ -377,7 +378,7 @@ } }; // Move options that belong to crmForm. Others will be passed through to crmSnippet - options && $.each(options, function(key, value) { + if (options) $.each(options, function(key, value) { if (typeof(settings.crmForm[key]) !== 'undefined') { settings.crmForm[key] = value; } @@ -403,7 +404,7 @@ } } - widget.data('uiDialog') && widget.on('dialogbeforeclose', function(e) { + if (widget.data('uiDialog')) widget.on('dialogbeforeclose', function(e) { // CRM-14353 - Warn unsaved changes if user clicks close button or presses "esc" if (e.originalEvent) { cancelAction(); @@ -413,7 +414,7 @@ widget.on('crmFormLoad.crmForm', function(event, data) { var $el = $(this).attr('data-unsaved-changes', 'false'), settings = $el.crmSnippet('option', 'crmForm'); - settings.cancelButton && $(settings.cancelButton, this).click(function(e) { + if (settings.cancelButton) $(settings.cancelButton, this).click(function(e) { e.preventDefault(); var returnVal = settings.onCancel.call($el, e); if (returnVal !== false) { @@ -451,7 +452,7 @@ } } else { - $el.crmSnippet('option', 'block') && $el.unblock(); + if ($el.crmSnippet('option', 'block')) $el.unblock(); response.url = data.url; $el.html(response.content).trigger('crmLoad', response).trigger('crmFormLoad', response); if (response.status === 'form_error') { @@ -466,7 +467,7 @@ beforeSerialize: function(form, options) { if (window.CKEDITOR && window.CKEDITOR.instances) { $.each(CKEDITOR.instances, function() { - this.updateElement && this.updateElement(); + if (this.updateElement) this.updateElement(); }); } if (window.tinyMCE && tinyMCE.editors) { @@ -477,9 +478,9 @@ }, beforeSubmit: function(submission) { $.each(formErrors, function() { - this && this.close && this.close(); + if (this && this.close) this.close(); }); - $el.crmSnippet('option', 'block') && $el.block(); + if ($el.crmSnippet('option', 'block')) $el.block(); $el.trigger('crmFormSubmit', submission); } }, settings.ajaxForm)); @@ -575,7 +576,7 @@ if ($table.length && $.fn.DataTable.fnIsDataTable($table[0]) && $table.dataTable().fnSettings().sAjaxSource) { // Refresh ALL datatables - needed for contact relationship tab $.each($.fn.dataTable.fnTables(), function() { - $(this).dataTable().fnSettings().sAjaxSource && $(this).unblock().dataTable().fnDraw(); + if ($(this).dataTable().fnSettings().sAjaxSource) $(this).unblock().dataTable().fnDraw(); }); } // Otherwise refresh the nearest crmSnippet diff --git a/js/crm.drupal.js b/js/crm.drupal.js index 4c1849cbc0..32ed437423 100644 --- a/js/crm.drupal.js +++ b/js/crm.drupal.js @@ -20,5 +20,5 @@ CRM.$(function($) { // D7 hack, restore toolbar position (CRM-15341) $('#toolbar').css('z-index', ''); } - }) + }); }); diff --git a/js/crm.joomla.js b/js/crm.joomla.js index 6ed88eb4cb..4d98804a05 100644 --- a/js/crm.joomla.js +++ b/js/crm.joomla.js @@ -10,5 +10,5 @@ CRM.$(function($) { // J3 - restore footer admin bar position (CRM-15723) $('#status').css('z-index', ''); } - }) + }); }); diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index d759c6caf4..bf993611cb 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -59,7 +59,7 @@ } // Master checkbox else if ($el.hasClass('select-rows')) { - params.name = $('input.select-row').map(function() {return $(this).attr('id')}).get().join('-'); + params.name = $('input.select-row').map(function() {return $(this).attr('id');}).get().join('-'); } } $.getJSON(url, params, function(data) { diff --git a/js/noconflict.js b/js/noconflict.js index d52906a31e..ec64c5e591 100644 --- a/js/noconflict.js +++ b/js/noconflict.js @@ -1,3 +1,3 @@ -window.CRM || (window.CRM = {}); +if (!window.CRM) window.CRM = {}; window.cj = CRM.$ = jQuery.noConflict(true); CRM._ = _.noConflict(); -- 2.25.1