-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyScript.js
177 lines (145 loc) · 7.23 KB
/
myScript.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Dropdown Search For BS4 Classes
$(document).ready(function() {
// JSON Pull from File, then split between ul & li Sections
$.getJSON("data2.json", function(data) {
var html = '';
for (var key in data) { // Each top-level entry
html += '<ul><span>' + key + '</span>';
for (var i = 0; i < data[key].length; i++) { // Each sub-entry
html += '<li>' + data[key][i] + '</li>';
}
html += '</ul>';
}
$('.bs4-list').append(html);
});
// Search Classes Function
$("#myInput1").on("keyup", function() {
var $classes = $('.bs4-list li');
var val = $(this).val().toLowerCase();
$classes.show().filter(function() {
var text = $(this).text().toLowerCase();
return !~text.indexOf(val);
}).hide();
$("ul").each(function() {
if ($(this).find("li").is(':visible') || $(this).find("li").css('display') != 'none') {
$(this).show();
} else {
$(this).hide();
}
});
});
});
// Show Scrollbar on hover & touch
$(".bs4-list").on('mouseenter touchstart', function() {
$('.bs4-list').addClass('show');
}).on('mouseleave touchend', function() {
$('.bs4-list').removeClass('show');
});
// -----------------------------------------------------------------------------------------------------------------
// MySelectBox with editable, addable, removerble Rows.
$('.MySelect').on('click', function(e) {
e.stopPropagation();
});
$(".add").click(function() {
var randomSelection = ["My New Selector", "Another Selector", "Newer Selector", "Inserted Row", "Selector Row", "Selection Sample", "Editable Selection Box", "Selector designs", "Informational Rows", "Title Prefix Posibilities", "Sample BootStrap Dropdown Ideas", "Random Text Selections, That are editable", "Only change CSS to Fit your Design", "Save to Local Storage, json, or DB", "Innovative Designs", "Ease of use!", "FixNet IT Solutions", "DataSafe 4 Client Database", "DS4 Form Designer", "MultiPage Form Designs"];
var randomSelector = randomSelection[Math.floor(Math.random() * randomSelection.length)];
var newElement =
'<div class="input-group">' +
'<input type="text" readonly="" class="MySelectItem form-control-plaintext text-secondary" value="' + randomSelector + '">' +
'<div class="input-group-append">' +
'<button class="btn btn-sm del" id="del" type="button"><i class="fas fa-minus-square"></i></button>' +
'</div>' +
'</div>';
$(".MySelect").prepend($(newElement));
$('.del').show();
$('.MySelectItem').prop("readonly", false);
});
var edit = false;
$('[name="Edit"]').on('click', function() {
if (!edit) {
$(this).html('<i class="text-warning fas fa-check-square"></i>');
$('.MySelectItem').prop("readonly", false);
$('.add, .del').show();
edit = true;
} else {
$(this).html('<i class="fa fa-ellipsis-v"></i>');
$('.MySelectItem').prop("readonly", true);
$('.add, .del').hide();
var itm = $('.MySelectBox').text();
save(itm);
edit = false;
}
});
$(document).ready(function() { // From Local Storage
var html = '';
var data = JSON.parse(localStorage.getItem('DropStore'));
console.log(JSON.stringify(data));
for (var key in data) {
for (var i = 0; i < data[key].length; i++) {
html +=
'<div class="input-group">' +
'<input type="text" readonly="" class="MySelectItem form-control-plaintext text-secondary" value="' + data[key][i] + '">' +
'<div class="input-group-append">' +
'<button class="btn btn-sm del" id="del" type="button"><i class="fas fa-minus-square"></i></button>' +
'</div>' +
'</div>';
}
}
// console.log(key);
$('.MySelectBox').text(key);
$(".MySelect").prepend($(html));
});
// Save to Local Storage
function save(key = 'MySelectBox') {
var arr = $('.MySelectItem').map(function() { return this.value; }).get();
var jsn = '{"' + key + '":' + JSON.stringify(arr) + '}'
localStorage.setItem('DropStore', jsn);
}
$('.MySelect').on('click', '.MySelectItem', function(e) {
if (edit) {return;}
var itm = e.target.value;
console.log('itm: ', itm);
$('.MySelectBox').text(itm);
save(itm);
});
// Delete the SelectBoxItem.
$('.MySelect').on('click', '.del', function() {
console.log('removing: ',$(this).parent().parent().html() );
$(this).parent().parent().remove();
})
// Extra Code to view or test.
// ---------------------------------------------------------------------------------------------------
// params = '123';
// jsn = {
// key: [...params]
// };
// console.log(JSON.stringify(jsn));
// var obj = JSON.parse(localStorage.getItem('DropStore'));
// localStorage.setItem('DropStore', JSON.stringify(obj));
// var person = { "name": "billy", "age": 23};
// localStorage.setItem('person', JSON.stringify(person)); //stringify object and store
// var retrievedPerson = JSON.parse(localStorage.getItem('person')); //retrieve the object
// JSON Pull from File, & insert to input values that are dynamically added.
// $.getJSON("myData.json", function(data) { // From Json File
// Get Array from Local Storage & add a key value
//$($('template').html()).insertAfter($('#somewhere_else'));
// $('.MySelectBox').trigger('click');
// function getInputsAsJSON() {
// var Values = [];
// $(".MySelectItem").each(function() {
// var key = 'Select'
// var value = $(this).val();
// Values.push([value])
// });
// return Values;
// }
// function renameKey(obj, oldKey, newKey) {
// obj[newKey] = obj[oldKey];
// delete obj[oldKey];
// }
// const arr = JSON.parse(json);
// arr.forEach(obj => renameKey(obj, '_id', 'id'));
// const updatedJson = JSON.stringify(arr);
// console.log(updatedJson);
// MySelectBox - Have to use Parent Element for dynamically added content.
//-------------------------------------------------------------------------------------------