Skip to content

Conversation

L3au
Copy link
Contributor

@L3au L3au commented Jun 3, 2019

Summary

close #860

This PR fix two problems.

  1. document.currentScript doesn't work in a callback or event handler, and will always return null with initializing config after DOMContentLoaded in docsify.

It's important to note that this will not reference the <script> element if the code in the script is being called as a callback or event handler; it will only reference the element while it's initially being processed. - MDN

/**
* Run Docsify
*/
ready(_ => new Docsify())

  1. There are some config fields coercions(e.g. config.loadSidebar === true) after merging from current executing script, but I think these coercions should not depend on the existence of current script, so I move them out.

const script =
document.currentScript ||
[].slice
.call(document.getElementsByTagName('script'))
.filter(n => /docsify\./.test(n.src))[0]
if (script) {
for (const prop in config) {
if (hasOwn.call(config, prop)) {
const val = script.getAttribute('data-' + hyphenate(prop))
if (isPrimitive(val)) {
config[prop] = val === '' ? true : val
}
}
}
if (config.loadSidebar === true) {
config.loadSidebar = '_sidebar' + config.ext
}
if (config.loadNavbar === true) {
config.loadNavbar = '_navbar' + config.ext
}
if (config.coverpage === true) {
config.coverpage = '_coverpage' + config.ext
}
if (config.repo === true) {
config.repo = ''
}
if (config.name === true) {
config.name = ''
}
}

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome, Chrome/74.0.3729.169
  • Firefox
  • Safari, Safari/605.1.15
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:


  • DO NOT include files inside lib directory.

@timaschew @QingWei-Li

@anikethsaha
Copy link
Member

@L3au can you rebase and resolve the conflicts, its good to go I guess 👍

@L3au
Copy link
Contributor Author

L3au commented Jan 15, 2020

@anikethsaha rebased and resolved the conflicts. please have a look.

@L3au
Copy link
Contributor Author

L3au commented Jan 15, 2020

lint failed, it seems there are all files in the lib folder. What gonna do with this issue?

@L3au L3au requested review from QingWei-Li and anikethsaha and removed request for QingWei-Li January 15, 2020 22:40
@anikethsaha
Copy link
Member

@L3au Please rebase to run the tests

@anikethsaha anikethsaha self-assigned this Feb 5, 2020
@L3au
Copy link
Contributor Author

L3au commented Feb 6, 2020

@anikethsaha Fixed. could you review it again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loadSidebar: true doesn't work well when script src doesn't contain docsify.

2 participants