Sun Jul 3 07:55:18 UTC 2011 pix@kepibu.org
* Minimal support for attribute-starts-with selector
diff -rN -u old-Oh, Ducks!/selectors.lisp new-Oh, Ducks!/selectors.lisp
--- old-Oh, Ducks!/selectors.lisp 2013-07-24 10:35:42.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2013-07-24 10:35:42.000000000 +0000
@@ -46,6 +46,7 @@
((val :reader attribute-value :initarg :value)))
(defclass attribute-present-selector (attribute-selector) ())
(defclass attribute-equal-selector (attribute-selector) ())
+(defclass attribute-starts-with-selector (attribute-selector) ())
(defmethod initialize-instance :after ((selector nth-child-selector)
&key (asign "+") a
@@ -115,6 +116,9 @@
(#T(regexp$ ("[" $name "=" $name "]") (?attribute ?value))
(cons (make-instance 'attribute-equal-selector :arg attribute :value value)
(parse-selector &rest)))
+ (#T(regexp$ ("[" $name "^=" $name "]") (?attribute ?value))
+ (cons (make-instance 'attribute-starts-with-selector :arg attribute :value value)
+ (parse-selector &rest)))
;; cyclic (An+B, n+B)
(#T(regexp$ (":nth-child(" \s* an+b \s* ")")
(?asign ?a ?bsign ?b))
@@ -280,6 +284,10 @@
(when-let* ((val (element-attribute (selector-arg selector) element)))
(string= val (attribute-value selector))))
+(defmethod subject-p ((selector attribute-starts-with-selector) element)
+ (when-let* ((val (element-attribute (selector-arg selector) element)))
+ (alexandria:starts-with-subseq (string-downcase (attribute-value selector)) (string-downcase val))))
+
(defmethod subject-p ((selector %implicit-element-selector) element)
(eq element *implicit-element*))