@websy/websy-designs 1.4.15 → 1.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,8 @@ router.post('/checkrecaptcha', function (req, res) {
12
12
  }
13
13
  console.log('recaptcha body')
14
14
  console.log(body)
15
- request.post(`https://www.google.com/recaptcha/api/siteverify?secret=${process.env.RECAPTCHA_SECRET}&response=${req.body.grecaptcharesponse}`, body, (err, response, body) => {
15
+ // request.post(`https://www.google.com/recaptcha/api/siteverify?secret=${process.env.RECAPTCHA_SECRET}&response=${req.body.grecaptcharesponse}`, body, (err, response, body) => {
16
+ request.post(`https://www.google.com/recaptcha/api/siteverify`, {form: body}, (err, response, body) => {
16
17
  if (err) {
17
18
  res.json({ err: err })
18
19
  }
@@ -194,7 +194,7 @@ class ButtonGroup {
194
194
  }
195
195
  this.options.activeItem = index
196
196
  if (this.options.onActivate) {
197
- this.options.onActivate(this.options.items[index], index)
197
+ this.options.onActivate(this.options.items[index], index, event)
198
198
  }
199
199
  const el = document.getElementById(this.elementId)
200
200
  let buttons = Array.from(el.querySelectorAll('.websy-button-group-item'))
@@ -2004,25 +2004,26 @@ class WebsyForm {
2004
2004
  checkRecaptcha () {
2005
2005
  return new Promise((resolve, reject) => {
2006
2006
  if (this.options.useRecaptcha === true) {
2007
- // if (this.recaptchaValue) {
2008
- grecaptcha.ready(() => {
2009
- grecaptcha.execute(ENVIRONMENT.RECAPTCHA_KEY, { action: 'submit' }).then(token => {
2010
- this.apiService.add('google/checkrecaptcha', {grecaptcharesponse: token}).then(response => {
2011
- if (response.success && response.success === true) {
2012
- resolve(true)
2013
- }
2014
- else {
2015
- reject(false)
2016
- }
2017
- })
2018
- }, err => {
2019
- reject(err)
2007
+ if (this.recaptchaValue) {
2008
+ // grecaptcha.ready(() => {
2009
+ // grecaptcha.execute(this.recaptchaValue, { action: 'submit' }).then(token => {
2010
+ this.apiService.add('google/checkrecaptcha', {grecaptcharesponse: this.recaptchaValue}).then(response => {
2011
+ if (response.success && response.success === true) {
2012
+ resolve(true)
2013
+ grecaptcha.reset(`${this.elementId}_recaptcha`, {sitekey: ENVIRONMENT.RECAPTCHA_KEY})
2014
+ }
2015
+ else {
2016
+ resolve(false)
2017
+ }
2020
2018
  })
2021
- })
2022
- // }
2023
- // else {
2024
- // reject(false)
2025
- // }
2019
+ // }, err => {
2020
+ // reject(err)
2021
+ // })
2022
+ // })
2023
+ }
2024
+ else {
2025
+ resolve(false)
2026
+ }
2026
2027
  }
2027
2028
  else {
2028
2029
  resolve(true)
@@ -2092,10 +2093,12 @@ class WebsyForm {
2092
2093
  recaptchaReady () {
2093
2094
  const el = document.getElementById(`${this.elementId}_recaptcha`)
2094
2095
  if (el) {
2095
- grecaptcha.render(`${this.elementId}_recaptcha`, {
2096
- sitekey: ENVIRONMENT.RECAPTCHA_KEY,
2097
- callback: this.validateRecaptcha.bind(this)
2098
- })
2096
+ grecaptcha.ready(() => {
2097
+ grecaptcha.render(`${this.elementId}_recaptcha`, {
2098
+ sitekey: ENVIRONMENT.RECAPTCHA_KEY,
2099
+ callback: this.validateRecaptcha.bind(this)
2100
+ })
2101
+ })
2099
2102
  }
2100
2103
  }
2101
2104
  render (update, data) {
@@ -2150,6 +2153,12 @@ class WebsyForm {
2150
2153
  `
2151
2154
  }
2152
2155
  })
2156
+ if (this.options.useRecaptcha === true) {
2157
+ html += `
2158
+ --><div id='${this.elementId}_recaptcha' data-sitekey='${ENVIRONMENT.RECAPTCHA_KEY}' class='websy-form-recaptcha'></div>
2159
+ <div id='${this.elementId}_recaptchaError' class='websy-alert websy-alert-error websy-hidden'>Invalid recaptcha response</div><!--
2160
+ `
2161
+ }
2153
2162
  html += `
2154
2163
  --><button class="websy-btn submit ${this.options.submit.classes || ''}">${this.options.submit.text || 'Save'}</button>${this.options.cancel ? '<!--' : ''}
2155
2164
  `
@@ -2162,24 +2171,30 @@ class WebsyForm {
2162
2171
  </form>
2163
2172
  <div id="${this.elementId}_validationFail" class="websy-validation-failure"></div>
2164
2173
  `
2165
- if (this.options.useRecaptcha === true) {
2166
- html += `
2167
- <div id='${this.elementId}_recaptcha'></div>
2168
- `
2169
- }
2170
2174
  el.innerHTML = html
2171
2175
  this.processComponents(componentsToProcess, () => {
2172
2176
  if (this.options.useRecaptcha === true && typeof grecaptcha !== 'undefined') {
2173
- // this.recaptchaReady()
2177
+ this.recaptchaReady()
2174
2178
  }
2175
2179
  })
2176
2180
  }
2177
2181
  }
2178
2182
  submitForm () {
2179
2183
  const formEl = document.getElementById(`${this.elementId}Form`)
2184
+ const buttonEl = formEl.querySelector('button.websy-btn.submit')
2185
+ const recaptchErrEl = document.getElementById(`${this.elementId}_recaptchaError`)
2180
2186
  if (formEl.reportValidity() === true) {
2187
+ if (buttonEl) {
2188
+ buttonEl.setAttribute('disabled', true)
2189
+ }
2181
2190
  this.checkRecaptcha().then(result => {
2182
- if (result === true) {
2191
+ if (buttonEl) {
2192
+ buttonEl.removeAttribute('disabled')
2193
+ }
2194
+ if (result === true) {
2195
+ if (recaptchErrEl) {
2196
+ recaptchErrEl.classList.add('websy-hidden')
2197
+ }
2183
2198
  const formData = new FormData(formEl)
2184
2199
  const data = {}
2185
2200
  const temp = new FormData(formEl)
@@ -2199,6 +2214,7 @@ class WebsyForm {
2199
2214
  // this.render()
2200
2215
  formEl.reset()
2201
2216
  }
2217
+ buttonEl.removeAttribute('disabled')
2202
2218
  this.options.onSuccess.call(this, result)
2203
2219
  }, err => {
2204
2220
  console.log('Error submitting form data:', err)
@@ -2215,7 +2231,12 @@ class WebsyForm {
2215
2231
  }
2216
2232
  }
2217
2233
  else {
2218
- console.log('bad recaptcha')
2234
+ if (buttonEl) {
2235
+ buttonEl.removeAttribute('disabled')
2236
+ }
2237
+ if (recaptchErrEl) {
2238
+ recaptchErrEl.classList.remove('websy-hidden')
2239
+ }
2219
2240
  }
2220
2241
  })
2221
2242
  }
@@ -2517,6 +2538,12 @@ class WebsyNavigationMenu {
2517
2538
  event.target.classList.toggle('menu-open')
2518
2539
  this.toggleMenu(item.id)
2519
2540
  }
2541
+ else {
2542
+ const el = document.getElementById(this.elementId)
2543
+ const allEls = el.querySelectorAll('.websy-menu-header')
2544
+ Array.from(allEls).forEach(e => e.classList.remove('active'))
2545
+ event.target.classList.add('active')
2546
+ }
2520
2547
  }
2521
2548
  if (event.target.classList.contains('websy-menu-mask')) {
2522
2549
  this.toggleMobileMenu()
@@ -2600,6 +2627,23 @@ class WebsyNavigationMenu {
2600
2627
  html += `</div>`
2601
2628
  }
2602
2629
  el.innerHTML = html
2630
+ // open the menu if an item is set as 'active'
2631
+ const activeEl = el.querySelector('.websy-menu-header.active')
2632
+ if (activeEl) {
2633
+ let parent = activeEl.parentElement
2634
+ while (parent) {
2635
+ if (parent.tagName === 'UL') {
2636
+ parent.classList.remove('websy-menu-collapsed')
2637
+ parent = parent.parentElement
2638
+ }
2639
+ else if (parent.tagName === 'LI') {
2640
+ parent = parent.parentElement
2641
+ }
2642
+ else {
2643
+ parent = null
2644
+ }
2645
+ }
2646
+ }
2603
2647
  if (this.options.enableSearch === true) {
2604
2648
  this.search = new WebsyDesigns.Search(`${this.elementId}_search`, Object.assign({}, {
2605
2649
  onSearch: this.handleSearch.bind(this),
@@ -2628,7 +2672,7 @@ class WebsyNavigationMenu {
2628
2672
  }
2629
2673
  html += `
2630
2674
  <li class='websy-${this.options.orientation}-list-item ${items[i].alwaysOpen === true ? 'always-open' : ''}'>
2631
- <div class='websy-menu-header ${items[i].classes || ''} ${selected} ${active}'
2675
+ <div class='websy-menu-header websy-menu-level-${level} ${items[i].classes || ''} ${selected} ${active}'
2632
2676
  id='${blockId}'
2633
2677
  data-id='${currentBlock}'
2634
2678
  data-path='${items[i].path}'