From 59f2a5953b77b1eed6f6199873891e182b215911 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 17 Feb 2017 17:08:27 +0000 Subject: [PATCH] Remove Javascript from explorer menu item --- .../wagtailadmin/js/explorer-menu.js | 52 ---- .../static_src/wagtailadmin/js/submenu.js | 7 +- .../wagtailadmin/js/vendor/jquery.dlmenu.js | 260 ------------------ .../templates/wagtailadmin/admin_base.html | 1 - wagtail/wagtailadmin/wagtail_hooks.py | 6 - 5 files changed, 1 insertion(+), 325 deletions(-) delete mode 100644 wagtail/wagtailadmin/static_src/wagtailadmin/js/explorer-menu.js delete mode 100644 wagtail/wagtailadmin/static_src/wagtailadmin/js/vendor/jquery.dlmenu.js diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/explorer-menu.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/explorer-menu.js deleted file mode 100644 index b473ba3f8..000000000 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/explorer-menu.js +++ /dev/null @@ -1,52 +0,0 @@ -$(function() { - var $explorer = $('#explorer'); - var $body = $('body'); - - // Dynamically load menu on request. - $(document).on('click', '.dl-trigger--unused', function() { - var $this = $(this); - - // Close all submenus - $('.nav-main .submenu-active, .nav-wrapper').removeClass('submenu-active'); - - if ($explorer.data('dlmenu') && $explorer.dlmenu('isOpen')) { - // if it's already open, allow the menu plugin to close it - return false; - } else { - if (!$explorer.children().length) { - $this.addClass('icon-spinner'); - $explorer.load($this.data('explorer-menu-url'), function() { - $this.removeClass('icon-spinner'); - - if ($explorer.find('.dl-menu li').length === 0) { - /* - AJAX fetch returned an empty dl-menu UL, i.e. no pages exist whatsoever. - Take the user directly to the page explorer view, since we aren't giving - them anything to click on to get there... - */ - document.location.href = $this.attr('href'); - } - - $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; - }); - - // Close menu on ESC key - $(document).on('keydown click', function(e) { - if ($explorer.data('dlmenu') && $explorer.dlmenu('isOpen') && (e.keyCode == 27 || !e.keyCode)) { - $explorer.dlmenu('closeMenu'); - } - }); -}); diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/submenu.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/submenu.js index 37c27a195..f032ab692 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/submenu.js +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/js/submenu.js @@ -4,11 +4,6 @@ $(function() { $('.nav-main .submenu-trigger').on('click', function() { if ($(this).closest('li').find('.nav-submenu').length) { - // Close explorer menu, although it may not be instantiated yet - if ($explorer.data('dlmenu') && $explorer.dlmenu('isOpen')) { - $explorer.dlmenu('closeMenu'); - } - // Close other active submenus first, if any if ($('.nav-wrapper.submenu-active').length && !$(this).closest('li').hasClass('submenu-active')) { $('.nav-main .submenu-active, .nav-wrapper').removeClass('submenu-active'); @@ -16,7 +11,7 @@ $(function() { $(this).closest('li').toggleClass('submenu-active'); $('.nav-wrapper').toggleClass('submenu-active'); - return false + return false; } }); diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/vendor/jquery.dlmenu.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/vendor/jquery.dlmenu.js deleted file mode 100644 index dbee6702c..000000000 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/vendor/jquery.dlmenu.js +++ /dev/null @@ -1,260 +0,0 @@ -/** - * jquery.dlmenu.js v1.0.1 - * http://www.codrops.com - * - * Licensed under the MIT license. - * http://www.opensource.org/licenses/mit-license.php - * - * Copyright 2013, Codrops - * http://www.codrops.com - */ -;( function( $, window, undefined ) { - - 'use strict'; - - // global - var Modernizr = window.Modernizr, $body = $( 'body' ); - - $.DLMenu = function( options, element ) { - this.$el = $( element ); - this._init( options ); - }; - - // the options - $.DLMenu.defaults = { - // classes for the animation effects - animationClasses : { classin : 'dl-animate-in-1', classout : 'dl-animate-out-1' }, - // callback: click a link that has a sub menu - // el is the link element (li); name is the level name - onLevelClick : function( el, name ) { return false; }, - // callback: click a link that does not have a sub menu - // el is the link element (li); ev is the event obj - onLinkClick : function( el, ev ) { return false; } - }; - - $.DLMenu.prototype = { - _init : function( options ) { - - // options - this.options = $.extend( true, {}, $.DLMenu.defaults, options ); - // cache some elements and initialize some variables - this._config(); - - var animEndEventNames = { - 'WebkitAnimation' : 'webkitAnimationEnd', - 'OAnimation' : 'oAnimationEnd', - 'msAnimation' : 'MSAnimationEnd', - 'animation' : 'animationend' - }, - transEndEventNames = { - 'WebkitTransition' : 'webkitTransitionEnd', - 'MozTransition' : 'transitionend', - 'OTransition' : 'oTransitionEnd', - 'msTransition' : 'MSTransitionEnd', - 'transition' : 'transitionend' - }; - // animation end event name - this.animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ] + '.dlmenu'; - // transition end event name - this.transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ] + '.dlmenu', - // support for css animations and css transitions - this.supportAnimations = Modernizr.cssanimations, - this.supportTransitions = Modernizr.csstransitions; - - this._initEvents(); - - }, - _config : function() { - this.open = false; - this.$trigger = $( '.dl-trigger' ); - this.$menu = this.$el.children( 'ul.dl-menu' ); - this.$menuitems = this.$menu.find( 'li:not(.dl-back) .children' ); - this.$el.find( 'ul.dl-submenu' ).prepend( '
  • back
  • ' ); - this.$back = this.$menu.find( 'li.dl-back' ); - }, - _initEvents : function() { - - var self = this; - - this.$trigger.on( 'click.dlmenu', function() { - - if( self.open ) { - self._closeMenu(); - } - else { - self._openMenu(); - } - return true; - - } ); - - this.$menuitems.on( 'click.dlmenu', function( event ) { - - event.stopPropagation(); - - var $item = $(this).parent(), - $submenu = $item.children( 'ul.dl-submenu' ); - - if( $submenu.length > 0 ) { - - var $flyin = $submenu.clone().css( 'opacity', 0 ).insertAfter( self.$menu ), - onAnimationEndFn = function() { - self.$menu.off( self.animEndEventName ).removeClass( self.options.animationClasses.classout ).addClass( 'dl-subview' ); - $item.addClass( 'dl-subviewopen' ).parents( '.dl-subviewopen:first' ).removeClass( 'dl-subviewopen' ).addClass( 'dl-subview' ); - $flyin.remove(); - }; - - setTimeout( function() { - $flyin.addClass( self.options.animationClasses.classin ); - self.$menu.addClass( self.options.animationClasses.classout ); - if( self.supportAnimations ) { - self.$menu.on( self.animEndEventName, onAnimationEndFn ); - } - else { - onAnimationEndFn.call(); - } - - self.options.onLevelClick( $item, $item.children( 'a:first' ).text() ); - } ); - - return false; - - } - else { - self.options.onLinkClick( $item, event ); - } - - } ); - - this.$back.on( 'click.dlmenu', function( event ) { - - var $this = $( this ), - $submenu = $this.parents( 'ul.dl-submenu:first' ), - $item = $submenu.parent(), - - $flyin = $submenu.clone().insertAfter( self.$menu ); - - var onAnimationEndFn = function() { - self.$menu.off( self.animEndEventName ).removeClass( self.options.animationClasses.classin ); - $flyin.remove(); - }; - - setTimeout( function() { - $flyin.addClass( self.options.animationClasses.classout ); - self.$menu.addClass( self.options.animationClasses.classin ); - if( self.supportAnimations ) { - self.$menu.on( self.animEndEventName, onAnimationEndFn ); - } - else { - onAnimationEndFn.call(); - } - - $item.removeClass( 'dl-subviewopen' ); - - var $subview = $this.parents( '.dl-subview:first' ); - if( $subview.is( 'li' ) ) { - $subview.addClass( 'dl-subviewopen' ); - } - $subview.removeClass( 'dl-subview' ); - } ); - - return false; - - } ); - - }, - - isOpen: function(){ - return this.open - }, - - closeMenu : function() { - if( this.open ) { - this._closeMenu(); - } - }, - _closeMenu : function() { - var self = this, - onTransitionEndFn = function() { - self.$menu.off( self.transEndEventName ); - self._resetMenu(); - $body.removeClass('explorer-open'); - }; - - this.$menu.removeClass( 'dl-menuopen' ); - this.$menu.addClass( 'dl-menu-toggle' ); - this.$trigger.removeClass( 'dl-active' ); - - if( this.supportTransitions ) { - this.$menu.on( this.transEndEventName, onTransitionEndFn ); - } - else { - onTransitionEndFn.call(); - } - - this.open = false; - }, - openMenu : function() { - if( !this.open ) { - this._openMenu(); - } - }, - _openMenu : function() { - var self = this; - // clicking somewhere else makes the menu close - // $body.off( 'click' ).on( 'click.dlmenu', function() { - // self._closeMenu() ; - // } ); - this.$menu.addClass( 'dl-menuopen dl-menu-toggle' ).on( this.transEndEventName, function() { - $( this ).removeClass( 'dl-menu-toggle' ); - } ); - this.$trigger.addClass( 'dl-active' ); - $body.addClass('explorer-open'); - $('.explorer').css('top', $(document).scrollTop()); - this.open = true; - }, - // resets the menu to its original state (first level of options) - _resetMenu : function() { - this.$menu.removeClass( 'dl-subview' ); - this.$menuitems.parent().removeClass( 'dl-subview dl-subviewopen' ); - } - }; - - var logError = function( message ) { - if ( window.console ) { - window.console.error( message ); - } - }; - - $.fn.dlmenu = function( options ) { - if ( typeof options === 'string' ) { - var args = Array.prototype.slice.call( arguments, 1 ); - this.each(function() { - var instance = $.data( this, 'dlmenu' ); - if ( !instance ) { - logError( "cannot call methods on dlmenu prior to initialization; " + - "attempted to call method '" + options + "'" ); - return; - } - if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) { - logError( "no such method '" + options + "' for dlmenu instance" ); - return; - } - instance[ options ].apply( instance, args ); - }); - } - else { - this.each(function() { - var instance = $.data( this, 'dlmenu' ); - if ( instance ) { - instance._init(); - } - else { - instance = $.data( this, 'dlmenu', new $.DLMenu( options, this ) ); - } - }); - } - return this; - }; - -} )( jQuery, window ); \ No newline at end of file diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/admin_base.html b/wagtail/wagtailadmin/templates/wagtailadmin/admin_base.html index 6efe40706..30c77f21c 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/admin_base.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/admin_base.html @@ -52,7 +52,6 @@ - diff --git a/wagtail/wagtailadmin/wagtail_hooks.py b/wagtail/wagtailadmin/wagtail_hooks.py index ac2f51496..9b43baf50 100644 --- a/wagtail/wagtailadmin/wagtail_hooks.py +++ b/wagtail/wagtailadmin/wagtail_hooks.py @@ -1,8 +1,6 @@ from __future__ import absolute_import, unicode_literals -from django import forms from django.contrib.auth.models import Permission -from django.contrib.staticfiles.templatetags.staticfiles import static from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ @@ -18,10 +16,6 @@ from wagtail.wagtailcore.permissions import collection_permission_policy class ExplorerMenuItem(MenuItem): template = 'wagtailadmin/shared/explorer_menu_item.html' - @property - def media(self): - return forms.Media(js=[static('wagtailadmin/js/explorer-menu.js')]) - def is_shown(self, request): return user_has_any_page_permission(request.user)