Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-11-26-11-43-18
[civicrm-core.git] / templates / CRM / Badge / Form / Layout.js
1 // http://civicrm.org/licensing
2 cj(function ($) {
3 function openKCFinder(field) {
4 window.KCFinder = {
5 callBack: function(url) {
6 field.val(url);
7 // calculate the image default width, height
8 // and assign to respective fields
9 var ajaxUrl = CRM.url('civicrm/ajax/rest', 'className=CRM_Badge_Page_AJAX&fnName=getImageProp&json=1&img=' + url);
10 $.ajax({
11 url: ajaxUrl,
12 async: false,
13 global: false,
14 dataType: "json",
15 success: function ( response ) {
16 var widthId = 'width_' + field.attr('id');
17 var heightId = 'height_' + field.attr('id');
18 $('#' + widthId).val(response.width.toFixed(0));
19 $('#' + heightId).val(response.height.toFixed(0));
20 }
21 });
22 window.KCFinder = null;
23 }
24 };
25
26 window.open(CRM.kcfinderPath + 'kcfinder/browse.php?cms=civicrm&type=images', 'kcfinder_textbox',
27 'status=0, toolbar=0, location=0, menubar=0, directories=0, ' +
28 'resizable=1, scrollbars=0, width=800, height=600'
29 );
30 }
31
32 $('input[id^="image_"]').click(function(){
33 openKCFinder($(this));
34 });
35
36 $('.clear-image').click(function(){
37 var imgName = $(this).attr('imgname');
38 $('#' + imgName).val('');
39 $('#width_' + imgName).val('');
40 $('#height_' + imgName).val('');
41 return false;
42 });
43 });