Commit 57ff4488 authored by Michael Bukachi's avatar Michael Bukachi

fix: Correct styling issue navbar sub category

parent 7ab5de3e
...@@ -9,5 +9,6 @@ database_path = op.join(app_dir, app.config['DATABASE_FILE']) ...@@ -9,5 +9,6 @@ database_path = op.join(app_dir, app.config['DATABASE_FILE'])
if not os.path.exists(database_path): if not os.path.exists(database_path):
build_sample_db() build_sample_db()
# Start app if __name__ == '__main__':
app.run(debug=True) # Start app
app.run(debug=True)
...@@ -203,7 +203,7 @@ def is_hybrid_property(model, attr_name): ...@@ -203,7 +203,7 @@ def is_hybrid_property(model, attr_name):
last_model = attr.property.argument last_model = attr.property.argument
if isinstance(last_model, _class_resolver): if isinstance(last_model, _class_resolver):
last_model = model._decl_class_registry[last_model.arg] last_model = model._decl_class_registry[last_model.arg]
elif isinstance(last_model, types.FunctionType): elif isinstance(last_model, (types.FunctionType, types.MethodType)):
last_model = last_model() last_model = last_model()
last_name = names[-1] last_name = names[-1]
return last_name in get_hybrid_properties(last_model) return last_name in get_hybrid_properties(last_model)
......
...@@ -146,4 +146,4 @@ class MenuLink(BaseMenu): ...@@ -146,4 +146,4 @@ class MenuLink(BaseMenu):
class SubMenuCategory(MenuCategory): class SubMenuCategory(MenuCategory):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(SubMenuCategory, self).__init__(*args, **kwargs) super(SubMenuCategory, self).__init__(*args, **kwargs)
self.class_name += ' dropdown-submenu' self.class_name += ' dropdown-submenu dropright'
# Bootstrap 4 Multiple Level Dropdown
Using official HTML without adding extra CSS styles and classes, it's just like native support.
All things listed in https://getbootstrap.com/docs/4.4/components/dropdowns/ are not effected. You can use css classes and js methods/events/options freely.
Dropdown of bootstrap can be easily changed to infinite level. It's a pity that they didn't do it.
## Usage
### Base
Just add js after jquery and bootstrap js files
```html
<script src="https://raw.githubusercontent.com/dallaslu/bootstrap-4-multi-level-dropdown/master/bootstrap4-dropdown-ml-hack.js"></script>
```
### Hover
If your want a hover tigger, just add class and some custom styles to reduce spacing to avoid triggering mouseleave.
```css
.dropdown-hover-all .dropdown-menu, .dropdown-hover > .dropdown-menu { margin:0 }
```
Then, add event handler (suggest 'toggle' for best experience):
```javascript
$('.dropdown-hover').on('mouseenter',function() {
if(!$(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover').on('mouseleave',function() {
if($(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover-all').on('mouseenter', '.dropdown', function() {
if(!$(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover-all').on('mouseleave', '.dropdown', function() {
if($(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
```
Or just using:
```html
<link rel="stylesheet" href="https://raw.githubusercontent.com/dallaslu/bootstrap-4-multi-level-dropdown/master/bootstrap4-dropdown-ml-hack-hover.css" />
...
<div class="dropdown-hover-all">
<!-- .dropdown elements -->
</div>
<div class="dropdown dropdown-hover">
<!-- toggle and menu elements -->
</div>
...
<script src="https://raw.githubusercontent.com/dallaslu/bootstrap-4-multi-level-dropdown/master/bootstrap4-dropdown-ml-hack-hover.js"></script>
```
## Demo
Here is a perfect demo: https://jsfiddle.net/dallaslu/adky6jvs/ (works well with Bootstrap v4.4.1)
.dropdown-hover-all .dropdown-menu, .dropdown-hover > .dropdown-menu { margin:0 }
$.fn.dropdown = (function() {
var $bsDropdown = $.fn.dropdown;
return function(config) {
if (typeof config === 'string' && config === 'toggle') { // dropdown toggle trigged
$('.has-child-dropdown-show').removeClass('has-child-dropdown-show');
$(this).closest('.dropdown').parents('.dropdown').addClass('has-child-dropdown-show');
}
var ret = $bsDropdown.call($(this), config);
$(this).off('click.bs.dropdown'); // Turn off dropdown.js click event, it will call 'this.toggle()' internal
return ret;
}
})();
$(function() {
$('.dropdown [data-toggle="dropdown"]').on('click', function(e) {
$(this).dropdown('toggle');
e.stopPropagation(); // do not fire dropdown.js click event, it will call 'this.toggle()' internal
});
$('.dropdown').on('hide.bs.dropdown', function(e) {
if ($(this).is('.has-child-dropdown-show')) {
$(this).removeClass('has-child-dropdown-show');
e.preventDefault();
}
e.stopPropagation(); // do not need pop in multi level mode
});
});
// for hover
$('.dropdown-hover').on('mouseenter',function() {
if(!$(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover').on('mouseleave',function() {
if($(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover-all').on('mouseenter', '.dropdown', function() {
if(!$(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover-all').on('mouseleave', '.dropdown', function() {
if($(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$.fn.dropdown = (function() {
var $bsDropdown = $.fn.dropdown;
return function(config) {
if (typeof config === 'string' && config === 'toggle') { // dropdown toggle trigged
$('.has-child-dropdown-show').removeClass('has-child-dropdown-show');
$(this).closest('.dropdown').parents('.dropdown').addClass('has-child-dropdown-show');
}
var ret = $bsDropdown.call($(this), config);
$(this).off('click.bs.dropdown'); // Turn off dropdown.js click event, it will call 'this.toggle()' internal
return ret;
}
})();
$(function() {
$('.dropdown [data-toggle="dropdown"]').on('click', function(e) {
$(this).dropdown('toggle');
e.stopPropagation(); // do not fire dropdown.js click event, it will call 'this.toggle()' internal
});
$('.dropdown').on('hide.bs.dropdown', function(e) {
if ($(this).is('.has-child-dropdown-show')) {
$(this).removeClass('has-child-dropdown-show');
e.preventDefault();
}
e.stopPropagation(); // do not need pop in multi level mode
});
});
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
{% endif %} {% endif %}
<link href="{{ admin_static.url(filename='admin/css/bootstrap4/admin.css', v='1.1.1') }}" rel="stylesheet"> <link href="{{ admin_static.url(filename='admin/css/bootstrap4/admin.css', v='1.1.1') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='bootstrap/bootstrap4/css/font-awesome.min.css', v='4.7.0') }}" rel="stylesheet"> <link href="{{ admin_static.url(filename='bootstrap/bootstrap4/css/font-awesome.min.css', v='4.7.0') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='admin/css/bootstrap4/submenu.css') }}" rel="stylesheet">
{% if admin_view.extra_css %} {% if admin_view.extra_css %}
{% for css_url in admin_view.extra_css %} {% for css_url in admin_view.extra_css %}
<link href="{{ css_url }}" rel="stylesheet"> <link href="{{ css_url }}" rel="stylesheet">
...@@ -87,6 +86,7 @@ ...@@ -87,6 +86,7 @@
<script src="{{ admin_static.url(filename='vendor/bootstrap4/dropdown.js', v='4.3.1') }}" type="text/javascript"></script> <script src="{{ admin_static.url(filename='vendor/bootstrap4/dropdown.js', v='4.3.1') }}" type="text/javascript"></script>
<script src="{{ admin_static.url(filename='vendor/select2/select2.min.js', v='4.2.1') }}" <script src="{{ admin_static.url(filename='vendor/select2/select2.min.js', v='4.2.1') }}"
type="text/javascript"></script> type="text/javascript"></script>
<script src="{{ admin_static.url(filename='vendor/multi-level-dropdowns-bootstrap/bootstrap4-dropdown-ml-hack.js') }}" type="text/javascript"></script>
<script src="{{ admin_static.url(filename='admin/js/helpers.js', v='1.0.0') }}" type="text/javascript"></script> <script src="{{ admin_static.url(filename='admin/js/helpers.js', v='1.0.0') }}" type="text/javascript"></script>
{% if admin_view.extra_js %} {% if admin_view.extra_js %}
{% for js_url in admin_view.extra_js %} {% for js_url in admin_view.extra_js %}
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{%- endmacro %} {%- endmacro %}
{% macro menu(menu_root=None) %} {% macro menu(menu_root=None) %}
{% set is_main_nav = menu_root == None %}
{% if menu_root is none %}{% set menu_root = admin_view.admin.menu() %}{% endif %} {% if menu_root is none %}{% set menu_root = admin_view.admin.menu() %}{% endif %}
{%- for item in menu_root %} {%- for item in menu_root %}
{%- if item.is_category() -%} {%- if item.is_category() -%}
...@@ -25,7 +27,7 @@ ...@@ -25,7 +27,7 @@
{% else -%} {% else -%}
<li class="dropdown{% if class_name %} {{ class_name }}{% endif %}"> <li class="dropdown{% if class_name %} {{ class_name }}{% endif %}">
{%- endif %} {%- endif %}
<a class="dropdown-toggle nav-link" data-toggle="dropdown" href="javascript:void(0)"> <a class="dropdown-toggle {% if is_main_nav %}nav-link{% else %}dropdown-item{% endif %}" data-toggle="dropdown" href="javascript:void(0)">
{% if item.class_name %}<span class="{{ item.class_name }}"></span> {% endif %} {% if item.class_name %}<span class="{{ item.class_name }}"></span> {% endif %}
{{ menu_icon(item) }}{{ item.name }} {{ menu_icon(item) }}{{ item.name }}
{%- if 'dropdown-submenu' in class_name -%} {%- if 'dropdown-submenu' in class_name -%}
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
{% endif %} {% endif %}
{% if search_supported %} {% if search_supported %}
<li class="nav-item col-auto"> <li class="nav-item ml-2">
{{ model_layout.search_form() }} {{ model_layout.search_form() }}
</li> </li>
{% endif %} {% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment