-
Notifications
You must be signed in to change notification settings - Fork 0
Run code PrismJS button registration #14
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 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33eb10b
Run code PrismJS button registration
cherifGsoul 2939c7d
remove comment in the code
cherifGsoul d579268
DOM queries enhancements
cherifGsoul 536289a
Prevent run button to be registred for every demo
cherifGsoul 8b1aa0c
Check if codepen iframe is selected
cherifGsoul df6865a
Be specific to div when selecting the codepen link
cherifGsoul 96d22a3
use event delegation on run button
cherifGsoul 7a18b43
One delegated event listener on the body
cherifGsoul 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
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 |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ describe("bit-docs-html-codepen-link", function() { | |
| html: { | ||
| dependencies: { | ||
| "bit-docs-html-codepen-link": __dirname, | ||
| "bit-docs-prettify": "^0.4.0", | ||
| "bit-docs-tag-demo": "^0.5.3" | ||
| } | ||
| }, | ||
|
|
@@ -54,10 +55,10 @@ describe("bit-docs-html-codepen-link", function() { | |
| browser.window.CREATE_CODE_PEN = function(data) { | ||
| createCallData.push(data); | ||
| }; | ||
| var codePens = doc.querySelectorAll('.codepen'); | ||
|
|
||
| Array.from(codePens).forEach(function(codePen) { | ||
| codePen.click(); | ||
| var toolbars = doc.querySelectorAll('.toolbar'); | ||
| Array.from(toolbars).forEach(function(toolbar) { | ||
|
||
| var btn = toolbar.children[toolbar.children.length - 1].querySelector('button'); | ||
| btn.click(); | ||
| }); | ||
| assert.deepEqual(createCallData, [{ | ||
| html: '<my-app></my-app>', | ||
|
|
@@ -70,8 +71,21 @@ describe("bit-docs-html-codepen-link", function() { | |
| js: 'import {DefineMap} from "//unpkg.com/can@^5.0.0-pre.1/core.mjs";\nconsole.log( myCounter.count ) //-> 1', | ||
| js_module: true, | ||
| editors: '0011' | ||
| } | ||
| ]); | ||
| }, | ||
| { | ||
| css: 'h1 {color: red;}', | ||
| editors: '1011', | ||
| html: '<h1>Hi There!</h1>', | ||
| js: 'var code = "code";', | ||
| js_module: true | ||
| }, | ||
| { | ||
| css: 'h1 {color: red;}', | ||
| editors: '1011', | ||
| html: '<h1>Hi There!</h1>', | ||
| js: 'var code = "code";', | ||
| js_module: true | ||
| }]); | ||
|
|
||
| close(); | ||
| done(); | ||
|
|
@@ -223,4 +237,45 @@ describe("bit-docs-html-codepen-link", function() { | |
| it("supports ts files", function() { | ||
| assert.ok(codepenData.ts, "there is a ts"); | ||
| }); | ||
|
|
||
| it("Registers run code button", function(done) { | ||
| this.timeout(60000); | ||
|
|
||
| var docMap = Promise.resolve({ | ||
| index: { | ||
| name: "index", | ||
| demo: "path/to/demo.html", | ||
| body: fs.readFileSync(__dirname + "/test-demo.md", "utf8"), | ||
| codepen: [ | ||
| ["can", "//unpkg.com/can@^5.0.0-pre.1/core.mjs"] | ||
| ] | ||
| } | ||
| }); | ||
|
|
||
| generate(docMap, { | ||
| html: { | ||
| dependencies: { | ||
| "bit-docs-html-codepen-link": __dirname, | ||
| "bit-docs-prettify": "^0.4.0", | ||
| "bit-docs-tag-demo": "^0.5.3" | ||
| } | ||
| }, | ||
| dest: path.join(__dirname, "temp"), | ||
| parent: "index", | ||
| forceBuild: true, | ||
| minifyBuild: false | ||
| }).then(function() { | ||
| open("temp/index.html", function(browser, close) { | ||
| var doc = browser.window.document; | ||
| var toolbars = doc.querySelectorAll(".code-toolbar"); | ||
| toolbars.forEach(function(toolbar) { | ||
| var children = toolbar.children; | ||
| assert.equal(toolbar.children.length, 2); | ||
| assert.equal(children[children.length - 1].innerHTML, '<div class="toolbar-item"><button>Copy</button></div><div class="toolbar-item"><button>Run</button></div>'); | ||
| }); | ||
| close(); | ||
| done(); | ||
| }, done); | ||
| }, done); | ||
| }); | ||
| }); | ||
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.
Does
registerButtononly need to be called once (vs. a call for each instance of the toolbar)?Instead of keeping the
parents, should we walk up fromenv.elementto find thepre?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.
The
registerButtonneeds to be called once otherwise it register all the buttons for each of the codes.For
parentsI did try to walk up but it didn't work.