/
manifestsPanel.js
172 lines (144 loc) · 6.42 KB
/
manifestsPanel.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
(function($) {
$.ManifestsPanel = function(options) {
jQuery.extend(true, this, {
element: null,
listItems: null,
appendTo: null,
manifestListItems: [],
manifestListElement: null,
manifestLoadStatusIndicator: null,
resultsWidth: 0,
state: null,
eventEmitter: null
}, options);
var _this = this;
_this.init();
};
$.ManifestsPanel.prototype = {
init: function() {
this.element = jQuery(this.template({
showURLBox : this.state.getStateProperty('showAddFromURLBox')
})).appendTo(this.appendTo);
this.manifestListElement = this.element.find('ul');
//this code gives us the max width of the results area, used to determine how many preview images to show
//cloning the element and adjusting the display and visibility means it won't break the normal flow
var clone = this.element.clone().css("visibility","hidden").css("display", "block").appendTo(this.appendTo);
this.resultsWidth = clone.find('.select-results').outerWidth();
this.controlsHeight = clone.find('.manifest-panel-controls').outerHeight();
this.paddingListElement = this.controlsHeight;
this.manifestListElement.css("padding-bottom", this.paddingListElement);
clone.remove();
// this.manifestLoadStatusIndicator = new $.ManifestLoadStatusIndicator({
// manifests: this.parent.manifests,
// appendTo: this.element.find('.select-results')
// });
this.bindEvents();
this.listenForActions();
},
listenForActions: function() {
var _this = this;
// handle subscribed events
_this.eventEmitter.subscribe('manifestsPanelVisible.set', function(_, stateValue) {
_this.onPanelVisible(_, stateValue);
});
_this.eventEmitter.subscribe('manifestReceived', function(event, newManifest) {
_this.onManifestReceived(event, newManifest);
});
},
bindEvents: function() {
var _this = this;
// handle interface events
this.element.find('form#url-load-form').on('submit', function(event) {
event.preventDefault();
_this.addManifestUrl(jQuery(this).find('input').val());
});
this.element.find('.remove-object-option').on('click', function(event) {
_this.togglePanel(event);
});
// Filter manifests based on user input
this.element.find('#manifest-search').on('keyup input', function(event) {
_this.filterManifests(this.value);
});
this.element.find('#manifest-search-form').on('submit', function(event) {
event.preventDefault();
});
jQuery(window).resize($.throttle(function() {
_this.resizePanel();
}, 50, true));
},
hide: function() {
var _this = this;
jQuery(this.element).hide({effect: "fade", duration: 160, easing: "easeOutCubic"});
},
show: function() {
var _this = this;
jQuery(this.element).show({effect: "fade", duration: 160, easing: "easeInCubic"});
},
addManifestUrl: function(url) {
var _this = this;
_this.eventEmitter.publish('ADD_MANIFEST_FROM_URL', url, "(Added from URL)");
},
togglePanel: function(event) {
var _this = this;
_this.eventEmitter.publish('TOGGLE_LOAD_WINDOW');
},
filterManifests: function(value) {
var _this = this;
if (value.length > 0) {
_this.element.find('.items-listing li').show().filter(function() {
return jQuery(this).text().toLowerCase().indexOf(value.toLowerCase()) === -1;
}).hide();
} else {
_this.element.find('.items-listing li').show();
}
},
resizePanel: function() {
var _this = this;
var clone = _this.element.clone().css("visibility","hidden").css("display", "block").appendTo(_this.appendTo);
_this.resultsWidth = clone.find('.select-results').outerWidth();
clone.remove();
_this.eventEmitter.publish("manifestPanelWidthChanged", _this.resultsWidth);
},
onPanelVisible: function(_, stateValue) {
var _this = this;
if (stateValue) { _this.show(); return; }
_this.hide();
},
onManifestReceived: function(event, newManifest) {
var _this = this;
_this.manifestListItems.push(new $.ManifestListItem({
manifest: newManifest,
resultsWidth: _this.resultsWidth,
state: _this.state,
eventEmitter: _this.eventEmitter,
appendTo: _this.manifestListElement }));
_this.element.find('#manifest-search').keyup();
},
template: Handlebars.compile([
'<div id="manifest-select-menu">',
'<div class="container">',
'<div class="manifest-panel-controls">',
'<a class="remove-object-option"><i class="fa fa-times fa-lg fa-fw"></i>{{t "close"}}</a>',
'<div id="load-controls">',
'{{#if showURLBox}}',
'<form action="" id="url-load-form">',
'<label for="url-loader">{{t "addNewObject"}}:</label>',
'<input type="text" id="url-loader" name="url-load" placeholder="http://...">',
'<input type="submit" value="{{t "load"}}">',
'</form>',
'{{/if}}',
'<form action="" id="manifest-search-form">',
'<label for="manifest-search">{{t "filterObjects"}}:</label>',
'<input id="manifest-search" type="text" name="manifest-filter">',
'</form>',
'</div>',
'</div>',
'<div class="select-results">',
'<ul class="items-listing">',
'</ul>',
'</div>',
'</div>',
'</div>'
].join(''))
};
}(Mirador));