-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathcomponent.js
123 lines (95 loc) · 2.85 KB
/
component.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
COMPONENT('approve', 'cancel:Cancel', function(self, config, cls) {
var cls2 = '.' + cls;
var events = {};
var buttons;
var oldcancel;
self.readonly();
self.singleton();
self.nocompile && self.nocompile();
self.make = function() {
self.aclass(cls + ' hidden');
self.aclass(cls + '-style-' + (config.style || 1));
self.html('<div><div class="{0}-body"><span class="{0}-close"><i class="ti ti-times"></i></span><div class="{0}-content"></div><div class="{0}-buttons"><button data-index="0"></button><button data-index="1"></button></div></div></div>'.format(cls));
buttons = self.find(cls2 + '-buttons').find('button');
self.event('click', 'button', function() {
self.hide(+$(this).attrd('index'));
});
self.event('click', cls2 + '-close', function() {
self.callback = null;
self.hide(-1);
});
self.event('click', function(e) {
var t = e.target.tagName;
if (t !== 'DIV')
return;
var el = self.find(cls2 + '-body');
el.aclass(cls + '-click');
setTimeout(function() {
el.rclass(cls + '-click');
}, 300);
});
};
events.keydown = function(e) {
var index = e.which === 13 ? 0 : e.which === 27 ? 1 : null;
if (index != null) {
self.find('button[data-index="{0}"]'.format(index)).trigger('click');
e.preventDefault();
e.stopPropagation();
events.unbind();
}
};
events.bind = function() {
$(W).on('keydown', events.keydown);
};
events.unbind = function() {
$(W).off('keydown', events.keydown);
};
self.show = function(message, a, b, fn, cancel) {
clearTimeout2(self.id);
if (typeof(b) === 'function') {
cancel = fn;
fn = b;
b = config.cancel;
}
if (M.scope)
self.currscope = M.scope();
self.callback = fn;
self.callbackcancel = typeof(cancel) === 'function' ? cancel : null;
var icon = a.match(/[":][a-z0-9-\s]+[":]/);
if (icon) {
var tmp = icon + '';
if (tmp.indexOf(' ') == -1)
tmp = 'ti ti-' + tmp;
a = a.replace(icon, '').trim();
icon = '<i class="{0}"></i>'.format(tmp.replace(/"|:/g, ''));
} else
icon = '';
var color = a.match(/#[0-9a-f]+/i);
if (color)
a = a.replace(color, '').trim();
buttons.eq(0).css('background-color', color || '').html(icon + a);
if (oldcancel !== b) {
oldcancel = b;
buttons.eq(1).html(b);
}
self.find(cls2 + '-content').html(message.replace(/\n/g, '<br />'));
$('html').aclass(cls + '-noscroll');
self.rclass('hidden');
events.bind();
self.aclass(cls + '-visible', 5);
document.activeElement && document.activeElement.blur();
};
self.hide = function(index) {
if (!index) {
self.currscope && M.scope(self.currscope);
self.callback && self.callback();
} else if (self.callbackcancel)
self.callbackcancel();
self.rclass(cls + '-visible');
events.unbind();
setTimeout2(self.id, function() {
$('html').rclass(cls + '-noscroll');
self.aclass('hidden');
}, 50);
};
});