-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstant-option.js
68 lines (55 loc) · 1.97 KB
/
instant-option.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
(function ($) {
$.CreateInstantOption = function () {
var $this = $("<div></div>");
return $this;
};
$.fn.instOpAddUrl = function (id, RefUrl, text, target, onclick) {
var str = "";
if (id)
str += "id=\"" + id + "\" ";
if (RefUrl)
str += "href=\"" + RefUrl + "\" ";
if (target)
str += "target=\"" + target + "\" ";
if (onclick)
str += "onclick=\"" + onclick + "\" ";
$(this).append("<a " + str + " class=\"inst-op-url\"> • " + text + "</a>");
return $(this);
};
$.fn.instOpSetCss = function (css) {
var $this = $(this);
$.each(css, function (index, value) {
$this.data(index, value);
});
$.alertVar($this.data());
return $(this);
};
$.fn.instOpSetClickable = function (cls, data) {
var $this = $(this);
$("." + cls).click(function (event) {
$('.instant-option').remove();
var $thisP = $("<div class=\"instant-option\" id=\"instantOp\"></div>");
var $thisOp = $(this);
var generatedHtml = $this.html();
$.each(data, function (index, value) {
generatedHtml = generatedHtml.split('{' + value + '}').join($thisOp.attr(index));
});
$("body").append($thisP);
$thisP
.css($this.data())
.css({
'display': 'block',
'left': ($(this).offset().left + $(this).outerWidth() - $thisP.outerWidth()),
'top': ($(this).offset().top + $(this).outerHeight())
})
.html(generatedHtml)
.click(function (event) {
event.stopPropagation();
});
$(window).click(function (event) {
$('.instant-option').remove();
});
event.stopPropagation();
});
};
})(jQuery);