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