modal.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Modal 组件: 仿BOOTSTRAP:MODAL
* @author xuan.chen@yoho.cn
*/
'use strict';
/* config */
var NAME = 'YModal';
var DATA_KEY = 'yoho.modal';
var Event = {
CLICK_DATA_API: 'click.yoho.modal.data-api'
};
var Selector = {
DATA_TOGGLE: '[data-toggle="ymodal"]'
};
var Modal = function(elem, config) {
};
/* ------------------------static attribute ------------------*/
Modal.DEFAULT = {};
/* ------------------------public method ------------------*/
Modal.prototype.show = function() {
};
Modal.prototype.hide = function() {
};
Modal.prototype.toggle = function() {
};
/* ------------------------private method ------------------*/
/* ------------------------static method ------------------*/
Modal._jqueryBridge = function(config, relatedTarget) {
return this.each(function() {
var data = this.data(DATA_KEY);
var configs = $.extend(
{},
Modal.DEFAULT,
toString.call(config) === '[object Object]' && config
);
if (!data) {
this.data(DATA_KEY, data = new Modal(this, configs));
}
if (typeof config === 'string') {
data[config](relatedTarget);
} else if (config.show) {
data.show(relatedTarget);
}
});
};
/* ----------------------- DATA-API ----------------------*/
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function(event) {
var selector = this.getAttribute('data-target');
var $target = $(selector);
if ($target[0].tagName.toUpperCase() === 'A') {
event.preventDefault();
}
Modal._jqueryBridge($target, {}, this);
});
$.fn[NAME] = Modal._jqueryBridge;
$.fn[NAME].constructor = Modal;
module.exports = Modal;