This repository was archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathautodividers.html
145 lines (128 loc) · 4.13 KB
/
autodividers.html
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery Mobile: Autodividers</title>
<link rel="stylesheet" href="../../css/themes/default/jquery.mobile.css" />
<script src="../../external/jquery/jquery.js"></script>
<script src="../../js/"></script>
</head>
<body>
<div data-role="page" id="baseline">
<div data-role="toolbar" data-type="header">
<h1>Autodividers</h1>
</div>
<div data-role="content">
<p>This should get auto-dividers based on link text.</p>
<ul id="link-text-dividers" data-role="listview" data-autodividers="true">
<li><a href="#">Amy</a></li>
<li><a href="#">Andrew</a></li>
<li><a href="#">Astrid</a></li>
<li><a href="#">Bertie</a></li>
<li><a href="#">Carrie</a></li>
<li><a href="#">Derek</a></li>
<li><a href="#">Ian</a></li>
<li><a href="#">Matthew</a></li>
</ul>
</div>
<div data-role="content">
<p>This should get auto-dividers based on link text but
shouldn't produce duplicate dividers. Should also
add more dividers if new list elements are added. Note that
removing Bertie should cause the duplicate "A" dividers to merge
and trigger a "listviewchange" event.</p>
<p>
<button id="add-gary-button" data-inline="true">Add Gary and refresh</button>
<button id="remove-bertie-button" data-inline="true">Remove Bertie and refresh</button>
</p>
<ul id="refreshable-dividers" data-role="listview" data-autodividers="true">
<li><a href="#">Amy</a></li>
<li><a href="#">Andrew</a></li>
<li><a href="#">Angela</a></li>
<li><a href="#">Bertie</a></li>
<li><a href="#">Astrid</a></li>
<li><a href="#">Carrie</a></li>
<li><a href="#">Derek</a></li>
<li><a href="#">Ian</a></li>
<li><a href="#">Matthew</a></li>
</ul>
</div>
<div data-role="content">
<p>This uses a custom selector to draw text from formatted list
items.</p>
<ul id="custom-selector">
<li><span>Anne</span> likes to eat sweets</li>
<li><span>Beth</span> likes to eat treats</li>
<li><span>Bill</span> likes to eat meats</li>
<li><span>Carl</span> likes to eat beets</li>
</ul>
</div>
<div data-role="content">
<p>This should get auto-dividers based on text. NB this has
intentionally blank li elements to check they don't get dividers.</p>
<ul id="text-dividers" data-role="listview" data-autodividers="true">
<li>Barry</li>
<li>Betty</li>
<li>Carrie</li>
<li>Harry</li>
<li></li>
<li>Hetty</li>
<li>Kitty</li>
<li>Larry</li>
<li></li>
<li>Laurie</li>
<li>Mary</li>
</ul>
</div>
<div data-role="content">
<p>Non-sorted list will produce duplicate auto-dividers.</p>
<ul id="non-sorted" data-role="listview" data-autodividers="true">
<li>Barry</li>
<li>Carrie</li>
<li>Betty</li>
<li>Harry</li>
<li>Carly</li>
<li>Hetty</li>
</ul>
</div>
<div data-role="content">
<p>This had dividers already which were replaced.</p>
<ul id="has-dividers" data-role="listview" data-autodividers="true">
<li data-role="list-divider">Any old iron</li>
<li><a href="#">Amy</a></li>
<li><a href="#">Andrew</a></li>
<li><a href="#">Astrid</a></li>
<li data-role="list-divider">Barnacles</li>
<li><a href="#">Bertie</a></li>
<li data-role="list-divider">Crop circle</li>
<li><a href="#">Carrie</a></li>
<li data-role="list-divider">Dog</li>
<li><a href="#">Derek</a></li>
<li data-role="list-divider">Igloos</li>
<li><a href="#">Ian</a></li>
<li data-role="list-divider">Massive clouds</li>
<li><a href="#">Matthew</a></li>
</ul>
</div>
</div>
<script>
$(document).bind('pagecreate', function () {
$('#custom-selector').listview({
autodividers: true,
autodividersSelector: function( elt ) {
return elt.find('span').text();
}
});
$('#add-gary-button').bind('click', function () {
var gary = $('<li><a href="#">Gary</a></li>');
$('#refreshable-dividers').find('li.ui-listview-item-divider:contains(I)').before(gary);
$('#refreshable-dividers').listview('refresh');
});
$('#remove-bertie-button').bind('click', function () {
$('#refreshable-dividers').find('li:contains("Bertie")').remove();
$('#refreshable-dividers').listview('refresh');
});
});
</script>
</body>
</html>