/* * create-calendar.js v1.0 * Url demo: https://www.tecnoblog.guru/2015/02/calendario-publicacion-blogger.html * You are free to use the code below and modify it according to your needs. * Date: 2015-02-23 * Author: José María Acuña Morgado || Web Developer * Email: jm.acuna73@gmail.com */ var confJson = {day:[], month:[], year:[], dateText:[], titleText:[], href:[]}, confDate = {monthName:[], dayName:[], today:new Date()}, confToday = {dateNow:confDate.today.getDate(), monthNow:confDate.today.getMonth(), yearNow:confDate.today.getYear()}, confStyle = {anchor:'text-decoration:none;color:#000;cursor:default;', border:'border:1px solid #6F695A;', family:'verdana,arial;', size:11, bgover:'#d2d2d2'}, confSource = {right:'https://cdn.rawgit.com/jmacuna/calendar-widget/master/right.gif', left:'https://cdn.rawgit.com/jmacuna/calendar-widget/master/left.gif', drop:'https://cdn.rawgit.com/jmacuna/calendar-widget/master/drop.gif'} confOther = {content:null, contentMonth:null, contentYear:null, contentDate:null, monthSelected:0, yearSelected:0, dateSelected:0, monthPosition:false, monthConstructed:false, yearConstructed:false, interval1:null, interval2:null, timeout1:null, timeout2:null, startYear:0} function createCalendar(json){ var entries = json.feed.entry; var date, year, month, day, entry, published, contentDate, pos, styleArrow, styleDate, headCalendar, widthCalendar; for(var i=0; i 0) confDate.monthName[nMonth] = conf.months.substr(0, pos); conf.months = conf.months.substr(pos + 1); } confDate.monthName[11] = conf.months; for(var nDay=0; nDay<6; nDay++){ pos = conf.days.indexOf("|"); if(pos > 0){ confDate.dayName[nDay] = conf.days.substr(0, pos); } conf.days = conf.days.substr(pos + 1); } confDate.dayName[6] = conf.days; confToday.yearNow += 1900; confOther.monthConstructed = false; confOther.yearConstructed = false; widthCalendar = 200; //calendar size contentDate = "\
\ \
"; document.getElementById("calendar").innerHTML = contentDate; document.getElementById("lblToday").innerHTML = ""+confDate.dayName[(confDate.today.getDay()-conf.start==-1)?6:(confDate.today.getDay()-conf.start)]+", "+confToday.dateNow+" " +confDate.monthName[confToday.monthNow]+" "+confToday.yearNow+""; confOther.content = document.getElementById("contentDate").style; confOther.contentMonth = document.getElementById("selectMonth").style; confOther.contentYear = document.getElementById("selectYear").style; confOther.contentDate = document.getElementById("contentDate"); styleArrow = "border:1px solid #eee;cursor:pointer;padding:1;line-height:8px;"; styleDate = "font-family:"+confStyle.family+"font-weight:bold;font-size:"+confStyle.size+"px;color:#313131;border:1px solid #eee;cursor:pointer;" headCalendar = ""; headCalendar += ""; headCalendar += ""; headCalendar += "
"; document.getElementById("caption").innerHTML = headCalendar; popUpCalendar(); } } function overMonth(obj){ obj.style.backgroundColor = confStyle.bgover; } function outMonth(obj){ obj.style.backgroundColor = conf.bgcolor; } function overBox(obj){ obj.style.backgroundColor = "#ced2db"; } function outBox(obj){ obj.style.backgroundColor = "#fff"; } function StartDecMonth(){ confOther.interval1 = setInterval("decMonth()",80); } function StartIncMonth(){ confOther.interval1 = setInterval("incMonth()",80); } function incMonth(){ confOther.monthSelected++; if(confOther.monthSelected > 11){ confOther.monthSelected = 0; confOther.yearSelected++; }constructCalendar(); } function decMonth(){ confOther.monthSelected--; if(confOther.monthSelected < 0){ confOther.monthSelected = 11; confOther.yearSelected--; }constructCalendar(); } function overDate(oTd){ oTd.style.backgroundColor = confStyle.bgover; } function posTop(){ //alert(confOther.contentDate.offsetHeight + '\n' + document.getElementById('chead').offsetHeight); var top = -(confOther.contentDate.offsetHeight) + (document.getElementById('chead').offsetHeight - 4); return top; } function constructMonth(){ var sHTML, styleTable; popDownYear(); confOther.monthPosition = true; if(!confOther.monthConstructed){ sHTML = ""; for(var i=0; i<12; i++){ sName = confDate.monthName[i]; if(i == confOther.monthSelected){ sName = ""+sName+""; } sHTML += " "+sName+" "; } styleTable = "font-family:arial;font-size:"+confStyle.size+"px;background-color:#fff;"; document.getElementById("selectMonth").innerHTML = ""+sHTML+"
"; confOther.monthConstructed = true; } } function popUpMonth(){ constructMonth(); if(confOther.contentMonth.visibility == "hidden"){ confOther.contentMonth.visibility = "visible"; }else{ confOther.contentMonth.visibility = "hidden"; } confOther.contentMonth.left = confOther.contentDate.offsetWidth/2 - 30; confOther.contentMonth.top = posTop(); } function popDownMonth(){ confOther.contentMonth.visibility = "hidden"; } function countYear(n){ var newYear, txtYear; for(var i=0; i<7; i++){ newYear = (i+confOther.startYear)+n; if(newYear == confOther.yearSelected){ txtYear = " "+newYear+" "; }else{ txtYear = " "+newYear+" "; } document.getElementById("y"+i).innerHTML = txtYear; } if(n>0){ confOther.startYear++; }else{ confOther.startYear--; } } function incYear(){ countYear(1); } function decYear(){ countYear(-1); } function selectYear(nYear){ confOther.yearSelected = parseInt(nYear+confOther.startYear); confOther.yearConstructed = false; constructCalendar(); popDownYear(); } function constructYear(){ var sHTML, styleTable; popDownMonth(); if(!confOther.yearConstructed){ sHTML = ""; j = 0; confOther.startYear = confOther.yearSelected-3; for(var i=(confOther.yearSelected-3); i<=(confOther.yearSelected+3); i++){ sName = i; if(i == confOther.yearSelected){ sName = ""+sName+""; } sHTML += " "+sName+" "; j++; } styleTable = "font-family:arial;font-size:"+confStyle.size+"px;background-color:#fff;"; sHTML += ""; document.getElementById("selectYear").innerHTML = ""+sHTML+"
"; confOther.yearConstructed = true; } } function popDownYear(){ clearInterval(confOther.interval1); clearTimeout(confOther.timeout1); clearInterval(confOther.interval2); clearTimeout(confOther.timeout2); confOther.contentYear.visibility = "hidden"; } function popUpYear(){ var heightMonth = 0; constructYear(); if(confOther.contentYear.visibility == "hidden"){ confOther.contentYear.visibility = "visible"; }else{ confOther.contentYear.visibility = "hidden"; } confOther.contentYear.left = confOther.contentDate.offsetWidth - 34; if(confOther.monthPosition){ heightMonth = document.getElementById("selectMonth").offsetHeight; } confOther.contentYear.top = posTop() - heightMonth; } function constructCalendar(){ var aNumDays = [31,0,31,30,31,30,31,31,30,31,30,31], startDate = new Date(confOther.yearSelected,confOther.monthSelected,1), datePointer, endDate, sTitle, sHref, aData, sClass, sTarget; if(confOther.monthSelected==1){ endDate = new Date(confOther.yearSelected,confOther.monthSelected+1,1); endDate = new Date(endDate - (24*60*60*1000)); numDaysInMonth = endDate.getDate(); }else{ numDaysInMonth = aNumDays[confOther.monthSelected]; } datePointer = 0; dayPointer = startDate.getDay() - conf.start; if(dayPointer<0){ dayPointer = 6; } sHTML = ""; for(var i=0; i<7; i++){ sHTML += ""; } sHTML +=""; for(var i=1; i<=dayPointer; i++){ sHTML += ""; } sTarget = (conf.newtab)?"_blank":"_parent"; sClass = (conf.tooltip)?"masterTooltip":""; for(datePointer=1; datePointer<=numDaysInMonth; datePointer++){ dayPointer++; sHTML += ""; } } document.getElementById("content").innerHTML = sHTML; document.getElementById("spanMonth").innerHTML = " "+confDate.monthName[confOther.monthSelected]+" "; document.getElementById("spanYear").innerHTML = " "+confOther.yearSelected+" "; if(conf.tooltip){ loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js', function(){ $(document).ready(function() { // Tooltip only Text $('.masterTooltip').hover(function(){ // Hover over code var title = $(this).attr('title'); $(this).data('tipText', title).removeAttr('title'); $('

') .text(title) .appendTo('body') .fadeIn('slow'); }, function() { // Hover out code $(this).attr('title', $(this).data('tipText')); $('.tooltip').remove(); }).mousemove(function(e) { var mousex = e.pageX + 10; //Get X coordinates var mousey = e.pageY + 10; //Get Y coordinates $('.tooltip') .css({ top: mousey, left: mousex }) }); }); }); } } function loadScript(url, callback){ var script, id = document.getElementById('jquery'); if(id != null){ callback(); return; } script = document.createElement('script'); script.type = 'text/javascript'; script.id = 'jquery'; if(script.readyState){ script.onreadystatechange = function(){ if (script.readyState == 'loaded' || script.readyState == 'complete'){ script.onreadystatechange = null; callback(); } }; }else{ script.onload = function(){ callback(); }; } script.src = url; document.getElementsByTagName('head')[0].appendChild(script); } function popUpCalendar(){ var aData = confJson.dateText[0].split("/"); confOther.dateSelected = parseInt(aData[0], 10); confOther.monthSelected = parseInt(aData[1]-1, 10); confOther.yearSelected = parseInt(aData[2], 10); if(isNaN(confOther.dateSelected)||isNaN(confOther.monthSelected)||isNaN(confOther.yearSelected)){ confOther.dateSelected = confToday.dateNow; confOther.monthSelected = confToday.monthNow; confOther.yearSelected = confToday.yearNow; } constructCalendar(); }
"+confDate.dayName[i].substr(0,3)+"
 "; sTitle = ""; sHref = "javascript:#"; sStyle = confStyle.anchor; for(var i=0; i "+datePointer+" "; }else if(dayPointer % 7 == (conf.start * -1)+1){ sHTML += " "+datePointer+" "; }else{ sHTML += " "+datePointer+" "; } sHTML += ""; if((dayPointer+conf.start) % 7 == conf.start){ sHTML += "