Skip to content

Commit

Permalink
refactor: replace normalizeImageUrl with relativeCurrentUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
ipluser committed May 16, 2016
1 parent 79c7903 commit a65a493
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 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.

11 changes: 6 additions & 5 deletions lib/magicbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@

for (index = 0, len = $images.length; index < len; index++) {
$image = $($images[index]);
$image.attr('src', self.normalizeImageUrl(global.location.hash || self.config.homeUrl, $image.attr('src')));
$image.attr('src', self.relativeCurrentUrl($image.attr('src')));
}
}

Expand Down Expand Up @@ -320,11 +320,12 @@
return _url;
};

proto.normalizeImageUrl = function normalizeImageUrl(baseFile, url) {
proto.relativeCurrentUrl = function relativeCurrentUrl(url) {
var self = this;
var normalizeUrl = baseFile || '';
var currentUrl = globalLocation.hash || self.config.homeUrl;
var normalizeUrl = currentUrl || '';

if ((!baseFile && !url) || !isString(baseFile) || (url && !isString(url))) {
if ((!currentUrl && !url) || !isString(currentUrl) || (url && !isString(url))) {
return url || '';
}

Expand All @@ -335,7 +336,7 @@

normalizeUrl = normalizeUrl.replace(/\#/, '').replace(/\/$/, '');
normalizeUrl = normalizeUrl +
(baseFile && '/../' || '') +
(currentUrl && '/../' || '') +
(url || '');
return self.normalizeUrl(normalizeUrl);
};
Expand Down
20 changes: 9 additions & 11 deletions public/doc/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ Get and set handler that add extra initialization to Magicbook.
| options | a options object that includes `priority` property that determines the order of execution. Under normal, the 0 is primary action, the 1 is Magicbooks own, the 2, 3, ... is others. |


### normalizeImageUrl
Normalizing image's url that based on base file.

##### parameters
| name | description |
|----------|------------------|
| baseFile | relative file of image |
| url | url of file |


### normalizeUrl
Normalizing url that will handle baseUrl, urlArgs and other before fetch resource.

Expand All @@ -38,6 +28,15 @@ Parsing content to some format after fetch resource.
| data | content of file |


### relativeCurrentUrl
Solve assigned url to relative path from current url.

##### parameters
| name | description |
|----------|------------------|
| url | url of file |


### render
Rendering content after handle resource.

Expand Down Expand Up @@ -92,4 +91,3 @@ book.route('public/doc/quick-start.md', {

### show
Show the Magicbook.

0 comments on commit a65a493

Please sign in to comment.