jsCalendar.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId])
  10. /******/ return installedModules[moduleId].exports;
  11. /******/
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // identity function for calling harmony imports with the correct context
  37. /******/ __webpack_require__.i = function(value) { return value; };
  38. /******/
  39. /******/ // define getter function for harmony exports
  40. /******/ __webpack_require__.d = function(exports, name, getter) {
  41. /******/ if(!__webpack_require__.o(exports, name)) {
  42. /******/ Object.defineProperty(exports, name, {
  43. /******/ configurable: false,
  44. /******/ enumerable: true,
  45. /******/ get: getter
  46. /******/ });
  47. /******/ }
  48. /******/ };
  49. /******/
  50. /******/ // getDefaultExport function for compatibility with non-harmony modules
  51. /******/ __webpack_require__.n = function(module) {
  52. /******/ var getter = module && module.__esModule ?
  53. /******/ function getDefault() { return module['default']; } :
  54. /******/ function getModuleExports() { return module; };
  55. /******/ __webpack_require__.d(getter, 'a', getter);
  56. /******/ return getter;
  57. /******/ };
  58. /******/
  59. /******/ // Object.prototype.hasOwnProperty.call
  60. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  61. /******/
  62. /******/ // __webpack_public_path__
  63. /******/ __webpack_require__.p = "";
  64. /******/
  65. /******/ // Load entry module and return exports
  66. /******/ return __webpack_require__(__webpack_require__.s = 2);
  67. /******/ })
  68. /************************************************************************/
  69. /******/ ([
  70. /* 0 */
  71. /***/ (function(module, exports, __webpack_require__) {
  72. // calendar with 8 column x 7 rows
  73. var labels = __webpack_require__(3);
  74. function isIterable(variable){
  75. if (variable == null) return false;
  76. if (variable.constructor === Array) return true;
  77. if (variable.constructor === Object) return true;
  78. return false;
  79. }
  80. function merge(_new, _old){
  81. for (var prop in _new){
  82. if (!_old[prop]) _old[prop] = _new[prop];
  83. else if (isIterable(_new[prop])) merge(_new[prop], _old[prop]);
  84. }
  85. }
  86. function addLabels(dayObject, lang){
  87. var cssClass = [labels.classes[dayObject.type]];
  88. if (dayObject.class) dayObject.class = (typeof dayObject.class == 'string' ? [dayObject.class] : dayObject.class).concat(cssClass);
  89. else dayObject.class = cssClass;
  90. if (dayObject.type.indexOf('Label') > 0){
  91. if (dayObject.index == 0 && labels.weekPlaceholder) dayObject.desc = labels.weekPlaceholder;
  92. else if (dayObject.index < 8) dayObject.desc = labels.columnNames[lang][dayObject.index];
  93. else if (dayObject.index % 8 == 0) dayObject.desc = dayObject.week;
  94. }
  95. if (dayObject.date) dayObject.monthName = labels.monthNames[lang][dayObject.date.getMonth()];
  96. if (!this.monthName) this.monthName = labels.monthNames[lang][this.month];
  97. if (!this.labels) this.labels = {
  98. monthNames: labels.monthNames[lang],
  99. columnNames: labels.columnNames[lang],
  100. classes: labels.classes
  101. }
  102. return dayObject;
  103. }
  104. addLabels.setLabels = function(newOptions){
  105. merge(newOptions, labels);
  106. };
  107. module.exports = addLabels;
  108. /***/ }),
  109. /* 1 */
  110. /***/ (function(module, exports) {
  111. // calendar with 8 column x 7 rows
  112. var oneDay = 1000 * 60 * 60 * 24;
  113. function daysInMonth(year, month) {
  114. return new Date(year, month + 1, 0).getDate();
  115. }
  116. function getYear(year, month, weekNr){
  117. if (month == 0 && weekNr > 50) return year - 1;
  118. else if(month == 11 && weekNr < 10) return year + 1;
  119. else return year;
  120. }
  121. function getDateInfo(y, m, d, iso) {
  122. if (m > 11){
  123. m = 0;
  124. y++;
  125. }
  126. var currentDay = new Date(y, m, d);
  127. if (iso) currentDay.setDate(currentDay.getDate() + 4 - (currentDay.getDay() || 7));
  128. var year = iso ? currentDay.getFullYear() : y;
  129. var firstOfJanuary = new Date(year, 0, 1);
  130. var numberOfDays = 1 + Math.round((currentDay - firstOfJanuary) / oneDay);
  131. if (!iso) numberOfDays += firstOfJanuary.getDay();
  132. var w = Math.ceil(numberOfDays / 7);
  133. if (!iso) {
  134. var initialDay = new Date(y, m, d);
  135. var beginOfNextYear = new Date(y + 1, 0, 1);
  136. var startDayOfNextYear = beginOfNextYear.getDay();
  137. if (initialDay.getTime() >= beginOfNextYear.getTime() - (oneDay * startDayOfNextYear)) w = 1;
  138. }
  139. return w;
  140. }
  141. function getMonthCalender(year, month, iteratorFns){
  142. // config passed by binding
  143. var lang = this.lang || 'en';
  144. var onlyDays = this.onlyDays;
  145. var weekStart = typeof this.weekStart == 'undefined' ? 1 : this.weekStart;
  146. var iso = weekStart == 1;
  147. var cells = [];
  148. var monthStartDate = new Date(year, month, 1); // make a date object
  149. var dayOfWeek = monthStartDate.getDay() || (iso ? 7 : 0); // month week day for day 1
  150. var currentDay = weekStart - dayOfWeek; // starting position of first day in the week
  151. var weekNr = getDateInfo(year, month, 1, iso); // get week number of month start
  152. var maxDays = daysInMonth(year, month); // total days in current month
  153. var lastMonthMaxDays = daysInMonth(year, month - 1);
  154. var currentMonth, day, dayBefore;
  155. var currentYear = getYear(year, month, weekNr);
  156. var returnObject = {
  157. month: month,
  158. year: year,
  159. daysInMonth: maxDays
  160. };
  161. for (var i = 0; i < 7; i++){ // 7 rows in the calendar
  162. dayBefore = currentDay;
  163. for (var j = 0; j < 8; j++){ // 8 columns: week nr + 7 days p/ week
  164. if (i > 0 && j > 0) currentDay++; // not first row, not week nr column
  165. if (currentDay > maxDays || currentDay < 1){ // day belongs to sibling month
  166. // calculate day in sibling month
  167. day = currentDay > maxDays ? currentDay - maxDays : lastMonthMaxDays + currentDay;
  168. currentMonth = currentDay > maxDays ? month + 1 : month - 1;
  169. } else {
  170. day = currentDay;
  171. currentMonth = month;
  172. }
  173. var type = (function(){
  174. if (j == 0) return 'weekLabel';
  175. else if (i == 0) return 'dayLabel';
  176. else if (currentDay < 1) return 'prevMonth';
  177. else if (currentDay > maxDays) return 'nextMonth';
  178. else return 'monthDay';
  179. })();
  180. var isDay = dayBefore != currentDay && i > 0;
  181. var dayData = {
  182. desc: isDay ? day : weekNr,
  183. week: weekNr,
  184. type: type,
  185. format: iso ? 'ISO 8601' : 'US',
  186. date: isDay ? new Date(Date.UTC(year, currentMonth, day)) : false,
  187. year: currentYear,
  188. index: cells.length
  189. };
  190. if (iteratorFns){
  191. if (typeof iteratorFns === "function") dayData = iteratorFns.call(returnObject, dayData, lang);
  192. else iteratorFns.forEach(function(fn){
  193. dayData = fn.call(returnObject, dayData, lang);
  194. });
  195. }
  196. if (onlyDays && isDay) cells.push(dayData); // add only days
  197. else if (!onlyDays) cells.push(dayData); // add also week numbers and labels
  198. }
  199. if (i > 0) weekNr = getDateInfo(year, currentMonth, day + 1, iso);
  200. currentYear = getYear(year, month, weekNr);
  201. }
  202. returnObject.cells = cells;
  203. return returnObject;
  204. }
  205. module.exports = function (config){
  206. return getMonthCalender.bind(config);
  207. }
  208. /***/ }),
  209. /* 2 */
  210. /***/ (function(module, exports, __webpack_require__) {
  211. module.exports = {
  212. Generator: __webpack_require__(1),
  213. addLabels: __webpack_require__(0)
  214. }
  215. /***/ }),
  216. /* 3 */
  217. /***/ (function(module, exports) {
  218. module.exports = {
  219. weekPlaceholder: '',
  220. columnNames: {
  221. en: {
  222. 0: 'w',
  223. 1: 'monday',
  224. 2: 'tuesday',
  225. 3: 'wednesday',
  226. 4: 'thursday',
  227. 5: 'friday',
  228. 6: 'saturday',
  229. 7: 'sunday'
  230. },
  231. sv: {
  232. 0: 'v',
  233. 1: 'mondag',
  234. 2: 'tisdag',
  235. 3: 'onsdag',
  236. 4: 'torsdag',
  237. 5: 'fredag',
  238. 6: 'lördag',
  239. 7: 'söndag'
  240. },
  241. pt: {
  242. 0: 's',
  243. 1: 'segunda',
  244. 2: 'terça',
  245. 3: 'quarta',
  246. 4: 'quinta',
  247. 5: 'sexta',
  248. 6: 'sabado',
  249. 7: 'domingo'
  250. }
  251. },
  252. monthNames: {
  253. en: [
  254. "January",
  255. "February",
  256. "March",
  257. "April",
  258. "May",
  259. "June",
  260. "July",
  261. "August",
  262. "September",
  263. "October",
  264. "November",
  265. "December"
  266. ],
  267. sv: [
  268. "januari",
  269. "februari",
  270. "mars",
  271. "april",
  272. "maj",
  273. "june",
  274. "juli",
  275. "augusti",
  276. "september",
  277. "oktober",
  278. "november",
  279. "december"
  280. ],
  281. pt: [
  282. "Janeiro",
  283. "Fevereiro",
  284. "Março",
  285. "Abril",
  286. "Maio",
  287. "Junho",
  288. "Julho",
  289. "Agosto",
  290. "Setembro",
  291. "Outubro",
  292. "Novembro",
  293. "Dezembro"
  294. ]
  295. },
  296. classes: {
  297. dayLabel: 'day-of-week',
  298. weekLabel: 'week-number',
  299. prevMonth: 'inactive',
  300. nextMonth: 'inactive',
  301. monthDay: 'day-in-month'
  302. }
  303. };
  304. /***/ })
  305. /******/ ]);