java programming ] 4 Problem allows its user to scan and find calendars for inpu
ID: 3750671 • Letter: J
Question
java programming
]
4 Problem allows its user to scan and find calendars for inputied dates in calendarct a reference date and locate other calendars from this doe Al lian the user ditDion e calendars can be fully enhanced for planning, tracking events and teactsing history for planning, RSpecifications that displays the current year, month and day on start Write a Piste February 12, 2014 is shown highlighted in the Interactive calerdst date Fe un the current date is taken as the reference date. up. For example,Che interactive calendar below On start up date can be changed by typing a new date in the textbox labelled Date and cicking on the Set as Ref... button The user can change inputted date is display rhe elapsed time from the reference date to the displayed date is printed in the isbelled Time from Reference Date. A negative sign in front of the Time from Reference Date e the displayed date by typing a new date in the textbox labelled Date The date 3 ed and its reference time is set to twelve midnight that the displayed date precedes the reference date. can change the displayed date by inputting the elapsed time from the reference date The calendar and the Date textbox display the calculated date from the elapsed time 5 A user chang Calenda Date Teruny 12.3034 14 303s Time from Reference Date. Ferary,23 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 28 || 29 30 and elapsed time include hours, minutes and seconds in bracketsExplanation / Answer
(function (undefined) { var today; var Kalendae = function (targetElement, options) { //if the first argument isn't an element and isn't a string, assume that it is the options object if (!(targetElement instanceof Element || typeof targetElement === 'string')) options = targetElement; var self = this, classes = self.classes, opts = self.settings = util.merge(self.defaults, {attachTo:targetElement}, options || {}), $container = self.container = util.make('div', {'class':classes.container}), calendars = self.calendars = [], startDay = moment().day(opts.weekStart), vsd, columnHeaders = [], $cal, $title, $caption, $header, $days, dayNodes = [], $span, i = 0, j = opts.months; if (util.isIE8()) util.addClassName($container, 'ie8'); //generate the column headers (Su, Mo, Tu, etc) i = 7; while (i--) { columnHeaders.push( startDay.format('ddd').substr(0,opts.columnHeaderLength) ); startDay.add('days',1); } //setup publish/subscribe and apply any subscriptions passed in settings MinPubSub(self); if (typeof opts.subscribe === 'object') { for (i in opts.subscribe) if (opts.subscribe.hasOwnProperty(i)) { self.subscribe(i, opts.subscribe[i]); } } //process default selected dates self._sel = []; if (!!opts.selected) self.setSelected(opts.selected, false); //set the view month if (!!opts.viewStartDate) { vsd = moment(opts.viewStartDate, opts.format); } else if (self._sel.length > 0) { vsd = moment(self._sel[0]); } else { vsd = moment(); } self.viewStartDate = vsd.date(1); var viewDelta = ({ 'past' : opts.months-1, 'today-past' : opts.months-1, 'any' : opts.months>2?Math.floor(opts.months/2):0, 'today-future' : 0, 'future' : 0 })[this.settings.direction]; if (viewDelta && moment().month()==moment(self.viewStartDate).month()){ self.viewStartDate = moment(self.viewStartDate).subtract({M:viewDelta}).date(1); } if (typeof opts.blackout === 'function') { self.blackout = opts.blackout; } else if (!!opts.blackout) { var bdates = parseDates(opts.blackout, opts.parseSplitDelimiter); self.blackout = function (input) { input = moment(input).yearDay(); if (input < 1 || !self._sel || self._sel.length < 1) return false; var i = bdates.length; while (i--) if (bdates[i].yearDay() === input) return true; return false; } } else { self.blackout = function () {return false;} } self.direction = self.directions[opts.direction] ? self.directions[opts.direction] : self.directions['any']; //for the total months setting, generate N calendar views and add them to the container j = Math.max(opts.months,1); while (j--) { $cal = util.make('div', {'class':classes.calendar}, $container); $cal.setAttribute('data-cal-index', j); if (opts.months > 1) { if (j == Math.max(opts.months-1,1)) util.addClassName($cal, classes.monthFirst); else if (j === 0) util.addClassName($cal, classes.monthLast); else util.addClassName($cal, classes.monthMiddle); } //title bar $title = util.make('div', {'class':classes.title}, $cal); util.make('a', {'class':classes.previousYear}, $title); //previous button util.make('a', {'class':classes.previousMonth}, $title); //previous button util.make('a', {'class':classes.nextYear}, $title); //next button util.make('a', {'class':classes.nextMonth}, $title); //next button $caption = util.make('span', {'class':classes.caption}, $title); //title caption //column headers $header = util.make('div', {'class':classes.header}, $cal); i = 0; do { $span = util.make('span', {}, $header); $span.innerHTML = columnHeaders[i]; } while (++i < 7) //individual day cells $days = util.make('div', {'class':classes.days}, $cal); i = 0; dayNodes = []; while (i++ < 42) { dayNodes.push(util.make('span', {}, $days)); } //store each calendar view for easy redrawing calendars.push({ caption:$caption, days:dayNodes }); if (j) util.make('div', {'class':classes.monthSeparator}, $container); } self.draw(); util.addEvent($container, 'mousedown', function (event, target) { var clickedDate; if (util.hasClassName(target, classes.nextMonth)) { //NEXT MONTH BUTTON if (!self.disableNext && self.publish('view-changed', self, ['next-month']) !== false) { self.viewStartDate.add('months',1); self.draw(); } return false; } else if (util.hasClassName(target, classes.previousMonth)) { //PREVIOUS MONTH BUTTON if (!self.disablePreviousMonth && self.publish('view-changed', self, ['previous-month']) !== false) { self.viewStartDate.subtract('months',1); self.draw(); } return false; } else if (util.hasClassName(target, classes.nextYear)) { //NEXT MONTH BUTTON if (!self.disableNext && self.publish('view-changed', self, ['next-year']) !== false) { self.viewStartDate.add('years',1); self.draw(); } return false; } else if (util.hasClassName(target, classes.previousYear)) { //PREVIOUS MONTH BUTTON if (!self.disablePreviousMonth && self.publish('view-changed', self, ['previous-year']) !== false) { self.viewStartDate.subtract('years',1); self.draw(); } return false; } else if (util.hasClassName(target.parentNode, classes.days) && util.hasClassName(target, classes.dayActive) && (clickedDate = target.getAttribute('data-date'))) { //DAY CLICK clickedDate = moment(clickedDate, opts.dayAttributeFormat).hours(12); if (self.publish('date-clicked', self, [clickedDate]) !== false) { switch (opts.mode) { case 'multiple': if (!self.addSelected(clickedDate)) self.removeSelected(clickedDate); break; case 'range': self.addSelected(clickedDate); break; case 'single': /* falls through */ default: self.addSelected(clickedDate); break; } } return false; } return false; }); if (!!(opts.attachTo = util.$(opts.attachTo))) { opts.attachTo.appendChild($container); } }; Kalendae.prototype = { defaults : { attachTo: null, /* the element to attach the root container to. can be string or DOMElement */ months: 1, /* total number of months to display side by side */ weekStart: 0, /* day to use for the start of the week. 0 is Sunday */ direction: 'any', /* past, today-past, any, today-future, future */ directionScrolling: true, /* if a direction other than any is defined, prevent scrolling out of range */ viewStartDate: null, /* date in the month to display. When multiple months, this is the left most */ blackout: null, /* array of dates, or function to be passed a date */ selected: null, /* dates already selected. can be string, date, or array of strings or dates. */ mode: 'single', /* single, multiple, range */ format: null, /* string used for parsing dates. */ subscribe: null, /* object containing events to subscribe to */ columnHeaderLength: 2, /* number of characters to show in the column headers */ titleFormat: 'MMMM, YYYY', /* format mask for month titles. See momentjs.com for rules */ dayNumberFormat: 'D', /* format mask for individual days */ dayAttributeFormat: 'YYYY-MM-DD', /* format mask for the data-date attribute set on every span */ parseSplitDelimiter: /,s*|s+-s+/, /* regex to use for splitting multiple dates from a passed string */ rangeDelimiter: ' - ', /* string to use between dates when outputting in range mode */ multipleDelimiter: ', ', /* string to use between dates when outputting in multiple mode */ dateClassMap: {} }, classes : { container :'kalendae', calendar :'k-calendar', monthFirst :'k-first-month', monthMiddle :'k-middle-month', monthLast :'k-last-month', title :'k-title', previousMonth :'k-btn-previous-month', nextMonth :'k-btn-next-month', previousYear :'k-btn-previous-year', nextYear :'k-btn-next-year', caption :'k-caption', header :'k-header', days :'k-days', dayOutOfMonth :'k-out-of-month', dayActive :'k-active', daySelected :'k-selected', dayInRange :'k-range', dayToday :'k-today', monthSeparator :'k-separator', disablePreviousMonth :'k-disable-previous-month-btn', disableNextMonth :'k-disable-next-month-btn', disablePreviousYear :'k-disable-previous-year-btn', disableNextYear :'k-disable-next-year-btn' }, disablePreviousMonth: false, disableNextMonth: false, disablePreviousYear: false, disableNextYear: false, directions: { 'past' :function (date) {return moment(date).yearDay() >= today.yearDay();}, 'today-past' :function (date) {return moment(date).yearDay() > today.yearDay();}, 'any' :function (date) {return false;}, 'today-future' :function (date) {return moment(date).yearDay() 0 || elem.offsetHeight > 0; }, getStyle: function (elem, styleProp) { var y; if (elem.currentStyle) { y = elem.currentStyle[styleProp]; } else if (window.getComputedStyle) { y = window.getComputedStyle(elem, null)[styleProp]; } return y; }, domReady:function (f){/in/.test(document.readyState) ? setTimeout(function() {util.domReady(f);},9) : f()}, // Adds a listener callback to a DOM element which is fired on a specified // event. Callback is sent the event object and the element that triggered the event addEvent: function (elem, eventName, callback) { var listener = function (event) { event = event || window.event; var target = event.target || event.srcElement; var block = callback.apply(elem, [event, target]); if (block === false) { if (!!event.preventDefault) event.preventDefault(); else { event.returnValue = false; event.cancelBubble = true; } } return block; }; if (elem.attachEvent) { // IE only. The "on" is mandatory. elem.attachEvent("on" + eventName, listener); } else { // Other browsers. elem.addEventListener(eventName, listener, false); } return listener; }, // Removes a listener callback from a DOM element which is fired on a specified // event. removeEvent: function (elem, event, listener) { if (elem.detachEvent) { // IE only. The "on" is mandatory. elem.detachEvent("on" + event, listener); } else { // Other browsers. elem.removeEventListener(event, listener, false); } }, hasClassName: function(elem, className) { //copied and modified from Prototype.js if (!(elem = util.$(elem))) return false; var eClassName = elem.className; return (eClassName.length > 0 && (eClassName == className || new RegExp("(^|\s)" + className + "(\s|$)").test(eClassName))); }, addClassName: function(elem, className) { //copied and modified from Prototype.js if (!(elem = util.$(elem))) return; if (!util.hasClassName(elem, className)) elem.className += (elem.className ? ' ' : '') + className; }, removeClassName: function(elem, className) { //copied and modified from Prototype.js if (!(elem = util.$(elem))) return; elem.className = util.trimString(elem.className.replace(new RegExp("(^|\s+)" + className + "(\s+|$)"), ' ')); }, isFixed: function (elem) { do { if (util.getStyle(elem, 'position') === 'fixed') return true; } while ((elem = elem.offsetParent)); return false; }, getPosition: function (elem, isInner) { var x = elem.offsetLeft, y = elem.offsetTop, r = {}; if (!isInner) { while ((elem = elem.offsetParent)) { x += elem.offsetLeft; y += elem.offsetTop; } } r[0] = r.left = x; r[1] = r.top = y; return r; }, getHeight: function (elem) { return elem.offsetHeight || elem.scrollHeight; }, getWidth: function (elem) { return elem.offsetWidth || elem.scrollWidth; }, // TEXT FUNCTIONS trimString: function (input) { return input.replace(/^s+/, '').replace(/s+$/, ''); }, // OBJECT FUNCTIONS merge: function () { /* Combines multiple objects into one. * Syntax: util.extend([true], object1, object2, ... objectN) * If first argument is true, function will merge recursively. */ var deep = (arguments[0]===true), d = {}, i = deep?1:0; var _c = function (a, b) { if (typeof b !== 'object') return; for (var k in b) if (b.hasOwnProperty(k)) { //if property is an object or array, merge the contents instead of overwriting, if extend() was called as such if (deep && typeof a[k] === 'object' && typeof b[k] === 'object') _update(a[k], b[k]); else a[k] = b[k]; } return a; } for (; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.