mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-07 03:00:49 -08:00
load script now by default waits for load of script
This commit is contained in:
parent
0fce8207c1
commit
19d753aa21
1 changed files with 17 additions and 6 deletions
|
|
@ -163,20 +163,31 @@ clog-document object. (Private)"))
|
||||||
;; load-script ;;
|
;; load-script ;;
|
||||||
;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defgeneric load-script (clog-document script-url)
|
(defgeneric load-script (clog-document script-url &key wait-for-load
|
||||||
|
wait-timeout)
|
||||||
(:documentation "Load script from SCRIPT-URL."))
|
(:documentation "Load script from SCRIPT-URL."))
|
||||||
|
|
||||||
(defmethod load-script ((obj clog-document) script-url)
|
(defmethod load-script ((obj clog-document) script-url &key (wait-for-load t)
|
||||||
|
(wait-timeout 3))
|
||||||
;; After we load the script from src we then fire the
|
;; After we load the script from src we then fire the
|
||||||
;; custom on-load-script event in the next line of
|
;; custom on-load-script event in the next line of
|
||||||
;; script after the load as scripts are loaded
|
;; script after the load as scripts are loaded
|
||||||
;; synchronously.
|
;; synchronously.
|
||||||
(Jquery-execute (head-element obj)
|
(let ((sem (bordeaux-threads:make-semaphore)))
|
||||||
(format nil "append('<script src=\"~A\"></script>~
|
(flet ((on-load (obj url)
|
||||||
|
(declare (ignore obj))
|
||||||
|
(when (equalp url script-url)
|
||||||
|
(bordeaux-threads:signal-semaphore sem))))
|
||||||
|
(when wait-for-load
|
||||||
|
(set-on-load-script obj #'on-load :one-time t))
|
||||||
|
(jquery-execute (head-element obj)
|
||||||
|
(format nil "append('<script src=\"~A\"></script>~
|
||||||
<script>$(clog[\\'document\\']).trigger(\\'on-load-script\\',~
|
<script>$(clog[\\'document\\']).trigger(\\'on-load-script\\',~
|
||||||
\\'~A\\')</script>')"
|
\\'~A\\')</script>')"
|
||||||
(escape-string script-url)
|
(escape-string script-url)
|
||||||
(escape-string script-url))))
|
(escape-string script-url)))
|
||||||
|
(when wait-for-load
|
||||||
|
(bordeaux-threads:wait-on-semaphore sem :timeout wait-timeout)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; set-on-load-script ;;
|
;; set-on-load-script ;;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue