-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.taggy.js
More file actions
53 lines (40 loc) · 1.58 KB
/
jquery.taggy.js
File metadata and controls
53 lines (40 loc) · 1.58 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
(function($) {
var pluginName = "taggy",
defaults = { items: [] };
function Plugin(element, options) {
this.$element = $(element);
this.options = $.extend({}, defaults, options);
this.$element.wrap($('<div class="taggy-wrapper" />'));
var $this = this,
$wrapper = this.$element.parent(".taggy-wrapper");
$.each(this.options.items, function() {
var $item = $('<span class="taggy-item" style="position: absolute; opacity: 0;" data-x="' + this.x + '" data-y="' + this.y + '" />');
if (typeof(this.class) === "string") {
$item.addClass(this.class);
}
$wrapper.append($item);
});
$(window).resize(function() { $this.draw(); });
$this.draw();
}
Plugin.prototype.draw = function() {
var $element = this.$element,
$wrapper = $element.parent(".taggy-wrapper");
$wrapper.find("span").each(function() {
var $this = $(this);
var top = $this.data("y") * $element.height(),
left = $this.data("x") * $element.width();
$this.css({
"top": top - $this.outerHeight(true) / 2,
"left": left - $this.outerWidth(true) / 2
});
});
};
$.fn[pluginName] = function(options) {
return this.each(function () {
if (typeof($.data(this, "plugin_" + pluginName)) === "undefined") {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
});
};
})(jQuery);