-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
125 lines (119 loc) · 4.6 KB
/
Copy pathpopup.js
File metadata and controls
125 lines (119 loc) · 4.6 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
/**
* popUp - jQuery Plugin
* version: 1.0.0
* requires jQuery v1.7 or later
*
* License: MIT
* Created by darkmoon on 4.2.16.
* Copyright 2016 darkmoon - jurenatomas@gmail.com
*
*/
(function ($) {
$.fn.extend({
popUp: function (options) {
options = $.extend({}, $.PopUp.defaults, options);
this.each(function () {
new $.PopUp(this, options);
});
return this;
}
});
$.PopUp = function (ctl, options) {
$(ctl).on(
{
mouseenter: function (e) {
var content = options.content;
if (!options.useDataAttrs)
var data = options.data[$(this).data(options.identificator)];
var re = /{(.*?)}/g;
var m;
var repeatKeys = [];
var repeat = '';
if (options.contentRepeat !== null) {
while ((m = re.exec(options.contentRepeat)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
repeatKeys.push(m);
}
var r = /{(\S+)}/;
m = r.exec(options.repeatKeyword);
data[m[1]].forEach(function (element) {
var toAdd = options.contentRepeat;
for (var i = 0; i < repeatKeys.length; i++) {
toAdd = toAdd.replace(repeatKeys[i][0], element[repeatKeys[i][1]]);
}
repeat = repeat.concat(toAdd);
});
}
while ((m = re.exec(options.content)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
if (options.useDataAttrs) {
content = content.replace(m[0], $(this).data(m[1]));
} else {
if (data[m[1]] && m[0] != options.repeatKeyword) {
content = content.replace(m[0], data[m[1]]);
} else if (data[m[1]] && m[0] == options.repeatKeyword) {
content = content.replace(m[0], repeat);
}
}
}
if ($("#popup").length == 0) {
var elm = $("<div id='popup' style='display: none;top: " + (e.pageY - options.offset) + "px;left: " + (e.pageX + options.offset) + "px'>" + content + "</div>").appendTo("body");
switch (options.animationIn) {
case "fadeIn":
elm.fadeIn(options.timingIn);
break;
case "show":
elm.show(options.timingIn);
break;
}
}
},
mousemove: function (e) {
$("#popup").css({
"top": (e.pageY - options.offset) + "px",
"left": (e.pageX + options.offset) + "px"
});
},
mouseleave: function () {
var pop = $("#popup");
var func = (function () {
return function () {
$(".removing").remove()
};
});
pop.addClass("removing");
pop.removeAttr("id");
switch (options.animationOut) {
case "hide":
pop.hide(options.timingOut, func());
break;
case "fadeOut":
pop.fadeOut(options.timingOut, func());
break;
}
}
});
if (!options.follow) {
$(ctl).off("mousemove");
}
};
// option defaults
$.PopUp.defaults = {
follow: true,
offset: 10,
content: "content",
contentRepeat: null,
repeatKeyword: "{repeat}",
identificator: "id",
data: undefined,
useDataAttrs: false,
timingIn: 750,
timingOut: 250,
animationIn: "fadeIn",
animationOut: "fadeOut"
};
})(jQuery);