@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.
@@ -198,7 +198,7 @@ class ButtonGroup {
198
198
  }
199
199
  this.options.activeItem = index
200
200
  if (this.options.onActivate) {
201
- this.options.onActivate(this.options.items[index], index)
201
+ this.options.onActivate(this.options.items[index], index, event)
202
202
  }
203
203
  const el = document.getElementById(this.elementId)
204
204
  let buttons = Array.from(el.querySelectorAll('.websy-button-group-item'))
@@ -2202,25 +2202,26 @@ class WebsyForm {
2202
2202
  checkRecaptcha () {
2203
2203
  return new Promise((resolve, reject) => {
2204
2204
  if (this.options.useRecaptcha === true) {
2205
- // if (this.recaptchaValue) {
2206
- grecaptcha.ready(() => {
2207
- grecaptcha.execute(ENVIRONMENT.RECAPTCHA_KEY, { action: 'submit' }).then(token => {
2208
- this.apiService.add('google/checkrecaptcha', {grecaptcharesponse: token}).then(response => {
2209
- if (response.success && response.success === true) {
2210
- resolve(true)
2211
- }
2212
- else {
2213
- reject(false)
2214
- }
2215
- })
2216
- }, err => {
2217
- reject(err)
2205
+ if (this.recaptchaValue) {
2206
+ // grecaptcha.ready(() => {
2207
+ // grecaptcha.execute(this.recaptchaValue, { action: 'submit' }).then(token => {
2208
+ this.apiService.add('google/checkrecaptcha', {grecaptcharesponse: this.recaptchaValue}).then(response => {
2209
+ if (response.success && response.success === true) {
2210
+ resolve(true)
2211
+ grecaptcha.reset(`${this.elementId}_recaptcha`, {sitekey: ENVIRONMENT.RECAPTCHA_KEY})
2212
+ }
2213
+ else {
2214
+ resolve(false)
2215
+ }
2218
2216
  })
2219
- })
2220
- // }
2221
- // else {
2222
- // reject(false)
2223
- // }
2217
+ // }, err => {
2218
+ // reject(err)
2219
+ // })
2220
+ // })
2221
+ }
2222
+ else {
2223
+ resolve(false)
2224
+ }
2224
2225
  }
2225
2226
  else {
2226
2227
  resolve(true)
@@ -2290,10 +2291,12 @@ class WebsyForm {
2290
2291
  recaptchaReady () {
2291
2292
  const el = document.getElementById(`${this.elementId}_recaptcha`)
2292
2293
  if (el) {
2293
- grecaptcha.render(`${this.elementId}_recaptcha`, {
2294
- sitekey: ENVIRONMENT.RECAPTCHA_KEY,
2295
- callback: this.validateRecaptcha.bind(this)
2296
- })
2294
+ grecaptcha.ready(() => {
2295
+ grecaptcha.render(`${this.elementId}_recaptcha`, {
2296
+ sitekey: ENVIRONMENT.RECAPTCHA_KEY,
2297
+ callback: this.validateRecaptcha.bind(this)
2298
+ })
2299
+ })
2297
2300
  }
2298
2301
  }
2299
2302
  render (update, data) {
@@ -2348,6 +2351,12 @@ class WebsyForm {
2348
2351
  `
2349
2352
  }
2350
2353
  })
2354
+ if (this.options.useRecaptcha === true) {
2355
+ html += `
2356
+ --><div id='${this.elementId}_recaptcha' data-sitekey='${ENVIRONMENT.RECAPTCHA_KEY}' class='websy-form-recaptcha'></div>
2357
+ <div id='${this.elementId}_recaptchaError' class='websy-alert websy-alert-error websy-hidden'>Invalid recaptcha response</div><!--
2358
+ `
2359
+ }
2351
2360
  html += `
2352
2361
  --><button class="websy-btn submit ${this.options.submit.classes || ''}">${this.options.submit.text || 'Save'}</button>${this.options.cancel ? '<!--' : ''}
2353
2362
  `
@@ -2360,24 +2369,30 @@ class WebsyForm {
2360
2369
  </form>
2361
2370
  <div id="${this.elementId}_validationFail" class="websy-validation-failure"></div>
2362
2371
  `
2363
- if (this.options.useRecaptcha === true) {
2364
- html += `
2365
- <div id='${this.elementId}_recaptcha'></div>
2366
- `
2367
- }
2368
2372
  el.innerHTML = html
2369
2373
  this.processComponents(componentsToProcess, () => {
2370
2374
  if (this.options.useRecaptcha === true && typeof grecaptcha !== 'undefined') {
2371
- // this.recaptchaReady()
2375
+ this.recaptchaReady()
2372
2376
  }
2373
2377
  })
2374
2378
  }
2375
2379
  }
2376
2380
  submitForm () {
2377
2381
  const formEl = document.getElementById(`${this.elementId}Form`)
2382
+ const buttonEl = formEl.querySelector('button.websy-btn.submit')
2383
+ const recaptchErrEl = document.getElementById(`${this.elementId}_recaptchaError`)
2378
2384
  if (formEl.reportValidity() === true) {
2385
+ if (buttonEl) {
2386
+ buttonEl.setAttribute('disabled', true)
2387
+ }
2379
2388
  this.checkRecaptcha().then(result => {
2380
- if (result === true) {
2389
+ if (buttonEl) {
2390
+ buttonEl.removeAttribute('disabled')
2391
+ }
2392
+ if (result === true) {
2393
+ if (recaptchErrEl) {
2394
+ recaptchErrEl.classList.add('websy-hidden')
2395
+ }
2381
2396
  const formData = new FormData(formEl)
2382
2397
  const data = {}
2383
2398
  const temp = new FormData(formEl)
@@ -2397,6 +2412,7 @@ class WebsyForm {
2397
2412
  // this.render()
2398
2413
  formEl.reset()
2399
2414
  }
2415
+ buttonEl.removeAttribute('disabled')
2400
2416
  this.options.onSuccess.call(this, result)
2401
2417
  }, err => {
2402
2418
  console.log('Error submitting form data:', err)
@@ -2413,7 +2429,12 @@ class WebsyForm {
2413
2429
  }
2414
2430
  }
2415
2431
  else {
2416
- console.log('bad recaptcha')
2432
+ if (buttonEl) {
2433
+ buttonEl.removeAttribute('disabled')
2434
+ }
2435
+ if (recaptchErrEl) {
2436
+ recaptchErrEl.classList.remove('websy-hidden')
2437
+ }
2417
2438
  }
2418
2439
  })
2419
2440
  }
@@ -2776,6 +2797,12 @@ class WebsyNavigationMenu {
2776
2797
  event.target.classList.toggle('menu-open')
2777
2798
  this.toggleMenu(item.id)
2778
2799
  }
2800
+ else {
2801
+ const el = document.getElementById(this.elementId)
2802
+ const allEls = el.querySelectorAll('.websy-menu-header')
2803
+ Array.from(allEls).forEach(e => e.classList.remove('active'))
2804
+ event.target.classList.add('active')
2805
+ }
2779
2806
  }
2780
2807
  if (event.target.classList.contains('websy-menu-mask')) {
2781
2808
  this.toggleMobileMenu()
@@ -2859,6 +2886,23 @@ class WebsyNavigationMenu {
2859
2886
  html += `</div>`
2860
2887
  }
2861
2888
  el.innerHTML = html
2889
+ // open the menu if an item is set as 'active'
2890
+ const activeEl = el.querySelector('.websy-menu-header.active')
2891
+ if (activeEl) {
2892
+ let parent = activeEl.parentElement
2893
+ while (parent) {
2894
+ if (parent.tagName === 'UL') {
2895
+ parent.classList.remove('websy-menu-collapsed')
2896
+ parent = parent.parentElement
2897
+ }
2898
+ else if (parent.tagName === 'LI') {
2899
+ parent = parent.parentElement
2900
+ }
2901
+ else {
2902
+ parent = null
2903
+ }
2904
+ }
2905
+ }
2862
2906
  if (this.options.enableSearch === true) {
2863
2907
  this.search = new WebsyDesigns.Search(`${this.elementId}_search`, Object.assign({}, {
2864
2908
  onSearch: this.handleSearch.bind(this),
@@ -2887,7 +2931,7 @@ class WebsyNavigationMenu {
2887
2931
  }
2888
2932
  html += `
2889
2933
  <li class='websy-${this.options.orientation}-list-item ${items[i].alwaysOpen === true ? 'always-open' : ''}'>
2890
- <div class='websy-menu-header ${items[i].classes || ''} ${selected} ${active}'
2934
+ <div class='websy-menu-header websy-menu-level-${level} ${items[i].classes || ''} ${selected} ${active}'
2891
2935
  id='${blockId}'
2892
2936
  data-id='${currentBlock}'
2893
2937
  data-path='${items[i].path}'
@@ -8602,7 +8646,7 @@ function recaptchaReadyCallBack () {
8602
8646
  // need a way of initializing these based on environment variables
8603
8647
  function useGoogleRecaptcha (key) {
8604
8648
  const rcs = document.createElement('script')
8605
- rcs.src = `//www.google.com/recaptcha/api.js?render=${key}`
8649
+ rcs.src = `//www.google.com/recaptcha/api.js`
8606
8650
  document.body.appendChild(rcs)
8607
8651
  }
8608
8652