From f1056a9b2fd6e4ff7bc107372e9210bae9e077f0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 5 Jul 2012 00:30:02 +0200 Subject: [PATCH] [ticket/10811] Make toogle_subscribe more generic so it can toogle all links PHPBB3-10811 --- phpBB/assets/javascript/core.js | 35 +++++++++++-------- phpBB/includes/functions_display.php | 3 +- .../prosilver/template/overall_footer.html | 4 +-- .../subsilver2/template/viewforum_body.html | 2 +- phpBB/viewforum.php | 8 +++-- phpBB/viewtopic.php | 6 ++-- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 3c1e39fca6..76615eb051 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -452,24 +452,31 @@ phpbb.add_ajax_callback('alt_text', function() { * It replaces the current text with the text in the alt-text data attribute, * and replaces the text in the attribute with the current text so that the * process can be repeated. - * Additionally it replaces the icon of the link and changes the link itself. + * Additionally it replaces the class of the link's parent + * and changes the link itself. */ -phpbb.add_ajax_callback('toggle_subscribe', function() { +phpbb.add_ajax_callback('toggle_link', function() { var el = $(this), - alt_text; + toggle_text, + toggle_url, + toggle_class; - phpbb.ajax_callbacks['alt_text'].call(this); + // Toggle link text - if (el.attr('href').indexOf('unwatch') !== -1) - { - el.attr('href', el.attr('href').replace('unwatch', 'watch')); - el.parent().attr('class', 'icon-subscribe'); - } - else - { - el.attr('href', el.attr('href').replace('watch', 'unwatch')); - el.parent().attr('class', 'icon-unsubscribe'); - } + toggle_text = el.attr('data-toggle-text'); + el.attr('data-toggle-text', el.text()); + el.attr('title', toggle_text); + el.text(toggle_text); + + // Toggle link url + toggle_url = el.attr('data-toggle-url'); + el.attr('data-toggle-url', el.attr('href')); + el.attr('href', toggle_url); + + // Toggle class of link parent + toggle_class = el.attr('data-toggle-class'); + el.attr('data-toggle-class', el.parent().attr('class')); + el.parent().attr('class', toggle_class); }); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 7c1d007d55..bbfd6fd6b6 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1218,8 +1218,9 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, if ($can_watch) { $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start&hash=" . generate_link_hash("{$mode}_$match_id")); + $s_watching['link_toggle'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&" . ((!$is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start&hash=" . generate_link_hash("{$mode}_$match_id")); $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)]; - $s_watching['toggle'] = $user->lang[((!$is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)]; + $s_watching['title_toggle'] = $user->lang[((!$is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)]; $s_watching['is_watching'] = $is_watching; } diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index 1aab6528cd..b473e7022c 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -8,8 +8,8 @@