/
jquery.qs.tagger.js
57 lines (48 loc) · 1.98 KB
/
jquery.qs.tagger.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
//===================================================================================
// Microsoft patterns & practices
// Silk : Web Client Guidance
//===================================================================================
// Copyright (c) Microsoft Corporation. All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious. No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===================================================================================
(function ($) {
var timer,
hideAfter = 1000; // ms
// could've been an option
$.widget('qs.tagger', {
widgetEventPrefix: 'tag',
options: {
activated: null,
deactivated: null
},
_create: function () {
var that = this,
name = this.name,
tag = this.element.text();
this.element
.addClass('qs-tagged')
.bind('mouseenter.' + name, function (event) {
clearTimeout(timer);
that._trigger('activated', event, {name: tag});
})
.bind('mouseleave.' + name, function () {
timer = setTimeout(function () {
that._trigger('deactivated');
}, hideAfter);
});
},
destroy: function () {
$.Widget.prototype.destroy.apply(this, arguments);
this.element.removeClass('qs-tagged');
}
});
} (jQuery));