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