-
Notifications
You must be signed in to change notification settings - Fork 0
Add a bar that advertises the community survey #397
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,3 +22,4 @@ | |
| @import "screenshots.less"; | ||
| @import "loading-bar.less"; | ||
| @import "search.less"; | ||
| @import "survey-ad.less"; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| var Control = require("can-control"); | ||
|
|
||
| module.exports = Control.extend({ | ||
| defaults: { | ||
| engagementCountKey: 'survey-ad-engagement-count', | ||
| engagementCountMinimum: 3, | ||
| userDidCloseKey: 'survey-ad-closed' | ||
| } | ||
| }, { | ||
|
|
||
| /* This should only happen once */ | ||
| init: function() { | ||
| var surveyAdElement = this.element; | ||
|
|
||
| // Always show the close button since JS is active | ||
| var closeButton = surveyAdElement.querySelector('.close'); | ||
| if (closeButton.classList) {// Only enable the close button in IE10+ | ||
| closeButton.style.display = 'inline-block'; | ||
| } | ||
|
|
||
| try { | ||
|
|
||
| // Look up the user’s preference in localStorage | ||
| var didClose = window.localStorage.getItem(this.options.userDidCloseKey); | ||
|
|
||
| // Get how many times the user has engaged | ||
| var engagementCount = window.localStorage.getItem(this.options.engagementCountKey); | ||
|
|
||
| // If the user hasn’t closed the control and their engagement count is | ||
| // greater than the minimum, show the control | ||
| if (!didClose && engagementCount >= this.options.engagementCountMinimum) { | ||
| this.show(); | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.info('Caught localStorage error:', error); | ||
| } | ||
| }, | ||
|
|
||
| /* This should happen whenever a new page is loaded */ | ||
| didEngage: function() { | ||
| try { | ||
| var storageKey = this.options.engagementCountKey; | ||
| var engagementCount = parseInt(window.localStorage.getItem(storageKey) || '0', 10); | ||
| var newEngagementCount = 1 + engagementCount; | ||
|
|
||
| // Store the new engagement count | ||
| window.localStorage.setItem(storageKey, newEngagementCount); | ||
|
|
||
| // Potentially show the control | ||
| if (newEngagementCount >= this.options.engagementCountMinimum) { | ||
|
|
||
| // Look up the user’s preference in localStorage | ||
| var didClose = window.localStorage.getItem(this.options.userDidCloseKey); | ||
| if (!didClose) { | ||
| this.show(); | ||
| } | ||
|
|
||
| } | ||
| } catch (error) { | ||
| console.info('Caught localStorage error:', error); | ||
| } | ||
| }, | ||
|
|
||
| hide: function(immediately) { | ||
|
|
||
| // Remove .showing to animate the control out of view | ||
| if (this.element.classList) { | ||
| this.element.classList.remove('showing'); | ||
| } | ||
|
|
||
| // .survey-ad-showing is used to change padding-bottom on the rest of the content | ||
| document.getElementById('everything').classList.remove('survey-ad-showing'); | ||
| }, | ||
|
|
||
| show: function() { | ||
|
|
||
| // Add a class to animate the control into view | ||
| if (this.element.classList) { | ||
| this.element.classList.add('showing'); | ||
| } | ||
|
|
||
| // .survey-ad-showing is used to change padding-bottom on the rest of the content | ||
| document.getElementById('everything').classList.add('survey-ad-showing'); | ||
| }, | ||
|
|
||
| /* This event will fire when the user clicks the X button */ | ||
| '{element} .close click': function() { | ||
|
|
||
| // Hide the control | ||
| this.hide(); | ||
|
|
||
| // Try to remember the user’s preference in localStorage | ||
| try { | ||
| // Get the current time; we don’t make use of this right now, | ||
| // but in the future if we want to re-enable the link after a | ||
| // certain amount of time or for a particular event, we can | ||
| // more easily do that :) | ||
| var currentTime = (new Date()).getTime(); | ||
| var storageKey = this.options.userDidCloseKey; | ||
| window.localStorage.setItem(storageKey, currentTime); | ||
| } catch (error) { | ||
| console.info('Caught localStorage error:', error); | ||
| } | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| survey-ad { | ||
| background: white; | ||
| border-top: 1px solid @border-color; | ||
| bottom: -3.1rem;// 3 rem + a little bit for the top border | ||
| position: absolute; | ||
| text-align: center; | ||
| transition: bottom @transition-speed ease; | ||
| width: 100%; | ||
| z-index: 90;// This matches #right’s z-index | ||
|
|
||
| a { | ||
| display: block; | ||
| line-height: 3rem; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .close { | ||
| background: none; | ||
| border: none; | ||
| cursor: pointer; | ||
| display: none; | ||
| font-size: 1.5rem; | ||
| line-height: 3rem; | ||
| margin: 0; | ||
| outline: none; | ||
| padding: 0; | ||
| position: absolute; | ||
| right: 0; | ||
| width: 3rem; | ||
| } | ||
|
|
||
| &.showing { | ||
| bottom: 0; | ||
| } | ||
| } | ||
|
|
||
| // Hide this component on mobile | ||
| @media screen and (max-width: @breakpoint) { | ||
| survey-ad { | ||
| display: none; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,3 +29,4 @@ | |
| </div> | ||
| </div> | ||
| </div> | ||
| {{> survey-ad.mustache}} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <survey-ad> | ||
| <button aria-label="Close" class="close" type="button"> | ||
| <span aria-hidden="true">×</span> | ||
| </button> | ||
| <a href="https://donejs.com/survey.html" target="_blank"> | ||
| Help us improve CanJS by signing up for our community survey | ||
| </a> | ||
| </survey-ad> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Props for avoiding jQuery 👏