|
1 | 1 | /*! |
2 | | - * WhatsApp Widget v1.0.2 (c) 2020 - Fajar Setya Budi |
| 2 | + * WhatsApp Widget v1.1.0 (c) 2020 - Fajar Setya Budi |
3 | 3 | * Contributors (https://github.com/agraris/whatsapp-widget/graphs/contributors) |
4 | 4 | * Licensed under MIT (https://github.com/agraris/whatsapp-widget/blob/master/LICENSE) |
5 | 5 | * WhatsApp Widget does not affiliate with WhatsApp Inc. in any way. |
|
153 | 153 | }, { |
154 | 154 | key: "_sendMessage", |
155 | 155 | value: function _sendMessage() { |
156 | | - var _this = this; |
157 | | - |
158 | 156 | if (!/^\d+$/.test(this._phoneNumber)) { |
159 | 157 | throw new Error('Phone number (' + this._phoneNumber + ') is invalid.'); |
160 | 158 | } |
|
165 | 163 |
|
166 | 164 | var parameters = send_url + this._phoneNumber + '?text='; |
167 | 165 | var valid = true; |
168 | | - inputs.forEach(function (item) { |
169 | | - if (!_this._formValidation(item)) return valid = false; |
| 166 | + |
| 167 | + for (var i = 0; i < inputs.length; i++) { |
| 168 | + var item = inputs[i]; |
| 169 | + if (!this._formValidation(item)) valid = false; |
170 | 170 | var title = item.getAttribute('data-message'); |
171 | 171 | parameters += title.replace(/^./, title[0].toUpperCase()) + ': ' + item.value + '%0A'; |
172 | | - }); |
| 172 | + } |
| 173 | + |
173 | 174 | if (valid) window.open(parameters, '_blank'); |
174 | 175 | } |
175 | 176 | }, { |
|
189 | 190 | }, { |
190 | 191 | key: "_cacheElements", |
191 | 192 | value: function _cacheElements() { |
192 | | - var _this2 = this; |
| 193 | + var _this = this; |
193 | 194 |
|
194 | 195 | this._toggleChat = document.querySelector("".concat(SELECTOR_DATA_TOGGLE_CHAT, "[data-target=\"#").concat(this._element.id, "\"]")); |
195 | 196 | this._contentElement = this._element.getElementsByClassName(CLASS_NAME_WIDGET_CONTENT).item(0); |
|
199 | 200 | this._toggleChat.addEventListener("click", function (e) { |
200 | 201 | e.preventDefault(); |
201 | 202 |
|
202 | | - _this2.toggle(); |
| 203 | + _this.toggle(); |
203 | 204 | }); |
204 | 205 | } |
205 | 206 |
|
206 | 207 | if (this._toggleSend) { |
207 | 208 | this._toggleSend.addEventListener('click', function (e) { |
208 | 209 | e.preventDefault(); |
209 | 210 |
|
210 | | - _this2._sendMessage(); |
| 211 | + _this._sendMessage(); |
211 | 212 | }); |
212 | 213 | } |
213 | 214 | } |
214 | 215 | }, { |
215 | 216 | key: "_show", |
216 | 217 | value: function _show() { |
217 | | - var _this3 = this; |
| 218 | + var _this2 = this; |
218 | 219 |
|
219 | 220 | this._element.classList.add(CLASS_NAME_WIDGET_EXPANDED); |
220 | 221 |
|
|
224 | 225 |
|
225 | 226 | this._isShown = true; |
226 | 227 | Object.keys(ChatData).forEach(function (key) { |
227 | | - if (key !== _this3._element.id && ChatData[key]._isShown) ChatData[key].toggle(); |
| 228 | + if (key !== _this2._element.id && ChatData[key]._isShown) ChatData[key].toggle(); |
228 | 229 | }); |
229 | 230 | } |
230 | 231 | }, { |
|
276 | 277 | }, { |
277 | 278 | key: "_typeCheckConfig", |
278 | 279 | value: function _typeCheckConfig(componentName, config, configTypes) { |
279 | | - var _this4 = this; |
| 280 | + var _this3 = this; |
280 | 281 |
|
281 | 282 | Object.keys(configTypes).forEach(function (property) { |
282 | 283 | var expectedTypes = configTypes[property]; |
283 | 284 | var value = config[property]; |
284 | | - var valueType = value && _this4._isElement(value) ? 'element' : _this4._toType(value); |
| 285 | + var valueType = value && _this3._isElement(value) ? 'element' : _this3._toType(value); |
285 | 286 |
|
286 | 287 | if (!new RegExp(expectedTypes).test(valueType)) { |
287 | 288 | throw new Error("".concat(componentName.toUpperCase(), ": ") + "Option \"".concat(property, "\" provided type \"").concat(valueType, "\" ") + "but expected type \"".concat(expectedTypes, "\".")); |
|
0 commit comments