├── favicon.ico ├── img ├── logo_70.png ├── logo_sm.png └── gif │ └── searching.gif ├── package.json ├── docs ├── CONTRIBUTING.md └── CHANGELOG.md ├── LICENSE.txt ├── css └── style.css ├── test.html ├── searchAreaControl ├── css │ └── sac-style.css └── searchAreaControl.js ├── lib └── index.d.ts ├── js └── main.js ├── README.md └── index.html /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapantzak/SearchAreaControl/HEAD/favicon.ico -------------------------------------------------------------------------------- /img/logo_70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapantzak/SearchAreaControl/HEAD/img/logo_70.png -------------------------------------------------------------------------------- /img/logo_sm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapantzak/SearchAreaControl/HEAD/img/logo_sm.png -------------------------------------------------------------------------------- /img/gif/searching.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapantzak/SearchAreaControl/HEAD/img/gif/searching.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "searchareacontrol", 3 | "version": "2.8.6", 4 | "description": "A jQuery plugin used to display, search and select multiple items", 5 | "main": "searchAreaControl/searchAreaControl.js", 6 | "types": "lib/index.d.ts", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/kapantzak/SearchAreaControl.git" 13 | }, 14 | "keywords": [ 15 | "jquery-plugin", 16 | "ecosystem:jquery", 17 | "multiselect" 18 | ], 19 | "dependencies": { 20 | "@types/jquery": "*" 21 | }, 22 | "author": "John Kapantzakis", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/kapantzak/SearchAreaControl/issues" 26 | }, 27 | "homepage": "https://github.com/kapantzak/SearchAreaControl#readme" 28 | } 29 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | Everyone who wants to contribute to this project is realy welcome. Please read the following steps if you want to contribute to this project. 4 | 5 | ## Steps 6 | 1. **[Fork](https://help.github.com/articles/fork-a-repo/ "Fork")** the project 7 | 2. **[Clone](https://help.github.com/articles/cloning-a-repository/ "Clone")** the forked project on your machine 8 | 3. Create **one branch for each** seperate issue (if more than one exists) 9 | 4. **TEST** the code before commiting your changes 10 | 4. Commit with meaningful messages 11 | 5. Create a **[Pull Request](https://help.github.com/articles/about-pull-requests/)** 12 | 13 | ## Some useful resources 14 | - [https://akrabat.com/the-beginners-guide-to-contributing-to-a-github-project/](https://akrabat.com/the-beginners-guide-to-contributing-to-a-github-project/) 15 | - [https://opensource.guide/how-to-contribute/](https://opensource.guide/how-to-contribute/) -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Ioannis Kapantzakis 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Montserrat', sans-serif; 3 | } 4 | 5 | p { 6 | font-size: 16px; 7 | line-height: 1.65; 8 | } 9 | 10 | .nowrap { 11 | white-space: nowrap; 12 | } 13 | 14 | .custom-text-info { 15 | font-size: 0.9em; 16 | } 17 | 18 | .marginLeft-sm { margin-left:5px } 19 | .marginLeft-md { margin-left:15px } 20 | 21 | #mainLogo { 22 | height:45px; 23 | } 24 | 25 | #gitHub { 26 | position: relative; 27 | top:5px; 28 | } 29 | 30 | .gif-holder { 31 | margin-bottom: 30px; 32 | text-align: center; 33 | } 34 | 35 | .gif-holder img { 36 | width:100%; 37 | max-width: 771px; 38 | } 39 | 40 | .demo-panel, 41 | .table-panel { 42 | margin: 30px 0; 43 | } 44 | 45 | .demo-panel-title { 46 | color:#777; 47 | } 48 | 49 | #footer { 50 | position: relative; 51 | background-color: #333; 52 | color:#fafafa; 53 | margin-top: 40px; 54 | padding: 40px 0; 55 | text-align: center; 56 | } 57 | 58 | #kapa_logo { 59 | position: absolute; 60 | height: 36px; 61 | right: 10px; 62 | top: 50%; 63 | margin-top: -18px; 64 | } 65 | 66 | @media (max-width: 768px) { 67 | #mainLogo { 68 | height: 5vw; 69 | } 70 | #mainTitleText { 71 | font-size: 16px; 72 | font-size: 4vw; 73 | } 74 | } 75 | 76 | @media (max-width: 1400px) { 77 | #mainTitleSecondaryText { 78 | display: none; 79 | } 80 | } -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |
SearchAreaControl jQuery pluginGithubTest page
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 |
SearchAreaControl jQuery pluginGithubSearchAreaControl is a complete jQuery plugin that let's you display, search and select multiple items of a tree data structure.
28 | 29 |
32 | In order to user SearchAreaControl plugin you have to include jQuery before the plugin's script. Then, you can initialize the plugin providing the appropriate data and any custom options.
36 |The plugin accepts a specific format of data. It actually accepts an array of nested objects (every object can hold an array of children objects) that produce a group of tree data structures.
37 | 38 |46 |
var myData = [
47 | {
48 | "code": null,
49 | "group": null,
50 | "name": "Economy car",
51 | "attributes": {
52 | "data-id": "1"
53 | },
54 | "children": [
55 | {
56 | "code": null,
57 | "group": null,
58 | "name": "Microcar",
59 | "attributes": {
60 | "data-id": "11"
61 | },
62 | "children": null
63 | },
64 | {
65 | "code": null,
66 | "group": null,
67 | "name": "Hatchbacks",
68 | "attributes": {
69 | "data-id": "12"
70 | },
71 | "children": [
72 | {
73 | "code": null,
74 | "group": null,
75 | "name": "Ultracompact car",
76 | "attributes": {
77 | "data-id": "121"
78 | },
79 | "children": null
80 | },
81 | {
82 | "code": null,
83 | "group": null,
84 | "name": "City car",
85 | "attributes": {
86 | "data-id": "122"
87 | },
88 | "children": null
89 | },
90 | {
91 | "code": null,
92 | "group": null,
93 | "name": "Supermini/subcompact car",
94 | "attributes": {
95 | "data-id": "123"
96 | },
97 | "children": null
98 | }
99 | ]
100 | }
101 | ]
102 | },
103 | {
104 | "code": null,
105 | "group": null,
106 | "name": "Family car",
107 | "attributes": {
108 | "data-id": "2"
109 | },
110 | "children": [
111 | {
112 | "code": null,
113 | "group": null,
114 | "name": "Small family car/compact car",
115 | "attributes": {
116 | "data-id": "21"
117 | },
118 | "children": null
119 | },
120 | {
121 | "code": null,
122 | "group": null,
123 | "name": " Large family / mid-size",
124 | "attributes": {
125 | "data-id": "22"
126 | },
127 | "children": null
128 | }
129 | ]
130 | },
131 | {
132 | "code": null,
133 | "group": null,
134 | "name": "Saloons / sedans",
135 | "attributes": {
136 | "data-id": "3"
137 | },
138 | "children": [
139 | {
140 | "code": null,
141 | "group": null,
142 | "name": "Large family / mid-size",
143 | "attributes": {
144 | "data-id": "31"
145 | },
146 | "children": null
147 | },
148 | {
149 | "code": null,
150 | "group": null,
151 | "name": "Full size / large",
152 | "attributes": {
153 | "data-id": "32"
154 | },
155 | "children": null
156 | },
157 | {
158 | "code": null,
159 | "group": null,
160 | "name": "Crossover SUV",
161 | "attributes": {
162 | "data-id": "33"
163 | },
164 | "children": null
165 | },
166 | {
167 | "code": null,
168 | "group": null,
169 | "name": "Minivans / MPVs",
170 | "attributes": {
171 | "data-id": "34"
172 | },
173 | "children": null
174 | }
175 | ]
176 | },
177 | {
178 | "code": null,
179 | "group": null,
180 | "name": "Luxury vehicle",
181 | "attributes": {
182 | "data-id": "4"
183 | },
184 | "children": [
185 | {
186 | "code": null,
187 | "group": null,
188 | "name": "Compact executive",
189 | "attributes": {
190 | "data-id": "41"
191 | },
192 | "children": null
193 | },
194 | {
195 | "code": null,
196 | "group": null,
197 | "name": "Executive / mid-luxury",
198 | "attributes": {
199 | "data-id": "42"
200 | },
201 | "children": null
202 | },
203 | {
204 | "code": null,
205 | "group": null,
206 | "name": "Full-size luxury / Grand saloon",
207 | "attributes": {
208 | "data-id": "43"
209 | },
210 | "children": null
211 | },
212 | {
213 | "code": null,
214 | "group": null,
215 | "name": "Estate cars / station wagons",
216 | "attributes": {
217 | "data-id": "44"
218 | },
219 | "children": null
220 | }
221 | ]
222 | },
223 | {
224 | "code": null,
225 | "group": null,
226 | "name": "Sports cars",
227 | "attributes": {
228 | "data-id": "5"
229 | },
230 | "children": [
231 | {
232 | "code": null,
233 | "group": null,
234 | "name": "Hot hatch",
235 | "attributes": {
236 | "data-id": "51"
237 | },
238 | "children": null
239 | },
240 | {
241 | "code": null,
242 | "group": null,
243 | "name": "Sports saloon / sports sedan",
244 | "attributes": {
245 | "data-id": "52"
246 | },
247 | "children": null
248 | },
249 | {
250 | "code": null,
251 | "group": null,
252 | "name": "Sports car",
253 | "attributes": {
254 | "data-id": "53"
255 | },
256 | "children": null
257 | },
258 | {
259 | "code": null,
260 | "group": null,
261 | "name": "Grand tourer",
262 | "attributes": {
263 | "data-id": "54"
264 | },
265 | "children": null
266 | },
267 | {
268 | "code": null,
269 | "group": null,
270 | "name": "Supercar",
271 | "attributes": {
272 | "data-id": "55"
273 | },
274 | "children": null
275 | },
276 | {
277 | "code": null,
278 | "group": null,
279 | "name": "Muscle car",
280 | "attributes": {
281 | "data-id": "56"
282 | },
283 | "children": null
284 | },
285 | {
286 | "code": null,
287 | "group": null,
288 | "name": "Pony car",
289 | "attributes": {
290 | "data-id": "57"
291 | },
292 | "children": null
293 | },
294 | {
295 | "code": null,
296 | "group": null,
297 | "name": "Convertible",
298 | "attributes": {
299 | "data-id": "58"
300 | },
301 | "children": null
302 | }
303 | ]
304 | },
305 | {
306 | "code": null,
307 | "group": null,
308 | "name": "Off-roaders",
309 | "attributes": {
310 | "data-id": "6"
311 | },
312 | "children": [
313 | {
314 | "code": null,
315 | "group": null,
316 | "name": "Sport utility vehicle",
317 | "attributes": {
318 | "data-id": "61"
319 | },
320 | "children": null
321 | }
322 | ]
323 | },
324 | {
325 | "code": null,
326 | "group": null,
327 | "name": "Commercial vehicle",
328 | "attributes": {
329 | "data-id": "7"
330 | },
331 | "children": [
332 | {
333 | "code": null,
334 | "group": null,
335 | "name": "Van",
336 | "attributes": {
337 | "data-id": "71"
338 | },
339 | "children": null
340 | }
341 | ]
342 | }
343 | ];
344 |
345 | Source: https://en.wikipedia.org/wiki/Car_classification#Microcar
346 |355 |
$('#myButton').searchAreaControl({
356 | data: myData,
357 | mainButton: {
358 | defaultText: 'Cars'
359 | }
360 | });
361 |
362 |
363 | Now, let's use setSelectedNodes method to initialize the plugin with a selected node. We actually initialize the plugin first, and then call the appropriate method.
372 |
var btn = $('#myButton');
373 |
374 | // Initialize plugin
375 | btn.searchAreaControl({
376 | data: myData,
377 | mainButton: {
378 | defaultText: 'Cars'
379 | }
380 | });
381 |
382 | // Call "setSelectedNodes" method to select one node by "data-id" attribute
383 | btn.searchAreaControl('setSelectedNodes', false, [55]);
384 |
385 | 386 | 387 |
388 |There are several methods available to use in order to perform various tasks.
392 | 393 |setSelectedNodes()Select one or more nodes.
402 | 403 |$(document).on('click', '#setSelectedNodes_button', function() {
404 | $('#myButton').searchAreaControl('setSelectedNodes',false,[57]);
405 | });
406 |
407 | getSelectedByAttribute()You can use getSelectedByAttribute() method to get the selected nodes by specific attribute. Here, we can use the data-id attribute.
$(document).on('click', '#getSelectedByAttribute_button', function() {
417 | var selected = $('#myButton').searchAreaControl('getSelectedByAttribute','data-id');
418 | });
419 |
420 | 421 |
setDisabled()You can use setDisabled() to enable or disable the button.
$(document).on('click', '#setDisabled_button', function() {
435 | $('#myButton').searchAreaControl('setDisabled',true);
436 | });
437 | 438 | 439 | 440 |
441 |There is a number of options you can provide in order to customize the appearance and behaviour of the plugin.
448 |The following table demonstate some of them. For a complete list of all the available options view the README.
449 | 450 || Name | 456 |Type | 457 |Default value | 458 |Description | 459 |
|---|---|---|---|
| data | 464 |object |
465 | [] |
466 | Provides the data that are going to be displayed | 467 |
| multiSelect | 470 |boolean |
471 | true |
472 | Set to false if you want to be able to select only one item at time | 473 |
| columns | 476 |number |
477 | 2 |
478 | Set the number of columns that the data will be rendered | 479 |
| selectionByAttribute | 482 |string |
483 | 'data-id' |
484 | Set the attribute that you want to select upon. The plugin will search for this attribute to match with the provided search string to filter all the items of the data array | 485 |
| modallHeader.text | 488 |string |
489 | 'Search' |
490 | The text that is going to be displayed in the modal header | 491 |
| mainButton.defaultText | 494 |string |
495 | 'Items' |
496 | Set the default button text | 497 |
We have already seen some of the available methods in action.
503 |The following table demonstate some of them. For a complete list of all the available methods view the README.
504 | 505 || Name | 511 |Parameters | 512 |Return | 513 |Description | 514 |
|---|---|---|---|
| getData() | 519 |no | 520 |array |
521 | Get the control's datasource object (array) | 522 |
| clearSelection() | 525 |no | 526 |void |
527 | Clear selected items | 528 |
| getSelectedNodes() | 531 |no | 532 |object |
533 | Get an object with two properties, selectedAll (boolean: All items are selected) and selectedNodes (array: Array of selected objects) |
534 |
| updateDatasource(data) | 537 |data [object] |
538 | void |
539 | Update the datasource | 540 |
| destroy() | 543 |no | 544 |void |
545 | Destroy the plugin | 546 |