Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaroop Guggilam committed Sep 24, 2023
2 parents c7b60e1 + 64edad5 commit e37d1f0
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## History
* 2023/09/24 ver 3.0.9
* New options in Screenshot to include Author and Rules for png and jpeg. svg support not included.
* Use new clipboard API when able. (Fixes Copy on iOS.)
* Minor bug fixes and code refactoring.
* 2023/07/28 ver 3.0.8
* Updated jquery, sweetalert to latest.
* Fixed the bug of correctly deleteing cagearrays.
Expand Down
17 changes: 16 additions & 1 deletion docs/branding.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const Branding = {
// Usage Button Amendments
addUsageButtons: {
// "Submission Rules for GMPuzzles": "https://tinyurl.com/GMPuzzlesFormatting"
}
},

googleTag: 'G-2WQYM10ZE7'
};

(function () {
Expand All @@ -29,4 +31,17 @@ const Branding = {
button.textContent = buttonName;
usageButtons.appendChild(button);
}

if (Branding.googleTag) {
let script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://www.googletagmanager.com/gtag/js?id=" + Branding.googleTag;
script.async = true;
document.head.appendChild(script);

window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', Branding.googleTag);
}
})();
19 changes: 19 additions & 0 deletions docs/css/base-structure.css
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,25 @@ h4 {
display: inline;
}

#modal-save-content textarea,
#modal-save-content input[type=text] {
padding: 2pt 5pt;
}

#modal-save-content button,
#modal-save-content input[type=button] {
border-radius: 3px;
}

textarea {
background-color: inherit;
transition: ease 0.3s all;
}

.copied {
transition: ease 0.8s all;
}

#savetextarea_pp {
min-width: 200px;
min-height: 40px;
Expand Down
25 changes: 25 additions & 0 deletions docs/css/dark_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ header,
color: var(--white);
}

#modal-save-content textarea,
#modal-save-content input[type=text] {
border: 1px solid var(--greyDark);
background: var(--greyDarkVery);
color: var(--white);
}

#modal-save-content button,
#modal-save-content input[type=button] {
border: 1px solid var(--greyDark);
background: var(--black);
color: var(--white);
}

#modal-save-content button:hover,
#modal-save-content input[type=button]:hover {
background: var(--greyDarkVery);
}

.copied {
color: var(--greenLightVery) !important;
border-color: var(--greenLightVery) !important;
background: var(--green) !important;
}

#save3texttitle,
#nb_note {
color: var(--white);
Expand Down
25 changes: 25 additions & 0 deletions docs/css/light_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ header,
background: var(--greyLight);
}

#modal-save-content textarea,
#modal-save-content input[type=text] {
border: 1px solid var(--greyLight);
background: var(--greyLightVery);
color: var(--black);
}

#modal-save-content button,
#modal-save-content input[type=button] {
border: 1px solid var(--greyLight);
background: var(--white);
color: var(--black);
}

#modal-save-content button:hover,
#modal-save-content input[type=button]:hover {
background: var(--greyLightVery);
}

.copied {
color: var(--green) !important;
border-color: var(--green) !important;
background: var(--greenLightVery) !important;
}

#save3texttitle,
#nb_note {
color: var(--black);
Expand Down
30 changes: 13 additions & 17 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Local styles -->
<script>
var ver = "3.0.8"; // Also defined in class_p.js
var ver = "3.0.9"; // Also defined in class_p.js
let style_sources = [
"./css/light_theme.css",
"./css/base-structure.css",
Expand Down Expand Up @@ -112,22 +112,6 @@
document.head.appendChild(script);
}
</script>
<!-- Global site tag (gtag.js) - Google Analytics (support for this tag will end in June 2023)-->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-180924087-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-180924087-1');
</script>
<!-- Global site tag (gtag.js) - Google Analytics (New GA4 Tag)-->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2WQYM10ZE7"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-2WQYM10ZE7');
</script>
</head>

