Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:51

is new item notice possible?


Poster: Ruth
Dated: Monday December 29 2003 - 12:46:06 GMT

There's a javascript I used to use to show that an item put on the site was new
Code:
<HEAD><SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function checknew(date) {
var pic = "http://www.your-web-site-address-here.com/where-you-put-it/new.gif";
expdate = new Date(date);
curdate = new Date();
if (expdate.getTime() > curdate.getTime())
document.write("<img src=" + pic + ">");
}
// End -->
</script>
</HEAD>
<BODY>

<script> checknew("6/01/2000") </script>Shown as "New" until 6/01/2000<br>
<script> checknew("12/01/2000") </script>Shown as "New" until 12/01/2000<br>
<script> checknew("6/01/2001") </script>Shown as "New" until 6/01/2001<br>
<script> checknew("12/01/2001") </script>Shown as "New" until 12/01/2001<br></body>
Let's say I did tutorials and put a new one up, is there a way to put something in the menu so the link would show 'new' for a specified time?
Ruth


Poster: kevin3442
Dated: Wednesday December 31 2003 - 17:33:15 GMT

Hi Ruth,

You could slightly modify your current function, then use it to help construct the argument to the aI() function that builds the menu item in question.

The checkNew() function:
Code:
function checkNew(date)
{
  var appendToItem = "";
  expdate = new Date(date);
  curdate = new Date();
  if (expdate.getTime() > curdate.getTime()) {
    appendToItem = "image=thePath/new.gif;imagealign=left;imagealt=new item!;";
  }
  return appendToItem;
}

Note that you can add any of the 'image' modifying menu item properties in the last part of the assignment to appendToItem; e.g., add imageheight, imagewidth, imageposition, etc.

How to use checkNew() in aI() when building a menu item:
Code:
aI("text=Item Text;url=whatever.htm;" + checkNew('1/05/2004'));

If the expiration date has not been reached, then checkNew() returns additional information to be appended to the string passed to aI(). If the expiration date has been reached, checkNew() does not return any additional information for the menu item.

One thing to consider... doing this through client-side scripting will increase the amount of time it takes to build the menu, for each page that the user visits. The increase may become noticable if you have a lot of items that use this function. Each time the function is called, it adds more time to building the menu, even if the item is expired (because the function is still called). So, it'd be prudent to go through your menu code now and then and get rid of the function call for long-expired items.

Hope that makes sense ;) -- You know... I kind of like your idea of automatically expiring new items... I might just have to borrow it!

Cheers,

Kevin


Poster: Ruth
Dated: Wednesday December 31 2003 - 18:48:22 GMT

Being code illiterate....I should use the first part you gave as the function in the same place the other code told me to put that, in the head of the document? The second part I see goes in the menu. And, you are welcome to use it...lol, I think I found it at javascript source....the only kinds i know how to use, since they have detailed instructions about where to put each thing :roll: . And, don't laugh, but a suggestion, about the going through and updating to remove really out of date expired ones, couldn't you..since you seem to know how to write functions, modify it to get it to remove it's own use after the expiration date? ....not sure since I don't really know what these things are doing.
Ruth


Poster: kevin3442
Dated: Wednesday December 31 2003 - 19:57:43 GMT

Hi Ruth,
innkeeper9 wrote:
...I should use the first part you gave as the function in the same place the other code told me to put that, in the head of the document?

Probably, it would be most convenient to put the function definition right at the top of your menu_data.js file.
Quote:
The second part I see goes in the menu.

To paraphrase Johnny Carson, "You are correct ma'am."
Quote:
...And, don't laugh, but a suggestion, about the going through and updating to remove really out of date expired ones, couldn't you...modify it to get it to remove it's own use after the expiration date?

:| - (This is me not laughing.) It would be nice, but the only way I could think of to do something like that efficiently would be with server-side scripting, which I don't think you're doing. In fact, if you were using server-side scripting, you could use it to accomplish the expiration functionality with no additional overhead on the client. But don't worry about it too much, the slowdown wouldn't be noticable unless you had a TON of new/expired items, and I doubt your menu would get that large... I probably shouldn't have even mentioned it.

I uploaded the example I used to test. To see it, download mm_timedNew.zip, unzip the file to a new folder, and copy your latest milonic_src.js, mmenudom.js, and mmenuns4.js files into the same folder. To see it in action, open menu.htm. You'll find the function definition in menu_data.js.

Hope that helps,

Kevin