the-carlisle-group / Abacus

HTML, CSS, and Markdown for Dyalog APL
MIT License
12 stars 0 forks source link

GetElementByClass does not support elements with multiple classes #18

Open norberturkiewicz opened 1 month ago

norberturkiewicz commented 1 month ago

Currently the input must search by full class list

Fails

       body A.GetElementByClass'item-title'
undefined class: item-title
      body A.GetElementByClass'item-title'
           ∧

Works

      body A.GetElementByClass'left item-title'
#.Abacus.Main.[Namespace]
PaulMansour commented 1 month ago

We also don't seen to have GetElementsByClass (with an "s")...

PaulMansour commented 1 month ago

Should we make it work on multiple classes:

d GetElementsByClass 'One' 'Two'

would then return elements that have both class One and Two. Or One or Two. Or just have it take only a single class, and then use ∩ and ∪ to get what you want.?

norberturkiewicz commented 1 month ago

How would we determine and/or? What if I want class1 and class2 but they may be in different orders?

PaulMansour commented 1 month ago

Order is no problem. I think we should just copy JavaScript which does an "and" ... all the classes must exist

PaulMansour commented 1 month ago
GetElementsByClass←{
     ⍝ ⍺ ←→ Element (or result of Elements ⍺)
     ⍝ ⍵ ←→ Class(es) Simple or nested: 'One' or 'One Two' or 'One' 'Two'
     ⍝ ← ←→ Elements
     c←' '(≠⊆⊢)1↓∊' ',¨⊆⍵
     e←{1=⍴⍴⍵:⍵ ⋄ Elements ⍵}⍺
     b←e{2≠⍺.⎕NC'class':0 ⋄ ∧/⍵∊' '(≠⊆⊢)⍺.class}¨⊂c
     b/e
 }
PaulMansour commented 1 month ago

Also, I think I should use "GetElementByTag" instead of "ElementByTag" and everywhere else, to be consistent with JavaScript internally consistent in Abacus....