The WordPress 404.php Tutorial Picture image creation work in yesterdayโs Interactively Change WordPress Blog Background Image on Scroll Tutorial set us to thinking of a Drag and Drop game (akin to those in the recent discussions) we could set up to โฆ
- show the user, in the โDragโ section a WordPress Blog Posting Title (and date) โฆ which the user should drag to the appropriate โฆ
- table cell, nine of which exist in the โDrop Zoneโ, and are numbered and backgrounded by a random WordPress Tutorial Picture image
โฆ in alignment with the adage โฆ
Every picture is worth a thousand words.
As well, today, both in terms of โฆ
- providing hints โฆ and/or โฆ
- providing information
โฆ those table cells are associated with โฆ
- double click event (โondblclickโ) logic that shows the โCut to the Chaseโ underlying โaction itemโ associated with the WordPress Blog Posting involved โฆ and, just quietly โฆ
- right click event (โoncontextmenuโ) logic that shows the associated WordPress Blog Posting involved itself
โฆ in our firstdraft โproof of conceptโ PHP based Inhouse WordPress Blog Posting Game (helped out by atweaked experimental_drag_and_drop
htm Drag and Drop basis) we hope you get to try below (when it transforms into the Inhouse Blog Game after the default incarnation) โฆ
โฆ worked by our WordPress 404.php now containg the PHP code snippet โฆ
<?php
if (strpos(('' . str_replace(');%20}','',$_SERVER['QUERY_STRING']) . '~'), '437195~') !== false) { // Drag and drop quiz
//file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'p.p','here');
$prevcontis='';
$ptfileis=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'ptitledddata.html';
if (file_exists($ptfileis)) { // thanks to https://stackoverflow.com/questions/67707029/how-do-i-get-how-long-the-file-was-created-in-seconds-in-php
$modifdate = filemtime($ptfileis);
$secondsago = time() - $modifdate;
if ($secondsago < 50) {
unlink($ptfileis);
} else {
//$prevcontis=file_get_contents("//www.rjmprogramming.com.au/ptitledddata.html" . "?random=" . rand(0,56453423));
$prevcontis=file_get_contents($ptfileis);
}
}
file_put_contents($ptfileis, $prevcontis . "\n" . $ptitle . '?' . str_replace(');%20}','',$_SERVER['QUERY_STRING']));
// file_put_contents($ptfileis, $prevcontis . "\n" . $ptitle . '?random=' . explode(')',$_GET['random'])[0]);
//file_put_contents($ptfileis . "huh", $prevcontis . "\n" . $ptitle . '?' . str_replace(');%20}','',$_SERVER['QUERY_STRING']));
//} else {
// file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'p.q',('' . str_replace(');%20}','',$_SERVER['QUERY_STRING']) . '~'));
}
?>
โฆ to help out the game.
Previous relevant Interactively Change WordPress Blog Background Image on Scroll Tutorial is shown below.
With yesterdayโs Interactively Change Background Image on Scroll User Settings Tutorialโs offering were you โan intrepidโ, typing โฆ
โฆ into that newly minted Javascript prompt window designed for user interaction purposes? This populates the background images in our new Image Scrolling with Fixed Text web application with a random selection from the WordPress Blog you are reading. Because we have some control here, we researched whether our WordPress 404.php logic could be tweaked to help out more in this scenario. The way the PHP works here, detecting this situation, at the end of its workings, is to use an image header (exemplified by the GIF one below) โฆ
<?php
header('Content-Type: image/gif');
echo file_get_contents($path);
exit;
?>
โฆ where $path would point at a GIF image file residing on the RJM Programming domain web server. This design restricts us from any echo functionality before this, so what can we achieve? Anyone? Anyone? Yes, Rasmus, we can write to other web server files that could be like middle-people between the server (supplier of image data) and client (the webpage that called the server). After the server work โฆ
<?php
if (strpos(('' . str_replace(');%20}','',$_SERVER['QUERY_STRING']) . '~'), '591734~') !== false) {
//file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'p.p','here');
$prevcontis='';
$ptfileis=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'ptitledata.html';
if (file_exists($ptfileis)) { // thanks to https://stackoverflow.com/questions/67707029/how-do-i-get-how-long-the-file-was-created-in-seconds-in-php
$modifdate = filemtime($ptfileis);
$secondsago = time() - $modifdate;
if ($secondsago > 5) {
unlink($ptfileis);
} else {
$prevcontis=file_get_contents($ptfileis);
}
}
file_put_contents($ptfileis, $prevcontis . "\n" . $ptitle . '?' . str_replace(');%20}','',$_SERVER['QUERY_STRING']));
//file_put_contents($ptfileis . "huh", $prevcontis . "\n" . $ptitle . '?' . str_replace(');%20}','',$_SERVER['QUERY_STRING']));
//} else {
// file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'p.q',('' . str_replace(');%20}','',$_SERVER['QUERY_STRING']) . '~'));
}
?>
โฆ back at that client (which called the server with that appended โ591734โ placed onto the URL to indicate the intention to want to examine this return data), we have Ajax based Javascript logic โฆ
var ptc='#';
var iptc=0;
var btlist=[];
var vsbtlist=[];
var omo='';
var zhr=null;
var zform=null;
var rawhtml='';
function defmaybe(inu) {
var retomo=omo;
if (omo != '') {
omo='';
return retomo;
}
return inu;
}
function stateChanged() {
var inm=1, jnm=1, thebtitle='';
if (zhr.readyState == 4) {
if (zhr.status == 200) {
rawhtml = zhr.response;
console.log('rawhtml=' + rawhtml);
if (rawhtml.indexOf('random=') != -1 && vsbtlist.length > 0) {
var rawrs=rawhtml.split('random=');
for (inm=1; inm<rawrs.length; inm++) {
for (jnm=0; jnm<vsbtlist.length; jnm++) {
if (vsbtlist[jnm].indexOf('?random=' + rawrs[inm].split(String.fromCharCode(10))[0]) != -1) {
console.log('found ...');
thebtitle=rawhtml.split('?random=' + rawrs[inm].split(String.fromCharCode(10))[0])[0].split(String.fromCharCode(10))[eval(-1 + rawhtml.split('?random=' + rawrs[inm].split(String.fromCharCode(10))[0])[0].split(String.fromCharCode(10)).length)];
console.log(thebtitle);
document.getElementById(vsbtlist[jnm].split('?')[0]).title=thebtitle + ' ... you can right click to navigate there';
document.getElementById(vsbtlist[jnm].split('?')[0]).onmouseout=function(){ omo=''; };
document.getElementById(vsbtlist[jnm].split('?')[0]).onmouseover=function(){ omo='//www.rjmprogramming.com.au/ITblog/' + thebtitle.split(' (')[0].toLowerCase().replace(/\ /g,'-'); };
document.getElementById(vsbtlist[jnm].split('?')[0]).oncontextmenu=function(){ window.open(defmaybe('//www.rjmprogramming.com.au/ITblog/' + thebtitle.split(' (')[0].toLowerCase().replace(/\ /g,'-')),'_blank','top=50,left=50,width=800,height=800'); };
}
}
}
}
}
}
}
function ajaxit() {
zhr = new XMLHttpRequest();
zhr.onreadystatechange=stateChanged;
zhr.open('get', '//www.rjmprogramming.com.au/ptitledata.html?random=' + Math.floor(Math.random() * 196756453), true);
zhr.send(null);
}
โฆ adding oncontextmenu (ie. right click) functionality to the background images, so as a popup window can open to show the associated WordPress Blog posting linked to the image data.
โฆ in todayโschanged interactively_change_background_image_on_scrollhtml web application you can also try way below.
Previous relevant Interactively Change Background Image on Scroll User Settings Tutorial is shown below.
If you are a regular reader, youโll know with the web applications presented here, we usually try to allow the user to control โฆ
- how they function โฆ and/or sometimes โฆ
- how they look
โฆ in the ephemeral โthis sessionโ sense, and sometimes follow that up, depending, with recallable settings often calling on window.localStorage or HTTP Cookies, associated with the web browser being used.
Regarding that ephemeral โthis sessionโ sense above, building on the work of yesterdayโs Interactively Change Background Image on Scroll Tutorial, we now allow the user control over defining any/all โฆ
- Background Image source URL
- Refresh delay (in seconds)
- Text Wording
- Text Background Image source URL
โฆ and regarding the use of that last one, weโve decided, somewhat, to take over with the CSS regarding the Text Wording showing through amongst so many โimage interestsโ with various opacities โฆ
var mode='dw';
function preask() {
if (backimg.trim() != '') {
if (backimg.toLowerCase().replace(/\ /g,'') == 'lorempicsum') {
backimg='//picsum.photos/600/400' + suffix + '?random=' + Math.floor(Math.random() * 198765643);
if (mode == 'dw') {
mode='';
document.write('<style> .bg-text { background: linear-gradient(rgba(255,255,255,0.8),rgba(255,255,255,0.8)),URL("' + backimg + '"); background-size: contain; background-repeat: repeat; text-shadow:-2px 2px 2px #ff2d95; opacity: 0.9; } </style>');
} else {
document.getElementById('dstyle').innerHTML+='<style> .bg-text { background: linear-gradient(rgba(255,255,255,0.8),rgba(255,255,255,0.8)),URL("' + backimg + '"); background-size: contain; background-repeat: repeat; text-shadow:-2px 2px 2px #ff2d95; opacity: 0.9; } </style>';
}
backimg='lorempicsum';
} else {
if (mode == 'dw') {
mode='';
document.write('<style> .bg-text { background: linear-gradient(rgba(255,255,255,0.8),rgba(255,255,255,0.8)),URL("' + backimg + '"); background-size: contain; background-repeat: repeat; text-shadow:-2px 2px 2px #ff2d95; opacity: 0.9; } </style>');
} else {
document.getElementById('dstyle').innerHTML+='<style> .bg-text { background: linear-gradient(rgba(255,255,255,0.8),rgba(255,255,255,0.8)),URL("' + backimg + '"); background-size: contain; background-repeat: repeat; text-shadow:-2px 2px 2px #ff2d95; opacity: 0.9; } </style>';
}
}
}
}
Which beggars the observation โฆ
Isnโt the CSS text-shadow property just great?!
We use it more and more often to help out foreground text presented with a lot of โoverlay imageryโ going on behind it.
Here is the Javascript prompt window โblurbโ presented to the user should they want to delve into this woooooorrrrrlllllldddd just by clicking or touching in the non-text part of the webpage โฆ
var ansis=prompt(โOptionally enter in background source URL prefix [โ + prefix + midbit + suffix + โ] ( or type Lorem Picsum or for blog posting images you could try //www.rjmprogramming.com.au/ITblog/โ + sixhundred + โ/โ + fourhundred + โ/ ), hashtag delimited from an optional imagery refresh rate in seconds [โ + ten + โ], hashtag delimited from an optional Text element background image (or type Lorem Picsum), hashtag delimited from optional Text wording [โ + tcont + โ] we will assume involves a space.โ, โ);
โฆ in thechanged interactively_change_background_image_on_scrollhtml web application you can also try below.
Previous relevant Interactively Change Background Image on Scroll Tutorial is shown below.
Regarding todayโs โInteractively Change Background Image on Scrollโ topic, weโd like to thank, profusely, two sources โฆ
- Ideas and Initial Code โฆ W3Schoolโs How TO โ Change Background on Scroll
- Background Image Content โฆ Lorem Picsum
Queue โฆ Lulu (no, not the dog, this time)!
Yes, weโve just added โInteractivelyโ, we hear you say (just maybe, perhaps, a tad sarcastically, shall we say โฆ huh?!!!!). But, itโs the โฆ
- contenteditable=true HTML div (not new by itself โฆ but combined with) โฆ
- text length calculator logic (using an HTML canvas elementโs measureText functionality), thanks to https://stackoverflow.com/questions/31305071/measuring-text-width-height-without-rendering โฆ calling on โฆ
- onkeydown logic โฆ to be a bit savvy regarding the text element width (along with use of innerText and the onblur event logic backup)
โฆ that is all a bit new, at least to us, today, continuing on the recent wonder regarding contenteditable=true, mentioned in the recent Animated GIF SVG Quiz Automation Interaction Tutorial โฆ
And did you know, at least for non-mobile platforms, you can set the focus (on non-mobile platforms only, as there are the โkeyboard getting in the wayโ issues weโre thankful for with mobile platforms which preclude any thoughts of a programmed [element].focus() operation) to one of these โcontenteditable=true style elementsโ? Weโd never been sure, only focussing to HTML input textboxes and textareas up to now, we believe.
โฆ whereby non-mobile focus to a contenteditable=true HTML div type (innerHTML style) element is possible, adding to the original W3Schoolโs content ideas swirling around โฆ
- CSS position: fixed; โฆ for foreground text, in relation to โฆ
- scrolling โฆ with โฆ
- background imagery
โฆ for topics we hope you find as interesting as we did, in our new โproofof conceptโ web application you can also try below โฆ
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.