NYCPHP Meetup

NYPHP.org

[nycphp-talk] translating behaviors from JavaScript to PHP

-sry sryBoston at hotmail.com
Sat Nov 29 16:52:40 EST 2003


[ repost - sent to the wrong list ]

> Hiya listies,
> 
> Seems like PHP is a bit of a sledgehammer for web design, 
> but I like it so far :)
> 
> I'm currently giving my brain a rest from the Flash/text
> protection thingy and revisiting a CSS design issue I'm
> trying to learn (positioning vs tables). I'm doing this vis a
> vis my personal web site. Since I like to keep code as 
> modularized as possible, I separated out my JavaScript 
> (for mouseover behavior and other sillyness) into a .js file.  
> As a mechanism for putting my hands on some PHP as I 
> learn it, I figured I'd take the existing page design and 
> behavior and "translate" it into a PHP implementation.
> 
> Obviously, I don't separate the PHP code from the page
> (the HTML, CSS, etc.) and obviously I have to adapt the
> few aspects of syntax which actually differ (PHP is sooooo
> kewl, btw :-) I love that my first language was C, this gives
> me such a head start learning any of the new languages
> coming out these days!) 
> 
> Do I just do a one to one translation of the code? 
> 
> http://www.sarahryoffa.com/ 
> http://www.sarahryoffa.com/mouseovers.js 
> has the sorta-working table version with the stylesheet
> embedded in the HEAD, while
> 
> http://www.sarahryoffa.com/debug/indexDebug.html 
> http://www.sarahryoffa.com/debug/debugMouseovers.js 
> has the sorta-working CSS version with the stylesheet
> linked in.
> 
> The .css files contain basically identical information and
> how they are read by the browser is irrelevant (AFAIK)
> 
> The JavaScript files are also nearly-identical (only difference
> is the content of the "answers" to the who, what, where
> links). No issues here relevant to this post (but I'm still
> trying to figure out why some onmouseovers work right
> and others don't when they all have the same code :-( if
> anyone knows or wants to look at this problem, I'm still 
> stumped. mouseover the "what" and then compare the
> behaviors of the "University of Massachusetts" and the
> "Mechanical Engineering" links to see what I mean.)
> 
> In the tables version, when a long "answer" is displayed on
> mouseover, the table readjusts itself and the large image
> in the middle/bottom of the screen (with the quote--yellow
> for the tables, orange for the CSS version) moves down
> nicely.
> 
> In the CSS version, since I'm absolute-positioning, the
> long "answer" text just writes itself "under" the quote
> image. This is not good.
> 
> The copout solution to tackling the CSS positioning issue is
> to simply display that amount of text which will fit into the
> "answer" DIV (one paragraph at a time) and if there's more 
> text, make a ">>" link to continue.  This is not hard but
> if I'm doing this anyway, I'll want to separate out the dynamically
> loaded content of the "answers" into 3 (who, what, where)
> text files.This is my preferred modal approach anyway.
> 
> Is there a way in PHP to #include the "next" paragraph of 
> text (assume I have the "answers" in files named by the 
> convention of "whoAns.txt", "whatAns.txt" and "whereAns.txt" 
> all located in the same directory as the page from which they 
> are called)? Do I need to break the text into edible chunks 
> ahead of time? Ick, if yes.  Ideally, the length and content of the
> "answers" will be completely independent of how they get
> displayed (separation of design and content). I'm just not sure
> of the best approach if the implementation is in PHP. Options
> I can think of:
> 
> 1. parse the strings in the "answer.txt" files and count chars, 
> display up to xxx chars (however many I determine will "fit"
> on the screen without flowing into the next DIV), ending with 
> a space, then display a ">>" to the next paragraph; onClick,
> parse the next xxx chars of the string up to a space char and 
> display them, etc. until the entire string has been displayed. 
> 
> PROBLEM with this idea: the string contains HTML (links)
> and the <A> tags have TARGETs so between the href info
> and the TARGET attributes, I have a lot of non-displaying
> characters in the string...this won't accomplish my goal of
> displaying equal-sized chunks of text in the small space.
> 
> 2. manually divide up the "answer.txt" strings into paragraphs
> using the <P> and search the string for these, inserting a ">>"
> after each one.
> 
> PROBLEM with this idea: What if one paragraph is long and
> another is short? I suppose then, I am modifying my content
> to suit the needs of my implementation -- sounds kinda ass-
> backwards to me. 
> 
> I'm sure there are other ideas on how to do this but these are
> the two that jumped out at me.
> 
> -sry
> ----------------------------------------------------------------------
> Sarah R. Yoffa
> http://www.sarahryoffa.com/
> sryBoston at hotmail.com
> "Stupid rules are meant to be changed, not broken."
>       [-sry on sci.space.shuttle, c. 1993]
> ----------------------------------------------------------------------
 



More information about the talk mailing list