Sha256: 42811f3b193a5f467797b4ad7736cfc375e62705a085f3fa0cf5aaa9b142d1e0

Contents?: true

Size: 1.13 KB

Versions: 16

Compression:

Stored size: 1.13 KB

Contents

import { Controller } from 'stimulus'
import axios from '../utils/axios'

export default class extends Controller {
  static targets = ['source', 'output']
  static values = { url: String }

  connect() {
    this.sourceTarget.addEventListener('load', () => {
      const html2canvasScript = document.createElement('script')
      html2canvasScript.setAttribute(
        'src',
        'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.3/html2canvas.min.js',
      )
      this.sourceTarget.contentDocument.head.appendChild(html2canvasScript)
    })
  }

  take() {
    const realSource = this.sourceTarget.contentDocument.querySelector(
      '[data-maglev-dropzone]',
    )
    this.sourceTarget.contentWindow
      .html2canvas(realSource, { allowTaint: true, logging: true })
      .then((canvas) => {
        this.outputTarget.src = canvas.toDataURL() // for debugging purpose
        axios
          .post(this.urlValue, {
            screenshot: { base64_image: canvas.toDataURL() },
          })
          .then(() => {
            alert('Screenshot done!')
          })
          .catch((error) => console.log('ERROR!', error))
      })
  }
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
maglevcms-1.3.0 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.2.2 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.2.1 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.2.0 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.7 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.6 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.5 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.4 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.3 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.2 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.1 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.1.0 app/frontend/admin/controllers/screenshot_controller.js
maglevcms-1.0.0 app/javascript/controllers/screenshot_controller.js
maglevcms-1.0.0.rc3 app/javascript/controllers/screenshot_controller.js
maglevcms-1.0.0.rc2 app/javascript/controllers/screenshot_controller.js
maglevcms-1.0.0.rc1 app/javascript/controllers/screenshot_controller.js