|
@@ -503,165 +503,6 @@ UI.Select.prototype.setValue = function ( value ) {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
-// FancySelect
|
|
|
|
-
|
|
|
|
-UI.FancySelect = function () {
|
|
|
|
-
|
|
|
|
- UI.Element.call( this );
|
|
|
|
-
|
|
|
|
- var scope = this;
|
|
|
|
-
|
|
|
|
- var dom = document.createElement( 'div' );
|
|
|
|
- dom.className = 'FancySelect';
|
|
|
|
- dom.tabIndex = 0; // keyup event is ignored without setting tabIndex
|
|
|
|
-
|
|
|
|
- Sortable.create( dom, {
|
|
|
|
- onUpdate: function ( event ) {
|
|
|
|
- console.log( event );
|
|
|
|
- }
|
|
|
|
- } );
|
|
|
|
-
|
|
|
|
- // Broadcast for object selection after arrow navigation
|
|
|
|
- var changeEvent = document.createEvent('HTMLEvents');
|
|
|
|
- changeEvent.initEvent( 'change', true, true );
|
|
|
|
-
|
|
|
|
- // Prevent native scroll behavior
|
|
|
|
- dom.addEventListener( 'keydown', function (event) {
|
|
|
|
-
|
|
|
|
- switch ( event.keyCode ) {
|
|
|
|
- case 38: // up
|
|
|
|
- case 40: // down
|
|
|
|
- event.preventDefault();
|
|
|
|
- event.stopPropagation();
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }, false);
|
|
|
|
-
|
|
|
|
- // Keybindings to support arrow navigation
|
|
|
|
- dom.addEventListener( 'keyup', function (event) {
|
|
|
|
-
|
|
|
|
- switch ( event.keyCode ) {
|
|
|
|
- case 38: // up
|
|
|
|
- case 40: // down
|
|
|
|
- scope.selectedIndex += ( event.keyCode == 38 ) ? -1 : 1;
|
|
|
|
-
|
|
|
|
- if ( scope.selectedIndex >= 0 && scope.selectedIndex < scope.options.length ) {
|
|
|
|
-
|
|
|
|
- // Highlight selected dom elem and scroll parent if needed
|
|
|
|
- scope.setValue( scope.options[ scope.selectedIndex ].value );
|
|
|
|
-
|
|
|
|
- scope.dom.dispatchEvent( changeEvent );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }, false);
|
|
|
|
-
|
|
|
|
- this.dom = dom;
|
|
|
|
-
|
|
|
|
- this.options = [];
|
|
|
|
- this.selectedIndex = -1;
|
|
|
|
- this.selectedValue = null;
|
|
|
|
-
|
|
|
|
- return this;
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-UI.FancySelect.prototype = Object.create( UI.Element.prototype );
|
|
|
|
-UI.FancySelect.prototype.constructor = UI.FancySelect;
|
|
|
|
-
|
|
|
|
-UI.FancySelect.prototype.setOptions = function ( options ) {
|
|
|
|
-
|
|
|
|
- var scope = this;
|
|
|
|
-
|
|
|
|
- var changeEvent = document.createEvent( 'HTMLEvents' );
|
|
|
|
- changeEvent.initEvent( 'change', true, true );
|
|
|
|
-
|
|
|
|
- while ( scope.dom.children.length > 0 ) {
|
|
|
|
-
|
|
|
|
- scope.dom.removeChild( scope.dom.firstChild );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- scope.options = [];
|
|
|
|
-
|
|
|
|
- for ( var i = 0; i < options.length; i ++ ) {
|
|
|
|
-
|
|
|
|
- var option = options[ i ];
|
|
|
|
-
|
|
|
|
- var div = document.createElement( 'div' );
|
|
|
|
- div.className = 'option';
|
|
|
|
- div.innerHTML = option.html;
|
|
|
|
- div.value = option.value;
|
|
|
|
- scope.dom.appendChild( div );
|
|
|
|
-
|
|
|
|
- scope.options.push( div );
|
|
|
|
-
|
|
|
|
- div.addEventListener( 'click', function ( event ) {
|
|
|
|
-
|
|
|
|
- scope.setValue( this.value );
|
|
|
|
- scope.dom.dispatchEvent( changeEvent );
|
|
|
|
-
|
|
|
|
- }, false );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return scope;
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-UI.FancySelect.prototype.getValue = function () {
|
|
|
|
-
|
|
|
|
- return this.selectedValue;
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-UI.FancySelect.prototype.setValue = function ( value ) {
|
|
|
|
-
|
|
|
|
- for ( var i = 0; i < this.options.length; i ++ ) {
|
|
|
|
-
|
|
|
|
- var element = this.options[ i ];
|
|
|
|
-
|
|
|
|
- if ( element.value === value ) {
|
|
|
|
-
|
|
|
|
- element.classList.add( 'active' );
|
|
|
|
-
|
|
|
|
- // scroll into view
|
|
|
|
-
|
|
|
|
- var y = element.offsetTop - this.dom.offsetTop;
|
|
|
|
- var bottomY = y + element.offsetHeight;
|
|
|
|
- var minScroll = bottomY - this.dom.offsetHeight;
|
|
|
|
-
|
|
|
|
- if ( this.dom.scrollTop > y ) {
|
|
|
|
-
|
|
|
|
- this.dom.scrollTop = y
|
|
|
|
-
|
|
|
|
- } else if ( this.dom.scrollTop < minScroll ) {
|
|
|
|
-
|
|
|
|
- this.dom.scrollTop = minScroll;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.selectedIndex = i;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- element.classList.remove( 'active' );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.selectedValue = value;
|
|
|
|
-
|
|
|
|
- return this;
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// Checkbox
|
|
// Checkbox
|
|
|
|
|
|
UI.Checkbox = function ( boolean ) {
|
|
UI.Checkbox = function ( boolean ) {
|