Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7101dae
commit 0d8f1f8
Showing
7 changed files
with
258 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script> | ||
window.vaadin = window.vaadin || {}; | ||
vaadin.elements = vaadin.elements || {}; | ||
vaadin.elements.grid = vaadin.elements.grid || {}; | ||
|
||
vaadin.elements.grid.CellClickBehavior = { | ||
|
||
listeners: { | ||
'click': '_onClick' | ||
}, | ||
|
||
// we need to listen to click instead of tap because on mobile safari, the | ||
// document.activeElement has not been updated (focus has not been shifted) | ||
// yet at the point when tap event is being executed. | ||
_onClick: function(e) { | ||
// Prevent item action if cell itself is not focused. | ||
if (!this._isFocusable(Polymer.dom(e).localTarget)) { | ||
if (this._cellClick) { | ||
this._cellClick(e); | ||
} | ||
} | ||
}, | ||
|
||
_isFocusable: function(target) { | ||
if (Polymer.Settings.useNativeShadow) { | ||
// https://nemisj.com/focusable/ | ||
// tabIndex is not reliable in IE. | ||
return target.tabIndex >= 0; | ||
} else { | ||
// unreliable with Shadow, document.activeElement doesn't go inside | ||
// the shadow root. | ||
// Also, atleast iOS doesn't seem to focus links or buttons. | ||
var focusableElements = ['A', 'BUTTON']; | ||
return target.contains(Polymer.dom(document.activeElement).node) || focusableElements.indexOf(target.tagName) > -1; | ||
} | ||
} | ||
}; | ||
</script> |
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,161 @@ | ||
<link rel="import" href="vaadin-grid-cell-click-behavior.html"> | ||
|
||
<dom-module id="vaadin-grid-sorter"> | ||
<template> | ||
<style> | ||
:host { | ||
display: inline-flex; | ||
justify-content: space-between; | ||
cursor: pointer; | ||
} | ||
|
||
#indicators { | ||
position: relative; | ||
padding-right: 8px; | ||
} | ||
|
||
#indicators[direction=desc] #direction { | ||
transform: rotateZ(180deg); | ||
} | ||
|
||
#indicators:not([direction]) { | ||
opacity: 0.2; | ||
} | ||
|
||
#order { | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
transform: translateY(-4px) scale(0.7); | ||
} | ||
|
||
</style> | ||
|
||
<content></content> | ||
<div id="indicators" direction$="[[direction]]"> | ||
<div id="direction">▼</div> | ||
<div id="order">[[_getDisplayOrder(_order)]]</div> | ||
</div> | ||
|
||
</template> | ||
<script> | ||
Polymer({ | ||
is: 'vaadin-grid-sorter', | ||
|
||
properties: { | ||
|
||
path: String, | ||
|
||
direction: { | ||
type: String, | ||
reflectToAttribute: true, | ||
notify: true, | ||
value: null | ||
}, | ||
|
||
_order: Number | ||
|
||
}, | ||
|
||
observers: [ | ||
'_parametersChanged(path, direction)' | ||
], | ||
|
||
behaviors: [ | ||
vaadin.elements.grid.CellClickBehavior | ||
], | ||
|
||
attached: function() { | ||
this._fireChange(); | ||
}, | ||
|
||
_parametersChanged: function(grid, path, direction) { | ||
this._fireChange(); | ||
}, | ||
|
||
_fireChange: function() { | ||
this.fire('sorter-changed'); | ||
}, | ||
|
||
_getDisplayOrder: function(order) { | ||
return order === null ? '' : order + 1; | ||
}, | ||
|
||
_cellClick: function(e) { | ||
if (this.direction === 'asc') { | ||
this.direction = 'desc'; | ||
} else if (this.direction === 'desc') { | ||
this.direction = null; | ||
} else { | ||
this.direction = 'asc'; | ||
} | ||
} | ||
|
||
}); | ||
</script> | ||
</dom-module> | ||
|
||
<script> | ||
window.vaadin = window.vaadin || {}; | ||
vaadin.elements = vaadin.elements || {}; | ||
vaadin.elements.grid = vaadin.elements.grid || {}; | ||
|
||
vaadin.elements.grid.SortBehavior = { | ||
|
||
properties: { | ||
|
||
_sorters: { | ||
type: Array, | ||
value: function() { | ||
return []; | ||
} | ||
} | ||
|
||
}, | ||
|
||
listeners: { | ||
'sorter-changed': '_onSorterChanged' | ||
}, | ||
|
||
_onSorterChanged: function(e) { | ||
var sorter = e.target; | ||
|
||
this._removeArrayItem(this._sorters, sorter); | ||
if (sorter.direction) { | ||
this._sorters.unshift(sorter); | ||
} | ||
|
||
sorter._order = null; | ||
this._sorters.forEach(function(sorter, index) { | ||
sorter._order = this._sorters.length > 1 ? index : null; | ||
}, this); | ||
|
||
e.stopPropagation(); | ||
|
||
this.fire('sort-order-changed', { | ||
sortOrder: this._mapSorters() | ||
}); | ||
|
||
if (this.dataSource) { | ||
this.clearCache(); | ||
} | ||
}, | ||
|
||
_mapSorters: function() { | ||
return this._sorters.map(function(sorter) { | ||
return { | ||
path: sorter.path, | ||
direction: sorter.direction | ||
}; | ||
}); | ||
}, | ||
|
||
_removeArrayItem: function(array, item) { | ||
var index = array.indexOf(item); | ||
if (index > -1) { | ||
array.splice(index, 1); | ||
} | ||
}, | ||
|
||
}; | ||
</script> |
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