-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.js
More file actions
322 lines (284 loc) · 12.9 KB
/
Plugin.js
File metadata and controls
322 lines (284 loc) · 12.9 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
Version : 01.10.2018
Author : WebDirigent (Manuel Maurer)
Contact: : office@weh-dirigent.at
Desc : Main Plugin JavaScript-Code to be included after jQuery and
Velocity.js
License : THIS PLUGIN IS LICENSED UNDER THE �CREATIVE COMMONS ATTRIBUTION-NON-COMMERCIAL LICENSE (CC BY-NC 4.0)�
LICENSE-LINK: https://creativecommons.org/licenses/by-nc/4.0/legalcode
YOU ARE ALLOWED TO ->
~ SHARE, COPY OR REDISTRIBUTE this plugin
~ ADAPT, REMIX, TRANSFORM OR BUILD UPON this plugin
~ FOR ANY COMMERCIAL AND NON-COMMERCIAL PURPOSE
YOU NEED TO ->
~ GIVE APPROPRIATE CREDIT: LINK TO "www.web-dirigent.at" (Author: WebDirigent)
FOR INSTANCE: Powered By "Modern Customer Feedback Plugin", available at <a title="WebDirigent" href="https://www.web-dirigent.at">www.web-dirigent.at</a>
*/
(function($) {
var ElemInitLeft;
var ElemInitTop;
$.fn.CustomerFeedback = function(Optionen) {
var FlowContainer = this;
//DEFAULT-SETTINGS (Plugin-Options)
var Settings = $.extend({}, {
ContainerHeight: 350,
OverFlowAllowed: true,
DefaultTargetsWidth: 55,
DefaultTargetsHeight: 55,
TargetsSizeRandomizePlus: 5,
TargetsSizeRandomizeMinus: 15,
InitiallyHideTargets: true,
UseAnimation: true,
AnimationDuration: 2500,
AnimationFriction: 150,
AnimationFrequency: 115,
AnimationType: dynamics.spring,
AnimationTimeBetween: 100,
MinSpreadX: 20,
MinSpreadY: 20,
MaxTries: 1500,
Scrollable: true,
LeftOverflowAllowed: true,
MinPaddingTop: 10,
MinPaddingBottom: 10,
CorrectionRuns: 10,
SlightMovementAnimation: true,
AutoscrollSpeed: 5,
ScrollWait: 0,
}, Optionen);
//Alle Elemente verstecken
if (Settings.InitiallyHideTargets) {
// $(FlowContainer).children().css({ height: 0, width: 0, opacity: 0, position: "absolute" })
$(FlowContainer).children().css({ position: "absolute" })
}
//Initialisierung: Dimensionen etc
$(FlowContainer).css({ "height": Settings.ContainerHeight, "position": "relative" }); //Container-Height
//Elemente mit zuf�lligen Dimensionen versehen
if (Settings.TargetsSizeRandomizeMinus != 0 || Settings.TargetsSizeRandomizePlus != 0) {
var Counter1 = -1;
var ElemNow;
var NewWidth;
var NewHeight;
$(FlowContainer).children().each(function(elem) {
Counter1++;
ElemNow = $(FlowContainer).children().eq(Counter1);
NewWidth = randomIntFromInterval(Settings.DefaultTargetsWidth - Settings.TargetsSizeRandomizeMinus, Settings.DefaultTargetsWidth + Settings.TargetsSizeRandomizePlus);
NewHeight = (NewWidth * Settings.DefaultTargetsHeight / Settings.DefaultTargetsWidth)
$(ElemNow).data("animheight", NewHeight).data("animwidth", NewWidth)
})
} else {
var Counter1 = -1;
$(FlowContainer).children().each(function(elem) {
$(FlowContainer).children().eq(Counter1).data("animheight", Settings.DefaultTargetsHeight).data("animwidth", Settings.DefaultTargetsWidth)
})
}
//Erstes Element exakt mittig positionieren
StartPositioning(FlowContainer, Settings);
//Animiert einblenden
if (Settings.UseAnimation) {
var Counter = -1;
var ElemNow;
$(FlowContainer).children().each(function(elem) {
Counter++;
ElemNow = $(FlowContainer).children().eq(Counter);
CustomerFeedbackAnimate(ElemNow[0], Settings, Settings.AnimationTimeBetween * Counter)
})
} else {
//TODO: Auch ohne Animation anzeigen
var Counter = -1;
var ElemNow;
$(FlowContainer).children().each(function(elem) {
Counter++;
ElemNow = $(FlowContainer).children().eq(Counter);
ShowNoAnimate(ElemNow[0], Settings.AnimationTimeBetween * Counter, Settings)
})
}
//Scrolling erm�glichen
if (Settings.Scrollable) {
var MaxRight = 0;
var ElemCounter = 0;
$(FlowContainer).children().each(function() {
if (parseInt($(FlowContainer).children().eq(ElemCounter).css("left")) > MaxRight) {
MaxRight = parseInt($(FlowContainer).children().eq(ElemCounter).css("left")) + parseInt($(FlowContainer).children().eq(ElemCounter).css("width"));
}
ElemCounter++;
})
$(FlowContainer).parent().css({ height: Settings.ContainerHeight, "overflow": "hidden" });
$(FlowContainer).css({ "height": Settings.ContainerHeight + 17, "overflow": "scroll", "padding-right": "17px", "margin-right": "-17px" });
if (Settings.AutoscrollSpeed > 0) {
var CalcTime;
if (Settings.UseAnimation) {
CalcTime = $(FlowContainer).children().length * Settings.AnimationTimeBetween + Settings.ScrollWait - (FlowContainer).children().length / 7;
} else {
CalcTime = $(FlowContainer).children().length * Settings.ScrollWait - (FlowContainer).children().length / 7;
}
var ScrollSpeed = (MaxRight / Settings.AutoscrollSpeed) * 1000
setTimeout(function() {
$(FlowContainer).animate({ scrollLeft: MaxRight }, ScrollSpeed, "linear");
$(FlowContainer).on({
mouseenter: function() {
(FlowContainer).stop();
},
mouseleave: function() {
$(FlowContainer).animate({ scrollLeft: MaxRight }, ScrollSpeed, "linear");
},
click: function() {
(FlowContainer).stop();
},
mouseover: function() {
(FlowContainer).stop();
},
hover: function() {
(FlowContainer).stop();
},
mousemove: function() {
(FlowContainer).stop();
}
});
}, CalcTime)
}
}
//PopOver
$(FlowContainer).find('[data-popovertitle]').each(function(index, element){
var Title = $(this).data("popovertitle");
var Content = $(this).data("popovercontent");
$(this).webuiPopover({title:Title,content:Content, animation:"pop", width: 200, placement:"bottom-right"})
$(this).hover(function(){
$(this).webuiPopover('show');
}, function(){
$(this).webuiPopover('hide');
})
})
};
function MakePositive(Num) {
if (Num < 0) {
return Num * -1;
} else {
return Num;
}
}
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function StartPositioning(FlowContainer, Settings) {
var PositionsArray = [];
PositionsArray.length = 0;
PositionsArray = [];
var ContainerCenterX = $(FlowContainer).width() / 2;
var ContainerCenterY = $(FlowContainer).height() / 2;
//Positionierung des 1. Elements (Mittig)
var ElemNow = $(FlowContainer).children().eq(0);
var ElemWidth = $(ElemNow).data("animwidth")
var ElemHeight = $(ElemNow).data("animheight")
var ElemNowTop = ContainerCenterY - (ElemHeight / 2);
ElemInitTop = ElemNowTop;
var ElemNowLeft = ContainerCenterX - (ElemWidth / 2);
ElemInitLeft = ElemNowLeft;
$(ElemNow).css({ top: ElemNowTop, left: ElemNowLeft })
PositionsArray[0] = [ElemNowTop, ElemNowLeft, ElemHeight, ElemWidth];
//Nun s�mtliche andere durchgehen und positionieren
var Counter2 = 0;
$(FlowContainer).children(':not(:last)').each(function(elem) {
Counter2++;
ElemNow = $(FlowContainer).children().eq(Counter2);
ElemWidth = $(ElemNow).data("animwidth")
ElemHeight = $(ElemNow).data("animheight")
var Tries = 0;
var TryNowX = ElemInitLeft;
var TryNowY = ElemInitTop;
do {
if (TryNowY < (10 + Settings.MinPaddingTop)) {
TryNowY += randomIntFromInterval(0, 10);
} else if (TryNowY > (FlowContainer.height() - ElemHeight - 10 - Settings.MinPaddingBottom)) {
TryNowY += randomIntFromInterval(-10, 0);
} else {
TryNowY += randomIntFromInterval(-10, 10);
}
if (TryNowX < 10) {
TryNowX += randomIntFromInterval(0, 10);
} else if (TryNowX > (FlowContainer.width() - ElemWidth - 10)) {
TryNowX += randomIntFromInterval(-10, 0);
} else {
TryNowX += randomIntFromInterval(-10, 10);
}
Tries++;
if (Tries > 200) {
if (Settings.LeftOverflowAllowed) {
if (TryNowX < (Tries / 5.5)) {
TryNowX += 150;
} else {
TryNowX += randomIntFromInterval((Tries / -4), (Tries / 4));
}
} else {
if (TryNowX < (Tries / 3.5)) {
TryNowX += 150;
} else {
TryNowX += randomIntFromInterval((Tries / -4), (Tries / 4));
}
}
}
if (Tries == Settings.MaxTries) {
$(ElemNow).css({ "height": "0!important", "width": "0!important" }).addClass("rpp-hide");
}
}
while (!NoCollision(TryNowX, TryNowY, ElemWidth, ElemHeight, PositionsArray, Settings.MinSpreadX, Settings.MinSpreadY) && Tries <= Settings.MaxTries)
$(ElemNow).css({ top: TryNowY, left: TryNowX });
PositionsArray[Counter2] = [TryNowY, TryNowX, ElemHeight, ElemWidth];
TryNowX = ElemInitLeft;
TryNowY = ElemInitTop;
})
PositionsArray.length = 0;
PositionsArray = [];
PositionsArray = undefined;
PositionsArray = null;
}
function NoCollision(X, Y, W, H, PositionsArray, SpreadX, SpreadY) {
var NoErrors = true;
//Jedes Element im PositionsArray durchgehen und Pr�fen
$.each(PositionsArray, function(PositionArray) {
var ArrY = PositionsArray[PositionArray][0];
var ArrX = PositionsArray[PositionArray][1];
var ArrW = PositionsArray[PositionArray][3];
var ArrH = PositionsArray[PositionArray][2];
if ((X < (ArrX - W - SpreadX) || X > (ArrX + ArrW + SpreadX)) || (Y < (ArrY - H - SpreadY) || Y > (ArrY + ArrH + SpreadY))) {
//SHOULD BE OKAY HERE
} else {
NoErrors = false;
}
})
return NoErrors;
}
function GetBigger(val1, val2) {
if (val1 > val2) {
return val1;
} else {
return val2;
}
}
function ShowNoAnimate(el, CountTime, Settings) {
setTimeout(function() {
$(el).show();
if (Settings.SlightMovementAnimation) {
$(el).addClass("rpp-anim").css({width: $(el).data("animwidth"),
height: $(el).data("animheight"),});
}
}, CountTime)
}
function CustomerFeedbackAnimate(el, Settings, CountTime) {
setTimeout(function() {
dynamics.animate(el, {
width: $(el).data("animwidth"),
height: $(el).data("animheight"),
opacity: 1
}, {
type: Settings.AnimationType,
frequency: Settings.AnimationFrequency,
friction: Settings.AnimationFriction,
duration: Settings.AnimationDuration
})
if (Settings.SlightMovementAnimation) {
$(el).addClass("rpp-anim");
}
}, CountTime)
}
}(jQuery));