Begin to move all src javascript to es6. Add search/filter ignore case option.

This commit is contained in:
Lars Jung 2016-06-02 23:16:23 +02:00
parent f37e8e7b89
commit 7ec2bdf16a
58 changed files with 3546 additions and 3420 deletions

View file

@ -1,108 +1,110 @@
modulejs.define('ext/preview-audio', ['_', '$', 'core/event', 'core/format', 'core/settings', 'ext/preview'], function (_, $, event, format, allsettings, preview) {
var settings = _.extend({
enabled: false,
types: []
}, allsettings['preview-aud']);
const {setTimeout, jQuery: jq, _: lo} = require('../win');
const event = require('../core/event');
const format = require('../core/format');
const allsettings = require('../core/settings');
const preview = require('./preview');
function preloadAudio(src, callback) {
var $audio = $('<audio/>')
.one('loadedmetadata', function () {
callback($audio);
// setTimeout(function () { callback($img); }, 1000); // for testing
})
.attr('autoplay', 'autoplay')
.attr('controls', 'controls')
.attr('src', src);
}
const settings = lo.extend({
enabled: false,
types: []
}, allsettings['preview-aud']);
function onEnter(items, idx) {
var currentItems = items;
var currentIdx = idx;
var currentItem = items[idx];
function preloadAudio(src, callback) {
const $audio = jq('<audio/>')
.one('loadedmetadata', () => {
callback($audio);
// setTimeout(function () { callback($img); }, 1000); // for testing
})
.attr('autoplay', 'autoplay')
.attr('controls', 'controls')
.attr('src', src);
}
function onAdjustSize() {
var $content = $('#pv-content');
var $audio = $('#pv-aud-audio');
function onEnter(items, idx) {
const currentItems = items;
let currentIdx = idx;
let currentItem = items[idx];
if ($audio.length) {
$audio.css({
left: String(($content.width() - $audio.width()) * 0.5) + 'px',
top: String(($content.height() - $audio.height()) * 0.5) + 'px'
});
function onAdjustSize() {
const $content = jq('#pv-content');
const $audio = jq('#pv-aud-audio');
preview.setLabels([
currentItem.label,
format.formatDate($audio[0].duration * 1000, 'm:ss')
]);
}
}
function onIdxChange(rel) {
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
currentItem = currentItems[currentIdx];
var spinnerTimeout = setTimeout(function () { preview.showSpinner(true); }, 200);
if ($('#pv-aud-audio').length) {
$('#pv-aud-audio')[0].pause();
}
function updateMeta() {
onAdjustSize();
preview.setIndex(currentIdx + 1, currentItems.length);
preview.setRawLink(currentItem.absHref);
}
function swap(nuContent) {
$('#pv-content').empty().append(nuContent.attr('id', 'pv-vid-audio')).fadeIn(200);
// small timeout, so nuContent is visible and therefore its width is available
setTimeout(updateMeta, 10);
}
function onReady($preloadedContent) {
clearTimeout(spinnerTimeout);
preview.showSpinner(false);
$('#pv-content').fadeOut(100, function () {
swap($preloadedContent);
});
}
preloadAudio(currentItem.absHref, onReady);
}
onIdxChange(0);
preview.setOnIndexChange(onIdxChange);
preview.setOnAdjustSize(onAdjustSize);
preview.enter();
}
function initItem(item) {
if (item.$view && _.includes(settings.types, item.type)) {
item.$view.find('a').on('click', function (ev) {
ev.preventDefault();
var matchedItems = _.compact(_.map($('#items .item'), function (matchedItem) {
matchedItem = $(matchedItem).data('item');
return _.includes(settings.types, matchedItem.type) ? matchedItem : null;
}));
onEnter(matchedItems, _.indexOf(matchedItems, item));
if ($audio.length) {
$audio.css({
left: String(($content.width() - $audio.width()) * 0.5) + 'px',
top: String(($content.height() - $audio.height()) * 0.5) + 'px'
});
preview.setLabels([
currentItem.label,
format.formatDate($audio[0].duration * 1000, 'm:ss')
]);
}
}
function onViewChanged(added) {
_.each(added, initItem);
}
function onIdxChange(rel) {
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
currentItem = currentItems[currentIdx];
function init() {
if (!settings.enabled) {
return;
const spinnerTimeout = setTimeout(() => preview.showSpinner(true), 200);
if (jq('#pv-aud-audio').length) {
jq('#pv-aud-audio')[0].pause();
}
event.sub('view.changed', onViewChanged);
function updateMeta() {
onAdjustSize();
preview.setIndex(currentIdx + 1, currentItems.length);
preview.setRawLink(currentItem.absHref);
}
function swap(nuContent) {
jq('#pv-content').empty().append(nuContent.attr('id', 'pv-vid-audio')).fadeIn(200);
// small timeout, so nuContent is visible and therefore its width is available
setTimeout(updateMeta, 10);
}
function onReady($preloadedContent) {
clearTimeout(spinnerTimeout);
preview.showSpinner(false);
jq('#pv-content').fadeOut(100, () => swap($preloadedContent));
}
preloadAudio(currentItem.absHref, onReady);
}
init();
});
onIdxChange(0);
preview.setOnIndexChange(onIdxChange);
preview.setOnAdjustSize(onAdjustSize);
preview.enter();
}
function initItem(item) {
if (item.$view && lo.includes(settings.types, item.type)) {
item.$view.find('a').on('click', ev => {
ev.preventDefault();
const matchedItems = lo.compact(lo.map(jq('#items .item'), matchedItem => {
matchedItem = jq(matchedItem).data('item');
return lo.includes(settings.types, matchedItem.type) ? matchedItem : null;
}));
onEnter(matchedItems, lo.indexOf(matchedItems, item));
});
}
}
function onViewChanged(added) {
lo.each(added, initItem);
}
function init() {
if (!settings.enabled) {
return;
}
event.sub('view.changed', onViewChanged);
}
init();