more whitespace -remove trailing spaces
[civicrm-core.git] / templates / CRM / Badge / Form / Layout.js
index 183331393f48024d7ee61f54962655854c2a4f36..d17751f7b87e1929774fb38441c8278a3c661df3 100644 (file)
@@ -1,24 +1,19 @@
 // http://civicrm.org/licensing
-cj(function ($) {
+CRM.$(function($) {
   function openKCFinder(field) {
+    var field = $(this);
     window.KCFinder = {
       callBack: function(url) {
-        field.val(url);
-        // calculate the image default width, height 
+        field.val(url).change();
+        // calculate the image default width, height
         // and assign to respective fields
          var ajaxUrl = CRM.url('civicrm/ajax/rest', 'className=CRM_Badge_Page_AJAX&fnName=getImageProp&json=1&img=' + url);
-         $.ajax({
-          url: ajaxUrl,
-          async: false,
-          global: false,
-          dataType: "json",
-          success: function ( response ) {
+         $.getJSON(ajaxUrl).done(function ( response ) {
             var widthId = 'width_' + field.attr('id');
             var heightId = 'height_' + field.attr('id');
             $('#' + widthId).val(response.width.toFixed(0));
             $('#' + heightId).val(response.height.toFixed(0));
-          }
-        }); 
+        });
         window.KCFinder = null;
       }
     };
@@ -29,15 +24,15 @@ cj(function ($) {
     );
   }
 
-  $('input[id^="image_"]').click(function(){
-    openKCFinder($(this));
-  });
+  $('input[id^="image_"]')
+    .click(openKCFinder)
+    .change(function() {
+      $(this).siblings('.clear-image').css({visibility: $(this).val() ? '' : 'hidden'});
+    })
+    .change();
 
-  $('.clear-image').click(function(){
-    var imgName = $(this).attr('imgname');
-    $('#' + imgName).val('');
-    $('#width_' + imgName).val('');
-    $('#height_' + imgName).val('');
+  $('.clear-image').click(function() {
+    $(this).closest('tr').find('input[type=text]').val('').change();
     return false;
   });
 });