dropped usage of gulp,
by using the external tool [jsmin](https://github.com/douglascrockford/JSMin.git)
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
+(function ($) {
|
||||
/*
|
||||
# chat control ids
|
||||
window.ChatHubHandler = (function ($) {
|
||||
|
||||
## inputs
|
||||
/*
|
||||
# chat control ids
|
||||
|
||||
## inputs
|
||||
|
||||
* msg_<rname> : input providing a room message
|
||||
* pv_<uname> : input providing a private message
|
||||
@ -17,7 +18,7 @@
|
||||
* server : container for server messages
|
||||
|
||||
## temporary containers
|
||||
|
||||
|
||||
* room_<rname> : room message list
|
||||
* pv_<uname> : private discussion display
|
||||
|
||||
@ -28,134 +29,132 @@
|
||||
|
||||
*/
|
||||
$.fn.filterByData = function (prop, val) {
|
||||
return this.filter(
|
||||
function () { return $(this).data(prop) == val; }
|
||||
)
|
||||
}
|
||||
return this.filter(function () { return $(this).data(prop) == val; });
|
||||
};
|
||||
var ChatView = function ($view, full) {
|
||||
|
||||
|
||||
var ChatView = function ($view, full)
|
||||
{
|
||||
|
||||
if (!full) throw "not implemented";
|
||||
if (!full) throw new Error('not implemented');
|
||||
|
||||
// build a channel list
|
||||
var chans = Array();
|
||||
var users = Array();
|
||||
var chans = [];
|
||||
var frontRoomName;
|
||||
|
||||
var ulist = $("<ul></ul>").addClass('userlist');
|
||||
var notifications = $("<ul></ul>").addClass('notifs');
|
||||
var ulist = $('<ul></ul>').addClass('userlist');
|
||||
var notifications = $('<ul></ul>').addClass('notifs');
|
||||
|
||||
ulist.appendTo($view);
|
||||
notifications.appendTo($view);
|
||||
|
||||
var chat = $.connection.chatHub
|
||||
var chat = $.connection.chatHub;
|
||||
// Create a function that the hub can call back to display messages.
|
||||
chat.client.addMessage = function (name, room, message) {
|
||||
// Add the message to the page.
|
||||
$('#room_'+room).append('<li class="discussion"><strong>' + htmlEncode(name)
|
||||
+ '</strong>: ' + htmlEncode(message) + '</li>')
|
||||
}
|
||||
$('#room_' + room).append('<li class="discussion"><strong>' + htmlEncode(name) + '</strong>: ' + htmlEncode(message) + '</li>');
|
||||
};
|
||||
|
||||
chat.client.addPV = function (name, message) {
|
||||
if (!$('#mute').prop('checked')) {
|
||||
audio.play()
|
||||
audio.play();
|
||||
}
|
||||
// Add the pv to the page.
|
||||
$('#pv_'+name).append('<li class="pv"><strong>' + htmlEncode(name)
|
||||
+ '</strong>: ' + htmlEncode(message) + '</li>')
|
||||
}
|
||||
chat.client.notify = function (tag, message) {
|
||||
$('#pv_' + name).append('<li class="pv"><strong>' + htmlEncode(name) + '</strong>: ' + htmlEncode(message) + '</li>');
|
||||
};
|
||||
|
||||
chat.client.notifyRoom = function (tag, targetid, message) {
|
||||
// Add the notification to the page.
|
||||
if (tag === 'connected' || tag === "reconnected") {
|
||||
onUserConnected(message);
|
||||
}
|
||||
else if (tag === 'disconnected') {
|
||||
onUserDisconnected(message)
|
||||
} // reconnected userpart userjoin deniedpv
|
||||
$("<li></li>").append(tag+": ").append(message).addClass(tag).
|
||||
appendTo(notifications);
|
||||
}
|
||||
|
||||
if (tag === 'connected' || tag === 'reconnected') onUserConnected(targetid, message);
|
||||
else if (tag === 'disconnected') onUserDisconnected(targetid, message);
|
||||
// eslint-disable-next-line no-warning-comments
|
||||
// TODO reconnected userpart userjoin deniedpv
|
||||
$('<li></li>').addClass(tag).append(tag + ': ' + targetid + ' ').append(message).addClass(tag).appendTo($('#room_' + targetid));
|
||||
};
|
||||
|
||||
chat.client.notifyUser = function (tag, targetid, message) {
|
||||
// Add the notification to the page.
|
||||
if (tag === 'connected' || tag === 'reconnected') onUserConnected(targetid, message);
|
||||
else if (tag === 'disconnected') onUserDisconnected(targetid, message);
|
||||
// eslint-disable-next-line no-warning-comments
|
||||
// TODO reconnected userpart userjoin deniedpv
|
||||
$('<li></li>').append(tag + ': ' + targetid).append(message).addClass(tag).appendTo(notifications);
|
||||
};
|
||||
|
||||
var setActiveRoom = function(room) {
|
||||
var frontRoom;
|
||||
if (frontRoomName!=='') {
|
||||
frontRoom=$("#vroom_"+frontRoomName);
|
||||
if (frontRoomName !== '') {
|
||||
frontRoom = $('#vroom_' + frontRoomName);
|
||||
// eslint-disable-next-line no-warning-comments
|
||||
// TODO animate
|
||||
frontRoom.addClass("hidden");
|
||||
$("#sel_"+frontRoomName).addClass("btn-primary");
|
||||
frontRoom.addClass('hidden');
|
||||
$('#sel_' + frontRoomName).addClass('btn-primary');
|
||||
}
|
||||
frontRoomName = room;
|
||||
frontRoom=$("#vroom_"+room);
|
||||
$("#sel_"+room).removeClass("btn-primary");
|
||||
frontRoom.removeClass("hidden");
|
||||
}
|
||||
frontRoom = $('#vroom_' + room);
|
||||
$('#sel_' + room).removeClass('btn-primary');
|
||||
frontRoom.removeClass('hidden');
|
||||
};
|
||||
|
||||
var chatbar = $('<div class="chatbar"></div>');
|
||||
|
||||
var roomjoin = $('<div class="chatctl" class=\"form-control\"></div>');
|
||||
var roomjoin = $('<div class="chatctl" class="form-control"></div>');
|
||||
|
||||
var roomlist = $('<div class="roomlist"></div>');
|
||||
roomlist.appendTo(chatbar);
|
||||
$("<label for=\"channame\">Join :</label>")
|
||||
$('<label for="channame">Join :</label>')
|
||||
.appendTo(roomjoin);
|
||||
var chanName = $("<input id=\"channame\" title=\"channel name\" hint=\"yavsc\" >");
|
||||
var chanName = $('<input id="channame" title="channel name" hint="yavsc" >');
|
||||
chanName.appendTo(roomjoin);
|
||||
roomjoin.appendTo(chatbar);
|
||||
|
||||
chatbar.appendTo($view);
|
||||
var chatlist = $('<div class="chatlist" ></div>');
|
||||
chatlist.appendTo($view);
|
||||
|
||||
var buildRoom = function (room)
|
||||
{
|
||||
var roomTag = $("<a>"+room+"</a>").addClass("btn");
|
||||
roomTag.prop("id","sel_"+room)
|
||||
.click(function(){
|
||||
var buildRoom = function (room) {
|
||||
var roomTag = $('<a>' + room + '</a>').addClass('btn');
|
||||
roomTag.prop('id', 'sel_' + room).click(function() {
|
||||
setActiveRoom(room);
|
||||
$(this).removeClass("btn-primary");
|
||||
$(this).removeClass('btn-primary');
|
||||
});
|
||||
|
||||
roomTag.appendTo(roomlist);
|
||||
var roomview = $("<div></div>").addClass("container");
|
||||
var roomview = $('<div></div>').addClass('container');
|
||||
roomview.appendTo(chatlist);
|
||||
roomview.prop('id',"vroom_"+room);
|
||||
var msglist = $("<ul></ul>").addClass("mesglist");
|
||||
msglist.prop('id',"room_"+room);
|
||||
roomview.prop('id', 'vroom_' + room);
|
||||
var msglist = $('<ul></ul>').addClass('mesglist');
|
||||
msglist.prop('id', 'room_' + room);
|
||||
msglist.appendTo(roomview);
|
||||
$("<input type=\"text\">")
|
||||
.prop('id','inp_'+room)
|
||||
.prop('enable',false)
|
||||
.prop('hint','hello')
|
||||
.prop('title','send to '+room)
|
||||
$('<input type="text">')
|
||||
.prop('id', 'inp_' + room)
|
||||
.prop('enable', false)
|
||||
.prop('hint', 'hello')
|
||||
.prop('title', 'send to ' + room)
|
||||
.addClass('form-control')
|
||||
.keydown(function(ev) {
|
||||
if (ev.which == 13) {
|
||||
if (this.value.length==0) return;
|
||||
|
||||
if (this.value.length == 0) return;
|
||||
chat.server.send(room, this.value);
|
||||
this.value="";
|
||||
}}).appendTo(roomview);
|
||||
this.value = '';
|
||||
}
|
||||
}).appendTo(roomview);
|
||||
chans.push(room);
|
||||
setActiveRoom(room);
|
||||
}
|
||||
};
|
||||
|
||||
$view.data("chans").split(",").forEach(function(chan) {
|
||||
buildRoom(chan)
|
||||
$view.data('chans').split(',').forEach(function(chan) {
|
||||
buildRoom(chan);
|
||||
});
|
||||
|
||||
|
||||
function onCx () {
|
||||
setTimeout(function () {
|
||||
getUsers()
|
||||
}, 120),
|
||||
getUsers();
|
||||
}, 120);
|
||||
|
||||
$('#chatview').removeClass('disabled');
|
||||
|
||||
chans.forEach(function(room) {
|
||||
chat.server.join(room).done(function(chatInfo)
|
||||
{
|
||||
chat.server.join(room).done(function(chatInfo) {
|
||||
setActiveRoom(chatInfo.Name);
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function onDisCx () {
|
||||
@ -164,125 +163,120 @@
|
||||
|
||||
// Start the connection.
|
||||
$.connection.hub.start().done(function () {
|
||||
onCx()
|
||||
})
|
||||
onCx();
|
||||
});
|
||||
|
||||
$.connection.hub.disconnected(function () {
|
||||
|
||||
onDisCx()
|
||||
onDisCx();
|
||||
setTimeout(function () {
|
||||
$.connection.hub.start().done(function () {
|
||||
// $('#mySignalRConnectionIdHidden').val($.connection.hub.id)
|
||||
onCx()
|
||||
onCx();
|
||||
}, 30000); // Re-start connection after 30 seconds
|
||||
})
|
||||
})
|
||||
|
||||
chanName.keydown(
|
||||
function (event) {
|
||||
if (event.which == 13) {
|
||||
if (this.value.length==0) return;
|
||||
buildRoom(this.value);
|
||||
chat.server.join(this.value).done(function(chatInfo)
|
||||
{
|
||||
setActiveRoom(chatInfo.Name);
|
||||
});
|
||||
this.value=""
|
||||
} else {
|
||||
// TODO showRoomInfo(this.value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var pvuis
|
||||
chanName.keydown(function (event) {
|
||||
if (event.which == 13) {
|
||||
if (this.value.length == 0) return;
|
||||
buildRoom(this.value);
|
||||
chat.server.join(this.value).done(function(chatInfo) {
|
||||
setActiveRoom(chatInfo.Name);
|
||||
});
|
||||
this.value = '';
|
||||
}
|
||||
// else TODO showRoomInfo(this.value);
|
||||
});
|
||||
|
||||
var pvuis;
|
||||
// eslint-disable-next-line no-warning-comments
|
||||
// TODO get this data from the chatview element
|
||||
var audio = new Audio('/sounds/bell.mp3')
|
||||
|
||||
var audio = new Audio('/sounds/bell.mp3');
|
||||
|
||||
var sendPV = function () {
|
||||
var msg = $('#pv').val()
|
||||
var msg = $('#pv').val();
|
||||
// Call the Send method on the hub.
|
||||
$.each(pvuis.CXs, function () {
|
||||
chat.server.sendPV(this, msg)
|
||||
})
|
||||
$('#discussion').append('<li class="pv">' + htmlEncode(pvuis.UserName)
|
||||
+ '<< ' + htmlEncode(msg) + '</li>')
|
||||
chat.server.sendPV(this, msg);
|
||||
});
|
||||
$('#discussion').append('<li class="pv">' + htmlEncode(pvuis.UserName) + '<< ' + htmlEncode(msg) + '</li>');
|
||||
// Clear text box and reset focus for next comment.
|
||||
$('#pv').val('')
|
||||
}
|
||||
$('#pv').val('');
|
||||
};
|
||||
|
||||
$('#pv').keydown(function (event) {
|
||||
if (event.which == 13) {
|
||||
sendPV()
|
||||
sendPV();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
$('#command').keydown(function (event) {
|
||||
if (event.which == 13) {
|
||||
sendCommand()
|
||||
// eslint-disable-next-line no-warning-comments
|
||||
// TODO server command: sendCommand()
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var addChatUser = function (uname) {
|
||||
|
||||
$("#u_"+uname).remove();
|
||||
$('#u_' + uname).remove();
|
||||
// ulist.remove("li.user[data='"+uname+"']");
|
||||
|
||||
$('<li class="user"><img src="/Avatars/' + uname + '.xs.png"> ' + uname + '</li>')
|
||||
.prop('id', 'u_'+uname)
|
||||
.prop('id', 'u_' + uname)
|
||||
.css('cursor', 'pointer')
|
||||
.click(function () { setPrivateTarget(this); })
|
||||
.appendTo(ulist)
|
||||
}
|
||||
|
||||
.appendTo(ulist);
|
||||
};
|
||||
|
||||
var getUsers = function () {
|
||||
$.get('/api/chat/users').done(
|
||||
function (users) {
|
||||
$.get('/api/chat/users').done(function (users) {
|
||||
$.each(users, function () {
|
||||
var user = this
|
||||
addChatUser(user.UserName)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
var user = this;
|
||||
addChatUser(user.UserName);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// This optional function html-encodes messages for display in the page.
|
||||
function htmlEncode (value) {
|
||||
var encodedValue = $('<div />').text(value).html()
|
||||
return encodedValue
|
||||
var encodedValue = $('<div />').text(value).html();
|
||||
return encodedValue;
|
||||
}
|
||||
|
||||
var setPrivateTarget = function (li) {
|
||||
$('#rooms').addClass('hidden')
|
||||
$('#sendpvbox').removeClass('hidden')
|
||||
pvuis = { CXs: $(li).data('cxids'), UserName: $(li).data('name') }
|
||||
$('#sendpvdest').html(pvuis.UserName)
|
||||
$('#pvs').focus()
|
||||
}
|
||||
$('#rooms').addClass('hidden');
|
||||
$('#sendpvbox').removeClass('hidden');
|
||||
pvuis = { CXs: $(li).data('cxids'), UserName: $(li).data('name') };
|
||||
$('#sendpvdest').html(pvuis.UserName);
|
||||
$('#pvs').focus();
|
||||
};
|
||||
|
||||
var setPublic = function () {
|
||||
$('#rooms').removeClass('hidden')
|
||||
$('#sendpvbox').addClass('hidden')
|
||||
$('#message').focus()
|
||||
}
|
||||
$('#pubChan').css('cursor', 'pointer')
|
||||
$('#pubChan').click(setPublic)
|
||||
setPublic()
|
||||
$('#rooms').removeClass('hidden');
|
||||
$('#sendpvbox').addClass('hidden');
|
||||
$('#message').focus();
|
||||
};
|
||||
|
||||
$('#pubChan').css('cursor', 'pointer');
|
||||
$('#pubChan').click(setPublic);
|
||||
setPublic();
|
||||
|
||||
var onUserDisconnected = function (uname) {
|
||||
$("#u_"+uname).remove();
|
||||
}
|
||||
$('#u_' + uname).remove();
|
||||
};
|
||||
|
||||
var onUserConnected = function (username) {
|
||||
addChatUser(username)
|
||||
}
|
||||
|
||||
$(window).unload(function () { chat.server.abort(); })
|
||||
addChatUser(username);
|
||||
};
|
||||
|
||||
}
|
||||
$(window).unload(function () { chat.server.abort(); });
|
||||
|
||||
$(document).ready(function($){
|
||||
ChatView($('#chatview'),true);
|
||||
};
|
||||
|
||||
$(document).ready(function($) {
|
||||
ChatView($('#chatview'), true);
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
})(window.jQuery);
|
||||
|
Reference in New Issue
Block a user