{"id":25728,"date":"2016-10-17T03:01:53","date_gmt":"2016-10-16T17:01:53","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=25728"},"modified":"2016-10-16T20:09:04","modified_gmt":"2016-10-16T10:09:04","slug":"html-style-mapping-tool-refinement-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/html-style-mapping-tool-refinement-tutorial\/","title":{"rendered":"HTML Style Mapping Tool Refinement Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emojislideshow.htm\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML Style Mapping Tool Refinement Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles_refined.jpg\" title=\"HTML Style Mapping Tool Refinement Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML Style Mapping Tool Refinement Tutorial<\/p><\/div>\n<p>We&#8217;re continuing on with a new web application tool idea today, an external Javascript tool that when applied to a webpage, <a onclick=\" document.getElementById('qpcomzm').style.display='inline'; document.getElementById('scomzm').style.display='inline';  \" style=\" text-decoration:underline; cursor: pointer; \"><font color=blue;>or not<\/font><\/a>, between &lt;head&gt; and &lt;\/head&gt; via &#8230;<\/p>\n<p><code><br \/>\n&lt;<span id='qpcomzm' style='display:none;color:blue;'>!--<\/span>script type='text\/javascript' src='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.js'&gt;&lt;\/script<span id='scomzm' style='display:none;color:blue;'>--<\/span>&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; that allows you to dynamically map some aspects of an HTML element&#8217;s style onto others.<\/p>\n<p>So, starting with the Javascript function &#8220;copyTextareaStyling&#8221; featuring in the <a title='HTML Textarea and Div Talents Primer Tutorial' href='#htadtpt'>HTML Textarea and Div Talents Primer Tutorial<\/a> as a starting point we&#8217;ve refined the functionality with our tool.  Yesterday we had our &#8220;tool&#8221; just differentiating by HTML element <i>type<\/i> but today we allow <a target=_blank title='window.getComputedStyle information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/getComputedStyle'>window.getComputedStyle()<\/a> to delve into CSS styling you&#8217;ve defined.  The web application <i>window<\/i> object&#8217;s <a target=_blank title='window.getComputedStyle information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/getComputedStyle'>window.getComputedStyle()<\/a> can &#8220;delve&#8221; so much better than Javascript DOM in this scenario, scouring CSS things floating above the <i>document<\/i> object of a webpage, and we show this in today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles_refined.jpg\">tutorial picture<\/a> today regarding the HTML h4 id=&#8221;myh4&#8243; element that has the CSS styling below &#8230;<\/p>\n<p><code><br \/>\n&lt;style&gt;<br \/>\n#myh4 { border: 5px solid lightgreen; }<br \/>\n&lt;\/style&gt;<br \/>\n<\/code><\/p>\n<p>On this point, have you noticed that there is an implied &#8220;window.&#8221; prefix to any &#8220;document.getElementById&#8221;?  In other words you can say &#8220;window.document.getElementById&#8221; and if in an HTML iframe looking back up to the parent you could say &#8220;parent.document.getElementById&#8221; (or very likely &#8220;top.document.getElementById&#8221;).  Well, these ideas form the heart and soul of the new &#8220;tool&#8221; today that has this changed external Javascript programming source you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.js-GETME\" title='meld_styles.js'>meld_style.js<\/a>, modified in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.js-GETME\" title='meld_styles.js'>this way<\/a>, and which you can try out because we have <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emojislideshow.htm\">here<\/a> a Random Emoji Slideshow to enable you to try this &#8220;tool&#8221;.<\/p>\n<p>Here&#8217;s a video (that we created using the &#8220;New Screen Recording&#8221; functionality of <a target=_blank title='QuickTime information from Apple' href='https:\/\/support.apple.com\/downloads\/quicktime'>QuickTime Player<\/a> using Mac OS X on a MacBook Pro laptop) we took of a &#8220;specially modified code&#8221; session of &#8220;Random Emoji Slideshow&#8221; and using this new functionality, reflected by this HTML and Javascript and CSS <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emojislideshow.html-GETME\">emojislideshow.htm<\/a> modified from yesterday in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emojislideshow.html-GETME\">this way<\/a> with this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emojislideshow.htm\">live run<\/a>, for you to peruse at your leisure &#8230;<\/p>\n<p><video width=\"100%\" controls=\"true\"><source src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.m4v\"\/><\/video><\/p>\n<p>We hope you try this CSS mapping &#8220;tool&#8221; yourself, and\/or it gets you thinking of one you write yourself.<\/p>\n<hr>\n<p id='hsmtpt'>Previous relevant <a target=_blank title='HTML Style Mapping Tool Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/html-style-mapping-tool-primer-tutorial\/'>HTML Style Mapping Tool Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emojislideshow.htm\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML Style Mapping Tool Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.jpg\" title=\"HTML Style Mapping Tool Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML Style Mapping Tool Primer Tutorial<\/p><\/div>\n<p>We&#8217;re having a first go at a new web application tool idea today, an external Javascript tool that when applied to a webpage, <a onclick=\" document.getElementById('qpcomzm').style.display='inline'; document.getElementById('scomzm').style.display='inline';  \" style=\" text-decoration:underline; cursor: pointer; \"><font color=blue;>or not<\/font><\/a>, between &lt;head&gt; and &lt;\/head&gt; via &#8230;<\/p>\n<p><code><br \/>\n&lt;<span id='qpcomzm' style='display:none;color:blue;'>!--<\/span>script type='text\/javascript' src='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.js'&gt;&lt;\/script<span id='scomzm' style='display:none;color:blue;'>--<\/span>&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; allows you to dynamically map some aspects of an HTML element&#8217;s style onto others.<\/p>\n<p>So far, with our prototype &#8220;tool&#8221; we only allow elements to have styling mapped from, be those with a non-blank <i>innerHTML<\/i> property, but we&#8217;ll see over time if this opens up &#8230; am not sure.<\/p>\n<p>Maybe you remember the Javascript function &#8220;copyTextareaStyling&#8221; featuring in the <a title='HTML Textarea and Div Talents Primer Tutorial' href='#htadtpt'>HTML Textarea and Div Talents Primer Tutorial<\/a> as shown below?  Well, that formed the heart and soul of the new &#8220;tool&#8221; today that has this external Javascript programming source you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.js_GETME\" title='meld_styles.js'>meld_style.js<\/a> and which you can try out because we have <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emojislideshow.htm\">here<\/a> a Random Emoji Slideshow to enable you to try this &#8220;tool&#8221;.<\/p>\n<hr>\n<p id='htadtpt'>Previous relevant <a target=_blank title='HTML Textarea and Div Talents Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/html-textarea-and-div-talents-primer-tutorial\/'>HTML Textarea and Div Talents Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML Textarea and Div Talents Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.jpg\" title=\"HTML Textarea and Div Talents Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML Textarea and Div Talents Primer Tutorial<\/p><\/div>\n<p>We faced a dilemma today with the name of our web application, and ended up with <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.html-GETME\" title='textarea_talent.html'>textarea_talent.html<\/a> (along with its business logic external Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.js_GETME\" title='textarea_talent.js'>textarea_talent.js<\/a>), but as the project went along we were torn towards a name of <i>div_talent.html<\/i> and <i>div_talent.js<\/i> as we shall explain below.<\/p>\n<p>We understand the great role the HTML <a target=_blank title='HTML textarea tag information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tag_textarea.asp'>textarea<\/a> element has in <a target=_blank title='Content Management System information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Content_management_system'>CMS<\/a> (Content Management Systems) work, and we illustrate this below with (a) WordPress (blog as an example) &#8230;<\/p>\n<p><img src='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.jpeg'><\/img><\/p>\n<p>It&#8217;s crucial for getting HTML or non-caretted Text (that is internally turned into HTML behind the scenes) &#8230; via those <a target=_blank title='Excel Online Spreadsheet Monthly Planner Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/excel-online-spreadsheet-monthly-planner-primer-tutorial\/'>wonderful<\/a> <a target=_blank title='Tab navigation button or panel information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Tab_(GUI)'>tabs<\/a> &#8230; off the user and onto the MySql database, and then out to the client user as part of a webpage.  Out at that webpage, though, we&#8217;ve no doubt this content is embedded in an HTML <a target=_blank title='HTML div tag information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tag_div.asp'>div<\/a> element, the other &#8220;talent&#8221; here.<\/p>\n<p>But their strengths and weaknesses go like this, at least to us, in the limited HTML text view of things &#8230;<\/p>\n<table border=100>\n<tr>\n<th>Text Functionality Issue<\/th>\n<th>HTML Element Type<\/th>\n<th>Strength<\/th>\n<th>Weakness (where a &#8220;Yes&#8221; is like &#8230; &#8220;Oh No!&#8221;)<\/th<\/tr>\n<tr>\n<td rowspan=2>Display Monocolour Text<\/td>\n<td>Textarea<\/th>\n<td>Yes<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Div<\/th>\n<td>Yes<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td rowspan=2>Display Editable Text<\/td>\n<td>Textarea<\/th>\n<td>Yes<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Div<\/th>\n<td><\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<tr>\n<td rowspan=2>Display Multicolour Text<\/td>\n<td>Textarea<\/th>\n<td><\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Div<\/th>\n<td>Yes<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<\/table>\n<p>Our web application today is like an inhouse version of (a web browser) View Page Source type of arrangement, but allowing, optionally, for the highlighting of words.  The &#8220;highlighting of words&#8221; functionality needed the HTML div element to come into the equation, otherwise the &#8220;talents&#8221; of an HTML textarea element would have sufficed, and are normally preferred, for those editing reasons.  By the way, an HTML textarea element given a <a target=_blank title='HTML textarea element readonly property' href='http:\/\/www.w3schools.com\/tags\/att_textarea_readonly.asp'><i>readonly<\/i><\/a> property stops the user changing an HTML textarea element&#8217;s contents, should that be what you require.<\/p>\n<p>Another issue came into play as a &#8220;subtheme&#8221; of today&#8217;s tutorial.  Are you aware that some HTML elements, such as &#8230;<\/p>\n<blockquote><p>\nTextarea elements do not, by default, inherit CSS styling settings of the webpage Body element\n<\/p><\/blockquote>\n<p> &#8230; which means, without Javascript DOM programmatic intervention the text shown in an HTML textarea element will differ greatly in its appearance to that of an HTML div element.  This annoyed us enough to warrant some research and development on this topic and found that the idea to have both HTML div and textarea elements to be mapped to the inherited look of the HTML body element, that you might attempt to do via CSS like &#8230;<\/p>\n<p><code><br \/>\n&lt;style&gt;<br \/>\ntextarea, div {<br \/>\n font-family: inherit;<br \/>\n font-size: inherit;<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; was not nearly so effective a thing to do, as to put in the hard yards to &#8220;purloin&#8221; the styling characteristics of one HTML element type and &#8220;slap&#8221; those characteristics, via Javascript DOM, onto the other HTML element type of interest, via code (snippet) like used today (with its &#8220;thank you&#8221; implied link), as per &#8230;<\/p>\n<p><code><br \/>\nfunction copyTextareaStyling() {<br \/>\n    var output = document.getElementById(\"tarea\"), divelem = document.getElementById(\"tareadiv\");<br \/>\n    if (divelem) { \/\/ thanks to ideas off <a target=_blank title='Useful link, thanks' href='http:\/\/stackoverflow.com\/questions\/12266320\/copy-div-content-to-textarea-or-text-with-the-same-font-family-style'>http:\/\/stackoverflow.com\/questions\/12266320\/copy-div-content-to-textarea-or-text-with-the-same-font-family-style<\/a><br \/>\n      divelem.style.fontFamily = window.getComputedStyle(output,null).fontFamily || output.style.fontFamily || output.currentStyle.getCurrentProperty('font-family');<br \/>\n      divelem.style.fontSize = window.getComputedStyle(output,null).fontSize || output.style.fontSize || output.currentStyle.getCurrentProperty('font-size');<br \/>\n      divelem.style.border = window.getComputedStyle(output,null).border || output.style.border || output.currentStyle.getCurrentProperty('border');<br \/>\n      divelem.style.padding = window.getComputedStyle(output,null).padding || output.style.padding || output.currentStyle.getCurrentProperty('padding');<br \/>\n      divelem.style.margin = window.getComputedStyle(output,null).margin || output.style.margin || output.currentStyle.getCurrentProperty('margin');<br \/>\n      divelem.style.overflow = window.getComputedStyle(output,null).overflow || output.style.overflow || output.currentStyle.getCurrentProperty('overflow');<br \/>\n    }<br \/>\n}<br \/>\n<\/code><\/p>\n<p> &#8230; via the wonders of the Javascript <a target=_blank title='window.getComputedStyle information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/getComputedStyle'>window.getComputedStyle()<\/a> method that we have mentioned before a few times at this <a target=_blank title='Search for window.getComputedStyle blog postings here' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/?s=window.getComputedStyle&#038;stype=Search'>blog<\/a>.<\/p>\n<p>Maybe you are a regular at this blog, and recognize the look of today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.html\" title='Click picture'>live run<\/a> web application?  Yes, a lot of the ideas emanating from <a target=_blank title='Legend for and from HTML Map Element Web Server Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/legend-for-and-from-html-map-element-web-server-tutorial\/'>Legend for and from HTML Map Element Web Server Tutorial<\/a> thread of blog postings went into the <a target=_blank title='Information about purloinment' href='http:\/\/www.yourdictionary.com\/purloinment'>&#8220;purloinment&#8221;<\/a> &#8230; <font size=1>nga, nga .. nga nga &#8230; ngaaa &#8230; it is a word<\/font> &#8230; exercise done on <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/legend_via_map.html------GETME\" title='legend_via_map.htm'>legend_via_map.htm<\/a>&#8216;s code <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.html-GETME\" title='textarea_talent.html'>in this way<\/a> mostly to do with the virtuous decision to hive off specific business logic to the external Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/textarea_talent.js_GETME\" title='textarea_talent.js'>textarea_talent.js<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d25195' onclick='var dv=document.getElementById(\"d25195\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/textarea\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d25195' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d25719' onclick='var dv=document.getElementById(\"d25719\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/css\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d25719' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d25728' onclick='var dv=document.getElementById(\"d25728\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/tool\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d25728' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;re continuing on with a new web application tool idea today, an external Javascript tool that when applied to a webpage, or not, between &lt;head&gt; and &lt;\/head&gt; via &#8230; &lt;!&#8211;script type=&#8217;text\/javascript&#8217; src=&#8217;http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/meld_styles.js&#8217;&gt;&lt;\/script&#8211;&gt; &#8230; that allows you to dynamically map some &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/html-style-mapping-tool-refinement-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[281,409,576,652,716,997,1254,2005,1319,1827],"class_list":["post-25728","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-css","tag-external-javascript","tag-html","tag-javascript","tag-log","tag-programming","tag-text","tag-tool","tag-tutorial","tag-window-getcomputedstyle"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/25728"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=25728"}],"version-history":[{"count":8,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/25728\/revisions"}],"predecessor-version":[{"id":25736,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/25728\/revisions\/25736"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=25728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=25728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=25728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}