From 56c1826b1801b6c3ce4342e5add9abe0c8b1cc41 Mon Sep 17 00:00:00 2001 From: Cameron McEfee Date: Tue, 11 Sep 2018 13:19:16 -0700 Subject: [PATCH] ref: make Platform related content use the event system --- src/_js/lib/PlatformContent.js | 31 ++++++++++--------------------- src/_js/main.js | 3 +-- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/_js/lib/PlatformContent.js b/src/_js/lib/PlatformContent.js index 5b64bce3664ba..c74de8ab36030 100644 --- a/src/_js/lib/PlatformContent.js +++ b/src/_js/lib/PlatformContent.js @@ -47,16 +47,6 @@ const updateUrlPlatform = function(url, slug) { return `${origin}?${qs.stringify(query)}`; }; -const initRelatedElements = function() { - $('.config-key').each(function() { - this.setAttribute('data-config-key', $(this).text()); - }); - - $('.unsupported').each(function() { - $('
').prependTo(this); - }); -}; - const syncRelatedElements = function() { let platform = window.platformData[window.activePlatform]; let style = platform && platform.case_style || 'canonical'; @@ -144,6 +134,16 @@ const showPlatform = function(slug) { }); history.replaceState({}, '', updateUrlPlatform(location.href, slug)); + + $('.config-key').each(function() { + this.setAttribute('data-config-key', $(this).text()); + }); + + $('.unsupported-hint').remove(); + $('.unsupported').each(function() { + $('
').prependTo(this); + }); + syncRelatedElements(); }; @@ -156,14 +156,3 @@ $(document).on('page.didUpdate', function(event) { // Update the preferredPlatform based on the url. showPlatform(qs.parse(location.search).platform); }); - -// Attach event listeners and set UI state based on the platform supplied via -// query param, stored in localStorage as the preferred platform, or the -// default platform, in that order. -// -// Returns nothing. -const init = function() { - initRelatedElements(); -}; - -export default { init }; diff --git a/src/_js/main.js b/src/_js/main.js index 07d6a7a640718..1d8d1d835f0a9 100644 --- a/src/_js/main.js +++ b/src/_js/main.js @@ -1,11 +1,11 @@ import Raven from 'raven-js'; import 'bootstrap'; -import PlatformContent from './lib/PlatformContent'; import UserContent from './lib/UserContent'; import Tracking from './lib/Tracking'; import User from './lib/User'; import DynamicLoad from './lib/DynamicLoad'; import Search from './lib/Search'; +import './lib/PlatformContent'; import './lib/HeaderLinker'; import './lib/Feedback'; import './lib/Sidebar'; @@ -24,7 +24,6 @@ $(document).on('page.didUpdate', function(event) { }); $(function() { - PlatformContent.init(); UserContent.init(); Tracking.init(); Search.init();