1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-05 23:25:30 +02:00

[ticket/10811] Make toogle_subscribe more generic so it can toogle all links

PHPBB3-10811
This commit is contained in:
Joas Schilling 2012-07-05 00:30:02 +02:00
parent fc3a19567f
commit f1056a9b2f
6 changed files with 35 additions and 23 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -8,8 +8,8 @@
<ul class="linklist">
<li class="icon-home"><a href="{U_INDEX}" accesskey="h">{L_INDEX}</a></li>
<!-- IF not S_IS_BOT -->
<!-- IF S_WATCH_FORUM_LINK --><li <!-- IF S_WATCHING_FORUM -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{S_WATCH_FORUM_LINK}" title="{S_WATCH_FORUM_TITLE}" data-ajax="toggle_subscribe" data-alt-text="{S_WATCH_FORUM_TOGGLE}">{S_WATCH_FORUM_TITLE}</a></li><!-- ENDIF -->
<!-- IF U_WATCH_TOPIC --><li <!-- IF S_WATCHING_TOPIC -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{U_WATCH_TOPIC}" title="{S_WATCH_TOPIC_TITLE}" data-ajax="toggle_subscribe" data-alt-text="{S_WATCH_TOPIC_TOGGLE}">{S_WATCH_TOPIC_TITLE}</a></li><!-- ENDIF -->
<!-- IF U_WATCH_FORUM_LINK --><li <!-- IF S_WATCHING_FORUM -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{U_WATCH_FORUM_LINK}" title="{S_WATCH_FORUM_TITLE}" data-ajax="toggle_link" data-toggle-class="icon-<!-- IF not S_WATCHING_FORUM -->unsubscribe<!-- ELSE -->subscribe<!-- ENDIF -->" data-toggle-text="{S_WATCH_FORUM_TOGGLE}" data-toggle-url="{U_WATCH_FORUM_TOGGLE}">{S_WATCH_FORUM_TITLE}</a></li><!-- ENDIF -->
<!-- IF U_WATCH_TOPIC --><li <!-- IF S_WATCHING_TOPIC -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{U_WATCH_TOPIC}" title="{S_WATCH_TOPIC_TITLE}" data-ajax="toggle_link" data-toggle-class="<!-- IF not S_WATCHING_TOPIC -->icon-unsubscribe<!-- ELSE -->icon-subscribe<!-- ENDIF -->" data-toggle-text="{S_WATCH_TOPIC_TOGGLE}" data-toggle-url="{U_WATCH_TOPIC_TOGGLE}">{S_WATCH_TOPIC_TITLE}</a></li><!-- ENDIF -->
<!-- IF U_BOOKMARK_TOPIC --><li class="icon-bookmark"><a href="{U_BOOKMARK_TOPIC}" title="{L_BOOKMARK_TOPIC}" data-ajax="alt_text" data-alt-text="{S_BOOKMARK_TOGGLE}">{S_BOOKMARK_TOPIC}</a></li><!-- ENDIF -->
<!-- IF U_BUMP_TOPIC --><li class="icon-bump"><a href="{U_BUMP_TOPIC}" title="{L_BUMP_TOPIC}" data-ajax="true">{L_BUMP_TOPIC}</a></li><!-- ENDIF -->
<!-- ENDIF -->

View File

@ -154,7 +154,7 @@
<td class="cat" colspan="<!-- IF S_TOPIC_ICONS -->7<!-- ELSE -->6<!-- ENDIF -->">
<table width="100%" cellspacing="0">
<tr class="nav">
<td valign="middle">&nbsp;<!-- IF S_WATCH_FORUM_LINK and not S_IS_BOT --><a href="{S_WATCH_FORUM_LINK}">{S_WATCH_FORUM_TITLE}</a><!-- ENDIF --></td>
<td valign="middle">&nbsp;<!-- IF U_WATCH_FORUM_LINK and not S_IS_BOT --><a href="{U_WATCH_FORUM_LINK}">{S_WATCH_FORUM_TITLE}</a><!-- ENDIF --></td>
<td align="{S_CONTENT_FLOW_END}" valign="middle"><!-- IF not S_IS_BOT and U_MARK_TOPICS --><a href="{U_MARK_TOPICS}">{L_MARK_TOPICS_READ}</a><!-- ENDIF -->&nbsp;</td>
</tr>
</table>

View File

@ -204,8 +204,9 @@ if (!$config['use_system_cron'])
// Forum rules and subscription info
$s_watching_forum = array(
'link' => '',
'link_toggle' => '',
'title' => '',
'toggle' => '',
'title_toggle' => '',
'is_watching' => false,
);
@ -319,9 +320,10 @@ $template->assign_vars(array(
'S_SELECT_SORT_KEY' => $s_sort_key,
'S_SELECT_SORT_DAYS' => $s_limit_days,
'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
'U_WATCH_FORUM_LINK' => $s_watching_forum['link'],
'U_WATCH_FORUM_TOGGLE' => $s_watching_forum['link_toggle'],
'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
'S_WATCH_FORUM_TOGGLE' => $s_watching_forum['toggle'],
'S_WATCH_FORUM_TOGGLE' => $s_watching_forum['title_toggle'],
'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&amp;start=$start")),
'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,

View File

@ -449,8 +449,9 @@ $viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&a
// Are we watching this topic?
$s_watching_topic = array(
'link' => '',
'link_toggle' => '',
'title' => '',
'toggle' => '',
'title_toggle' => '',
'is_watching' => false,
);
@ -651,8 +652,9 @@ $template->assign_vars(array(
'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;t=$topic_id") : '',
'U_WATCH_TOPIC' => $s_watching_topic['link'],
'U_WATCH_TOPIC_TOGGLE' => $s_watching_topic['link_toggle'],
'S_WATCH_TOPIC_TITLE' => $s_watching_topic['title'],
'S_WATCH_TOPIC_TOGGLE' => $s_watching_topic['toggle'],
'S_WATCH_TOPIC_TOGGLE' => $s_watching_topic['title_toggle'],
'S_WATCHING_TOPIC' => $s_watching_topic['is_watching'],
'U_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&amp;bookmark=1&amp;hash=' . generate_link_hash("topic_$topic_id") : '',