From b596364cf3f871887cce519291b684341cc5c014 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Sun, 8 Dec 2013 20:43:40 +0530 Subject: added nicEdit / on-the-fly question edit --- static/website/js/thread-user.js | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 static/website/js/thread-user.js (limited to 'static/website/js/thread-user.js') diff --git a/static/website/js/thread-user.js b/static/website/js/thread-user.js new file mode 100644 index 0000000..dbf9bdd --- /dev/null +++ b/static/website/js/thread-user.js @@ -0,0 +1,61 @@ +bkLib.onDomLoaded(function() { + + var questionNicEditor = new nicEditor({ + buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','image'], + iconsPath: "/static/website/js/nicEditorIcons.gif", + }); + questionNicEditor.setPanel('questionNicPanel'); + questionNicEditor.addInstance('questionInstance'); +}); + +$(document).ready(function() { + /*set the jquery variables */ + $question = $(".question"); + $modify = $(".modify"); + $edit = $(".modify .edit"); + $save = $(".modify .save"); + $questionNicPanel = $("#questionNicPanel"); + $questionInstance = $("#questionInstance"); + + /* make the question editable and show modify */ + $question.addClass("editable"); + $modify.show(); + + /* edit and save click events */ + function modify(thisObj){ + thisObj.hide(); + thisObj.next().css("display", "block"); + $questionNicPanel.show(); + $questionInstance.focus(); + } + $edit.click(function () { + modify($edit); + }); + $questionInstance.click(function() { + modify($edit); + }); + $save.click(function () { + $(this).hide(); + $questionNicPanel.hide(); + $(this).prev().css("display", "block"); + + /* make the ajax call */ + var id_length = $save.attr("id").length; + var question_id = parseInt($save.attr("id").substr(id_length-1)); + console.log(question_id); + var question_body = $questionInstance.html(); + $.ajax({ + url: "/ajax-question-update/", + data:{ + question_id: question_id, + question_body: question_body, + }, + type: "POST", + dataType: "html", + success: function(data){ + console.log(data); + } + }); + }); +}); + -- cgit