Skip to content

Commit

Permalink
markdown implementation
Browse files Browse the repository at this point in the history
showdown.js is a lib for markdown, also emoji (yea!!! :)) are supported,
also included libs for push notefications (serviceWorker, push).
  • Loading branch information
isabolic committed Jan 22, 2018
1 parent 2b20557 commit e64aaa3
Show file tree
Hide file tree
Showing 7 changed files with 2,644 additions and 574 deletions.
5 changes: 5 additions & 0 deletions apex.chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,8 @@ body.t-PageBody.js-rightCollapsed .t-Body-actions {
width: 20px;
}
}

pre {
background-color: #f8f8f8;
border: 1px solid #dfdfdf;
}
26 changes: 20 additions & 6 deletions apex.chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
chatRow : "<div class='ch-row'>" +
"<div class='ch-avatar'>{{avatar}}</div>" +
"<div class='ch-username'>{{username}}</div>" +
"<div class='ch-msg {{current_usr}}'>{{msg}}</div>" +
"<div class='ch-msg {{current_usr}}'>{{{msg}}}</div>" +
"</div>",
typingInfo : "<div class='ch-ty-row ty-{{usr}}'>" +
"<div class='ch-type'>{{msg}}</div>" +
Expand Down Expand Up @@ -198,6 +198,9 @@
var userName = user || this.options.currentUser,
rowtemplate;

msg = new showdown.Converter().makeHtml(msg);


rowtemplate = compileTemplate.call(this,
"chatRow", {
"msg" : msg,
Expand All @@ -207,7 +210,7 @@
}
);

if(document.hidden === true && this.options.currentUser !== userName){
if(document.hidden === true && this.options.currentUser !== userName && window.Push){
Push.create(lang.newMessageFrom + userName, {
body: msg,
timeout: 4000,
Expand Down Expand Up @@ -297,7 +300,7 @@
* @param string action [string "LEFT"/"JOIN"]
*/
var userLeftJoin = function userLeftJoin(msg, user, type){
var rowTemplate, push
var rowTemplate,
userName = user || this.options.currentUser;

if (this.options.showLeftNotefication === true && type === "LEFT") {
Expand All @@ -306,7 +309,7 @@
rowTemplate = "userJoinNot";
}

if (document.hidden === true){
if (document.hidden === true && window.Push){
Push.create(userName, {
body: type === "JOIN" ? lang.notUserJoin : lang.notUserLeft,
timeout: 4000,
Expand Down Expand Up @@ -405,7 +408,7 @@

this.container.on("keydown", ".ch-input", function(e) {
var msg;
if (e.keyCode === 13) {
if (e.keyCode === 13 && e.shiftKey === false) {
msg = $(e.currentTarget).val();
$(e.currentTarget).val("");
addMessageElement.call(this, msg);
Expand Down Expand Up @@ -661,7 +664,11 @@
this.linkDialog = $(dlgTemplate);

$("body").append(dlgTemplate);
}

var setShowdownOpts = function setShowdownOpts(){
showdown.setOption("emoji", true);
showdown.setOption("simpleLineBreaks", true);
}

apex.plugins.apexChat = function(opts) {
Expand All @@ -681,6 +688,10 @@
throw this.jsName || ": requires handlebars.js (http://handlebarsjs.com/)";
}

if (window.showdown === undefined) {
throw this.jsName || ": requires showdown.js (https://github.com/showdownjs/showdown)";
}

if ($.type(opts) === "string") {
opts = JSON.parse(opts);
}
Expand All @@ -700,9 +711,12 @@
this.parent.append(this.container);
}

Push.Permission.request();
if (window.Push) {
Push.Permission.request();
}

setDom.call(this);
setShowdownOpts.call(this);

return this;

Expand Down
14 changes: 14 additions & 0 deletions build/packages/ax_plg_socket_chat.pkb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@
p_version => NULL,
p_skip_extension => FALSE);

apex_javascript.add_library(p_name => 'serviceWorker',
p_directory => p_plugin.file_prefix,
p_version => NULL,
p_skip_extension => FALSE);

apex_javascript.add_library(p_name => 'push.min',
p_directory => p_plugin.file_prefix,
p_version => NULL,
p_skip_extension => FALSE);

apex_javascript.add_library(p_name => 'showdown.min',
p_directory => p_plugin.file_prefix,
p_version => NULL,
p_skip_extension => FALSE);
apex_css.add_file (
p_name => 'apex.chat',
p_directory => p_plugin.file_prefix );
Expand Down
Loading

0 comments on commit e64aaa3

Please sign in to comment.