-
-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathdemo.js
135 lines (116 loc) · 3.58 KB
/
demo.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
124
125
126
127
128
129
130
131
132
133
134
135
$(document).ready(function () {
console.log('ready');
// $("textarea.html").each(function(idx, textarea) {
// CodeMirror.fromTextArea(textarea, {
// lineNumbers: true,
// mode: "htmlmixed",
// readOnly: true
// });
// });
//
// $("textarea.css").each(function(idx, textarea) {
// CodeMirror.fromTextArea(textarea, {
// lineNumbers: true,
// mode: "css",
// readOnly: true
// });
// });
//
// $("textarea.javascript").each(function(idx, textarea) {
// CodeMirror.fromTextArea(textarea, {
// lineNumbers: true,
// mode: "javascript",
// readOnly: true
// });
// });
});
function ResizerDemo(element) {
element = $(element);
var handler = $('<div class="resizerDemo-handler"></div>');
var info = $('<div class="resizerDemo-info"></div>');
element.append(handler);
element.append(info);
var hammer = new Hammer(element[0], {recognizers: [
[Hammer.Pan, { threshold: 0}]
]});
var startWidth;
element.on('mousedown', function(e){
e.preventDefault();
});
hammer.on('panstart', function(e) {
startWidth = element[0].clientWidth;
});
hammer.on('panmove', function(e) {
element[0].style.width = (startWidth + e.deltaX) + 'px';
info.html(element[0].clientWidth + 'px x ' + element[0].clientHeight + 'px');
})
}
$( document ).ready(function(){
$('.examplesResizerDemos').each(function(idx, element){
new ResizerDemo(element);
});
perfTest();
example3();
example4();
example5();
});
function perfTest(){
var container = $('#dynamicContainer');
var dynamicCount = $('#dynamicCount');
var dynamicCounter = $('#dynamicCounter');
window.detachDynamic = function() {
container.children().each(function(idx, element) {
ResizeSensor.detach(element);
});
};
window.removeDynamic = function() {
container.html('');
};
window.addDynamic = function() {
container.html('');
var i = 0, to = dynamicCount.val(), div, counter = 0;
for (; i < to; i++) {
div = $('<div class="dynamicElement">#'+i+'</div>');
container.append(div);
new ResizeSensor(div, function(){
counter++;
dynamicCounter.html(counter + ' changes.');
});
}
}
}
function example3(){
var logger = $('#example-3-log');
var box = $('#example-3-box');
$('#startStop3').on('click', function(){
if (box.hasClass('example-3-box-start')) {
box.removeClass('example-3-box-start');
} else {
box.addClass('example-3-box-start');
}
});
new ResizeSensor(box, function(el){
logger.html('Changed to ' + box[0].clientWidth+'px width.');
});
}
function example4(){
var logger = $('#example-4-log');
var box = $('#example-4-box');
$('#startStop4').on('click', function(){
if (box.hasClass('example-4-box-start')) {
box.removeClass('example-4-box-start');
} else {
box.addClass('example-4-box-start');
}
});
new ResizeSensor(box, function(){
logger.html('Changed to ' + box[0].clientHeight+'px height.');
});
}
function example5(){
var box = $('#example-5');
var changed = 0;
new ResizeSensor(box.parent(), function(){
box[0].innerHTML = (++changed) + ' changes. ' + box.parent()[0].clientWidth+'px/'+box.parent()[0].clientHeight+'px';
});
}