@ajces/router
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ajces/utils"),require("@ajces/idiom")):"function"==typeof define&&define.amd?define(["exports","@ajces/utils","@ajces/idiom"],t):t(e.Router={},e._ajces_utils,e._ajces_idiom)}(this,function(e,t,n){"use strict";function r(e){function n(e){document.title=e.title;var t=[].filter.call(document.getElementsByTagName("meta"),function(e){return""!==e.name&&"origin"!==e.name&&"referrer"!==e.name&&"viewport"!==e.name}),n=Object.keys(e).filter(function(e){}),r=[];n.forEach(function(n){var o=t.filter(function(e){e.name})[0];if(void 0===o){var i=document.createElement("meta");i.setAttribute("name",n),i.setAttribute("content",e[n]),document.head.appendChild(i)}else o.setAttribute("content",e[n]);r.push(n)}),n.forEach(function(e){if(-1===r.indexOf(e)){var n=t.filter(function(e){e.name})[0];document.head.removeChild(n)}})}function r(t,n){for(var r,o,i,a={},u=0;u<n.length&&!r;u++){var c=n[u].path,f=[];t.replace(RegExp("*"===c?".*":"^"+c.replace(/\//g,"\\/").replace(/:([\w]+)/g,function(e,t){return f.push(t),"([-\\.%\\w\\(\\)]+)"})+"/?$","g"),function(){for(var t=1;t<arguments.length-2;){var s=arguments[t++];try{s=decodeURI(s)}catch(e){}a[f.shift()]=s}r=c,i=u,o=Object.assign({},e,n[u].meta)})}return{meta:o,match:r,index:i,params:a}}return null==e&&(e={}),function(e){return{state:{router:{}},actions:{router:{set:function(e,r,o){return null!=o.meta&&(t.isServer()?window.meta=meta:n(o.meta)),{router:o}},go:function(e,t,n){location.pathname+location.search!==n&&(history.pushState({},"",n),t.router.set({path:n}))}}},events:{load:function(e,t){addEventListener("popstate",function(){t.router.set({})})},render:function(t,n,o){return o[(t.router.index>=0?t:n.router.set(e("route",r(location.pathname,o)))).router.index].view}}}}}function o(e,t){return e.href=e.to,e.to=null,e.onclick=function(t){0!==t.button||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||"_blank"===e.target||t.target.origin!==window.location.origin||(t.preventDefault(),e.go(e.href))},n.h("a",e,t)}e.Router=r,e.Link=o}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ajces/idiom")):"function"==typeof define&&define.amd?define(["exports","@ajces/idiom"],t):t(e.Router={},e._ajces_idiom)}(this,function(e,t){"use strict";function n(e){function t(e){if(null==document.getElementsByTagName)window.meta=e;else{document.title=e.title;var t=[].filter.call(document.getElementsByTagName("meta"),function(e){return""!==e.name&&"origin"!==e.name&&"referrer"!==e.name&&"viewport"!==e.name}),n=Object.keys(e).filter(function(e){}),r=[];n.forEach(function(n){var o=t.filter(function(e){e.name})[0];if(void 0===o){var i=document.createElement("meta");i.setAttribute("name",n),i.setAttribute("content",e[n]),document.head.appendChild(i)}else o.setAttribute("content",e[n]);r.push(n)}),n.forEach(function(e){if(-1===r.indexOf(e)){var n=t.filter(function(e){e.name})[0];document.head.removeChild(n)}})}}function n(t,n){for(var r,o,i,a={},u=0;u<n.length&&!r;u++){var c=n[u].path,f=[];t.replace(RegExp("*"===c?".*":"^"+c.replace(/\//g,"\\/").replace(/:([\w]+)/g,function(e,t){return f.push(t),"([-\\.%\\w\\(\\)]+)"})+"/?$","g"),function(){for(var t=1;t<arguments.length-2;){var l=arguments[t++];try{l=decodeURI(l)}catch(e){}a[f.shift()]=l}r=c,i=u,o=Object.assign({},e,n[u].meta)})}return{meta:o,match:r,index:i,params:a}}return null==e&&(e={}),function(e){return{state:{router:{}},actions:{router:{set:function(e,n,r){return null!=r.meta&&t(r.meta),{router:r}},go:function(e,t,n){location.pathname+location.search!==n&&(history.pushState({},"",n),t.router.set({path:n}))}}},events:{load:function(e,t){addEventListener("popstate",function(){t.router.set({})})},render:function(t,r,o){return o[(t.router.index>=0?t:r.router.set(e("route",n(location.pathname,o)))).router.index].view}}}}}function r(e,n){return e.href=e.to,e.to=null,e.onclick=function(t){0!==t.button||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||"_blank"===e.target||t.target.origin!==window.location.origin||(t.preventDefault(),e.go(e.href))},t.h("a",e,n)}e.Router=n,e.Link=r}); | ||
//# sourceMappingURL=router.js.map |
{ | ||
"name": "@ajces/router", | ||
"description": "Utilities for routing client-side pages with Hyperapp/Idiom.", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/router.js", | ||
@@ -50,8 +50,4 @@ "jsnext:main": "src/index.js", | ||
"peerDependencies": { | ||
"@ajces/utils": "^1.0.0", | ||
"@ajces/idiom": "^1.0.1" | ||
}, | ||
"dependencies": { | ||
"@ajces/utils": "^1.0.0" | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
import { isServer } from "@ajces/utils"; | ||
export function Router(defaultMeta) { | ||
@@ -17,7 +15,3 @@ if (defaultMeta == null) { | ||
if (data.meta != null) { | ||
if ( !isServer()) { | ||
updateMeta(data.meta); | ||
} else { | ||
window.meta = meta; | ||
} | ||
updateMeta(data.meta); | ||
} | ||
@@ -57,41 +51,45 @@ return { | ||
function updateMeta(meta) { | ||
document.title = meta.title; | ||
var dynamicMeta = [].filter.call( | ||
document.getElementsByTagName("meta"), | ||
function(el) { | ||
if ( | ||
el.name === "" || | ||
el.name === "origin" || | ||
el.name === "referrer" || | ||
el.name === "viewport" | ||
) { | ||
return false; | ||
if (document.getElementsByTagName == null) { | ||
window.meta = meta; // hack work around for SSR... | ||
} else { | ||
document.title = meta.title; | ||
var dynamicMeta = [].filter.call( | ||
document.getElementsByTagName("meta"), | ||
function(el) { | ||
if ( | ||
el.name === "" || | ||
el.name === "origin" || | ||
el.name === "referrer" || | ||
el.name === "viewport" | ||
) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
); | ||
var keys = Object.keys(meta).filter(function(k) { k !== "title" }); | ||
var handled = []; | ||
keys.forEach(function(k) { | ||
var metaEl = dynamicMeta.filter(function (el) { el.name === k })[0]; | ||
if (metaEl === undefined) { | ||
// add missing meta element to head | ||
var newMeta = document.createElement("meta"); | ||
newMeta.setAttribute("name", k); | ||
newMeta.setAttribute("content", meta[k]); | ||
document.head.appendChild(newMeta); | ||
} else { | ||
return true; | ||
// update existing meta element | ||
metaEl.setAttribute("content", meta[k]); | ||
} | ||
} | ||
); | ||
var keys = Object.keys(meta).filter(function(k) { k !== "title" }); | ||
var handled = []; | ||
keys.forEach(function(k) { | ||
var metaEl = dynamicMeta.filter(function (el) { el.name === k })[0]; | ||
if (metaEl === undefined) { | ||
// add missing meta element to head | ||
var newMeta = document.createElement("meta"); | ||
newMeta.setAttribute("name", k); | ||
newMeta.setAttribute("content", meta[k]); | ||
document.head.appendChild(newMeta); | ||
} else { | ||
// update existing meta element | ||
metaEl.setAttribute("content", meta[k]); | ||
} | ||
handled.push(k); | ||
}); | ||
keys.forEach(function(k) { | ||
if (handled.indexOf(k) === -1) { | ||
// remove meta from document | ||
var metaEl = dynamicMeta.filter(function (el) { el.name === k })[0]; | ||
document.head.removeChild(metaEl); | ||
} | ||
}); | ||
handled.push(k); | ||
}); | ||
keys.forEach(function(k) { | ||
if (handled.indexOf(k) === -1) { | ||
// remove meta from document | ||
var metaEl = dynamicMeta.filter(function (el) { el.name === k })[0]; | ||
document.head.removeChild(metaEl); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -98,0 +96,0 @@ |
Sorry, the diff of this file is not supported yet
1
14504
163
- Removed@ajces/utils@^1.0.0
- Removed@ajces/utils@1.0.5(transitive)