X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=templates%2FCRM%2FBadge%2FForm%2FLayout.js;h=d17751f7b87e1929774fb38441c8278a3c661df3;hb=66cae70584f43f4d98a9a08b686487f9a0353d00;hp=183331393f48024d7ee61f54962655854c2a4f36;hpb=dfa8639f4cd3a0bd849469fb8019ae45f9dfbc7a;p=civicrm-core.git diff --git a/templates/CRM/Badge/Form/Layout.js b/templates/CRM/Badge/Form/Layout.js index 183331393f..d17751f7b8 100644 --- a/templates/CRM/Badge/Form/Layout.js +++ b/templates/CRM/Badge/Form/Layout.js @@ -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; }); });