-
Notifications
You must be signed in to change notification settings - Fork 1
/
writingarea.js
33 lines (27 loc) · 932 Bytes
/
writingarea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function WritingArea (element){
this.domElement = element;
element.model = this;
this.hasDefault = true;
this.currentSnippet = null;
}
WritingArea.prototype.setPlaceholder = function(toggle){
if(toggle) addClass(this.domElement, "placeholder");
else removeClass(this.domElement, "placeholder");
};
WritingArea.prototype.clear = function(){
this.domElement.value = "";
};
WritingArea.prototype.makeSnippet = function(){
if(!this.currentSnippet) this.currentSnippet = new Snippet(this.domElement.value);
else this.currentSnippet.update(this.domElement.value);
return this.currentSnippet;
};
WritingArea.prototype.loadSnippet = function(snippet){
this.currentSnippet = snippet;
this.domElement.value = snippet.content;
this.hasDefault = false;
this.setPlaceholder(false);
};
WritingArea.prototype.wordCount = function(){
return this.domElement.value.trim().replace(/\s+/g, ' ').split([" "]).length;
};