Fix a lot eslint errors.

This commit is contained in:
Lars Jung 2015-11-18 23:16:58 +01:00
parent 0c6143704a
commit 39ea94daa8
88 changed files with 3872 additions and 4930 deletions

View file

@ -1,37 +1,30 @@
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']);
enabled: false,
types: []
}, allsettings['preview-aud']);
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);
.one('loadedmetadata', function () {
callback($audio);
// setTimeout(function () { callback($img); }, 1000); // for testing
})
.attr('autoplay', 'autoplay')
.attr('controls', 'controls')
.attr('src', src);
}
function onEnter(items, idx) {
var currentItems = items;
var currentIdx = idx;
var currentItem = items[idx];
function onAdjustSize() {
var $content = $('#pv-content');
var $audio = $('#pv-aud-audio');
if ($audio.length) {
$audio.css({
left: String(($content.width() - $audio.width()) * 0.5) + 'px',
top: String(($content.height() - $audio.height()) * 0.5) + 'px'
@ -45,7 +38,6 @@ modulejs.define('ext/preview-audio', ['_', '$', 'core/event', 'core/format', 'co
}
function onIdxChange(rel) {
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
currentItem = currentItems[currentIdx];
@ -54,24 +46,29 @@ modulejs.define('ext/preview-audio', ['_', '$', 'core/event', 'core/format', 'co
if ($('#pv-aud-audio').length) {
$('#pv-aud-audio')[0].pause();
}
preloadAudio(currentItem.absHref, function ($preloadedAudio) {
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 () {
$('#pv-content').empty().append($preloadedAudio.attr('id', 'pv-aud-audio')).fadeIn(200);
// small timeout, so $preloadedAudio is visible and therefore $preloadedAudio.width is available
setTimeout(function () {
onAdjustSize();
preview.setIndex(currentIdx + 1, currentItems.length);
preview.setRawLink(currentItem.absHref);
}, 10);
swap($preloadedContent);
});
});
}
preloadAudio(currentItem.absHref, onReady);
}
onIdxChange(0);
@ -81,30 +78,25 @@ modulejs.define('ext/preview-audio', ['_', '$', 'core/event', 'core/format', 'co
}
function initItem(item) {
if (item.$view && _.indexOf(settings.types, item.type) >= 0) {
item.$view.find('a').on('click', function (event) {
item.$view.find('a').on('click', function (ev) {
ev.preventDefault();
event.preventDefault();
var matchedEntries = _.compact(_.map($('#items .item'), function (item) {
item = $(item).data('item');
return _.indexOf(settings.types, item.type) >= 0 ? item : null;
var matchedItems = _.compact(_.map($('#items .item'), function (matchedItem) {
matchedItem = $(matchedItem).data('item');
return _.indexOf(settings.types, matchedItem.type) >= 0 ? matchedItem : null;
}));
onEnter(matchedEntries, _.indexOf(matchedEntries, item));
onEnter(matchedItems, _.indexOf(matchedItems, item));
});
}
}
function onViewChanged(added) {
_.each(added, initItem);
}
function init() {
if (!settings.enabled) {
return;
}
@ -112,6 +104,5 @@ modulejs.define('ext/preview-audio', ['_', '$', 'core/event', 'core/format', 'co
event.sub('view.changed', onViewChanged);
}
init();
});