PDA

View Full Version : need to modify an alert popup in a specific dates & times



mub2
10-13-2006, 03:47 PM
I used a javascript made by jscheuer1 in this forum (here (http://www.dynamicdrive.com/forums/showthread.php?t=3810))
It is realy perfect.
Is it possible to add to it the same hours events in sevral days of the year,
let say :
jan 4
jan 14
feb 12
feb 16
june 16
So I don't have to update it.
the script I used is :

<script type="text/javascript">
function breakTime(){ // <<< do not edit or remove this line!
/* Set Break Hours in 24hr Notation */
var breakHour=[8, 11, 14, 17, 18]
/* Set Break Minutes */
var breakMinute=[30, 30, 10, 20, 30]
/* Set Break Messages */
var breakMessage=["test1", "test2", "test3", "test4", "test5"]
///////////////////No Need to Edit//////////////
var theDate=new Date()
for (i = 0; i < breakHour.length; i++)
if (Math.abs(theDate.getHours())==breakHour[i]&&Math.abs(theDate.getMinutes())==breakMinute[i]){
window.focus();
clearInterval(breakInt)
alert(breakMessage[i])
if (i<breakHour.length-1)
setTimeout("breakInt=setInterval('breakTime()',58000)",120000)
}
}
var breakInt=setInterval("breakTime()",58000)
////////////////////////////////////////////////
</script>

thanks

jscheuer1
10-14-2006, 08:18 AM
I'm not clear on what you are asking or if you realize that the script is for a closed environment, not the internet. If the alerts aren't critically important, an open environment like the internet would be OK. If you only want the alerts on certain dates - not on others, that could be added. Or if you only want certain alerts on certain dates, that could be done as well. If I knew more of the specifics I could be of more help.

mub2
10-14-2006, 03:37 PM
I'm using it in my site to remind my visitors of several events of the day,
and in sevral day of the year.
your script was very helpfull for me and my visitors.
But I have to update the time evry other day.
I just want to add the dates to the script but I don't know how!
Is it possible to add to it the date of the month, like I mentioned above:
jan 4
jan 14
feb 12
feb 16
june 16
each date have sevral breaktime.
thanks in advance for your kind help.

jscheuer1
10-15-2006, 02:57 PM
The configuration on this is a bit complex. Fortunately, much of any given date's data is optional. Here is a typical date entry with all possible data included:


/*October*/ special_dates[10]=[];
special_dates[10][15]=['Oct. 15th!', 'Did you see the leaves?', 'Do anything interesting last night?', 'Yo!'];
special_dates[10][15].breakHour=[9, 9, 9, 9];
special_dates[10][15].breakMinute=[41, 44, 47, 50];
special_dates[10][15].breakDay=1;

The month declaration is required only if there are any special dates in that month. Any given month should only be declared once. As many special dates for that month as are desired may be added once it has been declared.

The:


special_dates[month#][date#]=[message strings];

sets the alert messages for that date and is required for any customization of that date.

The:


special_dates[month#][date#].breakHour=[hours];

is required only if the breakHour times for that date are different than the defaults.

The:


special_dates[month#][date#].breakMinute=[minutes];

is required only if the breakMinute times for that date are different than the defaults.

The:


special_dates[month#][date#].breakDay=#;

is required only if the special_dates[month#][date#] must fall on a certain day of the week to be used. 1 = Sunday, 2= Monday . . . 7=Saturday.

One important note: Wherever they are used, the number of entries in breakHour, breakMinute and the number of message string entries should all be the same. For example, if you have 3 messages, and are using the optional hours, you need three hour entries. If no optional hours or minutes are used, the number of special messages should equal the default number of messages, hours and minutes. The script will error check and degrade gracefully if you ignore this but, the result will be that some messages may not get shown as alerts.

Here is the script with a few more example 'special_dates':


<script type="text/javascript">

/*Timely Alerts script John Davenport Scheuer
*as first seen in http://www.dynamicdrive.com/forums
*username: jscheuer1
*This notice must remain for legal use */

// Configure optional special dates:
var special_dates=[]; // <<< do not edit or remove this line!
/*January*/ special_dates[1]=[];
special_dates[1][1]=['Happy New Year!', 'Did you see the parade?', 'Do anything you regret last night?', 'Better get to bed early tonight'];
special_dates[1][1].breakHour=[0, 12, 17, 21];
special_dates[1][1].breakMinute=[0, 30, 30, 30];
/*May*/ special_dates[5]=[];
special_dates[5][25]=['Must be getting near Memorial Day', 'Aren\'t the flowers nice?', 'Is the pollen bothering you?'];
/*October*/ special_dates[10]=[];
special_dates[10][15]=['Oct. 15th!', 'Did you see the leaves?', 'Do anything interesting last night?', 'Yo!'];
special_dates[10][15].breakHour=[9, 9, 9, 9];
special_dates[10][15].breakMinute=[41, 44, 47, 50];
special_dates[10][15].breakDay=1;
special_dates[10][31]=['Happy Halloween!', 'Boo!', 'Don\'t eat too much candy!'];

function breakTime(){ // <<< do not edit or remove this line!
/* Set Default Break Hours in 24hr Notation */
var breakHour=[8, 12, 17];
/* Set Default Break Minutes */
var breakMinute=[30, 30, 30] ;
/* Set Default Break Messages */
var breakMessage=["Good Morning!", "Lunch Time!", "Good Evening!"];
///////////////////No Need to Edit//////////////
var theDate=new Date(), mo=theDate.getMonth()*1+1, dt=theDate.getDate()*1, dy=theDate.getDay()*1+1;
if ((special_dates[mo]&&special_dates[mo][dt]&&special_dates[mo][dt].breakDay&&special_dates[mo][dt].breakDay==dy)||(special_dates[mo]&&special_dates[mo][dt]&&!special_dates[mo][dt].breakDay)){
breakMessage=special_dates[mo][dt];
breakHour = special_dates[mo][dt].breakHour? special_dates[mo][dt].breakHour : breakHour;
breakMinute = special_dates[mo][dt].breakMinute? special_dates[mo][dt].breakMinute : breakMinute;
}
for (var i = 0; i < breakHour.length; i++)
if (breakHour[i]&&breakMinute[i]&&breakMessage[i]&&theDate.getHours()*1==breakHour[i]&&theDate.getMinutes()*1==breakMinute[i]){
window.focus();
clearInterval(breakInt)
alert(breakMessage[i])
if (i<breakHour.length-1&&i<breakMinute.length-1&&i<breakMessage.length-1)
setTimeout("breakInt=setInterval('breakTime()',58000)",120000)
}
}
var breakInt=setInterval("breakTime()",58000)
////////////////////////////////////////////////
</script>

mub2
10-16-2006, 12:59 AM
Thank you very much for solving my problem.
I will cusomize it to my needs and translate it to arabic if its possible.

May I have your permission to distribute it for free to arabic language sites
with your name and copyright remain in the script like this:

/*Timely Alerts script &#169; John Davenport Scheuer
*as first seen in http://www.dynamicdrive.com/forums
*username: jscheuer1
*This notice must remain for legal use */

your help is much appreciated.
Khaled Almubailesh
from Kuwait

jscheuer1
10-16-2006, 03:50 AM
May I have your permission to distribute it for free to arabic language sites
with your name and copyright remain in the script like this:

/*Timely Alerts script John Davenport Scheuer
*as first seen in http://www.dynamicdrive.com/forums
*username: jscheuer1
*This notice must remain for legal use */

You're welcome, and sure, it may be distributed anywhere for free, just like the official Dynamic Drive scripts, as long as the credit remains.