Skip to content

Commit

Permalink
refactor: add getCurrentDocUrl method to magicbook instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ipluser committed May 16, 2016
1 parent a65a493 commit c888f48
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/magicbook.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lib/magicbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@
}
};

proto.getCurrentDocUrl = function getCurrentDocUrl() {
var self = this;
var url = globalLocation.hash || self.config.homeUrl;

return url.replace(/^#/, '');
};

var markdownFactories = {};
Magicbook.markdown = function markdown(name, cfg) {
var factory = markdownFactories[name] || Magicbook;
Expand Down
8 changes: 1 addition & 7 deletions plugins/components/js/agilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
return urls;
}

function getCurrentUrl(defaultUrl) {
var url = globalLocation.hash || defaultUrl;

return url.replace(/^#/, '');
}

/**
* draw button of scroll to top
* @param {Object|boolean} cfg => true/false or {
Expand Down Expand Up @@ -135,7 +129,7 @@

function flip(type) {
var _type = type || 'next';
var curUrl = getCurrentUrl(homeUrl);
var curUrl = self.getCurrentDocUrl();
var curIndex = urls.indexOf(curUrl);

if (curIndex === -1) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/components/js/agilities.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions public/doc/methods.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## Methods
### getCurrentDocUrl
Get current document's url.

##### parameters
none


### handler
Get and set handler that add extra initialization to Magicbook.

Expand Down

0 comments on commit c888f48

Please sign in to comment.