Commit 8e9e75ce authored by bbaer's avatar bbaer
Browse files

Added initialization

parent c58a80bd
......@@ -31,24 +31,30 @@ var QfqNS = QfqNS || {};
* @param $target Reference to the HTML Element where the output (comment JSON)
* should be stored.
*/
n.CodeCorrection = function (form, data, $container, $target, currentUser, language) {
this.form = form;
this.data = data;
n.CodeCorrection = function () {
this.page = {};
this.data = {};
this.eventEmitter = new EventEmitter();
this.$parent = $container;
this.$target = $target;
this.$parent = {};
this.$target = {};
this.$rows = [];
this.annotations = [];
this.users = [];
this.currentUser = currentUser;
this.language = language;
this.currentUser = {};
this.language = "";
this.syntaxHighlight = {};
};
/**
* Initializes the Code Correction object, fetches data from URL or API if needed
*/
n.CodeCorrection.prototype.initialize = function() {
n.CodeCorrection.prototype.initialize = function($container, page) {
this.$parent = $container;
this.$target = $("#" + $container.data("target"));
this.data = {
url: $container.data("file")
};
this.currentUser = $container.data("uid");
var that = this;
if (this.$target.val()) {
var jImport = $.parseJSON(this.$target.val());
......@@ -132,11 +138,19 @@ var QfqNS = QfqNS || {};
var $hook = this.$rows[annotation.lineNumber];
var commentController = this._buildCommentContainer($hook);
commentController.importComments(annotation.comments, this.users);
this._setListeners(commentController);
this._setCommentController(annotation.lineNumber, commentController);
}
};
n.CodeCorrection.prototype._setCommentMarker = function($hook, numberOfComments) {
var container = $('<span/>', {
class: "badge",
text: numberOfComments
});
};
/**
* Builds a Line as a combination of HTML Elements. Binds the necessary Events.
*
......@@ -158,7 +172,13 @@ var QfqNS = QfqNS || {};
});
var cLine = line.replace(/\s/g, '&nbsp;')
.replace('<', '&lt;')
.replace('>', '&gt;');
.replace('>', '&gt;')
.replace('&', '&amp;')
.replace(';', '&semi;')
.replace('"', '&quot;')
.replace('\'', '&apos;')
.replace('\\', '&bsol;')
.replace('/', '&sol;');
cLine = this.syntaxHighlight.highlightLine(cLine);
var htmlCodeLine = $('<div/>', {
class: 'pull-right qfqCode'
......
......@@ -100,6 +100,15 @@ var QfqNS = QfqNS || {};
n.Log.error(e.message);
}
try {
$(".annotate-text").each(function() {
var codeCorrection = new QfqNS.CodeCorrection();
codeCorrection.initialize($(this), page);
});
} catch (e) {
n.Log.error(e.message);
}
QfqNS.TypeAhead.install(this.settings.typeAheadUrl);
QfqNS.CharacterCount.initialize();
};
......
......@@ -43,9 +43,9 @@
<div class="col-md-8">
<div class="annotate-text"
data-uid='{uid: 5, name: "Definitely not an AI", avatar: "mockData/avatar1.png"}' <!-- logged in user -->
data-file="../javascript/src/CodeCorrection.js" <!-- File to correct -->
data-target="codeCorrection-output1" <!-- input field -->
data-uid='{uid: 5, name: "Definitely not an AI", avatar: "mockData/avatar1.png"}'
data-file="../javascript/src/CodeCorrection.js"
data-target="codeCorrection-output1"
data-highlight="javascript"
>
</div>
......@@ -98,15 +98,14 @@
QfqNS.Log.level = 0;
var codeCorrection = new QfqNS.CodeCorrection(qfqPage, {
url: '../javascript/src/CodeCorrection.js'
}, $('.annotate-text'), $('#codeCorrection-output1'), {
uid: 5,
name: "Definitely not an AI",
avatar: "mockData/avatar1.png"
}, 'http://localhost:63342/qfq/mockup/mockData/javascript.json');
codeCorrection.initialize();
//var codeCorrection = new QfqNS.CodeCorrection(qfqPage, {
// url: '../javascript/src/CodeCorrection.js'
//}, $('.annotate-text'), $('#codeCorrection-output1'), {
// uid: 5,
// name: "Definitely not an AI",
// avatar: "mockData/avatar1.png"
//}, 'http://localhost:63342/qfq/mockup/mockData/javascript.json');
//codeCorrection.initialize();
});
</script>
</body>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment