forked from bitovi/jquerypp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompare.html
More file actions
113 lines (101 loc) · 2.76 KB
/
compare.html
File metadata and controls
113 lines (101 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!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>