jenie
v1.9.2
Published
A mighty tinny web components framework/library
Maintainers
Readme
Jenie
A mighty tinny web components framework/library.
Name Change From Jenie To Oxe
Pleas see Oxe for future development https://www.npmjs.com/package/oxe
Features
- Really Small 8.09KB gzipped and 27.08KB uncompressed
- In browser ES6/ESM module and template strings support
Support
- IE10~
- IE11
- Chrome
- Firefox
- Safari 7
- Mobile Safari
- Chrome Android
Note
Loader uses XHR and new Function to load on-demand and execute modules. If your worried about security please read the linked articles. In summary the articles support not using new Function/eval to process client input. So as long as your only importing local modules (Loader enforces this) then the safety concern is eliminated.
Resources:
- http://2ality.com/2014/01/eval.html
- https://www.nczonline.net/blog/2013/06/25/eval-isnt-evil-just-misunderstood/
Install
npm install jenie --save- UMD
dist/jenie.min.js - UMD with Web Component Pollyfill
dist/jenie.polly.min.js - Web Component Pollyfill
dist/webcomponents-lite.min.js
Example
Jenie.component.define({
name: 'v-home',
html: `
<h1 j-text="title"></h1>
`,
model: {
title: 'Old Title'
},
created: function () {
this.model.title = 'New Title';
}
});Jenie.setup({
http: {
request: function (opt, xhr) {
return true; // false will cancel the http.fetch
},
response: function (opt, xhr) {
return true; // false will cancel the http.fetch handlers
}
},
loader: {
esm: true, // Enables ES6 module re-writes support
est: true, // Enables ES6 template string re-writes support
loads: [
{
url: '/components/c-menu.js',
execute: true // Since this component is not a module/route or imported we must execute.
}
]
},
router: {
routes: [
{
path: '/',
title: 'Home',
component: 'v-home',
url: 'views/v-home.js'
}
]
}
});<html>
<head>
<base href="/">
<script src="jenie.min.js" defer></script>
<script src="index.js" defer></script>
</head>
<body>
<c-menu>
<ul>
<li><a href="/home">Home</a></li>
</ul>
</c-menu>
<j-view></j-view>
</body>
</html>API
Jenie.setup(options)
The recommend entry point. This allows you to setup Jenie and automatically starts the router
options: Objecthttp: ObjectJenie.http options.loader: ObjectJenie.loader options.router: ObjectJenie.router options.
Jenie.component
define: FunctionDefines a custom web componentoptions: Objectname: StringRequired the tag namehtml: StringAn HTML stringquery: StringAn querySelectortemplate: ElementA Elementmodel: Object<Any>See Jenie.controller.modelevents: Object<Function>See Jenie.controller.eventsmodifiers: Object<Function>See Jenie.controller.modifierscreated: FunctionTriggered once on creationattached: FunctionTriggered on each DOM attachmentdetached: FunctionTriggered on each DOM detachmentattributed: FunctionTriggered attribute change
Jenie.router
options: Objecthash: BooleanHash URL mode. Default is false.trailing: BooleanTrailing slash. Default is false.external: String, RegExp, FunctionFilters URL requests. If true or match Router will not handle request.container: ElementSets the event listeners for HREFs to the container. Default is window. Jenie use event delegationroutes: Arrayroute: Objectpath: StringAny path.parameters: StringNamed '/account/{user}', or catchalls '{*}'
title: StringThe title for the pagecomponent: StringThe name of a componenturl: Object, StringURL path to JS web-component or a Jenie.loader.load Object
run: FunctionMust be called after is createdredirect: FunctionUses window.location.href which is treated like a 301 redirect for SEOadd: Functionpath: String
remove: Functionpath: String
get: Functionpath: StringExact path matching, route path variables are not taken into account
find: FunctionApproximate path matching, route path variables are taken into accountpath: String
navigate: FunctionChanges to a new pagepath: StringPath to navigate
on: EventEmitternavigated: Event
Jenie.loader
ES6 import and export module support. Imports must be absolute from the domain. Also export default is the only export format supported. Please do not use Loader.interpret to handle user input.
options: Objectesm: BooleanEnables ES6 module re-writesest: BooleanEnables ES6 template string re-writesloads: Array<Object, String>Adds load objects or strings such as non route componentsload: Object, Stringurl: StringPath to a web component JS urlexecute: BooleanEnable this to load and define/register custom componentsesm: BooleanEnables ES6 module re-writes on an individual basesest: BooleanEnables ES6 template string re-writes on an individual bases
Jenie.http
options: Objectrequest: FunctionIntercepts the request. If the return value is false the fetch will not be triggeredoptions: Objectxhr: Object
response: FunctionIntercepts the request. If the return value is false the fetch success and error will not be triggeredoptions: Objectxhr: Object
mime: Objectserialize: Functionfetch: FunctionA fetch request.options: Objecturl: StringResource action url Requiredsuccess: FunctionRequired The fetch responseerror: FunctionRequired The fetch responsemethod: StringValid methods get, post, put, deletedata: ObjectIf method isGETthan data is concatenated to theaction/urlas parametersrequestType: StringConverts the request data before sending.script'text/javascript, application/javascript, application/x-javascript'json'application/json' stringifyoptions.dataxml'application/xml, text/xml'html'text/html'text'text/plain'- DEFAULT 'application/x-www-form-urlencoded' serialized
options.data
responseType: StringConverts the response data after sending.script'text/javascript, application/javascript, application/x-javascript'json'application/json'xml'application/xml, text/xml'html'text/html'text'text/plain'
contentType: StringShort hand to set the Content-Type Headers. (For request)accept: StringShort hand to set the Accept Headers. (For response)mimeType: StringOverwrites return type.username: Stringpassword: StringwithCredentials: Booleanheaders: ObjectA low level headers object it will map directly to the XHR header. The Will overwrite any above options.
Jenie.global
A global object for you.
Jenie.query(String: querySelector)
The result of a querySelector in the current document document.currentScript.ownerDocument.querySelector()
- Returns:
document.currentScript.ownerDocument.querySelector()
Jenie.script()
- Returns:
document.currentScript
Jenie.document()
- Returns:
document.currentScript.ownerDocument
Authors
Alexander Elias - AlexanderElias
License
This project is licensed under the MPL-2.0 License
