]>
git.ipfire.org Git - ipfire.org.git/blob - src/static/js/editor.js
3 this.parent
= $(parent
);
6 this.textarea
= this.parent
.find("textarea");
8 // Make the textarea magic
9 this.activateTextArea();
14 console
.log("Editor initialised for " + this.parent
);
20 // Remember any selected text
21 this.textarea
.select(function() {
23 start
: this.selectionStart
,
24 end
: this.selectionEnd
,
25 text
: this.value
.slice(this.selectionStart
, this.selectionEnd
)
28 console
.debug("Something got selected:");
29 console
.debug(editor
.selection
);
34 this.parent
.find("#bold").click(this.bold
.bind(this));
35 this.parent
.find("#italic").click(this.italic
.bind(this));
38 // Functions to modify the text
40 replaceSelection(replacement
) {
41 var text
= this.textarea
.val();
43 text
= text
.slice(0, this.selection
.start
) + replacement
+ text
.slice(this.selection
.end
);
45 // Write text to textarea
46 this.textarea
.val(text
);
50 console
.debug("Converting into bold: " + this.selection
.text
);
51 this.replaceSelection("**" + this.selection
.text
+ "**");
55 console
.debug("Converting into italic: " + this.selection
.text
);
56 this.replaceSelection("*" + this.selection
.text
+ "*");
60 $(document
).ready(function() {
61 // Initialise all editors
62 $(".editor").each(function(i
, e
) {