Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: make Platform related content use the event system #332

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions src/_js/lib/PlatformContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
$('<div class="unsupported-hint"></div>').prependTo(this);
});
};

const syncRelatedElements = function() {
let platform = window.platformData[window.activePlatform];
let style = platform && platform.case_style || 'canonical';
Expand Down Expand Up @@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one functional change I made. Since we're firing this off whenever the platform changes, we'll need to remove the previous elements so we don't keep adding them on top of one another.

$('.unsupported').each(function() {
$('<div class="unsupported-hint"></div>').prependTo(this);
});

syncRelatedElements();
};

Expand All @@ -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 };
3 changes: 1 addition & 2 deletions src/_js/main.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -24,7 +24,6 @@ $(document).on('page.didUpdate', function(event) {
});

$(function() {
PlatformContent.init();
UserContent.init();
Tracking.init();
Search.init();
Expand Down