1/** 2 * GCalendar Holidays - Googleã«ã¬ã³ãã¼ããæ¥æ¬ã®ç¥æ¥ãåå¾ 3 * @see http://0-oo.net/sbox/javascript/google-calendar-holidays 4 * @version 0.4.0 5 * @copyright 2008-2011 [email protected] 6 * @license http://0-oo.net/pryn/MIT_license.txt (The MIT license) 7 * 8 * See also 9 * @see http://code.google.com/intl/ja/apis/calendar/data/2.0/reference.html 10 * @see http://code.google.com/intl/ja/apis/gdata/docs/json.html 11 */ 12 13var GCalHolidays = { 14 /** Googleã«ã¬ã³ãã¼ã®IDï¼è¤æ°ã§ãå¯ï¼ */ 15 userIds: [ 16 "[email protected]" //Googleå ¬å¼ç 17 //"[email protected]" //Googleå ¬å¼ï¼è±èªï¼ç 18 //"[email protected]" //mozilla.orgç 19 ], 20 21 /** åå¾ããã¤ãã³ãï¼ã¹ã±ã¸ã¥ã¼ã«ï¼ã®æå¤§ä»¶æ° */ 22 maxResults: 31, 23 24 // @see http://code.google.com/intl/ja/apis/calendar/data/2.0/reference.html#Visibility 25 visibility: "public", 26 27 // @see http://code.google.com/intl/ja/apis/calendar/data/2.0/reference.html#Projection 28 projection: "full-noattendees", 29 30 /** jQuery UI Datepickerç¨ã®styleï¼Themeã«åããã¦ã好ã¿ã§ä¸æ¸ããã¦ä½¿ãï¼ */ 31 datepickerStyles: { 32 sunday: "background-image: none; background-color: #f99", //æ¥ææ¥ 33 saturday: "background-image: none; background-color: #6cf", //åææ¥ 34 holiday: "background-image: none; background-color: #f9f" //ç¥æ¥ 35 } 36}; 37/** 38 * ç¥æ¥ãåå¾ãã 39 * @param Function callback ãã¼ã¿å徿ã«å¼ã³åºãããfunction 40 * @param Number year (optional) å¹´ï¼æå®ããªããã°ä»å¹´ï¼ 41 * @param Number month (optional) æï¼1ï½12 æå®ããªããã°1å¹´ã®å ¨ã¦ï¼ 42 */ 43GCalHolidays.get = function(callback, year, month) { 44 //æ¥ä»ç¯å² 45 var padZero = function(value) { return ("0" + value).slice(-2); }; 46 var y = year || new Date().getFullYear(); 47 var start = [y, padZero(month || 1), "01"].join("-"); 48 var m = month || 12; 49 var end = [y, padZero(m), padZero(new Date(y, m, 0).getDate())].join("-"); 50 51 this._caches = (this._caches || {}); 52 this._userCallback = callback; 53 54 for (var i = 0, len = this.userIds.length; i < len; i++) { 55 var cache = this._caches[i + ":" + start + ".." + end]; 56 57 if (cache) { //å徿¸ã¿ã®å ´åã¯ããã使ã 58 callback(cache, i); 59 continue; 60 } 61 62 //URL使 63 var url = location.protocol + "//www.google.com/calendar/feeds/"; 64 url += encodeURIComponent(this.userIds[i]) + "/"; 65 url += this.visibility + "/" + this.projection; 66 url += "?alt=json-in-script&callback=GCalHolidays.decode"; 67 url += "&max-results=" + this.maxResults; 68 url += "&start-min=" + start + "&start-max=" + end + "T23:59:59"; 69 70 //scriptã¿ã°çæ 71 var script = document.createElement("script"); 72 script.type = "text/javascript"; 73 script.src = url; 74 script.charset = "UTF-8"; 75 document.body.appendChild(script); 76 } 77}; 78/** 79 * JSONPã«ããGoogle Calendar APIçµç±ã§å¼ã³åºãããfunction 80 * @param Object gdata ã«ã¬ã³ãã¼ãã¼ã¿ 81 */ 82GCalHolidays.decode = function(gdata) { 83 var days = GCalHolidays._entries2days(gdata.feed.entry); 84 85 var links = gdata.feed.link; 86 var href = ""; 87 88 for (var j = 0, len2 = links.length; j < len2; j++) { 89 if (links[j].rel == "self") { 90 href = links[j].href; 91 } 92 } 93 94 var userId = decodeURIComponent(href.split("/")[5]); 95 var index = null; 96 97 //ã©ã®ã«ã¬ã³ãã¼ãç¹å®ãã 98 for (var i = 0, len = this.userIds.length; i < len; i++) { 99 if (this.userIds[i] == userId) { 100 index = i; 101 break; 102 } 103 } 104 105 //ãã£ãã·ã¥ãã 106 var range = href.match(/\d{4}-\d{2}-\d{2}/g); //æ¥ä»ç¯å²ã®æåã®æ¥ã¨æå¾ã®æ¥ 107 this._caches[index + ":" + range[0] + ".." + range[1]] = days; 108 109 //ã³ã¼ã«ãã㯠110 this._userCallback(days, index); 111}; 112/** 113 * JSONPã§åå¾ãããã¼ã¿ããæ¥ä»æ å ±ãåãåºã 114 * @param Array entries ã¹ã±ã¸ã¥ã¼ã« 115 * @return Array æ¥ä»æ å ±ï¼year, month, date, titleï¼ 116 */ 117GCalHolidays._entries2days = function(entries) { 118 var days = []; 119 120 if (!entries) { 121 return days; 122 } 123 124 //æ¥ä»é ã«ã½ã¼ã 125 entries.sort(function(a, b) { 126 return (a.gd$when[0].startTime > b.gd$when[0].startTime) ? 1 : -1; 127 }); 128 129 //ã·ã³ãã«ãªå¨ã«ç§»ã 130 for (var i = 0, len = entries.length; i < len; i++) { 131 var ymd = entries[i].gd$when[0].startTime.split("T")[0].split("-"); 132 var title = entries[i].title.$t; 133 //å¹´ææ¥ã¯ä½¿ããããããã«æ°å¤ã«ãã 134 days[i] = { year: ymd[0] * 1, month: ymd[1] * 1, date: ymd[2] * 1, title: title }; 135 } 136 137 return days; 138}; 139 140/** 141 * jQuery UI Datepickerã®ã«ã¬ã³ãã¼ã«ç¥æ¥ã表示ãã 142 * @param Number year 表示ããå¹´ 143 * @param Number month 表示ããæ 144 * @param Object inst Datepicker 145 * @see http://jqueryui.com/demos/datepicker/ 146 */ 147GCalHolidays.datepicker = function(year, month, inst) { 148 setTimeout(function() { //å¦çå¾ã«å¯¾è±¡ã®divãåæ§ç¯ãããã±ã¼ã¹ãåé¿ 149 GCalHolidays.get(function(holidays) { 150 for (var i = 0, len = holidays.length; i < len; i++) { 151 var holiday = holidays[i]; 152 153 if (holiday.year != year || holiday.month != month) { 154 return; //æ¢ã«å¥ã®æã表示ãã¦ããå ´åã¯ä½ãããªã 155 } 156
157 inst.dpDiv.find("a").each(function() { 158 if ($(this).text() == holiday.date) { 159 $(this).addClass("gcal-holiday").attr("title", holiday.title); 160 return false; 161 } 162 }); 163 } 164 }, year, month); 165 }, 1); 166}; 167/** 168 * jQuery UI Datepickerãæå¹ãªå ´åã¯ã¤ãã³ããã³ãã©ã¨styleãã»ãããã 169 */ 170if (window.$ && $.datepicker && $.datepicker.setDefaults) { 171 $.datepicker.setDefaults({ 172 beforeShow: function(input, inst) { 173 var date = $(input).datepicker("getDate") || new Date(); 174 GCalHolidays.datepicker(date.getFullYear(), date.getMonth() + 1, inst); 175 }, 176 beforeShowDay: function(date) { //忥ã®class屿§ 177 return [true, { 0: "gcal-sunday", 6: "gcal-saturday" }[date.getDay()] || ""]; 178 }, 179 onChangeMonthYear: GCalHolidays.datepicker 180 }); 181 182 $(function() { //ãã¼ã¸è¡¨ç¤ºå¾ã«åæ¥ã»ç¥æ¥ç¨ã®styleãã»ãã 183 var styles = GCalHolidays.datepickerStyles; 184 var css = ""; 185 css += ".gcal-sunday .ui-state-default { " + styles.sunday + " } "; 186 css += ".gcal-saturday .ui-state-default { " + styles.saturday + " } "; 187 css += ".ui-widget-content .gcal-holiday { " + styles.holiday + " }"; 188 $("head").append($('<style type="text/css">' + css + "</style>")); 189 }); 190}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.