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_media').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=insertStructMedia', 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.insertStructMedia = function (edid, mediaid, opts, align) { 32 jQuery('#' + edid).val(mediaid).change(); 33 }; 34 35 /** 36 * Toggle the disabled class in the schema editor 37 */ 38 jQuery('#plugin__struct').find('td.isenabled input').change(function () { 39 var $checkbox = jQuery(this); 40 $checkbox.parents('tr').toggleClass('disabled', !$checkbox.prop('checked')); 41 }); 42 43 var $dokuform = jQuery('#dw__editform'); 44 45 /** 46 * Duplicate the elements in .newtemplate whenever any input in it changes 47 */ 48 $dokuform.find('.struct .newtemplate').each(function () { 49 var $tplwrapper = jQuery(this); 50 var $tpl = $tplwrapper.children().clone(true, true); 51 52 $tplwrapper.on('change', 'input,textarea,select', function () { 53 if (jQuery(this).val() == '') return; 54 55 // prepare a new template and make sure all the IDs in it are unique 56 var $copy = $tpl.clone(true, true); 57 copycount++; 58 $copy.find('*[id]').each(function () { 59 this.id = this.id + '_' + copycount; 60 }); 61 62 // append the template 63 $tplwrapper.append($copy); 64 }); 65 }); 66 67 /** 68 * Toggle fieldsets in edit form and remeber in cookie 69 */ 70 $dokuform.find('.struct fieldset legend').each(function () { 71 var $legend = jQuery(this); 72 var $fset = $legend.parent(); 73 74 // reinit saved state from cookie 75 if (DokuCookie.getValue($fset.data('schema'))) { 76 $fset.toggleClass('closed'); 77 } 78 79 // attach click handler 80 81 $legend.click(function () { 82 $fset.toggleClass('closed'); 83 // remember setting in preference cookie 84 if ($fset.hasClass('closed')) { 85 DokuCookie.setValue($fset.data('schema'), 1); 86 } else { 87 DokuCookie.setValue($fset.data('schema'), ''); 88 } 89 }); 90 }); 91 92}); 93