{"id":61990,"date":"2023-12-16T03:01:19","date_gmt":"2023-12-15T17:01:19","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=61990"},"modified":"2023-12-16T08:57:31","modified_gmt":"2023-12-15T22:57:31","slug":"angled-text-tool-clipboard-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/angled-text-tool-clipboard-tutorial\/","title":{"rendered":"Angled Text Tool Clipboard Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Angled Text Tool Clipboard Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool_clipboard.jpg\" title=\"Angled Text Tool Clipboard Tutorial\"   \/><\/a><p class=\"wp-caption-text\">Angled Text Tool Clipboard Tutorial<\/p><\/div>\n<p>We started feeling that yesterday&#8217;s <a title='Angled Text Tool Context Tutorial' href='#attct'>Angled Text Tool Context Tutorial<\/a>&#8216;s progress was starting to feel like a web application that was a &#8220;tool&#8221;.  But something was missing.  It wasn&#8217;t friendly enough to a serious user, the ones tempted to try it out and persevere, to see whether it could help them out &#8230; ie. being used as a &#8220;tool&#8221;.  And so we added some new Javascript &#8230;<\/p>\n<p><code><br \/>\nfunction fallbackCopyTextToClipboard(text) { \/\/ thanks to &lt;a target=\"_blank\" title=\"https:\/\/stackoverflow.com\/questions\/400212\/how-do-i-copy-to-the-clipboard-in-javascript\" href=\"https:\/\/stackoverflow.com\/questions\/400212\/how-do-i-copy-to-the-clipboard-in-javascript\"&gt;https:\/\/stackoverflow.com\/questions\/400212\/how-do-i-copy-to-the-clipboard-in-javascript&lt;\/a&gt;<br \/>\n  var textArea = document.createElement(\"textarea\");<br \/>\n  \/\/alert(text);<br \/>\n  textArea.value = text;<br \/>\n<br \/>\n  \/\/ Avoid scrolling to bottom<br \/>\n  textArea.style.top = \"0\";<br \/>\n  textArea.style.left = \"0\";<br \/>\n  textArea.style.position = \"fixed\";<br \/>\n<br \/>\n  document.body.appendChild(textArea);<br \/>\n  textArea.focus();<br \/>\n  textArea.select();<br \/>\n<br \/>\n  try {<br \/>\n    var successful = document.execCommand('copy');<br \/>\n    var msg = successful ? 'successful' : 'unsuccessful';<br \/>\n    console.log('Fallback: Copying text command was ' + msg);<br \/>\n  } catch (err) {<br \/>\n    console.error('Fallback: Oops, unable to copy', err);<br \/>\n  }<br \/>\n<br \/>\n  document.body.removeChild(textArea);<br \/>\n}<br \/>\n<br \/>\nfunction copyTextToClipboard(text) { \/\/ thanks to &lt;a target=\"_blank\" title=\"https:\/\/stackoverflow.com\/questions\/400212\/how-do-i-copy-to-the-clipboard-in-javascript\" href=\"https:\/\/stackoverflow.com\/questions\/400212\/how-do-i-copy-to-the-clipboard-in-javascript\"&gt;https:\/\/stackoverflow.com\/questions\/400212\/how-do-i-copy-to-the-clipboard-in-javascript&lt;\/a&gt;<br \/>\n  \/\/alert('text=' + text);<br \/>\n  if (!navigator.clipboard) {<br \/>\n    fallbackCopyTextToClipboard(text);<br \/>\n    return;<br \/>\n  }<br \/>\n  navigator.clipboard.writeText(text).then(function() {<br \/>\n    console.log('Async: Copying to clipboard was successful!');<br \/>\n  }, function(err) {<br \/>\n    console.error('Async: Could not copy text: ', err);<br \/>\n  });<br \/>\n}<br \/>\n<br \/>\nfunction nifotherthanfont(cii) {<br \/>\n  return decodeURIComponent(cii);<br \/>\n}<br \/>\n<br \/>\nfunction ifotherthanfont(cii) {<br \/>\n  var newcii=cii, allokay=true, ncs=[], incs=0;<br \/>\n  if (cii.indexOf('&lt;\/font&gt;') != -1 || cii.indexOf('&lt;\/FONT&gt;') != -1) {<br \/>\n    ncs=cii.split('&lt;\/');<br \/>\n    for (incs=1; incs&lt;ncs.length; incs++) {<br \/>\n      if (ncs[incs].toLowerCase().indexOf('font') != 0) { allokay=false;  }<br \/>\n    }<br \/>\n    if (!allokay || 1 == 1) {<br \/>\n    ncs=cii.split('&lt;font');<br \/>\n    for (incs=1; incs&lt;ncs.length; incs++) {<br \/>\n      newcii=newcii.replace('&lt;font' + ncs[incs].split('&gt;')[0] + '&gt;', '');<br \/>\n      newcii=newcii.replace('&lt;\/font&gt;', '');<br \/>\n    }<br \/>\n    ncs=cii.split('&lt;FONT');<br \/>\n    for (incs=1; incs&lt;ncs.length; incs++) {<br \/>\n      newcii=newcii.replace('&lt;FONT' + ncs[incs].split('&gt;')[0] + '&gt;', '');<br \/>\n      newcii=newcii.replace('&lt;\/FONT&gt;', '');<br \/>\n    }<br \/>\n    }<br \/>\n  }<br \/>\n  return newcii;<br \/>\n}<br \/>\n<br \/>\nfunction codecopying(mode) {<br \/>\n  var rectcos=null, icn=0, okpast=false;<br \/>\n  var eletype='td';<br \/>\n  if (mode != '') {<br \/>\n    eletype=document.getElementById(mode).outerHTML.substring(1).split(' ')[0].split('&gt;')[0];<br \/>\n  }<br \/>\n  var cos=document.getElementsByTagName(eletype); \/\/'code'<br \/>\n  for (var ico=0; ico&lt;cos.length; ico++) {<br \/>\n    if (cos[ico].id == 'is' || cos[ico].id == 'was' || (cos[ico].id == mode &amp;&amp; mode != '')) {<br \/>\n    if (mode == '') {<br \/>\n     rectcos=cos[ico].getBoundingClientRect();<br \/>\n     document.getElementById('dcode').innerHTML+='&lt;span data-fword=\"' + encodeURIComponent(ifotherthanfont(cos[ico].innerHTML.replace(\/\\&amp;lt\\;\/g,'&lt;').replace(\/\\&amp;gt\\;\/g,'&gt;')).substring(0)) + '\" onclick=\"codecopying(this.id);\" title=\"Copy unadorned HTML code to clipboard buffer\" id=scd' + ico + ' style=\"position:absolute;z-index:56;left:' + eval(-50 + eval('' + rectcos.right)) + 'px;top:' + eval(10 + eval('' + rectcos.top)) + 'px;font-size:24px;\"&gt;&lt;\/span&gt;';<br \/>\n    } else if (1 == 1) {<br \/>\n      document.getElementById(mode).style.border='1px dashed pink';<br \/>\n      copyTextToClipboard(nifotherthanfont(document.getElementById(mode).getAttribute('data-fword')).replace(\/\\&amp;amp\\;nbsp\\;\/g, '&amp;nbsp;').replace(\/\\&amp;amp\\;\\#\/g, '&amp;#').replace(\/ \\&amp;amp\\;\\;\/g, ' &amp;;').replace(\/\\&lt;br\\&gt;\/g, '').replace(\/\\&amp;amp;lt\\;\/g, '&lt;').replace(\/\\&amp;amp;gt\\;\/g, '&gt;').trim());<br \/>\n      okpast=false;<br \/>\n    }<br \/>\n    }<br \/>\n  }<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Does this code seem familiar to you?  It might be because we tried this &#8220;Being able to Copy Code to the Clipboard Here with the Blog You are Reading&#8221; when we published <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress-blog-code-element-clipboard-copy-primer-tutorial\/' title='WordPress Blog Code Element Clipboard Copy Primer Tutorial'>WordPress Blog Code Element Clipboard Copy Primer Tutorial<\/a> back in February.  The code above is very similar, but some differences are &#8230;<\/p>\n<ul>\n<li>we make the <i>codecopying(&#8221;);<\/i> call each time the Display button is pressed, rather than once on the Blog document &#8220;onload&#8221; event<\/li>\n<li>within that <i>codecopying<\/i> function the logic can be simpler, as we store the whole HTML code snippet of relevance to the &#8220;slapped over&#8221; span element&#8217;s &#8220;data-fword&#8221; global data attribute each time, and so just regurgitate that whole global data attribute when asked to copy code to the clipboard as a user clicks an &#8220;emoji span button&#8221; near HTML code of interest<\/li>\n<li>there are no &lt;FONT&gt;&lt;\/FONT&gt; colour coding embellishments to worry about<\/li>\n<\/ul>\n<p>Copying this way from our &#8220;tool&#8221; web application and into your HTML code text editor could be a way to save heaps of coding time, we&#8217;re hoping.  <\/p>\n<p>Maybe you want to try it in <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html--GETME\">the changed<\/a> <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html--GETME\">&#8220;third draft&#8221;<\/a> <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html\">Angled Text Helper Tool<\/a>.<\/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\/angled-text-tool-clipboard-tutorial\/'>Angled Text Tool Clipboard Tutorial<\/a>.<\/p-->\n<hr>\n<p id='attct'>Previous relevant <a target=_blank title='Angled Text Tool Context Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/angled-text-tool-context-tutorial\/'>Angled Text Tool Context Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Angled Text Tool Context Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool_context.jpg\" title=\"Angled Text Tool Context Tutorial\"   \/><\/a><p class=\"wp-caption-text\">Angled Text Tool Context Tutorial<\/p><\/div>\n<p>You only have to go about trying to solve a web application issue, often ending up at advice from the wonderful <a target=_blank href='https:\/\/stackoverflow.com' title='StackOverflow'>StackOverflow<\/a> website, to realize the &#8220;context&#8221; of a problem is often the issue.  There are so many different &#8220;takes&#8221; to how to go about the craft, it can be daunting.  As such, today, to improve on yesterday&#8217;s <a title='Angled Text Tool Primer Tutorial' href='#attpt'>Angled Text Tool Primer Tutorial<\/a>&#8216;s start to our Angled Text Helper Tool, we work at more &#8220;context&#8221; for the destination of the Angled Text, so that &#8230;<\/p>\n<ul>\n<li>yesterday&#8217;s &#8220;top left of screen&#8221; &#8230; is now joined by today&#8217;s added &#8230;<\/li>\n<li>&#8220;top right of screen&#8221; &#8230; and &#8230;<\/li>\n<li>3&#215;3 table cell nestings for top left and middle center and bottom right cells positioned to the top left without or with white spacing (of non-selected cells) &#8230; and &#8230;<\/li>\n<li>3&#215;3 table cell nestings for top left and middle center and bottom right cells positioned to the top right with cell white spacing<\/li>\n<\/ul>\n<p> &#8230; and add a text font size numerical textbox as another variable mixed in to the functionality of <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html-GETME\">the changed<\/a> <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html-GETME\">&#8220;second draft&#8221;<\/a> <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html\">Angled Text Helper Tool<\/a> you might want to try below &#8230;<\/p>\n<p><iframe style=\"width:100%;height:900px;\" src=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html\"><\/iframe><\/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\/new-angled-text-tool-context-tutorial\/'>Angled Text Tool Context Tutorial<\/a>.<\/p-->\n<hr>\n<p id='attpt'>Previous relevant <a target=_blank title='Angled Text Tool Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/angled-text-tool-primer-tutorial\/'>Angled Text Tool Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Angled Text Tool Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.jpg\" title=\"Angled Text Tool Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">Angled Text Tool Primer Tutorial<\/p><\/div>\n<p>Buoyed by our new found confidence in [element].<a target=_blank title='getBoundingClientRect' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Element\/getBoundingClientRect'>getBoundingClientRect<\/a>() when dealing with rotated text, in the clientside Javascript realm of proceedings, as we talked about with yesterday&#8217;s <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/google-chart-image-chart-angled-text-annotation-tutorial\/' title='Google Chart Image Chart Angled Text Annotation Tutorial'>Google Chart Image Chart Angled Text Annotation Tutorial<\/a>, today, we&#8217;re writing a new, and so far pretty simple &#8230;<\/p>\n<p><code><br \/>\nAngled Text Helper Tool<br \/>\n<\/code><\/p>\n<p> &#8230; and we&#8217;re hoping over time, perhaps it can deserve that moniker &#8220;tool&#8221; for some readers and users out there!  We hope so.<\/p>\n<p>What&#8217;s hard about angled text, leaving aside any &#8220;trying to fit in with PHP <a target=_blank title='GD and Image Functions' href='http:\/\/php.net\/manual\/en\/ref.image.php'>GD<\/a> <a target=_blank title='PHP GD imagettftext' href='https:\/\/www.php.net\/manual\/en\/function.imagettftext.php'>imagettftext<\/a> interfacing&#8221;?  For us, it&#8217;s that rotations, by default, happen in the middle of text, but that &#8220;middle of text&#8221; is not a data point collected naturally for an HTML element ( though is derivable, <a target=_blank title=? href='https:\/\/www.youtube.com\/watch?v=e9_7GcQeiqw&#038;t=2m37s'>again<\/a>, via [element].getBoundingClientRect() ) meaning &#8230;<\/p>\n<ul>\n<li>for angled text it is hard to &#8220;sidle up&#8221; to something easily &#8230; and &#8230;<\/li>\n<li>for angled text it is hard to &#8220;snugly fit it in&#8221; within a containing something easily<\/li>\n<\/ul>\n<p>Our proof of concept <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html\">Angled Text Tool<\/a> throws it to the user to try to fit some rotated text snugly up into the top left corner of a webpage, supplying their own editable CSS, onto a raw HTML div element, where what is asked, so far, is &#8230;<\/p>\n<ul>\n<li>text itself &#8230; in a textarea element<\/li>\n<li>clockwise angle from horizontal in degrees angle &#8230; in an input type=number textbox &#8230;<\/li>\n<li>user CSS &#8230; to be applied to said HTML div &#8230; in a textbox &#8230;<\/li>\n<li>checkbox for whether to display a finishing &#8220;bounding box&#8221;<\/li>\n<\/ul>\n<p>Simple premise, but see how you go, trying our <a target=_blank href=\"https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/angled_text_helper_tool.html_GETME\">&#8220;proof of concept&#8221; &#8220;first draft&#8221;<\/a> HTML and Javascript and CSS &#8220;would be&#8221; tool.<\/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='#d61982' onclick='var dv=document.getElementById(\"d61982\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/transform\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d61982' 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='#d61986' onclick='var dv=document.getElementById(\"d61986\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/nest\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d61986' 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='#d61990' onclick='var dv=document.getElementById(\"d61990\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/clipboard\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d61990' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We started feeling that yesterday&#8217;s Angled Text Tool Context Tutorial&#8216;s progress was starting to feel like a web application that was a &#8220;tool&#8221;. But something was missing. It wasn&#8217;t friendly enough to a serious user, the ones tempted to try &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/angled-text-tool-clipboard-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":[3363,4597,214,4262,2105,265,281,3980,385,2208,3981,576,652,1643,3965,2521,907,997,1071,4474,4598,2263,1545,1238,1581,1298,1300,1319],"class_list":["post-61990","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-angle","tag-angled-text","tag-clipboard","tag-containing","tag-context","tag-copy","tag-css","tag-data-attribute","tag-emoji","tag-getboundingclientrect","tag-global-data-attribute","tag-html","tag-javascript","tag-justification","tag-justify","tag-nest","tag-paste","tag-programming","tag-rotate","tag-sidle","tag-snug","tag-span","tag-stackoverflow","tag-table","tag-table-cell","tag-transform","tag-translate","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/61990"}],"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=61990"}],"version-history":[{"count":4,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/61990\/revisions"}],"predecessor-version":[{"id":61995,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/61990\/revisions\/61995"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=61990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=61990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=61990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}