Magento 2 自带模态的应用
Modal widget in Magento 2
Magento 2 自带模态的应用
使用magento 2 的自带模态组件,以下代码只供参考使用。
1,DOM 》模态块与触发元素
.pthml
<!-- 模态DOM -->
<div id="modal-content" hidden="hidden" data-goodsid=""> <?php if ($block->isLogin()): ?>
<!-- fixme view data-->
<!-- Add list CSS @var todo $mcsize_list Mc_Size::css/account/mcsize_list.css -->
<link rel="stylesheet" href="<?php echo $this->getViewFileUrl('Mc_Size::css/account/mcsize_list.css'); ?>"> <!-- Add list DOM-->
<div id="account-mcsize-lists">
<span class="base page-title">Select size</span>
<hr>
<div>
<span class="btn-xs cursor" id="tape">Tape </span>
<span> | </span>
<span class="btn-xs cursor" id="shirt">Shirt </span>
</div>
<br>
<!-- fixme tape-->
<div id="class_tape" class="measurement-profiles"> <?php $list_data = $block->getTapeList(); ?>
<?php foreach ($list_data as $news) { ?>
<div class="measurement-profile c-24 c-m-24" data-id="<?php echo $news['tape_id'] ?>" data-type="tape">
<div>
<div class="icon">
<!--fixme img icon-->
<!--fixme edit--> <img src="<?php echo $this->getViewFileUrl('Mc_Size::images/tape-measure.svg'); ?>"
alt=""> </div>
<div class="summary">
<span class="name"><?php echo $news['name']; ?></span><br>
<span class="type">Body measurements - <?php echo $news['created_at']; ?></span>
</div> <div class="actions">
<a class="primaryButton mini"
href="/mcsize/index/tape?id=<?php echo $news['tape_id'] ?>">Edit</a>
</div>
</div>
</div>
<?php } ?>
</div>
<!-- end--> </div>
<?php else: ?>
<!-- fixme view message-->
<div class="col-md-12">Go to <a href="/customer/account/login" class="">Login</a> now !</div>
<?php endif ?>
</div> <!-- 触发元素-->
<div id="__modal-button-<?php echo $_item->getId(); ?>" style="cursor: pointer;" data-mage-init='{"example-modal": {"target": "#modal-content"}}' class="btn-xs btn-primary"> Binding size</div>
2,配置模块名》目录自动加载
/app/code/vendor_name/module_name/view/frontend/requirejs-config.js
var config = {
map: {
'*': {
'example-modal': '<vendor_name>_<module_name>/js/example-modal'
}
}
};
3,调用模态》用于触发的 js 代码
example-modal.js —— 注意:ExampleModal 对象对模块绑定函数
define([
"jquery", "Magento_Ui/js/modal/modal", 'Mc_Size/plugins/sweetalert.min'
], function ($) { var p = "#account-mcsize-lists";
var f = ".measurement-profile";
var ac = 'active'; $(p).find(f).on('click', clickSize); function clickSize(e) {
e.stopPropagation();
var me = $(this);
me.addClass(ac); me.siblings().removeClass('active');
} /**
*
* @param name
* @returns {*|jQuery.fn.init|n.fn.init|m.fn.init|jQuery|HTMLElement}
*/
function getobj(name) {
return $(name);
} $('#tape').on('click', function () {//todo click tape var s = '#class_shirt';
var t = '#class_tape';
var t_html = $(t).clone(true);
var s_html = $(s).clone(true); $(t).remove();
$(s).remove(); $(p).append(t_html);
$('#shirt_dom').append(s_html);
}); $('#shirt').on('click', function () {//todo click shirt var s = '#class_shirt';
var t = '#class_tape';
var t_html = $(t).clone(true);
var s_html = $(s).clone(true); $(t).remove();
$(s).remove(); $('#shirt_dom').append(t_html);
$(p).append(s_html); $(p).find(f).on('click', clickSize);
}); // fixme modal
var ExampleModal = {
initModal: function (config, element) {
$target = $(config.target);
$element = $(element);
$target.modal({
closed: function () {
// Do some action when modal closed
var tape_id = $(p).find('.active').data('id');
var type = $(p).find('.active').data('type');
if (!tape_id) {
$target.modal('openModal');//open modal
return;
} var active = '#cart-' + ac;
$(active).attr({'data-id': tape_id,'data-type':type}).text('Already bound').addClass('btn-danger');
$(p).find(f).removeClass(ac);
$(active).attr('id', '');//remove id
}
}); $element.click(function () {
var dataid = $(this).attr('data-id');
var datatype = $(this).attr('data-type'); $(this).attr('id', 'cart-' + ac);//add id //data-type is shirt
if(datatype === 'shirt'){
$('#shirt').trigger('click');//event trigger
}else if(datatype === 'tape'){
$('#tape').trigger('click');//event trigger
} if (dataid) {
$(p).find('div[data-id=' + dataid + ']').addClass(ac);
}else{
// ..
} $target.modal('openModal');//open modal }); }
};
return {
'example-modal': ExampleModal.initModal
};
}
);
@其它——直接在页面使用
<script>
require(
["jquery", "Magento_Ui/js/modal/modal", 'Mc_Size/plugins/sweetalert.min']
, function ($,modal,swal) { var options = {
'type': 'popup',
'title': 'Select Gender',
'responsive': true,
'innerScroll': true,
}; var popup = modal(options, $('#modal-content'));
$('#modal-content').modal('openModal');//open modal
})
</script>
Magento 2 自带模态的应用的更多相关文章
- [转]解决Magento批量导入带图片的商品的问题
本文转自:http://www.phpstudio.info/show-121-791-1.html 一般来说,Magento后台管理里的CSV批量导入,可以解决我们商品批量上传的大部分问题,我们只要 ...
- magento安装
最近在做一个Magento 1.7.0.2的站,在安装环节Magento一直报错Database server does not support the InnoDB storage engine. ...
- Magento给新产品页面添加分页
本文介绍如何让magento创建一个带分页功能的新到产品页面,方便我们在首页或者其它CMS Page调用和展示新到产品. 在Magento我们经常有的做法是建立一个可以调用新产品的block,然后通过 ...
- magento数据库备份导入还原
Magento数据库备份.移植终极解决方案+3 分类:Magento教程 标签:magento搬家.magento数据库备份.magento更换域名.magento移植 4,355人浏览 作为电子商务 ...
- magneto创建运费模板
Magento系统自带了大概7种运费方式:平价.运费表.免运费.ups.usps.fedex.dhl等.不过这些依然无法满足我们的需求,这时候就需要创建一个shipping module 来实现了.创 ...
- 测试报告$\alpha$
pytorch可视化编程网站VisualPytorch NAG \(\alpha\)版本发布了!点击网址访问:VisualPytorch 一.测试查虫(bug detection) 测试贯穿了开发.集 ...
- QT模态对话框用法(在UI文件中设置Widget背景图,这个图是一个带阴影边框的图片——酷)
QT弹出模态对话框做法: 1.新建UI文件时,一定要选择基类是QDialog的,我的选择是:Dialog without Buttons(),如下图: 2.然后在使用的时候: MyDialog dlg ...
- Bootstrap 模态框(Modal)带参数传值实例
模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动.子窗体可提供信息.交互等. 为了实现父窗体与其的交互,通常需要向其传值,实现 ...
- bootstrap如何去除自带的样式----导航栏中的菜单实现平滑的过渡到对应的菜单区域-------动态跟换模态框中的内容
问题1:如何去除bootstap中css中自带的overflow:hidden这个样式 今天遇见在bootstap中轮播图上的 附带图 片不能够显示出来,图片始终有一部分的高度 被隐藏了 后来通 ...
随机推荐
- DSAPI TreeView节点增删简化操作
将一行或多行字符串添加到TreeView控件. 函数: 控件.TreeView控件.添加路径节点到TreeView(要添加节点的TreeView控件,字符串或字符串数组) 示例:将一个多行文本添加到T ...
- Python3中列表字符串转数字
比如我们有个列表: number = [']; 如果我们需要将列表里的元素转换为数字呢?最常用的大家可能会想到使用列表推导式: number = ['] number = [int(x) for x ...
- 【Json】fastjson与jackson常用操作记录
本文只是记录fastjson.jackson一些常用的操作方法,没作比较,网上写比较的文章很多啦. 1.对象转Json串 // fastjson String objStr = JSON.toJSON ...
- .net core identity集成微信授权登录
最快的方式是直接nuget安装AspNetCore.Authentication.WeChat包. 想要知道是如何实现的,可以看下面github上面的源码. 源码在这里:https://github. ...
- C# 通用单例窗体类
/// <summary> /// 通用的单例制作器 /// </summary> /// <typeparam name="T"></t ...
- Netty 核心容器之ByteBuf 结构详解
原文链接 Netty 核心容器之ByteBuf 结构详解 代码仓库地址 Java的NIO模块提供了ByteBuffer作为其字节存储容器,但是这个类的使用过于复杂,因此Netty实现了ByteBuf来 ...
- 配置MySQL的数据源
首先查看自己是否有这个驱动 有就进行以下操作,没有那就找下载 安装mysql-for-visualstudio 1)双击 mysql-for-visualstudio-2.0.5.msi 2)点击 ...
- git pull以及git pull --rebase
git pull的作用是将远程库中的更改代码合并到当前分支中,默认为:git fetch + git merge git fetch 的作用就相当于是从远程库中获取最新版本到本地分支,不会自动进行gi ...
- php类注释生成接口文档
参考地址:https://github.com/itxq/api-doc-php
- Vue组件之全局组件与局部组件
1全局注册实例 <div id="app"> <com-btn></com-btn> <com-btn></com-btn&g ...