Remove old js components

This commit is contained in:
Daniel Supernault 2019-07-26 21:23:52 -06:00
parent afddd0bcb3
commit daf8b00c80
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
5 changed files with 0 additions and 377 deletions

View File

@ -1,8 +0,0 @@
$(document).ready(function() {
$(document).on('submit', '.bookmark-form', function(e) {
e.preventDefault();
var el = $(this);
var id = el.data('id');
var res = axios.post('/i/bookmark', {item: id});
});
});

View File

@ -1,51 +0,0 @@
$(document).ready(function() {
$('.status-card > .card-footer').each(function() {
$(this).addClass('d-none');
});
$(document).on('click', '.status-comment-focus', function(el) {
var form = $(this).parents().eq(2).find('.card-footer');
form.removeClass('d-none');
var el = $(this).parents().eq(2).find('input[name="comment"]');
el.focus();
});
$(document).on('submit', '.comment-form', function(e, data) {
e.preventDefault();
let el = $(this);
let id = el.data('id');
let commentform = el.find('input[name="comment"]');
let commenttext = commentform.val();
let item = {item: id, comment: commenttext};
commentform.prop('disabled', true);
axios.post('/i/comment', item)
.then(function (res) {
var username = res.data.username;
var permalink = res.data.url;
var profile = res.data.profile;
var reply = res.data.comment;
if($('.status-container').length == 1) {
var comments = el.parents().eq(3).find('.comments');
} else {
var comments = el.parents().eq(1).find('.comments');
}
var comment = '<p class="mb-0"><span class="font-weight-bold pr-1"><bdi><a class="text-dark" href="' + profile + '">' + username + '</a></bdi></span><span class="comment-text">'+ reply + '</span></p>';
comments.prepend(comment);
commentform.val('');
commentform.blur();
commentform.prop('disabled', false);
})
.catch(function (res) {
});
});
});

View File

@ -1,33 +0,0 @@
window.ls = {};
window.ls.get = function(key) {
return JSON.parse(localStorage.getItem(key));
}
window.ls.set = function(key, val) {
try {
localStorage.setItem(key, JSON.stringify(val));
return true;
} catch(e) {
return false;
}
}
window.ls.del = function(key) {
try {
localStorage.removeItem(key);
return true;
} catch(e) {
return false;
}
}
window.ls.clear = function() {
try {
localStorage.clear();
return true;
} catch(e) {
return false;
}
}

View File

@ -1,159 +0,0 @@
$(document).ready(function() {
$('.nav-link.nav-notification').on('click', function(e) {
e.preventDefault();
let el = $(this);
if(el.attr('data-toggle') == 'tooltip') {
el.attr('data-toggle', 'dropdown');
el.tooltip('dispose');
}
let container = $('.navbar .nav-notification-dropdown');
if(pixelfed.notifications) {
return;
}
axios.get('/api/v2/notifications')
.then((res) => {
$('.nav-notification-dropdown .loader').hide();
let data = res.data;
data.forEach(function(v, k) {
let action = v.action;
let notification = $('<li>').addClass('dropdown-item py-3')
if(v.read_at == null) {
notification.attr('style', 'border: 1px solid #6cb2eb;background-color: #eff8ff;border-bottom:none;');
} else {
notification.attr('style', 'border-bottom: 1px solid #ccc;');
}
switch(action) {
case 'comment':
let avatar = $('<span>')
.attr('class', 'notification-icon pr-3');
let avatarImg = $('<img>')
.attr('width', '32px')
.attr('height', '32px')
.attr('class', 'rounded-circle')
.attr('style', 'border: 1px solid #ccc')
.attr('src', v.actor.avatar);
avatar = avatar.append(avatarImg);
let text = $('<span>')
.attr('href', v.url)
.attr('class', 'font-weight-bold')
.html(v.rendered);
notification.append(avatar);
notification.append(text);
container.append(notification);
break;
case 'follow':
avatar = $('<span>')
.attr('class', 'notification-icon pr-3');
avatarImg = $('<img>')
.attr('width', '32px')
.attr('height', '32px')
.attr('class', 'rounded-circle')
.attr('style', 'border: 1px solid #ccc')
.attr('src', v.actor.avatar);
avatar = avatar.append(avatarImg);
text = $('<span>')
.attr('href', v.url)
.attr('class', 'font-weight-bold')
.html(v.rendered);
notification.append(avatar);
notification.append(text);
container.append(notification);
break;
}
});
let all = $('<a>')
.attr('class', 'dropdown-item py-3 text-center text-primary font-weight-bold')
.attr('href', '/account/activity')
.attr('style', 'border-top:1px solid #ccc')
.text('View all notifications');
container.append(all);
pixelfed.notifications = true;
}).catch((err) => {
$('.nav-notification-dropdown .loader').addClass('font-weight-bold').text('Something went wrong. Please try again later.');
});
});
$('.notification-action[data-type="mark_read"]').on('click', function(e) {
e.preventDefault();
axios.post('/api/v2/notifications', {
'action': 'mark_read'
}).then(res => {
pixelfed.notifications = false;
ls.del('n.lastCheck');
ls.del('n.count');
swal(
'Success!',
'All of your notifications have been marked as read.',
'success'
);
}).catch(err => {
swal(
'Something went wrong!',
'An error occurred, please try again later.',
'error'
);
});
});
pixelfed.n.showCount = (count = 1) => {
let el = $('.nav-link.nav-notification');
el.tooltip('dispose');
el.attr('title', count)
el.attr('data-toggle', 'tooltip');
el.tooltip({
template: '<div class="tooltip notification-tooltip" role="tooltip"><div class="arrow"></div><div class="tooltip-inner bg-danger px-3"></div></div>'
});
setTimeout(function() {
el.fadeIn(function() {
el.tooltip('show')
});
}, 500);
}
pixelfed.n.sound = () => {
let beep = new Audio('/static/beep.mp3');
beep.play();
}
pixelfed.n.check = (count) => {
// pixelfed.n.sound();
pixelfed.n.showCount(count);
}
pixelfed.n.fetch = (force = false) => {
let now = Date.now();
let ts = ls.get('n.lastCheck');
let count = ls.get('n.count');
let offset = now - 9e5;
if(ts == null) {
ts = now;
}
if(!force && count != null || ts > offset) {
//pixelfed.n.showCount(count);
ls.set('n.lastCheck', ts);
return;
}
axios.get('/api/v2/notifications')
.then(res => {
let len = res.data.length;
if(len > 0) {
ls.set('n.count', len);
ls.set('n.lastCheck', Date.now());
pixelfed.n.check(len);
}
}).catch(err => {
})
}
});

View File

@ -1,126 +0,0 @@
$(document).ready(function() {
pixelfed.create = {};
pixelfed.filters = {};
pixelfed.create.hasGeneratedSelect = false;
pixelfed.create.selectedFilter = false;
pixelfed.create.currentFilterName = false;
pixelfed.create.currentFilterClass = false;
pixelfed.filters.list = [
['1977','filter-1977'],
['Aden','filter-aden'],
['Amaro','filter-amaro'],
['Ashby','filter-ashby'],
['Brannan','filter-brannan'],
['Brooklyn','filter-brooklyn'],
['Charmes','filter-charmes'],
['Clarendon','filter-clarendon'],
['Crema','filter-crema'],
['Dogpatch','filter-dogpatch'],
['Earlybird','filter-earlybird'],
['Gingham','filter-gingham'],
['Ginza','filter-ginza'],
['Hefe','filter-hefe'],
['Helena','filter-helena'],
['Hudson','filter-hudson'],
['Inkwell','filter-inkwell'],
['Kelvin','filter-kelvin'],
['Kuno','filter-juno'],
['Lark','filter-lark'],
['Lo-Fi','filter-lofi'],
['Ludwig','filter-ludwig'],
['Maven','filter-maven'],
['Mayfair','filter-mayfair'],
['Moon','filter-moon'],
['Nashville','filter-nashville'],
['Perpetua','filter-perpetua'],
['Poprocket','filter-poprocket'],
['Reyes','filter-reyes'],
['Rise','filter-rise'],
['Sierra','filter-sierra'],
['Skyline','filter-skyline'],
['Slumber','filter-slumber'],
['Stinson','filter-stinson'],
['Sutro','filter-sutro'],
['Toaster','filter-toaster'],
['Valencia','filter-valencia'],
['Vesper','filter-vesper'],
['Walden','filter-walden'],
['Willow','filter-willow'],
['X-Pro II','filter-xpro-ii']
];
function previewImage(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('.filterPreview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
function generateFilterSelect() {
let filters = pixelfed.filters.list;
for(var i = 0, len = filters.length; i < len; i++) {
let filter = filters[i];
let name = filter[0];
let className = filter[1];
let select = $('#filterSelectDropdown');
var template = '<option value="' + className + '">' + name + '</option>';
select.append(template);
}
pixelfed.create.hasGeneratedSelect = true;
}
$(document).on('change', '#fileInput', function() {
previewImage(this);
$('#statusForm .form-filters.d-none').removeClass('d-none');
$('#statusForm .form-preview.d-none').removeClass('d-none');
$('#statusForm #collapsePreview').collapse('show');
if(!pixelfed.create.hasGeneratedSelect) {
generateFilterSelect();
}
});
$(document).on('change', '#filterSelectDropdown', function() {
let el = $(this);
let filter = el.val();
let oldFilter = pixelfed.create.currentFilterClass;
if(filter == 'none') {
$('input[name=filter_class]').val('');
$('input[name=filter_name]').val('');
$('.filterContainer').removeClass(oldFilter);
pixelfed.create.currentFilterClass = false;
pixelfed.create.currentFilterName = 'None';
$('.form-group.form-preview .form-text').text('Current Filter: No filter selected');
return;
} else {
$('.filterContainer').removeClass(oldFilter).addClass(filter);
pixelfed.create.currentFilterClass = filter;
pixelfed.create.currentFilterName = el.find(':selected').text();
$('.form-group.form-preview .form-text').text('Current Filter: ' + pixelfed.create.currentFilterName);
$('input[name=filter_class]').val(pixelfed.create.currentFilterClass);
$('input[name=filter_name]').val(pixelfed.create.currentFilterName);
return;
}
});
$(document).on('keyup keydown', '#statusForm textarea[name=caption]', function() {
const el = $(this);
const len = el.val().length;
const limit = el.data('limit');
if(len > limit) {
const diff = limit - len;
$('#statusForm .caption-counter').text(diff).addClass('text-danger');
} else {
$('#statusForm .caption-counter').text(len).removeClass('text-danger');
}
});
$(document).on('focus', '#statusForm textarea[name=caption]', function() {
const el = $(this);
el.attr('rows', '3');
});
});