Skip to content

Commit da7e783

Browse files
author
ashfaq
committed
use our library
1 parent fd748af commit da7e783

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Greetr.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(function (global, $) {
1+
// If the other library injected before this didn't put semicolon at the end
2+
;(function (global, $) {
23

34
var Greetr = function (firstName, lastName, language) {
45
return new Greetr.init({ firstName, lastName, language })
@@ -61,6 +62,24 @@
6162
this.language = newlanguage;
6263
this.validate();
6364
return this
65+
},
66+
67+
HTMLGreeting: function(selector, formal){
68+
if(!$){
69+
throw new Error("jQuery not found");
70+
}
71+
if(!selector){
72+
throw new Error('misssing jQuery Selector ')
73+
}
74+
var msg;
75+
if(formal){
76+
msg = this.formalGreetings()
77+
}else{
78+
msg = this.greeting()
79+
}
80+
81+
$(selector).html(msg);
82+
return this;
6483
}
6584
};
6685

@@ -69,6 +88,7 @@
6988
self.firstName = firstName;
7089
self.lastName = lastName;
7190
self.language = language;
91+
this.validate();
7292
return self
7393
};
7494

app.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ g.greet();
44

55
// g.setLanguage("SDSD"); // unsupported language
66

7-
g.greet().greet(); // chanable functions
7+
// Used our chainable functions
8+
g.greet().greet();
89

910

1011
g.setLanguage('es');
1112

12-
g.greet().log();
13+
g.greet().log();
14+
15+
$('#login').click(function(){
16+
var loginGreetr = G$('ashfaq', 'ansari', 'en');
17+
// hide login from the screen
18+
$('#logindiv').hide();
19+
loginGreetr.setLanguage($('#language').val( )).HTMLGreeting('#greeting', true).log()
20+
})

framework.html

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33

44
</head>
55
<body>
6-
<meta charset="utf-8"/>
7-
6+
<meta charset="utf-8"/>
7+
<div class="logindiv" id="logindiv">
8+
<select id="language">
9+
<option value='en'>en</option>
10+
<option value='es'>es</option>
11+
</select>
12+
<input type="button", value="Login" id="login"/>
13+
</div>
14+
<h1 id="greeting" ></h1>
815
<script src="jquery-3.3.1.js"></script>
916
<script src="Greetr.js"></script>
1017
<script src="app.js"></script>

0 commit comments

Comments
 (0)