Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hvianna committed Feb 10, 2023
2 parents e38217d + 6ee69a8 commit 2eba371
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 193 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*.{js,html,css}]
charset = utf-8
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
14 changes: 14 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
=========

## version 23.2

### Added:

+ Support for regional holidays - thank you [koterpillar](https://github.com/koterpillar) [(#11)](https://github.com/hvianna/desktopCal.js/pull/11);
+ Holidays for Australia - thank you [koterpillar](https://github.com/koterpillar) [(#9)](https://github.com/hvianna/desktopCal.js/pull/9);
+ Regional holidays for Brazil.

### Fixed and improved:

+ Observation of consecutive holidays in UK - thank you [koterpillar](https://github.com/koterpillar) [(#7)](https://github.com/hvianna/desktopCal.js/issues/7);
+ Add, not replace, holidays in lieu (for UK and AU) - thank you [koterpillar](https://github.com/koterpillar) [(#10)](https://github.com/hvianna/desktopCal.js/pull/10);
+ Updated US holidays: added Juneteenth and renamed Washington's Birthday to Presidents' Day.

## version 23.1

### Added:
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ You can add your own custom holidays. These will be saved in your browser's loca
+ [Saving canvas as image](https://weworkweplay.com/play/saving-html5-canvas-as-image/) and [solution to CORS issue on canvas.toDataURL()](https://stackoverflow.com/a/30517793/2370385)
+ [W3Schools Canvas Reference](https://www.w3schools.com/tags/ref_canvas.asp)
+ [How to draw a rounded Rectangle on HTML Canvas?](https://stackoverflow.com/a/7838871/2370385)
+ Public holidays in [Argentina](https://en.wikipedia.org/wiki/Public_holidays_in_Argentina),
[Brazil](https://pt.wikipedia.org/wiki/Feriados_no_Brasil),
[Canada](https://en.wikipedia.org/wiki/Public_holidays_in_Canada),
[France](https://en.wikipedia.org/wiki/Public_holidays_in_France),
Germany ([here](https://en.wikipedia.org/wiki/Public_holidays_in_Germany), [here](https://en.wikipedia.org/wiki/Bu%C3%9F-_und_Bettag) and [here](https://www.schulferien.org/deutschland/feiertage/)),
[Mexico](https://en.wikipedia.org/wiki/Public_holidays_in_Mexico),
[Portugal](https://en.wikipedia.org/wiki/Public_holidays_in_Portugal),
[Spain](https://en.wikipedia.org/wiki/Public_holidays_in_Spain),
[United Kingdom](https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom),
[United States](https://en.wikipedia.org/wiki/Federal_holidays_in_the_United_States),
[Uruguay](https://en.wikipedia.org/wiki/Public_holidays_in_Uruguay).
+ [Paper sizes](https://papersizes.io/)
+ References for public holidays:
+ [Argentina](https://en.wikipedia.org/wiki/Public_holidays_in_Argentina)
+ [Australia](https://www.fairwork.gov.au/employment-conditions/public-holidays)
+ [Brazil](https://pt.wikipedia.org/wiki/Feriados_no_Brasil) - [AC](https://agencia.ac.gov.br/governo-do-acre-divulga-calendario-de-feriados-e-pontos-facultativos-de-2023/), [AL](https://www.correiodosmunicipios-al.com.br/2022/01/governo-de-alagoas-divulga-calendario-de-feriados-previstos-para-2022/), [PR](https://www.legislacao.pr.gov.br/legislacao/pesquisarAto.do?action=exibir&codAto=251964&indice=1&totalRegistros=28&dt=29.0.2023.11.16.25.855)
+ [Canada](https://en.wikipedia.org/wiki/Public_holidays_in_Canada)
+ [France](https://en.wikipedia.org/wiki/Public_holidays_in_France)
+ [Germany](https://en.wikipedia.org/wiki/Public_holidays_in_Germany), also [here](https://en.wikipedia.org/wiki/Bu%C3%9F-_und_Bettag) and [here](https://www.schulferien.org/deutschland/feiertage/)
+ [Mexico](https://en.wikipedia.org/wiki/Public_holidays_in_Mexico)
+ [Portugal](https://en.wikipedia.org/wiki/Public_holidays_in_Portugal)
+ [Spain](https://en.wikipedia.org/wiki/Public_holidays_in_Spain)
+ [United Kingdom](https://en.wikipedia.org/wiki/Public_holidays_in_the_United_Kingdom)
+ [United States](https://en.wikipedia.org/wiki/Federal_holidays_in_the_United_States)
+ [Uruguay](https://en.wikipedia.org/wiki/Public_holidays_in_Uruguay)

## License

Expand Down
Binary file added img/icons8-ru-flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 44 additions & 40 deletions js/desktopCal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
*/
'use strict';

var _VERSION = '23.1';
const VERSION = '23.2';

var cropper = [],
let cropper = [],
colorPresets;

function getVersion() {
return `v${_VERSION}`;
return `v${VERSION}`;
}

/**
* Update/create Cropper.js areas whenever the calendar layout or paper size change
*/
function changeLayout() {

var layout = document.querySelector('input[name="layout"]:checked').value;
const layout = document.querySelector('input[name="layout"]:checked').value;

// set layout
document.getElementById('config').className = layout;
Expand All @@ -61,10 +61,10 @@ function changeLayout() {

// Cropper.js won't change the aspect ratio of preview elements, so we need to recreate them..

for ( let i of [0,1] ) {
for ( const i of [0,1] ) {
// save loaded image
let imgEl = document.getElementById( `image${i}` );
let imgSrc = imgEl.src;
const imgEl = document.getElementById( `image${i}` ),
imgSrc = imgEl.src;

// destroy cropper instance
if ( cropper[ i ] )
Expand All @@ -74,7 +74,7 @@ function changeLayout() {
imgEl.src = imgSrc;

// clear preview element style
let pvwEl = document.getElementById( `preview${i}` );
const pvwEl = document.getElementById( `preview${i}` );
pvwEl.style = '';

// create new cropper instance with proper aspect ratio
Expand Down Expand Up @@ -119,8 +119,8 @@ function changeInitialWeekday() {
* Set CSS classnames for the preview to match selected calendar layout and settings
*/
function changeStyle() {
let layout = document.querySelector('input[name="layout"]:checked').value,
previewEl = document.getElementById('preview');
const layout = document.querySelector('input[name="layout"]:checked').value,
previewEl = document.getElementById('preview');

previewEl.className = layout;
if ( layout != 'digital' ) {
Expand Down Expand Up @@ -168,8 +168,8 @@ function configUIElements() {
// Cropper.js action buttons
document.querySelectorAll('.cropper-action').forEach( el => {
el.addEventListener('click', e => {
let n = e.target.dataset.obj;
let action = e.target.dataset.action;
const n = e.target.dataset.obj,
action = e.target.dataset.action;
switch ( action ) {
case 'rotR':
cropper[ n ].rotate(90);
Expand Down Expand Up @@ -214,7 +214,7 @@ function deleteColorPreset( index ) {
}

function listColorPresets() {
var html = '';
let html = '';

colorPresets.forEach( ( preset, index ) => {
html += '<tr><td>' +
Expand Down Expand Up @@ -246,8 +246,7 @@ function loadColorPreset( index ) {
*/
function loadImage( obj, n ) {

var reader = new FileReader(),
layout = document.getElementById('preview').className;
const reader = new FileReader();

reader.onload = function() {
document.getElementById( `image${n}` ).src = reader.result;
Expand Down Expand Up @@ -518,11 +517,10 @@ function generateCalendar( month, year, canvas = null ) {
*/
function updatePreview() {

var area = [ document.getElementById('top-half'), document.getElementById('bottom-half') ],
year = [ document.getElementById('top-year').value, document.getElementById('bottom-year').value ],
month = [ document.getElementById('top-month').value, document.getElementById('bottom-month').value ],
country = document.getElementById('country').value,
layout = document.querySelector('input[name="layout"]:checked').value;
const area = [ document.getElementById('top-half'), document.getElementById('bottom-half') ],
year = [ document.getElementById('top-year').value, document.getElementById('bottom-year').value ],
month = [ document.getElementById('top-month').value, document.getElementById('bottom-month').value ],
layout = document.querySelector('input[name="layout"]:checked').value;

// set lang attribute on html element
document.getElementsByTagName('html')[0].lang = `${lang}-${country.toUpperCase()}`;
Expand All @@ -532,20 +530,21 @@ function updatePreview() {
document.getElementById('v-align').disabled = document.getElementById('cal-size').value == 'col';

if ( layout != 'digital' ) {
for ( let i of [0,1] ) {
for ( const i of [0,1] ) {
if ( month[ i ] > 0 && year[ i ] > 0 ) {
area[ i ].querySelector('.cal-title').innerText = msg[ lang ].monthNames[ month[ i ] ] + ' ' + year[ i ];
area[ i ].querySelector('.calendar').innerHTML = generateCalendar( month[ i ], year[ i ] );
}
}
}
else {
let canvas = document.getElementById('canvas');
const canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d'),
img = cropper[0].getCroppedCanvas();

canvas.width = document.getElementById('canvas-width').value;
canvas.height = document.getElementById('canvas-height').value;
let ctx = canvas.getContext('2d');

let img = cropper[0].getCroppedCanvas();
if ( img )
ctx.drawImage( img, 0, 0, canvas.width, canvas.height );
generateCalendar( month[ 1 ], year[ 1 ], canvas );
Expand All @@ -565,10 +564,10 @@ function renderCredits() {
*/
function rotateCanvas() {

var tmp = document.getElementById('canvas-width').value;
const canvasWidth = document.getElementById('canvas-width'),
canvasHeight = document.getElementById('canvas-height');

document.getElementById('canvas-width').value = document.getElementById('canvas-height').value;
document.getElementById('canvas-height').value = tmp;
[ canvasWidth.value, canvasHeight.value ] = [ canvasHeight.value, canvasWidth.value ];

changeLayout();
}
Expand All @@ -578,7 +577,7 @@ function rotateCanvas() {
*/
function downloadCalendar( obj ) {

var format = document.querySelector('input[name="file-format"]:checked').value;
const format = document.querySelector('input[name="file-format"]:checked').value;
obj.download = 'desktopCal-' + document.getElementById('bottom-year').value + '-' + document.getElementById('bottom-month').value + '.' + format;
obj.href = document.getElementById('canvas').toDataURL(`image/${format}`);
}
Expand Down Expand Up @@ -609,12 +608,12 @@ CanvasRenderingContext2D.prototype.roundRect = function ( x, y, w, h, r ) {
*/
async function prepareForPrinting() {

for ( let i of [0,1] ) {
for ( const i of [0,1] ) {
document.getElementById( `preview${i}` ).style.display = 'none'; // hide cropper.js preview area
let img = cropper[ i ].getCroppedCanvas();
const img = cropper[ i ].getCroppedCanvas();
if ( img ) {
let blob = await new Promise( resolve => img.toBlob( resolve ) );
let url = URL.createObjectURL( blob );
const blob = await new Promise( resolve => img.toBlob( resolve ) );
const url = URL.createObjectURL( blob );
document.getElementById( `cal-image${i}` ).style = `background-image: url(${url})`;
}
}
Expand All @@ -626,7 +625,7 @@ async function prepareForPrinting() {
* Restore preview areas and clear background images used for printing
*/
function restoreFromPrinting() {
for ( let i of [0,1] ) {
for ( const i of [0,1] ) {
document.getElementById( `preview${i}` ).style.display = 'block';
document.getElementById( `cal-image${i}` ).style = '';
}
Expand All @@ -642,8 +641,8 @@ function initialize() {

// try to get preferred language and country
const [ browserLang, browserCountry ] = navigator.language.split('-'),
prefLang = localStorage.getItem('lang') || browserLang,
prefCountry = localStorage.getItem('country') || browserCountry && browserCountry.toLowerCase();
prefLang = localStorage.getItem('lang') || browserLang,
prefCountry = localStorage.getItem('country') || browserCountry && browserCountry.toLowerCase();

if ( Object.keys( msg ).includes( prefLang ) )
lang = prefLang;
Expand All @@ -655,6 +654,11 @@ function initialize() {
else
country = msg[ lang ].defCountry;

const prefRegion = localStorage.getItem('region');
if ( prefRegion && Object.keys( countries[country].regions ).includes( prefRegion ) ) {
region = prefRegion;
}

// load color presets
colorPresets = JSON.parse( localStorage.getItem( 'color-presets' ) ) || [];

Expand Down Expand Up @@ -696,8 +700,8 @@ function initialize() {

// init canvas width and height fields with the display's dimensions

let w = window.screen.width * window.devicePixelRatio,
h = window.screen.height * window.devicePixelRatio;
const w = window.screen.width * window.devicePixelRatio,
h = window.screen.height * window.devicePixelRatio;

document.getElementById('canvas-width').value = w;
document.getElementById('canvas-height').value = h;
Expand All @@ -706,12 +710,12 @@ function initialize() {

let loaded = 0;

for ( let i of [0,1] ) {
for ( const i of [0,1] ) {
fetch( `https://picsum.photos/${w}/${w*.75}/?random` )
.then( response => response.blob() )
.then( blob => {
let url = URL.createObjectURL( blob );
let imgEl = document.getElementById( `image${i}` );
const url = URL.createObjectURL( blob ),
imgEl = document.getElementById( `image${i}` );
imgEl.src = url;

// adjust paper layout and initialize croppable areas when both images finish loading
Expand Down
Loading

0 comments on commit 2eba371

Please sign in to comment.