- md5
- 9413d5678ff26994cd3059de17e4819f
- sha1
- d70d2dac3a9f30f22572c6aad04b34e49c6d8ac0
- sha256
- e411c07a6e5ca6cd38dcbec64dba7f25b6d17c022da8d385658bcddad1833277
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
import Directory from "./directory.vue";
import File from "./file.vue";
import Image from "./image.vue";
import Video from "./video.vue";
import Row from "./row.vue";
import * as types from "./../../../store/mutation-types";
export default {
props: ['item'],
data() {
return {
hoverActive: false,
}
},
methods: {
/**
* Return the correct item type component
*/
itemType() {
if (this.$store.state.listView === 'table') {
return Row;
}
let imageExtensions = ['jpg', 'jpeg', 'png', 'gif'];
let videoExtensions = ['mp4'];
// Render directory items
if (this.item.type === 'dir') return Directory;
// Render image items
if (this.item.extension && imageExtensions.indexOf(this.item.extension.toLowerCase()) !== -1) {
return Image;
}
// Render video items
if (this.item.extension && videoExtensions.indexOf(this.item.extension.toLowerCase()) !== -1) {
return Video;
}
// Default to file type
return File;
},
/**
* Get the styles for the media browser item
* @returns {{}}
*/
styles() {
if (this.$store.state.listView === 'table') {
return {};
}
return {
'width': 'calc(' + this.$store.state.gridSize + '% - 20px)',
};
},
/**
* Whether or not the item is currently selected
* @returns {boolean}
*/
isSelected() {
return this.$store.state.selectedItems.some(selected => selected.path === this.item.path);
},
/**
* Whether or not the item is currently active (on hover or via tab)
* @returns {boolean}
*/
isHoverActive() {
return this.hoverActive;
},
/**
* Turns on the hover class
*/
mouseover() {
this.hoverActive = true;
},
/**
* Turns off the hover class
*/
mouseleave() {
this.hoverActive = false;
},
/**
* Handle the click event
* @param event
*/
handleClick(event) {
let path = false;
const data = {
path: path,
thumb: false,
fileType: this.item.mime_type ? this.item.mime_type : false,
extension: this.item.extension ? this.item.extension : false,
};
if (this.item.type === 'file') {
data.path = this.item.path;
data.thumb = this.item.thumb ? this.item.thumb : false;
const ev = new CustomEvent('onMediaFileSelected', {
"bubbles": true,
"cancelable": false,
"detail": data
});
window.parent.document.dispatchEvent(ev);
}
// Handle clicks when the item was not selected
if (!this.isSelected()) {
// Unselect all other selected items, if the shift key was not pressed during the click event
if (!(event.shiftKey || event.keyCode === 13)) {
this.$store.commit(types.UNSELECT_ALL_BROWSER_ITEMS);
}
this.$store.commit(types.SELECT_BROWSER_ITEM, this.item);
return;
}
// If more than one item was selected and the user clicks again on the selected item,
// he most probably wants to unselect all other items.
if (this.$store.state.selectedItems.length > 1) {
this.$store.commit(types.UNSELECT_ALL_BROWSER_ITEMS);
this.$store.commit(types.SELECT_BROWSER_ITEM, this.item);
}
},
/**
* Handle the when an element is focused in the child to display the layover for a11y
* @param value
*/
focused(value) {
value ? this.mouseover() : this.mouseleave();
}
},
render: function (createElement) {
return createElement('div', {
'class': {
'media-browser-item': true,
selected: this.isSelected(),
active: this.isHoverActive(),
},
on: {
click: this.handleClick,
mouseover: this.mouseover,
mouseleave: this.mouseleave,
focused: this.focused,
},
},
[
createElement(this.itemType(), {
props: {
item: this.item,
focused: this.focused,
},
})
]
);
}
}
The same content is in 2 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha8. See them all, or every version of this file.