swap-element-by-id

This commit is contained in:
David Botton 2022-07-25 22:13:30 -04:00
parent 0f150a31a8
commit 1aa4d396c9
2 changed files with 26 additions and 9 deletions

View file

@ -2229,8 +2229,24 @@ Returns CLOG-ELEMENT"))
(jquery-execute obj (format nil "replaceWith(~A)" (jquery new)))
obj)
;;;;;;;;;;;;;;;;;;;;;;;;
;; swap-element-by-id ;;
;;;;;;;;;;;;;;;;;;;;;;;;
(defgeneric swap-element-by-id (html-id clog-element)
(:documentation "Replace an existing element on page with HTML-ID with
CLOG-ELEMENT and set CLOG-ELEMENT to html-id. Returns CLOG-ELEMENT"))
(defmethod swap-element-by-id (html-id (new clog-element))
(let ((obj (attach-as-child new html-id :new-id t)))
(setf (property new "id") html-id)
(setf (slot-value new 'html-id) html-id)
(replace-element obj new)
(destroy obj)
new))
;;;;;;;;;;;;;;;;;;;;
;; parent-element ;;
;; Parent-element ;;
;;;;;;;;;;;;;;;;;;;;
(defgeneric parent-element (clog-element)

View file

@ -357,6 +357,7 @@ embedded in a native template application.)"
(destroy generic-function)
(click generic-function)
(replace-element generic-function)
(swap-element-by-id generic-function)
"CLOG-Element - DOM Traversal Methods"
(parent-element generic-function)