33
44import dash
55import dash_bootstrap_components as dbc
6- from dash import html
6+ from dash import ClientsideFunction , Input , Output , html
77from jinja2 import Environment , FileSystemLoader
88
99from .components .table .simple import table_body , table_header # noqa
1818
1919LOREM = (COMPONENTS / "modal" / "lorem.txt" ).read_text ().strip ()
2020
21+ CLIENTSIDE_CALLBACK = """
22+ if (!window.dash_clientside) {
23+ window.dash_clientside = {};
24+ }
25+ window.dash_clientside.clientside = {
26+ make_draggable: function(id) {
27+ setTimeout(function() {
28+ var el = document.getElementById(id)
29+ window.console.log(el)
30+ dragula([el])
31+ }, 1)
32+ return window.dash_clientside.no_update
33+ }
34+ }
35+ """
36+
2137HIGHLIGHT_JS_CSS = (
2238 "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.13.1/"
2339 "build/styles/monokai-sublime.min.css"
@@ -149,6 +165,7 @@ def register_apps():
149165 )
150166 app = dash .Dash (
151167 external_stylesheets = ["/static/loading.css" ],
168+ external_scripts = ["/static/js/clientside.js" ],
152169 requests_pathname_prefix = requests_pathname_prefix ,
153170 suppress_callback_exceptions = True ,
154171 serve_locally = SERVE_LOCALLY ,
@@ -171,6 +188,17 @@ def register_apps():
171188 )
172189 else :
173190 app .layout = parse (app , ** kwargs )
191+
192+ app .clientside_callback (
193+ ClientsideFunction (
194+ namespace = "clientside" , function_name = "scrollAfterLoad"
195+ ),
196+ # id won't actually be updated, we just want the callback to run
197+ # once Dash has initialised and hydrated the page
198+ Output ("url" , "id" ),
199+ Input ("url" , "hash" ),
200+ )
201+
174202 if slug == "index" :
175203 routes ["/docs/components" ] = app
176204 else :
0 commit comments