Skip to main content
Participant
July 6, 2019
Beantwortet

JavaScript Calendar Premaker week number

  • July 6, 2019
  • 1 Antwort
  • 1496 Ansichten

Hi there all, I am a beginner to JavaScript and I need your help guys.

I have here a Calendar Premaker script that makes a basic calendar, what I want to add is a week number right on the left side, I found a ISO Standard (ISO week date - Wikipedia ) that show some rules how it's calculated.

Can anyone help me to implement it?

var sMS = "Ianuarie,Februarie,Martie,Aprilie,Mai,Iunie,Iulie,August,Septembrie,Octombrie,Noiembrie,Decembrie"; 

var sDS = "L,Ma,Mi,J,V,S,D"; 

var sHS = "1/1,8/3,1/5,25/12"; 

 

 

 

 

var pMS = "Scrie numele lunilor (separare prin virgula)\nSau lasa neschimbat!"; 

var pDS = "Scrie numele zilelor din saptamana (separare prin virgula)\nSau lasa neschimbat!"; 

var pHS = "Scrie sarbatorile, exemplu Z/L[,Z/L,Z/L...]"; 

 

 

var AppCap = "Calendar (pt. Adobe Illustrator CC)\n\n"; 

var iStr = "Pentru editare elemente:\n\n"+ 

   "Window -> Type -> Paragraph Styles\n"+ 

   "Window -> Type -> Character Styles\n"+ 

   "Window -> Swatches\n\n"; 

var pStr = AppCap+"Scrie anul.\nExemplu: 2019"; 

 

 

Year = 2019; 

Year = prompt(pStr, Year);  

if(Year>2000 && Year<2100 && Year != null) { 

 

 

MS = prompt(AppCap+pMS, sMS); 

if(MS){ 

MC = MS.split(',',12); 

 

for(i=0;i<12;i++) if(MC==null) MC.push(' '); 

for(i=0;i<12;i++) if(MC=='') MC=' '; 

 

DS = prompt(AppCap+pDS, sDS); 

if(DS) { 

DC = DS.split(',',7); 

for(i=0;i<7;i++) if(DC==null) DC.push(' '); 

for(i=0;i<7;i++) if(DC=='') DC=' '; 

 

HS = prompt(AppCap+pHS, sHS); 

if(HS == '') HS = ' '; 

if(HS) { 

HC = HS.split(','); 

HD = Array(); 

for(i=0;i<HC.length;i++) { 

  DM = HC.split('/'); 

  HD.push(DM[0],DM[1]); 

 

makeCalendar(); 

 

 

function makeCalendar() { 

CellHeight = 20; 

CellWidth  = 30; 

 

MN = Array(31,(Year%4==0)?29:28,31,30,31,30,31,31,30,31,30,31); 

FirstDay = Math.floor((Year-2001)*5/4%7); 

FD = FirstDay; 

var DocTop = CellHeight*52; 

var docRef = documents.add(DocumentColorSpace.CMYK,CellWidth*18,DocTop+CellHeight*3); 

 

 

//  

waitRef = docRef.textFrames.add(); 

waitRef.contents = "Procesare...\n ©️ PRINTCO"; 

waitRef.top = DocTop; 

waitRef.left = 10; 

waitRef.height = 100; 

waitRef.width = 300; 

redraw(); 

// 

 

docRef.swatches.removeAll(); 

try{docRef.characterStyles.removeAll()} catch(e){} 

 

var nColor = new CMYKColor(); 

var nSpotColor = new SpotColor(); 

 

var DefaultSpot = docRef.spots.add(); 

nColor.cyan = 90; 

nColor.magenta = 60; 

nColor.yellow = 0; 

nColor.black = 0; 

DefaultSpot.name = "Zile"; 

DefaultSpot.colorType = ColorModel.PROCESS; 

DefaultSpot.color = nColor; 

 

var HolidaySpot = docRef.spots.add(); 

nColor.cyan = 0; 

nColor.magenta = 90; 

nColor.yellow = 60; 

nColor.black = 0; 

HolidaySpot.name = "Sarbatori"; 

HolidaySpot.colorType = ColorModel.PROCESS; 

HolidaySpot.color = nColor; 

 

var DaySpot = docRef.spots.add(); 

nColor.cyan = 0; 

nColor.magenta = 0; 

nColor.yellow = 0; 

nColor.black = 70; 

DaySpot.name = "Color of caption of week day"; 

DaySpot.colorType = ColorModel.PROCESS; 

DaySpot.color = nColor; 

 

var HolydayDaySpot = docRef.spots.add(); 

nColor.cyan = 0; 

nColor.magenta = 60; 

nColor.yellow = 20; 

nColor.black = 50; 

HolydayDaySpot.name = "Color of caption of weekend"; 

HolydayDaySpot.colorType = ColorModel.PROCESS; 

HolydayDaySpot.color = nColor; 

 

var CaptionSpot = docRef.spots.add(); 

nColor.cyan = 0; 

nColor.magenta = 0; 

nColor.yellow = 0; 

nColor.black = 100; 

CaptionSpot.name = "Color of caption of month"; 

CaptionSpot.colorType = ColorModel.PROCESS; 

CaptionSpot.color = nColor; 

 

 

var charAttr; 

var paraAttr; 

var DefaultStyle = docRef.characterStyles.add("Week day"); 

var HolidayStyle = docRef.characterStyles.add("Holyday"); 

var DayCapStyle = docRef.characterStyles.add("Caption of week day"); 

var HolydayCapStyle = docRef.characterStyles.add("Caption of weekend"); 

var CaptionsStyle = docRef.characterStyles.add("Caption of month"); 

 

 

 

 

charAttr = DefaultStyle.characterAttributes; 

//charAttr.size = 14; 

nSpotColor.spot = DefaultSpot; 

charAttr.fillColor = nSpotColor; 

 

charAttr = HolidayStyle.characterAttributes; 

//charAttr.size = 14; 

nSpotColor.spot = HolidaySpot; 

charAttr.fillColor = nSpotColor; 

 

charAttr = DayCapStyle.characterAttributes; 

//charAttr.size = 14; 

nSpotColor.spot = DaySpot; 

charAttr.fillColor = nSpotColor; 

 

charAttr = HolydayCapStyle.characterAttributes; 

//charAttr.size = 14; 

nSpotColor.spot = HolydayDaySpot; 

charAttr.fillColor = nSpotColor; 

 

charAttr = CaptionsStyle.characterAttributes; 

//charAttr.size = 14; 

nSpotColor.spot = CaptionSpot; 

charAttr.fillColor = nSpotColor; 

 

 

var paraDayStyle = docRef.paragraphStyles.add("Dates"); 

paraAttr = paraDayStyle.paragraphAttributes; 

paraAttr.justification = Justification.RIGHT; 

 

var paraWeekDayStyle = docRef.paragraphStyles.add("Days of week"); 

paraAttr = paraWeekDayStyle.paragraphAttributes; 

paraAttr.justification = Justification.RIGHT; 

 

var paraMonthStyle = docRef.paragraphStyles.add("Months"); 

paraAttr = paraMonthStyle.paragraphAttributes; 

paraAttr.justification = Justification.LEFT; 

 

 

 

LeftMargin = CellWidth; 

for(m=0; m<6; m++){ 

textRef = docRef.textFrames.add(); 

textRef.contents = MC

textRef.top = DocTop - m*9*CellHeight+CellHeight*2; 

textRef.left = CellWidth + LeftMargin;      

CaptionsStyle.applyTo(textRef.textRange) 

paraMonthStyle.applyTo(textRef.paragraphs[0], true); 

 

for(i=0; i<7; i++){ 

textRef = docRef.textFrames.add(); 

textRef.contents = DC

textRef.top = DocTop - m*9*CellHeight+CellHeight; 

textRef.left = i*CellWidth + LeftMargin; 

(i<5) ? DayCapStyle.applyTo(textRef.textRange) : HolydayCapStyle.applyTo(textRef.textRange); 

paraWeekDayStyle.applyTo(textRef.paragraphs[0], true); 

}  

for(d=0; d<MN; d++){ 

textRef = docRef.textFrames.add(); 

textRef.contents = d+1; 

textRef.top = DocTop - ((Math.floor((FD+d)/7)*CellHeight) + m*9*CellHeight); 

textRef.left = (FD+d)%7*CellWidth + LeftMargin; 

paraDayStyle.applyTo(textRef.paragraphs[0], true); 

if ((FD+d+1)%7) DefaultStyle.applyTo(textRef.textRange); 

else            HolidayStyle.applyTo(textRef.textRange); 

if (isHoliday(d+1,m+1)) HolidayStyle.applyTo(textRef.textRange); 

FD = (FD+d)%7; 

 

LeftMargin = CellWidth*9; 

for(m=6; m<12; m++){ 

textRef = docRef.textFrames.add(); 

textRef.contents = MC

textRef.top = DocTop - (m-6)*9*CellHeight+CellHeight*2; 

textRef.left = CellWidth + LeftMargin;      

CaptionsStyle.applyTo(textRef.textRange) 

paraMonthStyle.applyTo(textRef.paragraphs[0], true); 

 

for(i=0; i<7; i++){ 

textRef = docRef.textFrames.add(); 

textRef.contents = DC

textRef.top = DocTop - (m-6)*9*CellHeight+CellHeight; 

textRef.left = i*CellWidth + LeftMargin;      

(i<5) ? DayCapStyle.applyTo(textRef.textRange) : HolydayCapStyle.applyTo(textRef.textRange); 

paraWeekDayStyle.applyTo(textRef.paragraphs[0], true); 

}  

for(d=0; d<MN; d++){ 

textRef = docRef.textFrames.add(); 

textRef.contents = d+1; 

textRef.top = DocTop - ((Math.floor((FD+d)/7)*CellHeight) + (m-6)*9*CellHeight); 

textRef.left = (FD+d)%7*CellWidth + LeftMargin; 

paraDayStyle.applyTo(textRef.paragraphs[0], true); 

if ((FD+d+1)%7) DefaultStyle.applyTo(textRef.textRange); 

else            HolidayStyle.applyTo(textRef.textRange); 

if (isHoliday(d+1,m+1)) HolidayStyle.applyTo(textRef.textRange); 

FD = (FD+d)%7; 

 

waitRef.remove(); 

redraw(); 

 

alert(iStr); 

 

 

function isHoliday(day,month) 

var i; 

for(i=0; i<HD.length; i+=2){ 

if(day==HD && month==HD[i+1]) return true; 

return false; 

Beste Antwort von Alexander Ladygin

Hi

Try this script as an option?

https://github.com/alexander-ladygin/illustrator-scripts/blob/master/calendarikko.jsx

1 Antwort

Alexander Ladygin
Inspiring
July 6, 2019
Participant
July 6, 2019

Yeah thats awesome, thank you!