UNPKG

doevisualizations

Version:

Data Visualization Library based on RequireJS and D3.js (v4+)

113 lines (101 loc) 2.83 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Compare Element Positions</title> <style type='text/css'> body { font-family: verdana } div { border: solid 1px black; margin: 5px; padding: 5px; font-size: 12px; } .red { background-color: red; } .green { background-color: green; } .hide { display: none; } h3 { margin: 20px 0px 0px 0px; } table { margin-top: 20px; border-collapse: collapse; } th, td { border: 1px solid gray; padding: 5px; } th { color: gray; text-align: left; } .matches { background-color: yellow; } </style> </head> <body> <p>Click 2 elements to compare them.</p> <pre> <code>$('.red').compare($('.green')) = <span id='result'></span></code> </pre> <div id="demo-html" style="margin: 0;"> <div> A <div>A.1</div> <div>A.2</div> </div> <div> B </div> </div> <table> <tr><th>Bits</th><th>Number</th><th>Meaning</th></tr> <tr class="no_0"><td>000000</td><td>0</td><td>.red and .green are identical</td></tr> <tr class="no_1"><td>000001</td><td>1</td><td>The nodes are in different documents (or one is outside of a document)</td></tr> <tr class="no_2"><td>000010</td><td>2</td><td>.green precedes .red</td></tr> <tr class="no_4"><td>000100</td><td>4</td><td>.red precedes .green</td></tr> <tr class="no_8"><td>001000</td><td>8</td><td>.green contains .red</td></tr> <tr class="no_16"><td>010000</td><td>16</td><td>.red contains .green</td></tr> </table> <script type='text/javascript' src='../../node_modules/steal/steal.js' main='@empty'> </script> <script id="demo-source" type='text/javascript'> steal('jquerypp/dom/compare',function(){ var placing = 'red' //on click, set red and green and compare positions $('div').click(function(ev){ var next = placing == 'red' ? 'green' : 'red'; $('.'+placing).removeClass(placing) $(this).addClass(placing) placing = next ev.stopPropagation(); //don't worry about repeat queries for simple example if($('.green').length){ var result = $('.red').compare($('.green')) $("#result").text(result); $('tr.matches').removeClass('matches'); $.each([0, 1, 2, 4, 8, 16], function(i, value) { if(result & value || result === value) { $('tr.no_' + value).addClass('matches'); } }); } }); $(function(){ if(window.parent == window){ $('.hide').show() } }); }); </script> </body> </html>