-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now an "options widget" supports hints about its rendering: - "renderHint: buttonset" will render via buttonset instead of select (dropdown). - "buttonsetIconClasses: key=value|key=value" let define css classes for the css icons to be used in the buttons (see fontawesome). - "buttonsetLabels: key=value|key=value" let define labels for the buttonset (you have less horizontal space so maybe you need shorter labels). - "renderHint: fontface" will use a styled dropdown using the keys of the dropadown as the font-family of the label. - "renderHint: images": - "imagesSources: key=url('path')|key=url('path')" to specify the template relative images to be used as labels of the select widget.
- Loading branch information
Showing
7 changed files
with
282 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.selectize-control.single { | ||
// hide the autocomplete/edit input as we are in a non-editable select | ||
&.selectize-force-single-noadd .selectize-input { | ||
cursor: default; | ||
> input { | ||
display: none !important; | ||
} | ||
&.input-active { | ||
cursor: inherit; | ||
} | ||
} | ||
&.selectize-hint-images .selectize-input, &.selectize-hint-images .selectize-input.input-active { | ||
padding-top: 2px; | ||
padding-bottom: 0px; | ||
padding-right: 32px; | ||
} | ||
.selectize-input, .selectize-input.input-active { | ||
// default selectize uses relative but we don't need that. | ||
position: initial; | ||
.input-style(); | ||
margin: 0; | ||
&:after { | ||
.button-style(); | ||
margin: 0; | ||
|
||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
line-height: 30px; | ||
width: 28px; | ||
margin-right: 0; | ||
border-top-left-radius: 0; | ||
border-bottom-left-radius: 0; | ||
|
||
font-family: FontAwesome; | ||
content: "\f0d7"; | ||
font-weight: normal; | ||
|
||
pointer-events:none; | ||
} | ||
} | ||
.selectize-input.dropdown-active::before { | ||
// prevent the 1px move | ||
display: none; | ||
} | ||
.selectize-dropdown { | ||
.win(); | ||
z-index: 1000; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"use strict"; | ||
/* global global: false, console: false */ | ||
var $ = require("jquery"); | ||
var ko = require("knockout"); | ||
// selectize doesn't work if we don't expose this in the global (window) object | ||
global.Sifter = require('@selectize/sifter'); | ||
var Selectize = require('@selectize/selectize'); | ||
|
||
// automatic dropdown direction: loop-logic like the one we contributed to Colorpicker | ||
if (!Selectize.prototype.positionDropdownOriginal) { | ||
Selectize.prototype.positionDropdownOriginal = Selectize.prototype.positionDropdown; | ||
Selectize.prototype.positionDropdown = function () { | ||
var el = this.$wrapper; | ||
var i = 0; | ||
|
||
while (el !== null && i < 100) { | ||
// Look up the first parent with non-visibile overflow and compute the relative position | ||
if (el.css('overflow') !== 'visible') { | ||
var offset = el.offset(); | ||
|
||
offset.top += this.$control.outerHeight(true); | ||
|
||
var dropdownHeight = this.$dropdown.prop('scrollHeight') + 5; // 5 - padding value; | ||
var controlPosTop = this.$control.get(0).getBoundingClientRect().top; | ||
var wrapperHeight = this.$wrapper.height(); | ||
|
||
var position = controlPosTop + dropdownHeight + wrapperHeight > global.innerHeight ? 'top' : 'bottom'; | ||
var styles = { | ||
width: this.$control.outerWidth(), | ||
left: 0, | ||
top: position === 'top' ? - dropdownHeight : wrapperHeight, | ||
}; | ||
|
||
this.$dropdown.css(styles); | ||
break; | ||
} | ||
if (el[0].tagName == 'HTML') break; | ||
else el = el.offsetParent(); | ||
i++; | ||
} | ||
}; | ||
} | ||
|
||
ko.bindingHandlers.selectize = { | ||
init: function(element, valueAccessor, allBindingsAccessor) { | ||
var $element = $(element); | ||
|
||
var renderFunction = function(type, item, escape) { | ||
return '<div class="' + type + '">' + escape(item.text) + '</div>'; | ||
}; | ||
|
||
var overrideRenderFunction = allBindingsAccessor.get("selectizeRenderer"); | ||
if (typeof overrideRenderFunction !== 'undefined' && overrideRenderFunction !== null) renderFunction = overrideRenderFunction; | ||
|
||
$element.selectize({ | ||
maxItems: 1, | ||
closeAfterSelect: true, | ||
selectOnTab: true, | ||
/* @see https://github.com/selectize/selectize.js/discussions/1804 | ||
onClear: function() { | ||
return false; | ||
}, | ||
onDelete: function() { | ||
return false; | ||
}, | ||
*/ | ||
// dropdownParent: 'body', | ||
// openOnFocus: true, | ||
onChange: function(value) { | ||
valueAccessor()(value); | ||
}, | ||
render: { | ||
option: renderFunction.bind(undefined, 'option'), | ||
item: renderFunction.bind(undefined, 'item') | ||
}, | ||
}); | ||
|
||
ko.utils.domNodeDisposal.addDisposeCallback(element, function() { | ||
$element[0].selectize.destroy(); | ||
}); | ||
}, | ||
|
||
update: function(element, valueAccessor) { | ||
var value = valueAccessor(); | ||
element.selectize.setValue(ko.utils.unwrapObservable(value), true); | ||
}, | ||
}; |
Oops, something went wrong.