source: imaps-frontend/node_modules/relateurl/lib/relate/absolutize.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[79a0317]1"use strict";
2
3var findRelation = require("./findRelation");
4var objUtils = require("../util/object");
5var pathUtils = require("../util/path");
6
7
8
9function absolutize(urlObj, siteUrlObj, options)
10{
11 findRelation.upToPath(urlObj, siteUrlObj, options);
12
13 // Fill in relative URLs
14 if (urlObj.extra.relation.minimumScheme) urlObj.scheme = siteUrlObj.scheme;
15 if (urlObj.extra.relation.minimumAuth) urlObj.auth = siteUrlObj.auth;
16 if (urlObj.extra.relation.minimumHost) urlObj.host = objUtils.clone(siteUrlObj.host);
17 if (urlObj.extra.relation.minimumPort) copyPort(urlObj, siteUrlObj);
18 if (urlObj.extra.relation.minimumScheme) copyPath(urlObj, siteUrlObj);
19
20 // Check remaining relativeness now that path has been copied and/or resolved
21 findRelation.pathOn(urlObj, siteUrlObj, options);
22
23 // Fill in relative URLs
24 if (urlObj.extra.relation.minimumResource) copyResource(urlObj, siteUrlObj);
25 if (urlObj.extra.relation.minimumQuery) urlObj.query = objUtils.clone(siteUrlObj.query);
26 if (urlObj.extra.relation.minimumHash) urlObj.hash = siteUrlObj.hash;
27}
28
29
30
31/*
32 Get an absolute path that's relative to site url.
33*/
34function copyPath(urlObj, siteUrlObj)
35{
36 if (urlObj.extra.relation.maximumHost || !urlObj.extra.hrefInfo.minimumResourceOnly)
37 {
38 var pathArray = urlObj.path.absolute.array;
39 var pathString = "/";
40
41 // If not erroneous URL
42 if (pathArray)
43 {
44 // If is relative path
45 if (urlObj.extra.hrefInfo.minimumPathOnly && urlObj.path.absolute.string.indexOf("/")!==0)
46 {
47 // Append path to site path
48 pathArray = siteUrlObj.path.absolute.array.concat(pathArray);
49 }
50
51 pathArray = pathUtils.resolveDotSegments(pathArray);
52 pathString += pathUtils.join(pathArray);
53 }
54 else
55 {
56 pathArray = [];
57 }
58
59 urlObj.path.absolute.array = pathArray;
60 urlObj.path.absolute.string = pathString;
61 }
62 else
63 {
64 // Resource-, query- or hash-only or empty
65 urlObj.path = objUtils.clone(siteUrlObj.path);
66 }
67}
68
69
70
71function copyPort(urlObj, siteUrlObj)
72{
73 urlObj.port = siteUrlObj.port;
74
75 urlObj.extra.portIsDefault = siteUrlObj.extra.portIsDefault;
76}
77
78
79
80function copyResource(urlObj, siteUrlObj)
81{
82 urlObj.resource = siteUrlObj.resource;
83
84 urlObj.extra.resourceIsIndex = siteUrlObj.extra.resourceIsIndex;
85}
86
87
88
89module.exports = absolutize;
Note: See TracBrowser for help on using the repository browser.