Skip to content

Commit c381162

Browse files
committed
String formatting moved to the class constructor
1 parent d36cb7d commit c381162

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

examples/questionnaire/Example.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<a class="f-enter-desc"
5252
href="#"
5353
v-on:click.prevent="onSendData()"
54-
v-html="language.formatKey(language.pressEnter)">
54+
v-html="language.pressEnter">
5555
</a>
5656
</div>
5757

examples/quiz/Example.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
class="f-enter-desc"
5050
href="#"
5151
v-on:click.prevent="onQuizSubmit()"
52-
v-html="language.formatKey(language.pressEnter)">
52+
v-html="language.pressEnter">
5353
</a>
5454
</div>
5555
<p class="text-success" v-if="submitted && score < 4">"You scored {{ score }} out of {{ total }}. There's a lot of room for improvement."</p>

src/components/FlowForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
href="#"
4545
v-on:click.prevent="submit()"
4646
v-if="!submitted"
47-
v-html="language.formatKey(language.pressEnter)">
47+
v-html="language.pressEnter">
4848
</a>
4949
</slot>
5050
</div>

src/components/Question.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<span class="f-sub" v-if="question.subtitle || question.type === QuestionType.LongText || question.multiple">
3232
<span v-if="question.subtitle">{{ question.subtitle }}</span>
3333

34-
<span class="f-help" v-if="question.type === QuestionType.LongText && !isMobile" v-html="question.helpText || language.formatKey(language.longTextHelpText)"></span>
34+
<span class="f-help" v-if="question.type === QuestionType.LongText && !isMobile" v-html="question.helpText || language.longTextHelpText"></span>
3535

3636
<span class="f-help" v-if="question.multiple">{{ question.helpText || language.multipleChoiceHelpText }}</span>
3737
</span>
@@ -67,7 +67,7 @@
6767
href="#"
6868
v-if="question.type !== QuestionType.LongText || !isMobile"
6969
v-on:click.prevent="onEnter"
70-
v-html="language.formatKey(language.pressEnter)">
70+
v-html="language.pressEnter">
7171
</a>
7272
</div>
7373

src/models/LanguageModel.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ export default class LanguageModel {
2929
this.ariaMultipleChoice = 'Press :letter to select'
3030
this.ariaTypeAnswer = 'Type your answer here'
3131

32+
33+
3234
Object.assign(this, options || {})
33-
}
34-
// Inserts a new CSS class into the language model string to format the :key
35-
formatKey(value) {
36-
if (!value) return ''
37-
let stringArr = value.toString().split(" ")
38-
for (let i = 0; i < stringArr.length; i++) {
39-
if (stringArr[i].slice(0,4) === ":key") {
40-
stringArr[i] = '<span class="f-language-key">' + stringArr[i].substring(5, stringArr[i].length - 1) + '</span>'
41-
}
35+
36+
// Inserts a new CSS class into the language model string to format the :key
37+
Object.keys(this).forEach(property => {
38+
if (!this[property]) return ''
39+
let stringArr = this[property].toString().split(" ")
40+
for (let i = 0; i < stringArr.length; i++) {
41+
if (stringArr[i].slice(0, 4) === ":key") {
42+
stringArr[i] = '<span class="f-language-key">' + stringArr[i].substring(5, stringArr[i].length - 1) + '</span>'
43+
}
4244
}
43-
return stringArr.join(" ")
44-
}
45+
this[property] = stringArr.join(" ")
46+
});
47+
}
4548
}
4649

0 commit comments

Comments
 (0)