Skip to content

Commit

Permalink
0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
htmlhero committed Feb 5, 2019
1 parent 2ab8004 commit 4c9d08b
Show file tree
Hide file tree
Showing 14 changed files with 1,569 additions and 37 deletions.
4 changes: 4 additions & 0 deletions lib/arrow-list/arrow-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ zb.ui.ArrowList.prototype._updateArrows = function() {
showHide(prevArr, false);
showHide(nextArr, false);
return;
} else if (this._buffer.isCyclical()) {
showHide(prevArr, true);
showHide(nextArr, true);
return;
}

var itemsSkipped = this._buffer.getLocalStart();
Expand Down
66 changes: 54 additions & 12 deletions lib/base-list/base-list-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,24 @@ zb.ui.BaseListBuffer.prototype.getLineByIndex = function(index) {
zb.ui.BaseListBuffer.prototype.selectNextLine = function() {
var currGlobalIndex = this.getGlobalIndex();
var nextGlobalIndex = zb.ui.BaseListUtils.getNextLine(currGlobalIndex, this._options.lineSize);
var lastGlobalIndex = this.getGlobalEnd();

// Воркэраунд для циклических списков
if (this.isCyclical() && nextGlobalIndex > lastGlobalIndex) {
var firstGlobalIndex = this.getGlobalStart();
var firstGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(firstGlobalIndex, this._options.lineSize);
var nextGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(nextGlobalIndex, this._options.lineSize);

nextGlobalIndex = firstGlobalLineEnd - (nextGlobalLineEnd - nextGlobalIndex);

// Воркэраунд для последней неполной строки элементов:
// Если на сервере больше нет данных и новый индекс выходит за пределы,
// То попробуем выбрать не строку, а элемент со следующим индексом
if (this.isGlobalEnd() && !this.isLocalIndex(nextGlobalIndex)) {
var possibleGlobalIndex = zb.ui.BaseListUtils.getNextIndex(currGlobalIndex);
} else if (this.isGlobalEnd() && !this.isLocalIndex(nextGlobalIndex)) {
var possibleNextGlobalIndex = zb.ui.BaseListUtils.getNextIndex(currGlobalIndex);

if (this.isLocalIndex(possibleGlobalIndex)) {
nextGlobalIndex = possibleGlobalIndex;
if (this.isLocalIndex(possibleNextGlobalIndex)) {
nextGlobalIndex = possibleNextGlobalIndex;
}
}

Expand All @@ -368,8 +377,22 @@ zb.ui.BaseListBuffer.prototype.selectNextLine = function() {
* @return {boolean}
*/
zb.ui.BaseListBuffer.prototype.selectPrevLine = function() {
var index = zb.ui.BaseListUtils.getPrevLine(this.getGlobalIndex(), this._options.lineSize);
return this.setGlobalIndex(index);
var currGlobalIndex = this.getGlobalIndex();
var prevGlobalIndex = zb.ui.BaseListUtils.getPrevLine(currGlobalIndex, this._options.lineSize);

if (this.isCyclical() && prevGlobalIndex < 0) {
var lastGlobalIndex = this.getGlobalEnd();
var lastGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(lastGlobalIndex, this._options.lineSize);
var prevGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(prevGlobalIndex, this._options.lineSize);

prevGlobalIndex = lastGlobalLineEnd - (prevGlobalLineEnd - prevGlobalIndex);

if (prevGlobalIndex > lastGlobalIndex) {
prevGlobalIndex = zb.ui.BaseListUtils.getPrevLine(prevGlobalIndex, this._options.lineSize);
}
}

return this.setGlobalIndex(prevGlobalIndex);
};


Expand All @@ -381,8 +404,17 @@ zb.ui.BaseListBuffer.prototype.selectNextIndex = function() {
return false;
}

var index = zb.ui.BaseListUtils.getNextIndex(this.getGlobalIndex());
return this.setGlobalIndex(index);
var currGlobalIndex = this.getGlobalIndex();
var lastGlobalIndex = this.getGlobalEnd();
var nextGlobalIndex;

if (this.isCyclical() && currGlobalIndex === lastGlobalIndex) {
nextGlobalIndex = 0;
} else {
nextGlobalIndex = zb.ui.BaseListUtils.getNextIndex(currGlobalIndex);
}

return this.setGlobalIndex(nextGlobalIndex);
};


Expand All @@ -394,8 +426,17 @@ zb.ui.BaseListBuffer.prototype.selectPrevIndex = function() {
return false;
}

var index = zb.ui.BaseListUtils.getPrevIndex(this.getGlobalIndex());
return this.setGlobalIndex(index);
var currGlobalIndex = this.getGlobalIndex();
var lastGlobalIndex = this.getGlobalEnd();
var prevGlobalIndex;

if (this.isCyclical() && currGlobalIndex === 0) {
prevGlobalIndex = lastGlobalIndex;
} else {
prevGlobalIndex = zb.ui.BaseListUtils.getPrevIndex(currGlobalIndex);
}

return this.setGlobalIndex(prevGlobalIndex);
};


Expand Down Expand Up @@ -428,8 +469,9 @@ zb.ui.BaseListBuffer.prototype.setGlobalIndex = function(globalIndex) {

var isSelected = false;

// Чтобы выделялся существующий в DOM элемент.
if (this.isLocalIndex(globalIndex)) {
// Выбрать NaN можно только программно через source,
// пользовательские действия не могут привести к выбору NaN
if (!isNaN(globalIndex)) {
var sourceIndex = globalIndex - this.getSourceStart();
isSelected = this._setSourceIndex(sourceIndex);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/base-list/base-list-data-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
goog.provide('zb.ui.BaseListDataList');
goog.require('zb.ui.BaseListBuffer');
goog.require('zb.ui.DynamicList');
goog.require('zb.ui.CyclicalDataList');



Expand Down Expand Up @@ -149,6 +150,14 @@ zb.ui.BaseListDataList.prototype.isDynamic = function() {
};


/**
* @return {boolean}
*/
zb.ui.BaseListDataList.prototype.isCyclical = function() {
return this._source instanceof zb.ui.CyclicalDataList;
};


/**
* @inheritDoc
*/
Expand Down
14 changes: 2 additions & 12 deletions lib/base-list/base-list-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ zb.ui.BaseListUtils.getPrevLine = function(currIndex, lineSize) {
*/
zb.ui.BaseListUtils.getNextIndex = function(currIndex) {
var nextIndex = currIndex + 1;

if (!zb.ui.BaseListUtils.isValidIndex(nextIndex)) {
return NaN;
}

return nextIndex;
return zb.ui.BaseListUtils.isValidIndex(nextIndex) ? nextIndex : NaN;
};


Expand All @@ -155,12 +150,7 @@ zb.ui.BaseListUtils.getNextIndex = function(currIndex) {
*/
zb.ui.BaseListUtils.getPrevIndex = function(currIndex) {
var prevIndex = currIndex - 1;

if (!zb.ui.BaseListUtils.isValidIndex(prevIndex)) {
return NaN;
}

return prevIndex;
return zb.ui.BaseListUtils.isValidIndex(prevIndex) ? prevIndex : NaN;
};


Expand Down
2 changes: 1 addition & 1 deletion lib/data-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ zb.ui.DataList.prototype.isLoading = function() {
* @inheritDoc
*/
zb.ui.DataList.prototype.preload = function() {
return Promise.resolve();
return /** @type {IThenable.<zb.ui.IDataList>} */(Promise.resolve(this));
};


Expand Down
4 changes: 2 additions & 2 deletions lib/dynamic-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ zb.ui.DynamicList.prototype.getFrameSize = function() {


/**
* @return {IThenable.<!zb.ui.DynamicList>}
* @inheritDoc
*/
zb.ui.DynamicList.prototype.preload = function() {
if (!this._preloadQuery) {
Expand All @@ -90,7 +90,7 @@ zb.ui.DynamicList.prototype.preload = function() {
this._preloadQuery = this.loadItems(from, to, false);
}

return this._preloadQuery;
return /** @type {IThenable.<zb.ui.IDataList>} */(this._preloadQuery);
};


Expand Down
2 changes: 1 addition & 1 deletion lib/i-data-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ zb.ui.IDataList.prototype.isLoading = function() {};


/**
* @return {IThenable}
* @return {IThenable.<zb.ui.IDataList>}
*/
zb.ui.IDataList.prototype.preload = function() {};

Expand Down
8 changes: 4 additions & 4 deletions lib/input/native-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ goog.require('zb.ui.IInputWidget');
* @constructor
*/
zb.ui.NativeInput = function(container, opt_params) {
this._onFocus = this._onFocus.bind(this);
this._onFocusInput = this._onFocusInput.bind(this);
this._onKeyDown = this._onKeyDown.bind(this);
this._internalFocus = false;

Expand Down Expand Up @@ -137,12 +137,12 @@ zb.ui.NativeInput.prototype._setupInput = function() {
var input = /** @type {HTMLInputElement} */(this._container);

if (this._input) {
this._input.removeEventListener('focus', this._onFocus);
this._input.removeEventListener('focus', this._onFocusInput);
this._input.removeEventListener('keydown', this._onKeyDown);
}

this._input = input;
this._input.addEventListener('focus', this._onFocus, false);
this._input.addEventListener('focus', this._onFocusInput, false);
this._input.addEventListener('keydown', this._onKeyDown, false);

clearInterval(this._detectChangeIntervalId);
Expand All @@ -155,7 +155,7 @@ zb.ui.NativeInput.prototype._setupInput = function() {
/**
* @protected
*/
zb.ui.NativeInput.prototype._onFocus = function() {
zb.ui.NativeInput.prototype._onFocusInput = function() {
if (this._internalFocus) {
this._internalFocus = false;
} else if (!this.isFocused()) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zombiebox-extension-ui",
"version": "0.1.3",
"version": "0.1.4",
"main": "zombiebox-extension.js",
"scripts": {
"test": "karma start karma.components.conf.js --single-run"
Expand All @@ -22,6 +22,6 @@
"mocha-test-steps": "^0.1.0",
"sinon": "^1.14.1",
"sinon-chai": "^2.7.0",
"zombiebox": "0.0.192"
"zombiebox": "0.0.197"
}
}
53 changes: 50 additions & 3 deletions test/base-list/integration/support/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,42 @@ zb.ui.test.support.Helper.defaultOptions = {
loadOnLeft: 1
};

/**
* @param {Array.<string>} array
* @return {zb.ui.DataList.<string>}
*/
zb.ui.test.support.Helper.createDataList = function(array) {
return new zb.ui.DataList(array);
};

zb.ui.test.support.Helper.createBuffer = function(dataList) {

/**
* @param {zb.ui.DataList.<string>} dataList
* @param {zb.ui.BaseListBuffer.Options=} opt_options
* @return {IThenable.<zb.ui.BaseListBuffer>}
*/
zb.ui.test.support.Helper.createBuffer = function(dataList, opt_options) {
var helper = zb.ui.test.support.Helper;
var buffer = new zb.ui.BaseListDataList(function() {
helper.changeCallback.apply(helper, arguments);
}, function() {
helper.selectCallback.apply(helper, arguments);
});

buffer.setSource(dataList, helper.defaultOptions);
buffer.setSource(dataList, opt_options || helper.defaultOptions);

return dataList.preload();
return dataList
.preload()
.then(function() {
return buffer;
});
};

// Default

/**
* @return {Array.<string>}
*/
zb.ui.test.support.Helper.createDefaultArray = function() {
return [
'A', 'B', 'C',
Expand All @@ -50,18 +67,29 @@ zb.ui.test.support.Helper.createDefaultArray = function() {
];
};


/**
* @return {zb.ui.DataList.<string>}
*/
zb.ui.test.support.Helper.createDefaultDataList = function() {
var array = zb.ui.test.support.Helper.createDefaultArray();
return zb.ui.test.support.Helper.createDataList(array);
};


/**
* @return {IThenable.<zb.ui.BaseListBuffer>}
*/
zb.ui.test.support.Helper.createDefaultBuffer = function() {
var dataList = zb.ui.test.support.Helper.createDefaultDataList();
return zb.ui.test.support.Helper.createBuffer(dataList);
};

// Other

/**
* @return {Array.<string>}
*/
zb.ui.test.support.Helper.createOtherArray = function() {
return [
'alpha', 'beta', 'gamma',
Expand All @@ -75,27 +103,46 @@ zb.ui.test.support.Helper.createOtherArray = function() {
];
};


/**
* @return {zb.ui.DataList.<string>}
*/
zb.ui.test.support.Helper.createOtherDataList = function() {
var array = zb.ui.test.support.Helper.createOtherArray();
return zb.ui.test.support.Helper.createDataList(array);
};


/**
* @return {IThenable.<zb.ui.BaseListBuffer>}
*/
zb.ui.test.support.Helper.createOtherBuffer = function() {
var dataList = zb.ui.test.support.Helper.createOtherDataList();
return zb.ui.test.support.Helper.createBuffer(dataList);
};

// Empty

/**
* @return {Array.<string>}
*/
zb.ui.test.support.Helper.createEmptyArray = function() {
return [];
};


/**
* @return {zb.ui.DataList.<string>}
*/
zb.ui.test.support.Helper.createEmptyDataList = function() {
var array = zb.ui.test.support.Helper.createEmptyArray();
return zb.ui.test.support.Helper.createDataList(array);
};


/**
* @return {IThenable.<zb.ui.BaseListBuffer>}
*/
zb.ui.test.support.Helper.createEmptyBuffer = function() {
var dataList = zb.ui.test.support.Helper.createEmptyDataList();
return zb.ui.test.support.Helper.createBuffer(dataList);
Expand Down
Loading

0 comments on commit 4c9d08b

Please sign in to comment.