vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Trimming thread title at end of a cell rather than at specific number of characters (https://vborg.vbsupport.ru/showthread.php?t=201747)

sparklywater 01-14-2009 01:37 PM

Trimming thread title at end of a cell rather than at specific number of characters
 
I am currently using a function which trims the thread title automatically after a specified number of characters in the title. Since the thread-title is displayed in a table-cell with a percentage width, the cell automatically expands depending on the size of the screen. I would therefore like to use a function that will trim the thread-title whenever the title reaches the end of the cell, rather than at a fixed position after a certain number of characters. How can I do this?

Here is the code to the current function:

Code:

if (strlen($row['thread_title']) > $vbulletin->options['latest_trim'])
      {
                // adds the cutoff ... with fetch_trimmed_title
            $row['thread_title'] = fetch_trimmed_title($row['thread_title'], $vbulletin->options['latest_trim'], true);
      }


Lynne 01-14-2009 01:42 PM

You can't do that. Every browser renders a page differently and the table cell width is very often dependent and other table cell widths also. There is no way to figure out what the width of the cell is going to be prior to it being rendered. And even then, sometimes you see it expand/contract right before your eyes.

Bellardia 01-14-2009 04:46 PM

Only way to do this is with javascript.
PHP is static, you can't change how something looks after the page loads.

sparklywater 01-14-2009 06:48 PM

Quote:

Originally Posted by Bellardia (Post 1712285)
Only way to do this is with javascript.
PHP is static, you can't change how something looks after the page loads.

Any idea what javascript I can use?

thanks.

Dismounted 01-15-2009 04:01 AM

Quote:

Originally Posted by Bellardia (Post 1712285)
Only way to do this is with javascript.
PHP is static, you can't change how something looks after the page loads.

However, I don't think you can fetch the width of a displayed cell in Javascript. The width as defined in the source code may be fetchable, but the width (in pixels) that it is currently displayed cannot.

sparklywater 01-15-2009 06:45 AM

Quote:

Originally Posted by Dismounted (Post 1712918)
However, I don't think you can fetch the width of a displayed cell in Javascript. The width as defined in the source code may be fetchable, but the width (in pixels) that it is currently displayed cannot.

Well, it doesn't necessarily have to determine the width of the cell in pixels. I was wondering if there is a function which can determine when a text is flowing onto a new line, because this is what happens when the text hits the end of a cell, it moves onto a new line on the screen. So there won't be any need to work out the width of the cell. If a function can tell that the width of the cell has caused the text to flow onto another line, it can trim the string at that point to make it fit on one line.

Not sure if this is too much to ask, but may be possible somehow.


All times are GMT. The time now is 11:59 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02652 seconds
  • Memory Usage 1,732KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete