Removed Unsplash

Removed Unsplash in order to keep everything simple. (Also the load times were too god damn high)
This commit is contained in:
Kukielka
2018-04-16 12:15:00 +02:00
parent 05247c761f
commit b9dfafa3bd
11 changed files with 49 additions and 209 deletions

View File

@ -1,31 +1,20 @@
html {height: 100%; width: 100%;}
body {font-family: sans-serif; z-index: 1; height: 100%; width: 100%; background-position: center; background-attachment: fixed;}
.hidden {display: none;}
.menu-item {display: none; z-index: 3;}
#bg-overlay {
position:fixed;
padding:0;
margin:0;
top:0;
left:0;
width: 100%;
html {
height: 100%;
background-color: #fff;
opacity: 0;
z-index: 2;
transition: .3s all;
width: 100%;
}
body.menu-shown #bg-overlay {opacity: 0.3;}
#mobile-menu-wrap {z-index: 3; position: absolute; top: 15px; left: 15px;}
#mobile-menu-wrap a {font-size: 20px;}
body {
font-family: sans-serif;
z-index: 1;
height: 100%;
width: 100%;
background-position: center;
background-attachment: fixed;
}
.bg {
border-radius: 5px;
background-color: rgba(0, 0, 0, .5);
border-radius: 6px;
background-color: rgba(0, 0, 0, .4);
padding: 20px;
}
@ -35,29 +24,41 @@ body.menu-shown #bg-overlay {opacity: 0.3;}
#links-wrap {
font-size: 80px;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding-bottom: 3px;
width: fit-content;
height: auto;
max-width: 75%;
max-width: 80%;
max-height: 85%;
overflow: auto;
display: flex;
}
#links-wrap a {transition: .3s all;}
#links-wrap a:hover {color: #d3d3d3;}
#links-wrap .link {display: inline-block; width: 33%; float: left; text-align: center;}
#links-wrap::-webkit-scrollbar {width: 10px; background-color: transparent;}
#links-wrap::-webkit-scrollbar-thumb {border-radius: 10px; -webkit-box-shadow: inset 0 0 3px rgba(0,0,0,.4); background-color: rgba(255,255,255,.2);}
#links-wrap a {
transition: .3s all;
}
#pic-info-wrap {color: #fff; font-size: 16px; position: absolute; bottom: 15px; left: 15px;}
#pic-info-wrap a:hover, #pic-info-wrap a:active {color: #fff; text-decoration: none;}
#links-wrap a:hover {
color: #c4c4c4;
}
#links-wrap .link {
display: inline-block;
width: 33%;
float: left;
text-align: center;
}
#links-wrap::-webkit-scrollbar {
width: 10px;
background-color: transparent;
}
#links-wrap::-webkit-scrollbar-thumb {
border-radius: 6px;
-webkit-box-shadow: inset 0 0 3px rgba(0,0,0,.4);
background-color: rgba(255,255,255,.2);
}

View File

@ -1,53 +0,0 @@
// Set random background image
function setBgImg() {
var bg = "";
$.getJSON("hp_assets/lib/ajax_get_image.php").done(function(data) {
if (data['success']) {
bg = data['url'];
if (bg != "" && bg != null) {
preloadimages([bg]).done(function(images) {
$("#homepage").css("background-image", "url(" + bg + ")").css("background-size", "cover");
$("#pic-info-wrap").removeClass("hidden");
$("#pic-info-url").attr("href", data['image_user_url']).text(data['image_user_name']);
});
}
}
});
}
// http://www.javascriptkit.com/javatutors/preloadimagesplus.shtml
function preloadimages(arr){
var newimages=[], loadedimages=0
var postaction=function(){}
var arr=(typeof arr!="object")? [arr] : arr
function imageloadpost(){
loadedimages++
if (loadedimages==arr.length){
postaction(newimages) //call postaction and pass in newimages array as parameter
}
}
for (var i=0; i<arr.length; i++){
newimages[i]=new Image()
newimages[i].src=arr[i]
newimages[i].onload=function(){
imageloadpost()
}
newimages[i].onerror=function(){
imageloadpost()
}
}
return { //return blank object with done() method
done:function(f){
postaction=f || postaction //remember user defined callback functions to be called when images load
}
}
}
$(function() {
$("#mobile-menu-wrap a").click(function(e) {
e.preventDefault();
});
setBgImg();
});

View File

@ -1,66 +0,0 @@
<?php
// AJAX call to fetch a new background image
// http://stackoverflow.com/a/24707821 => use instead of file_get_contents for external URL's
function curl_get_contents($url, $headers = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
// Include potential headers with request
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
// Traverse a JSON object given a string selector
function traverse_json($json, $selector) {
$regex = "\[\'?([{}a-z0-9_]+)\'?\]";
preg_match_all('/' . $regex . '/i', $selector, $matches);
// Go through each regex match and traverse the JSON object given the keys
$obj = $json;
foreach ($matches[1] as $i => $match) {
if ($match == '{random}' && is_array($obj)) {
// Let's fetch a random index of the array
$rand = rand(0, count($obj));
$obj = $obj[$rand];
} else {
// Keep traversing the object
$obj = $obj[$match];
}
}
return $obj;
}
$config = json_decode(file_get_contents(dirname(__FILE__) . "/../../config.json"), true);
if (!empty($config['custom_url'])) {
// We're fetching from a custom URL
$json = json_decode(curl_get_contents($config['custom_url'], $config['custom_url_headers']), true);
$image_url = traverse_json($json, $config['custom_url_selector']);
echo json_encode(array('success' => 1, 'url' => $image_url));
} else if (!empty($config['unsplash_client_id'])) {
// We're fetching from Unsplash's API
$url = "https://api.unsplash.com/photos/random?per_page=1&client_id=" . $config['unsplash_client_id'];
$json = json_decode(curl_get_contents($url), true);
$image_url = $json['urls']['regular'];
$image_user_name = $json['user']['name'];
$image_user_url = $json['user']['links']['html'];
echo json_encode(array('success' => 1, 'url' => $image_url, 'image_user_name' => $image_user_name, 'image_user_url' => $image_user_url));
}
die();
?>