1// Add your own Custom Turbo StreamActions 2// Define Rails helpers in `app/helpers/turbo_stream_actions_helper.rb` 3// 4// These actions run in the context of a turbo-stream element. You have access to methods like the following: 5// 6// this.action - The action attribute value (for example: "append") 7// this.target - The target attribute value (the target element ID) 8// this.targetElements - An array of target elements the template will be rendered to 9// this.templateContent - The contents of the main `<template>` 10// 11// Source code for the stream element can be found here: 12// https://github.com/hotwired/turbo/blob/main/src/elements/stream_element.ts 13 14// Remove elements after X milliseconds 15// <%= turbo_stream.remove_later, target: "my-id", after: "2000" %> 16Turbo.StreamActions.remove_later = function() { 17 setTimeout(() => { 18 this.targetElements.forEach((element) => element.remove()) 19 }, this.getAttribute("after")) 20} 21 22// Resets a form 23// <%= turbo_stream.reset_form "new_post" 24Turbo.StreamActions.reset_form = function() { 25 this.targetElements.forEach((element) => element.reset()) 26} 27 28// Scrolls an element into view 29// <%= turbo_stream.scroll_to "comment_1" 30Turbo.StreamActions.scroll_to = function() { 31 this.targetElements.forEach((element) => element.scrollIntoView({behavior: 'smooth'})) 32}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.