mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-10 00:06:13 +00:00
Allow menu items to define their own javascript includes, and put the explorer menu js there rather than in core.js
This commit is contained in:
parent
ee71fff1b8
commit
28592b4d9b
6 changed files with 49 additions and 29 deletions
|
|
@ -8,8 +8,9 @@ try:
|
|||
except ImportError:
|
||||
from django.forms.util import flatatt
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.text import slugify
|
||||
from django.utils.html import format_html
|
||||
from django.utils.html import format_html, format_html_join
|
||||
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
|
|
@ -27,6 +28,13 @@ class MenuItem(object):
|
|||
else:
|
||||
self.attr_string = ""
|
||||
|
||||
js_files = []
|
||||
def render_js(self):
|
||||
if self.js_files:
|
||||
return format_html_join('\n', '<script src="{0}{1}"></script>',
|
||||
((settings.STATIC_URL, filename) for filename in self.js_files)
|
||||
)
|
||||
|
||||
def is_shown(self, request):
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -21,32 +21,6 @@ $(function(){
|
|||
}
|
||||
});
|
||||
|
||||
// Dynamically load menu on request.
|
||||
$(document).on('click', '.dl-trigger', function(){
|
||||
var $this = $(this);
|
||||
var $explorer = $('#explorer');
|
||||
|
||||
$this.addClass('icon-spinner');
|
||||
|
||||
if(!$explorer.children().length){
|
||||
$explorer.load($this.data('explorer-menu-url'), function() {
|
||||
$this.removeClass('icon-spinner');
|
||||
|
||||
$explorer.addClass('dl-menuwrapper').dlmenu({
|
||||
animationClasses : {
|
||||
classin : 'dl-animate-in-2',
|
||||
classout : 'dl-animate-out-2'
|
||||
}
|
||||
});
|
||||
$explorer.dlmenu('openMenu');
|
||||
});
|
||||
}else{
|
||||
$explorer.dlmenu('openMenu');
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// Resize nav to fit height of window. This is an unimportant bell/whistle to make it look nice
|
||||
var fitNav = function(){
|
||||
$('.nav-wrapper').css('min-height',$(window).height());
|
||||
|
|
|
|||
27
wagtail/wagtailadmin/static/wagtailadmin/js/explorer-menu.js
Normal file
27
wagtail/wagtailadmin/static/wagtailadmin/js/explorer-menu.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
$(function(){
|
||||
// Dynamically load menu on request.
|
||||
$(document).on('click', '.dl-trigger', function(){
|
||||
var $this = $(this);
|
||||
var $explorer = $('#explorer');
|
||||
|
||||
$this.addClass('icon-spinner');
|
||||
|
||||
if(!$explorer.children().length){
|
||||
$explorer.load($this.data('explorer-menu-url'), function() {
|
||||
$this.removeClass('icon-spinner');
|
||||
|
||||
$explorer.addClass('dl-menuwrapper').dlmenu({
|
||||
animationClasses : {
|
||||
classin : 'dl-animate-in-2',
|
||||
classout : 'dl-animate-out-2'
|
||||
}
|
||||
});
|
||||
$explorer.dlmenu('openMenu');
|
||||
});
|
||||
}else{
|
||||
$explorer.dlmenu('openMenu');
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "wagtailadmin/skeleton.html" %}
|
||||
{% load compress %}
|
||||
{% load compress wagtailadmin_tags %}
|
||||
|
||||
{% block css %}
|
||||
{% compress css %}
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/bootstrap-tab.js"></script>
|
||||
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery.dlmenu.js"></script>
|
||||
<script src="{{ STATIC_URL }}wagtailadmin/js/core.js"></script>
|
||||
{% main_nav_js %}
|
||||
{% endcompress %}
|
||||
|
||||
{% block extra_js %}{% endblock %}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ def main_nav(context):
|
|||
'request': request,
|
||||
}
|
||||
|
||||
@register.simple_tag
|
||||
def main_nav_js():
|
||||
js_snippets = [item.render_js() or '' for item in get_master_menu_item_list()]
|
||||
return ''.join(js_snippets)
|
||||
|
||||
|
||||
@register.filter("ellipsistrim")
|
||||
def ellipsistrim(value, max_length):
|
||||
|
|
|
|||
|
|
@ -5,9 +5,14 @@ from wagtail.wagtailcore import hooks
|
|||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
|
||||
class ExplorerMenuItem(MenuItem):
|
||||
js_files = [
|
||||
'wagtailadmin/js/explorer-menu.js',
|
||||
]
|
||||
|
||||
@hooks.register('register_admin_menu_item')
|
||||
def register_explorer_menu_item():
|
||||
return MenuItem(
|
||||
return ExplorerMenuItem(
|
||||
_('Explorer'), urlresolvers.reverse('wagtailadmin_explore_root'),
|
||||
classnames='icon icon-folder-open-inverse dl-trigger',
|
||||
attrs={'data-explorer-menu-url': urlresolvers.reverse('wagtailadmin_explorer_nav')},
|
||||
|
|
|
|||
Loading…
Reference in a new issue