1jQuery(function () { 2 'use strict'; 3 4 /** counter for copied multi templates */ 5 var copycount = 0; 6 7 /** 8 * Attach datepicker to date types 9 */ 10 jQuery('input.struct_date').datepicker({ 11 dateFormat: 'yy-mm-dd' 12 }); 13 14 /** 15 * Attach image dialog to image types 16 */ 17 jQuery('button.struct_img').click(function () { 18 var input_id = jQuery(this).siblings('input').attr('id'); 19 window.open( 20 DOKU_BASE + 'lib/exe/mediamanager.php' + 21 '?ns=' + encodeURIComponent(JSINFO['namespace']) + 22 '&edid=' + encodeURIComponent(input_id) + 23 '&onselect=insertStructImage', 24 'mediaselect', 25 'width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes'); // 26 }); 27 28 /** 29 * Custom onSelect handler for struct img button 30 */ 31 window.insertStructImage = function (edid, mediaid, opts, align) { 32 jQuery('#' + edid).val(mediaid).change(); 33 }; 34 35 /** 36 * Duplicate the elements in .newtemplate whenever any input in it changes 37 */ 38 jQuery('#dw__editform').find('.struct .newtemplate').each(function () { 39 var $tplwrapper = jQuery(this); 40 var $tpl = $tplwrapper.children().clone(true, true); 41 42 $tplwrapper.on('change', 'input,textarea,select', function () { 43 if (jQuery(this).val() == '') return; 44 45 // prepare a new template and make sure all the IDs in it are unique 46 var $copy = $tpl.clone(true, true); 47 copycount++; 48 $copy.find('*[id]').each(function() { 49 this.id = this.id + '_' + copycount; 50 }); 51 52 // append the template 53 $tplwrapper.append($copy); 54 }); 55 }); 56 57 /** 58 * Toggle the disabled class in the schema editor 59 */ 60 jQuery('#plugin__struct').find('td.isenabled input').change(function() { 61 var $checkbox = jQuery(this); 62 $checkbox.parents('tr').toggleClass('disabled', !$checkbox.prop('checked')); 63 }); 64 65}); 66