Merge remote-tracking branch 'origin/feature/modal' into feature/modal
# Conflicts: # apps/example/views/action/index.hbs # public/js/common/modal.js # public/js/common/overlay.js # public/js/example/home.page.js # public/scss/common/_modal.css # public/scss/common/_overlay.css
Showing
6 changed files
with
32 additions
and
227 deletions
1 | <h1>公有样式示例</h1> | 1 | <h1>公有样式示例</h1> |
2 | 2 | ||
3 | <h2>color</h2> | 3 | <h2>color</h2> |
4 | -统一色号(css 中使用统一变量)<br> | 4 | +统一色号(css 中使用统一变量) |
5 | 5 | ||
6 | -黑色: $black; <span class="example color black"></span><br> | ||
7 | -白色: $white; <span class="example color white"></span><br> | ||
8 | -红色: $red; <span class="example color red"></span><br> | ||
9 | -绿色: $green; <span class="example color green"></span><br> | ||
10 | -灰色: $grey; <span class="example color grey"></span><br> | ||
11 | -蓝色: $blue; <span class="example color blue"></span><br> | 6 | +主色调: |
7 | +底色: | ||
8 | +红色: | ||
12 | 9 | ||
13 | <h2>icon</h2> | 10 | <h2>icon</h2> |
14 | -iconfont 新建项目,使用 class 控制图标样式,不要用 unicode<br> | ||
15 | - | ||
16 | -<span class="icon icon-bag"></span> | ||
17 | -<span class="icon icon-check"></span> | ||
18 | -<span class="icon icon-close"></span> | ||
19 | -<span class="icon icon-left"></span> | ||
20 | -<span class="icon icon-right"></span> | ||
21 | -<span class="icon icon-search"></span> | ||
22 | -<span class="icon icon-down"></span> | ||
23 | -<span class="icon icon-up"></span> | ||
24 | -<span class="icon icon-love"></span> | ||
25 | -<span class="icon icon-delete"></span> | ||
26 | - | 11 | +iconfont 新建项目,使用 class 控制图标样式,不要用 unicode |
27 | 12 | ||
28 | <h2>button</h2> | 13 | <h2>button</h2> |
29 | -三种尺寸,圆角直角,实心空心<br> | ||
30 | - | ||
31 | -<button class="button">空心</button> | ||
32 | -<button class="button button-solid">实心</button> | ||
33 | -<hr> | ||
34 | -<button class="button button-round">圆角</button> | ||
35 | -<button class="button button-round button-solid">圆角,实心</button> | ||
36 | -<hr> | ||
37 | -<button class="button button-large">大</button> | ||
38 | -<hr> | ||
39 | -<button class="button button-small">小</button> | ||
40 | -<hr> | ||
41 | -<button class="button button-large button-round button-solid">大,圆角,实心</button> | 14 | +三种尺寸,圆角直角,实心空心,选中未选中 |
42 | 15 | ||
43 | <h2>badge</h2> | 16 | <h2>badge</h2> |
44 | 一个数字的时候是圆形,数字长的时候圆角长方形,类似跑道 | 17 | 一个数字的时候是圆形,数字长的时候圆角长方形,类似跑道 |
@@ -58,19 +31,14 @@ iconfont 新建项目,使用 class 控制图标样式,不要用 unicode<br> | @@ -58,19 +31,14 @@ iconfont 新建项目,使用 class 控制图标样式,不要用 unicode<br> | ||
58 | 支持 一个按钮,两个按钮,多个按钮 | 31 | 支持 一个按钮,两个按钮,多个按钮 |
59 | 每个按钮支持自定义事件 | 32 | 每个按钮支持自定义事件 |
60 | <p> | 33 | <p> |
61 | - <button href="javascript:void(0);" id="modal-overlay">显示覆盖层</button> | ||
62 | - <button href="javascript:void(0);" id="modal-alert">Alert</button> | ||
63 | - <button href="javascript:void(0);" id="modal-confirm">Confirm</button> | ||
64 | - <button href="javascript:void(0);" id="modal-custom">自定义</button> | 34 | + <a href="javascript:void(0);" id="modal-overlay">显示覆盖层</a> |
65 | </p> | 35 | </p> |
66 | 36 | ||
37 | +<h2>Handlebars Template</h2> | ||
38 | +<p>Hello,<span id="hbs-placeholder"></span>!</p> | ||
67 | 39 | ||
68 | -<h2>Vue 示例(大展示,使用新路由)</h2> | 40 | +<h2>Vue 示例</h2> |
69 | 41 | ||
70 | <div id="app"> | 42 | <div id="app"> |
71 | - <app></app> | ||
72 | -</div> | ||
73 | - | ||
74 | -<h2>Handlebars 示例</h2> | ||
75 | -<div id="hbs-placeholder"> | 43 | + <app></app> |
76 | </div> | 44 | </div> |
1 | /** | 1 | /** |
2 | * Modal 模态组件 | 2 | * Modal 模态组件 |
3 | * | 3 | * |
4 | - * @author: Aiden Xu<aiden.xu@yoho.cn> | ||
5 | - * @date: 2016/07/18 | 4 | + * @author: aiden.xu<aiden.xu@yoho.cn> |
5 | + * @date: 2016/5/6 | ||
6 | */ | 6 | */ |
7 | 7 | ||
8 | 'use strict'; | 8 | 'use strict'; |
9 | 9 | ||
10 | -const template = require('./modal.hbs'); | 10 | +const Overlay = require('./overlay'); |
11 | 11 | ||
12 | class Modal { | 12 | class Modal { |
13 | /** | 13 | /** |
@@ -18,106 +18,31 @@ class Modal { | @@ -18,106 +18,31 @@ class Modal { | ||
18 | constructor(opts) { | 18 | constructor(opts) { |
19 | // 默认参数 | 19 | // 默认参数 |
20 | this.defaults = { | 20 | this.defaults = { |
21 | - isModal: true, | ||
22 | - template: template, | ||
23 | - title: '', | ||
24 | - text: '', | ||
25 | - buttons: [ | ||
26 | - { | ||
27 | - text: '好', | ||
28 | - handler: () => { | ||
29 | - this.hide(); | ||
30 | - } | ||
31 | - } | ||
32 | - ] | 21 | + template: '' |
33 | }; | 22 | }; |
34 | 23 | ||
35 | // 初始化参数 | 24 | // 初始化参数 |
36 | this.settings = Object.assign({}, this.defaults, opts); | 25 | this.settings = Object.assign({}, this.defaults, opts); |
37 | - const tpl = this.settings.template({ | ||
38 | - title: this.settings.title, | ||
39 | - text: this.settings.text, | ||
40 | - buttons: this.settings.buttons | ||
41 | - }); | ||
42 | 26 | ||
43 | - // 生成模版 | ||
44 | - this.elem = $(tpl); | ||
45 | - | ||
46 | - const buttons = this.elem.find('.button-group').children(); | ||
47 | - const self = this; | ||
48 | - | ||
49 | - this.elem.appendTo('body'); | ||
50 | - | ||
51 | - // 事件绑定 | ||
52 | - buttons.each(function(index) { | ||
53 | - $(this).click(self.settings.buttons[index].handler.bind(self)); | ||
54 | - }); | ||
55 | } | 27 | } |
56 | 28 | ||
57 | show() { | 29 | show() { |
58 | - // 显示覆盖层 | ||
59 | - this.overlay = $.overlay({ | ||
60 | - clickToClose: false | ||
61 | - }); | ||
62 | - this.overlay.show(); | ||
63 | 30 | ||
64 | - // 居中显示 | ||
65 | - this.elem.css({ | ||
66 | - left: ($(window).width() - this.elem.outerWidth()) / 2, | ||
67 | - top: ($(window).height() - this.elem.outerHeight()) / 2 + $(window).scrollTop() | ||
68 | - }).show().addClass('animation-target'); | ||
69 | } | 31 | } |
70 | 32 | ||
71 | hide() { | 33 | hide() { |
72 | - this.overlay.hide(); | ||
73 | - this.elem.hide().remove(); | 34 | + |
74 | } | 35 | } |
36 | + | ||
75 | } | 37 | } |
76 | 38 | ||
77 | (function($) { | 39 | (function($) { |
78 | - $.modal = function(opts) { | ||
79 | - return new Modal(opts); | ||
80 | - }; | ||
81 | - | ||
82 | - $.extend($.modal, { | ||
83 | - alert: (text, title)=> { | ||
84 | - const modal = $.modal({ | ||
85 | - text: text, | ||
86 | - title: title | ||
87 | - }); | ||
88 | - | ||
89 | - modal.show(); | ||
90 | - } | ||
91 | - }); | ||
92 | - | ||
93 | - $.extend($.modal, { | ||
94 | - alert: (text, title)=> { | ||
95 | - const modal = $.modal({ | ||
96 | - text: text, | ||
97 | - title: title | ||
98 | - }); | 40 | + $.extend(Overlay.prototype, { |
41 | + show: function() { | ||
99 | 42 | ||
100 | - modal.show(); | ||
101 | }, | 43 | }, |
102 | - confirm: (text, title, callback)=> { | ||
103 | - const modal = $.modal({ | ||
104 | - text: text, | ||
105 | - title: title, | ||
106 | - buttons: [ | ||
107 | - { | ||
108 | - text: '取消', | ||
109 | - handler: function() { | ||
110 | - this.hide(); | ||
111 | - } | ||
112 | - }, | ||
113 | - { | ||
114 | - text: '好', | ||
115 | - handler: callback || $.noop | ||
116 | - } | ||
117 | - ] | ||
118 | - }); | 44 | + hide: function() { |
119 | 45 | ||
120 | - modal.show(); | ||
121 | } | 46 | } |
122 | }); | 47 | }); |
123 | }(jQuery)); | 48 | }(jQuery)); |
@@ -42,11 +42,11 @@ class Overlay { | @@ -42,11 +42,11 @@ class Overlay { | ||
42 | this.elem.appendTo('body'); | 42 | this.elem.appendTo('body'); |
43 | 43 | ||
44 | // 点击关闭 | 44 | // 点击关闭 |
45 | - this.elem.click(()=> { | ||
46 | - if (this.settings.clickToClose) { | 45 | + if (this.settings.clickToClose) { |
46 | + this.elem.click(()=> { | ||
47 | this.hide(); | 47 | this.hide(); |
48 | - } | ||
49 | - }); | 48 | + }); |
49 | + } | ||
50 | 50 | ||
51 | if (this.settings.disableScrolling) { | 51 | if (this.settings.disableScrolling) { |
52 | // 覆盖层出现时阻止滚动 | 52 | // 覆盖层出现时阻止滚动 |
@@ -93,7 +93,6 @@ class Overlay { | @@ -93,7 +93,6 @@ class Overlay { | ||
93 | }); | 93 | }); |
94 | this._clearStylesClasses(); | 94 | this._clearStylesClasses(); |
95 | this.isVisible = false; | 95 | this.isVisible = false; |
96 | - this.elem.remove(); | ||
97 | }; | 96 | }; |
98 | 97 | ||
99 | this.elem[0].addEventListener('webkitTransitionEnd', listener); | 98 | this.elem[0].addEventListener('webkitTransitionEnd', listener); |
@@ -108,8 +107,13 @@ class Overlay { | @@ -108,8 +107,13 @@ class Overlay { | ||
108 | } | 107 | } |
109 | 108 | ||
110 | ((function($) { | 109 | ((function($) { |
110 | + let inst = null; | ||
111 | + | ||
111 | $.overlay = opts => { | 112 | $.overlay = opts => { |
112 | - return new Overlay(opts); | 113 | + if (!inst) { |
114 | + inst = new Overlay(opts); | ||
115 | + } | ||
116 | + return inst; | ||
113 | }; | 117 | }; |
114 | })(jQuery)); | 118 | })(jQuery)); |
115 | 119 |
1 | +var tpl = require('./hello.hbs'); | ||
2 | + | ||
1 | var Vue = require('yoho-vue'); | 3 | var Vue = require('yoho-vue'); |
2 | 4 | ||
3 | var app = require('example/home.vue'); | 5 | var app = require('example/home.vue'); |
4 | -var tpl = require('../../hbs/example/hello.hbs'); | ||
5 | 6 | ||
6 | var vm = new Vue({ | 7 | var vm = new Vue({ |
7 | el: '#app', | 8 | el: '#app', |
@@ -24,7 +25,6 @@ var cookie = require('yoho-cookie'); | @@ -24,7 +25,6 @@ var cookie = require('yoho-cookie'); | ||
24 | 25 | ||
25 | console.log(cookie.all()); | 26 | console.log(cookie.all()); |
26 | 27 | ||
27 | -// ES6 test | ||
28 | var test = { | 28 | var test = { |
29 | data() { | 29 | data() { |
30 | return { | 30 | return { |
@@ -41,50 +41,9 @@ $('#hbs-placeholder').html(tpl({ | @@ -41,50 +41,9 @@ $('#hbs-placeholder').html(tpl({ | ||
41 | 41 | ||
42 | 42 | ||
43 | var overlay = require('../common/overlay'); | 43 | var overlay = require('../common/overlay'); |
44 | -var modal = require('../common/modal'); | ||
45 | -var customModal = require('../../hbs/example/custom-modal.hbs'); | ||
46 | - | ||
47 | $('#modal-overlay').click(()=> { | 44 | $('#modal-overlay').click(()=> { |
48 | var overlay = $.overlay(); | 45 | var overlay = $.overlay(); |
49 | overlay.show(); | 46 | overlay.show(); |
50 | }); | 47 | }); |
51 | 48 | ||
52 | -$('#modal-alert').click(()=> { | ||
53 | - $.modal.alert('自毁系统已经开启,请马上撤离!', '警告'); | ||
54 | -}); | ||
55 | - | ||
56 | -$('#modal-confirm').click(()=> { | ||
57 | - $.modal.confirm('是否开启自毁系统?', '', function() { | ||
58 | - this.hide(); | ||
59 | - alert('BOOM!'); | ||
60 | - }); | ||
61 | -}); | ||
62 | - | ||
63 | -// 自定义模态 | ||
64 | -$('#modal-custom').click(()=> { | ||
65 | - const modal = $.modal({ | ||
66 | - title: '自定义模态对话框', | ||
67 | - text: '你可以自定义哦!', | ||
68 | - template: customModal, | ||
69 | - buttons: [ | ||
70 | - { | ||
71 | - text: '香蕉', | ||
72 | - handler: function() { | ||
73 | - this.hide(); | ||
74 | - alert('香蕉'); | ||
75 | - } | ||
76 | - }, | ||
77 | - { | ||
78 | - text: '苹果', | ||
79 | - handler: function() { | ||
80 | - this.hide(); | ||
81 | - alert('苹果'); | ||
82 | - } | ||
83 | - } | ||
84 | - ] | ||
85 | - }); | ||
86 | - modal.show(); | ||
87 | -}); | ||
88 | - | ||
89 | - | ||
90 | /* eslint-enable */ | 49 | /* eslint-enable */ |
1 | @import "overlay"; | 1 | @import "overlay"; |
2 | - | ||
3 | -.modal { | ||
4 | - position: absolute; | ||
5 | - margin: 0 auto; | ||
6 | - background: #fcfcfc; | ||
7 | - width: 512px; | ||
8 | - z-index: 1001; | ||
9 | - | ||
10 | - h2 { | ||
11 | - font-size: 32px; | ||
12 | - text-align: center; | ||
13 | - margin-top: 50px; | ||
14 | - margin-bottom: 0; | ||
15 | - } | ||
16 | - | ||
17 | - p { | ||
18 | - font-size: 21px; | ||
19 | - text-align: center; | ||
20 | - margin-top: 20px; | ||
21 | - margin-bottom: 48px; | ||
22 | - } | ||
23 | - | ||
24 | - hr { | ||
25 | - border: none; | ||
26 | - border-top: 1px solid #e0e0e0; | ||
27 | - margin: 0; | ||
28 | - } | ||
29 | - | ||
30 | - .button-group { | ||
31 | - display: flex; | ||
32 | - flex-direction: row; | ||
33 | - justify-content: space-around; | ||
34 | - align-items: stretch; | ||
35 | - height: 88px; | ||
36 | - | ||
37 | - a.modal-button { | ||
38 | - flex: 1; | ||
39 | - align-self: center; | ||
40 | - text-align: center; | ||
41 | - color: $blue; | ||
42 | - font-size: 30px; | ||
43 | - } | ||
44 | - } | ||
45 | -} | ||
46 | - | ||
47 | -.animation-target { | ||
48 | - -webkit-animation: animation 1000ms linear both; | ||
49 | - animation: animation 1000ms linear both; | ||
50 | -} | ||
51 | - |
-
Please register or login to post a comment