| 1 |
"use strict"; |
| 2 |
var URL = require('./URL'); |
| 3 |
var URLUtils = require('./URLUtils'); |
| 4 |
|
| 5 |
module.exports = Location; |
| 6 |
|
| 7 |
function Location(window, href) { |
| 8 |
this._window = window; |
| 9 |
this._href = href; |
| 10 |
} |
| 11 |
|
| 12 |
Location.prototype = Object.create(URLUtils.prototype, { |
| 13 |
constructor: { value: Location }, |
| 14 |
|
| 15 |
|
| 16 |
href: { |
| 17 |
get: function() { return this._href; }, |
| 18 |
set: function(v) { this.assign(v); } |
| 19 |
}, |
| 20 |
|
| 21 |
assign: { value: function(url) { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
var current = new URL(this._href); |
| 29 |
var newurl = current.resolve(url); |
| 30 |
|
| 31 |
|
| 32 |
this._href = newurl; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
}}, |
| 39 |
|
| 40 |
replace: { value: function(url) { |
| 41 |
|
| 42 |
|
| 43 |
this.assign(url); |
| 44 |
}}, |
| 45 |
|
| 46 |
reload: { value: function() { |
| 47 |
|
| 48 |
|
| 49 |
this.assign(this.href); |
| 50 |
}}, |
| 51 |
|
| 52 |
toString: { value: function() { |
| 53 |
return this.href; |
| 54 |
}} |
| 55 |
|
| 56 |
}); |