|
@@ -62,268 +62,266 @@
|
|
|
<source src="{{ _p.web_main }}chat/sound/notification.mp3" type="audio/mpeg"></source>
|
|
|
</audio>
|
|
|
<script>
|
|
|
- $(document).on('ready', function () {
|
|
|
- var ChChat = {
|
|
|
- _ajaxUrl: '{{ _p.web_ajax }}course_chat.ajax.php?{{ _p.web_cid_query }}',
|
|
|
- _historySize: -1,
|
|
|
- usersOnline: 0,
|
|
|
- currentFriend: 0,
|
|
|
- call: false,
|
|
|
- track: function () {
|
|
|
- return $.get(ChChat._ajaxUrl, {
|
|
|
- action: 'track',
|
|
|
- size: ChChat._historySize,
|
|
|
- users_online: ChChat.usersOnline,
|
|
|
- friend: ChChat.currentFriend
|
|
|
- })
|
|
|
- .done(function (response) {
|
|
|
- if (response.data.history) {
|
|
|
- ChChat._historySize = response.data.oldFileSize;
|
|
|
- ChChat.setHistory(response.data.history);
|
|
|
- }
|
|
|
-
|
|
|
- if (response.data.userList) {
|
|
|
- ChChat.usersOnline = response.data.usersOnline;
|
|
|
- ChChat.setConnectedUsers(response.data.userList);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- setHistory: function (messageList) {
|
|
|
- var chatHistoryContainer = ChChat.currentFriend ? ('#chat-history-' + ChChat.currentFriend) : '#chat-history';
|
|
|
-
|
|
|
- $(chatHistoryContainer)
|
|
|
- .html(messageList)
|
|
|
- .prop('scrollTop', function () {
|
|
|
- return this.scrollHeight;
|
|
|
- });
|
|
|
-
|
|
|
- $('#chat-alert').get(0).play();
|
|
|
- },
|
|
|
- setConnectedUsers: function (userList) {
|
|
|
- var html = '';
|
|
|
-
|
|
|
- userList.forEach(function (user) {
|
|
|
- var buttonStatus = user.isConnected ? 'success' : 'muted',
|
|
|
- buttonTitle = user.isConnected ? '{{ 'StartAChat'|get_lang }}' : '{{ 'LeaveAMessage'|get_lang }}';
|
|
|
-
|
|
|
- html += '<li class="col-xs-12 chat-user">' +
|
|
|
- ' <div>' +
|
|
|
- ' <img src="'+ user.image_url + '" alt="' + user.complete_name + '" class="img-circle user-image-chat"/>' +
|
|
|
- ' <ul class="list-unstyled">' +
|
|
|
- ' <li>' + user.complete_name;
|
|
|
-
|
|
|
- if (user.id != {{ _u.user_id }}) {
|
|
|
- html += ' <button type="button" class="btn btn-link btn-xs" title="' + buttonTitle + '" data-name="' + user.complete_name + '" data-user="' + user.id + '">' +
|
|
|
- ' <i class="fa fa-comments text-' + buttonStatus + '"></i><span class="sr-only">' + buttonTitle + '</span>' +
|
|
|
- ' </button>';
|
|
|
- }
|
|
|
+$(document).on('ready', function () {
|
|
|
+ var ChChat = {
|
|
|
+ _ajaxUrl: '{{ _p.web_ajax }}course_chat.ajax.php?{{ _p.web_cid_query }}',
|
|
|
+ _historySize: -1,
|
|
|
+ usersOnline: 0,
|
|
|
+ currentFriend: 0,
|
|
|
+ call: false,
|
|
|
+ track: function () {
|
|
|
+ return $.get(ChChat._ajaxUrl, {
|
|
|
+ action: 'track',
|
|
|
+ size: ChChat._historySize,
|
|
|
+ users_online: ChChat.usersOnline,
|
|
|
+ friend: ChChat.currentFriend
|
|
|
+ })
|
|
|
+ .done(function (response) {
|
|
|
+ if (response.data.history) {
|
|
|
+ ChChat._historySize = response.data.oldFileSize;
|
|
|
+ ChChat.setHistory(response.data.history);
|
|
|
+ }
|
|
|
|
|
|
- html += ' </li>' +
|
|
|
- ' <li><small>' + user.username + '</small></li>' +
|
|
|
- ' </ul>' +
|
|
|
- ' </div>' +
|
|
|
- '</li>';
|
|
|
- });
|
|
|
+ if (response.data.userList) {
|
|
|
+ ChChat.usersOnline = response.data.usersOnline;
|
|
|
+ ChChat.setConnectedUsers(response.data.userList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ setHistory: function (messageList) {
|
|
|
+ var chatHistoryContainer = ChChat.currentFriend ? ('#chat-history-' + ChChat.currentFriend) : '#chat-history';
|
|
|
+
|
|
|
+ $(chatHistoryContainer)
|
|
|
+ .html(messageList)
|
|
|
+ .prop('scrollTop', function () {
|
|
|
+ return this.scrollHeight;
|
|
|
+ });
|
|
|
|
|
|
- $('#chat-users').html(html);
|
|
|
- },
|
|
|
- onPreviewListener: function () {
|
|
|
- $.post(ChChat._ajaxUrl, {
|
|
|
- action: 'preview',
|
|
|
- 'message': $('textarea#chat-writer').val()
|
|
|
- })
|
|
|
- .done(function (response) {
|
|
|
- if (!response.status) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ $('#chat-alert').get(0).play();
|
|
|
+ },
|
|
|
+ setConnectedUsers: function (userList) {
|
|
|
+ var html = '';
|
|
|
+
|
|
|
+ userList.forEach(function (user) {
|
|
|
+ var buttonStatus = user.isConnected ? 'success' : 'muted',
|
|
|
+ buttonTitle = user.isConnected ? '{{ 'StartAChat'|get_lang }}' : '{{ 'LeaveAMessage'|get_lang }}';
|
|
|
+
|
|
|
+ html += '<li class="col-xs-12 chat-user">' +
|
|
|
+ ' <div>' +
|
|
|
+ ' <img src="'+ user.image_url + '" alt="' + user.complete_name + '" class="img-circle user-image-chat"/>' +
|
|
|
+ ' <ul class="list-unstyled">' +
|
|
|
+ ' <li>' + user.complete_name;
|
|
|
+
|
|
|
+ if (user.id != {{ _u.user_id }}) {
|
|
|
+ html += ' <button type="button" class="btn btn-link btn-xs" title="' + buttonTitle + '" data-name="' + user.complete_name + '" data-user="' + user.id + '">' +
|
|
|
+ ' <i class="fa fa-comments text-' + buttonStatus + '"></i><span class="sr-only">' + buttonTitle + '</span>' +
|
|
|
+ ' </button>';
|
|
|
+ }
|
|
|
|
|
|
- $('#html-preview').html(response.data.message);
|
|
|
- });
|
|
|
- },
|
|
|
- onSendMessageListener: function (e) {
|
|
|
- e.preventDefault();
|
|
|
+ html += ' </li>' +
|
|
|
+ ' <li><small>' + user.username + '</small></li>' +
|
|
|
+ ' </ul>' +
|
|
|
+ ' </div>' +
|
|
|
+ '</li>';
|
|
|
+ });
|
|
|
|
|
|
- if (!$('textarea#chat-writer').val().trim().length) {
|
|
|
+ $('#chat-users').html(html);
|
|
|
+ },
|
|
|
+ onPreviewListener: function () {
|
|
|
+ $.post(ChChat._ajaxUrl, {
|
|
|
+ action: 'preview',
|
|
|
+ 'message': $('textarea#chat-writer').val()
|
|
|
+ })
|
|
|
+ .done(function (response) {
|
|
|
+ if (!response.status) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var self = this;
|
|
|
- self.disabled = true;
|
|
|
+ $('#html-preview').html(response.data.message);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onSendMessageListener: function (e) {
|
|
|
+ e.preventDefault();
|
|
|
|
|
|
- $.post(ChChat._ajaxUrl, {
|
|
|
- action: 'write',
|
|
|
- message: $('textarea#chat-writer').val(),
|
|
|
- friend: ChChat.currentFriend
|
|
|
- })
|
|
|
- .done(function (response) {
|
|
|
- self.disabled = false;
|
|
|
+ if (!$('textarea#chat-writer').val().trim().length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (!response.status) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ var self = this;
|
|
|
+ self.disabled = true;
|
|
|
|
|
|
- $('textarea#chat-writer').val('');
|
|
|
- $(".emoji-wysiwyg-editor").html('');
|
|
|
- });
|
|
|
- },
|
|
|
- onResetListener: function (e) {
|
|
|
- if (!confirm("{{ 'ConfirmReset'|get_lang }}")) {
|
|
|
- e.preventDefault();
|
|
|
+ $.post(ChChat._ajaxUrl, {
|
|
|
+ action: 'write',
|
|
|
+ message: $('textarea#chat-writer').val(),
|
|
|
+ friend: ChChat.currentFriend
|
|
|
+ })
|
|
|
+ .done(function (response) {
|
|
|
+ self.disabled = false;
|
|
|
+
|
|
|
+ if (!response.status) {
|
|
|
return;
|
|
|
}
|
|
|
- $.get(ChChat._ajaxUrl, {
|
|
|
- action: 'reset',
|
|
|
- friend: ChChat.currentFriend
|
|
|
- })
|
|
|
- .done(function (response) {
|
|
|
- if (!response.status) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- ChChat.setHistory(response.data);
|
|
|
- });
|
|
|
- },
|
|
|
- init: function () {
|
|
|
- ChChat.track().done(function () {
|
|
|
- ChChat.init();
|
|
|
- });
|
|
|
+ $('textarea#chat-writer').val('');
|
|
|
+ $(".emoji-wysiwyg-editor").html('');
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onResetListener: function (e) {
|
|
|
+ if (!confirm("{{ 'ConfirmReset'|get_lang }}")) {
|
|
|
+ e.preventDefault();
|
|
|
+ return;
|
|
|
}
|
|
|
- };
|
|
|
+ $.get(ChChat._ajaxUrl, {
|
|
|
+ action: 'reset',
|
|
|
+ friend: ChChat.currentFriend
|
|
|
+ })
|
|
|
+ .done(function (response) {
|
|
|
+ if (!response.status) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- hljs.initHighlightingOnLoad();
|
|
|
+ ChChat.setHistory(response.data);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ init: function () {
|
|
|
+ ChChat.track().done(function () {
|
|
|
+ ChChat.init();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- emojione.ascii = true;
|
|
|
- emojione.imagePathPNG = '{{ _p.web_lib }}javascript/emojione/png/';
|
|
|
- emojione.imagePathSVG = '{{ _p.web_lib }}javascript/emojione/svg/';
|
|
|
- emojione.imagePathSVGSprites = '{{ _p.web_lib }}javascript/emojione/sprites/';
|
|
|
+ hljs.initHighlightingOnLoad();
|
|
|
|
|
|
- var emojiStrategy = {{ emoji_strategy|json_encode }};
|
|
|
+ emojione.ascii = true;
|
|
|
+ emojione.imagePathPNG = '{{ _p.web_lib }}javascript/emojione/png/';
|
|
|
+ emojione.imagePathSVG = '{{ _p.web_lib }}javascript/emojione/svg/';
|
|
|
+ emojione.imagePathSVGSprites = '{{ _p.web_lib }}javascript/emojione/sprites/';
|
|
|
|
|
|
- $.emojiarea.path = '{{ _p.web_lib }}javascript/emojione/png/';
|
|
|
- $.emojiarea.icons = {{ icons|json_encode }};
|
|
|
+ var emojiStrategy = {{ emoji_strategy|json_encode }};
|
|
|
|
|
|
- $('body').on('click', '#chat-reset', ChChat.onResetListener);
|
|
|
+ $.emojiarea.path = '{{ _p.web_lib }}javascript/emojione/png/';
|
|
|
+ $.emojiarea.icons = {{ icons|json_encode }};
|
|
|
|
|
|
- $('#preview').on('click', ChChat.onPreviewListener);
|
|
|
+ $('body').on('click', '#chat-reset', ChChat.onResetListener);
|
|
|
|
|
|
- $('#emojis').on('click', function () {
|
|
|
- $('[data-toggle="tab"][href="#tab1"]')
|
|
|
- .show()
|
|
|
- .tab('show');
|
|
|
- });
|
|
|
+ $('#preview').on('click', ChChat.onPreviewListener);
|
|
|
|
|
|
- $('textarea#chat-writer').emojiarea({
|
|
|
- button: '#emojis'
|
|
|
- });
|
|
|
+ $('#emojis').on('click', function () {
|
|
|
+ $('[data-toggle="tab"][href="#tab1"]').show().tab('show');
|
|
|
+ });
|
|
|
|
|
|
- $('body').delay(1500).find('.emoji-wysiwyg-editor').textcomplete([
|
|
|
- {
|
|
|
- match: /\B:([\-+\w]*)$/,
|
|
|
- search: function (term, callback) {
|
|
|
- var results = [];
|
|
|
- var results2 = [];
|
|
|
- var results3 = [];
|
|
|
- $.each(emojiStrategy, function (shortname, data) {
|
|
|
- if (shortname.indexOf(term) > -1) {
|
|
|
- results.push(shortname);
|
|
|
- } else {
|
|
|
- if ((data.aliases !== null) && (data.aliases.indexOf(term) > -1)) {
|
|
|
- results2.push(shortname);
|
|
|
- } else if ((data.keywords !== null) && (data.keywords.indexOf(term) > -1)) {
|
|
|
- results3.push(shortname);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ $('textarea#chat-writer').emojiarea({
|
|
|
+ button: '#emojis'
|
|
|
+ });
|
|
|
|
|
|
- if (term.length >= 3) {
|
|
|
- results.sort(function (a, b) {
|
|
|
- return (a.length > b.length);
|
|
|
- });
|
|
|
- results2.sort(function (a, b) {
|
|
|
- return (a.length > b.length);
|
|
|
- });
|
|
|
- results3.sort();
|
|
|
+ $('body').delay(1500).find('.emoji-wysiwyg-editor').textcomplete([
|
|
|
+ {
|
|
|
+ match: /\B:([\-+\w]*)$/,
|
|
|
+ search: function (term, callback) {
|
|
|
+ var results = [];
|
|
|
+ var results2 = [];
|
|
|
+ var results3 = [];
|
|
|
+ $.each(emojiStrategy, function (shortname, data) {
|
|
|
+ if (shortname.indexOf(term) > -1) {
|
|
|
+ results.push(shortname);
|
|
|
+ } else {
|
|
|
+ if ((data.aliases !== null) && (data.aliases.indexOf(term) > -1)) {
|
|
|
+ results2.push(shortname);
|
|
|
+ } else if ((data.keywords !== null) && (data.keywords.indexOf(term) > -1)) {
|
|
|
+ results3.push(shortname);
|
|
|
+ }
|
|
|
}
|
|
|
+ });
|
|
|
|
|
|
- var newResults = results.concat(results2).concat(results3);
|
|
|
-
|
|
|
- callback(newResults);
|
|
|
- },
|
|
|
- template: function (shortname) {
|
|
|
- return '<img class="emojione" src="{{ _p.web_lib }}javascript/emojione/png/'
|
|
|
- + emojiStrategy[shortname].unicode
|
|
|
- + '.png"> :' + shortname + ':';
|
|
|
- },
|
|
|
- replace: function (shortname) {
|
|
|
- return ':' + shortname + ': ';
|
|
|
- },
|
|
|
- index: 1,
|
|
|
- maxCount: 10
|
|
|
- }
|
|
|
- ], {});
|
|
|
+ if (term.length >= 3) {
|
|
|
+ results.sort(function (a, b) {
|
|
|
+ return (a.length > b.length);
|
|
|
+ });
|
|
|
+ results2.sort(function (a, b) {
|
|
|
+ return (a.length > b.length);
|
|
|
+ });
|
|
|
+ results3.sort();
|
|
|
+ }
|
|
|
|
|
|
- $('button#chat-send-message').on('click', ChChat.onSendMessageListener);
|
|
|
+ var newResults = results.concat(results2).concat(results3);
|
|
|
|
|
|
- $('#chat-users').on('click', 'button.btn', function (e) {
|
|
|
- e.preventDefault();
|
|
|
+ callback(newResults);
|
|
|
+ },
|
|
|
+ template: function (shortname) {
|
|
|
+ return '<img class="emojione" src="{{ _p.web_lib }}javascript/emojione/png/'
|
|
|
+ + emojiStrategy[shortname].unicode
|
|
|
+ + '.png"> :' + shortname + ':';
|
|
|
+ },
|
|
|
+ replace: function (shortname) {
|
|
|
+ return ':' + shortname + ': ';
|
|
|
+ },
|
|
|
+ index: 1,
|
|
|
+ maxCount: 10
|
|
|
+ }
|
|
|
+ ], {});
|
|
|
|
|
|
- var jSelf = $(this),
|
|
|
- userId = parseInt(jSelf.data('user')) || 0;
|
|
|
+ $('button#chat-send-message').on('click', ChChat.onSendMessageListener);
|
|
|
|
|
|
- if (!userId) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ $('#chat-users').on('click', 'button.btn', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
|
|
|
- var exists = false;
|
|
|
+ var jSelf = $(this),
|
|
|
+ userId = parseInt(jSelf.data('user')) || 0;
|
|
|
|
|
|
- $('#chat-tabs ul.nav li').each(function (i, el) {
|
|
|
- if ($(el).data('user') == userId) {
|
|
|
- exists = true;
|
|
|
- }
|
|
|
- });
|
|
|
+ if (!userId) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (exists) {
|
|
|
- $('#chat-tab-' + userId).tab('show');
|
|
|
+ var exists = false;
|
|
|
|
|
|
- return;
|
|
|
+ $('#chat-tabs ul.nav li').each(function (i, el) {
|
|
|
+ if ($(el).data('user') == userId) {
|
|
|
+ exists = true;
|
|
|
}
|
|
|
+ });
|
|
|
|
|
|
- $('#chat-tabs ul.nav-tabs').append('\
|
|
|
- <li role="presentation" data-user="' + userId + '">\
|
|
|
- <a id="chat-tab-' + userId + '" href="#chat-' + userId + '" aria-controls="chat-' + userId + '" role="tab" data-toggle="tab">' + jSelf.data('name') + '</a>\
|
|
|
- </li>\
|
|
|
- ');
|
|
|
+ if (exists) {
|
|
|
+ $('#chat-tab-' + userId).tab('show');
|
|
|
|
|
|
- $('#chat-tabs .tab-content').append('\
|
|
|
- <div role="tabpanel" class="tab-pane" id="chat-' + userId + '">\
|
|
|
- <div class="course-chat chat-history" id="chat-history-' + userId + '"></div>\
|
|
|
- </div>\
|
|
|
- ');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- $('#chat-tab-' + userId).tab('show');
|
|
|
- });
|
|
|
+ $('#chat-tabs ul.nav-tabs').append('\
|
|
|
+ <li role="presentation" data-user="' + userId + '">\
|
|
|
+ <a id="chat-tab-' + userId + '" href="#chat-' + userId + '" aria-controls="chat-' + userId + '" role="tab" data-toggle="tab">' + jSelf.data('name') + '</a>\
|
|
|
+ </li>\
|
|
|
+ ');
|
|
|
|
|
|
- $('#chat-tabs ul.nav-tabs').on('shown.bs.tab', 'li a', function (e) {
|
|
|
- var jSelf = $(this);
|
|
|
- var userId = parseInt(jSelf.parent().data('user')) || 0;
|
|
|
+ $('#chat-tabs .tab-content').append('\
|
|
|
+ <div role="tabpanel" class="tab-pane" id="chat-' + userId + '">\
|
|
|
+ <div class="course-chat chat-history" id="chat-history-' + userId + '"></div>\
|
|
|
+ </div>\
|
|
|
+ ');
|
|
|
|
|
|
- if (!userId) {
|
|
|
- ChChat.currentFriend = 0;
|
|
|
+ $('#chat-tab-' + userId).tab('show');
|
|
|
+ });
|
|
|
|
|
|
- return;
|
|
|
- }
|
|
|
+ $('#chat-tabs ul.nav-tabs').on('shown.bs.tab', 'li a', function (e) {
|
|
|
+ var jSelf = $(this);
|
|
|
+ var userId = parseInt(jSelf.parent().data('user')) || 0;
|
|
|
|
|
|
- ChChat.currentFriend = userId;
|
|
|
+ if (!userId) {
|
|
|
+ ChChat.currentFriend = 0;
|
|
|
|
|
|
- $(this).tab('show');
|
|
|
- });
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- $('.emoji-wysiwyg-editor').on('keyup', function (e) {
|
|
|
- if (e.ctrlKey && e.keyCode === 13) {
|
|
|
- $('button#chat-send-message').trigger('click');
|
|
|
- }
|
|
|
- });
|
|
|
+ ChChat.currentFriend = userId;
|
|
|
+
|
|
|
+ $(this).tab('show');
|
|
|
+ });
|
|
|
|
|
|
- ChChat.init();
|
|
|
+ $('.emoji-wysiwyg-editor').on('keyup', function (e) {
|
|
|
+ if (e.ctrlKey && e.keyCode === 13) {
|
|
|
+ $('button#chat-send-message').trigger('click');
|
|
|
+ }
|
|
|
});
|
|
|
+
|
|
|
+ ChChat.init();
|
|
|
+});
|
|
|
</script>
|