Skip to content

Commit 1d391c8

Browse files
author
robmadeyou
committed
Use Selectize instead!
1 parent 43e89ba commit 1d391c8

24 files changed

+467
-126
lines changed

CHANGELONG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#Changelog
22

3+
### 1.1.0
4+
* Using Selectize for better ajax searchable inputs
5+
36
### 1.0.0
47
* Refactored the Single select and multi select dropdowns
58

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Module.Leaf.Chosen
1+
Module.Leaf.Selectize

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "gcdtech/module-leaf-chosen",
3-
"description": "Dropdowns and selections from the Chosen library",
2+
"name": "gcdtech/module-leaf-selectize",
3+
"description": "Dropdowns and selections from the Selectize library",
44
"keywords": [
55
"leaf",
66
"mvp",
7-
"chosen",
7+
"selectize",
88
"rhubarb",
99
"php",
1010
"framework",
1111
"harvest"
1212
],
13-
"homepage": "https://github.com/GCDTech/Module.Leaf.Chosen",
13+
"homepage": "https://github.com/GCDTech/Module.Leaf.Selectize",
1414
"license": "Apache-2.0",
1515
"autoload": {
1616
"psr-4": {
17-
"Rhubarb\\Leaf\\Chosen\\": "src/"
17+
"Rhubarb\\Leaf\\Selectize\\": "src/"
1818
}
1919
},
2020
"require": {

src/Ajax/ChosenAjaxDropDown/ChosenAjaxDropDownView.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Ajax/ChosenAjaxDropDown/ChosenAjaxDropDownViewBridge.js

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace Rhubarb\Leaf\Chosen\Ajax\ChosenAjaxDropDown;
3+
namespace Rhubarb\Leaf\Selectize\Ajax\SelectizeAjaxDropDown;
44

55
use Rhubarb\Crown\Events\Event;
6-
use Rhubarb\Leaf\Chosen\ChosenDropdown\ChosenDropdown;
6+
use Rhubarb\Leaf\Selectize\SelectizeDropdown\SelectizeDropdown;
77

8-
class ChosenAjaxDropDown extends ChosenDropdown
8+
class SelectizeAjaxDropDown extends SelectizeDropdown
99
{
10-
/** @var ChosenAjaxDropDownModel $model */
10+
/** @var SelectizeAjaxDropDownModel $model */
1111
protected $model;
1212

1313
/** @var Event $searchedEvent */
@@ -22,20 +22,20 @@ public function __construct($name = null)
2222

2323
protected function getViewClass()
2424
{
25-
return ChosenAjaxDropDownView::class;
25+
return SelectizeAjaxDropDownView::class;
2626
}
2727

2828
protected function createModel()
2929
{
30-
return new ChosenAjaxDropDownModel();
30+
return new SelectizeAjaxDropDownModel();
3131
}
3232

3333
protected function onModelCreated()
3434
{
3535
parent::onModelCreated();
3636

3737
$this->model->searchedEvent->attachHandler(function($searchQuery) {
38-
$this->searchedEvent->raise($searchQuery);
38+
return $this->searchedEvent->raise($searchQuery);
3939
});
4040
}
4141
}

src/Ajax/ChosenAjaxDropDown/ChosenAjaxDropDownModel.php renamed to src/Ajax/SelectizeAjaxDropDown/SelectizeAjaxDropDownModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace Rhubarb\Leaf\Chosen\Ajax\ChosenAjaxDropDown;
3+
namespace Rhubarb\Leaf\Selectize\Ajax\SelectizeAjaxDropDown;
44

55
use Rhubarb\Crown\Events\Event;
66
use Rhubarb\Leaf\Controls\Common\SelectionControls\SelectionControlModel;
77

8-
class ChosenAjaxDropDownModel extends SelectionControlModel
8+
class SelectizeAjaxDropDownModel extends SelectionControlModel
99
{
1010
public $searchedEvent;
1111

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rhubarb\Leaf\Selectize\Ajax\SelectizeAjaxDropDown;
4+
5+
use Rhubarb\Leaf\Selectize\SelectizeDropdown\SelectizeDropdownView;
6+
7+
class SelectizeAjaxDropDownView extends SelectizeDropdownView
8+
{
9+
protected function getViewBridgeName()
10+
{
11+
return 'SelectizeAjaxDropDownViewBridge';
12+
}
13+
14+
public function getViewBridgePath()
15+
{
16+
return __DIR__ . '/SelectizeAjaxDropDownViewBridge.js';
17+
}
18+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
rhubarb.vb.create('SelectizeAjaxDropDownViewBridge', function(parent) {
2+
return {
3+
attachEvents: function() {
4+
var self = this;
5+
this.currentRequest = null;
6+
this.searchTimeout = null;
7+
8+
parent.attachEvents.call(this);
9+
10+
this.chosen.parent().find('.chosen-search-input').keyup(function(event) {
11+
if (self.searchTimeout) {
12+
clearTimeout(self.searchTimeout);
13+
}
14+
15+
var value = this.value;
16+
17+
self.searchTimeout = setTimeout(function() {
18+
if (value) {
19+
if (self.currentRequest) {
20+
self.currentRequest.abort();
21+
}
22+
23+
self.currentRequest = self.raiseServerEvent('searched', value, function (response) {
24+
if (response && response instanceof Array && response.length) {
25+
self.updateSelectionItems(response, value);
26+
}
27+
28+
self.currentRequest = null;
29+
});
30+
}
31+
}, 150);
32+
});
33+
},
34+
updateSelectionItems: function(response, value) {
35+
var self = this;
36+
37+
self.viewNode.innerHTML = '';
38+
39+
$.map(response, function(item){
40+
$(self.viewNode).append('<option value="' + item.value + '">' + item.name + '</option>');
41+
});
42+
43+
$(this.viewNode).trigger("chosen:updated");
44+
self.chosen.parent().find('.chosen-search-input').val(value);
45+
}
46+
};
47+
}, window.rhubarb.viewBridgeClasses.SelectizeLibraryViewBridge);

src/Ajax/ChosenAjaxMultiSelect/ChosenAjaxMultiSelect.php renamed to src/Ajax/SelectizeAjaxMultiSelect/SelectizeAjaxMultiSelect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Rhubarb\Leaf\Chosen\Ajax\ChosenAjaxMultiSelect;
3+
namespace Rhubarb\Leaf\Selectize\Ajax\SelectizeAjaxMultiSelect;
44

5-
use Rhubarb\Leaf\Chosen\Ajax\ChosenAjaxDropDown\ChosenAjaxDropDown;
5+
use Rhubarb\Leaf\Selectize\Ajax\SelectizeAjaxDropDown\SelectizeAjaxDropDown;
66

7-
class ChosenAjaxMultiSelect extends ChosenAjaxDropDown
7+
class SelectizeAjaxMultiSelect extends SelectizeAjaxDropDown
88
{
99
protected function supportsMultipleSelection()
1010
{

0 commit comments

Comments
 (0)