-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpane.js
More file actions
99 lines (82 loc) · 2.11 KB
/
pane.js
File metadata and controls
99 lines (82 loc) · 2.11 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
(function($) {
UberSearch.Pane = function(options) {
var eventsTriggered = {
shown: 'shown',
hidden: 'hidden'
}
options = $.extend({
alwaysOpen: false
}, options)
var context = this
var model = {}
var isOpen = false
var view = $('<div class="pane" role="listbox"></div>').toggle(isOpen)
var innerPane = $('<div class="pane_inner"></div>').appendTo(view)
// PUBLIC INTERFACE
$.extend(this, {
model: model,
view: view,
addContent: addContent,
removeContent: removeContent,
show: show,
hide: hide,
toggle: toggle,
isOpen: paneIsOpen,
isClosed: paneIsClosed
})
// BEHAVIOUR
// Make it possible to have elements in the pane that close it
view.on('click', '[data-behaviour~=close-pane]', function(event){
context.hide()
})
// Close the pane when the user presses escape
if (!options.alwaysOpen) {
$(document).on('keyup', function(event){
if (event.which == 27 && isOpen){
context.hide()
return false
}
})
}
// HELPER FUNCTIONS
function paneIsOpen(){
return isOpen
}
function paneIsClosed(){
return !isOpen
}
function addContent(name, content){
model[name] = content
innerPane.append(content)
}
function removeContent(name){
$(model[name]).remove()
delete model['name']
}
function show(){
if (isOpen) { return }
isOpen = true
view.show()
view.addClass('showing')
triggerEvent(eventsTriggered.shown)
}
function hide(){
if (!isOpen) { return }
isOpen = false
view.hide()
view.removeClass('showing')
triggerEvent(eventsTriggered.hidden)
}
function toggle(){
if (isOpen) {
context.hide()
} else {
context.show()
}
}
function triggerEvent(eventType, callbackArgs){
view.trigger(eventType, callbackArgs)
$(context).triggerHandler(eventType, callbackArgs)
}
}
})(jQuery)