Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional javascript #94

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootstrap4/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"javascript_in_head": False,
"include_jquery": False,
"use_i18n": False,
"use_javascript": True,
"horizontal_label_class": "col-md-3",
"horizontal_field_class": "col-md-9",
"set_placeholder": True,
Expand Down
3 changes: 2 additions & 1 deletion bootstrap4/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from bootstrap4.utils import render_tag, add_css_class

from .text import text_value
from .bootstrap import get_bootstrap_setting


def render_alert(content, alert_type=None, dismissable=True):
Expand All @@ -15,7 +16,7 @@ def render_alert(content, alert_type=None, dismissable=True):
if not alert_type:
alert_type = "info"
css_classes = ["alert", "alert-" + text_value(alert_type)]
if dismissable:
if dismissable and get_bootstrap_setting("use_javascript"):
css_classes.append("alert-dismissable")
button = (
'<button type="button" class="close" '
Expand Down
3 changes: 3 additions & 0 deletions bootstrap4/templates/bootstrap4/form_errors.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{% load bootstrap4 %}
<div class="alert alert-danger alert-dismissable alert-link">
{% if 'use_javascript'|bootstrap_setting %}
<button class="close" type="button" data-dismiss="alert" aria-hidden="true">&#215;</button>
{% endif %}
{% for error in errors %}
{{ error }}{% if not forloop.last %}<br>{% endif %}
{% endfor %}
Expand Down
2 changes: 2 additions & 0 deletions bootstrap4/templates/bootstrap4/messages.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% load bootstrap4 %}
{% for message in messages %}
<div class="{{ message|bootstrap_message_classes }} alert-dismissable fade show">
{% if 'use_javascript'|bootstrap_setting %}
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&#215;</button>
{% endif %}
{{ message }}
</div>
{% endfor %}
8 changes: 7 additions & 1 deletion bootstrap4/templatetags/bootstrap4.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ def bootstrap_javascript_url():

{% bootstrap_javascript_url %}
"""
return javascript_url()
if not get_bootstrap_setting('use_javascript'):
return None
else:
return javascript_url()


@register.simple_tag
Expand Down Expand Up @@ -339,6 +342,9 @@ def bootstrap_javascript(jquery="falsy"):
{% bootstrap_javascript jquery="slim" %}
"""

if not get_bootstrap_setting('use_javascript'):
return None

# List of JS tags to include
javascript_tags = []

Expand Down
3 changes: 3 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ The ``BOOTSTRAP4`` dict variable contains these settings and defaults:
# The complete URL to the Bootstrap CSS file (None means no theme)
'theme_url': None,

# Whether to use any JavaScript at all
'use_javascript': True,

# The complete URL to the Bootstrap JavaScript file (None means derive it from base_url)
'javascript_url': None,

Expand Down