Merge pull request #2414 from prototech/ticket/12440

[ticket/12440] Set browser URL to point to specific post when using view=unread

* prototech/ticket/12440:
  [ticket/12440] Use a more generic approach for replacing the URL.
  [ticket/12440] Set browser URL to point to specific post when using view=unread

Conflicts:
	phpBB/styles/prosilver/template/viewtopic_body.html
This commit is contained in:
Joas Schilling 2014-05-08 13:23:12 +02:00
commit e976f7908a
3 changed files with 75 additions and 3 deletions

View file

@ -694,6 +694,74 @@ $('#phpbb').click(function(e) {
} }
}); });
phpbb.history = {};
/**
* Check whether a method in the native history object is supported.
*
* @param string fn Method name.
* @return bool Returns true if the method is supported.
*/
phpbb.history.isSupported = function(fn) {
if (typeof history === 'undefined' || typeof history[fn] === 'undefined') {
return false;
}
return true;
};
/**
* Wrapper for the pushState and replaceState methods of the
* native history object.
*
* @param string mode Mode. Either push or replace.
* @param string url New URL.
* @param string title Optional page title.
* @patam object obj Optional state object.
*
* @return undefined
*/
phpbb.history.alterUrl = function(mode, url, title, obj) {
var fn = mode + 'State';
if (!url || !phpbb.history.isSupported(fn)) {
return;
}
if (!title) {
title = document.title;
}
if (!obj) {
obj = null;
}
history[fn](obj, title, url);
};
/**
* Wrapper for the native history.replaceState method.
*
* @param string url New URL.
* @param string title Optional page title.
* @patam object obj Optional state object.
*
* @return undefined
*/
phpbb.history.replaceUrl = function(url, title, obj) {
phpbb.history.alterUrl('replace', url, title, obj);
};
/**
* Wrapper for the native history.pushState method.
*
* @param string url New URL.
* @param string title Optional page title.
* @patam object obj Optional state object.
*
* @return undefined
*/
phpbb.history.pushUrl = function(url, title, obj) {
phpbb.history.alterUrl('push', url, title, obj);
};
/** /**
* Hide the optgroups that are not the selected timezone * Hide the optgroups that are not the selected timezone
* *
@ -1444,6 +1512,10 @@ $(document).ready(function() {
$('#color_palette_placeholder').each(function() { $('#color_palette_placeholder').each(function() {
phpbb.registerPalette($(this)); phpbb.registerPalette($(this));
}); });
// Update browser history URL to point to specific post in viewtopic.php
// when using view=unread#unread link.
phpbb.history.replaceUrl($('#unread[data-url]').data('url'));
}); });
})(jQuery); // Avoid conflicts with other libraries })(jQuery); // Avoid conflicts with other libraries

View file

@ -115,7 +115,7 @@
<!-- BEGIN postrow --> <!-- BEGIN postrow -->
<!-- EVENT viewtopic_body_postrow_post_before --> <!-- EVENT viewtopic_body_postrow_post_before -->
<!-- IF postrow.S_FIRST_UNREAD --><a id="unread"></a><!-- ENDIF --> <!-- IF postrow.S_FIRST_UNREAD --><a id="unread" data-url="{postrow.U_MINI_POST}"></a><!-- ENDIF -->
<div id="p{postrow.POST_ID}" class="post <!-- IF postrow.S_ROW_COUNT is odd -->bg1<!-- ELSE -->bg2<!-- ENDIF --><!-- IF postrow.S_UNREAD_POST --> unreadpost<!-- ENDIF --><!-- IF postrow.S_POST_REPORTED --> reported<!-- ENDIF --><!-- IF postrow.S_POST_DELETED --> deleted<!-- ENDIF --><!-- IF postrow.S_ONLINE and not postrow.S_POST_HIDDEN --> online<!-- ENDIF --><!-- IF postrow.POSTER_WARNINGS --> warned<!-- ENDIF -->"> <div id="p{postrow.POST_ID}" class="post <!-- IF postrow.S_ROW_COUNT is odd -->bg1<!-- ELSE -->bg2<!-- ENDIF --><!-- IF postrow.S_UNREAD_POST --> unreadpost<!-- ENDIF --><!-- IF postrow.S_POST_REPORTED --> reported<!-- ENDIF --><!-- IF postrow.S_POST_DELETED --> deleted<!-- ENDIF --><!-- IF postrow.S_ONLINE and not postrow.S_POST_HIDDEN --> online<!-- ENDIF --><!-- IF postrow.POSTER_WARNINGS --> warned<!-- ENDIF -->">
<div class="inner"> <div class="inner">

View file

@ -141,7 +141,7 @@
<!-- IF postrow.S_POST_HIDDEN --> <!-- IF postrow.S_POST_HIDDEN -->
<td class="gensmall" colspan="2" height="25" align="center"> <td class="gensmall" colspan="2" height="25" align="center">
<!-- IF postrow.S_FIRST_UNREAD --><a name="unread"></a><!-- ENDIF --> <!-- IF postrow.S_FIRST_UNREAD --><a id="unread" data-url="{postrow.U_MINI_POST}"></a><!-- ENDIF -->
<a name="p{postrow.POST_ID}"></a> <a name="p{postrow.POST_ID}"></a>
<!-- IF postrow.S_POST_HIDDEN --> <!-- IF postrow.S_POST_HIDDEN -->
<!-- IF postrow.S_POST_DELETED --> <!-- IF postrow.S_POST_DELETED -->
@ -155,7 +155,7 @@
<!-- ELSE --> <!-- ELSE -->
<td align="center" valign="middle"> <td align="center" valign="middle">
<!-- IF postrow.S_FIRST_UNREAD --><a name="unread"></a><!-- ENDIF --><a name="p{postrow.POST_ID}"></a> <!-- IF postrow.S_FIRST_UNREAD --><a id="unread" data-url="{postrow.U_MINI_POST}"></a><!-- ENDIF --><a name="p{postrow.POST_ID}"></a>
<b class="postauthor"<!-- IF postrow.POST_AUTHOR_COLOUR --> style="color: {postrow.POST_AUTHOR_COLOUR}"<!-- ENDIF -->>{postrow.POST_AUTHOR}</b> <b class="postauthor"<!-- IF postrow.POST_AUTHOR_COLOUR --> style="color: {postrow.POST_AUTHOR_COLOUR}"<!-- ENDIF -->>{postrow.POST_AUTHOR}</b>
</td> </td>
<td width="100%" height="25"> <td width="100%" height="25">