Merge pull request #9598 from JMAConsulting/CRM-19585-7
[civicrm-core.git] / templates / CRM / Badge / Form / Layout.js
CommitLineData
d87c3006 1// http://civicrm.org/licensing
3cc60a06 2CRM.$(function($) {
d87c3006 3 function openKCFinder(field) {
4a143c04 4 var field = $(this);
d87c3006
KJ
5 window.KCFinder = {
6 callBack: function(url) {
4a143c04 7 field.val(url).change();
66cae705 8 // calculate the image default width, height
07d113b7
PJ
9 // and assign to respective fields
10 var ajaxUrl = CRM.url('civicrm/ajax/rest', 'className=CRM_Badge_Page_AJAX&fnName=getImageProp&json=1&img=' + url);
4a143c04 11 $.getJSON(ajaxUrl).done(function ( response ) {
07d113b7
PJ
12 var widthId = 'width_' + field.attr('id');
13 var heightId = 'height_' + field.attr('id');
14 $('#' + widthId).val(response.width.toFixed(0));
15 $('#' + heightId).val(response.height.toFixed(0));
4a143c04 16 });
d87c3006
KJ
17 window.KCFinder = null;
18 }
19 };
20
21 window.open(CRM.kcfinderPath + 'kcfinder/browse.php?cms=civicrm&type=images', 'kcfinder_textbox',
22 'status=0, toolbar=0, location=0, menubar=0, directories=0, ' +
23 'resizable=1, scrollbars=0, width=800, height=600'
24 );
25 }
26
4a143c04
CW
27 $('input[id^="image_"]')
28 .click(openKCFinder)
29 .change(function() {
30 $(this).siblings('.clear-image').css({visibility: $(this).val() ? '' : 'hidden'});
31 })
32 .change();
0e7af214 33
4a143c04
CW
34 $('.clear-image').click(function() {
35 $(this).closest('tr').find('input[type=text]').val('').change();
0e7af214
KJ
36 return false;
37 });
d87c3006 38});