mirror of
https://github.com/Codiad/Codiad.git
synced 2026-03-25 02:16:52 +01:00
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
/*
|
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
|
* as-is and without warranty under the MIT License. See
|
|
* [root]/license.txt for more. This information must remain intact.
|
|
*/
|
|
|
|
(function (global, $) {
|
|
|
|
var codiad = global.codiad;
|
|
|
|
$(function () {
|
|
codiad.collaborative.init();
|
|
});
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
//
|
|
// Collaborative Component for Codiad
|
|
// ---------------------------------
|
|
// Displays in real time the cursor position and
|
|
// the changes when concurrently editing files.
|
|
//
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
codiad.collaborative = {
|
|
|
|
controller: 'components/collaborative/collaborative.php',
|
|
|
|
init: function () {
|
|
this.$onDocumentChange = this.onDocumentChange.bind(this);
|
|
},
|
|
|
|
addListenerToOnDocumentChange: function () {
|
|
var session = this._getEditSession();
|
|
session.addEventListener('change', this.$onDocumentChange);
|
|
},
|
|
|
|
removeListenerToOnDocumentChange: function () {
|
|
var session = this._getEditSession();
|
|
session.removeEventListener('change', this.$onDocumentChange);
|
|
},
|
|
|
|
onDocumentChange: function (e) {
|
|
console.log('document change');
|
|
var post = { change: JSON.stringify(e.data) };
|
|
console.log(post);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: this.controller,
|
|
data: post,
|
|
complete: function (data) {
|
|
console.log('complete');
|
|
console.log(data.text);
|
|
}
|
|
});
|
|
},
|
|
|
|
/* Set of helper methods to manipulate the editor. */
|
|
_getEditor: function () {
|
|
return codiad.editor.getActive();
|
|
},
|
|
|
|
_getEditSession: function () {
|
|
return codiad.editor.getActive().getSession();
|
|
},
|
|
|
|
_getDocument: function () {
|
|
return codiad.editor.getActive().getSession().getDocument();
|
|
}
|
|
|
|
};
|
|
|
|
})(this, jQuery);
|
|
|
|
|