Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal添加draggable,modal、loading、imagepreview添加el,指定父级元素 #350

Merged
merged 5 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const doc = (isDev, callback) => {
// 组件文档
CATES.forEach((c) => {
const components = getComponents(c.cate).filter((comp) => {
if (isDev && !/^KL(Sidebar|Upload|Menu|Button|Table|Select|MultiSelect)$/.test(comp)) {
if (isDev && !/^KL(Sidebar|Modal|Draggable|Button|Loading|ImagePreview)$/.test(comp)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion doc/themes/nekui/layout/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $(document).ready(function() {
'background': '#1D2E45 url(//haitao.nos.netease.com/056f5787-daa5-4a46-8eb4-d662eb6c7618.jpg) no-repeat scroll right bottom'});
$('.m-section1').addClass('loaded');
};
earth.src = 'http://haitao.nos.netease.com/056f5787-daa5-4a46-8eb4-d662eb6c7618.jpg';
earth.src = '//haitao.nos.netease.com/056f5787-daa5-4a46-8eb4-d662eb6c7618.jpg';

var $header = $('#header'),
$logo = $('#logo'),
Expand Down
2 changes: 2 additions & 0 deletions doc/themes/nekui/layout/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">

<link rel="dns-prefetch" href="//cdnjs.cloudflare.com" />
<link rel="dns-prefetch" href="//haitao.nos.netease.com" />
<link rel="dns-prefetch" href="//at.alicdn.com" />

<% if (isIndex) { %>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.5/jquery.fullpage.min.css" />
Expand Down
10 changes: 5 additions & 5 deletions src/js/components/notice/KLModal/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="m-modal {class}" r-animation='on:leave;class: modal_animated modal_zoomOut'>
<div class="modal_dialog modal_animated zoomIn fast" style="width: {width}px" ref="modalDialog">
<draggable disabled={!draggable} proxy={this.$refs.modalDialog} on-dragstart={this._onDragStart($event)}>
<div class="m-modal {class}" r-anim='on:enter; class: modal_animated modal_zoomIn; on:leave; class: modal_animated modal_zoomOut;'>
<div class="modal_dialog" style="width: {width}px;" ref="modalDialog">
<kl-draggable disabled={!draggable} proxy={this.$refs.modalDialog} on-dragstart={this._onDragStart($event)}>
<div class="modal_hd">
{#if isCanClose}
<a class="modal_close" on-click={this.close(false)}><i class="u-icon u-icon-close"></i></a>
{/if}
<h3 class="modal_title">{title}</h3>
</div>
</draggable>
</kl-draggable>
<div class="modal_bd" {#if maxHeight || minHeight} style="max-height: {maxHeight}px; min-height: {minHeight}px; overflow: auto;" {/if}>
{#if contentTemplate}{#inc @(contentTemplate)}{#else}{content}{/if}
</div>
Expand All @@ -17,7 +17,7 @@ <h3 class="modal_title">{title}</h3>
{#inc @(footerTemplate)}
{#else}
{#if okButton}
<kl-button type="primary" title={okButton === true ? this.$trans('CONFIRM') : okButton}on-click={this.close(true, $event)} disabled={okDisabled} />
<kl-button type="primary" title={okButton === true ? this.$trans('CONFIRM') : okButton} on-click={this.close(true, $event)} disabled={okDisabled} />
{/if}
{#if cancelButton && isCanClose}
<kl-button title={cancelButton === true ? this.$trans('CANCEL') : cancelButton}
Expand Down
9 changes: 6 additions & 3 deletions src/js/components/notice/KLModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const _ = require('../../../ui-base/_');
* @param {boolean} [options.data.noClose] => ok时是否关闭弹窗
* @param {number} [options.data.minHeight] => 内容区域最小高度
* @param {number} [options.data.maxHeight] => 内容区域最大高度,超出则显示滚动条
* @param {string} [options.data.el] => 设置对话框要插入的父级元素,默认为document.body
* @param {boolean} [options.data.draggable=false] => 是否可以拖拽对话框
*/
const KLModal = Component.extend({
name: 'kl-modal',
Expand All @@ -48,9 +50,10 @@ const KLModal = Component.extend({

init() {
this.supr();

// 如果不是内嵌组件,则嵌入到document.body中
if (this.$root === this) this.$inject(document.body);
// 如果不是内嵌组件,则嵌入到data.el或document.body中
if (this.$root === this) {
this.$inject(this.data.el || document.body);
}
},
/**
* @method KLModal#close(result) 关闭对话框
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/notice/KLModal/index.mcss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// - Mask the background page
background: rgba(0, 0, 0, 0.6);

&:before {
&:after {
content: '';
display: inline-block;
vertical-align: middle;
Expand Down
88 changes: 70 additions & 18 deletions src/js/components/notice/KLModal/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@ var component = new NEKUI.Component({
```
<!-- demo_end -->

<!-- demo_start -->
### 配置要嵌入的父级元素

设置modal嵌入的父级元素,默认为document.body

<div class="m-example"></div>

```xml
<kl-button on-click="{this.show()}" title="el: main"/>
```

```javascript
var component = new NEKUI.Component({
template: template,
show: function() {
// 打开一个Modal,inject到#main元素里
var modal = new NEKUI.KLModal({
data: {
content: 'Modal内容',
el: '#main'
}
});
}
});
```
<!-- demo_end -->

<!-- demo_start -->
### 配置信息title

Expand Down Expand Up @@ -95,7 +122,7 @@ var component = new NEKUI.Component({
show: function() {
var modal = new NEKUI.KLModal({
data: {

name: 'Rabbit',
contentTemplate: '<kl-row><kl-col span=10><kl-input value="{name}"/></kl-col></kl-row>'
}
Expand All @@ -121,7 +148,7 @@ var component = new NEKUI.Component({
show: function() {
var modal = new NEKUI.KLModal({
data: {

name: 'Rabbit',
content: '自定义footer',
footerTemplate: '<kl-row><kl-col span=6><kl-button title="提交" type="secondary" /></kl-col><kl-col span=6><kl-button title="撤销" type="success" /></kl-col></kl-row>'
Expand All @@ -148,7 +175,7 @@ var component = new NEKUI.Component({
show: function(okDisabled) {
var modal = new NEKUI.KLModal({
data: {

okDisabled: okDisabled,
content: 'okDisabled设置为' + okDisabled,
}
Expand All @@ -174,7 +201,7 @@ var component = new NEKUI.Component({
show: function(cancelDisabled) {
var modal = new NEKUI.KLModal({
data: {

cancelDisabled: cancelDisabled,
cancelButton: true,
content: 'cancelDisabled设置为' + cancelDisabled,
Expand Down Expand Up @@ -203,7 +230,7 @@ var component = new NEKUI.Component({
show: function(hasFooter) {
var modal = new NEKUI.KLModal({
data: {

hasFooter: hasFooter,
content: 'hasFooter设置为' + hasFooter,
}
Expand Down Expand Up @@ -233,7 +260,7 @@ var component = new NEKUI.Component({
show: function(isCanClose) {
var modal = new NEKUI.KLModal({
data: {

isCanClose: isCanClose,
content: 'isCanClose设置为' + isCanClose,
}
Expand Down Expand Up @@ -263,7 +290,7 @@ var component = new NEKUI.Component({
show: function(okButton) {
var modal = new NEKUI.KLModal({
data: {

okButton: okButton,
content: '设置okButton的值',
}
Expand All @@ -290,7 +317,7 @@ var component = new NEKUI.Component({
show: function(cancelButton) {
var modal = new NEKUI.KLModal({
data: {

cancelButton: cancelButton,
content: '设置cancelButton'
}
Expand Down Expand Up @@ -324,7 +351,7 @@ var component = new NEKUI.Component({
show: function() {
var modal = new NEKUI.KLModal({
data: {

cancelButton: true,
content: '设置自定义样式',
class: 'u-modal-red',
Expand Down Expand Up @@ -352,7 +379,7 @@ var component = new NEKUI.Component({
show: function(noClose) {
var modal = new NEKUI.KLModal({
data: {

noClose: noClose,
content: '设置noClose:' + noClose,
}
Expand Down Expand Up @@ -430,6 +457,31 @@ var component = new NEKUI.Component({
```
<!-- demo_end -->

<!-- demo_start -->
### 配置信息draggable
设置Modal可拖拽,默认不可拖拽。

<div class="m-example"></div>

```xml
<kl-button on-click="{this.show()}" title="draggable:true"/>
```

```javascript
var component = new NEKUI.Component({
template: template,
show: function() {
var modal = new NEKUI.KLModal({
data: {
content: 'Modal可拖拽',
draggable: true
}
});
}
});
```
<!-- demo_end -->

<!-- demo_start -->
### 实例方法cancel
通过实例调用,执行该实例对象的`cancel`事件
Expand All @@ -453,11 +505,11 @@ var component = new NEKUI.Component({
var modal = new NEKUI.KLModal({
data: data
});

modal.$on('cancel', function(){
console.log('监听cancel事件');
});

setTimeout(function(){
modal.cancel();
}, 3000);
Expand Down Expand Up @@ -535,11 +587,11 @@ var component = new NEKUI.Component({
var modal = new NEKUI.KLModal({
data: data
});

modal.$on('ok', function(){
console.log('监听ok事件');
});

setTimeout(function(){
modal.ok();
}, 3000);
Expand Down Expand Up @@ -584,11 +636,11 @@ var component = new NEKUI.Component({
template: template,
show: function(content, title, okButton, cancelButton) {
var modal = NEKUI.KLModal.confirm(content, title, okButton, cancelButton);

modal.$on('ok', function(){
console.log('监听ok事件');
});

modal.$on('cancel', function(){
console.log('监听cancel事件');
});
Expand Down Expand Up @@ -622,9 +674,9 @@ var component = new NEKUI.Component({
var component = new NEKUI.Component({
template: template,
show: function(content, title, okButton) {

var modal = NEKUI.KLModal.alert(content, title, okButton);

modal.$on('ok', function(){
console.log('监听ok事件');
});
Expand Down
17 changes: 17 additions & 0 deletions src/js/components/widget/KLDraggable/dragdrop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const dragdrop = {
dragging: false,
data: null,
proxy: null,
screenX: 0,
screenY: 0,
clientX: 0,
clientY: 0,
pageX: 0,
pageY: 0,
movementX: 0,
movementY: 0,
droppable: null,
droppables: [],
};

module.exports = dragdrop;
Loading