Topagination (suck it, Dicsourse)
-
Continuing the discussion from The Official "Likes" Thread:
By the way, if you want pages, set up this in a user script to run on page load
, and then have it added to trigger to run thenm, added the document onscroll event handler attachment at the end, now it auto-pages as you scroll and/or click the page links. Also works to bookmark the code and run on pageload if you dont have a userscripts extension.__pagemaker();
function on every ember loading trigger so it updates the pages as you scroll and/or click through the pages. Could also attach to the body onscroll event probably.--snip: see code below--
yes it's javascript-soup. i can't be arsed to make it less soupy because I don't care that much; it's just funny to me that it took me about 30 minutes to turn the topic-progress bar into a working pages system.
eat topagination punks.
[code]
function __pagemaker(){
try{$("#topicalized").remove()}catch(err){};
var loc=location.pathname.split("/");
var tlink = "/"+loc[1]+"/"+loc[2]+"/"+loc[3]+"/";
var npp=50;
var h4s=$("#topic-progress h4");
var c=+h4s.get(0).innerText;
var t=+h4s.get(1).innerText;
var tp = $("#topic-progress").get(0);
tp.innerHTML+=""+(c>2*npp?"1 | ... | ":"")+(c>npp?""+Math.floor(c/npp)+"":"")+" | "+(1+Math.floor(c/npp))+""+(c<Math.floor(t/npp)*npp ?" | "+(2+Math.floor(c/npp))+"":"")+(c<Math.floor(t/npp)*npp-npp?" | ... | "+(Math.ceil(t/npp))+"":"")+"";
tp.style.overflow="visible";tp.style.height="70px";
tp.style.textAlign="center";
$("#topic-progress i").get(0).style.display="none";
$("#topic-progress .nums,#topic-progress .bg").each(
function(){
$(this).get(0).style.height="34px";
});
};
__pagemaker();
$(document).scroll(__pagemaker);
[/code]Also, reply as new topic mangles the shit out of [code] blocks, had to FTFM. And quotes mangle [code] blocks too...
If anyone wants to take that and make it a bit more robust in terms of listing the page #s out instead of just having 1 ... n-1 | n | n+1 ... N, go for it. I might fool with it later if there is actually interest, otherwise it was just me burning an hour for lulz of dicsourse topagination.
-
Topagination add-on pics:
or
or from a slightly less insane topic:
-
-
var npp = new Date % 1000;
-
sucks when you get the 1 post / page then huh?
-
-
I'll leave it to the users to add divbyzero error handling in the case that they want 0 posts/page
summons inner-jeffness WORKINGASINTENDED, WONTFIX
-
You really should make a plugin instead of userscripts
-
You really should make a plugin instead of userscripts
how long do you figure it'd take to figure out the pluggy-inning system?
noting that the last time I did ruby, it was just an up and coming fad language destined for "greatness" (2001-ish?).
-
Also, the positive response is appreciated.
Anyone else is welcome to the code to create a plug-in from it, unless Discourse Topagination Patent is worth millions, then I patent it right now and charge one meeeeeellion dollors
-
Also, the positive response is appreciated.
So where left out venting our negative response ... I would have thought you knew us better ...
-
Congratulations
-
how long do you figure it'd take to figure out the pluggy-inning system?
Careful, that mentality got us PHP.
-
how long do you figure it'd take to figure out the pluggy-inning system?
The main barrier is getting up the dev environment, there are a bunch of plugins out there you could use as a template, (like the stop spamming history one)
If you are comfortable around Linux then its probably not too hard.
-
Has no one really made a VM appliance for this yet?
-
We have this, http://blog.discourse.org/2013/04/discourse-as-your-first-rails-app/ but I think it is due for a full update.
It should work, some use it.
-
Not feeling it right now for getting a VM fired up just to run a Discourse install… just getting the install up and running would take more time that I've invested total in all the scripting done here (actually the screenshot below my have taken longer to generate than the code... :(). Maybe another day if I'm even more bored and have too much time on my hands.
Including this new one I just made for the topics list, which took about 15 minutes since I already had an idea as to what I wanted it to do this time:
[code]
function __topaginateTopicList() {
$(".topaginatedtopiclist").remove();
$("#topic-list td.posts span.number").each(
function () {
var _numPostsPerPage = 50;
var _pagesToShow = 5;
try {
var posts = +$(this).attr("title").split(" ")[2];
var lastPage = Math.ceil(posts / _numPostsPerPage);
var pages = Math.min(_pagesToShow, lastPage+1);
var temp = $(this).parent().attr("href").split("/");
var url = "/" + temp[1] + "/" + temp[2] + "/" + temp[3] + "/";
if (lastPage == 1) {
return;
}
var pageList = "1";for (var i = 2; i < pages; i++) { pageList += ", <a href='" + url + (_numPostsPerPage * (i - 1) + 1) + "'>" + i + "</a>"; } var delim = "… "; if (lastPage == _pagesToShow) { delim = ","; } if (lastPage >= _pagesToShow) { pageList += delim+" <a href='" + url + (_numPostsPerPage * (lastPage - 1) + 1) + "'>" + lastPage + "</a>"; } $(this).parent().parent().append("<div class='topaginatedtopiclist'>" + pageList + "</div>"); } catch (err) { alert('screwyoudiscourse:)'); } });
};
__topaginateTopicList();
$(document).scroll(__topaginateTopicList);
[/code]Adding that will paginate the Topic Listing, making it look more like a regular forum. I stole the numbering [1, 2, 3, 4...n] numbering system from diablo forums. Where there is only 1 page, there are no page links because clicking the topic takes you to page1 anyway. in that you can jump to last page if you're not logged in (this would probably actually be useful, for the Lurkers-that-don't-want-to-make-accounts). At least then they have the old way of jumping to page# X on topics they're semi-paying attention to without having to sign up for the full watching/tracking features.
pics or it didn't happen:
-
Clearly the topic list page number links are useless if you're logged in and have a topic tracked/watched. But if you haven't started reading a topic and just want to hit the end to mark it viewed, or if you don't want to log in at all, you can still jump ahead to the last group of posts as in a normal forum without loading the first page and knowing that you have to hit END or use the green blob to go bottom. It might help let new Dicsourse users get used to the system and keys on a more gradual basis instead of being dumped straight into infini-scroll hell like we were.
-
Since I made the last one actually function like a real forum, I figured I'd fix the original in a couple of minutes too, and make it somewhat less soupy:
[code]
function __pagemaker() {
try { $("#topicalized").remove() } catch (err) { };
var loc = location.pathname.split("/");
var url = "/" + loc[1] + "/" + loc[2] + "/" + loc[3] + "/";
var npp = 50;
var h4s = $("#topic-progress h4");
var c = +h4s.get(0).innerText;
var t = +h4s.get(1).innerText;
var tp = $("#topic-progress").get(0);
var cp = Math.ceil(c / npp);
var lp = Math.ceil(t / npp);
var pageList = "";
if (cp == 1) {
pageList += "1";
} else {
pageList += "1";
}
var mincp = cp - 2;
var maxcp = cp + 2;
if (mincp > 2) {
pageList += "… ";
}
for (var i = Math.max(2, mincp) ; i <= Math.min(maxcp, lp) ; i++) {
if (i == 2 || i > mincp) {
pageList += ", ";
}
if (cp == i) {
pageList += i;
} else {
pageList += "" + i + "";
}
}
if (maxcp < lp - 1) {
pageList += "… ";
} else if (maxcp == lp - 1) {
pageList += ", ";
}if (maxcp <= lp - 1) { if (cp == lp) { pageList += lp; } else { pageList += "<a href='" + url + (npp * (lp - 1) + 1) + "'>" + lp + "</a>"; } } var fontsize = t > 9999 ? 14 : 16; tp.innerHTML += "<div id='topicalized' style='text-align:center;padding-top:10px;width:240px;background-color:#e9e9e9;height:34px;font-weight:bold;font-size:" + fontsize + "px;'>" + pageList + "</div>"; tp.style.overflow = "visible"; tp.style.height = "70px"; $("#topic-progress i").get(0).style.display = "none"; $("#topic-progress .nums,#topic-progress .bg").each( function () { $(this).get(0).style.height = "34px"; });
};
__pagemaker();
$(document).scroll(__pagemaker);
[/code]Ironically, because Dicsourse is all AJAX, including apparently navigating back to the topics list using the Home Icon, just running the Pagination scripts 1x keeps them loaded for that window until you refresh or go to a new tab.
-
The new one looks like this instead of that ugly thing I had pasted in before:
or in the case of the immortal Likes Topic:
-
} catch (err) { alert('screwyoudiscourse:)'); }
+1 for logging "there was an error" to the end user's screen
-
The new one looks like this instead of that ugly thing I had pasted in before:
or in the case of the immoral Likes Topic:
FTFY. HTH. HAND. (GD&R)
-
At least the error text is always correct.
-
On Discourse Resume Next
-
You didn't post in the evil ideas thread.
-
So... how does this happen? Impressive job @Arantor, replying without replying.
-
It's another DC bug, of course.
-
Even better, because I got that post. Still haven't gotten the other, or even a notification that the other post even exists.
Though I can see that the post #s on my screen skip #25. They need a way for their UI to fix itself when it borks up.
-
They need to write code to not bork the UI in the first place. Solve the problem, not the symptoms.
-
They need to write code to not bork the UI in the first place.
Well, in this case it just lost a post. Though I suppose since the #s are sequential, it should be smart enough to know that it should re-try for post 25 when it gets a stream with post 26 in it.
-
There's probably an ajax error that you didn't notice. I've had a few of those today where stuff stalled and I forced a refresh. I suspect that if I'd waited, someone else might have posted and I'd have seen what you saw.
-
The post is there now.
-
The post is there now.
Woah so it is.... took long enough, but their UI does in fact fix itself in this scenario.
-
There's probably an ajax error that you didn't notice.
There was an error (though I don't know whether it was an AJAX fail on my side or server side, I didn't have the network window open) and I noticed, that's why I pointed it out. The how does this happen? comment was just me being facetious.
Now I wish I could remember whether I had left this topic open waiting on it to fix itself, or reloaded it accidentally by clicking a notification.
-
Woah so it is.... took long enough, but their UI does in fact fix itself in this scenario.
At a guess, from poking around earlier when I had enough patience for userscript stuff...
Every update, even if it's only a single post update, sends along the whole "batch" (whatever it's at atm). Possibly it got delayed on the backend and arrived in the next request, triggered by either it finally appearing, or something else pulling it alongside with it.
-
Every update, even if it's only a single post update, sends along the whole "batch" (whatever it's at atm). Possibly it got delayed on the backend and arrived in the next request, triggered by either it finally appearing, or something else pulling it alongside with it.
I'm shocked because it seems like they just always tack posts onto the end of the stream (as evidenced when the "end" gets jacked and is off by 1).
I think it's more likely I clicked a notification and caused this topic to reload, and then it got all the posts again.
-
I'm shocked because it seems like they just always tack posts onto the end of the stream (as evidenced when the "end" gets jacked and is off by 1).
Consistent inconsistency? I don't feel like hunting for the JSON now (on laptop in train), but I'm pretty sure the ordering is fine in the JSON.
-
It is ordered fine in the JSON.
It's when the stream fails after the topic is loaded, you can end up losing a post, and it doesn't seem to have a way to fix itself without a refresh.
-
-
-
That sounds like a barrier to error-handling.
The Discourse part or the Resume Next part?
-
Definitely the Resume Next. Using Discourse forces you into handling lots of errors.
-
Interestingly, they ninja-broke the topics topagination script with their last release by changing one of the ids to a class.
Filed Under: Very Interesting Indeed.two can play at that game. Fixed:
[code]
function __topaginateTopicList() {
$(".topaginatedtopiclist").remove();
$(".topic-list td.posts span.number").each(
function () {
var _numPostsPerPage = 50;
var _pagesToShow = 5;
try {
var posts = +$(this).attr("title").split(" ")[2];
var lastPage = Math.ceil(posts / _numPostsPerPage);
var pages = Math.min(_pagesToShow, lastPage+1);
var temp = $(this).parent().attr("href").split("/");
var url = "/" + temp[1] + "/" + temp[2] + "/" + temp[3] + "/";
if (lastPage == 1) {
return;
}
var pageList = "1";
for (var i = 2; i < pages; i++) {
pageList += ", " + i + "";
}
var delim = "… ";
if (lastPage == _pagesToShow) {
delim = ",";
}
if (lastPage >= _pagesToShow) {
pageList += delim+" " + lastPage + "";
}
$(this).parent().parent().append("" + pageList + "");
} catch (err) { alert('screwyoudiscourse:)'); }
});
};
__topaginateTopicList();
$(document).scroll(__topaginateTopicList);
[/code]
-
I'd be mildly surprised if it were deliberate because I'd like to think that they're not all that petty.
-
And they'll apparently accept any old non-working garbage as long as it doesn't break something they bothered to write a test for.
-
And they'll apparently accept any old non-working garbage as long as it doesn't break something they bothered to write a test for.
At least they have tests. This is ∞% improved on a situation with no tests whatsoever.
-
At least they have tests. This is ∞% improved on a situation with no tests whatsoever.
Except for the false sense of security. But yeah, they probably catch regressions now and then.
-
Except for the false sense of security. But yeah, they probably catch regressions now and then.
You'd think so, wouldn't you?