/    Sign up×
Community /Pin to ProfileBookmark

javascript with Aspx html

Hi..
I am developing a silverlight application using mixture of JavaScript and HTML.
Guide me please where am i wrong?
please see the below js file:
== DefaultBehavior.js ==
$(document).ready(function() {
$(“#box”).hide();
$(“#chatbar”).hide();
$(“#login”).show();
$(“#nicknameTextBox”).blur(function() {
if($(“#nicknameTextBox”).val() == “”) {
$(“#nicknameTextBox”).val(“Type a nickname”);
}
});
$(“#nicknameTextBox”).focus(function() {
if($(“#nicknameTextBox”).val() == “Type a nickname”) {
$(“#nicknameTextBox”).val(“”);
}
});
$(“#usersButton”).click(function() {
$(“#box”).slideToggle(“fast”);
});
$(“#connectButton”).click(function() {
if($(“#connectButton”).val() == “connect”) {
if($(“#nicknameTextBox”).val() != “Type a nickname”) {
connect();
}
}
else {
leave();
}
});
});

var allUsers = null;

function getUsers(users) {
allUsers = eval(users);
for(i=0; i<allUsers.length; i=i+1) {
var u = allUsers[i];
if(u.Name == $(“#nicknameTextBox”).val())
$(“#listOUsers”).prepend(“<tr id=”” + u.ID + “”><td class=”me”>” + u.Name + “</td></tr>”);
else
$(“#listOUsers”).append(“<tr id=”” + u.ID + “”><td class=”userOnline”>” + u.Name + “</td></tr>”);
}
$(“#numberOfOnline”).html(“(” + allUsers.length + “)”);
$(“#connectButton”).val(“disconnect”);
$(“#connectButton”).fadeIn(“slow”);
register($(“.userOnline”));
}

function userLeft(user) {
index = -1;
for(i=0; i<allUsers.length; i=i+1) {
var u = allUsers[i];
if(u.ID == user) {
$(“#” + u.ID).remove();
index = i;

var chatID = “#” + u.Name + “chat”;
if($(chatID).length > 0) {
insertToChatBody(u.Name, “<b><i>” + u.Name + ” has left</i></b>”);
$(“#” + u.Name + “chatInput”).attr(“disabled”, “disabled”);
}

break;
}
}
if(index > -1) {
allUsers.splice(index, 1);
}
$(“#numberOfOnline”).html(“(” + allUsers.length + “)”);

}

function userJoined(userJson) {
var user = eval(“(” + userJson + “)”);
$(“#listOUsers”).append(“<tr id=”” + user.ID + “”><td class=”userOnline”>” + user.Name + “</td></tr>”);
allUsers.push(user);
$(“#numberOfOnline”).html(“(” + allUsers.length + “)”);
register($(“#” + user.ID));
if($(“#” + user.Name + “chat”).length > 0) {
$(“#” + user.Name + “chatInput”).removeAttr(“disabled”);
}
}

function newMessage(message) {
var chatMessage = eval(“(” + message + “)”);
for(i=0;i<allUsers.length;i+=1) {
var user = allUsers[i];
if(user.ID == chatMessage.FromID) {
var name = user.Name;
// Make sure it exists
chatboxRegister(name);
// Insert into the text body
var chatBodyID = “#” + name + “chatBody”;
insertToChatBody(name, “<b>” + name + “: </b>” + chatMessage.Body);
break;
}
}
}

function connect() {
$(“#login”).show();
$(“#login”).val(“Logging in…”);
$(“#connectButton”).fadeOut(“slow”);
var slCtrl = document.getElementById(“Xaml1”);
alert(slCtrl);
slCtrl.Content.PlexScriptApp.Connect($(“#nicknameTextBox”).val());
}

function leave() {
$(“#chatbar”).fadeOut(“fast”);
$(“#login”).fadeIn(“slow”);
$(“#connectButton”).val(“connect”);
var slCtrl = document.getElementById(“Xaml1”);
slCtrl.Content.PlexScriptApp.Leave();
}

function connected() {
$(“#login”).hide();
$(“#chatbar”).show();
$(“#chatbar”).fadeIn(“fast”);
}

var currentChatID = null;
var currentChatName = null;
function register(obj) {
$(obj).click(function() { chatboxRegister($(this).text()); });
}

function chatboxRegister(name) {
var id = “#” + name + “chat”;
if($(id).length == 0) {
var chatContent = “<div id='” + name + “chatbox’ class=’chatbox’>” +
“<div class=’titleBar’>Chatting with: ” + name + “</div>” +
“<div id='” + name + “chatBody’ class=’chatbody’></div>” +
“<input type=’text’ id='” + name + “chatInput’ class=’chatInput’ />” +
“</div>”;
var newContent = “<div id='” + name + “chat’ class=’button removepad’>” +
“<div id='” + name + “button’ class=’buttonName’>” + name +
“</div>” +
chatContent +
“</div>”;
$(“#usersButton”).before(newContent);
var chatBoxID = “#” + name + “chatbox”;
// Hide the chatbox
$(chatBoxID).hide();
// Show the chatbox when the button is pressed
$(“#” + name + “button”).click(function() {
if(currentChatID != null && currentChatID != chatBoxID) {
$(currentChatID).hide();
$(“#” + currentChatName + “button”).removeClass(“selected”);
}
if($(chatBoxID).css(“display”) == “none”) {
$(chatBoxID).show();
$(“#” + name + “button”).addClass(“selected”);
}
else {
$(chatBoxID).hide();
$(“#” + name + “button”).removeClass(“selected”);
}
currentChatID = chatBoxID;
currentChatName = name;
});
var chatInputID = “#” + name + “chatInput”;
// Wire to the chatbox’s typing a message enter
$(chatInputID).keypress(function(e) {
if(e.which == 13) {
// Send the message
var text = $(chatInputID).val();
var userID = null;
for(i=0;i<allUsers.length;i+=1) {
var u = allUsers[i];
if(u.Name == name) {
userID = u.ID;
break;
}
}
send(userID, text);
// Insert into the text body
var chatBodyID = “#” + name + “chatBody”;
var values = $(chatBodyID).val();
$(chatInputID).val(“”);
var myName = $(“#nicknameTextBox”).val();
insertToChatBody(name, “<b>” + myName + “: </b>” + text);
}
});
}
}

function send(user, text) {
var slCtrl = document.getElementById(“Xaml1”);
slCtrl.Content.PlexScriptApp.PostMessage(user, text);
}

function insertToChatBody(username, text) {
var newContent = “<div class=’chattext’>” + text + “</div>”;
var bodyID = username + “chatBody”;
$(“#” + bodyID).append(newContent);
var bodyDiv = document.getElementById(bodyID);
bodyDiv.scrollTop = bodyDiv.scrollHeight;
}

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @maifs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...