For Webmasters |
|
ru | |||||||
For Webmasters2. ButtonsLet's see now how to work with buttons. For example, we need to show the Lives of Saints on May 1, 2008 and April 2, 2009 when we click on the button: Example 2.1. The top half of HTML is the same as in previous examples - we have references to the loadCalendar.js scrip, Style Sheet and script to manage pop up window. Code for the May button will be: <button onclick="loadCalendar2(5,1,2008,1,1,3,0,0)">May 1, 2008</button> First 3 parameters of loadCalendar2 is Month, Day and Year which is May 1, 2008. 4th parameter allows output of today's day in format Gregorian/Julian. 5th parameter allows output of Calendar's header. Then 6th parameter says output only Lives of major Saints in separate paragraphs. 7th parameter disallows output of the Scripture Readings and 8th parameter disallows output of Troparion. Code for April button is: <button onclick="loadCalendar2(4,2,2009,1,1,3,0,0)">April 2, 2009</button> In Example 2.2 we can see how to create a button to show today's Lives of Saints and Scripture Readings. Code is: <button onclick="todayDate()">Today</button> When you click on the button it calls todayDate function which looks like JavaScipt in Example 1.2:
Let's do "tomorrow" button. See Example 2.3. In order to do this we need calculate tomorrow's day by adding one day to today. We are going to use the getTime() method to calculate next day. The getTime() method returns the number of milliseconds since midnight of January 1, 1970. In one day we have 24*60*60*1000 milliseconds: 24 hour * 60 minutes * 60 seconds * 1000 milliseconds. Tomorrow's day will be: var today=new Date(); // Get
today's date Now we can write another function tomorrowDate() to calculate and call the calendar:
Based on Example 2.3 we can create the "next day" button. See Example 2.4. We need create variable global to both functions todayDate() and nextdayDate(): var currentDay = new Date(); Then at the and of each function we will assign the calculated day to this variable. In todayDate() function it will be: currentDay = today; and in nextdayDate() function it will be: currentDay = next; The nextdayDate() will be:
Functions todayDate() and nextdayDate() have common HTML code to call Orthodox Calendar. Let's optimize code in Example 2.5: <script type="text/Javascript"> Now it is easy to create "previous day" button. We will write another function previousDate() based on nextdayDate(). Just change plus sign to minus and change variable name next to previous: function previousDate() { Let's add "previous day" button before today day button: <button onclick="previousDate()">Previous Day</button> You can see results in Example 2.6 or Example 2.7.
|
|||||||||
| O Most Holy Trinity, Our God, Glory to Thee! |
|||||||||