Updated
This commit is contained in:
114
imports/ui/NewsAndPhotos.js
Normal file
114
imports/ui/NewsAndPhotos.js
Normal file
@@ -0,0 +1,114 @@
|
||||
|
||||
import './NewsAndPhotos.html';
|
||||
|
||||
let PREFIX = "PhotoGallery_";
|
||||
|
||||
Tracker.autorun(function() {
|
||||
Meteor.subscribe("pages");
|
||||
Meteor.subscribe("slideshow");
|
||||
});
|
||||
|
||||
Template.NewsAndPhotos.onCreated(function() {
|
||||
let template = this;
|
||||
this.slideshows = Meteor.collections.Slideshow.find({}, {sort: {name: 1}});
|
||||
});
|
||||
Template.NewsAndPhotos.events({
|
||||
'click .galleryLink': function(event, template) {
|
||||
let slideshowId = $(event.target).data("slideshow-id");
|
||||
let slideshow = slideshowId ? Meteor.collections.Slideshow.findOne(slideshowId) : undefined;
|
||||
|
||||
Session.set(PREFIX + 'selectedSlideshow', slideshow);
|
||||
}
|
||||
});
|
||||
|
||||
Template.NewsAndPhotos.helpers({
|
||||
editableHTML: function() {
|
||||
let doc = Meteor.collections.Pages.findOne({name: "Slideshow"});
|
||||
|
||||
return doc === undefined ? "" : doc.html;
|
||||
},
|
||||
slideshows: function() {
|
||||
return Template.instance().slideshows;
|
||||
},
|
||||
slideshow: function() {
|
||||
return Session.get(PREFIX + "selectedSlideshow");
|
||||
},
|
||||
newsHTML: function() { //Moved this from the News & Notices page when we replaced that page.
|
||||
let doc = Meteor.collections.Pages.findOne({name: 'News'});
|
||||
|
||||
return doc === undefined ? "" : doc.html;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Template.Slideshow.onRendered(function() {
|
||||
let template = this;
|
||||
|
||||
this.slideTimer = Meteor.setInterval(function() {
|
||||
let current = template.$('.slide.showSlide');
|
||||
|
||||
if(current) {
|
||||
let next = current.next();
|
||||
|
||||
if(next.length === 0) {
|
||||
next = template.$('.slide:first');
|
||||
}
|
||||
|
||||
current.removeClass('showSlide');
|
||||
next.addClass('showSlide');
|
||||
}
|
||||
else {
|
||||
let first = template.$('.slide:first');
|
||||
|
||||
if(first) first.addClass('showSlide');
|
||||
}
|
||||
}, 6000);
|
||||
});
|
||||
Template.Slideshow.onDestroyed(function() {
|
||||
if(this.slideTimer) Meteor.clearTimeout(this.slideTimer);
|
||||
});
|
||||
Template.Slideshow.helpers({
|
||||
slides: function() {
|
||||
return Session.get(PREFIX + "selectedSlideshow").images;
|
||||
}
|
||||
});
|
||||
Template.Slideshow.events({
|
||||
"click .next": function(event, template) {
|
||||
let current = template.$('.slide.showSlide');
|
||||
|
||||
if(current) {
|
||||
let next = current.next();
|
||||
|
||||
if(next.length === 0) {
|
||||
next = template.$('.slide:first');
|
||||
}
|
||||
|
||||
current.removeClass('showSlide');
|
||||
next.addClass('showSlide');
|
||||
}
|
||||
else {
|
||||
let first = template.$('.slide:first');
|
||||
|
||||
if(first) first.addClass('showSlide');
|
||||
}
|
||||
},
|
||||
"click .previous": function(event, template) {
|
||||
let current = template.$('.slide.showSlide');
|
||||
|
||||
if(current) {
|
||||
let previous = current.prev();
|
||||
|
||||
if(previous.length === 0) {
|
||||
previous = template.$('.slide:last');
|
||||
}
|
||||
|
||||
current.removeClass('showSlide');
|
||||
previous.addClass('showSlide');
|
||||
}
|
||||
else {
|
||||
let last = template.$('.slide:last');
|
||||
|
||||
if(last) last.addClass('showSlide');
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user