@zambezi/address
Advanced tools
Comparing version 2.0.0 to 2.1.0-real-urls.0
@@ -60,14 +60,14 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
address: __webpack_require__(1) | ||
, created: __webpack_require__(22) | ||
, created: __webpack_require__(21) | ||
, error: __webpack_require__(16) | ||
, httpStatusCode: __webpack_require__(6) | ||
, interpolate: __webpack_require__(9) | ||
, into: __webpack_require__(23) | ||
, into: __webpack_require__(22) | ||
, location: __webpack_require__(19) | ||
, middleware: __webpack_require__(24) | ||
, ok: __webpack_require__(25) | ||
, redirect: __webpack_require__(26) | ||
, response: __webpack_require__(27) | ||
, serialize: __webpack_require__(28) | ||
, stream: __webpack_require__(29) | ||
, middleware: __webpack_require__(23) | ||
, ok: __webpack_require__(24) | ||
, redirect: __webpack_require__(25) | ||
, response: __webpack_require__(26) | ||
, serialize: __webpack_require__(27) | ||
, stream: __webpack_require__(28) | ||
} | ||
@@ -98,2 +98,3 @@ }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
, rebind = __webpack_require__(18) | ||
, location = __webpack_require__(19) | ||
@@ -104,3 +105,2 @@ function address(r) { | ||
, web | ||
, location | ||
, method = "get" | ||
@@ -150,3 +150,2 @@ , headers = { accept : "application/x.nap.view" } | ||
web = w | ||
location = __webpack_require__(19)(web, address) | ||
return api | ||
@@ -770,135 +769,138 @@ } | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var location = __webpack_require__(20) | ||
, state = location.state() | ||
, findClosest = __webpack_require__(5) | ||
var findClosest = __webpack_require__(5) | ||
, rebind = __webpack_require__(18) | ||
, dispatch = __webpack_require__(17).dispatch | ||
, dispatcher = dispatch('statechange') | ||
, on = __webpack_require__(21) | ||
, ignoreFlag = false | ||
, dispatcher = __webpack_require__(17).dispatch('statechange') | ||
, history = window.history | ||
, location = window.location | ||
, on = __webpack_require__(20) | ||
, base = '' | ||
location.on('statechange.location', handleStateChange) | ||
on.call(window, 'popstate.location', handleStateChange) | ||
on.call(document, 'click.location', handleClick) | ||
function handleStateChange() { | ||
if(ignore()) return ignore(false) | ||
setState(location.state()) | ||
ignore(false) | ||
if (~location.hash.indexOf('#/')) { | ||
// Redirect current hash fragment location to "real" path | ||
var path = location.hash.slice(1) | ||
history.replaceState(null, null, rebase(path)) | ||
} | ||
function ignore(value) { | ||
if(!arguments.length) return ignoreFlag | ||
ignoreFlag = value | ||
} | ||
var api = | ||
{ getState: getState | ||
, setState: setState | ||
, pushState: pushState | ||
, openNewWindow: openNewWindow | ||
, basePath: basePath | ||
} | ||
function pushState(value) { | ||
if(isCurrentState(value)) return | ||
ignore(true) | ||
currentState(value) | ||
location.state(value) | ||
return true | ||
} | ||
return rebind(api, dispatcher, 'on') | ||
function setState(value) { | ||
var pushed = pushState(value) | ||
if (pushed) dispatcher.statechange(value) | ||
} | ||
function getState() { | ||
var path = location.href.replace(location.origin, '') | ||
function currentState(value) { | ||
if(!arguments.length) return state | ||
state = value | ||
if (path.slice(0, base.length) === base) { | ||
return path.slice(base.length) | ||
} else { | ||
return path | ||
} | ||
} | ||
function isCurrentState(value) { | ||
return value == currentState() | ||
function setState(path) { | ||
var actual = pushState(path) | ||
if (actual) { | ||
var state = { base: base, path: actual } | ||
dispatcher.statechange(state) | ||
return state | ||
} else { | ||
return false | ||
} | ||
} | ||
return function createComponent(web, address) { | ||
var api = {} | ||
function pushState(path) { | ||
if (~path.indexOf('#/')) { | ||
path = '/' + trimSlashes(path.split('#/').slice(1)).join('/') | ||
} | ||
on.call(document, 'click.location', handleClick) | ||
if (path === getState()) { | ||
return false | ||
} else { | ||
history.pushState({ base: base, path: path }, null, rebase(path)) | ||
return path | ||
} | ||
} | ||
api.getState = function() { return currentState() } | ||
api.setState = setState | ||
api.pushState = pushState | ||
api.openNewWindow = openNewWindow | ||
function openNewWindow(path, target) { | ||
return window.open(rebase(path), target, '') | ||
} | ||
return rebind(api, dispatcher, 'on') | ||
function basePath(path) { | ||
if (arguments.length === 0) return base | ||
base = path? '/' + trimSlashes(path) : '' | ||
} | ||
function openNewWindow(path, target) { | ||
window.open(location.hrefFromPath(path), target, '') | ||
} | ||
function handleClick(event) { | ||
var a | ||
, target = event.target | ||
, path | ||
function handleClick(event) { | ||
var anchor | ||
, target = event.target | ||
, path | ||
if (event.ctrlKey) return // Ignore ctrl+click | ||
if (event.button !== 0) return // Ignore clicks by buttons other than primary (usually left button) | ||
if (event.ctrlKey) return | ||
if (event.button == 1) return | ||
anchor = findClosest.anchor(target) | ||
if (!anchor) return | ||
if (!!anchor.target) return | ||
if (location.shouldIgnoreHref(anchor.href)) return | ||
a = findClosest.anchor(target) | ||
path = location.pathFromHref(anchor.href) | ||
if (!a) return // Ignore non-anchor clicks | ||
if (!!a.target) return // Ignore anchors with specified targets | ||
if (!path) return | ||
if (!web.find(path)) return | ||
if (a.origin !== location.origin) return // Ignore links to different origins | ||
if (a.hash && !~a.hash.indexOf('#/')) return // Ignore links with a non-path hash | ||
var path = rebase(a.hash? a.hash.slice(1) : a.href.slice(a.origin.length)) | ||
if (path) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
var actual = pushState(path) | ||
address(path).origin(target).navigate() | ||
if (actual) { | ||
var state = { base: base, path: actual, target: a } | ||
dispatcher.statechange(state) | ||
} | ||
} | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 20 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var on = __webpack_require__(21) | ||
, rebind = __webpack_require__(18) | ||
, dispatch = __webpack_require__(17).dispatch | ||
, dispatcher = dispatch('statechange') | ||
, api = {} | ||
function handleStateChange(event) { | ||
var path = location.href.slice(location.origin.length) | ||
, base = (event.state && event.state.base) || '' | ||
on.call(window, 'hashchange.location-hash', dispatcher.statechange) | ||
if (~path.indexOf('#/')) { | ||
// "Redirect" current location to a proper path | ||
var path = location.hash.slice(1) | ||
api.state = state | ||
api.hrefFromPath = hrefFromPath | ||
api.pathFromHref = pathFromHref | ||
api.shouldIgnoreHref = shouldIgnoreHref | ||
if (path) { | ||
var state = { base: base, path: path } | ||
history.replaceState(state, null, rebase(path)) | ||
} | ||
} else { | ||
var state = { base: base, path: rebase(path).slice(base.length) } | ||
} | ||
return rebind(api, dispatcher, 'on') | ||
function state(value) { | ||
if (!arguments.length) return pathFromHref(loc_href()) | ||
document.location.hash = value | ||
return api | ||
dispatcher.statechange(state) | ||
} | ||
function hrefFromPath(path) { | ||
var hash = '#' + path | ||
return /#/.test(loc_href()) ? loc_href().replace(/#.*/, hash) : loc_href() + hash | ||
} | ||
function rebase(path) { | ||
if (path.slice(0, base.length) === base) { | ||
// Remove base before adding it back in again | ||
// This is a boo-boo case | ||
path = path.slice(base.length) | ||
} | ||
function loc_href() { | ||
return document.location.href | ||
return base + '/' + trimSlashes(path) | ||
} | ||
function pathFromHref(href) { | ||
return href.split('#')[1] ||'' | ||
function trimSlashes(path) { | ||
return (path || '').replace(/^\/+/, '').replace(/\/+$/, '') | ||
} | ||
function shouldIgnoreHref(href) { | ||
return !~href.indexOf('#') | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 21 */ | ||
/* 20 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -955,3 +957,3 @@ | ||
/***/ }, | ||
/* 22 */ | ||
/* 21 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -973,3 +975,3 @@ | ||
/***/ }, | ||
/* 23 */ | ||
/* 22 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -987,3 +989,3 @@ | ||
/***/ }, | ||
/* 24 */ | ||
/* 23 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1028,3 +1030,3 @@ | ||
/***/ }, | ||
/* 25 */ | ||
/* 24 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1040,3 +1042,3 @@ | ||
/***/ }, | ||
/* 26 */ | ||
/* 25 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1057,3 +1059,3 @@ | ||
/***/ }, | ||
/* 27 */ | ||
/* 26 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1072,3 +1074,3 @@ | ||
/***/ }, | ||
/* 28 */ | ||
/* 27 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1089,8 +1091,8 @@ | ||
/***/ }, | ||
/* 29 */ | ||
/* 28 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) { | ||
var dispatch = __webpack_require__(30) | ||
, redispatch = __webpack_require__(31) | ||
var dispatch = __webpack_require__(29) | ||
, redispatch = __webpack_require__(30) | ||
, rebind = __webpack_require__(18) | ||
@@ -1118,3 +1120,3 @@ | ||
/***/ }, | ||
/* 30 */ | ||
/* 29 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1173,3 +1175,3 @@ | ||
/***/ }, | ||
/* 31 */ | ||
/* 30 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1176,0 +1178,0 @@ |
{ | ||
"name": "@zambezi/address", | ||
"version": "2.0.0", | ||
"version": "2.1.0-real-urls.0", | ||
"description": "API for nap resources", | ||
@@ -18,2 +18,3 @@ "main": "lib/address.js", | ||
"sinon": "^1.14.1", | ||
"squirejs": "^0.2.1", | ||
"webpack": "^1.12.2" | ||
@@ -23,2 +24,3 @@ }, | ||
"test": "karma start --single-run", | ||
"test:debug": "karma start --debug", | ||
"prepublish": "npm run build", | ||
@@ -25,0 +27,0 @@ "build": "rimraf lib && webpack" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94998
967
13
2