Yesterdayโs Nostalgia Game External Javascript Iframe CSS Style Tutorial, as shown below, set out with the modest aim โฆ
allow a child HTML iframe webpage calling a particular external Javascript file ... still keep_parent_backgroundjs extending on yesterday's Nostalgia Game External Javascript Iframe CSS Inheritance Tutorial start to proceedings ... be able to change its document.body CSS styling (and perhaps even its parent's (parent.document.body)) via argument calls
โฆ today needs an overhaul to โฆ
allow a child HTML iframe webpage calling a particular external Javascript file ... still keep_parent_backgroundjs extending on yesterday's Nostalgia Game External Javascript Iframe CSS Inheritance Tutorial start to proceedings ... be able to change its
document.body CSS styling (and perhaps even its parent's (parent.document.body)) via argument calls
โฆ to allow for a new mechanism to be now honing in on individual HTML element โฆ
- types
- classes
- IDs
Do the three above sound familiar? Yes, they are the basis of CSS Rules and today, we open up the functionality of our external Javascript to still use style= argument settings, and add to yesterdayโs โฆ
- functionality for inline CSS (ie. via HTML style= parameters) โฆ with โฆ
- functionality for stylesheet CSS
โฆ enabling dynamic CSS definition as if it was all !important and using Javascript DOM to achieve it. How does our web application tell the difference? It looks for โ{โ and โ}โ characters in your style=[someCSSstyleAsYouWouldSeeInHTMLstyleEqualsParameterValues|
someCSSstyleAsYouWouldSeeInCSSstylesheetValues] argument data, and if they exist, you are defining stylesheet CSS, in our web applicationโs view.
As you might imagine there is no way around this needing new purpose built Javascript functions to help out here, for sanityโs sake, but the โtraffic lightโ spot at which this happens in that original external Javascript โone horseโ function is a very simple to arrange a โpeel offโ to the new Javascript function today, as you can see with โฆ
// keep_parent_background.js
// RJM Programming
// May, 2017
// As an HTML iframe child and parent defines document.body background, and the child has not defined background, adopt that parent one as the background
function css_text_processing(fromarg,betweenstyles) {
var i, j, k, cname='',cvalue=' ', cdname='', oneele=null, oneeleset,cnames;
var thisrule="body", therules=["body"];
for (i=0; i<betweenstyles.length; i++) {
betweenstyles[i]=betweenstyles[i].replace(/ !important/g,'').replace(/ !IMPORTANT/g,'').replace(/!important/g,'').replace(/!IMPORTANT/g,'');
if (betweenstyles[i].indexOf("{") != -1) {
thisrule=betweenstyles[i].replace(/\|/g,':').split("{")[0].split("}")[eval(-1 + betweenstyles[i].split("{")[0].split("}").length)].trim();
therules=thisrule.replace(/\ ,\ /g,',').replace(/\ ,/g,',').replace(/,\ /g,',').replace(/,,/g,',').replace(/,,/g,',').split(",");
cname=betweenstyles[i].split("{")[1].trim();
cdname=cname.replace(/\ /g,'').replace(/-a/g,'A').replace(/-b/g,'B').replace(/-c/g,'C').replace(/-d/g,'D').replace(/-e/g,'E').replace(/-f/g,'F').replace(/-g/g,'G').replace(/-h/g,'H').replace(/-i/g,'I').replace(/-j/g,'J').replace(/-k/g,'K').replace(/-l/g,'L').replace(/-m/g,'M').replace(/-n/g,'N').replace(/-o/g,'O').replace(/-p/g,'P').replace(/-q/g,'Q').replace(/-r/g,'R').replace(/-s/g,'S').replace(/-t/g,'T').replace(/-u/g,'U').replace(/-v/g,'V').replace(/-w/g,'W').replace(/-x/g,'X').replace(/-y/g,'Y').replace(/-z/g,'Z');
cvalue=" ";
} else if (i == 0) {
cname=betweenstyles[i].split(";")[eval(-1 + betweenstyles[i].split(";").length)].split("}")[0].trim().split(";")[0];
cdname=cname.replace(/\ /g,'').replace(/-a/g,'A').replace(/-b/g,'B').replace(/-c/g,'C').replace(/-d/g,'D').replace(/-e/g,'E').replace(/-f/g,'F').replace(/-g/g,'G').replace(/-h/g,'H').replace(/-i/g,'I').replace(/-j/g,'J').replace(/-k/g,'K').replace(/-l/g,'L').replace(/-m/g,'M').replace(/-n/g,'N').replace(/-o/g,'O').replace(/-p/g,'P').replace(/-q/g,'Q').replace(/-r/g,'R').replace(/-s/g,'S').replace(/-t/g,'T').replace(/-u/g,'U').replace(/-v/g,'V').replace(/-w/g,'W').replace(/-x/g,'X').replace(/-y/g,'Y').replace(/-z/g,'Z');
} else {
cnames=betweenstyles[eval(-1 + i)].split(";")[eval(-1 + betweenstyles[eval(-1 + i)].split(";").length)].split("}")[0].trim().split(";")[0].split('{');
cname=cnames[eval(-1 + cnames.length)].trim();
cdname=cname.replace(/\ /g,'').replace(/-a/g,'A').replace(/-b/g,'B').replace(/-c/g,'C').replace(/-d/g,'D').replace(/-e/g,'E').replace(/-f/g,'F').replace(/-g/g,'G').replace(/-h/g,'H').replace(/-i/g,'I').replace(/-j/g,'J').replace(/-k/g,'K').replace(/-l/g,'L').replace(/-m/g,'M').replace(/-n/g,'N').replace(/-o/g,'O').replace(/-p/g,'P').replace(/-q/g,'Q').replace(/-r/g,'R').replace(/-s/g,'S').replace(/-t/g,'T').replace(/-u/g,'U').replace(/-v/g,'V').replace(/-w/g,'W').replace(/-x/g,'X').replace(/-y/g,'Y').replace(/-z/g,'Z');
cvalue=betweenstyles[i].split("}")[0].trim().split(";")[0];
}
if (cvalue != " ") {
for (j=0; j<therules.length; j++) {
if (therules[j].toLowerCase().indexOf('~not (') != 0) { // is something
therules[j] = therules[j].split(':')[0].trim();
}
if (therules[j].toLowerCase().indexOf('~not (') == 0) { // not something
therules[j] = therules[j].split('(')[1].split(')')[0].trim();
oneeleset=[];
if (fromarg.indexOf("&sTYLE=") != -1) {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (therules[j].substring(0,1) == '#') {
if (oneeleset[k].id.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].substring(0,1) == '.') {
if (oneeleset[k].className.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('#') != -1) {
if (oneeleset[k].id.toLowerCase() != therules[j].split('#')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('.') != -1) {
if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
} else if (fromarg.indexOf("&Style=") != -1) {
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (therules[j].substring(0,1) == '#') {
if (oneeleset[k].id.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].substring(0,1) == '.') {
if (oneeleset[k].className.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('#') != -1) {
if (oneeleset[k].id.toLowerCase() != therules[j].split('#')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('.') != -1) {
if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
} else {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (therules[j].substring(0,1) == '#') {
if (oneeleset[k].id.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].substring(0,1) == '.') {
if (oneeleset[k].className.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('#') != -1) {
if (oneeleset[k].id.toLowerCase() != therules[j].split('#')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('.') != -1) {
if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (therules[j].substring(0,1) == '#') {
if (oneeleset[k].id.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].substring(0,1) == '.') {
if (oneeleset[k].className.toLowerCase() != therules[j].substring(1).toLowerCase()) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('#') != -1) {
if (oneeleset[k].id.toLowerCase() != therules[j].split('#')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else if (therules[j].indexOf('.') != -1) {
if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
} else {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
}
} else if (therules[j].substring(0,1) == '#') { // single ID
oneele=null;
if (fromarg.indexOf("&sTYLE=") != -1) {
oneele=parent.document.getElementById(therules[j].split('#')[1]);
if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
} else if (fromarg.indexOf("&Style=") != -1) {
oneele=document.getElementById(therules[j].split('#')[1]);
if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
} else {
oneele=parent.document.getElementById(therules[j].split('#')[1]);
if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
oneele=document.getElementById(therules[j].split('#')[1]);
if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
}
} else if (therules[j].substring(0,1) == '.') { // single class
oneeleset=[];
if (fromarg.indexOf("&sTYLE=") != -1) {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
} else if (fromarg.indexOf("&Style=") != -1) {
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
} else {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
}
} else if (therules[j].substring(0,1) == '*') { // everything
oneeleset=[];
if (fromarg.indexOf("&sTYLE=") != -1) {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
} else if (fromarg.indexOf("&Style=") != -1) {
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
} else {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
} else if (therules[j].indexOf('#') != -1) { // single ID
oneele=null;
if (fromarg.indexOf("&sTYLE=") != -1) {
oneele=parent.document.getElementById(therules[j].split('#')[1]);
if (oneele) {
if (oneele.outerHTML.toLowerCase().indexOf('<' + therules[j].split('#')[0].toLowerCase()) == 0) {
eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
}
}
} else if (fromarg.indexOf("&Style=") != -1) {
oneele=document.getElementById(therules[j].split('#')[1]);
if (oneele) {
if (oneele.outerHTML.toLowerCase().indexOf('<' + therules[j].split('#')[0].toLowerCase()) == 0) {
eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
}
}
} else {
oneele=parent.document.getElementById(therules[j].split('#')[1]);
if (oneele) {
if (oneele.outerHTML.toLowerCase().indexOf('<' + therules[j].split('#')[0].toLowerCase()) == 0) {
eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
}
}
oneele=document.getElementById(therules[j].split('#')[1]);
if (oneele) {
if (oneele.outerHTML.toLowerCase().indexOf('<' + therules[j].split('#')[0].toLowerCase()) == 0) {
eval("oneele.style." + cdname + "=\"" + cvalue + "\";");
}
}
}
} else if (therules[j].indexOf('.') != -1) { // single class
oneeleset=[];
if (fromarg.indexOf("&sTYLE=") != -1) {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
}
} else if (fromarg.indexOf("&Style=") != -1) {
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
}
} else {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
}
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (('' + oneeleset[k].className).toLowerCase() == therules[j].split('.')[1].toLowerCase()) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
}
}
} else { // an element type
oneeleset=[];
if (fromarg.indexOf("&sTYLE=") != -1) {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
} else if (fromarg.indexOf("&Style=") != -1) {
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
} else {
oneeleset=parent.document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
oneeleset=document.getElementsByTagName('*');
for (k=0; k<oneeleset.length; k++) {
if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) {
eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";");
}
}
}
}
}
}
}
}
function filterit(sb) {
var outsb=sb, sp;
var pbits=sb.split('{');
if (pbits.length > 1) {
outsb=pbits[0].replace(/:/g,'|');
for (var ij=1; ij<pbits.length; ij++) {
sp=pbits[ij].split('}');
outsb+='{' + sp[0];
if (sp.length > 1) {
outsb+='}' + sp[1].replace(/:/g,'|');
}
}
}
return outsb;
}
function adopt_parent_background_maybe() {
if (parent.document) {
var fromthetop=false;
// Start of more generic ideas regarding passing CSS styling ideas over via ?style=[HTMLstyleString] argument at address bar or at call to external Javascript (ie. this keep_parent_background.js) from parent
var dbs = document.getElementsByTagName('body');
var pdbs = parent.document.getElementsByTagName('body');
var pdhs = parent.document.getElementsByTagName('head');
if (pdhs.length >= 1) {
var passingahih = pdhs[0].innerHTML.split('keep_parent_background.js?');
if (passingahih.length <= 1) {
fromthetop = true;
passingahih = parent.document.URL.split('?');
}
if (passingahih.length > 1) {
var ph = '&' + passingahih[eval(-1 + passingahih.length)].split("'")[0].split('"')[0] + '&';
if (ph.toLowerCase().indexOf('&style=') != -1) {
var sbitsare = decodeURIComponent(ph.replace('&STYLE=','&style=').replace('&sTYLE=','&style=').replace('&Style=','&style=').split('&style=')[1].split('&')[0]);
var aname='',avalue='',thenpartsbits;
var partsbits = filterit(sbitsare.replace(/:not \(/g,'~not (').replace(/:NOT \(/g,'~not (').replace(/:Not \(/g,'~not (')).split(':');
if (sbitsare.indexOf('{') != -1) {
css_text_processing(ph,partsbits);
} else {
for (var iparts=1; iparts<partsbits.length; iparts++) {
aname=partsbits[eval(-1 + iparts)].split(";")[eval(-1 + partsbits[eval(-1 + iparts)].split(";").length)].replace(/\ /g,'').replace(/-a/g,'A').replace(/-b/g,'B').replace(/-c/g,'C').replace(/-d/g,'D').replace(/-e/g,'E').replace(/-f/g,'F').replace(/-g/g,'G').replace(/-h/g,'H').replace(/-i/g,'I').replace(/-j/g,'J').replace(/-k/g,'K').replace(/-l/g,'L').replace(/-m/g,'M').replace(/-n/g,'N').replace(/-o/g,'O').replace(/-p/g,'P').replace(/-q/g,'Q').replace(/-r/g,'R').replace(/-s/g,'S').replace(/-t/g,'T').replace(/-u/g,'U').replace(/-v/g,'V').replace(/-w/g,'W').replace(/-x/g,'X').replace(/-y/g,'Y').replace(/-z/g,'Z');
avalue=(partsbits[iparts] + ";").split(";")[0].trim();
if (fromthetop) {
if (ph.indexOf("&sTYLE=") != -1) {
eval("parent.document.body.style." + aname + "=\"" + avalue + "\";");
} else if (ph.indexOf("&Style=") != -1) {
eval("document.body.style." + aname + "=\"" + avalue + "\";");
} else {
eval("parent.document.body.style." + aname + "=\"" + avalue + "\";");
eval("document.body.style." + aname + "=\"" + avalue + "\";");
}
} else {
eval("document.body.style." + aname + "=\"" + avalue + "\";");
}
}
}
}
}
// Specifically, any background image of parent declared within the HTML body tag is inherited by child iframe calling this external Javascript keep_parent_background.js
if (pdbs[0].outerHTML) {
var parent_style_bits=pdbs[0].outerHTML.split('>')[0].split(' style="');
if (parent_style_bits.length > 1) {
var parent_style=(";" + parent_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';');
if (parent_style.toLowerCase().indexOf(";background") != -1) {
if (dbs[0].outerHTML) {
var self_style_bits=dbs[0].outerHTML.split('>')[0].split(' style="');
if (self_style_bits.length > 1) {
var self_style=(";" + self_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';');
if (self_style.toLowerCase().indexOf(";background") == -1 || 1 == 1) {
if (parent_style.toLowerCase().indexOf(";background-color:") != -1) {
document.body.style.backgroundColor=parent_style.toLowerCase().split(";background-color:")[1].split(";")[0].trim();
}
}
if (self_style.toLowerCase().indexOf("url(") == -1) {
if (parent_style.toLowerCase().indexOf("url(") != -1) {
var pd=parent.document;
var parifs=pd.getElementsByTagName('iframe');
for (var iparifs=0; iparifs<parifs.length; iparifs++) {
if (parifs[iparifs].contentWindow === window || parifs.length == 1) { // idea here via //stackoverflow.com/questions/4691718/determine-current-own-iframe
var stylebits = parifs[iparifs].getBoundingClientRect();
document.body.style.backgroundPosition=('' + eval(0 - eval(('' + stylebits.left).replace('px','')))).split('.JUNXK')[0] + 'px' + (' ' + eval(0 - eval(('' + stylebits.top).replace('px','')))).split('.JUNXK')[0] + 'px';
}
}
document.body.style.backgroundImage="url('" + parent_style.replace('URL(','url(').replace('Url(','url(').split("url(")[1].split(")")[0].replace("'","").replace("'","").replace("'","").replace("'","").replace(""","").replace(""","") + "')";
}
}
}
}
}
}
}
}
}
setTimeout(adopt_parent_background_maybe, 2000);
Weโll leave you with the Javascript code changes for todayโs work with keep_parent_backgroundjsโs changesfor this. The upshot of these changes are that you could have an endless variety of live run variations using the address bar URL argument method for style=[someCSSstyleAsYouWouldSeeInHTMLstyleEqualsParameterValues|
someCSSstyleAsYouWouldSeeInCSSstylesheetValues] โฆ
- style=border:12px dotted pink parent and child body elements
- style=select { border:12px dotted pink; } parent and child select elements
- sTYLE=border:12px dotted orange just parent body element
- sTYLE=#myiframe { border:12px dotted orange; } just parent id=myiframe element
- Style=border:12px dashed red just child body element
- Style=:not (.emoji) { border:12px dashed red; } just child not class=emoji elements
- style=border:22px solid blue;opacity:0.4 parent and child body elements
- style=* { border:22px solid blue;opacity:0.4; } parent and child all elements
Previous relevant Nostalgia Game External Javascript Iframe CSS Style Tutorial is shown below.
Weโre keen on doing CSS styling in amongst the HTML via style= parameter settings (sometimes termed โinline CSSโ). Please donโt think that this approach is as popular as creating stylesheets and external CSS file maintainance. And believe me, I understand that approach, and weโll be talking about dealing with that more accepted approach in tutorials soon to come. However (and isnโt there always an Howevvvvvverrrr?!) as CSS styling is allowed in HTML it is neither here nor there whether it is popular or not, if you want to get โfull coverageโ with todayโs plan to โฆ
allow a child HTML iframe webpage calling a particular external Javascript file ... still keep_parent_backgroundjs extending on yesterday's Nostalgia Game External Javascript Iframe CSS Inheritance Tutorial start to proceedings ... be able to change its document.body CSS styling (and perhaps even its parent's (parent.document.body)) via argument calls
โฆ we need to be able to cater for both scenarios of โฆ
- CSS styling achieved with HTML via style= parameter settings โฆ and โฆ
- CSS styling achieved via CSS stylesheet internally defined or externally defined
โฆ but it just so happens we โinchโ along (or โcentimetreโ along, for you non-avoirdupoisians) by first tackling the first of the two scenarios above.
Some projects are more in the thought planning than the coding and unit testing, but we find a lot the other way around. Todayโs โphaseโ of progression does well in the planning, we think. How so? Well, when we coded it, we were trepidatious about there being two โargument passingโ ideas that we should cater for โฆ
- argument passing via the parentโs call of todayโs external Javascript
- argument passing via the parent.document.URL (in our mind, equivalent to top.document.URL, in our mind, equivalent to the web browser address bar URL)
โฆ via an argument that goes style=[someCSSstyleAsYouWouldSeeInHTMLstyleEqualsParameterValues] โฆ and we thought these would cause twice the (additional) code, but really only amount to a small โifโ section different โฆ and when that sort of thing happens, we figure, the design is pretty good โฆ
// keep_parent_background.js
// RJM Programming
// May, 2017
// As an HTML iframe child and parent defines document.body background, and the child has not defined background, adopt that parent one as the background
function adopt_parent_background_maybe() {
if (parent.document) {
var fromthetop=false;
// Start of more generic ideas regarding passing CSS styling ideas over via ?style=[HTMLstyleString] argument at address bar or at call to external Javascript (ie. this keep_parent_background.js) from parent
var dbs = document.getElementsByTagName('body');
var pdbs = parent.document.getElementsByTagName('body');
var pdhs = parent.document.getElementsByTagName('head');
if (pdhs.length >= 1) {
var passingahih = pdhs[0].innerHTML.split('keep_parent_background.js?');
if (passingahih.length <= 1) {
fromthetop = true;
passingahih = parent.document.URL.split('?');
}
if (passingahih.length > 1) {
var ph = '&' + passingahih[eval(-1 + passingahih.length)].split("'")[0].split('"')[0] + '&';
if (ph.toLowerCase().indexOf('&style=') != -1) {
var sbitsare = decodeURIComponent(ph.replace('&STYLE=','&style=').replace('&sTYLE=','&style=').replace('&Style=','&style=').split('&style=')[1].split('&')[0]);
var aname='',avalue='',thenpartsbits, partsbits = sbitsare.split(':');
for (var iparts=1; iparts<partsbits.length; iparts++) {
aname=partsbits[eval(-1 + iparts)].split(";")[eval(-1 + partsbits[eval(-1 + iparts)].split(";").length)].replace(/\ /g,'').replace(/-a/g,'A').replace(/-b/g,'B').replace(/-c/g,'C').replace(/-d/g,'D').replace(/-e/g,'E').replace(/-f/g,'F').replace(/-g/g,'G').replace(/-h/g,'H').replace(/-i/g,'I').replace(/-j/g,'J').replace(/-k/g,'K').replace(/-l/g,'L').replace(/-m/g,'M').replace(/-n/g,'N').replace(/-o/g,'O').replace(/-p/g,'P').replace(/-q/g,'Q').replace(/-r/g,'R').replace(/-s/g,'S').replace(/-t/g,'T').replace(/-u/g,'U').replace(/-v/g,'V').replace(/-w/g,'W').replace(/-x/g,'X').replace(/-y/g,'Y').replace(/-z/g,'Z');
avalue=(partsbits[iparts] + ";").split(";")[0].trim();
if (fromthetop) {
if (ph.indexOf("&sTYLE=") != -1) {
eval("parent.document.body.style." + aname + "=\"" + avalue + "\";");
} else if (ph.indexOf("&Style=") != -1) {
eval("document.body.style." + aname + "=\"" + avalue + "\";");
} else {
eval("parent.document.body.style." + aname + "=\"" + avalue + "\";");
eval("document.body.style." + aname + "=\"" + avalue + "\";");
}
} else {
eval("document.body.style." + aname + "=\"" + avalue + "\";");
}
}
}
}
// Specifically, any background image of parent declared within the HTML body tag is inherited by child iframe calling this external Javascript keep_parent_background.js
if (pdbs[0].outerHTML) {
var parent_style_bits=pdbs[0].outerHTML.split('>')[0].split(' style="');
if (parent_style_bits.length > 1) {
var parent_style=(";" + parent_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';');
if (parent_style.toLowerCase().indexOf(";background") != -1) {
if (dbs[0].outerHTML) {
var self_style_bits=dbs[0].outerHTML.split('>')[0].split(' style="');
if (self_style_bits.length > 1) {
var self_style=(";" + self_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';');
if (self_style.toLowerCase().indexOf(";background") == -1 || 1 == 1) {
if (parent_style.toLowerCase().indexOf(";background-color:") != -1) {
document.body.style.backgroundColor=parent_style.toLowerCase().split(";background-color:")[1].split(";")[0].trim();
}
}
if (self_style.toLowerCase().indexOf("url(") == -1) {
if (parent_style.toLowerCase().indexOf("url(") != -1) {
var pd=parent.document;
var parifs=pd.getElementsByTagName('iframe');
for (var iparifs=0; iparifs<parifs.length; iparifs++) {
if (parifs[iparifs].contentWindow === window || parifs.length == 1) { // idea here via //stackoverflow.com/questions/4691718/determine-current-own-iframe
var stylebits = parifs[iparifs].getBoundingClientRect();
document.body.style.backgroundPosition=('' + eval(0 - eval(('' + stylebits.left).replace('px','')))).split('.JUNXK')[0] + 'px' + (' ' + eval(0 - eval(('' + stylebits.top).replace('px','')))).split('.JUNXK')[0] + 'px';
}
}
document.body.style.backgroundImage="url('" + parent_style.replace('URL(','url(').replace('Url(','url(').split("url(")[1].split(")")[0].replace("'","").replace("'","").replace("'","").replace("'","").replace(""","").replace(""","") + "')";
}
}
}
}
}
}
}
}
}
setTimeout(adopt_parent_background_maybe, 2000);
โฆ and so weโll leave you with the Javascript code changes for todayโs work with keep_parent_backgroundjs. The upshot of these changes are that you could have an endless variety of live run variations using the address bar URL argument method โฆ
- style=border:12px dotted pink parent and child
- sTYLE=border:12px dotted orange just parent
- Style=border:12px dashed red just child
- style=border:22px solid blue;opacity:0.4 parent and child
Previous relevant Nostalgia Game External Javascript Iframe CSS Inheritance Tutorial is shown below.
Yesterdayโs aesthetically motivated Nostalgia Game Gimp Tutorial as shown below, got us thinking about โฆ
- CSS styling
- child HTML iframe CSS styling
- background images in webpages
- background images in child HTML iframe โinheritingโ CSS styling
โฆ and hope you can see the progression of thinking up to that last one, which maybe pulled you up with a wooooaahh! Yes, CSS inheritance in a child HTML iframe webpage from a parent webpage, regarding background image work, is not a default inheritance scenario, because an HTML iframe โchildโ webpage, is, to all intents and purposes, another (brand new) webpage in the โeyesโ of the web browser.
Okay, be that as it may, what could help with facilitating that final list entry thought above? Well, we can think of, just quickly โฆ
- getting the child iframe webpage โcallโ the same stylesheets as the parent, having set both up to be predominantly working their styling via CSS styling (be that via internal <style></style> styling or external stylesheet file styling) โฆ or โฆ
- use Javascript DOM (be that via internal <script></script> scripting or external Javascript file scripting)
โฆ and for two reasons we plump for the second of those, and lean towards the external Javascript thoughts within that option, because โฆ
- the Nostalgia web application mainly styles via style property of its HTML โฆ and โฆ
- it is less dependent on the nature of the parent, and its โmotivesโ if you will, to use Javascript DOM to do this โฆ and a contination of that thinking is that โฆ
- an external Javascript file is a more generic approach than internal Javascript scripting
- an external Javascript file can be called in a variety of ways to make it tailorable, to add to genericity, as this project progresses โฆ this is just our first draft of an idea, just, at this stage, relating to webpage background image management
โฆ to help have a coding design with increased genericity and flexibility (especially regarding future thinking)
So how does the โfirst draftโ external Javascript keep_parent_backgroundjs get used in a child HTML iframe webpage today? Well, we pick, as the guinea pig idea to fit in with our recent Nostalgia web application, its child HTML iframe webpage partner karaoke_youtube_api
htm (changed inthis miniscule way) and place up into its header section between <head> and </head> โฆ
<script type='text/javascript' src='keep_parent_background.js'></script>
โฆ and that external Javascript does not work off any document.body onload event logic, but rather, a Javascript timed setTimeout function scenario. To see what we mean with all this, try this liverun link.
See this โfirst draftโ external Javascript below โฆ
// keep_parent_background.js
// RJM Programming
// May, 2017
// As an HTML iframe child and parent defines document.body background, and the child has not defined background, adopt that parent one as the background
function adopt_parent_background_maybe() {
if (parent.document.body.outerHTML) {
var parent_style_bits=parent.document.body.outerHTML.split('>')[0].split(' style="');
if (parent_style_bits.length > 1) {
var parent_style=(";" + parent_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';');
if (parent_style.toLowerCase().indexOf(";background") != -1) {
if (document.body.outerHTML) {
var self_style_bits=document.body.outerHTML.split('>')[0].split(' style="');
if (self_style_bits.length > 1) {
var self_style=(";" + self_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';');
if (self_style.toLowerCase().indexOf(";background") == -1 || 1 == 1) {
if (parent_style.toLowerCase().indexOf(";background-color:") != -1) {
document.body.style.backgroundColor=parent_style.toLowerCase().split(";background-color:")[1].split(";")[0].trim();
}
}
if (self_style.toLowerCase().indexOf("url('") == -1) {
if (parent_style.toLowerCase().indexOf("url('") != -1) {
var parifs=parent.document.getElementsByTagName('iframe');
for (var iparifs=0; iparifs<parifs.length; iparifs++) {
if (parifs[iparifs].contentWindow === window) { // idea here via //stackoverflow.com/questions/4691718/determine-current-own-iframe
var stylebits = parifs[iparifs].getBoundingClientRect();
document.body.style.backgroundPosition=('' + eval(0 - eval(('' + stylebits.left).replace('px','')))).split('.JUNXK')[0] + 'px' + (' ' + eval(0 - eval(('' + stylebits.top).replace('px','')))).split('.JUNXK')[0] + 'px';
}
}
document.body.style.backgroundImage="url('" + parent_style.replace('URL(','url(').replace('Url(','url(').split("url('")[1].split("'")[0] + "')";
}
}
}
}
}
}
}
}
setTimeout(adopt_parent_background_maybe, 2000);
โฆ featuring, today, as with WordPress 4.1.1โs Nostalgia Game External Javascript Iframe CSS Inheritance Tutorial โฆ
- an idea to identify the parent enclosing HTML iframe element of a parent webpage from the viewpoint of the child HTML iframe webpageโs external Javascript thanks to ideas of this great webpage, thanks
- use of document.body.style.backgroundPosition (like we did in blog posting thread headed by Legend for and from HTML Map Element Web Server Tutorial) is called into play to correctly position the โparent inheritedโ background image into the child HTML iframe element, the suitable offsets being the โnegativesโ of the HTML parent iframe elementโs top and left point, calculated using the Javascript method [ourIframeElementObject].getBoundingClientRectโs .top and .left values
Previous relevant Nostalgia Game Gimp Tutorial is shown below.
Aesthetically, a web application has many and varied โinputsโ, some of the main being for us โฆ
- the media resources you add to it
- the stylesheet CSS โsmartsโ you add to it
- at a user experience (or UX) level, how user friendly the web application is, as a combination of HTML and Javascript client code
- the data available to the web application, managed by HTML and Javascript and perhaps server side code like PHP
โฆ because โaestheticsโ is the look of something, but โlookโ is a lot like โfeelโ and, at least for us, we think โlookโ and โfeelโ (and โhearโ for that matter) when we think software application โaestheticsโ.
Our emphasis at this โblogโ on the theme of web applications tilts strongly towards the โhowโ of the workings of software code and so we tend to most neglect those first two โinputsโ above. Occasionally, though, it is good to get out of the comfort zone, and if the project is apt for it, we like to, regarding those first two โinputsโ above โฆ
- the media resources you add to it
- capture the media
- use email to send the media to a place where applications can be used to modify the media, as required
- modify the media, as required, via applications
- send the media to the public website for โpublicationโ
- the stylesheet CSS โsmartsโ you add to it
- style the webpage to place that media above
- attend to the effects of having that media, on other styling aspects of the webpage, and other Javascript logic aspects to the webpage, and design aspects to the webpage
Before we go on and show you our โaestheticโ changes, in a step by step replay of what we did to our web application, we started with Nostalgia Game Primer Tutorial we need to talk a bit about how these first two โinputsโ could fit into the work of a middle sized web agency โฆ
- a graphic designer could create the โmedia resourcesโ the web agency needs, and may never need to get involved with CSS, but they might, also
- a frontend web developer could take that media from the graphic designer and โaestheticallyโ make that media work and/or follow a design system (to make it work), like wireframes (a webpage schematic or screen blueprint)
โฆ a workflow that could keep worker skills separated, as required. We say this, because the skills of a graphic designer would be great to have as a frontend web developer but in a busy middle sized web agency office, sounds like too distracting a scenario for any one employee, in our opinion. Our opinion comes from a small sized web agency where I am no graphic designer (in the true sense of the job) but know what it takes to create image media, at least on this MacBook Pro, from a variety of desktop applications โฆ
- Paintbrush โฆ yes, Mac OS X version of Paintbrush โฆ really good for File -> New from Clipboard and moving Pasted clipboard data quickly, Resizing, Horizontal Flip, Vertical Flop, rudimentary Cropping, panning โbigger thanโ image data into a small rectangular position (which is size set aside for the image), Cut, Copy, Rectangular Selects, rudimentary Annotations via lines and circles, Jpeg density
- Grab (read about this โdynamic duoโ (for us) at Paintbrush and Grab Primer Tutorial) or Mac OS X command โ control โ shift 3 or 4 clipboard screen capture or command โ shift 3 or 4 for desktop save of screen capture
- Preview โฆ good for Copy, Paste, 90 degree rotations, Export as PDF
- Gimp โฆ good for Layers, Opacity, Move tool, Rotation tool, Scale tool, Resizing, lots of Filters, Rectangular and Freeform Selections, lots of Export options
โฆ which brings us to the creation of the image media file โฆ
- took photos of Nostalgia realia (old football photo and some photograph albums) in a series of 6 photos (3 used) with an iPhoneโs Camera (in Photo mode)
- used the iPhoneโs Photos app to Select the six images and Share this to the Mail icon, sending in Small density mode, as the resolution for our job is not supercritical, and you will be able to fit 6 images as attachments in the one email if sent in Small density mode
- from now on, on MacBook Pro, open the Gmail web application and download all 6 image attachments to the Downloads folder
- in Finder, open the image of the football team, and via two finger gesture Open Withโฆ Preview
- open Paintbrush and File -> Open a previous tutorial image that we Edit -> Select All then Edit -> Cut and File -> Save Asโฆ nostalgia.png
- in Preview, rotate image to the left 90 degrees to make it straight, and Edit -> Copy it to clipboard
- back at Paintbrush use File -> New from Clipboard to create new image that we resize 300% width and 300% height and Edit -> Select All and Edit -> Copy
- in Paintbrush we File -> Open โnostalgia.pngโ and Edit -> Paste and File -> Save โฆ nostalgia.png
- open Gimp and File -> Open nostalgia.png
- in Gimp at Layer window for the one Layer (so far) called โnostalgia.pngโ change Opacity from 100.0 to 53.0
- in Finder, open the second image of photo album of black and white photos, and via two finger gesture Open Withโฆ Preview
- in Preview, rotate image to the left 90 degrees to make it straight, and Edit -> Copy it to clipboard
- back at Paintbrush use File -> New from Clipboard to create new image that we resize 200% width and 200% height and Edit -> Select All and Edit -> Copy
- in Gimp use Edit-> Paste Asโฆ New Layer and the clipboard fully opaque clipboard image falls into its own layer called โClipboardโ
- in Gimp use Move tool to move the fully opaque clipboard โClipboardโ image over to the right more
- in Gimp at Layer window in the Layer called โClipboardโ change Opacity from 100.0 to 47.0
- in Gimp use Rotate tool to rotate the Layer โClipboardโ appropriately
- in Finder, open the second image of photo album of colour photos, and via two finger gesture Open Withโฆ Preview
- in Preview, rotate image to the left 90 degrees to make it straight, and Edit -> Copy it to clipboard
- back at Paintbrush use File -> New from Clipboard to create new image that we resize 250% width and 250% height and Edit -> Select All and Edit -> Copy
- in Gimp use Edit-> Paste Asโฆ New Layer and the clipboard fully opaque clipboard image falls into its own layer called โClipboard #1โ
- in Gimp use Move tool to move the fully opaque clipboard โClipboard #1โ image over to the right more
- in Gimp at Layer window in the Layer called โClipboard #1โ change Opacity from 100.0 to 55.0
- in Gimp use Rotate tool to rotate the Layer โClipboard #1โ appropriately
- in Gimp use File -> Export As โnostalgia.pngโ to override its contents, and end up with image above and we โฆ
- send โnostalgia.pngโ to RJM Programming website via FileZilla (s)ftp protocol file transfer to same folder as nostalgia.htm
โฆ and the use we make of the image media file โnostalgia.pngโ within the HTML and Javascript and CSS nostalgiahtm via the bold CSS styling with the HTML as per โฆ
- set โnostalgia.pngโ as the nostalgia
htm background image behind a background colour transparent default document.body styling scenario โฆ
<body style="background-color:transparent;background: url('nostalgia.png');"> - give โnostalgia.pngโ a change to show a bit under the YouTube video player HTML iframe element but not stop the YouTube video being seen comfortably โฆ
<iframe id='myiframe' src='//www.rjmprogramming.com.au/HTMLCSS/karaoke_youtube_api.htm?emoji=on&nokaraoke=y&youtubeid=%20%20%20%20%20%20%20%20%20%20%20%20%20%20Putt%20Putt%20Golf%2c%20Ermington' style="display:block;width:100%;height:900px;opacity:0.8;"></iframe>
โฆ the changes of which can be seen with thisreport (for this liverun).
Previous relevant Nostalgia Game Primer Tutorial is shown below.
Was sad to hear of the closing of Ermington Putt Putt Golf the other day. Maybe Putt Putt Golf is on the cheesy side, but it is sad to see innocent entertainments like this go in the community, especially regarding great places for childrenโs birthday parties, as was the case for us the time we got 10 over par (if we fudge the scorecard just a little bit). So 30th April is its last day, sadly. Remember, as kids, my brother and I climbing the โmountainโ (=200 mole hills) at Mermaid Beach Putt Putt, rather than paying for the chairlift, to get up to the Putt Putt Golf there.
Then yesterdayโs Variety Italian Style got me to thinking โNostalgiaโ big time โฆ Mario Milano, Bugs Bunny, school holidays etcetera etceterayada yada, so decided to write a web application channelling โฆ
- YouTube video via its Embedded Iframe API โฆ and/or โฆ
- Google search
โฆ to offer users of our HTML and Javascript web application liverunโs underlying nostalgia
html source code, for your perusal.
Naturally, youโre likely to go โฆ whaaaaatttt โฆ at a lot of the nostalgia reminiscence suggestions that sprung to my mind โฆ a lot by free association โฆ but there is an option there for you to enter in your own โNostalgia Search Topicโ should you want it to be looked up on the huge world wide web resources that YouTube and Google are โฆ thanks.
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.
If this was interesting you may be interested in this too.