Sha256: 54217ca67a72d63f5dc51beac063829f2bb8efc102ec38cc0697ef5a36827b38

Contents?: true

Size: 1.26 KB

Versions: 36

Compression:

Stored size: 1.26 KB

Contents

import ApplicationController from "satis/controllers/application_controller"

/*
 * Link controller
 *
 *   div data-controller="satis-link" href="" data-turbo="false" target="_blank" data-action='click->satis-link#follow'
 *
 */
export default class LinkController extends ApplicationController {
  connect() {
    super.connect()
  }

  follow(event) {
    if (event.target.tagName != this.element.tagName && event.target.closest(this.element.tagName.toLowerCase()) != this.element) {
      // Don't do this anymore when both tagNames are the same (the one you click and the element with the controller
      // This is in to make sure row-links using satis-link controller will not trigger when an A or an SVG in that A is triggered.
      return
    }

    if (event.target != this.element && event.target.closest('a') != undefined) {
      // There is an 'a' tag inside the 'satis-link' tag, and we just clicked on it.
      return
    }

    if (event.metaKey || event.ctrlKey) {
      window.open(this.element.getAttribute("href"), "_blank")
    } else if (this.element.getAttribute("data-turbo") == "false") {
      window.open(this.element.getAttribute("href"), this.element.getAttribute("target"))
    } else {
      Turbo.visit(this.element.getAttribute("href"))
    }
  }
}

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
satis-2.1.43 app/javascript/satis/controllers/link_controller.js
satis-2.1.42 app/javascript/satis/controllers/link_controller.js
satis-2.1.41 app/javascript/satis/controllers/link_controller.js
satis-2.1.40 app/javascript/satis/controllers/link_controller.js
satis-2.1.39 app/javascript/satis/controllers/link_controller.js
satis-2.1.38 app/javascript/satis/controllers/link_controller.js
satis-2.1.37 app/javascript/satis/controllers/link_controller.js
satis-2.1.36 app/javascript/satis/controllers/link_controller.js
satis-2.1.35 app/javascript/satis/controllers/link_controller.js
satis-2.1.33 app/javascript/satis/controllers/link_controller.js
satis-2.1.31 app/javascript/satis/controllers/link_controller.js
satis-2.1.30 app/javascript/satis/controllers/link_controller.js
satis-2.1.29 app/javascript/satis/controllers/link_controller.js
satis-2.1.28 app/javascript/satis/controllers/link_controller.js
satis-2.1.27 app/javascript/satis/controllers/link_controller.js
satis-2.1.26 app/javascript/satis/controllers/link_controller.js
satis-2.1.24 app/javascript/satis/controllers/link_controller.js
satis-2.1.23 app/javascript/satis/controllers/link_controller.js
satis-2.1.22 app/javascript/satis/controllers/link_controller.js
satis-2.1.21 app/javascript/satis/controllers/link_controller.js