-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwikipedia_search_suggestion.js
90 lines (72 loc) · 2.2 KB
/
wikipedia_search_suggestion.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const St = imports.gi.St;
const Lang = imports.lang;
const Tweener = imports.ui.tweener;
const Signals = imports.signals;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const ANIMATION_TIME = 0.5;
const WikipediaSearchSuggestion = new Lang.Class({
Name: "WikipediaSearchSuggestion",
_init: function() {
this.actor = new St.BoxLayout({
visible: false,
style_class: 'wikipedia-suggestion-box' + Utils.get_style_postfix()
});
this._label = new St.Label({
style_class: 'wikipedia-suggestion-label'
});
this._suggestion_button = new St.Button({
style_class: 'wikipedia-suggestion-button'
});
this._suggestion_button.connect("clicked", Lang.bind(this, function() {
this.emit("suggestion-activated")
}));
this.actor.add_child(this._label);
this.actor.add_child(this._suggestion_button);
},
show: function() {
if(this.actor.visible) return;
this.actor.opacity = 0;
this.actor.show();
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor, {
time: ANIMATION_TIME,
opacity: 255,
transition: 'easeOutQuad'
})
},
hide: function() {
if(!this.actor.visible) return;
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor, {
time: ANIMATION_TIME,
opacity: 0,
transition: 'easeOutQuad',
onComplete: Lang.bind(this, function() {
this.actor.hide();
})
})
},
destroy: function() {
this.actor.destroy();
},
set label(text) {
this._label.set_text(text);
},
get label() {
return this._label;
},
set suggestion(text) {
this._suggestion_button.set_label(text);
},
get suggestion() {
return this._suggestion_button.get_label();
},
get button() {
return this._suggestion_button;
},
get is_empty() {
return Utils.is_blank(this._suggestion_button.get_label());
}
});
Signals.addSignalMethods(WikipediaSearchSuggestion.prototype);