This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy patheditable-list.html
executable file
·99 lines (91 loc) · 3.22 KB
/
editable-list.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
<!DOCTYPE html>
<html lang="en" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-tap-highlight" content="no">
<title>ChocolateChip-UI Android</title>
<link rel="stylesheet" href="../chui/chui-android-3.9.2.css">
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="../chui/chui-3.9.2.js"></script>
<script>
var listData = [
'التفاح',
'البرتقال',
'الموز',
'الكمثرى',
'الخس',
'الطماطم',
'البطاطا',
'هذه هي بعض النصوص سخيفة ليستغرق الكثير من الفضاء.'
];
$(function() {
if (localStorage.getItem('chosen-items')) {
var items = localStorage.getItem('chosen-items');
items = items.split("'")[1];
JSON.parse(items).forEach(function(ctx) {
$('#editList').append('<li data-list-item-value="'+ ctx + '"><h3>' + ctx + '</h3></li>');
});
} else {
listData.forEach(function(ctx) {
$('#editList').append('<li data-list-item-value="'+ ctx + '"><h3>' + ctx + '</h3></li>');
});
}
////////////////////////////////////////
// Inialize editable list with callback:
////////////////////////////////////////
var editableListOptions = {
// Uncomment either of these to
// disable movable or deletable:
// movable: false,
// deletable: false,
editLabel: 'تحرير',
doneLabel: 'منجز',
deleteLabel: 'حذف',
// Define callback for "Done" button:
callback: function(item) {
var text = $(item).siblings('h3').text();
$('#response').html('You deleted: <strong>' + text + '</strong>');
var tempArray = [];
$('#editList').find('li').forEach(function(ctx) {
tempArray.push($(ctx).attr('data-list-item-value'));
});
tempArray = "'" + JSON.stringify(tempArray) + "'";
try {
localStorage.setItem('chosen-items', tempArray);
} catch(err) {
return
}
}
};
$('#editList').UIEditList(editableListOptions);
// Reset list by deleting localStorage:
$('#resetList').on('singletap', function() {
localStorage.removeItem('chosen-items');
$('#editList').empty();
listData.forEach(function(ctx) {
$('#editList').append('<li data-list-item-value="'+ ctx + '"><h3>' + ctx + '</h3></li>');
});
$('#editList').UIEditList(editableListOptions);
$('#editList').removeClass('showIndicators');
$('button.done').addClass('edit').removeClass('done').text('Edit');
});
});
</script>
</head>
<body>
<nav>
<h1>قائمة قابلة للتحرير</h1>
</nav>
<article id='main'>
<section>
<ul class='list' id='editList'>
</ul>
<p><button id='resetList' class="action">إعادة تعيين القائمة</button></p>
</section>
</article>
</body>
</html>
</html>