diff --git a/public/src/forum/account/edit.js b/public/src/forum/account/edit.js deleted file mode 100644 index a99c6c448f..0000000000 --- a/public/src/forum/account/edit.js +++ /dev/null @@ -1,336 +0,0 @@ -'use strict'; - -/* globals define, ajaxify, socket, app, config, utils, translator, bootbox */ - -define('forum/account/edit', ['forum/account/header', 'uploader'], function(header, uploader) { - var AccountEdit = {}, - gravatarPicture = '', - uploadedPicture = '', - selectedImageType = '', - currentEmail; - - AccountEdit.init = function() { - gravatarPicture = ajaxify.variables.get('gravatarpicture'); - uploadedPicture = ajaxify.variables.get('uploadedpicture'); - - header.init(); - - $('#submitBtn').on('click', updateProfile); - - $('#inputBirthday').datepicker({ - changeMonth: true, - changeYear: true, - yearRange: '1900:+0' - }); - - currentEmail = $('#inputEmail').val(); - - handleImageChange(); - handleAccountDelete(); - handleImageUpload(); - handleEmailConfirm(); - handlePasswordChange(); - updateSignature(); - updateImages(); - }; - - function updateProfile() { - var userData = { - uid: $('#inputUID').val(), - username: $('#inputUsername').val(), - email: $('#inputEmail').val(), - fullname: $('#inputFullname').val(), - website: $('#inputWebsite').val(), - birthday: $('#inputBirthday').val(), - location: $('#inputLocation').val(), - signature: $('#inputSignature').val() - }; - - socket.emit('user.updateProfile', userData, function(err, data) { - if (err) { - return app.alertError(err.message); - } - - app.alertSuccess('[[user:profile_update_success]]'); - - if (data.picture) { - $('#user-current-picture').attr('src', data.picture); - $('#user_label img').attr('src', data.picture); - } - - if (data.gravatarpicture) { - $('#user-gravatar-picture').attr('src', data.gravatarpicture); - gravatarPicture = data.gravatarpicture; - } - - if (data.userslug) { - var oldslug = $('.account-username-box').attr('data-userslug'); - $('.account-username-box a').each(function(index) { - $(this).attr('href', $(this).attr('href').replace(oldslug, data.userslug)); - }); - - $('.account-username-box').attr('data-userslug', data.userslug); - - $('#user-profile-link').attr('href', config.relative_path + '/user/' + data.userslug); - $('#user-header-name').text(userData.username); - } - - if (currentEmail !== data.email) { - currentEmail = data.email; - $('#confirm-email').removeClass('hide'); - } - }); - - return false; - } - - function handleImageChange() { - function selectImageType(type) { - $('#gravatar-box .fa-check').toggle(type === 'gravatar'); - $('#uploaded-box .fa-check').toggle(type === 'uploaded'); - selectedImageType = type; - } - - $('#changePictureBtn').on('click', function() { - selectedImageType = ''; - updateImages(); - - $('#change-picture-modal').modal('show'); - $('#change-picture-modal').removeClass('hide'); - - return false; - }); - - $('#gravatar-box').on('click', function() { - selectImageType('gravatar'); - }); - - $('#uploaded-box').on('click', function() { - selectImageType('uploaded'); - }); - - $('#savePictureChangesBtn').on('click', function() { - $('#change-picture-modal').modal('hide'); - - if (selectedImageType) { - changeUserPicture(selectedImageType); - - if (selectedImageType === 'gravatar') { - $('#user-current-picture').attr('src', gravatarPicture); - $('#user-header-picture').attr('src', gravatarPicture); - } else if (selectedImageType === 'uploaded') { - $('#user-current-picture').attr('src', uploadedPicture); - $('#user-header-picture').attr('src', uploadedPicture); - } - } - }); - } - - function handleAccountDelete() { - $('#deleteAccountBtn').on('click', function() { - translator.translate('[[user:delete_account_confirm]]', function(translated) { - bootbox.confirm(translated + '

', function(confirm) { - if (!confirm) { - return; - } - - if ($('#confirm-username').val() !== app.username) { - app.alertError('[[error:invalid-username]]'); - return false; - } else { - socket.emit('user.deleteAccount', {}, function(err) { - if (!err) { - app.logout(); - } - }); - } - }); - }); - return false; - }); - } - - function handleImageUpload() { - function onUploadComplete(urlOnServer) { - urlOnServer = urlOnServer + '?' + new Date().getTime(); - - $('#user-current-picture').attr('src', urlOnServer); - $('#user-uploaded-picture').attr('src', urlOnServer); - $('#user-header-picture').attr('src', urlOnServer); - uploadedPicture = urlOnServer; - } - - - $('#upload-picture-modal').on('hide', function() { - $('#userPhotoInput').val(''); - }); - - $('#uploadPictureBtn').on('click', function() { - - $('#change-picture-modal').modal('hide'); - uploader.open(config.relative_path + '/api/user/' + ajaxify.variables.get('userslug') + '/uploadpicture', {}, config.maximumProfileImageSize, function(imageUrlOnServer) { - onUploadComplete(imageUrlOnServer); - }); - - return false; - }); - - $('#uploadFromUrlBtn').on('click', function() { - $('#change-picture-modal').modal('hide'); - var uploadModal = $('#upload-picture-from-url-modal'); - uploadModal.modal('show').removeClass('hide'); - - uploadModal.find('.upload-btn').on('click', function() { - var url = uploadModal.find('#uploadFromUrl').val(); - if (!url) { - return; - } - socket.emit('user.uploadProfileImageFromUrl', url, function(err, imageUrlOnServer) { - if (err) { - return app.alertError(err.message); - } - onUploadComplete(imageUrlOnServer); - - uploadModal.modal('hide'); - }); - - return false; - }); - return false; - }); - } - - function handleEmailConfirm() { - $('#confirm-email').on('click', function() { - socket.emit('user.emailConfirm', {}, function(err) { - if (err) { - return app.alertError(err.message); - } - app.alertSuccess('[[notifications:email-confirm-sent]]'); - }); - }); - } - - function handlePasswordChange() { - var currentPassword = $('#inputCurrentPassword'); - var password_notify = $('#password-notify'); - var password_confirm_notify = $('#password-confirm-notify'); - var password = $('#inputNewPassword'); - var password_confirm = $('#inputNewPasswordAgain'); - var passwordvalid = false; - var passwordsmatch = false; - var successIcon = ''; - - function onPasswordChanged() { - passwordvalid = utils.isPasswordValid(password.val()); - if (password.val().length < config.minimumPasswordLength) { - showError(password_notify, '[[user:change_password_error_length]]'); - } else if (!passwordvalid) { - showError(password_notify, '[[user:change_password_error]]'); - } else { - showSuccess(password_notify, successIcon); - } - } - - function onPasswordConfirmChanged() { - if(password.val()) { - if (password.val() !== password_confirm.val()) { - showError(password_confirm_notify, '[[user:change_password_error_match]]'); - passwordsmatch = false; - } else { - showSuccess(password_confirm_notify, successIcon); - passwordsmatch = true; - } - } - } - - password.on('blur', onPasswordChanged); - password_confirm.on('blur', onPasswordConfirmChanged); - - $('#changePasswordBtn').on('click', function() { - if ((passwordvalid && passwordsmatch) || app.isAdmin) { - socket.emit('user.changePassword', { - 'currentPassword': currentPassword.val(), - 'newPassword': password.val(), - 'uid': ajaxify.variables.get('theirid') - }, function(err) { - currentPassword.val(''); - password.val(''); - password_confirm.val(''); - passwordsmatch = false; - passwordvalid = false; - - if (err) { - return app.alertError(err.message); - } - - app.alertSuccess('[[user:change_password_success]]'); - }); - } - return false; - }); - } - - function changeUserPicture(type) { - socket.emit('user.changePicture', { - type: type, - uid: ajaxify.variables.get('theirid') - }, function(err) { - if(err) { - app.alertError(err.message); - } - }); - } - - function updateImages() { - var currentPicture = $('#user-current-picture').attr('src'); - - if (gravatarPicture) { - $('#user-gravatar-picture').attr('src', gravatarPicture); - } - - if (uploadedPicture) { - $('#user-uploaded-picture').attr('src', uploadedPicture); - } - - $('#gravatar-box').toggle(!!gravatarPicture); - $('#uploaded-box').toggle(!!uploadedPicture); - - $('#gravatar-box .fa-check').toggle(currentPicture !== uploadedPicture); - $('#uploaded-box .fa-check').toggle(currentPicture === uploadedPicture); - } - - function updateSignature() { - function getSignatureCharsLeft() { - return $('#inputSignature').length ? '(' + $('#inputSignature').val().length + '/' + config.maximumSignatureLength + ')' : ''; - } - - $('#signatureCharCountLeft').html(getSignatureCharsLeft()); - - $('#inputSignature').on('keyup change', function(ev) { - $('#signatureCharCountLeft').html(getSignatureCharsLeft()); - }); - } - - function showError(element, msg) { - translator.translate(msg, function(msg) { - element.html(msg); - element.parent() - .removeClass('alert-success') - .addClass('alert-danger'); - element.show(); - }); - } - - function showSuccess(element, msg) { - translator.translate(msg, function(msg) { - element.html(msg); - element.parent() - .removeClass('alert-danger') - .addClass('alert-success'); - element.show(); - }); - } - - return AccountEdit; -}); diff --git a/public/src/forum/account/favourites.js b/public/src/forum/account/favourites.js deleted file mode 100644 index 6a08a814a5..0000000000 --- a/public/src/forum/account/favourites.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -/* globals define, app, utils */ - -define('forum/account/favourites', ['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) { - var Favourites = {}; - - Favourites.init = function() { - header.init(); - - $('.user-favourite-posts img').addClass('img-responsive'); - - infinitescroll.init(loadMore); - }; - - function loadMore(direction) { - if (direction < 0) { - return; - } - - infinitescroll.loadMore('posts.loadMoreFavourites', { - after: $('.user-favourite-posts').attr('data-nextstart') - }, function(data, done) { - if (data.posts && data.posts.length) { - onPostsLoaded(data.posts, done); - $('.user-favourite-posts').attr('data-nextstart', data.nextStart); - } else { - done(); - } - }); - } - - function onPostsLoaded(posts, callback) { - infinitescroll.parseAndTranslate('account/favourites', 'posts', {posts: posts}, function(html) { - $('.user-favourite-posts').append(html); - html.find('img').addClass('img-responsive'); - html.find('span.timeago').timeago(); - app.createUserTooltips(); - utils.makeNumbersHumanReadable(html.find('.human-readable-number')); - callback(); - }); - } - - return Favourites; -}); diff --git a/public/src/forum/account/followers.js b/public/src/forum/account/followers.js deleted file mode 100644 index 6dfb3bf83c..0000000000 --- a/public/src/forum/account/followers.js +++ /dev/null @@ -1,19 +0,0 @@ -define('forum/account/followers', ['forum/account/header'], function(header) { - var Followers = {}; - - Followers.init = function() { - header.init(); - - var yourid = ajaxify.variables.get('yourid'), - theirid = ajaxify.variables.get('theirid'), - followersCount = ajaxify.variables.get('followersCount'); - - - if (parseInt(followersCount, 10) === 0) { - $('#no-followers-notice').removeClass('hide'); - } - - }; - - return Followers; -}); diff --git a/public/src/forum/account/following.js b/public/src/forum/account/following.js deleted file mode 100644 index 0e27a235aa..0000000000 --- a/public/src/forum/account/following.js +++ /dev/null @@ -1,15 +0,0 @@ -define('forum/account/following', ['forum/account/header'], function(header) { - var Following = {}; - - Following.init = function() { - header.init(); - - var followingCount = ajaxify.variables.get('followingCount'); - - if (parseInt(followingCount, 10) === 0) { - $('#no-following-notice').removeClass('hide'); - } - }; - - return Following; -}); diff --git a/public/src/forum/account/header.js b/public/src/forum/account/header.js deleted file mode 100644 index f552bf4056..0000000000 --- a/public/src/forum/account/header.js +++ /dev/null @@ -1,34 +0,0 @@ -define('forum/account/header', function() { - var AccountHeader = {}; - - AccountHeader.init = function() { - displayAccountMenus(); - selectActivePill(); - }; - - function displayAccountMenus() { - var yourid = ajaxify.variables.get('yourid'), - theirid = ajaxify.variables.get('theirid'); - - if (parseInt(yourid, 10) !== 0 && parseInt(yourid, 10) === parseInt(theirid, 10)) { - $('#editLink, #settingsLink, #favouritesLink').removeClass('hide'); - } else { - $('.account-sub-links .plugin-link').each(function() { - var $this = $(this); - $this.toggleClass('hide', $this.hasClass('private')); - }); - } - } - - function selectActivePill() { - $('.account-sub-links li').removeClass('active').each(function() { - var href = $(this).find('a').attr('href'); - if (window.location.href.indexOf(href) !== -1) { - $(this).addClass('active'); - return false; - } - }); - } - - return AccountHeader; -}); diff --git a/public/src/forum/account/posts.js b/public/src/forum/account/posts.js deleted file mode 100644 index 70410e0819..0000000000 --- a/public/src/forum/account/posts.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -/* globals define, app, socket, utils */ - -define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) { - var AccountPosts = {}; - - AccountPosts.init = function() { - header.init(); - - $('.user-favourite-posts img').addClass('img-responsive'); - - infinitescroll.init(loadMore); - }; - - function loadMore(direction) { - if (direction < 0) { - return; - } - - infinitescroll.loadMore('posts.loadMoreUserPosts', { - uid: $('.account-username-box').attr('data-uid'), - after: $('.user-favourite-posts').attr('data-nextstart') - }, function(data, done) { - if (data.posts && data.posts.length) { - onPostsLoaded(data.posts, done); - $('.user-favourite-posts').attr('data-nextstart', data.nextStart); - } else { - done(); - } - }); - } - - function onPostsLoaded(posts, callback) { - infinitescroll.parseAndTranslate('account/posts', 'posts', {posts: posts}, function(html) { - $('.user-favourite-posts').append(html); - html.find('img').addClass('img-responsive'); - html.find('span.timeago').timeago(); - app.createUserTooltips(); - utils.makeNumbersHumanReadable(html.find('.human-readable-number')); - callback(); - }); - } - - return AccountPosts; -}); diff --git a/public/src/forum/account/profile.js b/public/src/forum/account/profile.js deleted file mode 100644 index 2d273a33ca..0000000000 --- a/public/src/forum/account/profile.js +++ /dev/null @@ -1,127 +0,0 @@ -'use strict'; - -/* globals define, ajaxify, app, utils, socket, translator*/ - -define('forum/account/profile', ['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) { - var Account = {}, - yourid, - theirid, - isFollowing; - - Account.init = function() { - header.init(); - - yourid = ajaxify.variables.get('yourid'); - theirid = ajaxify.variables.get('theirid'); - isFollowing = ajaxify.variables.get('isFollowing'); - - app.enterRoom('user/' + theirid); - - processPage(); - - updateButtons(); - - $('#follow-btn').on('click', function() { - return toggleFollow('follow'); - }); - - $('#unfollow-btn').on('click', function() { - return toggleFollow('unfollow'); - }); - - $('#chat-btn').on('click', function() { - app.openChat($('.account-username').html(), theirid); - }); - - socket.removeListener('event:user_status_change', onUserStatusChange); - socket.on('event:user_status_change', onUserStatusChange); - - if (yourid !== theirid) { - socket.emit('user.increaseViewCount', theirid); - } - - infinitescroll.init(loadMoreTopics); - }; - - function processPage() { - $('.user-recent-posts img, .post-signature img').addClass('img-responsive'); - } - - function updateButtons() { - var isSelfOrNotLoggedIn = yourid === theirid || parseInt(yourid, 10) === 0; - $('#follow-btn').toggleClass('hide', isFollowing || isSelfOrNotLoggedIn); - $('#unfollow-btn').toggleClass('hide', !isFollowing || isSelfOrNotLoggedIn); - $('#chat-btn').toggleClass('hide', isSelfOrNotLoggedIn); - } - - function toggleFollow(type) { - socket.emit('user.' + type, { - uid: theirid - }, function(err) { - if(err) { - return app.alertError(err.message); - } - - $('#follow-btn').toggleClass('hide', type === 'follow'); - $('#unfollow-btn').toggleClass('hide', type === 'unfollow'); - app.alertSuccess('[[global:alert.' + type + ', ' + $('.account-username').html() + ']]'); - }); - return false; - } - - function onUserStatusChange(data) { - var onlineStatus = $('.account-online-status'); - - if(parseInt(ajaxify.variables.get('theirid'), 10) !== parseInt(data.uid, 10)) { - return; - } - - translator.translate('[[global:' + data.status + ']]', function(translated) { - onlineStatus.attr('class', 'account-online-status fa fa-circle status ' + data.status) - .attr('title', translated) - .attr('data-original-title', translated); - }); - - } - - function loadMoreTopics(direction) { - if(direction < 0 || !$('.user-recent-posts').length) { - return; - } - - $('.loading-indicator').removeClass('hidden'); - - infinitescroll.loadMore('user.loadMoreRecentPosts', { - after: $('.user-recent-posts').attr('data-nextstart'), - uid: theirid - }, function(data, done) { - if (data.posts && data.posts.length) { - onPostsLoaded(data.posts, done); - $('.user-recent-posts').attr('data-nextstart', data.nextStart); - } else { - done(); - } - $('.loading-indicator').addClass('hidden'); - }); - } - - function onPostsLoaded(posts, callback) { - posts = posts.filter(function(post) { - return !$('.user-recent-posts div[data-pid=' + post.pid + ']').length; - }); - - if (!posts.length) { - return callback(); - } - - infinitescroll.parseAndTranslate('account/profile', 'posts', {posts: posts}, function(html) { - - $('.user-recent-posts .loading-indicator').before(html); - html.find('span.timeago').timeago(); - - callback(); - }); - } - - return Account; -}); diff --git a/public/src/forum/account/settings.js b/public/src/forum/account/settings.js deleted file mode 100644 index 107e766c77..0000000000 --- a/public/src/forum/account/settings.js +++ /dev/null @@ -1,71 +0,0 @@ -define('forum/account/settings', ['forum/account/header'], function(header) { - var AccountSettings = {}; - - AccountSettings.init = function() { - header.init(); - - $('#submitBtn').on('click', function() { - var settings = {}; - - $('.account').find('input, textarea, select').each(function(id, input) { - input = $(input); - var setting = input.attr('data-property'); - if (input.is('select')) { - settings[setting] = input.val(); - return; - } - - switch (input.attr('type')) { - case 'text': - case 'textarea': - settings[setting] = input.val(); - break; - case 'checkbox': - settings[setting] = input.is(':checked') ? 1 : 0; - break; - } - }); - - socket.emit('user.saveSettings', {uid: ajaxify.variables.get('theirid'), settings: settings}, function(err) { - if (err) { - return app.alertError(err.message); - } - - app.alertSuccess('[[success:settings-saved]]'); - app.loadConfig(); - if (parseInt(app.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) { - ajaxify.refresh(); - } - }); - - return false; - }); - - socket.emit('user.getSettings', {uid: ajaxify.variables.get('theirid')}, function(err, settings) { - var inputs = $('.account').find('input, textarea, select'); - - inputs.each(function(index, input) { - input = $(input); - var setting = input.attr('data-property'); - if (setting) { - if (input.is('select')) { - input.val(settings[setting]); - return; - } - - switch (input.attr('type')) { - case 'text' : - case 'textarea' : - input.val(settings[setting]); - break; - case 'checkbox' : - input.prop('checked', !!settings[setting]); - break; - } - } - }); - }); - }; - - return AccountSettings; -}); diff --git a/public/src/forum/account/topics.js b/public/src/forum/account/topics.js deleted file mode 100644 index 231ddfd5ec..0000000000 --- a/public/src/forum/account/topics.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -/* globals define, app, socket, utils */ - -define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) { - var AccountTopics = {}; - - AccountTopics.init = function() { - header.init(); - - infinitescroll.init(loadMore); - }; - - function loadMore(direction) { - if (direction < 0) { - return; - } - - infinitescroll.loadMore('topics.loadMoreFromSet', { - set: 'uid:' + $('.account-username-box').attr('data-uid') + ':topics', - after: $('.user-topics').attr('data-nextstart') - }, function(data, done) { - - if (data.topics && data.topics.length) { - onTopicsLoaded(data.topics, done); - $('.user-topics').attr('data-nextstart', data.nextStart); - } else { - done(); - } - }); - } - - function onTopicsLoaded(topics, callback) { - infinitescroll.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) { - $('#topics-container').append(html); - html.find('span.timeago').timeago(); - app.createUserTooltips(); - utils.makeNumbersHumanReadable(html.find('.human-readable-number')); - callback(); - }); - } - - return AccountTopics; -}); diff --git a/public/src/forum/admin/appearance/customise.js b/public/src/forum/admin/appearance/customise.js deleted file mode 100644 index 482dd7fb6d..0000000000 --- a/public/src/forum/admin/appearance/customise.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; -/* global define, app, socket */ - -define('forum/admin/appearance/customise', ['forum/admin/settings'], function(Settings) { - var Customise = {}; - - Customise.init = function() { - Settings.prepare(function() { - $('#customCSS').text($('#customCSS-holder').val()); - $('#customHTML').text($('#customHTML-holder').val()); - - var customCSS = ace.edit("customCSS"), - customHTML = ace.edit("customHTML"); - - customCSS.setTheme("ace/theme/twilight"); - customCSS.getSession().setMode("ace/mode/css"); - - customCSS.on('change', function(e) { - $('#customCSS-holder').val(customCSS.getValue()); - }); - - customHTML.setTheme("ace/theme/twilight"); - customHTML.getSession().setMode("ace/mode/html"); - - customHTML.on('change', function(e) { - $('#customHTML-holder').val(customHTML.getValue()); - }); - }); - }; - - return Customise; -}); - \ No newline at end of file diff --git a/public/src/forum/admin/appearance/skins.js b/public/src/forum/admin/appearance/skins.js deleted file mode 100644 index 75a57e60e5..0000000000 --- a/public/src/forum/admin/appearance/skins.js +++ /dev/null @@ -1,73 +0,0 @@ -"use strict"; -/* global define, app, socket */ - -define('forum/admin/appearance/skins', function() { - var Skins = {}; - - Skins.init = function() { - var scriptEl = $('