site

files for beauhilton.com
git clone https://git.beauhilton.com/site.git
Log | Files | Refs

set-tab-index.lua (792B)


      1 selectors = config["selectors"]
      2 tab_index = config["tab_index"]
      3 
      4 if not Value.is_list(selectors) then
      5   Plugin.fail("selectors option must be a list")
      6 end
      7 
      8 if not Value.is_int(tab_index) then
      9   Plugin.fail("tab_index option must be an integer")
     10 end
     11 
     12 -- Set the tabindex attribute for a single element
     13 function set_elem_tab_index(elem, index)
     14   current_index = HTML.get_attribute(elem, "tabindex")
     15 
     16   -- Only set tabindex for elements where it's not set already
     17   if current_index == nil then
     18     HTML.set_attribute(elem, "tabindex", tab_index)
     19   end
     20 end
     21 
     22 -- Sets the tabindex attribute for all elements that match a selector
     23 function set_tab_index(selector)
     24   elems = HTML.select(page, selector)
     25   Table.iter_values(set_elem_tab_index, elems)
     26 end
     27 
     28 Table.iter_values(set_tab_index, selectors)