@websy/websy-designs 1.4.14 → 1.4.16

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.
@@ -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
  }
@@ -2786,7 +2807,7 @@ class WebsyNavigationMenu {
2786
2807
  let lowestItems = this.flatItems.filter(d => d.level === this.maxLevel)
2787
2808
  let visibleItems = lowestItems
2788
2809
  let defaultMethod = 'remove'
2789
- if (searchText.length > 1) {
2810
+ if (searchText && searchText.length > 1) {
2790
2811
  defaultMethod = 'add'
2791
2812
  visibleItems = lowestItems.filter(d => d[this.options.searchProp].toLowerCase().indexOf(searchText.toLowerCase()) !== -1)
2792
2813
  }
@@ -2799,7 +2820,7 @@ class WebsyNavigationMenu {
2799
2820
  for (let l = 0; l < listEls.length; l++) {
2800
2821
  listEls[l].classList.add('websy-menu-collapsed')
2801
2822
  }
2802
- if (searchText.length > 1) {
2823
+ if (searchText && searchText.length > 1) {
2803
2824
  visibleItems.forEach(d => {
2804
2825
  // show the item and open the list
2805
2826
  let pathParts = d.path.split('::')
@@ -2853,10 +2874,16 @@ class WebsyNavigationMenu {
2853
2874
  }
2854
2875
  html += this.renderBlock(this.elementId, this.elementId, this.options.items, 'main', 0)
2855
2876
  html += `</div>`
2877
+ if (this.options.secondaryItems) {
2878
+ html += `<div class='websy-menu-secondary' style='height: ${this.options.secondaryHeight || '100%'}; width: ${this.options.secondaryWidth || '100%'}'>`
2879
+ html += this.renderBlock(this.elementId, this.elementId, this.options.secondaryItems, 'main', 0)
2880
+ html += `</div>`
2881
+ }
2856
2882
  el.innerHTML = html
2857
2883
  if (this.options.enableSearch === true) {
2858
2884
  this.search = new WebsyDesigns.Search(`${this.elementId}_search`, Object.assign({}, {
2859
- onSearch: this.handleSearch.bind(this)
2885
+ onSearch: this.handleSearch.bind(this),
2886
+ onClear: this.handleSearch.bind(this)
2860
2887
  }, this.options.searchOptions))
2861
2888
  }
2862
2889
  }
@@ -2891,7 +2918,7 @@ class WebsyNavigationMenu {
2891
2918
  style='padding-left: ${level * this.options.childIndentation}px'
2892
2919
  ${(items[i].attributes && items[i].attributes.join(' ')) || ''}
2893
2920
  >
2894
- `
2921
+ `
2895
2922
  if (this.options.orientation === 'horizontal') {
2896
2923
  html += items[i].text
2897
2924
  }
@@ -2900,22 +2927,33 @@ class WebsyNavigationMenu {
2900
2927
  <span class='selected-bar'></span>
2901
2928
  `
2902
2929
  }
2903
- if (this.options.activeSymbol === 'triangle') {
2904
- html += `
2905
- <span class='active-square'></span>
2906
- `
2907
- }
2908
- html += `
2909
- <span class='${items[i].items && items[i].items.length > 0 ? 'menu-carat' : ''}'></span>
2910
- `
2911
2930
  if (this.options.orientation === 'vertical') {
2912
2931
  // html += `
2913
2932
  // &nbsp;
2914
2933
  // `
2915
2934
  }
2916
2935
  if (items[i].isLink === true && items[i].href) {
2917
- html += `<a href='${items[i].href}'>${items[i].text}</a>`
2918
- }
2936
+ html += `<a href='${items[i].href}' target='${items[i].openInNewTab ? 'blank' : '_self'}'>`
2937
+ }
2938
+ if (items[i].icon) {
2939
+ html += `
2940
+ <div class='websy-menu-item-icon'>${items[i].icon}</div>
2941
+ `
2942
+ }
2943
+ html += `<span>${items[i].text}</span>`
2944
+ if (items[i].isLink === true && items[i].href) {
2945
+ html += `</a>`
2946
+ }
2947
+ if (items[i].items && items[i].items.length > 0) {
2948
+ html += `
2949
+ <span class='menu-carat'></span>
2950
+ `
2951
+ }
2952
+ if (this.options.activeSymbol === 'triangle') {
2953
+ html += `
2954
+ <span class='active-square'></span>
2955
+ `
2956
+ }
2919
2957
  html += `
2920
2958
  </div>
2921
2959
  `
@@ -8585,7 +8623,7 @@ function recaptchaReadyCallBack () {
8585
8623
  // need a way of initializing these based on environment variables
8586
8624
  function useGoogleRecaptcha (key) {
8587
8625
  const rcs = document.createElement('script')
8588
- rcs.src = `//www.google.com/recaptcha/api.js?render=${key}`
8626
+ rcs.src = `//www.google.com/recaptcha/api.js`
8589
8627
  document.body.appendChild(rcs)
8590
8628
  }
8591
8629