kendo.mobile.actionsheet.js
9.35 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Kendo UI v2016.1.112 (http://www.telerik.com/kendo-ui)
* Copyright 2016 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
(function (f, define) {
define('kendo.mobile.actionsheet', [
'kendo.mobile.popover',
'kendo.mobile.shim'
], f);
}(function () {
var __meta__ = {
id: 'mobile.actionsheet',
name: 'ActionSheet',
category: 'mobile',
description: 'The mobile ActionSheet widget displays a set of choices related to a task the user initiates.',
depends: [
'mobile.popover',
'mobile.shim'
]
};
(function ($, undefined) {
var kendo = window.kendo, support = kendo.support, ui = kendo.mobile.ui, Shim = ui.Shim, Popup = ui.Popup, Widget = ui.Widget, OPEN = 'open', CLOSE = 'close', COMMAND = 'command', BUTTONS = 'li>a', CONTEXT_DATA = 'actionsheetContext', WRAP = '<div class="km-actionsheet-wrapper" />', cancelTemplate = kendo.template('<li class="km-actionsheet-cancel"><a href="\\#">#:cancel#</a></li>');
var ActionSheet = Widget.extend({
init: function (element, options) {
var that = this, ShimClass, tablet, type, os = support.mobileOS;
Widget.fn.init.call(that, element, options);
options = that.options;
type = options.type;
element = that.element;
if (type === 'auto') {
tablet = os && os.tablet;
} else {
tablet = type === 'tablet';
}
ShimClass = tablet ? Popup : Shim;
if (options.cancelTemplate) {
cancelTemplate = kendo.template(options.cancelTemplate);
}
element.addClass('km-actionsheet').append(cancelTemplate({ cancel: that.options.cancel })).wrap(WRAP).on('up', BUTTONS, '_click').on('click', BUTTONS, kendo.preventDefault);
that.view().bind('destroy', function () {
that.destroy();
});
that.wrapper = element.parent().addClass(type ? ' km-actionsheet-' + type : '');
that.shim = new ShimClass(that.wrapper, $.extend({
modal: os.ios && os.majorVersion < 7,
className: 'km-actionsheet-root'
}, that.options.popup));
that._closeProxy = $.proxy(that, '_close');
that._shimHideProxy = $.proxy(that, '_shimHide');
that.shim.bind('hide', that._shimHideProxy);
if (tablet) {
kendo.onResize(that._closeProxy);
}
kendo.notify(that, ui);
},
events: [
OPEN,
CLOSE,
COMMAND
],
options: {
name: 'ActionSheet',
cancel: 'Cancel',
type: 'auto',
popup: { height: 'auto' }
},
open: function (target, context) {
var that = this;
that.target = $(target);
that.context = context;
that.shim.show(target);
},
close: function () {
this.context = this.target = null;
this.shim.hide();
},
openFor: function (target) {
var that = this, context = target.data(CONTEXT_DATA);
that.open(target, context);
that.trigger(OPEN, {
target: target,
context: context
});
},
destroy: function () {
Widget.fn.destroy.call(this);
kendo.unbindResize(this._closeProxy);
this.shim.destroy();
},
_click: function (e) {
if (e.isDefaultPrevented()) {
return;
}
var currentTarget = $(e.currentTarget);
var action = currentTarget.data('action');
if (action) {
var actionData = {
target: this.target,
context: this.context
}, $angular = this.options.$angular;
if ($angular) {
this.element.injector().get('$parse')(action)($angular[0])(actionData);
} else {
kendo.getter(action)(window)(actionData);
}
}
this.trigger(COMMAND, {
target: this.target,
context: this.context,
currentTarget: currentTarget
});
e.preventDefault();
this._close();
},
_shimHide: function (e) {
if (!this.trigger(CLOSE)) {
this.context = this.target = null;
} else {
e.preventDefault();
}
},
_close: function (e) {
if (!this.trigger(CLOSE)) {
this.close();
} else {
e.preventDefault();
}
}
});
ui.plugin(ActionSheet);
}(window.kendo.jQuery));
return window.kendo;
}, typeof define == 'function' && define.amd ? define : function (a1, a2, a3) {
(a3 || a2)();
}));