Remove last jQuery refs and jQuery itself.
This commit is contained in:
parent
3761a40e50
commit
24945faded
6 changed files with 123 additions and 135 deletions
|
@ -93,13 +93,6 @@
|
||||||
"interval": 5000
|
"interval": 5000
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
|
||||||
Enable a context menu (right-click) on some elements.
|
|
||||||
*/
|
|
||||||
"contextmenu": {
|
|
||||||
"enabled": false
|
|
||||||
},
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Show a clickable breadcrumb.
|
Show a clickable breadcrumb.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#cm-overlay {
|
#cm-overlay {
|
||||||
display: none;
|
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|
|
@ -1,65 +1,71 @@
|
||||||
const {each} = require('../util');
|
const {each, dom} = require('../util');
|
||||||
const {win, jq} = require('../globals');
|
|
||||||
const resource = require('../core/resource');
|
const resource = require('../core/resource');
|
||||||
const allsettings = require('../core/settings');
|
const allsettings = require('../core/settings');
|
||||||
|
|
||||||
const doc = win.document;
|
|
||||||
const settings = Object.assign({
|
const settings = Object.assign({
|
||||||
enabled: false
|
enabled: false
|
||||||
}, allsettings.contextmenu);
|
}, allsettings.contextmenu);
|
||||||
const templateOverlay = '<div id="cm-overlay"/>';
|
const tplOverlay = '<div id="cm-overlay"></div>';
|
||||||
const templatePanel = '<div class="cm-panel"><ul/></div>';
|
const tplPanel = '<div class="cm-panel"><ul></ul></div>';
|
||||||
const templateSep = '<li class="cm-sep"/>';
|
const tplSep = '<li class="cm-sep"></li>';
|
||||||
const templateEntry = '<li class="cm-entry"><span class="cm-icon"><img/></span><span class="cm-text"/></li>';
|
const tplEntry = '<li class="cm-entry"><span class="cm-icon"><img/></span><span class="cm-text"></span></li>';
|
||||||
const templateLabel = '<li class="cm-label"><span class="cm-text"/></li>';
|
const tplLabel = '<li class="cm-label"><span class="cm-text"></span></li>';
|
||||||
|
|
||||||
|
|
||||||
function createOverlay(callback) {
|
const closestId = el => {
|
||||||
const $overlay = jq(templateOverlay);
|
while (!el._cmId && el.parentNode) {
|
||||||
|
el = el.parentNode;
|
||||||
|
}
|
||||||
|
return el._cmId;
|
||||||
|
};
|
||||||
|
|
||||||
$overlay
|
const createOverlay = callback => {
|
||||||
.on('click contextmenu', ev => {
|
const $overlay = dom(tplOverlay);
|
||||||
ev.stopPropagation();
|
|
||||||
ev.preventDefault();
|
|
||||||
|
|
||||||
const cmId = jq(ev.target).closest('.cm-entry').data('cm-id');
|
const handle = ev => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
ev.preventDefault();
|
||||||
|
|
||||||
if (ev.target === $overlay[0] || cmId !== undefined) {
|
const cmId = closestId(ev.target);
|
||||||
$overlay.remove();
|
|
||||||
callback(cmId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $overlay;
|
if (ev.target === $overlay[0] || cmId !== undefined) {
|
||||||
}
|
$overlay.rm();
|
||||||
|
callback(cmId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function createPanel(menu) {
|
return $overlay
|
||||||
const $panel = jq(templatePanel);
|
.on('contextmenu', handle)
|
||||||
|
.on('click', handle);
|
||||||
|
};
|
||||||
|
|
||||||
|
const createPanel = menu => {
|
||||||
|
const $panel = dom(tplPanel);
|
||||||
const $ul = $panel.find('ul');
|
const $ul = $panel.find('ul');
|
||||||
let $li;
|
let $li;
|
||||||
|
|
||||||
each(menu, entry => {
|
each(menu, entry => {
|
||||||
if (entry.type === '-') {
|
if (entry.type === '-') {
|
||||||
jq(templateSep).appendTo($ul);
|
dom(tplSep).appTo($ul);
|
||||||
} else if (entry.type === 'l') {
|
} else if (entry.type === 'l') {
|
||||||
jq(templateLabel).appendTo($ul)
|
dom(tplLabel).appTo($ul)
|
||||||
.find('.cm-text').text(entry.text);
|
.find('.cm-text').text(entry.text);
|
||||||
} else if (entry.type === 'e') {
|
} else if (entry.type === 'e') {
|
||||||
$li = jq(templateEntry).appendTo($ul);
|
$li = dom(tplEntry).appTo($ul);
|
||||||
$li.data('cm-id', entry.id);
|
$li[0]._cmId = entry.id;
|
||||||
$li.find('.cm-text').text(entry.text);
|
$li.find('.cm-text').text(entry.text);
|
||||||
if (entry.icon) {
|
if (entry.icon) {
|
||||||
$li.find('.cm-icon img').attr('src', resource.icon(entry.icon));
|
$li.find('.cm-icon img').attr('src', resource.icon(entry.icon));
|
||||||
} else {
|
} else {
|
||||||
$li.find('.cm-icon').addClass('no-icon');
|
$li.find('.cm-icon').addCls('no-icon');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $panel;
|
return $panel;
|
||||||
}
|
};
|
||||||
|
|
||||||
function positionPanel($overlay, $panel, x, y) {
|
const positionPanel = ($overlay, $panel, x, y) => {
|
||||||
const margin = 4;
|
const margin = 4;
|
||||||
|
|
||||||
$panel.css({
|
$panel.css({
|
||||||
|
@ -69,17 +75,16 @@ function positionPanel($overlay, $panel, x, y) {
|
||||||
});
|
});
|
||||||
$overlay.show();
|
$overlay.show();
|
||||||
|
|
||||||
const overlayOffset = $overlay.offset();
|
const or = $overlay[0].getBoundingClientRect();
|
||||||
const overlayLeft = overlayOffset.left;
|
const pr = $panel[0].getBoundingClientRect();
|
||||||
const overlayTop = overlayOffset.top;
|
|
||||||
const overlayWidth = $overlay.outerWidth(true);
|
|
||||||
const overlayHeight = $overlay.outerHeight(true);
|
|
||||||
|
|
||||||
// const panelOffset = $panel.offset();
|
const overlayLeft = or.left;
|
||||||
// const panelLeft = panelOffset.left;
|
const overlayTop = or.top;
|
||||||
// const panelTop = panelOffset.top;
|
const overlayWidth = or.width;
|
||||||
let panelWidth = $panel.outerWidth(true);
|
const overlayHeight = or.height;
|
||||||
let panelHeight = $panel.outerHeight(true);
|
|
||||||
|
let panelWidth = pr.width;
|
||||||
|
let panelHeight = pr.height;
|
||||||
|
|
||||||
let posLeft = x;
|
let posLeft = x;
|
||||||
let posTop = y;
|
let posTop = y;
|
||||||
|
@ -111,54 +116,42 @@ function positionPanel($overlay, $panel, x, y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$panel.css({
|
$panel.css({
|
||||||
left: posLeft,
|
left: posLeft + 'px',
|
||||||
top: posTop,
|
top: posTop + 'px',
|
||||||
width: panelWidth,
|
width: panelWidth + 'px',
|
||||||
height: panelHeight,
|
height: panelHeight + 'px',
|
||||||
opacity: 1
|
opacity: 1
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function showMenuAt(x, y, menu, callback) {
|
const showMenuAt = (x, y, menu, callback) => {
|
||||||
const $overlay = createOverlay(callback);
|
const $overlay = createOverlay(callback);
|
||||||
const $panel = createPanel(menu);
|
const $panel = createPanel(menu);
|
||||||
$overlay.append($panel).appendTo('body');
|
$overlay.hide().app($panel).appTo('body');
|
||||||
positionPanel($overlay, $panel, x, y);
|
positionPanel($overlay, $panel, x, y);
|
||||||
}
|
};
|
||||||
|
|
||||||
function init() {
|
const init = () => {
|
||||||
if (!settings.enabled) {
|
if (!settings.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
jq(doc).on('contextmenu', ev => {
|
const menu = [
|
||||||
ev.stopPropagation();
|
{type: 'e', id: 'e1', text: 'testing context menus'},
|
||||||
ev.preventDefault();
|
{type: 'e', id: 'e2', text: 'another entry'},
|
||||||
jq(ev.target).trigger(jq.Event('h5ai-contextmenu', {
|
{type: 'e', id: 'e3', text: 'one with icon', icon: 'folder'},
|
||||||
originalEvent: ev,
|
{type: '-'},
|
||||||
showMenu: (menu, callback) => {
|
{type: 'e', id: 'e4', text: 'one with icon', icon: 'x'},
|
||||||
showMenuAt(ev.pageX, ev.pageY, menu, callback);
|
{type: 'e', id: 'e5', text: 'one with icon', icon: 'img'}
|
||||||
}
|
];
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
// const menu = [
|
|
||||||
// {type: 'e', id: 'e1', text: 'testing context menus'},
|
dom('#view').on('contextmenu', ev => {
|
||||||
// {type: 'e', id: 'e2', text: 'another entry'},
|
ev.preventDefault();
|
||||||
// {type: 'e', id: 'e3', text: 'one with icon', icon: 'folder'},
|
// showMenuAt(ev.pageX, ev.pageY, menu, res => console.log('>> CB-RESULT >> ' + res));
|
||||||
// {type: '-'},
|
showMenuAt(ev.pageX, ev.pageY, menu);
|
||||||
// {type: 'e', id: 'e4', text: 'one with icon', icon: 'x'},
|
});
|
||||||
// {type: 'e', id: 'e5', text: 'one with icon', icon: 'img'}
|
};
|
||||||
// ];
|
|
||||||
// const callback = res => {
|
|
||||||
// console.log('>> CB-RESULT >> ' + res);
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// jq(doc).on('h5ai-contextmenu', '#items .item.folder', ev => {
|
|
||||||
// console.log('CM', ev);
|
|
||||||
// ev.showMenu(menu, callback);
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const {each, map, includes, compact} = require('../util');
|
const {each, includes, compact, dom} = require('../util');
|
||||||
const {win, jq} = require('../globals');
|
const {win} = require('../globals');
|
||||||
const event = require('../core/event');
|
const event = require('../core/event');
|
||||||
const allsettings = require('../core/settings');
|
const allsettings = require('../core/settings');
|
||||||
const preview = require('./preview');
|
const preview = require('./preview');
|
||||||
|
@ -9,84 +9,92 @@ const settings = Object.assign({
|
||||||
types: []
|
types: []
|
||||||
}, allsettings['preview-vid']);
|
}, allsettings['preview-vid']);
|
||||||
|
|
||||||
function preloadVideo(src, callback) {
|
const preloadVideo = (src, callback) => {
|
||||||
const $video = jq('<video/>')
|
const $video = dom('<video/>')
|
||||||
.one('loadedmetadata', () => {
|
.on('loadedmetadata', () => {
|
||||||
callback($video);
|
callback($video);
|
||||||
// win.setTimeout(function () { callback($video); }, 1000); // for testing
|
// win.setTimeout(() => {callback($video);}, 1000); // for testing
|
||||||
})
|
})
|
||||||
.attr('autoplay', 'autoplay')
|
.attr('autoplay', 'autoplay')
|
||||||
.attr('controls', 'controls')
|
.attr('controls', 'controls')
|
||||||
.attr('src', src);
|
.attr('src', src);
|
||||||
}
|
};
|
||||||
|
|
||||||
function onEnter(items, idx) {
|
const onEnter = (items, idx) => {
|
||||||
const currentItems = items;
|
const currentItems = items;
|
||||||
let currentIdx = idx;
|
let currentIdx = idx;
|
||||||
let currentItem = items[idx];
|
let currentItem = items[idx];
|
||||||
|
|
||||||
function onAdjustSize() {
|
const onAdjustSize = () => {
|
||||||
const $content = jq('#pv-content');
|
const $content = dom('#pv-content');
|
||||||
const $vid = jq('#pv-vid-video');
|
const $vid = dom('#pv-vid-video');
|
||||||
|
|
||||||
if ($vid.length) {
|
const contentW = $content[0].offsetWidth;
|
||||||
$vid.css({
|
const contentH = $content[0].offsetHeight;
|
||||||
left: String(($content.width() - $vid.width()) * 0.5) + 'px',
|
const vidW = ($vid[0] || {}).offsetWidth;
|
||||||
top: String(($content.height() - $vid.height()) * 0.5) + 'px'
|
const vidH = ($vid[0] || {}).offsetHeight;
|
||||||
});
|
|
||||||
|
|
||||||
preview.setLabels([
|
if ($vid.length === 0) {
|
||||||
currentItem.label,
|
return;
|
||||||
String($vid[0].videoWidth) + 'x' + String($vid[0].videoHeight),
|
|
||||||
String((100 * $vid.width() / $vid[0].videoWidth).toFixed(0)) + '%'
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function onIdxChange(rel) {
|
$vid.css({
|
||||||
|
left: (contentW - vidW) * 0.5 + 'px',
|
||||||
|
top: (contentH - vidH) * 0.5 + 'px'
|
||||||
|
});
|
||||||
|
|
||||||
|
const vidVW = $vid[0].videoWidth;
|
||||||
|
const vidVH = $vid[0].videoHeight;
|
||||||
|
|
||||||
|
preview.setLabels([
|
||||||
|
currentItem.label,
|
||||||
|
String(vidVW) + 'x' + String(vidVH),
|
||||||
|
String((100 * vidW / vidVW).toFixed(0)) + '%'
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onIdxChange = rel => {
|
||||||
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
|
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
|
||||||
currentItem = currentItems[currentIdx];
|
currentItem = currentItems[currentIdx];
|
||||||
|
|
||||||
const spinnerTimeout = win.setTimeout(() => preview.showSpinner(true), 200);
|
const spinnerTimeout = win.setTimeout(() => preview.showSpinner(true), 200);
|
||||||
|
|
||||||
if (jq('#pv-vid-video').length) {
|
if (dom('#pv-vid-video').length) {
|
||||||
jq('#pv-vid-video')[0].pause();
|
dom('#pv-vid-video')[0].pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMeta() {
|
const updateMeta = () => {
|
||||||
onAdjustSize();
|
onAdjustSize();
|
||||||
preview.setIndex(currentIdx + 1, currentItems.length);
|
preview.setIndex(currentIdx + 1, currentItems.length);
|
||||||
preview.setRawLink(currentItem.absHref);
|
preview.setRawLink(currentItem.absHref);
|
||||||
}
|
};
|
||||||
|
|
||||||
function swap(nuContent) {
|
const onReady = $preloadedContent => {
|
||||||
jq('#pv-content').empty().append(nuContent.attr('id', 'pv-vid-video')).fadeIn(200);
|
|
||||||
// small timeout, so nuContent is visible and therefore its width is available
|
|
||||||
win.setTimeout(updateMeta, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onReady($preloadedContent) {
|
|
||||||
win.clearTimeout(spinnerTimeout);
|
win.clearTimeout(spinnerTimeout);
|
||||||
preview.showSpinner(false);
|
preview.showSpinner(false);
|
||||||
|
|
||||||
jq('#pv-content').fadeOut(100, () => swap($preloadedContent));
|
dom('#pv-content')
|
||||||
}
|
.clr()
|
||||||
|
.app($preloadedContent.attr('id', 'pv-vid-video'))
|
||||||
|
.show();
|
||||||
|
updateMeta();
|
||||||
|
};
|
||||||
|
|
||||||
preloadVideo(currentItem.absHref, onReady);
|
preloadVideo(currentItem.absHref, onReady);
|
||||||
}
|
};
|
||||||
|
|
||||||
onIdxChange(0);
|
onIdxChange(0);
|
||||||
preview.setOnIndexChange(onIdxChange);
|
preview.setOnIndexChange(onIdxChange);
|
||||||
preview.setOnAdjustSize(onAdjustSize);
|
preview.setOnAdjustSize(onAdjustSize);
|
||||||
preview.enter();
|
preview.enter();
|
||||||
}
|
};
|
||||||
|
|
||||||
function initItem(item) {
|
const initItem = item => {
|
||||||
if (item.$view && includes(settings.types, item.type)) {
|
if (item.$view && includes(settings.types, item.type)) {
|
||||||
item.$view.find('a').on('click', ev => {
|
item.$view.find('a').on('click', ev => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
const matchedItems = compact(map(jq('#items .item'), el => {
|
const matchedItems = compact(dom('#items .item').map(el => {
|
||||||
const matchedItem = el._item;
|
const matchedItem = el._item;
|
||||||
return includes(settings.types, matchedItem.type) ? matchedItem : null;
|
return includes(settings.types, matchedItem.type) ? matchedItem : null;
|
||||||
}));
|
}));
|
||||||
|
@ -94,18 +102,18 @@ function initItem(item) {
|
||||||
onEnter(matchedItems, matchedItems.indexOf(item));
|
onEnter(matchedItems, matchedItems.indexOf(item));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function onViewChanged(added) {
|
const onViewChanged = added => {
|
||||||
each(added, initItem);
|
each(added, initItem);
|
||||||
}
|
};
|
||||||
|
|
||||||
function init() {
|
const init = () => {
|
||||||
if (!settings.enabled) {
|
if (!settings.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.sub('view.changed', onViewChanged);
|
event.sub('view.changed', onViewChanged);
|
||||||
}
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -8,7 +8,6 @@ const publish = (id, name) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
publish('window', 'win');
|
publish('window', 'win');
|
||||||
publish('jQuery', 'jq');
|
|
||||||
publish('kjua', 'kjua');
|
publish('kjua', 'kjua');
|
||||||
publish('marked', 'marked');
|
publish('marked', 'marked');
|
||||||
publish('Prism', 'prism');
|
publish('Prism', 'prism');
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue