From a94ab44431d368609e5bcd563a2f47045e050913 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 22 Aug 2016 12:24:40 -0700 Subject: [PATCH] [Selection] Toggle selected class --- src/selection/SelectGesture.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/selection/SelectGesture.js b/src/selection/SelectGesture.js index 395d27b749..ccd1f7f8ab 100644 --- a/src/selection/SelectGesture.js +++ b/src/selection/SelectGesture.js @@ -20,18 +20,34 @@ * at runtime from the About dialog for additional information. *****************************************************************************/ -define(['zepto'], function ($) { - function SelectGesture(selection) { +define(['zepto', './Path'], function ($, Path) { + function SelectGesture(selection, contextManager) { this.selection = selection; + this.contextManager = contextManager; } SelectGesture.prototype.apply = function (htmlElement, item) { var $element = $(htmlElement); + var contextManager = this.contextManager; var selection = this.selection; - var select = selection.add.bind(selection, item); + var path = new Path(item, contextManager.path(htmlElement)); + + function select() { + selection.add(path); + } + + function change() { + var selected = selection.primary(); + $element.toggleClass( + 'selected', + selected && path.matches(selected) + ); + } $element.addClass('selectable'); $element.on('click', select); + selection.on('change', change); + change(); // Initialize }; return SelectGesture;