about to make big changes necessary for real-time editing

This commit is contained in:
Curtis SerVaas
2014-09-22 13:33:20 -04:00
parent 0b6c96a9cd
commit 56d174d7e6
7 changed files with 28 additions and 12 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ function addNode(data, socket){
var now = Date.now();
var callback = function(err, instance, now){
socket.emit("updateReceived", [modelJson._id ,instance, data[0]]);
socket.emit("updateReceived", [modelJson._id ,instance, data[0]]); //(update the ID)
socket.broadcast.emit("newNode", [ [parId,newIndex] , instance ]);
+3
View File
@@ -87,11 +87,14 @@ function attachLogInListeners(socket){
//This works for all ids except negative ids.
socket.on("editing", function(data){ //data=[id, Author.name]
console.log("EDITING received!");
console.log(data);
socket.broadcast.emit("editing", data);
});
socket.on("blurred", function(data){
console.log("BLURRED");
socket.broadcast.emit("blurred", data);
var id = data[0];
+8 -1
View File
@@ -1,6 +1,7 @@
$(function(){
//alert("jquery works");
INPUT_PROCESSED = true;
// editing = false;
myRouter = new AppRouter;
Backbone.history.start();
@@ -93,6 +94,12 @@ voInitializer = function(that, event){
console.log(nodesCollection);
console.log(vo.thisModel);
// if(!editing){
// // alert("editing!");
// socket.emit("editing", [vo.thisId, CurrentUser.google.name]);
// editing=true;
// }
@@ -116,7 +123,7 @@ voInitializer = function(that, event){
}
vo.grandParentModel = nodesCollection.findWhere({_id: vo.grandParentId});
vo.parentModel = nodesCollection.findWhere({_id: vo.parentId});
}
} //(vo-initializer)
+3 -3
View File
@@ -198,11 +198,11 @@ socket.on("editing", function(data){
var id = data[0];
var authorName = data[1];
console.log("EDITING RECEIVED + ID");
console.log(id);
if(id < 0){return;}
console.log(id, authorName);
if(id < 0){return;} //(ID is updated later) //(newNode is called);
var tempViews = nodesCollection.findWhere({_id: id}).get("views");
_.each(tempViews, function(tempView){
tempView.lock();
tempView.lock(authorName);
});
});
+2
View File
@@ -170,10 +170,12 @@ var showView = Backbone.View.extend({
lock: function(name){ //for concurrent editing...
this.$el.children().children("textarea").attr("readonly", "readonly");
this.$el.children().children("textarea").val(name + " is editing.");
this.$el.addClass("editing");
},
unlock: function(){
this.$el.children().children("textarea").removeAttr("readonly");
this.$el.children().children("textarea").val(this.model.get("text"));
this.$el.removeClass("editing");
},
removeNode: function(index){
var that = this;
+7 -4
View File
@@ -14,6 +14,7 @@ $(function(){
wrapper.html(html).addClass('markdown');
//editor.remove() is redundant.
alert("blur!!");
});
@@ -42,11 +43,12 @@ $(function(){
$("body").on("keydown", "textarea", keydownHandler);
$("body").on("focus", "textarea", function(event){
var that = this;
voInitializer(that, event);
// alert("editing"); console.log("EDITING");
var id = $(event.target).closest("li").attr("data-id");
keydownHandler(event);
socket.emit("editing", [id, CurrentUser.google.name]);
voInitializer(that, event);
keydownHandler(event);
//(This event is not firing for some reason..(I wonder if I put it at the top)).
});
$("body").on("blur", "textarea", function(event){
var thisLI = $(event.target).closest("li");
@@ -54,7 +56,8 @@ $(function(){
var text = thisLI.children().children("textarea").val();
$("textarea").textareaAutoExpand();
socket.emit("blurred", [id, text, CurrentUser]);
// alert("blur!!");
// editing=false;
});
$("body").on("click", ".transclude", function(event){
alert("Transclusion syncing with the server has not been implemented. KnownBugs:\n0.Don't make infinite loops.\n1.");
+4 -3
View File
@@ -29,7 +29,8 @@
background-repeat: no-repeat;
list-style: none;
/*background-image: url(smiley.png);
/*background-size: 15px 15px;
background-position: -1px 2px;
}
.root li.editing {
outline: 1px dotted black;
}