From 15eda163ebc5f28f19161d567afdf03e37cf516a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 13 Feb 2018 14:03:45 +0100 Subject: [PATCH] =?utf8?q?HTML=20Men=C3=BC:=20Javascript=20ausgelagert=20i?= =?utf8?q?n=20eigene=20Datei?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Layout/MenuLeft.pm | 11 ++++------- js/kivi.LeftMenu.js | 22 ++++++++++++++++++++++ templates/webpages/menu/menu.html | 20 -------------------- 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 js/kivi.LeftMenu.js delete mode 100644 templates/webpages/menu/menu.html diff --git a/SL/Layout/MenuLeft.pm b/SL/Layout/MenuLeft.pm index 25119fed2..d365210c9 100644 --- a/SL/Layout/MenuLeft.pm +++ b/SL/Layout/MenuLeft.pm @@ -3,25 +3,22 @@ package SL::Layout::MenuLeft; use strict; use parent qw(SL::Layout::Base); -use URI; - use List::MoreUtils qw(apply); +use SL::JSON qw(to_json); +use URI; sub stylesheets { qw(icons16.css icons24.css menu.css) } sub javascripts_inline { - my $self = shift; - my $sections = [ section_menu($self->menu) ]; - $self->presenter->render('menu/menu', - sections => $sections, - ) + "\$(function(){kivi.LeftMenu.init(@{[ to_json([ section_menu($_[0]->menu) ]) ]})});" } sub javascripts { qw( js/jquery.cookie.js + js/kivi.LeftMenu.js ); } diff --git a/js/kivi.LeftMenu.js b/js/kivi.LeftMenu.js new file mode 100644 index 000000000..537974e72 --- /dev/null +++ b/js/kivi.LeftMenu.js @@ -0,0 +1,22 @@ +namespace('kivi.LeftMenu', function(ns) { + 'use strict'; + ns.init = function(sections) { + sections.forEach(function(b,i){ + var a=$('').append($('').append($('
').addClass(b[3])),$('').append(b[0])); + if(b[5])a.attr('href', b[5]); + if(b[6])a.attr('target', b[6]); + $('#html-menu').append($('
').addClass(b[4]).addClass(b[1]).attr('id','mi'+b[2]).append(a)) + }); + $('#html-menu div.i, #html-menu div.sm').not('[id^='+$.cookie('html-menu-selection')+'_]').hide(); + $('#html-menu div.m#'+$.cookie('html-menu-selection')).addClass('menu-open'); + $('#html-menu div.m').each(function(){ + $(this).click(function(){ + $.cookie('html-menu-selection',$(this).attr('id')); + $('#html-menu div.mi').not('div.m').not('[id^='+$(this).attr('id')+'_]').hide(); + $('#html-menu div.mi[id^='+$(this).attr('id')+'_]').toggle(); + $('#html-menu div.m').not('[id^='+$(this).attr('id')+']').removeClass('menu-open'); + $(this).toggleClass('menu-open'); + }); + }); + }; +}); diff --git a/templates/webpages/menu/menu.html b/templates/webpages/menu/menu.html deleted file mode 100644 index b37574271..000000000 --- a/templates/webpages/menu/menu.html +++ /dev/null @@ -1,20 +0,0 @@ -[%- USE JSON %] -$(function(){$([% JSON.json(sections) %]).each(function(i,b){ - var a=$('').append($('').append($('
').addClass(b[3])),$('').append(b[0])); - if(b[5])a.attr('href', b[5]); - if(b[6])a.attr('target', b[6]); - $('#html-menu').append($('
').addClass(b[4]).addClass(b[1]).attr('id','mi'+b[2]).append(a)) -}); -$('#html-menu div.i, #html-menu div.sm').not('[id^='+$.cookie('html-menu-selection')+'_]').hide(); -$('#html-menu div.m#'+$.cookie('html-menu-selection')).addClass('menu-open'); -$('#html-menu div.m').each(function(){ - $(this) - .click(function(){ - $.cookie('html-menu-selection',$(this).attr('id')); - $('#html-menu div.mi').not('div.m').not('[id^='+$(this).attr('id')+'_]').hide(); - $('#html-menu div.mi[id^='+$(this).attr('id')+'_]').toggle(); - $('#html-menu div.m').not('[id^='+$(this).attr('id')+']').removeClass('menu-open'); - $(this).toggleClass('menu-open'); - }) -}) -}) -- 2.20.1