stear/README.md

193 lines
6.2 KiB
Markdown
Raw Permalink Normal View History

2022-06-07 23:38:46 +02:00
# Stear
2022-06-09 16:21:59 +02:00
## Introduction
2022-08-13 17:52:45 +02:00
A simple Framework. Combine all Content in one File in an Modular way and native JavaScript.
2022-06-07 23:38:46 +02:00
## Getting started
2022-08-13 17:52:45 +02:00
Download the stear Submodule and add it to your Project.
2022-06-09 16:40:56 +02:00
## Features
2022-06-09 16:21:59 +02:00
### Create Stear Instance
```javascript
import { Stear, SWindow } from "./stear/main.js";
var stear = new Stear(document.querySelector("#stear"));
2022-06-07 23:38:46 +02:00
```
2022-06-09 16:21:59 +02:00
### Addind Windows
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
```javascript
2022-08-13 17:52:45 +02:00
stear.addElement("connect", connect);
stear.addElement("start", start);
2022-06-09 16:21:59 +02:00
```
2022-08-13 17:52:45 +02:00
Windows don't necessarily have to be add this Way.
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
An SWindow is an Extendion of the SFrame class. SWindow adds an DIV Element around the page content in Fullscreen.
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
### Calling Windows
```javascript
2022-08-13 17:52:45 +02:00
import start from "./start.js";
2022-06-09 16:21:59 +02:00
stear.call(stear.g("start"), {});
2022-08-13 17:52:45 +02:00
stear.call(start, {});
2022-06-09 16:21:59 +02:00
```
2022-08-13 17:52:45 +02:00
The first Argument must be an SFrame Instance. The secound Argument can be used to pass Data to the new Window.
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
This Methode returns a Promise. When the Promise will be resolved, the return Value can be accessed. The Promise can be awaited.
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
### Creating a Window
```javascript
2022-08-13 17:52:45 +02:00
import { Stear, SWindow, _ } from "../stear/main.js";
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
const call = async (stear, { find, resolve, render, call, event }, args) => {
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
return _({
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
}, [
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
]);
}
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
export default new SWindow({ call, preRender:true, backgroundColor: "#dde" });
2022-06-09 16:21:59 +02:00
```
2022-08-13 17:52:45 +02:00
**preRender**: This is set to true by default. When set to true the content will be rendered imidiatly. Atherwise only when called render().
2022-06-09 16:21:59 +02:00
2022-08-13 17:52:45 +02:00
**call**: When calling a Window this function will be called. The first Argument is the used Stear Instance. The secound Argument contains some StearingTools. The third Argument are the Arguments passt in the call request. This function must return the page Content or function which returns the page content.
2022-06-09 16:21:59 +02:00
### Creating Page Content / class_ class
```javascript
_({
find:"someString",
type:"div",
style:{
color:"#fff",
backgroundColor:"black",
},
2022-08-13 17:52:45 +02:00
event: {
click: ()=>{
}
}
2022-06-09 16:21:59 +02:00
//other Attributes
},[
2022-08-13 17:52:45 +02:00
//pass here other class_ Instances or Strings or Language Sentences
//or functions that generats things like this
2022-06-09 16:21:59 +02:00
])
```
The function _(settings, childs) returns an class\_ Instance.
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
Attributes of the Settings Object while be applyed as HTML-Element Attribute.
2022-08-13 17:52:45 +02:00
Exeptions are find, type, style, event (all can be empty):
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
**type**: The type Attribute determines the DOMElement Type. The Default is div.
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
**find**: The find Attribute is an identifier. With find.someString you can get this Element. With find.someString._ you get the underlying DOMElement.
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
**style**: The content of the style Attribute will be applied as css style.
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
**event**: The content of the style Attribute will be applied with addEventListener.
2022-06-09 16:21:59 +02:00
Other Methodes:
```javascript
var element = _({},[]);
2022-08-13 17:52:45 +02:00
var newRenderedHTMLElement = await element.build(someArgsInArray); //Executs functions to create dynamic Structures
2022-06-09 16:21:59 +02:00
var newRenderedHTMLElement = element.render ;
var HTMLElement = element._ ; //Same as line befor when Element was completly rendered
element.childs = [
//Overrides the secound Argument
];
element.settings = {
//Overrides first Argument (when possible)
}
```
2022-06-07 23:38:46 +02:00
2022-08-13 17:52:45 +02:00
### Intelligent Content / StearingTools
- find: Contains all Elements labeled with find.
- resolve: This function resolves the call, like a regular Promise. The secound Argument determies wheser the SWindow shut be closed.
- close: This will close the SWindow.
- render: This function, will (re-)render the page content (executes every function in Content Tree (again).)
- call: The way to call an other SWindow/SFrame with an appropriate zIndex.
- event: An objects with callback functions, that can be overriden:
- onloaded: Called after initial Content render.
- onresolve: Will be awaited to execute operations on resolve or to delay it, when async.
- onclose: Will be executed on calling close(). It will delay the closing process if async.
- onBeforRerender: This will be executed befor the (re-)render while called render(). When async the render will be delayed.
- onAfterRerender: This will be executed befor the (re-)render while called render(). When async it will delay the resolve of the render() function.
2022-06-09 16:21:59 +02:00
### Globel functions
2022-06-07 23:38:46 +02:00
2022-06-09 16:21:59 +02:00
#### Adding Global CSS the Oldway
```javascript
Stear.addGlobalStyleText(`
.cssClass {
color: #fff;
background-color:black;
}
`);
```
#### Adding Global CSS the with JSON
```javascript
var name = ".cssClass";
name = Stear.addGlobalStyleJSON({
color: "#fff",
backgroundColor: "black",
},name);
```
The Function can add CSS like CSS can be added to Elements in Pages. When leaving name empty a cssClass will be added with a sortof random name.
2022-06-09 16:26:27 +02:00
#### Adding CSS Animations with JSON
2022-06-09 16:21:59 +02:00
```javascript
var KeyframeName = Stear.addAnimation({
"0%":{
transform: "scale(100%)",
},
"50%": {
transform: "scale(110%)",
},
"100%": {
transform: "scale(100%)",
}
}/*,name*/);
2022-06-09 16:40:56 +02:00
```
2022-08-13 17:52:45 +02:00
#### Language
This Tool can be used in MultiLingual Projects.
Default Schema:
```javascript
const pool = Stear.addLanguagePool("poolname");
const sentences1 = pool.add("sentences1", "Some Text"); //id, default Text
const sentences2 = pool.add("sentences2", "Some {} Text with {}.");
sentences1 // Some Text
sentences2 // Some {} Text with {}.
sentences2.r("nice","a good flavour") // Some nice Text with a good flavour.
```
The Language System is a two level System. It is recomendet, to use the Name of the Window as poolname.
The LanguageString can be used like a normal String. The Methode .r() can repalace "{}" in the Text.
When useing Stear.addLanguagePool or pool.add twise the same instance will be returned.
Other Language functions
```javascript
var someJSON = Stear.getLanguageFile;//contains all Defaults created yet.
Stear.lang = "de"; //change Language
2022-10-09 16:36:35 +02:00
Stear.addLanguageFile(fileJSON/*like someJSON*/,lang); //Language code like.
2022-08-13 17:52:45 +02:00
```
2022-06-09 16:40:56 +02:00
### Utils
#### wait
```javascript
await wait(200);
```
Simpel Methode of Timedelay in an async fcuntion
#### fadein
```javascript
await fadein(elems,ms,force);
await fadeout(elems,ms,force);
```
2022-08-13 17:52:45 +02:00
- **elems**: contains Element to Fade in or an Array of Elements
- **ms** Fade time
- **force** If set to true a alredy invisible/visible Element will be refaded out/in.
2022-06-09 16:40:56 +02:00
### Extras
loading1.js: simple to use Loadinganimation