{"id":722,"date":"2011-05-28T16:51:18","date_gmt":"2011-05-28T15:51:18","guid":{"rendered":"http:\/\/www.monkeyshines.co.uk\/blog\/?p=722"},"modified":"2011-05-28T23:24:03","modified_gmt":"2011-05-28T22:24:03","slug":"the-war-and-peace-o-meter","status":"publish","type":"post","link":"https:\/\/monkeyshines.co.uk\/blog\/the-war-and-peace-o-meter\/","title":{"rendered":"The War-and-Peace-O-Meter"},"content":{"rendered":"<p style='width: 400px; float: left;'>\nSome years ago I asked for <em>War and Peace<\/em> by Leo Tolstoy for Christmas; a new translation had just been published, and that seemed as good a reason as any to tackle this metaphorically and literally immense book. I do a lot of my reading on the bus, which has tended to put me off starting it, but I decided that I should stop procrastinating and get on with it. I&#8217;ve read the first few chapters, and I&#8217;m enjoying it &#8211; I was a bit worried that my historical ignorance might make the setting a bit confusing, but Tolstoy does a fine job of filling in the background, and there are a few judicious notes by the translator, Anthony Briggs (it&#8217;s the 2005 Penguin edition, by the way).\n<\/p>\n<div  style='width: 90px; height: 370px; padding: 5px; float: right; border: 2px solid maroon; background: white; margin-left: 5px; margin-right: 5px;'>\n<div class=\"ometer_coloured\">\n<div id=\"mask\" class=\"ometer_mask\" style='height: 357px;'>\n<div id=\"ometer\">\t<\/div>\n<\/p><\/div>\n<\/div>\n<\/div>\n<p style='width: 400px; float: left;'>\nI thought it might be nice to visually track my progress, so, naturally, I built a <strong>War-and-Peace-O-Meter<\/strong>. I swiped the image from <a href=\"http:\/\/www.webdeveloperjuice.com\/2010\/01\/29\/css-trick-making-vertical-rating-meter-easy-way\">elsewhere<\/a>, modified it a bit, then wrote some very simple CSS rules to do the &#8220;filling up&#8221;. For the <strong>War-and-Peace-O-Meter<\/strong> I only need a static level (and will be posting weekly updates), but to demonstrate how you can fill up the meter dynamically, you can change the percentage:\n<\/p>\n<form style='width: 400px; float: left; text-align: right;' id='ometer_form' method='post' onsubmit=\"updateMeter('mask', 'ometer_pc'); return false;\">\n<fieldset>\n<input id='ometer_pc' type='text' name='ometer_pc' value='1.25' style='width: 50px; text-align:right;' \/> % <input type='submit' name='submit' value='Go' \/><br \/>\n<\/fieldset>\n<\/form>\n<div style='width: 100%; clear: both;'><\/div>\n<h1>Geek Details<\/h1>\n<div style='width: 60px; padding-left:10px; float:left;'><strong>Method<\/strong>: <\/div>\n<div style='width: 450px; padding-left:10px; padding-right:10px; float: right;'>The image of the <strong>-o-meter<\/strong> is a gif with transparency in the middle. Behind that is a div with a white background, and behind that is a div with a red background. The height of the middle div is dynamically adjusted, revealing more or less of the red behind. This is a bit more complicated than absolutely necessary, but it&#8217;s easy to implement, and it&#8217;s flexible in that you don&#8217;t have to use a solid block of colour as the bottom layer, it could be an image that is gradually revealed. Like in pubs which have packets of nuts mounted on a bit of card, and which reveal a saucy lady as the packets are removed. No saucy ladies here though, this is a family-friendly website.<\/span>\n<\/div>\n<div style='width: 100%; clear: both;'><\/div>\n<div style='width: 60px; padding-left:10px; float:left;'><strong>Image<\/strong>: <\/div >\n<div style='width: 470px; float: right;'><a href='\/img\/ometer.gif'>ometer.gif<\/a><\/div >\n<div style='width: 100%; clear: both;'><\/div>\n<div style='width: 60px; padding-left:10px; float: left;'><strong>CSS<\/strong>: <\/div>\n<div style='width: 470px; white-space: pre; font-family: monospace; float: right; padding-top:5px;'>.ometer_coloured {<br \/>\n\tbackground:crimson;<br \/>\n\twidth:90px;<br \/>\n\theight:370px;<br \/>\n\t}<br \/>\n.ometer_mask {<br \/>\n\tbackground:white;<br \/>\n\tposition:absolute;<br \/>\n\tz-index:1;<br \/>\n\theight:361px;<br \/>\n\twidth:90px;<br \/>\n\t}<br \/>\n#ometer {<br \/>\n\tbackground:url(&#8216;\/img\/ometer.gif&#8217;) no-repeat;<br \/>\n\tposition:absolute;<br \/>\n\tz-index:10;<br \/>\n\twidth:90px;<br \/>\n\theight:370px;<br \/>\n\t}\n<\/div>\n<div style='clear: both;'><\/div>\n<div style='width: 60px; padding-left:10px; float: left;'><strong>HTML<\/strong>: <\/div>\n<div style='width: 470px; white-space: pre; font-family: monospace; float: right; padding-top:5px;'>&lt;div class=&#8217;ometer_coloured&#8217;&gt;<br \/>\n\t&lt;div id=&#8217;mask&#8217; class=&#8217;ometer_mask&#8217;&gt;<br \/>\n\t\t&lt;div id=&#8217;ometer&#8217;&gt;&lt;\/div&gt;<br \/>\n\t&lt;\/div&gt;<br \/>\n&lt;\/div>\n<\/div>\n<div style='clear: both;'><\/div>\n<div style='width: 60px; padding-left:10px; float: left;'><strong>JS<\/strong>: <\/div>\n<div style='width: 470px; white-space: pre; font-family: monospace; float: right; padding-top:5px;'>function updateMeter(ometer_mask_id, ometer_pc_id) {<br \/>\n    var pc = document.getElementById(ometer_pc_id).value;<br \/>\n    var numericExpression = \/^[0-9\\.]+$\/;<br \/>\n    if (pc.match(numericExpression)){<br \/>\n        var total_rows = 353;<br \/>\n        rows = Math.round(total_rows * (pc\/100));<br \/>\n        if (rows > total_rows) {<br \/>\n            rows = total_rows;<br \/>\n        }<br \/>\n        rows = 361 &#8211; rows;<br \/>\n        var mask = document.getElementById(ometer_mask_id)<br \/>\n        mask.style.height = rows+&#8217;px&#8217;;<br \/>\n    } else {<br \/>\n        alert(&#8216;Numbers only, please.&#8217;);<br \/>\n    }<br \/>\n}\n<\/div>\n<p><script type=\"text\/javascript\">\nfunction updateMeter(ometer_mask_id, ometer_pc_id) {\n    var pc = document.getElementById(ometer_pc_id).value;\n    var numericExpression = \/^[0-9\\.]+$\/;\n    if (pc.match(numericExpression)){\n        var total_rows = 353;\n        rows = Math.round(total_rows * (pc\/100));\n        if (rows > total_rows) {\n            rows = total_rows;\n        }\n        rows = 361 - rows;\n        document.getElementById(ometer_mask_id).style.height = rows+'px';\n    } else {\n        alert('Numbers only, please.');\n    }\n}\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some years ago I asked for War and Peace by Leo Tolstoy for Christmas; a new translation had just been published, and that seemed as good a reason as any to tackle this metaphorically and literally immense book. I do a lot of my reading on the bus, which has tended to put me off [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,7],"tags":[],"class_list":["post-722","post","type-post","status-publish","format-standard","hentry","category-books","category-coding"],"_links":{"self":[{"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/posts\/722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=722"}],"version-history":[{"count":96,"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/posts\/722\/revisions"}],"predecessor-version":[{"id":818,"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/posts\/722\/revisions\/818"}],"wp:attachment":[{"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monkeyshines.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}