Skip to content

Commit 84480ed

Browse files
Merge pull request #16 from diegojromerolopez/0.6.8
"onload" parameter for the async_include template_tag, allowing calling a callback function
2 parents af447c1 + aee8975 commit 84480ed

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changes
22
=======
33

4+
Version 0.6.8
5+
-------------
6+
* Feature: "onload" parameter for the async_include template_tag, allowing calling a callback function.
7+
48
Version 0.6.7
59
-------------
610
* Add some tests.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ need in your included template as named parameters of the **async_include** temp
115115
There is also a repository with a full example:
116116
[django-async-include-example](https://github.com/diegojromerolopez/django-async-include-example).
117117

118+
## Call javascript function whe load is completed
119+
120+
Pass the attribute `onload` with the name of the function you want to call after the request and the replacement
121+
has been completed. e.g.
122+
123+
```html
124+
{% async_include "boards/components/view/current_percentage_of_completion.html" board=board onload="load_board_style" %}
125+
```
126+
118127
## Warning and limitations
119128

120129
### Object dynamic attributes

async_include/templates/async_include/template_tag.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ document.addEventListener("DOMContentLoaded", function(event) {
4242
if(request_frequency == "once"){
4343
document.getElementById(block_id).innerHTML = response_data;
4444
document.getElementById(script_block_id).remove();
45+
{% if onload_func %}
46+
{{onload_func}}();
47+
{% endif %}
4548
}else{
4649
document.getElementById(block_id).appendChild(
4750
document.createTextNode(response_data)

async_include/templatetags/async_include.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def async_include(context, template_path, *args, **kwargs):
7373
# Recurrent requests
7474
request__frequency = kwargs.pop('request__frequency', 'once')
7575

76+
# On load call this function
77+
onload = kwargs.pop(
78+
'onload', None
79+
)
80+
7681
replacements = {
7782
'template_path': template_path,
7883
'block_id': block_id,
@@ -81,6 +86,7 @@ def async_include(context, template_path, *args, **kwargs):
8186
'spinner__visible': spinner__visible,
8287
'spinner__template_path': spinner__template_path,
8388
'request__frequency': request__frequency,
89+
'onload_func': onload,
8490
'context': {}
8591
}
8692

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name="django-async-include",
23-
version="0.6.7",
23+
version="0.6.8",
2424
author="Diego J. Romero López",
2525
author_email="[email protected]",
2626
description=(

0 commit comments

Comments
 (0)