INFRA-132 - Fix jshint warnings in js/*.js
authorTim Otten <totten@civicrm.org>
Sat, 3 Jan 2015 22:59:12 +0000 (14:59 -0800)
committerTim Otten <totten@civicrm.org>
Mon, 5 Jan 2015 21:46:24 +0000 (13:46 -0800)
js/Audit/audit.js
js/Common.js
js/crm.ajax.js
js/crm.drupal.js
js/crm.joomla.js
js/crm.searchForm.js
js/noconflict.js

index 96a4e2fdb106d13685823dcc144317da818ce138..3388c6fee07a027fbf110751a3cd9a464bcc9d2f 100644 (file)
@@ -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;
 }
index 6bdaf36eb07f98f72f07312f1fb8781391b5a7c6..f5d29891749d5a5cdcf167981161ec7d096ffe2c 100644 (file)
@@ -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);
index c492f21b9ead3d182d3575d09ade617ab0dc8a59..fc7610cceff39938f2eea044bf0a0b1513c34ed4 100644 (file)
@@ -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');
     },
     _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':
     _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();
         });
     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;
         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);
       });
           }
         });
       }
-      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');
         height: '75%'
       };
     }
-    options && $.extend(true, settings, options);
+    if (options) $.extend(true, settings, options);
     settings.url = url;
     // Create new dialog
     if (settings.dialog) {
       }
     };
     // 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;
       }
       }
     }
 
-    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();
     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) {
             }
           }
           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') {
         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) {
         },
         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));
     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
index 4c1849cbc077f98e2750771734a61d1d3a7b2b1a..32ed437423d3933cb60c5b2753285bfd55a80931 100644 (file)
@@ -20,5 +20,5 @@ CRM.$(function($) {
         // D7 hack, restore toolbar position (CRM-15341)
         $('#toolbar').css('z-index', '');
       }
-    })
+    });
 });
index 6ed88eb4cb807df24825c67edd93a8dd7aa4b4cb..4d98804a05f13a0ac8a501cf86bd27e379143fe5 100644 (file)
@@ -10,5 +10,5 @@ CRM.$(function($) {
         // J3 - restore footer admin bar position (CRM-15723)
         $('#status').css('z-index', '');
       }
-    })
+    });
 });
index d759c6caf47b7d7e8b6bcdcb46c8aff3f7b006c1..bf993611cb94ab036f6bdfff74e8c03cc193d2bb 100644 (file)
@@ -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) {
index d52906a31e5f3619926c61b685daec562469dfee..ec64c5e591893a972244b9b4f075dbce07ee8cd8 100644 (file)
@@ -1,3 +1,3 @@
-window.CRM || (window.CRM = {});
+if (!window.CRM) window.CRM = {};
 window.cj = CRM.$ = jQuery.noConflict(true);
 CRM._ = _.noConflict();