views:

402

answers:

3

Hi folks,

First post here.

I'm working on an information warehousing site for HIV prevention. Lots of collaborators will be posting articles via a tinyMCE GUI.

The graphic designers, of course, want control over page lengths. They would like automatic pagination based on the height of content in the page.

Anyone seen AJAX code to manage this?

Barring that anyone seen PHP code that can do a character count and a look-behind regex to avoid splitting words or tags?

Any links much appreciated!

Peace

JG

+1  A: 

You don't just have to worry about character count, you also have to worry about image heights if there are images or any other kind of embedded objects in your pages that can take up height. Character count will also not give you an idea of paragraph structure (a single long paragraph with more characters than a page with many paragraphs might be shorter).

If you're willing to use JavaScript, that might be the ideal solution, post the entire article to the client and let JavaScript handle the pagination. From the client you can detect image and object heights. You could use PHP to place markers about where you think the pages should be, and then use JavaScript to make it happen. Unless the pages are very long I don't think you'll need to do several xmlHttpRequests (AJAX).

For just a straight PHP solution is also simple, but probably not ideal as you're not dealing with a matter of managing row counts. You could use a GET variable to determine where you are in the page.

apphacker
+1  A: 

Although this might not be the exact answer you're looking for, but you should really make sure your site doesn't have a fixed height. Flexible width's are really nice, but not as critical as the height.

Especially for a cause like this, and a content-heavy site; it's fair to require flexible heights.

As mentioned by apphacker, you can't really detect the height from within PHP and you're kind of stuck with javascript. If you're absolutely stuck with paging, it's probably better to let your content authors decide when to break off the page, so you break it on a real section, instead of mid-word, sentence, etc.

Edit: usability should dictate design, not the other way around. You're doing it wrong ;)

Evert
I agree absolutely that we are doing it wrong on this one. It's what happens when a bunch of print people hire a web dev. I have said to them hundreds of times that this is just wrong but they have the contract and I don't get paid for doing it right; I get paid for doing it like the ad exec says.
jerrygarciuh
+2  A: 

If it doesn't need to be exact there's no reason you can't use a simple word count function to determine an appropriate place to break the page (at the nearest paragraph I suppose). You could go so far as to reduce the words per page based on whether there are images in the post, even taking the size of the images into account.

That could get ugly fast though, I think the best way to do it is to allow them to manually set the page dividers with a tag in the article that you can parse out. Something like [pagebreak] is pretty straightforward and you'll get much more logical and readable page breaks than any automated solution would achieve.

epalla
Thanks epalla. I had put that suggestion forward but the ad execs feel I must simply be to ignorant and that automatic pagination of unknown code is really a simple matter.
jerrygarciuh