diff --git a/gallery/__init__.py b/gallery/__init__.py index f3ef3d9..c24f1a3 100644 --- a/gallery/__init__.py +++ b/gallery/__init__.py @@ -82,18 +82,18 @@ def create_app(test_config=None): msg = "You are not authorized to view this page!!!!" return render_template("error.html", error=error, msg=msg), error - js_pre = Bundle( - "js/pre/*.js", filters="jsmin", output="gen/pre_packed.js", depends="**" + lib = Bundle( + "lib/*.js", filters="jsmin", output="gen/lib.js", depends="lib/*.js" ) - js_post = Bundle( - "js/post/*.js", filters="jsmin", output="gen/post_packed.js", depends="**" + js = Bundle( + "js/*.js", filters="jsmin", output="gen/index.js", depends="js/*.js" ) styles = Bundle( "sass/*.sass", filters="libsass,cssmin", output="gen/styles.css", depends="**" ) - assets.register("js_pre", js_pre) - assets.register("js_post", js_post) + assets.register("lib", lib) + assets.register("js", js) assets.register("styles", styles) # Error handlers, if the error is not a HTTP error, return 500 diff --git a/gallery/static/js/pre/main.js b/gallery/static/js/index.js similarity index 92% rename from gallery/static/js/pre/main.js rename to gallery/static/js/index.js index 76fd4cf..f8f09ac 100644 --- a/gallery/static/js/pre/main.js +++ b/gallery/static/js/index.js @@ -1,19 +1,12 @@ -let webpSupport = false; -try { - new Image().src = 'data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAwA0JaQAA3AA/vuUAAA='; - webpSupport = true; -} catch (e) { - webpSupport = false; -} - // fade in images -function imgFade(obj, time = 250) { +async function imgFade(obj, time = 250) { obj.style.transition = `opacity ${time}ms`; obj.style.opacity = 1; } // Lazy load images when they are in view -function loadOnView() { +async function loadOnView() { const lazyLoad = document.querySelectorAll('#lazy-load'); + const webpSupport = checkWebpSupport(); for (let i = 0; i < lazyLoad.length; i++) { let image = lazyLoad[i]; diff --git a/gallery/static/js/post/login.js b/gallery/static/js/login.js similarity index 100% rename from gallery/static/js/post/login.js rename to gallery/static/js/login.js diff --git a/gallery/static/js/post/uploadTab.js b/gallery/static/js/uploadTab.js similarity index 100% rename from gallery/static/js/post/uploadTab.js rename to gallery/static/js/uploadTab.js diff --git a/gallery/static/js/pre/notifications.js b/gallery/static/lib/notifications.js similarity index 99% rename from gallery/static/js/pre/notifications.js rename to gallery/static/lib/notifications.js index f550344..1cda690 100644 --- a/gallery/static/js/pre/notifications.js +++ b/gallery/static/lib/notifications.js @@ -61,5 +61,3 @@ function addNotification(notificationText, notificationLevel) { } }, 5000); } - -// uwu diff --git a/gallery/static/js/pre/popup.js b/gallery/static/lib/popup.js similarity index 100% rename from gallery/static/js/pre/popup.js rename to gallery/static/lib/popup.js diff --git a/gallery/static/lib/webp.js b/gallery/static/lib/webp.js new file mode 100644 index 0000000..debea3f --- /dev/null +++ b/gallery/static/lib/webp.js @@ -0,0 +1,10 @@ +async function checkWebpSupport() { + var webpSupport = false; + try { + webpSupport = document.createElement('canvas').toDataURL('image/webp').indexOf('data:image/webp') == 0; + } catch (e) { + webpSupport = false; + } + + return webpSupport; +}