rejetto forum

in list,how to display the file if %item-name% is a jpg/gif?

0 Members and 1 Guest are viewing this topic.

Offline vervethe

  • Occasional poster
  • *
    • Posts: 6
    • View Profile
in list,how to display the file if file is a jpg/gif?
in Template,[file] section,default code is
Code: [Select]
[file]
<tr><td class=row>%new% <a href="%item-url%"><img align=top src="/~img_file"> %item-name%</a>%comment%<td class="row right">%item-size%<td class="row right">%item-modified%<td class="row right">%item-dl-count%
i want to check %item-name%,if the file is a jpg or gif,then display the file  instead of “/~img_file”.how to write the [file] section code?
rc.263.net----vervethe.*
qq12936867


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i think it can be done with javascript
will someone spend a little time doing it? :)



Anonymous

  • Guest
Code: [Select]
<script language="jscript">

if (  '%item-name%'.match(/(\.jpg)|(\.gif)$/i)  )
document.write('<tr><td class=row>%new% <a href="%item-url%"><img align=top src="%item-url%"> %item-name%</a>%comment%<td class="row right">%item-size%<td class="row right">%item-modified%<td class="row right">%item-dl-count%');
else
document.write('<tr><td class=row>%new% <a href="%item-url%"><img align=top src="/~img_file"> %item-name%</a>%comment%<td class="row right">%item-size%<td class="row right">%item-modified%<td class="row right">%item-dl-count%');

</script>


Offline vervethe

  • Occasional poster
  • *
    • Posts: 6
    • View Profile
also:

Code: [Select]
[file]
<tr><td class=row>%new% <a href="%item-url%">
<script language="jscript">
if (  '%item-name%'.match(/\.(jpg)|(gif)|(png)$/i)  ) document.write('<img align=top src="%item-url%"> ');
else if (  '%item-name%'.match(/\.wav$/i)  ) document.write('<img align=top src="/imgs/sound.gif"> ');
else if (  '%item-name%'.match(/\.dll$/i)  ) document.write('<img align=top src="/imgs/dll_13[].gif"> ');
else if (  '%item-name%'.match(/\.m4a$/i)  ) document.write('<img align=top src="/imgs/leaf_G_13[].gif"> ');
else if (  '%item-name%'.match(/\.doc$/i)  ) document.write('<img align=top src="/imgs/paper_13[].gif"> ');
else if (  '%item-name%'.match(/\.lrc$/i)  ) document.write('<img align=top src="/imgs/Icon47_13[].gif"> ');
else if (  '%item-name%'.match(/\.txt$/i)  ) document.write('<img align=top src="/imgs/txt__13[].gif"> ');
else if (  '%item-name%'.match(/\.url$/i)  ) document.write('<img align=top src="/imgs/Pointer_or_url__13[].gif"> ');
else if (  '%item-name%'.match(/\.htm$/i)  ) document.write('<img align=top src="/imgs/net doc_13[].gif"> ');
else if (  '%item-name%'.match(/\.exe$/i)  ) document.write('<img align=top src="/imgs/runnerA_13[].gif"> ');
else if (  '%item-name%'.match(/\.(zip)|(rar)$/i)  ) document.write('<img align=top src="/imgs/ar_11_8_13[]_orange.gif"> ');
else if (  '%item-name%'.match(/\.ini$/i)  ) document.write('<img align=top src="/imgs/ini__13[].gif"> ');
else document.write('<img align=top src="/~img_file"> ');
</script>
%item-name%</a>%comment%<td class="row right">%item-size%<td class="row right">%item-modified%<td class="row right">%item-dl-count%
rc.263.net----vervethe.*
qq12936867


Offline vervethe

  • Occasional poster
  • *
    • Posts: 6
    • View Profile
but contructing regular express is slow.

this is better:
Code: [Select]
<tr><td class=row>%new% <a href="%item-url%">
<script language="jscript">
var c='%item-name%';
switch (  c.substr(  c.lastIndexOf('.')  ) .toLowerCase()  )
{
case '.txt' : document.write('<img align=top src="/imgs/txt__13[].gif"> ');break;
case '.htm' : case '.html' : document.write('<img align=top src="/imgs/net doc_13[].gif"> ');break;
case '.url' : case '.lnk' : document.write('<img align=top src="/imgs/Pointer_or_url__13[].gif"> ');break;
case '.exe' : case '.com' : document.write('<img align=top src="/imgs/runnerA_13[].gif"> ');break;
case '.dll' : document.write('<img align=top src="/imgs/dll_13[].gif"> ');break;
case '.zip' : case '.rar' : document.write('<img align=top src="/imgs/ar_11_8_13[]_orange.gif"> ');break;
case '.jpg' :case '.jpeg': case '.gif' : case '.png' :case '.ico':case '.bmp': document.write('<img align=top src="%item-url%"> ');break;
case '.wav':case '.aiff':case '.au':case '.cda':case '.ape': document.write('<img align=top src="/imgs/sound.gif"> ');break;
case '.m4a' : case '.mp4' : case '.aac' : document.write('<img align=top src="/imgs/leaf_G_13[].gif"> ');break;
case '.ogg':case '.wma':case '.mp3':case '.ra':case '.mpc': document.write('<img align=top src="/imgs/leaf.gif"> ');break;
case '.mid' : document.write('<img align=top src="/imgs/bowstr_13[].gif"> ');break;
case '.wmv':case '.rm':case '.rmvb':case '.avi':case '.dat': document.write('<img align=top src="/imgs/screen_9_6_13[].gif"> ');break;
case '.doc' : document.write('<img align=top src="/imgs/paper_13[].gif"> ');break;
case '.lrc' : document.write('<img align=top src="/imgs/Icon47_13[].gif"> ');break;
case '.ini' : case '.inf' : document.write('<img align=top src="/imgs/ini__13[].gif"> ');break;
case '.js':case '.vbs': document.write('<img align=top src="/imgs/winScript_13[].gif"> ');break;
case '.fnd': document.write('<img align=top src="/imgs/searCH.gif"> ');break;
case '.sf2':case '.akp':case '.exs':case '.fxp':case '.sxt':case '.nki': document.write('<img align=top src="/imgs/guitar_13[].gif"> ');break;
default : document.write('<img align=top src="/~img_file"> ');
}
</script>
%item-name%</a>%comment%<td class="row right">%item-size%<td class="row right">%item-modified%<td class="row right">%item-dl-count%
rc.263.net----vervethe.*
qq12936867


Anonymous

  • Guest
better use
<script language="javascript">

rather than
<script language="jscript">

works in mozilla based, then.
Thank you for this, real good work!