Sha256: 40a3cad3df6d58bc7341b240f7f0c392288645dca751f288234c9a94255c33bb

Contents?: true

Size: 684 Bytes

Versions: 27

Compression:

Stored size: 684 Bytes

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  
  connect() {
    this.replaceHTML()
  }
  
  replaceHTML() {
    let html = this.element.innerHTML
    
    let uuid = this.generateUUID()
    let regex = new RegExp(this.id, 'g')
    let replaced_html = html.replace(regex, uuid)
    
    this.element.innerHTML = replaced_html
    this.element.id = uuid
  }
  
  generateUUID() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8)
      return v.toString(16)
    })
  }
  
  get id() {
    return this.element.dataset.uniqueId
  }
  
}

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
spina-2.18.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.17.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.16.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.15.1 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.15.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.14.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.13.1 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.13.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.12.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.11.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.10.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.9.1 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.9.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.8.1 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.8.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.7.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.6.2 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.6.1 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.6.0 app/assets/javascripts/spina/controllers/unique_id_controller.js
spina-2.5.0 app/assets/javascripts/spina/controllers/unique_id_controller.js