⬆️ [megamenu] Upgrade to SmartMenus 1.2.1
This commit is contained in:
parent
10b496af27
commit
aed120f96d
13 changed files with 359 additions and 195 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use pagetop::prelude::*;
|
||||
use pagetop_jquery::JQuery;
|
||||
|
||||
use crate::component::MegaMenu;
|
||||
|
||||
new_handle!(COMPONENT_MEGAMENUITEM);
|
||||
|
||||
|
|
@ -141,135 +142,3 @@ impl MegaMenuItem {
|
|||
&self.item_type
|
||||
}
|
||||
}
|
||||
|
||||
// MegaMenu.
|
||||
|
||||
new_handle!(COMPONENT_MEGAMENU);
|
||||
|
||||
actions_for_component!(MegaMenu);
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Default)]
|
||||
pub struct MegaMenu {
|
||||
weight : Weight,
|
||||
renderable: Renderable,
|
||||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
items : PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
impl ComponentTrait for MegaMenu {
|
||||
fn new() -> Self {
|
||||
MegaMenu::default().with_classes(ClassesOp::SetDefault, "sm sm-clean")
|
||||
}
|
||||
|
||||
fn handle(&self) -> Handle {
|
||||
COMPONENT_MEGAMENU
|
||||
}
|
||||
|
||||
fn id(&self) -> Option<String> {
|
||||
self.id.get()
|
||||
}
|
||||
|
||||
fn weight(&self) -> Weight {
|
||||
self.weight
|
||||
}
|
||||
|
||||
fn is_renderable(&self, cx: &Context) -> bool {
|
||||
(self.renderable.check)(cx)
|
||||
}
|
||||
|
||||
fn before_prepare_component(&mut self, cx: &mut Context) {
|
||||
run_actions_before_prepare_megamenu(self, cx);
|
||||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
cx.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/megamenu/css/menu.css").with_version("1.1.1"),
|
||||
))
|
||||
.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/megamenu/css/menu-clean.css").with_version("1.1.1"),
|
||||
))
|
||||
.alter(ContextOp::AddJavaScript(
|
||||
JavaScript::at("/megamenu/js/menu.min.js").with_version("1.1.1"),
|
||||
));
|
||||
JQuery.enable_jquery(cx);
|
||||
|
||||
let id = cx.required_id::<MegaMenu>(self.id());
|
||||
|
||||
PrepareMarkup::With(html! {
|
||||
ul id=(id) class=[self.classes().get()] {
|
||||
(self.items().prepare(cx))
|
||||
}
|
||||
script type="text/javascript" defer {
|
||||
"jQuery(function(){jQuery('#" (id) "').smartmenus({"
|
||||
"hideTimeout: 0,"
|
||||
"showTimeout: 80,"
|
||||
"});});"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn after_prepare_component(&mut self, cx: &mut Context) {
|
||||
run_actions_after_prepare_megamenu(self, cx);
|
||||
}
|
||||
}
|
||||
|
||||
impl MegaMenu {
|
||||
// MegaMenu BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
|
||||
self.weight = value;
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
|
||||
self.renderable.check = check;
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.alter_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
|
||||
self.classes.alter_value(op, classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_item(mut self, item: MegaMenuItem) -> Self {
|
||||
self.items.alter(PackOp::Add, ComponentRef::to(item));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_items(&mut self, op: PackOp, item: MegaMenuItem) -> &mut Self {
|
||||
self.items.alter(op, ComponentRef::to(item));
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_template(&mut self, template: &str) -> &mut Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
||||
// MegaMenu GETTERS.
|
||||
|
||||
pub fn classes(&self) -> &Classes {
|
||||
&self.classes
|
||||
}
|
||||
|
||||
pub fn items(&self) -> &PackComponents {
|
||||
&self.items
|
||||
}
|
||||
|
||||
pub fn template(&self) -> &str {
|
||||
self.template.as_str()
|
||||
}
|
||||
}
|
||||
160
pagetop-megamenu/src/component/menu.rs
Normal file
160
pagetop-megamenu/src/component/menu.rs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
use pagetop::prelude::*;
|
||||
use pagetop_jquery::JQuery;
|
||||
|
||||
use crate::component::MegaMenuItem;
|
||||
use crate::LOCALES_MEGAMENU;
|
||||
|
||||
new_handle!(COMPONENT_MEGAMENU);
|
||||
|
||||
actions_for_component!(MegaMenu);
|
||||
|
||||
// SmartMenus library version.
|
||||
const VERSION_SMARTMENUS: &str = "1.2.1";
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Default)]
|
||||
pub struct MegaMenu {
|
||||
weight : Weight,
|
||||
renderable: Renderable,
|
||||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
items : PackComponents,
|
||||
}
|
||||
|
||||
impl ComponentTrait for MegaMenu {
|
||||
fn new() -> Self {
|
||||
MegaMenu::default().with_classes(ClassesOp::SetDefault, "megamenu-menu sm sm-clean")
|
||||
}
|
||||
|
||||
fn handle(&self) -> Handle {
|
||||
COMPONENT_MEGAMENU
|
||||
}
|
||||
|
||||
fn id(&self) -> Option<String> {
|
||||
self.id.get()
|
||||
}
|
||||
|
||||
fn weight(&self) -> Weight {
|
||||
self.weight
|
||||
}
|
||||
|
||||
fn is_renderable(&self, cx: &Context) -> bool {
|
||||
(self.renderable.check)(cx)
|
||||
}
|
||||
|
||||
fn before_prepare_component(&mut self, cx: &mut Context) {
|
||||
cx.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/megamenu/css/smartmenus.css").with_version(VERSION_SMARTMENUS),
|
||||
))
|
||||
.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/megamenu/css/sm-clean.css").with_version(VERSION_SMARTMENUS),
|
||||
))
|
||||
.alter(ContextOp::AddJavaScript(
|
||||
JavaScript::at("/megamenu/js/smartmenus.min.js").with_version(VERSION_SMARTMENUS),
|
||||
));
|
||||
JQuery.enable_jquery(cx);
|
||||
|
||||
run_actions_before_prepare_megamenu(self, cx);
|
||||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
let id_nav = cx.required_id::<MegaMenu>(self.id());
|
||||
let id_menu = concat_string!(id_nav, "-menu");
|
||||
let id_state = concat_string!(id_nav, "-state");
|
||||
|
||||
PrepareMarkup::With(html! {
|
||||
nav id=(id_nav) class="megamenu" role="navigation" {
|
||||
input id=(id_state) class="megamenu-state" type="checkbox" {}
|
||||
label class="megamenu-btn" for=(id_state) {
|
||||
span class="megamenu-btn-icon" {}
|
||||
(L10n::t("toggle_menu", &LOCALES_MEGAMENU).prepare(cx))
|
||||
}
|
||||
ul id=(id_menu) class=[self.classes().get()] {
|
||||
(self.items().prepare(cx))
|
||||
}
|
||||
script type="text/javascript" defer {
|
||||
r###"
|
||||
$(function() {
|
||||
$('#"###r (id_menu) r###"').smartmenus({
|
||||
hideTimeout: 0,
|
||||
showTimeout: 80,
|
||||
});
|
||||
});
|
||||
$(function() {
|
||||
var $menuState = $('#"###r (id_state) r###"');
|
||||
if ($menuState.length) {
|
||||
// Animate mobile menu.
|
||||
$menuState.change(function(e) {
|
||||
var $menu = $('#"###r (id_menu) r###"');
|
||||
if (this.checked) {
|
||||
$menu.hide().slideDown(250, function() { $menu.css('display', ''); });
|
||||
} else {
|
||||
$menu.show().slideUp(250, function() { $menu.css('display', ''); });
|
||||
}
|
||||
});
|
||||
// Hide mobile menu beforeunload.
|
||||
$(window).on('beforeunload unload', function() {
|
||||
if ($menuState[0].checked) {
|
||||
$menuState[0].click();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
"###r
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn after_prepare_component(&mut self, cx: &mut Context) {
|
||||
run_actions_after_prepare_megamenu(self, cx);
|
||||
}
|
||||
}
|
||||
|
||||
impl MegaMenu {
|
||||
// MegaMenu BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
|
||||
self.weight = value;
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
|
||||
self.renderable.check = check;
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_id(&mut self, id: &str) -> &mut Self {
|
||||
self.id.alter_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
|
||||
self.classes.alter_value(op, classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_item(mut self, item: MegaMenuItem) -> Self {
|
||||
self.items.alter(PackOp::Add, ComponentRef::to(item));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_items(&mut self, op: PackOp, item: MegaMenuItem) -> &mut Self {
|
||||
self.items.alter(op, ComponentRef::to(item));
|
||||
self
|
||||
}
|
||||
|
||||
// MegaMenu GETTERS.
|
||||
|
||||
pub fn classes(&self) -> &Classes {
|
||||
&self.classes
|
||||
}
|
||||
|
||||
pub fn items(&self) -> &PackComponents {
|
||||
&self.items
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,16 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
pub mod component;
|
||||
pub mod component {
|
||||
mod item;
|
||||
pub use item::{MegaMenuItem, MegaMenuItemType, COMPONENT_MEGAMENUITEM};
|
||||
mod menu;
|
||||
pub use menu::{MegaMenu, COMPONENT_MEGAMENU};
|
||||
}
|
||||
|
||||
new_handle!(MODULE_MEGAMENU);
|
||||
|
||||
static_locales!(LOCALES_MEGAMENU);
|
||||
|
||||
static_files!(megamenu);
|
||||
|
||||
pub struct MegaMenu;
|
||||
|
|
@ -13,6 +20,14 @@ impl ModuleTrait for MegaMenu {
|
|||
MODULE_MEGAMENU
|
||||
}
|
||||
|
||||
fn name(&self) -> L10n {
|
||||
L10n::t("module_name", &LOCALES_MEGAMENU)
|
||||
}
|
||||
|
||||
fn description(&self) -> L10n {
|
||||
L10n::t("module_description", &LOCALES_MEGAMENU)
|
||||
}
|
||||
|
||||
fn dependencies(&self) -> Vec<ModuleRef> {
|
||||
vec![&pagetop_jquery::JQuery]
|
||||
}
|
||||
|
|
|
|||
4
pagetop-megamenu/src/locale/en-US/module.ftl
Normal file
4
pagetop-megamenu/src/locale/en-US/module.ftl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
module_name = MegaMenu
|
||||
module_description = ...
|
||||
|
||||
toggle_menu = Toggle menu visibility
|
||||
4
pagetop-megamenu/src/locale/es-ES/module.ftl
Normal file
4
pagetop-megamenu/src/locale/es-ES/module.ftl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
module_name = MegaMenu
|
||||
module_description = ...
|
||||
|
||||
toggle_menu = Alternar visibilidad del menú
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
.sm {
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
z-index: 9999;
|
||||
-webkit-tap-highlight-color: rgba(0,0,0,0);
|
||||
}
|
||||
.sm,
|
||||
.sm ul,
|
||||
.sm li {
|
||||
display: block;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
line-height: normal;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
}
|
||||
.sm-rtl,
|
||||
.sm-rtl ul,
|
||||
.sm-rtl li {
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
.sm > li > h1,
|
||||
.sm > li > h2,
|
||||
.sm > li > h3,
|
||||
.sm > li > h4,
|
||||
.sm > li > h5,
|
||||
.sm > li > h6 {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.sm ul {
|
||||
display: none;
|
||||
}
|
||||
.sm li,
|
||||
.sm a {
|
||||
position: relative;
|
||||
}
|
||||
.sm a {
|
||||
display: block;
|
||||
}
|
||||
.sm a.disabled {
|
||||
cursor: default;
|
||||
}
|
||||
.sm::after {
|
||||
content: "";
|
||||
display: block;
|
||||
height: 0;
|
||||
font: 0px/0 serif;
|
||||
clear: both;
|
||||
overflow: hidden;
|
||||
}
|
||||
.sm *,
|
||||
.sm *::before,
|
||||
.sm *::after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
170
pagetop-megamenu/static/css/smartmenus.css
Normal file
170
pagetop-megamenu/static/css/smartmenus.css
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/* Mobile first layout SmartMenus Core CSS (it's not recommended editing these rules)
|
||||
You need this once per page no matter how many menu trees or different themes you use.
|
||||
-------------------------------------------------------------------------------------------*/
|
||||
|
||||
.megamenu {
|
||||
background: #eee;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-ms-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.megamenu {
|
||||
-webkit-border-radius: 50px;
|
||||
-moz-border-radius: 50px;
|
||||
-ms-border-radius: 50px;
|
||||
-o-border-radius: 50px;
|
||||
border-radius: 50px;
|
||||
}
|
||||
}
|
||||
|
||||
.megamenu:after {
|
||||
clear: both;
|
||||
content: "\00a0";
|
||||
display: block;
|
||||
height: 0;
|
||||
font: 0px/0 serif;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.nav-brand {
|
||||
float: left;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.nav-brand a {
|
||||
display: block;
|
||||
padding: 12px 12px 12px 20px;
|
||||
color: #555;
|
||||
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
font-size: 22px;
|
||||
font-weight: normal;
|
||||
line-height: 17px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.megamenu-menu {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.megamenu-menu {
|
||||
float: right;
|
||||
clear: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mobile menu toggle button */
|
||||
|
||||
.megamenu-btn {
|
||||
float: right;
|
||||
margin: 6px 10px;
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 29px;
|
||||
height: 29px;
|
||||
text-indent: 29px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* Hamburger icon */
|
||||
|
||||
.megamenu-btn-icon,
|
||||
.megamenu-btn-icon:before,
|
||||
.megamenu-btn-icon:after {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 2px;
|
||||
height: 2px;
|
||||
width: 24px;
|
||||
background: #555;
|
||||
-webkit-transition: all 0.25s;
|
||||
transition: all 0.25s;
|
||||
}
|
||||
|
||||
.megamenu-btn-icon:before {
|
||||
content: '';
|
||||
top: -7px;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.megamenu-btn-icon:after {
|
||||
content: '';
|
||||
top: 7px;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
/* X icon */
|
||||
|
||||
.megamenu-state:checked ~ .megamenu-btn .megamenu-btn-icon {
|
||||
height: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.megamenu-state:checked ~ .megamenu-btn .megamenu-btn-icon:before {
|
||||
top: 0;
|
||||
-webkit-transform: rotate(-45deg);
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
.megamenu-state:checked ~ .megamenu-btn .megamenu-btn-icon:after {
|
||||
top: 0;
|
||||
-webkit-transform: rotate(45deg);
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
/* Hide menu state checkbox (keep it visible to screen readers) */
|
||||
|
||||
.megamenu-state {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
margin: -1px;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
clip: rect(1px, 1px, 1px, 1px);
|
||||
}
|
||||
|
||||
/* Hide the menu in mobile view */
|
||||
|
||||
.megamenu-state:not(:checked) ~ .megamenu-menu {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.megamenu-state:checked ~ .megamenu-menu {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
/* Hide the button in desktop view */
|
||||
.megamenu-btn {
|
||||
position: absolute;
|
||||
top: -99999px;
|
||||
}
|
||||
/* Always show the menu in desktop view */
|
||||
.megamenu-state:not(:checked) ~ .megamenu-menu {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.sm{box-sizing:border-box;position:relative;z-index:9999;-webkit-tap-highlight-color:rgba(0,0,0,0);}
|
||||
.sm,.sm ul,.sm li{display:block;list-style:none;margin:0;padding:0;line-height:normal;direction:ltr;text-align:left;}
|
||||
.sm-rtl,.sm-rtl ul,.sm-rtl li{direction:rtl;text-align:right;}
|
||||
.sm>li>h1,.sm>li>h2,.sm>li>h3,.sm>li>h4,.sm>li>h5,.sm>li>h6{margin:0;padding:0;}
|
||||
.sm ul{display:none;}
|
||||
.sm li,.sm a{position:relative;}
|
||||
.sm a{display:block;}
|
||||
.sm a.disabled{cursor:default;}
|
||||
.sm::after{content:"";display:block;height:0;font:0px/0 serif;clear:both;overflow:hidden;}
|
||||
.sm *,.sm *::before,.sm *::after{box-sizing:inherit;}
|
||||
3
pagetop-megamenu/static/js/menu.min.js
vendored
3
pagetop-megamenu/static/js/menu.min.js
vendored
File diff suppressed because one or more lines are too long
3
pagetop-megamenu/static/js/smartmenus.min.js
vendored
Normal file
3
pagetop-megamenu/static/js/smartmenus.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue