/home/ytevagd/public_html/wp-content/themes/flatsome/inc/admin/advanced/assets/js/index.js
/* eslint-disable no-undef, no-var */

wp.domReady(function () {
  var button = document.getElementById('flatsome-instagram-access-token-submit')
  var token = document.getElementById('flatsome-instagram-access-token-value')
  var errors = document.getElementById('flatsome-instagram-errors')

  var abortController = null

  if (button) {
    button.addEventListener('click', function () {
      addInstagramAccount()
    })
  }

  if (token) {
    token.addEventListener('keydown', function (event) {
      if (event.key === 'Enter') {
        event.stopPropagation()
        event.preventDefault()
        addInstagramAccount()
      }
    })
  }

  function addInstagramAccount () {
    if (abortController) abortController.abort()
    if (errors) errors.innerHTML = ''

    if (!token.value) return

    var data = new FormData()

    abortController = new AbortController()

    data.append('action', 'flatsome_validate_instagram_access_token')
    data.append('access_token', token.value)
    data.append('nonce', window.flatsomeAdvancedData.nonce)

    setEditable(false)

    fetch(window.ajaxurl, { method: 'POST', body: data, signal: abortController.signal })
      .then(function (response) {
        return response.json()
      })
      .then(function (response) {
        if (response.success) {
          addAccount(response.data)
          token.value = ''
        } else {
          showError('An error occured while adding the account: ' + response.data)
        }
      })
      .catch(showError)
      .finally(function () {
        setEditable(true)
      })
  }

  function setEditable (editable) {
    token.readOnly = !editable
    if (button) {
      button.classList.toggle('is-busy', !editable)
    }
  }

  function showError (error) {
    if (error.name === 'AbortError') return
    if (errors) {
      errors.innerHTML = '<div class="notice notice-error inline"><p>' + error + '</p></div>'
    } else {
      console.error(error)
    }
  }

  function addAccount (data) {
    var tbody = document.querySelector('.flatsome-instagram-accounts__body')
    var tr = document.querySelector('.instagram-account--' + data.username)
    var id = wp.escapeHtml.escapeAttribute(data.id)
    var username = wp.escapeHtml.escapeAttribute(data.username)
    var accessToken = wp.escapeHtml.escapeAttribute(data.access_token)
    var usernameDisplay = wp.escapeHtml.escapeHTML(data.username)
    var expiresAt = parseInt(data.expires_at, 10)

    var html = [
      '<tr class="instagram-account instagram-account-updated instagram-account--' + username + '">',
      '<td>',
      '<input type="hidden" name="facebook_accounts[' + username + '][type]" value="instagram">',
      '<input type="hidden" name="facebook_accounts[' + username + '][id]" value="' + id + '">',
      '<input type="hidden" name="facebook_accounts[' + username + '][username]" value="' + username + '">',
      '<input type="hidden" name="facebook_accounts[' + username + '][access_token]" value="' + accessToken + '">',
      '<input type="hidden" name="facebook_accounts[' + username + '][expires_at]" value="' + expiresAt + '">',
      '<a target="_blank" href="https://www.instagram.com/' + username + '/" rel="noopener">' + usernameDisplay + '</a>',
      '</td>',
      '<td align="right">',
      '<button type="button" class="button button-small" onclick="jQuery(this).closest(\'.instagram-account\').remove()">Remove</button>',
      '</td>',
      '</tr>'
    ].join('\n')

    if (tr) {
      tr.outerHTML = html
    } else {
      tbody.innerHTML += html
    }
  }
})
CVARA – NHẬP KHẨU PHÁP – GIÚP PHÁT TRIỂN CHIỀU CAO VÀ PHÒNG CHỐNG LOÃNG XƯƠNG. - Giải pháp chăm sóc tại nhà Việt Nam

CVARA – NHẬP KHẨU PHÁP – GIÚP PHÁT TRIỂN CHIỀU CAO VÀ PHÒNG CHỐNG LOÃNG XƯƠNG.

390,000

CVARA – NHẬP KHẨU PHÁP – BỔ SUNG CALCI NANO VITAMIN D3 VÀ MK7 – GIÚP PHÁT TRIỂN CHIỀU CAO VÀ PHÒNG CHỐNG LOÃNG XƯƠNG.
CVARA – NHẬP KHẨU PHÁP – BỔ SUNG CALCI NANO VITAMIN D3 VÀ MK7 – GIÚP PHÁT TRIỂN CHIỀU CAO VÀ PHÒNG CHỐNG LOÃNG XƯƠNG

– Bổ sung Canxi nhằm hỗ trợ phát triển chiều cao cho thanh thiếu niên trong độ tuổi phát triển chiều cao, giúp xương chắc khỏe, phòng ngừa còi xương ở trẻ em

– Chống loãng xương, giúp phục hồi xương gãy, giảm đau lưng cho người lớn, ngăn chặn các hiện tượng thoái hóa, giòn xương do thiếu canxi trong máu, giúp cơ thể khỏe mạnh

– Giảm tình trạng viêm khớp, thoái hóa khớp. Cung cấp canxi, vitamin D3 cho phụ nữ có thai và cho con bú. Tăng cường và phát triển hệ xương ở thai nhi

– Giảm tê bì chân tay, chuột rút. Kết hợp hỗ trợ điều trị thiếu canxi huyết

CAM KẾT HÀNG CHÍNH HÃNG – GIÁ CẢ HỢP LÝ – TIẾT KIỆM 5-7% – GIAO HÀNG TOÀN QUỐC.