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
|
(function () {
if (!String.prototype.capitalize) {
String.prototype.capitalize = function () {
return this.slice(0, 1).toUpperCase() + this.slice(1);
};
}
})();
(function ($) {
$.fn.realWidth = function (type, margin, $el) {
var width = null, $div = null, method = null;
type = type === 'inner' || type === 'outer' ? type : '';
method = type === '' ? 'width' : type + 'Width';
margin = margin === true ? true : false;
$div = $(this).clone().css({position: 'absolute', left: -10000}).appendTo($el || 'body');
width = margin ? $div[method](margin) : $div[method]();
$div.remove();
return width;
};
$.fn.realHeight = function (type, margin, $el) {
var height = null, $div = null, method = null;
type = type === 'inner' || type === 'outer' ? type : '';
method = type === '' ? 'height' : type + 'Height';
margin = margin === true ? true : false;
$div = $(this).clone().css({position: 'absolute', left: -10000}).appendTo($el || 'body');
height = margin ? $div[method](margin) : $div[method]();
$div.remove();
return height;
};
$.fn.bindMobileEvents = function () {
$(this).on('touchstart touchmove touchend touchcancel', function () {
var touches = (event.changedTouches || event.originalEvent.targetTouches),
first = touches[0],
type = '';
switch (event.type) {
case 'touchstart':
type = 'mousedown';
break;
case 'touchmove':
type = 'mousemove';
event.preventDefault();
break;
case 'touchend':
type = 'mouseup';
break;
default:
return;
}
var simulatedEvent = document.createEvent('MouseEvent');
simulatedEvent.initMouseEvent(
type, true, true, window, 1,
first.screenX, first.screenY, first.clientX, first.clientY,
false, false, false, false, 0/*left*/, null
);
first.target.dispatchEvent(simulatedEvent);
});
};
})(jQuery);
|