require.config({
baseUrl: '/js',
paths: {
"moment": "/static/niji_www/js/vendor/moment-with-locales.min",
"jquery": "/static/niji_www/js/vendor/jquery-2.2.3.min",
"masonry": "/static/niji_www/js/vendor/masonry.pkgd.min",
"jquery-bridget": "/static/niji_www/js/vendor/jquery-bridget",
"text":"/static/niji_www/js/vendor/text",
"handlebars":"/static/niji_www/js/vendor/handlebars-v4.0.5",
"auto-preloader":"/static/niji_www/js/auto-preloader",
"scroll-monitor":"/static/niji_www/js/vendor/scrollMonitor"
}
});
var internalDomains = [/pokemon.com/];
var ModalManager = function(){
//console.log("MODALMANAGER init")
this.closeButton = $(".close-button",this.container);
this.closeButton.on("click", $.proxy(function(){
//console.log("CLOSE")
this.close();
},this));
console.log("REGISTER");
$(document).on("modal-open", $.proxy(function(evt, data){
//console.log("OPEN")
//console.log("MODAL OPEN", arguments)
this.open(data[0], data[1]);
},this));
}
ModalManager.prototype.mask = $("
");
ModalManager.prototype.open = function(content){
this.container.find(".wrapper .contents").html("");
$("body").append(this.mask);
//console.log("this.mask",this.mask)
this.container.css({
opacity:0
});
this.openTimeout = setTimeout(function(){
$("body").addClass("modal-open");
}, 100);
this.addContentTimeout = setTimeout($.proxy(function(){
$("body").append(this.container);
this.container.find(".wrapper .contents").html(content);
},this),500);
this.animateContentTimeout = setTimeout($.proxy(function(){
this.container.css({
opacity:1
});
},this),600);
}
ModalManager.prototype.close = function(){
$("body").removeClass("modal-open");
this.container.detach();
this.closeTimout = setTimeout($.proxy(function(){
this.mask.detach();
//this.container.detach();
},this),250);
}
var modal = new ModalManager();
require(["auto-preloader","moment","handlebars", "scroll-monitor", "text!/static/niji_www/js/templates/region-popup.html", "text!/static/niji_www/js/templates/video-popup.html"], function(AutoPreloader, moment, Handlebars, scrollMonitor, selectRegionTemplate, videoPopupTemplate){
$(document).ready(function(){
//PRELOADER
$("body").on("imageLoaded", function(evt, data){
//console.log("imageLoaded ", data);
$("#progress-bar").css({
"width":data.percent+"%"
})
});
$("body").on("preloadComplete", function(){
////////////console.log("preloadComplete ");
var timeout = setTimeout(function(){
initSite();
},1.75);
$("body").removeClass("loading");
});
document.onAnimationLoaded = function(){
//console.log("onAnimationLoaded");
$("body").removeClass("animation-loading");
}
function initSite(){
$("body").removeClass("loading");
var timeout = setTimeout(function(){
console.log("remove animation-loading")
$("body").removeClass("animation-loading");
},2000);
$("body").css({
position:"relative"
})
$(".preload-mask").css({
opacity:0
});
var timeout2 = setTimeout(function() {
$(".preload-mask").detach();
},1500);
var watchers = [];
//$(window).scrollTop(0);
$('section.subsection').addClass("out-of-view");
$('section.subsection').each(function(index, subsection){
subsection = $(subsection);
var watcher = scrollMonitor.create(subsection, -100 );
watcher.lock(); // ensure that we're always watching the place the element originally was
watcher.exitViewport(function() {
subsection.addClass('out-of-view');
});
watcher.enterViewport(function() {
subsection.removeClass('out-of-view');
});
watchers.push(watcher);
});
}
var hasPreloaded = Cookies.get('preloaded');
Cookies.set('preloaded', true, { expires: 7 });
if(!hasPreloaded){
$("body").addClass("run-animations");
$(".preload-mask").css({
"visibility":"visible"
})
var preloader = new AutoPreloader();
}else{
var timeout = setTimeout(function(){
initSite();
},1.75);
}
var langCookie = Cookies.get('lang');
var htmlLang = $("body").attr("lang");
Cookies.set('lang', htmlLang, { expires: 365 });
videoPopupTemplate = Handlebars.compile(videoPopupTemplate);
// Scroll at-top
var isAtTop = false;
$(window).on("scroll", function(evt){
console.log("isAtTop",isAtTop)
if($(window).scrollTop() > 50 && isAtTop){
$("body").removeClass("at-top");
isAtTop = false;
}else if ($(window).scrollTop() <= 50 && !isAtTop){
$("body").addClass("at-top");
isAtTop = true;
}
});
$(window).scroll();
//EXPAND TEXT IN GALLERY
var galleryTextExpand = $(".detail-gallery .expand");
galleryTextExpand.on("click", function(evt){
//console.log("CLICK")
var target = $(evt.currentTarget);
var subsection = target.closest(".detail-gallery");
subsection.addClass("expanded");
});
//Gallery Popup
var galleries = $(".detail-gallery");
var galleryViewMore = $(".view-gallery", galleries);
galleryViewMore.on("click", function(evt){
console.log("CLICK")
var target = $(evt.currentTarget);
var gallery = target.closest("ul.gallery");
var popGallery = gallery.clone();
var items = $("li", popGallery);
var popGalleryWrapper = $("
");
var prev = $("
");
var next = $("
");
popGalleryWrapper.append(popGallery);
popGallery.before(prev);
popGallery.after(next);
modal.open(popGalleryWrapper);
prev.on("click", function(){
var activeItem = popGallery.find(".active");
var activeIndex = activeItem.index();
var maxLen = items.length;
if(activeIndex == 0){
activeIndex = maxLen-1;
}else{
activeIndex--;
}
console.log("activeIndex",activeIndex)
items.removeClass("active");
items.eq(activeIndex).addClass("active");
});
next.on("click", function(){
var activeItem = popGallery.find(".active");
var activeIndex = activeItem.index();
var maxLen = items.length;
if(activeIndex == maxLen-1){
activeIndex = 0;
}else{
activeIndex++;
}
items.removeClass("active");
items.eq(activeIndex).addClass("active");
})
//var subsection = target.closest(".detail-gallery");
//subsection.addClass("expanded");
});
//LOCALIZE DATES
var dates = $(".local-date");
moment.locale($("body").attr("lang"));
dates.each(function(index, el){
var el = $(el);
var d = moment(el.attr("datetime"));
if(d.isValid){
el.html(d.format("LL"))
}
});
//SELECT REGION
$(".select-region").on("click", function(){
//console.log("CLICK");
modal.open(selectRegionTemplate);
//$(document).trigger("modal-open",["",[]]);
})
// INIT SUN_MOON
var sunMoonTimeout = setTimeout(function(){
if($("html").hasClass("no-appleios")){
//if($("body").hasClass("run-animations")){
// $("#sun-moon iframe").attr("src","/img/edge_full/niji_bg.html");
//}else{
$("#sun-moon iframe").attr("src","/static/niji_www/img/edge/niji_bg.html");
//}
}
},1000);
window.videoOpen = function(videoId){
modal.open(videoPopupTemplate({videoId:videoId}));
}
//INIT VIDEOS
//var links = $("a");
//links.each(function(index, link){
// link = $(link);
// var href = link.attr("href");
//
// var isVideoId = /^[a-zA-Z0-9]{32}$/.test(href);
// //console.log("href",href, isVideoId);
// if(isVideoId){
// link.addClass("video");
// link.on("click", function(evt){
// //modal.open(videoPopupTemplate({videoId:href}));
// videoOpen(href);
// return false;
// });
// }
//});
var links = $("a.video");
links.each(function(index, link){
link = $(link);
var videoId = link.attr("data-video-id");
link.on("click", function(evt){
videoOpen(videoId);
return false;
});
});
// NOW LEAVING
var nowLeavingTxt = $('
').append($('#now-leaving').clone()).html();
var nowLeavingPopupTemplate = Handlebars.compile(nowLeavingTxt);
//var nowLeavingData = JSON.parse(nowLeavingPopupTemplate);
$("a").each(function(index, el){
var a = $(el);
var regex = /^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/;
var url = a.attr("href");
//console.log("url",url)
if(url){
var matches = url.match(regex);
if(matches){
//console.log("matches",matches);
var protocal = String(matches[2]).toUpperCase();
var domain = matches[3];
if(protocal == "HTTP" | protocal== "HTTPS"){
//console.log("protocal",protocal, "domain",domain);
for(var i=0;i
");
var stars = [];
var starWrapper = $("
");
$("#body-wrapper").prepend(starWrapper);
for(var i=0;i<50;i++){
var sprite = starSpriteTempalate.clone();
sprite.css({
left: (Math.floor(Math.random() * 100) + 1) + "%",
top: (Math.floor(Math.random() * 100) + 1) + "%",
"animation-delay":(Math.floor(Math.random() * 15) + 1) + "s",
"animation-duration":(Math.floor(Math.random() * 4) + 10) + "s"
});
stars.push(sprite);
starWrapper.append(sprite);
sprite.addClass("playing");
//sprite.data("timer", setInterval(function(){
// console.log("SET INTERVAL", sprite)
//
//
// //sprite.timeout = setTimeout(function(){
// // sprite.removeClass("playing");
// //},4000);
//},1000));
}
});
});