var imagekey = ''; var imgobj = null; var nosource = false; var running = false; var clickindex = null; var wobblebottom; var searchcontent; var localimages; var allshown = true; var stream = ""; var progress; function getNewAlbumArt(div) { debug.log("ALBUMART","Getting art in",div); $.each($(div).find("img").filter(filterImages), function () { coverscraper.GetNewAlbumArt($(this)); } ); if (running == false) { running = true; progress.fadeIn('slow'); $("#harold").off("click"); $("#harold").on("click", reset ); $("#harold").html("Stop Download"); $('#doobag').off('click'); } } // Does anybody ever read the comments in code? // I hope they do, because most of the comments in my code are entirely useless. function reset() { coverscraper.reset(-1); } // I like badgers function start() { getNewAlbumArt('#wobblebottom'); } function getsmall() { $('#doobag').html(language.gettext('label_searching')).makeFlasher(); $("#doobag").off("click"); $.ajax({ type: 'GET', url: 'utils/findsmallimages.php', dataType: 'json', timeout: 300000 }) .done(function(data) { $('#doobag').stopFlasher().css('opacity', '0'); debug.log("SMALL IMAGES","Got List!",data); for (var i in data) { $('img[name="'+data[i]+'"]').removeAttr('src').addClass('notexist'); } coverscraper.reset($('.notexist:not(.notfound)').length + $('.notfound:not(.notexist)').length); }) .fail(function() { $('#doobag').html("FAILED!").stopFlasher(); debug.error("SMALL IMAGES","Big Wet Balls"); }); } function aADownloadFinished() { if (running == true) { running = false; $("#harold").off("click"); $("#harold").on("click", start ); $("#doobag").off("click"); $("#doobag").on("click", getsmall ); $("#harold").html("Get Missing Covers"); } $("#status").html(""); if (progress) { progress.fadeOut('slow'); progress.rangechooser('setProgress', 0); } } function onWobblebottomClicked(event) { var clickedElement = findClickableElement(event); if (clickedElement.hasClass("clickalbumcover")) { event.stopImmediatePropagation(); imageEditor.show(clickedElement); } if (clickedElement.hasClass('clickselectartist')) { event.stopImmediatePropagation(); var a = clickedElement.attr("id"); $(".clickselectartist").filter('.selected').removeClass('selected'); clickedElement.addClass('selected'); if (a == "allartists") { $(".cheesegrater").show(); if (!allshown) { boogerbenson(); boogerbenson(); } } else { $(".cheesegrater").filter('[name!="'+a+'"]').hide(); $('[name="'+a+'"]').show(); } } } function findClickableElement(event) { var clickedElement = $(event.target); // Search upwards through the parent elements to find the clickable object while (!clickedElement.hasClass("clickable") && clickedElement.prop("id") != "wobblebottom" && clickedElement.prop("id") != "searchcontent") { clickedElement = clickedElement.parent(); } return clickedElement; } // It's not raining function boogerbenson() { if (allshown) { $("img", "#wobblebottom").filter( onlywithcovers ).parent().parent().hide(); $("#finklestein").html(language.gettext("albumart_showall")); $(".albumsection").filter( emptysections ).hide(); $(".bigholder").filter( emptysections2 ).hide(); } else { $(".bigholder").show(); $(".albumsection").show(); $("img", "#wobblebottom").parent().parent().show(); $("#finklestein").html(language.gettext("albumart_onlyempty")); } allshown = !allshown; } function onlywithcovers() { if ($(this).hasAttr('src')) { return true; } else { return false; } } function filterImages() { if ($(this).hasClass('playlistimage')){ return false; } if ($(this).hasAttr('src')) { return false; } else { return true; } } // This comment is useless function emptysections() { var empty = true; $.each($(this).next().find('.albumimg'), function() { if (!$(this).is(':hidden')) { empty = false } }); return empty; } function emptysections2() { var empty = true; $.each($(this).find('.albumimg'), function() { if (!$(this).is(':hidden')) { empty = false } }); return empty; } function sections_without_missing_images() { var ne = $(this).find('img.notexist'); var nf = $(this).find('img.notfound'); if (ne.length + nf.length > 0) { return false; } return true; } function sections_with_missing_images() { var ne = $(this).find('img.notexist'); var nf = $(this).find('img.notfound'); if (ne.length + nf.length > 0) { return true; } return false; } $(document).ready(function () { debug.log("ALBUMART","Document is ready"); prefs.rgbs = null; prefs.maxrgbs = null; prefs.setTheme(prefs.theme); progress = $('#progress'); progress.rangechooser({range: 100, startmax: 0, interactive: false}); $(window).on('resize', wobbleMyBottom ); $("#harold").on('click', start ); $("#doobag").on('click', getsmall ); $("#finklestein").on('click', boogerbenson ); wobblebottom = $('#wobblebottom'); wobbleMyBottom(); $('#artistcoverslist').mCustomScrollbar({ theme: "light", scrollInertia: 300, contentTouchScroll: 25, mouseWheel: { scrollAmount: 40, }, advanced: { updateOnContentResize: true, updateOnImageLoad: false, autoScrollOnFocus: false, autoUpdateTimeout: 500, } }); $('#coverslist').mCustomScrollbar({ theme: "light", scrollInertia: 200, contentTouchScroll: 25, mouseWheel: { scrollAmount: 20, }, advanced: { updateOnContentResize: true, updateOnImageLoad: false, autoScrollOnFocus: false, autoUpdateTimeout: 500, } }); document.body.addEventListener('drop', function(e) { e.preventDefault(); }, false); wobblebottom.on('click', onWobblebottomClicked); $('.droppable').on('dragenter', dragEnter); $('.droppable').on('dragover', dragOver); $('.droppable').on('dragleave', dragLeave); $('.droppable').on('drop', handleDrop); $(document).on('mouseenter', '.clearbox', makeHoverWork); $(document).on('mouseleave', '.clearbox', makeHoverWork); $(document).on('mousemove', '.clearbox', makeHoverWork); $(document).on('click', '.clearbox.enter', makeClearWork); }); $(window).on('load', function () { debug.log("ALBUMART","Document has loaded"); coverscraper = new coverScraper(1, true, true, true); var count = 0; $.each($(document).find("img").filter(filterImages), function() { count++; $(this).addClass("notexist"); }); $('.cheesegrater').filter(sections_with_missing_images).each(function() { $(this).children('.albumsection').find('button').show(); }); $('#poobag').prop('checked', false); $('#dinkytoy').prop('checked', false); coverscraper.toggleScrolling(false); coverscraper.toggleLocal(false); $("#totaltext").html(numcovers+" "+language.gettext("label_albums")); coverscraper.reset(albums_without_cover); coverscraper.updateInfo(albums_without_cover - count); $("#status").html(language.gettext("albumart_instructions")); }); function dragEnter(ev) { evt = ev.originalEvent; evt.stopPropagation(); evt.preventDefault(); $(ev.target).addClass("highlighted"); return false; } function dragOver(ev) { evt = ev.originalEvent; evt.stopPropagation(); evt.preventDefault(); return false; } function dragLeave(ev) { evt = ev.originalEvent; evt.stopPropagation(); evt.preventDefault(); $(ev.target).removeClass("highlighted"); return false; } function handleDrop(ev) { debug.log("ALBUMART","Dropped",ev); evt = ev.originalEvent; $(ev.target).removeClass("highlighted"); imgobj = $(ev.target); imagekey = imgobj.attr("name"); nosource = (imgobj.hasClass('notfound') || imgobj.hasClass('notexist')); clickindex = null; dropProcessor(ev.originalEvent, imgobj, coverscraper, uploadComplete, searchFail); } var imageEditor = function() { var start = 1; var position = null; var bigdiv = null; var bigimg = new Image(); var currparent = null; var currhighlight = null; var currname = null; var current = "g"; var nureek = "https://www.googleapis.com/customsearch/v1?key="+prefs.google_api_key+"&cx="+prefs.google_search_engine_id+"&searchType=image&alt=json"; bigimg.onload = function() { imageEditor.displayBigImage(); } return { show: function(where) { var newpos = where.parent().parent(); if (where.attr('name') == currname) { imageEditor.close(); return true; } if (currparent !== null) { imageEditor.close(); } currname = where.attr('name'); bigdiv = $('
', {id: "imageeditor", class: "containerbox highlighted dropshadow"}).appendTo(newpos); bigdiv.on('click', imageEditor.onGoogleSearchClicked); start = 1; currhighlight = where.parent(); currhighlight.addClass('highlighted'); currparent = newpos; bigimg.src = ""; bigdiv.empty(); imgobj = where; imagekey = imgobj.attr('name'); nosource = (imgobj.hasClass('notfound') || imgobj.hasClass('notexist')); var phrase = decodeURIComponent(imgobj.parent().find('input[name="searchterm"]').val()); var path = imgobj.parent().find('input[name="albumpath"]').val(); debug.log('ALBUMART','Local Path Is',path); bigdiv.append($('
', { id: "searchcontent" })); bigdiv.append($('
', { id: "origimage"}).append($("", { id: 'browns' }))); $("#searchcontent").append( $('
', {id: "editcontrols", class: "clearfix fullwidth"}), $('
', {id: "gsearch", class: "noddy fullwidth invisible"}), $('
', {id: "fsearch", class: "noddy fullwidth invisible"}), $('
', {id: "usearch", class: "noddy fullwidth invisible"})); $("#"+current+"search").removeClass("invisible"); $("#gsearch").append( $('
', {id: "brian", class: "fullwidth"}), $('
', {id: "searchresultsholder", class: "fullwidth"})); $("#searchresultsholder").append($('
', {id: "searchresults", class: "clearfix fullwidth"})); var fdiv = $('
', {class: "fullwidth"}).appendTo('#usearch'); var uform = $('
', { id: 'uform', action: 'getalbumcover.php', method: 'post', enctype: 'multipart/form-data' }).appendTo(fdiv); uform.append( $('', { id: 'uploadkey', type: 'hidden', name: 'key', value: '' }), $('', { id: 'uploadartist', type: 'hidden', name: 'artist', value: '' }), $('', { id: 'uploadalbum', type: 'hidden', name: 'album', value: '' }), ); var fb = $('
', {class: 'filebutton textcentre'}).appendTo(uform); var inp = $('', { name: 'ufile', type: 'file', id: 'ufile', class: 'inputfile'}).appendTo(fb); inp.on('change', function() { var filename = $(this).val().replace(/.*(\/|\\)/, ''); $(this).next().html(filename); $(this).parent().next('input[type="button"]').fadeIn('fast'); }); var lab = $('