From 22a3794c51088ccfa889be0a3ff90be211ababbd Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 21 Nov 2013 16:47:32 -0500 Subject: [PATCH 1/3] closes #525 --- public/src/modules/composer.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index dae501565d..54402ef55a 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -210,13 +210,17 @@ define(['taskbar'], function(taskbar) { selectionEnd = postContentEl.selectionEnd, selectionLength = selectionEnd - selectionStart; + function insertIntoInput(element, value) { + var start = postContentEl.selectionStart; + element.value = element.value.slice(0, start) + value + element.value.slice(start, element.value.length); + postContentEl.selectionStart = postContentEl.selectionEnd = start + value.length; + } + switch(iconClass) { case 'icon-bold': if (selectionStart === selectionEnd) { // Nothing selected - postContentEl.value = postContentEl.value + '**bolded text**'; - postContentEl.selectionStart = cursorEnd+2; - postContentEl.selectionEnd = postContentEl.value.length - 2; + insertIntoInput(postContentEl, "**bolded text**"); } else { // Text selected postContentEl.value = postContentEl.value.slice(0, selectionStart) + '**' + postContentEl.value.slice(selectionStart, selectionEnd) + '**' + postContentEl.value.slice(selectionEnd); @@ -227,9 +231,7 @@ define(['taskbar'], function(taskbar) { case 'icon-italic': if (selectionStart === selectionEnd) { // Nothing selected - postContentEl.value = postContentEl.value + '*italicised text*'; - postContentEl.selectionStart = cursorEnd+1; - postContentEl.selectionEnd = postContentEl.value.length - 1; + insertIntoInput(postContentEl, "*italicised text*"); } else { // Text selected postContentEl.value = postContentEl.value.slice(0, selectionStart) + '*' + postContentEl.value.slice(selectionStart, selectionEnd) + '*' + postContentEl.value.slice(selectionEnd); @@ -239,16 +241,12 @@ define(['taskbar'], function(taskbar) { break; case 'icon-list': // Nothing selected - postContentEl.value = postContentEl.value + "\n\n* list item"; - postContentEl.selectionStart = cursorEnd+4; - postContentEl.selectionEnd = postContentEl.value.length; + insertIntoInput(postContentEl, "\n\n* list item"); break; case 'icon-link': if (selectionStart === selectionEnd) { // Nothing selected - postContentEl.value = postContentEl.value + '[link text](link url)'; - postContentEl.selectionStart = cursorEnd+12; - postContentEl.selectionEnd = postContentEl.value.length - 1; + insertIntoInput(postContentEl, "[link text](link url)"); } else { // Text selected postContentEl.value = postContentEl.value.slice(0, selectionStart) + '[' + postContentEl.value.slice(selectionStart, selectionEnd) + '](link url)' + postContentEl.value.slice(selectionEnd); @@ -258,6 +256,7 @@ define(['taskbar'], function(taskbar) { break; } }); + window.addEventListener('resize', function() { if (composer.active !== undefined) composer.reposition(composer.active); }); From da8d198676e7ad0ed6d12f25f086180933918e0e Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 21 Nov 2013 17:00:20 -0500 Subject: [PATCH 2/3] added some user friendly warnings to chat --- public/src/app.js | 22 ++++++++++++++++++++++ public/src/forum/topic.js | 3 --- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 5b0f7a4c48..9b72751aa3 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -331,6 +331,28 @@ var socket, } app.openChat = function (username, touid) { + if (username === app.username) { + app.alert({ + type: 'warning', + title: 'Invalid Chat', + message: "You can't chat with yourself!", + timeout: 5000 + }); + + return; + } + + if (!app.username) { + app.alert({ + type: 'danger', + title: 'Not Logged In', + message: 'Please log in to chat with ' + username + '', + timeout: 5000 + }); + + return; + } + require(['chat'], function (chat) { var chatModal; if (!chat.modalExists(touid)) { diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index f0133be07c..fde5f56f19 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -362,9 +362,6 @@ define(function() { var username = $(this).parents('li.row').attr('data-username'); var touid = $(this).parents('li.row').attr('data-uid'); - if (username === app.username || !app.username) - return; - app.openChat(username, touid); }); From 34c74770ce6bfb7a0751f1415ef2628b2d9edaf8 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 21 Nov 2013 17:02:40 -0500 Subject: [PATCH 3/3] app.js minor cleanup --- public/src/app.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 9b72751aa3..1a69a3e96c 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -396,12 +396,15 @@ var socket, app.infiniteLoaderActive = false; app.loadMorePosts = function (tid, callback) { - if (app.infiniteLoaderActive) + if (app.infiniteLoaderActive) { return; + } + app.infiniteLoaderActive = true; - if ($('#loading-indicator').attr('done') === '0') + if ($('#loading-indicator').attr('done') === '0') { $('#loading-indicator').removeClass('hide'); + } socket.emit('api:topic.loadMore', { tid: tid, @@ -433,9 +436,9 @@ var socket, } app.scrollToPost = function (pid) { - - if (!pid) + if (!pid) { return; + } var container = $(document.body), scrollTo = $('#post_anchor_' + pid), @@ -445,7 +448,6 @@ var socket, $('body,html').animate({ scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height() }, 400); - //$('body,html').scrollTop(scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height()); } if (!scrollTo.length && tid) {