2014-08-29 10:37:35 +09:00
|
|
|
var confirmSubscription = function () {
|
|
|
|
$('.newsletter-banner form').css('opacity', 0);
|
|
|
|
$('.newsletter-banner .newsletter-subscribed').css('display', 'block').css('opacity', 1);
|
|
|
|
Meteor.setInterval(function () {
|
|
|
|
// required because otherwise banner disappears immediately after confirmation
|
|
|
|
dismissBanner();
|
|
|
|
}, 2000)
|
|
|
|
}
|
|
|
|
|
|
|
|
var dismissBanner = function () {
|
|
|
|
$('.newsletter-banner').fadeOut('fast', function () {
|
|
|
|
if(Meteor.user()){
|
|
|
|
// if user is connected, change setting in their account
|
|
|
|
setUserSetting('showBanner', false);
|
|
|
|
}else{
|
|
|
|
// set cookie
|
2015-01-07 08:22:46 +01:00
|
|
|
Cookie.set('showBanner', "no");
|
2014-08-29 10:37:35 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-08 11:49:34 +09:00
|
|
|
Meteor.startup(function () {
|
|
|
|
Template[getTemplate('newsletterBanner')].helpers({
|
|
|
|
siteName: function () {
|
2015-03-28 18:30:26 +09:00
|
|
|
return Settings.get('title');
|
2014-10-08 11:49:34 +09:00
|
|
|
},
|
|
|
|
isNotConnected: function () {
|
|
|
|
return !Meteor.user()
|
|
|
|
},
|
|
|
|
showBanner: function () {
|
|
|
|
// note: should not be reactive
|
|
|
|
if(
|
2015-03-28 18:30:26 +09:00
|
|
|
Settings.get('showBanner', false) == false
|
2015-01-07 08:22:46 +01:00
|
|
|
|| !can.view(Meteor.user())
|
|
|
|
|| Router.current().location.get().path != '/'
|
|
|
|
|| Cookie.get('showBanner') == "no"
|
|
|
|
|| (Meteor.user() && getUserSetting('showBanner', true) == false)
|
|
|
|
|| (Meteor.user() && getUserSetting('subscribedToNewsletter', false) == true)
|
2014-10-08 11:49:34 +09:00
|
|
|
){
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-29 10:37:35 +09:00
|
|
|
}
|
2014-10-08 11:49:34 +09:00
|
|
|
});
|
2014-08-29 10:37:35 +09:00
|
|
|
|
2014-10-08 11:49:34 +09:00
|
|
|
Template[getTemplate('newsletterBanner')].events({
|
|
|
|
'click .newsletter-button': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var $banner = $('.newsletter-banner');
|
|
|
|
if(Meteor.user()){
|
|
|
|
$banner.addClass('show-loader');
|
|
|
|
Meteor.call('addCurrentUserToMailChimpList', function (error, result) {
|
|
|
|
$banner.removeClass('show-loader');
|
|
|
|
if(error){
|
|
|
|
console.log(error);
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(error.message, "error");
|
2014-10-08 11:49:34 +09:00
|
|
|
}else{
|
|
|
|
console.log(result);
|
|
|
|
confirmSubscription();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
var email = $('.newsletter-email').val();
|
|
|
|
if(!email){
|
|
|
|
alert('Please fill in your email.');
|
|
|
|
return
|
2014-08-29 10:37:35 +09:00
|
|
|
}
|
2014-10-08 11:49:34 +09:00
|
|
|
$banner.addClass('show-loader');
|
|
|
|
Meteor.call('addEmailToMailChimpList', email, function (error, result) {
|
|
|
|
$banner.removeClass('show-loader');
|
|
|
|
if(error){
|
|
|
|
console.log(error);
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(error.reason, "error");
|
2014-10-08 11:49:34 +09:00
|
|
|
}else{
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.clearSeen();
|
2014-10-08 11:49:34 +09:00
|
|
|
console.log(result);
|
|
|
|
confirmSubscription();
|
|
|
|
}
|
|
|
|
});
|
2014-08-29 10:37:35 +09:00
|
|
|
}
|
2014-10-08 11:49:34 +09:00
|
|
|
// $('body').addClass('showing-lightbox');
|
|
|
|
// $(e.target).parents('.post').find('.post-video-lightbox').fadeIn('fast');
|
|
|
|
},
|
|
|
|
'click .newsletter-dismiss': function (e) {
|
|
|
|
$('.newsletter-banner').fadeOut('fast');
|
|
|
|
dismissBanner();
|
|
|
|
e.preventDefault();
|
2015-01-07 08:22:46 +01:00
|
|
|
}
|
2014-10-08 11:49:34 +09:00
|
|
|
});
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
});
|