How Random Babbling Becomes Corporate Policy (t3knomanser) wrote in component_help,
How Random Babbling Becomes Corporate Policy

Ha! Or... skip back entries with a form...

In this thread someone said it was impossible to skip back entries via a form. So I had to be a jerk and prove them wrong. Note: this is a hack, and hence, is not 100% browser compatible (it uses meta-refresh). Also, I'm not at this point checking the page-view, so it redirects back to your base URL (it won't work for your friends-page). At any rate, let's play.

First, we need a component in our print_free_text that works as the form.
"""<form action="$p.base_url" method="get">""";
"""<b>Skip any value of entries</b><br/>
<input type="text" name=".skipnum"/><br/>
<input type="submit" value="Skip"/>

Okay, good, that was easy. Now, when someone hits the submit button there, they're going to want to have their request handled. We're going to do this in your print_custom_head function. Add this:
var string skip = $this.args{"skipnum"};
if ($skip) {
  """<meta http-equiv="refresh" content="0;$this.base_url?skip=$skip"/>""";
}else {
  //whatever your normal print_custom_head does

This is sloppy, but the easiest way I saw to hack things. This sends a message to the browser not to pay attention to this page, and after zero seconds, redirect to the appropriate skip location. However, the "zero seconds" is measured from after the page loads, so it won't due to have people waiting around while the whole page loads.

So, you must customize the print_my_entries function. What you'll have to do is this:

var string skipnum = $p.args{"skipnum"};
if ($skipnum) {
"""<p> Redirecting </p> """;
} else {
  //whatever code you'd want to use normally

Ideally, you should do something similar for your print_profile function and your print_free_text function, so that your journal doesn't load more than it has to while redirecting, making the whole process as fast as possible. If you have a function that outputs something, make the output conditional, based on what you see here. I've got it demoing over on my journal. I have no interest in keeping it, so don't expect it to be around long.

That wasn't so hard, was it?

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened