diff --git a/less/topic.less b/less/topic.less index 60ff503..642dddf 100644 --- a/less/topic.less +++ b/less/topic.less @@ -273,6 +273,51 @@ margin-left: 0; } } + + .quick-reply { + .icon { + position: relative; + border-radius: 50%; + min-width: 46px; + min-height: 46px; + margin-top: 2px; + + > a > .status { + position: absolute; + right: 12px; + font-size: 12px; + top: 0px; + + @media (min-width: @screen-md-min) { + top: 2px; + font-size: 16px; + } + } + + img, .user-icon { + margin-right: 15px; + .user-icon-style(46px, 2.4rem, 50%); + } + } + + .quickreply-message { + margin-left: 61px; + margin-bottom: 5px; + + @media (max-width: @screen-sm-max) { + margin-left: 0; + + [component="topic/quickreply/text"] { + font-size: 16px; + padding: 10px; + } + } + } + + [component="topic/quickreply/button"] { + margin-bottom: 10px; + } + } } diff --git a/lib/modules/quickreply.js b/lib/modules/quickreply.js new file mode 100644 index 0000000..6ffa1b4 --- /dev/null +++ b/lib/modules/quickreply.js @@ -0,0 +1,47 @@ +"use strict"; + +/*globals $, app, ajaxify, socket*/ + +define('persona/quickreply', ['components'], function(components) { + var QuickReply = {}; + + QuickReply.init = function() { + + var element = components.get('topic/quickreply/text'); + var data = { + element: element, + strategies: [], + options: { + zIndex: 100, + listPosition: function(position) { + this.$el.css(this._applyPlacement(position)); + this.$el.css('position', 'absolute'); + return this; + } + } + }; + + $(window).trigger('composer:autocomplete:init', data); + data.element.textcomplete(data.strategies, data.options); + $('.textcomplete-wrapper').css('height', '100%').find('textarea').css('height', '100%'); + + components.get('topic/quickreply/button').on('click', function(e) { + var replyMsg = components.get('topic/quickreply/text').val(); + var replyData = { + tid: ajaxify.data.tid, + handle: undefined, + content: replyMsg + }; + + socket.emit('posts.reply', replyData, function(err, data) { + if (err) { + app.alertError(err.message); + } + + components.get('topic/quickreply/text').val(''); + }); + }); + }; + + return QuickReply; +}); \ No newline at end of file diff --git a/lib/persona.js b/lib/persona.js index 85f1a85..37f62a3 100644 --- a/lib/persona.js +++ b/lib/persona.js @@ -9,6 +9,7 @@ $(document).ready(function() { setupTaskbar(); setupEditedByIcon(); setupMobileMenu(); + setupQuickReply(); if (env === 'xs' || env ==='sm') { $(".navbar-fixed-top").autoHidingNavbar({ @@ -302,4 +303,14 @@ $(document).ready(function() { drop.css({top: y + 'px', left: x + 'px'}).addClass('animate'); }); } + + function setupQuickReply() { + $(window).on('action:ajaxify.end', function(ev, data) { + if (data.url && data.url.match('^topic/')) { + require(['persona/quickreply'], function(quickreply) { + quickreply.init(); + }); + } + }); + } }); \ No newline at end of file diff --git a/library.js b/library.js index 4495add..dde1728 100644 --- a/library.js +++ b/library.js @@ -2,6 +2,7 @@ var S = require.main.require('string'); var meta = module.parent.require('./meta'); +var user = module.parent.require('./user'); var library = {}; @@ -91,6 +92,7 @@ library.getThemeConfig = function(config, callback) { meta.settings.get('persona', function(err, settings) { config.hideSubCategories = settings.hideSubCategories === 'on'; config.hideCategoryLastPost = settings.hideCategoryLastPost === 'on'; + config.enableQuickReply = settings.enableQuickReply === 'on'; }); callback(false, config); @@ -100,4 +102,19 @@ function renderAdmin(req, res, next) { res.render('admin/plugins/persona', {}); } +library.addUserToTopic = function(data, callback) { + if (data.req.user) { + user.getUserData(data.req.user.uid, function(err, userdata) { + if (err) { + return callback(err); + } + + data.templateData.loggedInUser = userdata; + callback(null, data); + }); + } else { + callback(null, data); + } +}; + module.exports = library; \ No newline at end of file diff --git a/plugin.json b/plugin.json index d26f5cc..2aea4b9 100644 --- a/plugin.json +++ b/plugin.json @@ -6,13 +6,15 @@ { "hook": "filter:widgets.getAreas", "method": "defineWidgetAreas" }, { "hook": "filter:config.get", "method": "getThemeConfig" }, { "hook": "static:app.load", "method": "init" }, - { "hook": "filter:admin.header.build", "method": "addAdminNavigation" } + { "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, + { "hook": "filter:topic.build", "method": "addUserToTopic" } ], "scripts": [ "lib/persona.js", "lib/modules/nprogress.js", "lib/modules/autohidingnavbar.min.js", "lib/modules/slideout.min.js", + "lib/modules/quickreply.js", "lib/client/chats.js" ], "acpScripts": [ diff --git a/templates/admin/plugins/persona.tpl b/templates/admin/plugins/persona.tpl index 37595d2..c0e16b6 100644 --- a/templates/admin/plugins/persona.tpl +++ b/templates/admin/plugins/persona.tpl @@ -14,6 +14,12 @@ Hide last post on categories view +
+ +
diff --git a/templates/partials/topic/quickreply.tpl b/templates/partials/topic/quickreply.tpl new file mode 100644 index 0000000..41345f4 --- /dev/null +++ b/templates/partials/topic/quickreply.tpl @@ -0,0 +1,18 @@ + +
+ +
+ +
+ +
+ \ No newline at end of file diff --git a/templates/topic.tpl b/templates/topic.tpl index 4d3f6c6..18cb539 100644 --- a/templates/topic.tpl +++ b/templates/topic.tpl @@ -32,7 +32,11 @@ - + + + + +