mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-06-27 16:00:04 +08:00
about to make big changes necessary for real-time editing
This commit is contained in:
+1
-1
@@ -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 ]);
|
||||
|
||||
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user