File: /var/www/vhosts/creativefellows.nl/figi.creativefellows.nl/public/js/app copy.js
// datepicker settings
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define([ "../jquery.ui.datepicker" ], factory );
} else {
// Browser globals
factory( jQuery.datepicker );
}
}(function( datepicker ) {
datepicker.regional['nl'] = {
closeText: 'Sluiten',
prevText: 'Vorige',
nextText: 'Volgende',
currentText: 'vandaag',
monthNames: ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni','Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'],
monthNamesShort: ['jan', 'feb', 'mrt', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
dayNames: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
dayNamesShort: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
dayNamesMin: ['z','m','d','w','d','v','z'],
weekHeader: 'Week',
dateFormat: 'dd-mm-yy',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''};
datepicker.setDefaults(datepicker.regional['nl']);
return datepicker.regional['nl'];
}));
$(document).foundation().ready(function(){
$(".toggle-navigation").toggleSearchNavigation();
$("#header").fixednav();
// cookie accept
$('#acceptCookie').on("click",function(event)
{
event.preventDefault();
var cookies = $(this).closest(".cookies");
$.ajax({
type: 'POST',
url: "accept-cookies",
success: function (response) {
$("#cookies").slideUp("fast");
}
});
});
// open external links in new window
//$(document.links).filter(function() {
// return this.hostname != window.location.hostname;
//}).attr('target', '_blank');
// check form response
$(".form-response").checkIsSent();
// showcase
$('.image-showcase').slick({
pauseOnHover:true,
autoplay: false,
autoplaySpeed: 4000,
dots: false,
infinite: true,
speed: 500,
fade: true,
cssEase: 'linear',
arrows: true
});
$('.slick-center').slick({
centerMode: true,
slidesToShow: 3,
centerPadding: '40px',
responsive: [
{
breakpoint: 900,
settings: {
arrows: true,
centerMode: true,
slidesToShow: 2
}
},
{
breakpoint: 480,
settings: {
arrows: false,
centerMode: true,
slidesToShow: 1
}
}
]
});
// fade out header on scroll
$(window).scroll(function(){
$(".image-showcase .cell .column-wrapper").css("opacity", 1 - $(window).scrollTop() / 250);
});
$(".show-schedule .fake-input-element").fakeInput();
// search shows
$(".find-shows").findShows();
// search shows
$(".figi-calendar").getCalendar();
// scroll to element
$(".loopback button[data-toggle], button[data-scroll]").scrollToForm();
$("img.lazyLoad").lazyload({
effect : "fadeIn"
});
// enlarge images
$(".enlarge-images img").enlargeImage();
//$("img").showAltDescription();
$(".play-trailer").embedYoutube();
// HP reviews
$("#reviews-gasten").showReviews();
// HP
$(".agenda-figi").figiAgenda();
// get iens widget
$(".iens-widget").embedIens();
$(".calendar").datepicker({
dateFormat: "dd-mm-yy",
minDate: 0,
showOtherMonths: true,
selectOtherMonths: true,
onSelect: function(dateText, inst){
var date = $(this).datepicker('getDate');
var startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
var hidden_format = $.datepicker.formatDate( "mm/dd/yy", startDate, inst.settings )
var copy = $(this).attr("data-copy");
$(copy).val(hidden_format);
$(copy).updateBookUrl();
}
});
$(".actueel-slider").horizontSlider();
});
$.fn.horizontSlider = function(){
return this.each(function()
{
var plugin = this;
var wrapper = $(this).find(".agenda-items");
plugin.init = function(){
wrapper.slick({
infinite: true,
autoplay: true,
slidesToShow: 4,
arrows: true,
lazyLoad: 'ondemand',
responsive: [
{
breakpoint: 480,
settings: {
slidesToShow: 1
}
}
]
});
}
// init the plugin
plugin.init();
});
}
$.fn.updateBookUrl = function()
{
return this.each(function(){
var element = $(this);
var form = element.closest(".book-a-room");
var change_elements = form.find(".update-url");
var link = form.find(".button");
var org_url = link.attr("data-org");
var qpm = [];
element.init = function()
{
change_elements.each(function(){
qpm[ $(this).attr("name") ] = $(this).val();
element.updateParameter();
});
}
element.updateParameter = function(){
var str = "";
for (var i in qpm) {
if(i =="" || qpm[i] == "") continue;
str += '&'+ i + '=' + qpm[i];
console.log(i + '=' + qpm[i]);
}
var action = org_url.replace("{data}",str);
link.attr("href",action);
}
element.init();
});
}
$.fn.embedIens = function()
{
return this.each(function(){
var widget = $(this);
var tp = $('<div class="reveal tiny" data-reveal=""><div class="wrapper text-center"></div><button aria-label="Close reveal" class="close-button" data-close="" type="button"><span aria-hidden="true">×</span></button></div>');
var reveal;
widget.init = function()
{
widget.on("click",function(event){
event.preventDefault();
// new FD reveal
reveal = new Foundation.Reveal(tp,{"speed":500});
// get data
widget.getData();
//open reveal
reveal.open();
});
}
widget.getData = function(){
$.ajax('get-iens').done(function(resp){
tp.find(".wrapper").html(resp);
});
}
// init the plugin
widget.init();
});
}
$.fn.figiAgenda = function(options)
{
return this.each(function(){
var defaults = {
duration: 4000,
effectspeed : 500
}
var plugin = this;
plugin.settings = {}
var wrapper = $(this);
var counter = 0;
var items,current_item,next_item,timer;
plugin.init = function(){
plugin.settings = $.extend({}, defaults, options);
plugin.getAgenda();
}
// get json reviews
plugin.getAgenda = function(){
$.ajax({
dataType: "json",
type: 'GET',
url: "get-agenda",
data: {},
success: function(json)
{
plugin.setAgenda(json);
}
});
}
// set the reviews
plugin.setAgenda = function(json){
wrapper.html("");
$(json).each(function(i, item){
var tp = $('<div class="agenda-item"><img src="'+ item.image +'"><div class="text"><h3>'+ item.title +'</h3><h4>'+ item.artist +'</h4><p>'+ item.date+ '</p></div><a href="'+ item.url +'" class="more">meer</a></div>');
wrapper.append(tp);
});
}
// init the plugin
plugin.init();
});
}
$.fn.showReviews = function(options)
{
return this.each(function(){
var defaults = {
duration: 4000,
effectspeed : 500
}
var plugin = this;
plugin.settings = {}
var wrapper = $(this).find(".reviews");
var dots = $(this).find("li");
var counter = 0;
var items,current_item,next_item,timer;
plugin.init = function(){
plugin.settings = $.extend({}, defaults, options);
plugin.getReviews();
dots.on("click",function(){
var id = $(this).index()
dots.removeClass("active");
$(this).addClass("active");
clearInterval(timer);
$(current_item).fadeOut(plugin.settings.effectspeed);
$(items[id]).fadeIn(plugin.settings.effectspeed);
current_item = items[id];
});
}
// get json reviews
plugin.getReviews = function(){
$.ajax({
dataType: "json",
type: 'GET',
url: "get-reviews",
data: {},
success: function(json)
{
plugin.setReviews(json);
}
});
}
// set the reviews
plugin.setReviews = function(json){
wrapper.html("");
var highest = 0;
$(json).each(function(i, review){
var tp = $('<div class="review"><blockquote>'+ review.review +'</blockquote><p><strong>'+ review.naam +'</strong><br>'+ review.plaats +'</p></div>');
wrapper.append(tp);
var h = tp.height();
if(h > highest) highest = h;
tp.css("height", h+"px");
// only show first
if(i != 0) tp.hide();
});
items = $(this).find(".review");
current_item = items[counter];
next_item = items[counter+1];
wrapper.css("height",highest+"px")
plugin.timeOut();
}
// timeout
plugin.timeOut = function(){
dots.removeClass("active");
$(dots[counter]).addClass("active");
timer = setTimeout(plugin.showItem, plugin.settings.duration);
}
// start the plugin
plugin.showItem = function (){
$(current_item).fadeOut(plugin.settings.effectspeed);
$(next_item).fadeIn(plugin.settings.effectspeed);
counter++;
if(counter == items.length) counter = 0;
setTimeout(function(){
current_item = next_item;
next_item = items[counter];
plugin.timeOut();
},plugin.settings.effectspeed)
}
// init the plugin
plugin.init();
});
}
$.fn.embedYoutube = function()
{
return this.each(function(){
var embed = $(this);
var video = embed.attr("date-video-id");
var trailer = embed.closest(".showcase-case").find(".trailer");
var clse = trailer.find(".close-button");
var loaded = false;
var done = false;
var player;
embed.init = function()
{
embed.getYoutubeApi();
// load and play video
embed.click(function(event){
event.preventDefault();
// load the trailer
if(loaded == false) embed.showTrailer();
else embed.resumeVideo();
});
// stop video when closing
clse.click(function(){
setTimeout(embed.stopVideo, 500);
});
}
embed.showTrailer = function()
{
player = new YT.Player('player', {
videoId: video,
playerVars: { 'rel': 0, 'color': 'white','controls':0,'showinfo':0,'autohide':1, 'autoplay':1 ,'modestbranding':1},
events: {
'onReady': embed.playVideo,
'onStateChange': embed.onPlayerStateChange
}
});
}
embed.getYoutubeApi = function()
{
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
embed.playVideo = function(event)
{
loaded = true;
event.target.playVideo();
}
embed.onPlayerStateChange = function(event)
{
if (event.data == 0){
done = true;
trailer.hide();
}
}
embed.stopVideo = function()
{
player.stopVideo();
}
embed.resumeVideo = function()
{
player.playVideo();
}
// init the plugin
embed.init();
});
}
$.fn.showAltDescription = function()
{
return this.each(function(){
var image = $(this);
var img_wrapper = $('<figure class="image-alt"></figure>');
image.init = function()
{
//var img = plugin.clone();
if(!image.getAltText()) return;
image.wrap(img_wrapper);
var test = img_wrapper.find("img")
$("<figcaption>"+ image.getAltText() +"</figcaption>").insertAfter(image);
//console.log(image);
}
image.getAltText = function()
{
return image.attr("alt");
}
// init the plugin
image.init();
});
}
$.fn.enlargeImage = function(){
return this.each(function(){
var image = $(this);
var img_alt = image.attr("alt");
var tp = $('<div class="reveal full text-center" data-reveal data-animation-in="scale-in-up" data-animation-out="scale-out-down"><button class="close-button" data-close aria-label="Close modal" type="button"><span aria-hidden="true">×</span></button><div><h2>'+ img_alt +'</h2></div></div>');
var img_wrapper = $('<div class="show-large-image"></div>');
var has_closed = false;
var reveal;
image.init = function()
{
// duplicate image
image.duplicate()
reveal = new Foundation.Reveal(tp,{"speed":500});
image.on("click",function(){
reveal.open();
});
}
image.duplicate = function()
{
var img = image.clone();
image.wrap(img_wrapper);
tp.append(img);
tp.insertAfter(image);
}
// init the plugin
image.init();
});
}
$.fn.scrollToForm = function(element, options)
{
return this.each(function(){
var button = $(this);
var scroll_to_element = button.attr("data-toggle");
button.init = function()
{
$(this).on("click",function(){
setTimeout(function(){
button.animate();
},100);
});
}
button.animate = function()
{
$("html,body").animate({
scrollTop: $("#"+scroll_to_element).offset().top - $("#header").height()
},1000);
$("#"+scroll_to_element).find("input").first().focus();
}
// init the plugin
button.init();
});
}
$.fn.getCalendar = function()
{
return this.each(function()
{
var form = $(this);
form.settings = {}
var button = form.find("button");
var inputs = form.find(".fake-input-element:not(.weekdays-select) ");
var container = $(form.attr("data-container"));
var pagination = $(form.attr("data-pagination"));
var weekday = form.find(".weekdays-select a");
form.init = function()
{
// Submit form
button.on("click",function(event){
event.preventDefault();
form.getMonth();
});
// fake inputs
inputs.fakeInput();
}
// get the shows
form.getMonth = function()
{
$.ajax({
url: "get-calendar",
data: {
'date': form.getMonthId()
},
method: "POST",
success: function(data){
if(data) form.setMonth(data);
}
});
}
// update dom
form.setMonth = function(data)
{
$(".reveal-overlay").remove();
container.html(data);
var events = container.find(".reveal");
events.each(function(){
var elem = new Foundation.Reveal($(this));
});
}
// get selected date
form.getMonthId = function()
{
return inputs.find("#date-id").val();
}
// init the plugin
form.init();
});
}
$.fn.findShows = function()
{
return this.each(function()
{
var form = $(this);
form.settings = {}
var button = form.find("button");
var inputs = form.find(".fake-input-element:not(.weekdays-select) ");
var container = $(form.attr("data-container"));
var pagination = $(form.attr("data-pagination"));
var weekday = form.find(".weekdays-select a");
var options = form.find(".fake-input-element:not(.weekdays-select) a.option");
var search = form.find("a.search");
var baseurl = null;
form.getTerm = function(){
var minlength = 2;
var searchRequest;
var timer = null;
// focus search term
setTimeout( function(){
$("#term").focus()
},750);
$("#term").keyup(function(){
clearInterval(timer);
timer = null;
var value = $(this).val();
timer = setTimeout(function(){
$.ajax({
url: "get-tickets",
data: {
'type' : "cinema",
'q' : value
},
method: "POST",
success: function(data){
form.clearCells();
if(data) form.setShows(data);
}
});
},500);
});
}
form.init = function()
{
// button search
button.on("click",function(event){
event.preventDefault();
form.getShows(1);
});
// toggle search term input
search.one("click",function(event){
event.preventDefault();
form.getTerm();
});
// cinema weekdays
weekday.on("click",function(event){
event.preventDefault();
// set active
$(this).closest("ul").find("a.current").removeClass("current");
$(this).addClass("current");
// toggle search shows
if($(this).hasClass("search")){
return;
}
// get IDs
var day_id = $(this).attr("data-value");
var genre = $(this).attr("data-genre");
var group_id = $(this).attr("data-group-id");
// empty current cells
form.clearCells();
// get tickets
$.ajax({
url: "get-tickets",
data: {
'type' : "cinema",
'genre' : genre,
'date' : day_id,
'group' : group_id
},
method: "POST",
success: function(data){
// insert shows
if(data) form.setShows(data);
}
});
});
// pagination clicks
form.paginationClick();
// fake inputs
inputs.fakeInput();
// click on fake input elements, auto update results
options.on("click",function(){
form.getShows(1);
});
// ajax history
form.setBaseUrl();
window.addEventListener('popstate', function(e){
if(e.state) form.historyUrl(e.state);
});
}
form.setBaseUrl = function()
{
baseurl = form.find("#base").val();//window.location.pathname;
//alert(baseurl);
}
// fade oud and remove current shows
form.clearCells = function(){
var h = container.height();
container.css("height",h+"px");
// fade out current items
var cells = container.find(".cell");
cells.each(function()
{
$(this).fadeOut("fast",function(){
$(this).remove();
});
});
}
form.paginationClick = function()
{
pagination.on('click', 'a', function(event){
event.preventDefault();
var page = $(this).attr("data-page");
form.getShows(page);
});
}
// get the shows
form.getShows = function(page)
{
// empty current cells
form.clearCells();
$.ajax({
url: "get-tickets",
data: {
'date': form.getDate(),
'category': form.getCategory(),
'name': form.getCategoryName(),
'type' : form.getTicketType(),
'q' : form.getSearchQuery()
},
method: "POST",
success: function(data){
if(data) form.setShows(data);
}
});
var hist = {
date: form.getDate(),
category: form.getCategory(),
name: form.getCategoryName(),
type: form.getTicketType(),
q: form.getSearchQuery()
}
var url = baseurl +'/'+ form.getDate() +'/'+ form.getCategory() ;
window.history.pushState(hist, '', url);
//console.log(hist);
}
form.historyUrl = function(state){
// empty current cells
form.clearCells();
$.ajax({
url: "get-tickets",
data: {
'date': state.date,
'category': state.category,
'name': state.name,
'type' : state.type,
'q' : state.q
},
method: "POST",
success: function(data){
if(data) form.setShows(data);
}
});
}
// update dom
form.setShows = function(shows)
{
// toggle pagination
if(shows.meta.pagination === 0) $("#show-pagination").hide();
else form.setPagination(shows.meta);
//console.log(shows.tickets);
if(!shows.tickets)
{
var tp = $('<div class="cell small-12 text-center no-results" style="width:100%;"><h3>Geen voorstellingen gevonden</h3><p>Wijzig de datum of kies een andere categorie.</p></div>');
tp.hide();
container.append(tp);
tp.fadeIn("fast");
$("#show-pagination").hide();
}
else if( $(".no-results").length ){
$(".no-results").remove();
}
$(shows.tickets).each(function(i, show){
var genre = show.genre != null ? '<h5>'+ show.genre +'</h5>' : '';
var tp = $('<div class="cell show"><div class="card">\
<div class="card-image"><a href="'+ show.link +'"><img class="lazyload" src="'+ show.image +'"></a></div>\
<div class="card-section">\
<h4 data-equalizer-watch><a href="'+ show.link +'">'+ show.artist +'</a></h4>\
'+ genre +'\
<p>'+ show.lead +'</p>\
</div>\
</div></div>');
if(show.date)
{
tp.find(".card-section h4").after(show.icon);
}
tp.hide();
container.append(tp);
tp.fadeIn("fast");
});
container.css("height","");
var elem = new Foundation.Equalizer(container);
}
// update the pagination
form.setPagination = function(metadata)
{
$("#show-pagination").html(metadata.pagination).show();
}
form.getSearchQuery = function()
{
return form.find("#search-shows").val();
}
// get selected date
form.getDate = function()
{
return inputs.find("#date-id").val();
}
// get selected category
form.getCategory = function()
{
return inputs.find("#genre-id").val();
}
// fet ticket type
form.getTicketType = function()
{
return inputs.find("#ticket-type").val();
}
form.getCategoryName = function()
{
return inputs.find("#genre-name").val();
}
// init the plugin
form.init();
});
}
$.fn.fakeInput = function()
{
return this.each(function(){
var input = $(this);
var select = $(this).find(".fake-input");
var options = $(this).find("a.option");
var label = $(this).find(".current-element span");
var input_id = $( $(this).attr('data-id') );
var input_name = $( $(this).attr('data-name') );
var update_el = $(this).attr('data-update-element');
input.init = function()
{
select.on("click",function(event){
event.preventDefault();
var clicked = $(this);
var dropdown = $(this).next();
var par = $(this).parent();
par.toggleClass("active");
dropdown.toggleClass("hidden");
// hide open selects
$(".fake-input-values").not(dropdown).addClass("hidden");
});
}
options.on("click",function(event){
event.preventDefault();
var text = $(this).html();
var id = $(this).attr('data-value');
var lbl = $(this).attr('data-label');
//var name = $(this).attr('data-name');
// update label
label.text(text);
// set hidden input value
input_id.val(id);
input_name.val(lbl);
// hide deopdowns
$(".fake-input-values").addClass("hidden");
// update an alement with given id / url
input.updateOrderUrl(id);
});
input.updateOrderUrl = function(id)
{
$(update_el).attr("href", id);
}
// init the plugin
input.init();
});
}
$.fn.checkIsSent = function()
{
return this.each(function(){
var form = $(this);
form.init = function()
{
var s = form.getUrlParameter("s");
var id = form.getUrlParameter("id");
var h = form.getUrlParameter("h");
if(s == 1)
{
$('html, body').animate({
scrollTop: form.offset().top -200
}, 1000);
}
}
form.getUrlParameter = function(sParam){
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
// init the plugin
form.init();
});
}
/*
* fixed navigation
*/
$.fn.fixednav = function()
{
var shrinkHeader = $('#header').height();
var lastScrollTop = 0;
$(window).scroll(function() {
var scrollYpos = getCurrentScroll();
if(scrollYpos >= shrinkHeader) $('#header').addClass('has-scrolled');
else $('#header').removeClass('has-scrolled');
// scrolling up
//if (scrollYpos < lastScrollTop) $('#header').removeClass('has-scrolled');
// set scroll pos
lastScrollTop = scrollYpos;
});
function getCurrentScroll()
{
return window.pageYOffset;
}
function checkScrollPosition()
{
var scroll = getCurrentScroll();
if(scroll >= shrinkHeader) $('#header').addClass('has-scrolled');
}
checkScrollPosition();
}
/*
* toggle navigation
*/
$.fn.toggleSearchNavigation = function()
{
var shadeout = null;
var fadeDelay = 500;
var menu_el = new Foundation.ResponsiveToggle('.toggle-menu');
var toggle_nav = $(this);
var navcopied = false;
var close_search = $('.close-search');
var search = $('#search-products');
$(this).on("click",function(event)
{
// toggle open class
$(this).toggleClass('open');
$("#header").toggleClass('open');
// create mask element if not exists
if( $(".shade-out").length == 0 ) createShadeOut();
// open
if( !$(this).hasClass("open") )
{
// hide shade-out
shadeout.removeClass("is-open").delay(fadeDelay).fadeOut("fast");
}
else
{
// show shade-out
shadeout.addClass("is-open").hide().fadeIn("fast");
}
// copy nav
if( navcopied == false ) copyNav();
else deleteNav();
});
$(".toggle-search").on("click",function(event)
{
$("#header").toggleClass('navigation-open');
if($("#header").hasClass('navigation-open')){
setTimeout(function(){
$("#q").focus();
},100)
}
});
$('.close-search').on("click",function(event)
{
$("#header").toggleClass('navigation-open');
});
var createShadeOut = function()
{
shadeout = $('<div class="shade-out"></div>').hide();
shadeout.insertAfter("#header");
shadeout.on("click",function(event)
{
// fade shade
hideShadeOut();
// close menu
menu_el.toggleMenu('close');
//
toggle_nav.toggleClass('open');
});
}
var hideShadeOut = function()
{
// hide shade-out
shadeout.removeClass("is-open").delay(fadeDelay).fadeOut("fast");
}
var copyNav = function()
{
var langs = $('.language').html();
var html = $('<li class="language hide-for-large"></li>').append(langs);
if( navcopied == false )
{
html.insertBefore( $("li.search") );
navcopied = true;
}
}
var deleteNav = function()
{
// delete inserted navs
//$(".sub-items").remove();
///navcopied = false;
}
}