Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
export const isMobile = (() => /Mobi/.test(navigator.userAgent))() | ||
|
||
export const setCookie = (cname, cvalue, exdays = 365) => { | ||
const d = new Date() | ||
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)) | ||
const expires = `expires=${d.toUTCString()}` | ||
document.cookie = `${cname}=${cvalue};${expires};path=/` | ||
} | ||
|
||
export const getCookie = (cname) => { | ||
const name = `${cname}=` | ||
const decodedCookie = decodeURIComponent(document.cookie) | ||
const ca = decodedCookie.split(';') | ||
for (let i = 0; i < ca.length; i++) { | ||
let c = ca[i] | ||
while (c.charAt(0) === ' ') c = c.substring(1) | ||
if (c.indexOf(name) === 0) return c.substring(name.length, c.length) | ||
} | ||
return '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
import DOM from '../../src' | ||
import { isObjectLike, exec } from '../../src/utils' | ||
import { classList } from '../../src/element/mixins' | ||
|
||
import { css } from 'emotion' | ||
|
||
const style = (params, element, node) => { | ||
if (params) { | ||
if (isObjectLike(element.class)) element.class.style = params | ||
else element.class = { style: params } | ||
} | ||
classf(element.class, element, node) | ||
} | ||
|
||
const classf = (params, element, node) => { | ||
if (isObjectLike(params)) { | ||
const classObjHelper = {} | ||
for (const key in params) { | ||
const prop = exec(params[key], element) | ||
const CSSed = css(prop) | ||
classObjHelper[key] = CSSed | ||
} | ||
classList(classObjHelper, element, node) | ||
} | ||
} | ||
|
||
DOM.define({ | ||
style, | ||
class: classf | ||
}, { | ||
overwrite: true | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
import { Link } from '@rackai/symbols' | ||
import { deepMerge } from '../../src/utils' | ||
import route from './router' | ||
|
||
const RouteLink = { | ||
on: { | ||
click: (event, element, state) => { | ||
const root = element.lookup('app') | ||
const { href } = element.props | ||
const firstThree = href[0] + href[1] + href[2] | ||
if (href && firstThree !== 'htt' && firstThree !== 'ske') { | ||
route(root, href, {}) | ||
event.preventDefault() | ||
} | ||
} | ||
} | ||
} | ||
|
||
deepMerge(Link, RouteLink) | ||
|
||
export default RouteLink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
export const splitRoute = (route = window.location.pathname) => route.slice(1).split('/') | ||
|
||
export default (rootElement, path, state = {}, level = 0, pushState = true) => { | ||
const route = path || window.location.pathname | ||
const routes = splitRoute(route) | ||
|
||
const content = rootElement.routes[`/${routes[level]}`] | ||
|
||
if (content) { | ||
if (pushState) window.history.pushState(state, null, route) | ||
rootElement.set({ proto: content }) | ||
.node.scrollIntoView({ behavior: 'smooth' }) | ||
} | ||
|
||
if (level === 0) rootElement.state.update({ activePage: routes[level] }) | ||
} |