1jQuery(function() { 2 var copyThisPage = function() { 3 var oldId = JSINFO.id; 4 while (true) { 5 var newId = prompt(LANG.plugins.copypage.enter_page_id, oldId); 6 // Note: When a user canceled, most browsers return the null, but Safari returns the empty string 7 if (newId) { 8 if (newId === oldId) { 9 alert(LANG.plugins.copypage.different_id_required); 10 continue; 11 } 12 13 var url = DOKU_BASE + 'doku.php?id=' + encodeURIComponent(newId) + 14 '&do=edit©from=' + encodeURIComponent(oldId); 15 location.href = url; 16 } 17 break; 18 } 19 }; 20 21 // Handle click of desktop menu. 22 jQuery('.copypageplugin__copy').click(function(e) { 23 e.preventDefault(); 24 copyThisPage(); 25 }); 26 27 // Add a menu item to the "Page Tools" group of the mobile menu. 28 // No longer needed for new menu system since 2017-09-01. 29 if (jQuery('select.quickselect option[value="copypageplugin__copy"]').length == 0) { 30 jQuery('select.quickselect optgroup:nth-of-type(1)').append( 31 jQuery('<option value="copypageplugin__copy">').text(jQuery('.copypageplugin__copy').text())); 32 } 33 34 // Dirty hack to handle selection of mobile menu. 35 // See: https://github.com/splitbrain/dokuwiki/blob/release_stable_2018-04-22/lib/scripts/behaviour.js#L102-L115 36 jQuery('select.quickselect') 37 .unbind('change') // Remove dokuwiki's default handler to override its behavior 38 .change(function(e) { 39 if (e.target.value != 'copypageplugin__copy') { 40 // do the default action 41 e.target.form.submit(); 42 return; 43 } 44 45 e.target.value = ''; // Reset selection to enable re-select when a prompt is canceled 46 copyThisPage(); 47 }); 48}); 49