Former-commit-id: 18a1b6540895d83370677bea474ac7dd8cfa1bd2
This commit is contained in:
Henrique Dias
2017-01-02 12:20:20 +00:00
parent df4a030843
commit abcaf3aba7
8 changed files with 129 additions and 84 deletions

View File

@@ -72,21 +72,6 @@ Element.prototype.changeToDone = function(error, html) {
return false;
}
function getCSSRule(ruleName) {
ruleName = ruleName.toLowerCase();
var result = null,
find = Array.prototype.find;
find.call(document.styleSheets, styleSheet => {
result = find.call(styleSheet.cssRules, cssRule => {
return cssRule instanceof CSSStyleRule &&
cssRule.selectorText.toLowerCase() == ruleName;
});
return result != null;
});
return result;
}
function toWebDavURL(url) {
return window.location.origin + url.replace(baseURL + "/", webdavURL + "/");
}
@@ -100,6 +85,33 @@ var removeLastDirectoryPartOf = function(url) {
return (arr.join('/'));
}
function getCSSRule(rules) {
for (let i = 0; i < rules.length; i++) {
rules[i] = rules[i].toLowerCase();
}
var result = null,
find = Array.prototype.find;
find.call(document.styleSheets, styleSheet => {
result = find.call(styleSheet.cssRules, cssRule => {
let found = false;
if (cssRule instanceof CSSStyleRule) {
for (let i = 0; i < rules.length; i++) {
if (cssRule.selectorText.toLowerCase() == rules[i]) found = true;
}
}
return found;
});
return result != null;
});
return result;
}
/* * * * * * * * * * * * * * * *
* *
* EVENTS *

View File

@@ -14,7 +14,8 @@ listing.reload = function(callback) {
if (request.readyState == 4) {
if (request.status == 200) {
document.querySelector('body main').innerHTML = request.responseText;
listing.addDoubleTapEvent();
if (typeof callback == 'function') {
callback();
}
@@ -311,11 +312,42 @@ listing.newFilePrompt = function(event) {
listing.updateColumns = function(event) {
let columns = Math.floor(document.getElementById('listing').offsetWidth / 300),
items = getCSSRule('#listing.mosaic .item');
items = getCSSRule(['#listing.mosaic .item', '.mosaic#listing .item']);
items.style.width = `calc(${100/columns}% - 1em)`;
}
listing.addDoubleTapEvent = function() {
let items = document.getElementsByClassName('item'),
touches = {
id: '',
count: 0
};
Array.from(items).forEach(file => {
file.addEventListener('touchstart', event => {
console.log("hey")
if (touches.id != file.id) {
touches.id = file.id;
touches.count = 1;
setTimeout(() => {
touches.count = 0;
}, 500)
return;
}
touches.count++;
if (touches.count > 1) {
window.location = file.dataset.url;
}
});
});
}
// Keydown events
window.addEventListener('keydown', (event) => {
if (event.keyCode == 27) {
@@ -346,6 +378,7 @@ window.addEventListener("resize", () => {
document.addEventListener('DOMContentLoaded', event => {
listing.updateColumns();
listing.addDoubleTapEvent();
buttons.rename = document.getElementById("rename");
buttons.upload = document.getElementById("upload");
@@ -400,29 +433,5 @@ document.addEventListener('DOMContentLoaded', event => {
document.addEventListener("drop", listing.documentDrop, false);
}
let touches = {
id: '',
count: 0
};
Array.from(items).forEach(file => {
file.addEventListener('touchstart', event => {
if (touches.id != file.id) {
touches.id = file.id;
touches.count = 1;
setTimeout(() => {
touches.count = 0;
}, 500)
return;
}
touches.count++;
if (touches.count > 1) {
window.location = file.dataset.url;
}
});
});
});