⬆️ ⬇️

Extending the iCal widget on Mac OS X

On Habré an article was recently published on how to write widgets for Mac OS X Dashboard.



Let's use the knowledge gained in order to teach the standard dashboard calendar to show non-working days and holidays.







Widget sources are located in the /Library/Widgets/iCal.wdgt directory. Find in the Calendar.css file the design of the days of the month (normal, “muffled”, highlighted) and add a style for non-working days; by analogy with the existing ones, let's call it .calendar-dayOfMonthNumberHoliday .

')

The easiest way is to make a copy-paste of the standard style, but for reasons of aesthetics I reissued the code as follows:



.calendar-dayOfMonthNumberNormal, .calendar-dayOfMonthNumberHoliday, .calendar-dayOfMonthNumberDimmed, .calendar-dayOfMonthNumberHighlighted { float: left; position: relative; left: 3px; width: 16px; padding-right: 0px; border-right: 7px solid transparent; margin-top: 0px; text-align: right; } .calendar-dayOfMonthNumberNormal { color: white; } .calendar-dayOfMonthNumberHoliday { color: rgb(255,102,51); } .calendar-dayOfMonthNumberDimmed { color: rgb(51,51,51); } .calendar-dayOfMonthNumberHighlighted { color: rgb(204,255,0); } 


Now add to the Calendar.js file a list of holidays and weekends of 2012 (in accordance with the production calendar calend.ru ), as well as the function of checking for "holiday":



 var holidays = [ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15, 21, 22 ], [ 4, 5, 11, 12, 18, 19, 23, 25, 26 ], [ 3, 4, 8, 9, 10, 17, 18, 24, 25, 31 ], [ 1, 7, 8, 14, 15, 21, 22, 29, 30 ], [ 1, 6, 7, 8, 9, 13, 19, 20, 26, 27 ], [ 2, 3, 10, 11, 12, 16, 17, 23, 24, 30 ], [ 1, 7, 8, 14, 15, 21, 22, 28, 29 ], [ 4, 5, 11, 12, 18, 19, 25, 26 ], [ 1, 2, 8, 9, 15, 16, 22, 23, 29, 30 ], [ 6, 7, 13, 14, 20, 21, 27, 28 ], [ 3, 4, 5, 10, 11, 17, 18, 24, 25 ], [ 1, 2, 8, 9, 15, 16, 22, 23, 30, 31 ] ]; function isHoliday(month, dayOfMonth) { return holidays[month].indexOf(dayOfMonth) != -1; } 


It remains to correct one line in the drawGrid function, which exposes the class for a number:



 dateSpan.setAttribute ("class", isHoliday(ourMonth, date) ? "calendar-dayOfMonthNumberHoliday" : "calendar-dayOfMonthNumberNormal"); 


In order for the changes to take effect, you must remove the widget from the dashboard and add it again. By the way, if you need to frequently look at the result in the development process, a new copy of the widget can be run directly from the Finder or from the terminal (open /Library/Widgets/iCal.wdgt).



You will ask: “If everything is so simple with these widgets, why do many sites not even think about what they can provide? For example, Gismeteo ? Good question. In many ways, for his sake, this little article was written.

Source: https://habr.com/ru/post/143303/



All Articles