<body>
Expand Down Expand Up @@ -942,6 +926,18 @@ <h4><label class="label_imagespace" id="nb_type_lb">File Type:</label></h4>
<label for="nb_type2" class="label" id="nb_type2_lb">jpeg</label>
<input type="radio" name="nb_type" value="3" id="nb_type3">
<label for="nb_type3" class="label" id="nb_type3_lb">svg</label>
<br>
<h4><label class="label_imagespace" id="nb_title_lb">Title &amp; Author:</label></h4>
<input type="radio" name="nb_title" value="1" id="nb_title1">
<label for="nb_title1" class="label" id="nb_title1_lb">Yes</label>
<input type="radio" name="nb_title" value="2" id="nb_title2" checked="checked">
<label for="nb_title2" class="label" id="nb_title2_lb">No</label>
<br>
<h4><label class="label_imagespace" id="nb_rules_lb">Rules:</label></h4>
<input type="radio" name="nb_rules" value="1" id="nb_rules1">
<label for="nb_rules1" class="label" id="nb_rules1_lb">Yes</label>
<input type="radio" name="nb_rules" value="2" id="nb_rules2" checked="checked">
<label for="nb_rules2" class="label" id="nb_rules2_lb">No</label>
<br><br>
<span id="saveimagename_lb">File name:<input type="text" placeholder="sample_name" id="saveimagename"></span>
</div>
Expand Down
94 changes: 84 additions & 10 deletions docs/js/class_p.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Puzzle {
["\"__a\"", "z_"],
["null", "zO"],
];
this.version = [3, 0, 8]; // Also defined in HTML Script Loading in header tag to avoid Browser Cache Problems
this.version = [3, 0, 9]; // Also defined in HTML Script Loading in header tag to avoid Browser Cache Problems
this.undoredo_disable = false;
this.comp = false;
this.multisolution = false;
Expand Down Expand Up @@ -2094,8 +2094,14 @@ class Puzzle {

resizedContext.drawImage(this.canvas, 0, 0, resizedCanvas.width, resizedCanvas.height);
if (document.getElementById("nb_type1").checked) {
if (document.getElementById("nb_title1").checked || document.getElementById("nb_rules1").checked) {
resizedCanvas = this.canvaswithinfo();
}
var canvastext = resizedCanvas.toDataURL("image/png");
} else if (document.getElementById("nb_type2").checked) {
if (document.getElementById("nb_title1").checked || document.getElementById("nb_rules1").checked) {
resizedCanvas = this.canvaswithinfo();
}
var canvastext = resizedCanvas.toDataURL("image/jpeg");
} else if (document.getElementById("nb_type3").checked) {
var svg_canvas = new C2S(this.canvasx, this.canvasy);
Expand Down Expand Up @@ -2160,6 +2166,70 @@ class Puzzle {
return canvastext;
}

canvaswithinfo() {
//put the title text on the top
let main_c = $('#canvas')[0];
let main_ctx = main_c.getContext("2d");

let gif_c = document.createElement('canvas');
let gif_ctx = gif_c.getContext("2d");

let fontSize = 16;
let fontLineSize = fontSize * 1.2;
gif_ctx.font = "bold " + fontSize + "px sans-serif";
let puzzleTitle = 'Title: ' + document.getElementById("saveinfotitle").value;
let puzzleRules = document.getElementById("saveinforules").value;
let puzzleTitleLines = this.splitTextLines(gif_ctx, puzzleTitle, main_c.offsetWidth);
let puzzleRulesLines = this.splitTextLines(gif_ctx, puzzleRules, main_c.offsetWidth);
let puzzleAuthor = ('Author: ' + document.getElementById("saveinfoauthor").value).split(",");
if (document.getElementById("nb_title1").checked && document.getElementById("nb_rules1").checked) {
let puzzletext = puzzleTitleLines.concat(puzzleAuthor.concat(puzzleRulesLines));
} else if (document.getElementById("nb_title1").checked) {
let puzzletext = puzzleTitleLines.concat(puzzleAuthor);
} else {
let puzzletext = puzzleRulesLines;
}

let gif_vertical_offset = puzzletext.length * fontLineSize;
gif_c.width = main_c.offsetWidth;
gif_c.height = main_c.offsetHeight + gif_vertical_offset;
gif_ctx.font = "bold " + fontSize + "px sans-serif";

//clear the gif canvas
gif_ctx.fillStyle = "#fff";
gif_ctx.fillRect(0, 0, gif_c.width, gif_c.height);

//draw the title text.
gif_ctx.fillStyle = "#0000ff";
let textY = fontSize;
for (let textLine of puzzletext) {
gif_ctx.fillText(textLine, (gif_c.width - gif_ctx.measureText(textLine).width) / 2, textY);
textY += fontLineSize;
}

gif_ctx.drawImage(main_c, 0, 0, main_c.width, main_c.height, 0, gif_vertical_offset, gif_c.width, gif_c.height - gif_vertical_offset);
return gif_c;
}

splitTextLines(ctx, text, maxWidth) {
var words = text.split(" ");
var lines = [];
var currentLine = words[0];

for (var i = 1; i < words.length; i++) {
var word = words[i];
var width = ctx.measureText(currentLine + " " + word).width;
if (width < maxWidth) {
currentLine += " " + word;
} else {
lines.push(currentLine);
currentLine = word;
}
}
lines.push(currentLine);
return lines;
}

gridspace_calculate() {
this.redraw();
// ピクセルデータから計算
Expand Down Expand Up @@ -13134,16 +13204,20 @@ class Puzzle {

// Sanity check
if (outputstring.length === size * size) {
document.getElementById("iostring").value = outputstring;
let textarea = document.getElementById("iostring");
textarea.select();
let range = document.createRange();
range.selectNodeContents(textarea);
let sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
textarea.setSelectionRange(0, 1e5);
document.execCommand("copy");
if (navigator.clipboard) {
navigator.clipboard.writeText(textarea.value);
} else {
document.getElementById("iostring").value = outputstring;
textarea.select();
let range = document.createRange();
range.selectNodeContents(textarea);
let sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
textarea.setSelectionRange(0, 1e5);
document.execCommand("copy");
}
} else {
document.getElementById("iostring").value = "Error: Some cells have more than 1 digit";
}
Expand Down
53 changes: 35 additions & 18 deletions docs/js/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -1658,15 +1658,26 @@ function make_gmpfile() {

function savetext_copy() {
infoMsg('<h2 class="info">URL is copied to clipboard</h2>');
var textarea = document.getElementById("savetextarea");
textarea.select();
var range = document.createRange();
range.selectNodeContents(textarea);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
textarea.setSelectionRange(0, 1e5);
document.execCommand("copy");

const textarea = document.getElementById("savetextarea");

textarea.classList.add('copied');
setTimeout(() => {
textarea.classList.remove('copied');
}, 2500);

if (navigator.clipboard) {
navigator.clipboard.writeText(textarea.value);
} else {
textarea.select();
let range = document.createRange();
range.selectNodeContents(textarea);
let sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
textarea.setSelectionRange(0, 1e5);
document.execCommand("copy");
}
}

function savetext_download() {
Expand Down Expand Up @@ -1722,15 +1733,21 @@ function savetext_window() {
}

function shorturl_tab() {
var textarea = document.getElementById("savetextarea");
textarea.select();
var range = document.createRange();
range.selectNodeContents(textarea);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
textarea.setSelectionRange(0, 1e5);
document.execCommand("copy");
const textarea = document.getElementById("savetextarea");

if (navigator.clipboard) {
navigator.clipboard.writeText(textarea.value);
} else {
textarea.select();
let range = document.createRange();
range.selectNodeContents(textarea);
let sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
textarea.setSelectionRange(0, 1e5);
document.execCommand("copy");
}

window.open('https://tinyurl.com/app', '_blank');
}

Expand Down
Loading

0 comments on commit e37d1f0

Please sign in to comment.