-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from wildbit/feature/template-preview
Template preview command
- Loading branch information
Showing
23 changed files
with
2,427 additions
and
83 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,87 @@ | ||
var activeToggleClass = 'is-active' | ||
|
||
/** | ||
* Mode toggles | ||
*/ | ||
var mode = document.querySelectorAll('.js-mode') | ||
var currentMode = 'html' | ||
|
||
mode.forEach(function(toggle) { | ||
toggle.addEventListener('click', function(event) { | ||
// Reset all classes | ||
mode.forEach(function(modeToggle) { | ||
// Remove active class from all toggles | ||
modeToggle.classList.remove(activeToggleClass) | ||
|
||
// Hide all views | ||
document | ||
.querySelector('.js-' + modeToggle.dataset.mode) | ||
.classList.add('is-hidden') | ||
}) | ||
|
||
// Add active class | ||
currentMode = this.dataset.mode | ||
this.classList.add(activeToggleClass) | ||
|
||
// Show view | ||
document | ||
.querySelector('.js-' + this.dataset.mode) | ||
.classList.remove('is-hidden') | ||
}) | ||
}) | ||
|
||
/** | ||
* View toggles | ||
*/ | ||
var view = document.querySelectorAll('.js-view') | ||
var currentView = 'desktop' | ||
|
||
view.forEach(function(toggle) { | ||
// Add click event | ||
toggle.addEventListener('click', function(event) { | ||
view.forEach(function(viewToggle) { | ||
// Remove active class from all toggles | ||
viewToggle.classList.remove(activeToggleClass) | ||
|
||
document.querySelectorAll('.preview-iframe').forEach(function(item) { | ||
item.classList.remove('preview-iframe--mobile') | ||
}) | ||
}) | ||
|
||
currentView = this.dataset.view | ||
this.classList.add(activeToggleClass) | ||
|
||
if (this.dataset.view === 'mobile') { | ||
document.querySelectorAll('.preview-iframe').forEach(function(item) { | ||
item.classList.add('preview-iframe--mobile') | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
function keypress(e) { | ||
var evt = window.event ? event : e | ||
|
||
// ctrl + v | ||
if (evt.keyCode == 86 && evt.ctrlKey) { | ||
var view = currentView === 'desktop' ? 'mobile' : 'desktop' | ||
document.querySelector('.js-view[data-view="' + view + '"]').click() | ||
} | ||
|
||
// ctrl + m | ||
if (evt.keyCode == 77 && evt.ctrlKey) { | ||
var mode = currentMode === 'html' ? 'text' : 'html' | ||
document.querySelector('.js-mode[data-mode="' + mode + '"]').click() | ||
} | ||
} | ||
|
||
document.onkeydown = keypress | ||
|
||
// Manage state when HTML iframe is finished loading | ||
document.querySelector('.js-html').onload = function() { | ||
// Hide loading indicator | ||
document.querySelector('.js-loader').classList.add('is-hidden') | ||
|
||
// Add state class to HTML iframe | ||
this.classList.add('is-loaded') | ||
} |
Oops, something went wrong.