| 1 | // http://civicrm.org/licensing |
| 2 | CRM.$(function($) { |
| 3 | function openKCFinder(field) { |
| 4 | var field = $(this); |
| 5 | window.KCFinder = { |
| 6 | callBack: function(url) { |
| 7 | field.val(url).change(); |
| 8 | // calculate the image default width, height |
| 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); |
| 11 | $.getJSON(ajaxUrl).done(function ( response ) { |
| 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)); |
| 16 | }); |
| 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 | |
| 27 | $('input[id^="image_"]') |
| 28 | .click(openKCFinder) |
| 29 | .change(function() { |
| 30 | $(this).siblings('.clear-image').css({visibility: $(this).val() ? '' : 'hidden'}); |
| 31 | }) |
| 32 | .change(); |
| 33 | |
| 34 | $('.clear-image').click(function() { |
| 35 | $(this).closest('tr').find('input[type=text]').val('').change(); |
| 36 | return false; |
| 37 | }); |
| 38 | }); |