<file_sep># MediaDb

MediaDb — theme for UiB's MediaDb.

## About

Based on the [blank](http://themes.gohugo.io/theme/blank/) theme.

## License

This theme is released under the [MIT license](//github.com/Vimux/blank/blob/master/LICENSE.md).
<file_sep>name = "MediaDb"
license = "MIT"
licenselink = "https://github.com/vimux/blank/blob/master/LICENSE.md"
description = "MediaDb — theme for UiB's MediaDb."
homepage = "https://github.com/semafor/blank/"
tags = []
features = ["blog"]
min_version = 0.15

[author]
  name = "Vimux"
  homepage = "https://github.com/vimux"
<file_sep>window.addEventListener("load", function load(event) {
    var container = document.getElementById("all-movies-placeholder");

    if (!container) {
        return;
    }

    var tmpl = mediadb.templates.movie_summary;

    for (var movie_id in movies_object) {
        movies_object[movie_id]._key = movie_id;
        movies_object[movie_id].art_path = getNelsonImageUrl(movie_id);
        container.innerHTML += template(tmpl, movies_object[movie_id]);
    }
});
<file_sep>function toggleSiteNav() {
    document.getElementById("main-nav").classList.toggle("open");
}
<file_sep>function openDialog() {
    document.body.classList.add("show-dialog");
}

function closeDialog() {
    document.body.classList.remove("show-dialog");
}
<file_sep>window.addEventListener("load", function load(event) {
    var placeholder = document.getElementById("single-genre-placeholder");
    if (!placeholder) {
        return;
    }

    var query_params = get_query_string_parameters(document.location.href);
    var genre = query_params.title;
    var movies = [];
    console.log(genres_object)

    for (var movieId in genres_object) {
        for (var genreName in genres_object[movieId]) {
            if (genreName.indexOf(genre) >= 0) {
                movies.push(movieId);
            }
        }
    }

    var tmp = document.createElement('div');
    tmp.innerHTML = template(
        mediadb.templates.genre_single, { title: genre }
    );
    placeholder.parentNode.insertBefore(tmp, placeholder);

    render_set_of_movies("single-genre-placeholder", movies);
});
<file_sep>---
made:
actors:
    - <NAME>
    - <NAME>

alternateTitles:
    nb_no:

genres:
    - horror
    - suspense
summary: ""
extraMaterial:
    - deleted scenes
    - gaffes
runtime: 0
originCountries: []
type: film
artwork: []
---
<file_sep>{{ partial "header.html" . }}
    <main class="genre-single single-view">
        <article>
            <h1>{{ .Title }}</h1>

            <h2>Filmer i denne sjangeren:</h2>
            <ul class="film-list">
                {{ range .Params.associatedFilms }}
                    {{ range . }}
                        <li><a href="{{ "/film/" | relLangURL }}{{ .url | urlize }}.html">{{ .name }}</a> </li>
                    {{ end }}
                {{ end }}
            </ul>
        </article>
    </main>
{{ partial "footer.html" . }}
<file_sep>function search_for_movie(keyword, movies) {
    return movies.filter(
        m => (m.ntitle.toLowerCase().indexOf(keyword.toLowerCase()) >= 0) ||
             (m.otitle.toLowerCase().indexOf(keyword.toLowerCase()) >= 0)
    );
}

function search_for_genre(genre, movies) {
    return movies.filter(function (m) {
        for (var genreName in genres_object[m._key]) {
            if (genreName.indexOf(genre.toLowerCase()) >= 0) {
                return true;
            }
        }
        return false;
    });
}

function search_for_cast(cast, movies) {
    return movies.filter(function (m) {

        if (!m.folk) {
            return false;
        }

        var folk = m.folk.split(", ");
        for (var i = 0; i < folk.length; i++) {
            var f = folk[i].toLowerCase().trim();
            if (f.indexOf(cast) >= 0) {
                return true;
            }
        }

        return false;
    });
}

function display_search_for_movie(results, container) {
    if (results.length == 0) {
        container.innerHTML = mediadb.templates.no_results;
        return;
    }

    var tmpl = mediadb.templates.movie_summary;
    container.innerHTML = "<div class='movie-section front-section'>";
    for (var i = 0; i < results.length; i++) {
        results[i].art_path = getNelsonImageUrl(results[i]._key);
        container.innerHTML += template(tmpl, results[i]);
    }
    container.innerHTML += "</div>";
}

window.addEventListener("load", function load(event) {

    // Whether or not to do a search.
    var placeholder = document.getElementById("search-results-placeholder");

    if (!placeholder) {
        return;
    }

	query_params = get_query_string_parameters(
        document.location.href.toLowerCase()
    );

    // Create an array of movie objects and preserve the key.
	search_results = [];
    for (var key in movies_object) {
        var obj = movies_object[key];
        obj["_key"] = key;
        search_results.push(obj);
    }

	if (query_params.cast) {
        var cast = query_params.cast.split(" ");
        for (var i = 0; i < cast.length; i++) {
            search_results = search_for_cast(cast[i], search_results);
        }
    }

	if (query_params.director) {
		search_results = search_results.filter(
            m => (m.dir && m.dir.toLowerCase().indexOf(query_params.director) >= 0)
        );
    }

	if (query_params.genre) {
        var genres = query_params.genre.split(",");
        for (var i = 0; i < genres.length; i++) {
            search_results = search_for_genre(genres[i].trim(), search_results);
        }
    }

    if (query_params.country) {
        search_results = search_results.filter(
            m => (m.dir && m.country.toLowerCase() == query_params.country)
        );
    }

    if (query_params.search) {
        search_results = search_for_movie(query_params.search, search_results);
    }

    display_search_for_movie(search_results, placeholder);
});
<file_sep>---
name: ""
films:
    - intouchables
---
<file_sep>window.addEventListener("load", function load(event) {
    var container = document.getElementById("single-movie-placeholder");
    if (!container) {
        return;
    }

    var query_params = get_query_string_parameters(document.location.href);
    if (!query_params.id) {
        window.location.href = "/404.html";
        return;
    }

    var xhr = new XMLHttpRequest();
    xhr.open("GET", "http://wildboy.uib.no/mongodb/objects/?filter_id=" + query_params.id, true);
    xhr.responseType = "json";
    xhr.onload = function () {
        movie_object = xhr.response.rows[0];

        if (!movie_object) {
            window.location.href = "/404.html";
            return;
        }

        // get the genre info (if it exists)
        var genre_object = genres_object[query_params.id];

        // get the review info (if it exists)
        var review_object = reviews_object[query_params.id];

        // Slap some more stuff onto the movie_object
        movie_object.art_path = getNelsonImageUrl(query_params.id);

        // Genre stuffs.
        movie_object.genre_html = "<nav class='genre-nav inline-menu'><ul>";
        for (var k in genre_object) {
            movie_object.genre_html += template(mediadb.templates.genre, {
                title: k
            });
        }
        movie_object.genre_html += "</ul></nav>";

        // People stuff.
        movie_object.people_html = "<ul class='actor-list'>";
        var people_list = movie_object.folk ? movie_object.folk.split(",") : [];
        for (var i = 0; i < people_list.length; i++) {
            movie_object.people_html += template(mediadb.templates.person, {
                title: people_list[i].trim()
            });
        }
        movie_object.people_html += "</ul>";

        // Trailer stuff.
        movie_object.trailer_html = "";
        if (movie_object["youtube trailer id"]) {
            movie_object.trailer_html = template(mediadb.templates.trailer, {
                youtube_embed: getYouTubeEmbed(movie_object["youtube trailer id"])
            });
        }

        // Set up reviews html.
        if (review_object) {
            movie_object.reviews_html = "<ul class='reviews'>";
            var avg = 0;
            var numReviews = 0;
            var reviews = "";
            for (var reviewId in review_object) {
                avg += review_object[reviewId].rating;
                numReviews++;
                reviews += template(mediadb.templates.review, review_object[reviewId]);
            }

            if (numReviews) {
                var tmpl = mediadb.templates.rating_average;
                avg = avg / numReviews;
                avg = avg.toFixed(1);
                movie_object.reviews_html += template(tmpl, {'avg': avg});
            }
            movie_object.reviews_html += reviews;
            movie_object.reviews_html += "</ul>";
        }

        container.innerHTML = template(mediadb.templates.movie_single, movie_object);
    }

    xhr.send();
});
