mirror of
https://github.com/Codiad/Codiad.git
synced 2026-03-24 01:46:51 +01:00
Hook listener to changeCursor event.
This commit is contained in:
@@ -26,5 +26,10 @@
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
if (isset($_POST["cursor"]) && !empty($_POST["cursor"])) {
|
||||
$data = json_decode($_POST["cursor"]);
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -23,10 +23,16 @@
|
||||
|
||||
codiad.collaborative = {
|
||||
|
||||
controller: 'components/collaborative/collaborative.php',
|
||||
controller: 'components/collaborative/controler.php',
|
||||
|
||||
init: function () {
|
||||
this.$onDocumentChange = this.onDocumentChange.bind(this);
|
||||
this.$onCursorChange = this.onCursorChange.bind(this);
|
||||
},
|
||||
|
||||
addListeners: function () {
|
||||
this.addListenerToOnDocumentChange();
|
||||
this.addListenerToOnCursorChange();
|
||||
},
|
||||
|
||||
addListenerToOnDocumentChange: function () {
|
||||
@@ -39,6 +45,16 @@
|
||||
session.removeEventListener('change', this.$onDocumentChange);
|
||||
},
|
||||
|
||||
addListenerToOnCursorChange: function () {
|
||||
var selection = this._getSelection();
|
||||
selection.addEventListener('changeCursor', this.$onCursorChange);
|
||||
},
|
||||
|
||||
removeListenerToOnCursorChange: function () {
|
||||
var selection = this._getSelection();
|
||||
selection.removeEventListener('changeCursor', this.$onCursorChange);
|
||||
},
|
||||
|
||||
onDocumentChange: function (e) {
|
||||
console.log('document change');
|
||||
var post = { change: JSON.stringify(e.data) };
|
||||
@@ -49,8 +65,24 @@
|
||||
url: this.controller,
|
||||
data: post,
|
||||
complete: function (data) {
|
||||
console.log('complete');
|
||||
console.log(data.text);
|
||||
console.log('complete doc change');
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onCursorChange: function (e) {
|
||||
console.log('cursor change');
|
||||
var post = { cursor: JSON.stringify(this._getSelection().getRange()) };
|
||||
console.log(post);
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: this.controller,
|
||||
data: post,
|
||||
complete: function (data) {
|
||||
console.log('complete cursor');
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -64,6 +96,10 @@
|
||||
return codiad.editor.getActive().getSession();
|
||||
},
|
||||
|
||||
_getSelection: function () {
|
||||
return codiad.editor.getActive().getSelection();
|
||||
},
|
||||
|
||||
_getDocument: function () {
|
||||
return codiad.editor.getActive().getSession().getDocument();
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@
|
||||
$.ctrl('32', function() {
|
||||
// TODO remove this it is for testing purpose.
|
||||
// codiad.autocomplete.suggest();
|
||||
console.log('add listener.');
|
||||
codiad.collaborative.addListenerToOnDocumentChange();
|
||||
console.log('add listeners.');
|
||||
codiad.collaborative.addListeners();
|
||||
});
|
||||
|
||||
$.ctrl('71', function(){
|
||||
|
||||
Reference in New Issue
Block a user