|
@@ -12,30 +12,35 @@ var $dialogWrapper, |
|
@@ -12,30 +12,35 @@ var $dialogWrapper, |
12
|
dialogTpl,
|
12
|
dialogTpl,
|
13
|
dialogTemplate;
|
13
|
dialogTemplate;
|
14
|
|
14
|
|
15
|
-
|
|
|
16
|
-dialogTpl = '<div id="dialog-wrapper" class="dialog-wrapper">' +
|
|
|
17
|
- '<div class="dialog-box">' +
|
|
|
18
|
- '{{# hasHeader}}' +
|
|
|
19
|
- '{{/ hasHeader}}' +
|
|
|
20
|
- '<div class="dialog-content">{{dialogText}}</div>' +
|
|
|
21
|
- '{{# hasFooter}}' +
|
|
|
22
|
- '<div class="dialog-footer">' +
|
|
|
23
|
- '{{# leftBtnText}}' +
|
|
|
24
|
- '<span class="dialog-left-btn">{{.}}</span>' +
|
|
|
25
|
- '{{/ leftBtnText}}' +
|
|
|
26
|
- '{{# rightBtnText}}' +
|
|
|
27
|
- '<span class="dialog-right-btn">{{.}}</span>' +
|
|
|
28
|
- '{{/ rightBtnText}}' +
|
|
|
29
|
- '</div>' +
|
|
|
30
|
- '{{/ hasFooter}}' +
|
|
|
31
|
- '</div>' +
|
15
|
+function getInstance() {
|
|
|
16
|
+ if (dialogTpl === undefined) {
|
|
|
17
|
+ dialogTpl = '<div id="dialog-wrapper" class="dialog-wrapper">' +
|
|
|
18
|
+ '<div class="dialog-box">' +
|
|
|
19
|
+ '{{# hasHeader}}' +
|
|
|
20
|
+ '{{/ hasHeader}}' +
|
|
|
21
|
+ '<div class="dialog-content">{{dialogText}}</div>' +
|
|
|
22
|
+ '{{# hasFooter}}' +
|
|
|
23
|
+ '<div class="dialog-footer">' +
|
|
|
24
|
+ '{{# leftBtnText}}' +
|
|
|
25
|
+ '<span class="dialog-left-btn">{{.}}</span>' +
|
|
|
26
|
+ '{{/ leftBtnText}}' +
|
|
|
27
|
+ '{{# rightBtnText}}' +
|
|
|
28
|
+ '<span class="dialog-right-btn">{{.}}</span>' +
|
|
|
29
|
+ '{{/ rightBtnText}}' +
|
|
|
30
|
+ '</div>' +
|
|
|
31
|
+ '{{/ hasFooter}}' +
|
|
|
32
|
+ '</div>' +
|
32
|
'</div>';
|
33
|
'</div>';
|
33
|
|
34
|
|
34
|
-dialogTemplate = Handlebars.compile(dialogTpl);
|
35
|
+ dialogTemplate = Handlebars.compile(dialogTpl);
|
|
|
36
|
+ }
|
|
|
37
|
+ return dialogTemplate;
|
|
|
38
|
+}
|
35
|
|
39
|
|
36
|
exports.showDialog = function(data, callback, callbackForLeft) {
|
40
|
exports.showDialog = function(data, callback, callbackForLeft) {
|
37
|
|
41
|
|
38
|
- var dialogStr = dialogTemplate(data),
|
42
|
+ var dialogTemplate = getInstance(),
|
|
|
43
|
+ dialogStr = dialogTemplate(data),
|
39
|
$dialogBox,
|
44
|
$dialogBox,
|
40
|
defaultHideDuraton,
|
45
|
defaultHideDuraton,
|
41
|
dialogWrapperHammer;
|
46
|
dialogWrapperHammer;
|
|
@@ -73,6 +78,11 @@ exports.showDialog = function(data, callback, callbackForLeft) { |
|
@@ -73,6 +78,11 @@ exports.showDialog = function(data, callback, callbackForLeft) { |
73
|
}, defaultHideDuraton);
|
78
|
}, defaultHideDuraton);
|
74
|
}
|
79
|
}
|
75
|
|
80
|
|
|
|
81
|
+ //禁止在dialog上可以上下滚动
|
|
|
82
|
+ $dialogWrapper.on('touchmove', function() {
|
|
|
83
|
+ return false;
|
|
|
84
|
+ });
|
|
|
85
|
+
|
76
|
dialogWrapperHammer.on('tap', function(event) {
|
86
|
dialogWrapperHammer.on('tap', function(event) {
|
77
|
|
87
|
|
78
|
if ($(event.target).hasClass('dialog-left-btn')) {
|
88
|
if ($(event.target).hasClass('dialog-left-btn')) {
|
|
@@ -83,5 +93,9 @@ exports.showDialog = function(data, callback, callbackForLeft) { |
|
@@ -83,5 +93,9 @@ exports.showDialog = function(data, callback, callbackForLeft) { |
83
|
} else if ($(event.target).hasClass('dialog-right-btn')) {
|
93
|
} else if ($(event.target).hasClass('dialog-right-btn')) {
|
84
|
callback();
|
94
|
callback();
|
85
|
}
|
95
|
}
|
|
|
96
|
+
|
|
|
97
|
+ // 防止出现点透问题
|
|
|
98
|
+ event.preventDefault();
|
|
|
99
|
+ event.srcEvent.stopPropagation();
|
86
|
});
|
100
|
});
|
87
|
}; |
101
|
}; |