summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/with_select.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/with_select.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/with_select.js')
-rw-r--r--third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/with_select.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/with_select.js b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/with_select.js
new file mode 100644
index 0000000000..2a99feaadf
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/with_select.js
@@ -0,0 +1,64 @@
+'use strict';
+
+define(
+
+ function() {
+
+ return withSelect;
+
+ function withSelect() {
+
+ this.defaultAttrs({
+ selectedIds: []
+ });
+
+ this.initializeSelections = function() {
+ this.select('selectedItemSelector').toArray().forEach(function(el) {
+ this.attr.selectedIds.push(el.getAttribute('id'));
+ }, this);
+ };
+
+ this.getSelectedIds = function() {
+ return this.attr.selectedIds;
+ };
+
+ this.toggleItemSelect = function(ev, data) {
+ var $item = $(data.el), append;
+
+ if ($item.hasClass(this.attr.selectedClass)) {
+ this.unselectItem($item);
+ } else {
+ append = this.attr.allowMultiSelect && (ev.metaKey || ev.ctrlKey || ev.shiftKey);
+ this.selectItem($item, append);
+ }
+ };
+
+ this.selectItem = function($item, append) {
+ if (!append) {
+ this.select('selectedItemSelector').removeClass(this.attr.selectedClass);
+ this.attr.selectedIds = [];
+ }
+ $item.addClass(this.attr.selectedClass);
+
+ this.attr.selectedIds.push($item.attr('id'));
+ this.trigger(this.attr.selectionChangedEvent, {selectedIds: this.attr.selectedIds});
+ };
+
+ this.unselectItem = function($item) {
+ $item.removeClass(this.attr.selectedClass);
+
+ var thisIdIndex = this.attr.selectedIds.indexOf($item.attr('id'));
+ this.attr.selectedIds.splice(thisIdIndex, 1);
+ this.trigger(this.attr.selectionChangedEvent, {selectedIds: this.attr.selectedIds});
+ };
+
+ this.after("initialize", function() {
+ this.on('click', {
+ 'itemSelector': this.toggleItemSelect
+ });
+
+ this.initializeSelections();
+ });
+ }
+ }
+);