mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update components
This commit is contained in:
parent
02e924e3c5
commit
05b25af69f
55 changed files with 1554 additions and 907 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iron-selector",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.4",
|
||||
"description": "Manages a set of elements that can be selected",
|
||||
"private": true,
|
||||
"license": "http://polymer.github.io/LICENSE.txt",
|
||||
|
@ -30,11 +30,11 @@
|
|||
"web-component-tester": "^4.0.0",
|
||||
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
|
||||
},
|
||||
"_release": "1.2.1",
|
||||
"_release": "1.2.4",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.2.1",
|
||||
"commit": "1e6a7ee05e5ff350472ffc1ee780f145a7606b7b"
|
||||
"tag": "v1.2.4",
|
||||
"commit": "1ee4e2e11a9e5118320987d93fc2c03ae9a489f4"
|
||||
},
|
||||
"_source": "git://github.com/PolymerElements/iron-selector.git",
|
||||
"_target": "^1.0.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iron-selector",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.4",
|
||||
"description": "Manages a set of elements that can be selected",
|
||||
"private": true,
|
||||
"license": "http://polymer.github.io/LICENSE.txt",
|
||||
|
|
|
@ -46,7 +46,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
},
|
||||
|
||||
observers: [
|
||||
'_updateSelected(attrForSelected, selectedValues)'
|
||||
'_updateSelected(selectedValues)'
|
||||
],
|
||||
|
||||
/**
|
||||
|
@ -77,6 +77,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
(this.selectedValues != null && this.selectedValues.length);
|
||||
},
|
||||
|
||||
_updateAttrForSelected: function() {
|
||||
if (!this.multi) {
|
||||
Polymer.IronSelectableBehavior._updateAttrForSelected.apply(this);
|
||||
} else if (this._shouldUpdateSelection) {
|
||||
this.selectedValues = this.selectedItems.map(function(selectedItem) {
|
||||
return this._indexToValue(this.indexOf(selectedItem));
|
||||
}, this).filter(function(unfilteredValue) {
|
||||
return unfilteredValue != null;
|
||||
}, this);
|
||||
}
|
||||
},
|
||||
|
||||
_updateSelected: function() {
|
||||
if (this.multi) {
|
||||
this._selectMulti(this.selectedValues);
|
||||
|
@ -86,11 +98,16 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
},
|
||||
|
||||
_selectMulti: function(values) {
|
||||
this._selection.clear();
|
||||
if (values) {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
this._selection.setItemSelected(this._valueToItem(values[i]), true);
|
||||
var selectedItems = this._valuesToItems(values);
|
||||
// clear all but the current selected items
|
||||
this._selection.clear(selectedItems);
|
||||
// select only those not selected yet
|
||||
for (var i = 0; i < selectedItems.length; i++) {
|
||||
this._selection.setItemSelected(selectedItems[i], true);
|
||||
}
|
||||
} else {
|
||||
this._selection.clear();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -113,6 +130,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
this.splice('selectedValues',i,1);
|
||||
}
|
||||
this._selection.setItemSelected(this._valueToItem(value), unselected);
|
||||
},
|
||||
|
||||
_valuesToItems: function(values) {
|
||||
return (values == null) ? null : values.map(function(value) {
|
||||
return this._valueToItem(value);
|
||||
}, this);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -136,7 +136,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
},
|
||||
|
||||
observers: [
|
||||
'_updateSelected(attrForSelected, selected)'
|
||||
'_updateAttrForSelected(attrForSelected)',
|
||||
'_updateSelected(selected)'
|
||||
],
|
||||
|
||||
created: function() {
|
||||
|
@ -148,7 +149,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
this._observer = this._observeItems(this);
|
||||
this._updateItems();
|
||||
if (!this._shouldUpdateSelection) {
|
||||
this._updateSelected(this.attrForSelected,this.selected)
|
||||
this._updateSelected();
|
||||
}
|
||||
this._addListener(this.activateEvent);
|
||||
},
|
||||
|
@ -241,6 +242,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
this._setItems(nodes);
|
||||
},
|
||||
|
||||
_updateAttrForSelected: function() {
|
||||
if (this._shouldUpdateSelection) {
|
||||
this.selected = this._indexToValue(this.indexOf(this.selectedItem));
|
||||
}
|
||||
},
|
||||
|
||||
_updateSelected: function() {
|
||||
this._selectSelected(this.selected);
|
||||
},
|
||||
|
@ -310,7 +317,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
}
|
||||
|
||||
// Let other interested parties know about the change so that
|
||||
// we don't have to recreate mutation observers everywher.
|
||||
// we don't have to recreate mutation observers everywhere.
|
||||
this.fire('iron-items-changed', mutations, {
|
||||
bubbles: false,
|
||||
cancelable: false
|
||||
|
|
|
@ -69,16 +69,19 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
*/
|
||||
setItemSelected: function(item, isSelected) {
|
||||
if (item != null) {
|
||||
if (isSelected) {
|
||||
this.selection.push(item);
|
||||
} else {
|
||||
var i = this.selection.indexOf(item);
|
||||
if (i >= 0) {
|
||||
this.selection.splice(i, 1);
|
||||
if (isSelected !== this.isSelected(item)) {
|
||||
// proceed to update selection only if requested state differs from current
|
||||
if (isSelected) {
|
||||
this.selection.push(item);
|
||||
} else {
|
||||
var i = this.selection.indexOf(item);
|
||||
if (i >= 0) {
|
||||
this.selection.splice(i, 1);
|
||||
}
|
||||
}
|
||||
if (this.selectCallback) {
|
||||
this.selectCallback(item, isSelected);
|
||||
}
|
||||
}
|
||||
if (this.selectCallback) {
|
||||
this.selectCallback(item, isSelected);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
<!DOCTYPE html><!--
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
--><html><head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<title>Tests</title>
|
||||
|
@ -19,7 +15,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
<body>
|
||||
|
||||
<script>
|
||||
|
||||
WCT.loadSuites([
|
||||
'activate-event.html',
|
||||
'basic.html',
|
||||
|
@ -29,10 +24,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
'selected-attribute.html',
|
||||
'template-repeat.html',
|
||||
'content.html',
|
||||
'excluded-local-names.html'
|
||||
'excluded-local-names.html',
|
||||
'activate-event.html?dom=shadow',
|
||||
'basic.html?dom=shadow',
|
||||
'multi.html?dom=shadow',
|
||||
'next-previous.html?dom=shadow',
|
||||
'selected-attribute.html?dom=shadow',
|
||||
'template-repeat.html?dom=shadow',
|
||||
'content.html?dom=shadow',
|
||||
'excluded-local-names.html?dom=shadow'
|
||||
]);
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
</body></html>
|
||||
|
|
|
@ -93,8 +93,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
|
||||
test('set multi-selection via tap', function() {
|
||||
// set selectedValues
|
||||
s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
|
||||
s.children[2].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
|
||||
MockInteractions.tap(s.children[0]);
|
||||
MockInteractions.tap(s.children[2]);
|
||||
// check selected class
|
||||
assert.isTrue(s.children[0].classList.contains('iron-selected'));
|
||||
assert.isTrue(s.children[2].classList.contains('iron-selected'));
|
||||
|
@ -104,31 +104,106 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
assert.equal(s.selectedItems[1], s.children[2]);
|
||||
});
|
||||
|
||||
test('fire iron-select/deselect events', function() {
|
||||
// setup listener for iron-select event
|
||||
var selectEventCounter = 0;
|
||||
test('fire iron-select/deselect events when selectedValues changes', function() {
|
||||
// setup listener for iron-select/deselect events
|
||||
var items = [s.children[0], s.children[1], s.children[2]],
|
||||
selectEventCounters = [0, 0, 0],
|
||||
deselectEventCounters = [0, 0, 0];
|
||||
|
||||
s.addEventListener('iron-select', function(e) {
|
||||
selectEventCounter++;
|
||||
selectEventCounters[items.indexOf(e.detail.item)]++;
|
||||
});
|
||||
// setup listener for core-deselect event
|
||||
var deselectEventCounter = 0;
|
||||
s.addEventListener('iron-deselect', function(e) {
|
||||
deselectEventCounter++;
|
||||
deselectEventCounters[items.indexOf(e.detail.item)]++;
|
||||
});
|
||||
// tap to select an item
|
||||
s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
|
||||
|
||||
// programatically select values 0 and 1 (both fire select)
|
||||
s.selectedValues = [0, 1];
|
||||
|
||||
// programatically select values 1 and 2 (2 fires select, 0 fires deselect)
|
||||
s.selectedValues = [1, 2];
|
||||
|
||||
// programatically deselect all values (1 and 2 fire deselect)
|
||||
s.selectedValues = [];
|
||||
|
||||
// check events
|
||||
assert.equal(selectEventCounter, 1);
|
||||
assert.equal(deselectEventCounter, 0);
|
||||
// tap on already selected item should deselect it
|
||||
s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
|
||||
// check selectedValues
|
||||
assert.equal(s.selectedValues.length, 0);
|
||||
// check class
|
||||
assert.isFalse(s.children[0].classList.contains('iron-selected'));
|
||||
assert.equal(selectEventCounters[0], 1);
|
||||
assert.equal(deselectEventCounters[0], 1);
|
||||
assert.equal(selectEventCounters[1], 1);
|
||||
assert.equal(deselectEventCounters[1], 1);
|
||||
assert.equal(selectEventCounters[2], 1);
|
||||
assert.equal(deselectEventCounters[2], 1);
|
||||
});
|
||||
|
||||
test('fire iron-select/deselect events when toggling items', function() {
|
||||
// setup listener for iron-select/deselect events
|
||||
var items = [s.children[0], s.children[1], s.children[2]],
|
||||
selectEventCounters = [0, 0, 0],
|
||||
deselectEventCounters = [0, 0, 0];
|
||||
|
||||
s.addEventListener('iron-select', function(e) {
|
||||
selectEventCounters[items.indexOf(e.detail.item)]++;
|
||||
});
|
||||
s.addEventListener('iron-deselect', function(e) {
|
||||
deselectEventCounters[items.indexOf(e.detail.item)]++;
|
||||
});
|
||||
|
||||
// tap to select items 0 and 1 (both fire select)
|
||||
MockInteractions.tap(items[0]);
|
||||
MockInteractions.tap(items[1]);
|
||||
|
||||
// programatically select values 1 and 2 (2 fires select, 0 fires deselect)
|
||||
s.selectedValues = [1, 2];
|
||||
|
||||
// tap to deselect items 1 and 2 (both fire deselect)
|
||||
MockInteractions.tap(items[1]);
|
||||
MockInteractions.tap(items[2]);
|
||||
|
||||
// check events
|
||||
assert.equal(selectEventCounter, 1);
|
||||
assert.equal(deselectEventCounter, 1);
|
||||
assert.equal(selectEventCounters[0], 1);
|
||||
assert.equal(deselectEventCounters[0], 1);
|
||||
assert.equal(selectEventCounters[1], 1);
|
||||
assert.equal(deselectEventCounters[1], 1);
|
||||
assert.equal(selectEventCounters[2], 1);
|
||||
assert.equal(deselectEventCounters[2], 1);
|
||||
});
|
||||
|
||||
test('toggle iron-selected class when toggling items selection', function() {
|
||||
// setup listener for iron-item-select/deselect events
|
||||
var item0 = s.children[0], item1 = s.children[1];
|
||||
|
||||
assert.isFalse(item0.classList.contains('iron-selected'));
|
||||
assert.isFalse(item1.classList.contains('iron-selected'));
|
||||
|
||||
// tap to select item 0 (add iron-selected class)
|
||||
MockInteractions.tap(item0);
|
||||
|
||||
assert.isTrue(item0.classList.contains('iron-selected'));
|
||||
assert.isFalse(item1.classList.contains('iron-selected'));
|
||||
|
||||
// tap to select item 1 (add iron-selected class)
|
||||
MockInteractions.tap(item1);
|
||||
|
||||
assert.isTrue(item0.classList.contains('iron-selected'));
|
||||
assert.isTrue(item1.classList.contains('iron-selected'));
|
||||
|
||||
// tap to deselect item 1 (remove iron-selected class)
|
||||
MockInteractions.tap(item1);
|
||||
|
||||
assert.isTrue(item0.classList.contains('iron-selected'));
|
||||
assert.isFalse(item1.classList.contains('iron-selected'));
|
||||
|
||||
// programatically select both values (1 add iron-selected class)
|
||||
s.selectedValues = [0, 1];
|
||||
|
||||
assert.isTrue(item0.classList.contains('iron-selected'));
|
||||
assert.isTrue(item1.classList.contains('iron-selected'));
|
||||
|
||||
// programatically deselect all values (both removes iron-selected class)
|
||||
s.selectedValues = [];
|
||||
|
||||
assert.isFalse(item0.classList.contains('iron-selected'));
|
||||
assert.isFalse(item1.classList.contains('iron-selected'));
|
||||
});
|
||||
|
||||
test('fires selected-values-changed when selection changes', function() {
|
||||
|
@ -180,10 +255,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
|
||||
Polymer.dom(s).removeChild(lastChild);
|
||||
|
||||
Polymer.Base.async(function() {
|
||||
expect(s.selectedItems.length).to.be.equal(1);
|
||||
done();
|
||||
});
|
||||
Polymer.dom.flush();
|
||||
|
||||
expect(s.selectedItems.length).to.be.equal(1);
|
||||
expect(s.selectedItems[0]).to.be.equal(firstChild);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -43,6 +43,28 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<test-fixture id="test-attr-change">
|
||||
<template>
|
||||
<iron-selector id="selector" attr-for-selected="data-x" selected="x-1">
|
||||
<div data-x="x-1" data-y="y-1">1</div>
|
||||
<div data-x="x-2" data-y="y-2">2</div>
|
||||
<div data-x="x-3" data-y="y-3">3</div>
|
||||
</iron-selector>
|
||||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<test-fixture id="test-attr-change-multi">
|
||||
<template>
|
||||
<iron-selector multi id="selector"
|
||||
attr-for-selected="data-x"
|
||||
selected-values='["x-1","x-2"]'>
|
||||
<div data-x="x-1" data-y="y-1">1</div>
|
||||
<div data-x="x-2" data-y="y-2">2</div>
|
||||
<div data-x="x-3" data-y="y-3">3</div>
|
||||
</iron-selector>
|
||||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
|
||||
suite('selected attributes', function() {
|
||||
|
@ -66,6 +88,40 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
|
||||
});
|
||||
|
||||
suite('changing attrForSelected', function() {
|
||||
|
||||
var s;
|
||||
|
||||
setup(function () {
|
||||
s = fixture('test-attr-change');
|
||||
});
|
||||
|
||||
test('changing selectedAttribute', function() {
|
||||
Polymer.dom.flush();
|
||||
s.attrForSelected = 'data-y';
|
||||
assert.equal(s.selected, 'y-1');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('changing attrForSelected in multi', function() {
|
||||
|
||||
var s;
|
||||
|
||||
setup(function () {
|
||||
s = fixture('test-attr-change-multi');
|
||||
});
|
||||
|
||||
test('changing selectedAttribute', function() {
|
||||
Polymer.dom.flush();
|
||||
s.attrForSelected = 'data-y';
|
||||
assert.equal(s.selectedValues.length, 2);
|
||||
assert.equal(s.selectedValues[0],'y-1');
|
||||
assert.equal(s.selectedValues[1],'y-2');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue