1jQuery(function () { 2 var $links = jQuery('a.plugin_qsub_subscribe'); 3 if (!$links.length) return; 4 5 /** 6 * Add additional stuff to the dialog 7 * 8 * @param $to {object} jQuery dialog object 9 * @param href {string} 10 */ 11 function addmore($to, href) { 12 var $more = jQuery(document.createElement('div')); 13 $more.addClass('more'); 14 $more.html( 15 '<p>' + LANG.plugins.quicksubscribe.edit_subscr + 16 '<button class="button">' + LANG.plugins.quicksubscribe.edit_subscr_button + 17 '</button></p>' 18 ).find('button').click(function () { 19 document.location = href; 20 }); 21 22 $to.append($more); 23 } 24 25 /** 26 * Handles the whole click processing 27 * 28 * @param e 29 * @returns {boolean} 30 */ 31 function clickhandler(e) { 32 // remove any existing popup 33 jQuery('#plugin_qsub__popup').remove(); 34 35 // create a new popup 36 var $overlay = jQuery(document.createElement('div')); 37 $overlay.attr({ 38 id: 'plugin_qsub__popup', 39 title: LANG.plugins.quicksubscribe.title 40 }); 41 42 var $link = jQuery(this); 43 44 if (jQuery(this).hasClass('plugin_qsub_notsubscribed')) { 45 // Handle Subscriptions 46 $overlay.html( 47 '<p>' + LANG.plugins.quicksubscribe.subscr_in_progress + '</p>' 48 ).load( 49 DOKU_BASE + 'lib/exe/ajax.php', 50 { 51 call: 'plugin_quicksubscribe', 52 ns: JSINFO.namespace + ':', 53 'do': 'subscribe' 54 }, 55 function (text, status) { 56 if (status === 'success') { 57 $link.addClass('plugin_qsub_subscribed'); 58 $link.removeClass('plugin_qsub_notsubscribed'); 59 $link.data('target', JSINFO.namespace + ':'); 60 } 61 addmore($overlay, $link.attr('href')); 62 } 63 ); 64 } else { 65 // Handle unsubscriptions 66 $overlay.html( 67 '<p>' + LANG.plugins.quicksubscribe.is_subscr.replace(/%s/, $link.data('target')) + 68 ' ' + LANG.plugins.quicksubscribe.del_subscr + 69 '<button class="button">' + 70 LANG.plugins.quicksubscribe.del_subscr_button + 71 '</button>' + '</p>' 72 ).find('button').click(function () { 73 $overlay.load( 74 DOKU_BASE + 'lib/exe/ajax.php', 75 { 76 call: 'plugin_quicksubscribe', 77 ns: $link.data('target'), 78 'do': 'unsubscribe' 79 }, 80 function (text, status) { 81 if (status === 'success') { 82 $link.data('target', ''); 83 $link.removeClass('plugin_qsub_subscribed'); 84 $link.addClass('plugin_qsub_notsubscribed'); 85 } 86 addmore($overlay, $link.attr('href')); 87 } 88 ); 89 }); 90 addmore($overlay, $link.attr('href')); 91 } 92 93 // show the dialog 94 $overlay.dialog(); 95 e.preventDefault(); 96 e.stopPropagation(); 97 return false; 98 } 99 100 // attach dialog creation to any quicksubscribe link 101 $links.each(function () { 102 var $link = jQuery(this); 103 // attach click handler 104 $link.click(clickhandler); 105 }); 106}); 107