-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
iframe width and tabs #70
Open
janat08
wants to merge
2
commits into
egoist:master
Choose a base branch
from
janat08:embedParams
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
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 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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
You can embed the URL using an iframe in your website. | ||
|
||
Optionally append `?readonly` to make the editor read-only. | ||
|
||
You can specify which tabs are to be active at start, and their width. Tab names are `html`, `css`, `js`, `console`, and `output`. Once specifying a tab to be active, none of defaults tabs will be active. You may specify a tab to be just active with average/standard width by passing `1` or specify custom width with any larger number which be parsed as percentage of window width to take. | ||
|
||
For example: | ||
`<iframe src='/?html=30&js=1&console=10&output=30&css=1' width=100% height=500 frameborder='0'></iframe>` |
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,2 @@ | ||
<!-- To test iframes go to localhost:4000/iFrameTest.html --> | ||
<iframe src='/?html=30&js=10&console=1&output=20&css=20' width=100% height=500 param='one' frameborder='0'></iframe> |
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,48 @@ | ||
// lets you specify what tabs are to be opened on init, and what width they should be | ||
// 1 is just on of equal/standard width, and 50 is 50% width | ||
const pans = ['html', 'css', 'js', 'console', 'output'] | ||
const nonembed = window.self === window.top | ||
const nulify = val => { | ||
return nonembed ? null : val | ||
} | ||
const params = window.location.search.slice(1).split('&').map(x => x.split('=')) | ||
const paramsO = params.reduce((a, x) => { | ||
a[x[0]] = x[1] | ||
return a | ||
}, {}) | ||
|
||
const selected = pans.filter(x => Boolean(paramsO[x])) | ||
const visiblePans = nulify(selected.length ? selected : null) | ||
|
||
const sorted = pans.map(x => paramsO[x]).filter(x => x) | ||
const sortedNames = pans.filter(x => paramsO[x]) | ||
const sortLen = sorted.length | ||
const specified = sorted.filter(x => x > 1) | ||
const specLen = specified.length | ||
// width specified | ||
let mutedStyles | ||
if (specLen) { | ||
const sum = specified.reduce((a, x) => a + Number(x), 0) | ||
const average = parseFloat((100 - sum) / (sortLen - specLen)) | ||
let left = 0 | ||
mutedStyles = sorted.map(x => { | ||
let width | ||
if (x > 1) { | ||
width = x | ||
} else { | ||
width = average | ||
} | ||
const res = { left: per(left) } | ||
left += Number(width) | ||
res.right = per(100 - left) | ||
return res | ||
}).reduce((a, x, i) => { | ||
a[sortedNames[i]] = x | ||
return a | ||
}, {}) | ||
} | ||
const initialStyles = mutedStyles || {} | ||
function per(x) { | ||
return parseFloat(x) + '%' | ||
} | ||
export { visiblePans, paramsO, initialStyles } |
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
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
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.
we can use
$store.dispatch('showPans', [])
and$route.query
insteadThere 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.
const params2 = router.match(window.location).query
returns nothing. Otherwise $route object isn't accessible outside vue.