From 1db79044b5a2413723bd6f4a23daef169b3db0b8 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Mon, 4 May 2015 14:38:50 -0700 Subject: [PATCH] Quicksand - fix toggle behavior to work with quicksand Summary: Fixes T7919. This is a pretty generic toggle behavior. Make it quicksand ready by making it install only once and swallow the regular "click" event so the quicksand "click" event doesn't get funky with it. Also fixes a bug in Quicksand that I discovered developing / testing this feature. We have to update the internal member variable to be better than 0 similarly to how id works. So do that. Test Plan: went to phriction, toggled menu open, clicked home, clicked phriction and toggled menu again. Went back in history and noted menu was left to toggle state I previously had it. (currently a feature, not a bug) Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7919 Differential Revision: https://secure.phabricator.com/D12708 --- resources/celerity/map.php | 26 ++++++------- .../rsrc/externals/javelin/lib/Quicksand.js | 1 + webroot/rsrc/js/core/behavior-toggle-class.js | 39 +++++++++++++------ 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 9e37438fa0..6a78fae4e3 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -8,7 +8,7 @@ return array( 'names' => array( 'core.pkg.css' => 'ca3f6a60', - 'core.pkg.js' => '3331b919', + 'core.pkg.js' => 'e9484a4e', 'darkconsole.pkg.js' => 'e7393ebb', 'differential.pkg.css' => 'bb338e4b', 'differential.pkg.js' => '3cfa26f9', @@ -205,7 +205,7 @@ return array( 'rsrc/externals/javelin/lib/JSON.js' => '69adf288', 'rsrc/externals/javelin/lib/Leader.js' => '331b1611', 'rsrc/externals/javelin/lib/Mask.js' => '8a41885b', - 'rsrc/externals/javelin/lib/Quicksand.js' => '7ba665f5', + 'rsrc/externals/javelin/lib/Quicksand.js' => '977e1f47', 'rsrc/externals/javelin/lib/Request.js' => '94b750d2', 'rsrc/externals/javelin/lib/Resource.js' => '44959b73', 'rsrc/externals/javelin/lib/Routable.js' => 'b3e7d692', @@ -488,7 +488,7 @@ return array( 'rsrc/js/core/behavior-scrollbar.js' => '834a1173', 'rsrc/js/core/behavior-search-typeahead.js' => '048330fa', 'rsrc/js/core/behavior-select-on-click.js' => '4e3e79a6', - 'rsrc/js/core/behavior-toggle-class.js' => 'e566f52c', + 'rsrc/js/core/behavior-toggle-class.js' => '5d7c9f33', 'rsrc/js/core/behavior-tokenizer.js' => 'b3a4b884', 'rsrc/js/core/behavior-tooltip.js' => '3ee3408b', 'rsrc/js/core/behavior-watch-anchor.js' => '9f36c42d', @@ -659,7 +659,7 @@ return array( 'javelin-behavior-slowvote-embed' => '887ad43f', 'javelin-behavior-stripe-payment-form' => '3f5d6dbf', 'javelin-behavior-test-payment-form' => 'fc91ab6c', - 'javelin-behavior-toggle-class' => 'e566f52c', + 'javelin-behavior-toggle-class' => '5d7c9f33', 'javelin-behavior-typeahead-browse' => '635de1ec', 'javelin-behavior-typeahead-search' => '93d0c9e3', 'javelin-behavior-view-placeholder' => '47830651', @@ -677,7 +677,7 @@ return array( 'javelin-leader' => '331b1611', 'javelin-magical-init' => '3010e992', 'javelin-mask' => '8a41885b', - 'javelin-quicksand' => '7ba665f5', + 'javelin-quicksand' => '977e1f47', 'javelin-reactor' => '2b8de964', 'javelin-reactor-dom' => 'c90a04fc', 'javelin-reactor-node-calmer' => '76f4ebed', @@ -1234,6 +1234,11 @@ return array( 'javelin-dom', 'javelin-vector', ), + '5d7c9f33' => array( + 'javelin-behavior', + 'javelin-stratcom', + 'javelin-dom', + ), '5e9f347c' => array( 'javelin-behavior', 'multirow-row-manager', @@ -1408,9 +1413,6 @@ return array( 'javelin-stratcom', 'javelin-util', ), - '7ba665f5' => array( - 'javelin-install', - ), '7cbe244b' => array( 'javelin-install', 'javelin-util', @@ -1594,6 +1596,9 @@ return array( 'javelin-resource', 'javelin-routable', ), + '977e1f47' => array( + 'javelin-install', + ), '988040b4' => array( 'javelin-install', 'javelin-dom', @@ -1895,11 +1900,6 @@ return array( 'javelin-behavior', 'javelin-dom', ), - 'e566f52c' => array( - 'javelin-behavior', - 'javelin-stratcom', - 'javelin-dom', - ), 'e5822781' => array( 'javelin-behavior', 'javelin-dom', diff --git a/webroot/rsrc/externals/javelin/lib/Quicksand.js b/webroot/rsrc/externals/javelin/lib/Quicksand.js index 780e03131d..f72eb23cbc 100644 --- a/webroot/rsrc/externals/javelin/lib/Quicksand.js +++ b/webroot/rsrc/externals/javelin/lib/Quicksand.js @@ -53,6 +53,7 @@ JX.install('Quicksand', { var path = self._getRelativeURI(window.location); self._id = window.history.state || 0; var id = self._id; + self._onpage = id; self._history.push({path: path, id: id}); self._responses[id] = first_response; diff --git a/webroot/rsrc/js/core/behavior-toggle-class.js b/webroot/rsrc/js/core/behavior-toggle-class.js index 2e21ed9716..d8f7ef5bb5 100644 --- a/webroot/rsrc/js/core/behavior-toggle-class.js +++ b/webroot/rsrc/js/core/behavior-toggle-class.js @@ -14,17 +14,32 @@ * Optionally, you may provide a `state` key to set the default state of the * element. */ -JX.behavior('toggle-class', function() { - JX.Stratcom.listen( - ['touchstart', 'mousedown'], - 'jx-toggle-class', - function(e) { - e.kill(); +JX.behavior('toggle-class', function(config, statics) { + statics.install = statics.install || install(); - var t = e.getNodeData('jx-toggle-class'); - t.state = !t.state; - for (var k in t.map) { - JX.DOM.alterClass(JX.$(k), t.map[k], t.state); - } - }); + function install() { + JX.Stratcom.listen( + ['touchstart', 'mousedown'], + 'jx-toggle-class', + function(e) { + e.kill(); + + var t = e.getNodeData('jx-toggle-class'); + t.state = !t.state; + for (var k in t.map) { + JX.DOM.alterClass(JX.$(k), t.map[k], t.state); + } + }); + + // Swallow the regular click handler event so e.g. Quicksand + // click handler doesn't get a hold of it + JX.Stratcom.listen( + ['click'], + 'jx-toggle-class', + function(e) { + e.kill(); + }); + + return true; + } });