{"id":50046,"date":"2020-08-23T03:01:44","date_gmt":"2020-08-22T17:01:44","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=50046"},"modified":"2020-08-24T10:10:40","modified_gmt":"2020-08-24T00:10:40","slug":"input-colour-picker-multiple-linear-gradient-background-time-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/input-colour-picker-multiple-linear-gradient-background-time-tutorial\/","title":{"rendered":"Input Colour Picker Multiple Linear Gradient Background Time Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.htm\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=Input Colour Picker Multiple Linear Gradient Background Time Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple_time.jpg\" title=\"Input Colour Picker Multiple Linear Gradient Background Time Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Input Colour Picker Multiple Linear Gradient Background Time Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Input Colour Picker Multiple Linear Gradient Background Primer Tutorial' href='#icpmlgbpt'>Input Colour Picker Multiple Linear Gradient Background Primer Tutorial<\/a> could do with some more &#8220;genericization <a target=_blank onclick=\"  setTimeout(function(){ alert(' ... and awaiting ... &#129704; &#129704; ... the rocks!'); }, 4000);\" href='https:\/\/www.google.com\/search?q=chops+meaning&#038;rlz=1C5CHFA_enAU832AU832&#038;oq=chops+meaning&#038;aqs=chrome..69i57j0l7.3587j1j7&#038;sourceid=chrome&#038;ie=UTF-8'>chops<\/a>&#8220;.<\/p>\n<p>With any web application that is &#8230;<\/p>\n<ul>\n<li>largely &#8220;external Javascript&#8221; as far as the scripting goes &#8230; and has been tested with &#8230;<\/li>\n<li>a simple &#8220;proof of concept&#8221; web application supervisor &#8230; needs &#8230;<\/li>\n<li>genericization thoughts regarding other uses for the &#8220;external Javascript&#8221; that can facilitate setting that Javascript free to be of use in <i>other scenarios<\/i><\/li>\n<\/ul>\n<p>That <i>other scenario<\/i> we can envisage is regarding those <a target=_blank title='HTML Canvas element information from w3schools' href='http:\/\/www.w3schools.com\/tags\/ref_canvas.asp'>canvas<\/a> element based annotation functionalities that use a colour picker (ie. input type=color element) to determine a colour (such as a line drawing colour).  We want to, eventually, &#8220;imbue&#8221; that colour picker with more functionality, and yet leave its functionality as is, for the <i>simple &#8220;one colour&#8221; linework arrangements<\/i> a lot of users will be happy to stick with.  How do we keep both ideas happy?  We introduce (into the equation) &#8230;<\/p>\n<ul>\n<li>a time factor to the user interactions with the colour picker &#8230; so that &#8230;<\/li>\n<li>if a user takes a long time between colour selections using the colour picker (or even only visits it the once) that means they are selecting <i>simple &#8220;one colour&#8221; linework arrangements<\/i> &#8230; but &#8230;<\/li>\n<li>if a user takes a short time between colour selections that indicates they wouldn&#8217;t be against creating linear gradient linework on their canvas annotations (until a &#8220;double click&#8221; on the same colour to revert back to <i>simple &#8220;one colour&#8221; linework arrangements<\/i> as above)<\/li>\n<\/ul>\n<p> &#8230; leaving any calling web application the global variable &#8230;<\/p>\n<p><code><br \/>\n var iohuh='';     \/\/ if iohuh contains \"),\" linear gradients will be observed, rather than simple one colour arrangements<br \/>\n<\/code><\/p>\n<p> &#8230; <font color=blue>containing &#8220;),&#8221;<\/font> (being <font color=blue>true<\/font>) as a determinant that linear gradients <font color=blue>are currently in play<\/font> (in the user&#8217;s mind), else use the last colour picked as your <i>simple &#8220;one colour&#8221; linework arrangement<\/i>.<\/p>\n<p>All today&#8217;s changes to our <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.htm\" title=\"Click picture\">live run<\/a> link&#8217;s workings are derived from <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.js-GETME\" title=\"input_col_multiple.js\">a changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.js-GETME\" title=\"input_col_multiple.js\">input_col_multiple.js<\/a> external Javascript code.<\/p>\n<p>And what drives the &#8220;timeliness&#8221; of this changed external Javascript code?  Good ol&#8217; <a target=_blank title='Javascript setTimeout method information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_settimeout.asp'><i>setTimeout<\/i><\/a> (combined with some global var<font size=1>iable<\/font> &#8220;inplay&#8221; usage where you should know that &#8220;inplay++;&#8221; happens each time a body background change is made and then a &#8220;setTimeout(lessinplay, 20000);&#8221; immediately follows), as per &#8230;<\/p>\n<p><code><br \/>\n  var inplay=0;<br \/>\n  var documentbody=document.body;<br \/>\n<br \/> <br \/>\n  function lessinplay() {<br \/>\n    if (iohuh.indexOf('),') == -1) {<br \/>\n      inplay--;<br \/>\n      if (eval('' + inplay) &lt;= 0) {<br \/>\n        iohuh='';<br \/>\n        documentbody.style.background='';<br \/>\n        documentbody.style.backgroundColor='white';<br \/>\n        if ((optionvalmultiple ? optionvalmultiple : elsel)) {<br \/>\n          if ((optionvalmultiple ? optionvalmultiple : elsel).innerHTML.indexOf(')') == -1) {<br \/>\n            iohuh=' ';<br \/>\n            if (optionvalmultiple) {<br \/>\n            optionvalmultiple.innerHTML+=optionsuffix;<br \/>\n            } else {<br \/>\n            elsel.innerHTML=elsel.innerHTML.replace('&lt;\/option&gt;', optionsuffix + '&lt;\/option&gt;');<br \/>\n            }<br \/>\n          }<br \/>\n        }<br \/>\n      }<br \/>\n    } else if (<i>(optionvalmultiple ? optionvalmultiple : elsel)<\/i>) {<br \/>\n      if (<i>(optionvalmultiple ? optionvalmultiple : elsel)<\/i>.innerHTML.indexOf(')') != -1) {<br \/>\n            iohuh+=' ';<br \/>\n            if (optionvalmultiple) {<br \/>\n            optionvalmultiple.innerHTML=optionvalmultiple.innerHTML.replace(optionsuffix, '');<br \/>\n            } else {<br \/>\n            elsel.innerHTML=elsel.innerHTML.replace(optionsuffix + '&lt;\/option&gt;', '&lt;\/option&gt;');<br \/>\n            }<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><\/p>\n<p> &#8230; those <i>ternary element object tests<\/i> having a meaning because of a <font color=blue>more &#8220;forensic&#8221;<\/font> &#8230;<\/p>\n<p><code><br \/>\n  <font color=blue>var elsel=null;<br \/>\n  var willingtotryupto=55;<br \/>\n  var linear_gradient_part='';<br \/>\n  var elitext=null;<br \/>\n  var optionvalmultiple=null;<\/font><br \/>\n<br \/>\n  function onl() {<br \/>\n    <font color=blue>var el=document.querySelector(\"input[type='color']\");<br \/>\n    if (!el && eval('' + willingtotryupto) &gt; 0) {<br \/>\n      willingtotryupto--;<br \/>\n      setTimeout(onl, 1000);<br \/>\n      return;<br \/>\n    }<br \/>\n    if (document.getElementById('mycolour') && el) {<br \/>\n      documentbody=document.getElementById('mycolour');<br \/>\n      document.getElementById('mycolour').title=('' + document.getElementById('mycolour').title + ' ') + ' (negative opacity value here stops Linear Gradient mode). Multiple selections with colour picker within 20 seconds signify a linear gradient stroke (as relevant)';<br \/>\n      el.title=('' + el.title + ' ') + 'Multiple selections of this colour picker within 20 seconds signify a linear gradient stroke (as relevant)';<br \/>\n      linear_gradient_part='to right,';<br \/>\n      iomultiple='multiple';<br \/>\n      willingtotryupto=555;<br \/>\n    } else {<br \/>\n      documentbody=document.body;<br \/>\n    }<br \/>\n    elitext=document.querySelector(\"input[type='text']\");<br \/>\n    optionvalmultiple=document.querySelector(\"option[value='multiple']\");<br \/>\n    if (!optionvalmultiple && iomultiple == '') { iomultiple='multiple'; }<br \/>\n    if (el) {<br \/>\n     if (!el.onclick) {<br \/>\n       el.addEventListener('click', function(event) {  checkformultiple(event.target);  });<br \/>\n     } else if (('' + el.onclick).indexOf('checkformultiple') == -1) {<br \/>\n       el.addEventListener('click', function(event) {  checkformultiple(event.target);  });<br \/>\n     }<br \/>\n     if (!el.onblur) {<br \/>\n       el.addEventListener('blur', function(event) {  finalchoice(event.target);  });<br \/>\n     } else if (('' + el.onblur).indexOf('finalchoice') == -1) {<br \/>\n       el.addEventListener('blur', function(event) {  finalchoice(event.target);  });<br \/>\n     }<br \/>\n     if (!el.onchange) {<br \/>\n       el.addEventListener('change', function(event) {  finalchoice(event.target);  });<br \/>\n     } else if (('' + el.onchange).indexOf('finalchoice') == -1) {<br \/>\n       el.addEventListener('change', function(event) {  finalchoice(event.target);  });<br \/>\n     }<br \/>\n    }<br \/>\n    var elsels=document.querySelectorAll(\"select\");<br \/>\n    if (elsels.length > 0) {<br \/>\n    for (var iko=0; iko&lt;elsels.length; iko++) {<br \/>\n    if (elsels[iko].innerHTML.indexOf('ultiple') != -1 && !elsel) {<br \/>\n    <\/font>elsel=<font color=blue>elsels[iko]; \/\/<\/font>document.querySelector(\"select\");<font color=blue><br \/>\n    }<br \/>\n    }<br \/>\n    }<\/font><br \/>\n    if (elsel && documentbody == document.body) { if (('' + elsel.id) == '') { iomultiple='' + elsel.value;  } else { sel(('' + elsel.id)); } }<br \/>\n  }<br \/>\n<\/code> <\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/input-colour-picker-multiple-linear-gradient-background-primer-tutorial\/'>Input Colour Picker Multiple Linear Gradient Background Primer Tutorial<\/a>.<\/p-->\n<hr>\n<p id='icpmlgbpt'>Previous relevant <a target=_blank title='Input Colour Picker Multiple Linear Gradient Background Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/input-colour-picker-multiple-linear-gradient-background-primer-tutorial\/'>Input Colour Picker Multiple Linear Gradient Background 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\/input_col_multiple.htm\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=Input Colour Picker Multiple Linear Gradient Background Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.jpg\" title=\"Input Colour Picker Multiple Linear Gradient Background Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Input Colour Picker Multiple Linear Gradient Background Primer Tutorial<\/p><\/div>\n<p>We&#8217;ve got two ideas floating around today&#8217;s proof of concept &#8220;Input Colour Picker Multiple Linear Gradient Background&#8221; web application concept, the second being the &#8220;proof of concept&#8221; bit, at least for us &#8230;<\/p>\n<ul>\n<li>dynamically created linear-gradient backgrounds (as you can read about recently at <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/css-gradient-creations-popup-integration-tutorial' title='CSS Gradient Creations Popup Integration Tutorial'>CSS Gradient Creations Popup Integration Tutorial<\/a>) &#8230; augmented by the interactive input required, via the new idea of &#8230;<\/li>\n<li>input type=color &#8220;multiple&#8221; attribute (not of meaning to default HTML and CSS and Javascript that involves element types that are not &#8220;select&#8221; (dropdowns), but) made to mean something (for input type=color elements) today<\/li>\n<\/ul>\n<p> &#8230; in our inhouse HTML and Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.html-GETME\" title=\"input_col_multiple.htm\">input_col_multiple.htm<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.htm\" title=\"Click picture\">live run<\/a> link (that includes the crucial external Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.js_GETME\" title=\"input_col_multiple.js\">input_col_multiple.js<\/a> and <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.html-GETME\" title=\"input_col_multiple.htm\">derived via<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/input_col_multiple.html\" title=\"Click picture\">less interesting live run<\/a>), (any\/all of which) you can try for yourself.<\/p>\n<p>Notice some <font color=red>genericization considerations<\/font> in the Javascript with code snippets like &#8230;<\/p>\n<p><code><br \/>\n    var el=<font color=red>document.<a target=_blank title='HTML DOM querySelector() Method information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/met_document_queryselector.asp'>querySelector<\/a>(\"input[type='color']\")<\/font>;  \/\/ gets first CSS'y element selector filtering (in Javascript)<br \/>\n    var eloh='';<br \/>\n    if (el && iomultiple != '') { if (el.outerHTML.toLowerCase().indexOf(' multiple') == -1) { el.setAttribute('multiple',true);  }  eloh=el.outerHTML; }<br \/>\n    if (eloh.toLowerCase().indexOf(' multiple') != -1) {<br \/>\n      \/\/ do stuff regarding document.body linear gradient background<br \/>\n    }<br \/>\n<\/code><\/p>\n<p> &#8230; or the body onload substitute code &#8230;<\/p>\n<p><code><br \/>\n  var iomultiple='';<br \/>\n<br \/>\n  function sel(oid) {<br \/>\n    if (document.getElementById(oid)) {<br \/>\n      iomultiple='' + document.getElementById(oid).value;<br \/>\n    }<br \/>\n  }<br \/>\n<br \/>\n  function onl() {<br \/>\n    var elsel=document.querySelector(\"select\");<br \/>\n    if (elsel) { <font color=blue>if (('' + elsel.id) == '') { iomultiple='' + elsel.value;  } else {<\/font> sel(('' + elsel.id)); } }<br \/>\n  }<br \/>\n<br \/> <br \/>\n  setTimeout(onl, 1000);<br \/>\n<\/code><\/p>\n<p> &#8230; where the determining &#8220;select&#8221; dropdown (as to whether linear gradients will be dynamically applied to document.body background)<strike style=color:blue> needs an ID but we do not care what that ID<\/strike> is.<\/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='#d50036' onclick='var dv=document.getElementById(\"d50036\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/multiple\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50036' 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='#d50046' onclick='var dv=document.getElementById(\"d50046\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/time\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50046' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s Input Colour Picker Multiple Linear Gradient Background Primer Tutorial could do with some more &#8220;genericization chops&#8220;. With any web application that is &#8230; largely &#8220;external Javascript&#8221; as far as the scripting goes &#8230; and has been tested with &#8230; &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/input-colour-picker-multiple-linear-gradient-background-time-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":[126,224,228,281,1683,409,1839,3081,576,609,652,2020,2092,997,2835,2854,1126,3404,1279,1319],"class_list":["post-50046","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-background","tag-colour","tag-colour-picker","tag-css","tag-dynamic","tag-external-javascript","tag-genericization","tag-global-variable","tag-html","tag-input","tag-javascript","tag-linear-gradient","tag-multiple","tag-programming","tag-queryselector","tag-queryselectorall","tag-settimeout","tag-ternary","tag-time","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50046"}],"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=50046"}],"version-history":[{"count":19,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50046\/revisions"}],"predecessor-version":[{"id":50081,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50046\/revisions\/50081"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=50046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=50046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=50046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}