seule v2.1.12
š± Introduction:
š° Seule is a light-weight (19.3KB), blazing fast and feature-rich Javascript Framework. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers š§āā.
š Getting Started
You can create an index.html file and include Seule with:
Installation
npm i seule --save
š¹ At the core of Seule.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
<div id='app'>
{{message}}
</div>
import {Instance} from "seule";
new Instance({
el: '#app',
data: {
message : 'hello Seule'
}
})
ā¶ļø Quick Start
We have already created Hello World Seule app! Click on the "Quick Start" š button to see how it works.
ā©ļø Styling Apps in Seule
Seule uses Shadow DOM, It allows us to ship self contained components along with their style and isolate the component from global style while "protecting" the host application from styles defined inside the component.
Two Ways to Insert CSS
there are two ways of inserting a style sheet:
- Using _Css Method
- Adding Style property (only for components)
_Css Method
To use _Css Method, it should be included from the Model Module.
š¹ for exemple:
<div id='app'></div>
import css from "./assets/css/app.css";
import {Instance} from "seule";
import {_Css} from "seule/model";
new Instance({
el: '#app',
data: {
message : 'hello Seule'
},
async handlers($app){
_Css(css, $app);
}
})
To use _Css Method, it should be included from the Model Module.
Adding Style property
š¹ you can add css to your application just by passing it into the style property.
import css from "./assets/css/app.css";
import {Instance} from "seule";
const app = new Seule({
el: '#app',
style: css,
data:{
message: "Hello World"
}
})
ā©ļø Bind element attributes
In addition to text interpolation, we can also bind element attributes like this:
ć½ļø Syntax:
<element data-attribute="[attribute: <String>]:[variable: <String>]"></element>
š¹ for exemple:
<div id='app'>
<p data-attribute="title:message"> Hover your mouse over me <br> for a few seconds </p>
</div>
import {Instance} from "seule";
new Instance({
el: '#app',
data: {
message : 'You visited this page on ' + new Date().toLocaleString()
}
})
ā©ļø Handling User Input
Magic Happens here by invoking Methods inside the handlers(), using one parameter $app and let users interact with your app
š¹ for exemple:
<div id='app'>
<p>{{message}}</p>
<button>click-me</button>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
new Instance({
el: '#app',
data:{message: "Hello my Friend"},
async handlers($app){
const scope = Scope($app);
scope.Native(e=>{
const btn = e.querySelector("button");
btn.addEventListener("click", ()=>
$app.data.message = $app.data.message.split('').reverse().join(''));
});
}
});
ā©ļø Selectors
For more security, Seule uses Shadow DOM. The problem in that, is you can't get access to the DOM element(s) directly unless you use Css selectors inside the handlers() by invoking the Scoop Method.
Scope Method can accept one argument.
Scope Method has a function call Select returns all elements in the Seule app that matches a specified CSS selector(s), as a static Seule Object.
ć½ļø Syntax
Scope([Seule_component])
ć½ļø Select Function Syntax
Scope([Seule_component]).Select([CSS_selectors])
Parameter --> CSS selectors
Type --> String
Tip: For a list of all CSS Selectors, look at w3schools !CSS Selectors Reference
Example
š¹ You can select all <p> elements on app like this:
Scope($app).Select("p")
When a user clicks on a button, all <p> elements will be hidden:
<div id='app'>
<p>{{message}} 1</p>
<p>{{message}} 2</p>
<p>{{message}} 3</p>
<button title="{{title}}">Hide All!</button>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Effects} from "seule/effects";
import {Events} from "seule/events";
new Instance({
el: '#app',
data:{message: "Hello my Friend"},
modules:{Effects, Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button"),
p = scope.Select("p");
btn.Click(()=> p.Hide());
}
});
ā©ļø Events
What is an Event?
An event represents the precise moment when something happens. Examples:
- moving a mouse over an element
- selecting a radio button
- clicking on an element
for mor details about !Event reference
Before using Events in Seule, we have to import the Events method from the events module and call it into the main component Single.
Example
import {Instance} from "seule";
import {Events} from "seule/events";
new Instance({
el: '#app',
modules:{Events}
});
š° On()
using the On Method to assign an event to an element.
ć½ļø Syntax
Select([CSS selectors]).On([event:<String>], [handler:<Function>])
Example
š¹ for exemple To assign a click event to all button on a Seule app, you can do this:
<div id='app'>
<img src="https://bit.ly/3mA0FbG" width="150">
<button>Change the picture</button>
<p>{{message}}</p>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
new Instance({
el: '#app',
data:{
message: "Click the button to see what happens!",
source: "https://bit.ly/3mA0FbG"
},
modules:{Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button");
btn.On("click",()=> $app.data.source = "https://bit.ly/3Jb61VN"); }
});
ā©ļø Special Events
š° Click()
The function is executed when the user clicks on the HTML element.
š¹ For example When a click event fires on an element show an alert box.
Select("button")
.Click(()=> alert('just a simple click'))
š° Hold()
The function is executed when the user make a long presse on the HTML element.
ć½ļø Syntax
Select([CSS selectors]).Hold([handler:<Function>], [time:<Integer>])
the time by default is 1500 => 1.5s
Example
š¹ Show an alert box When user make a long presse on button for 3s.
<div id='app'>
<button>Hold Me for 3s</button>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
new Instance({
el: '#app',
data:{
message: "Click the button to see what happens!",
source: "https://bit.ly/3mA0FbG"
},
modules:{Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button");
btn.Hold(()=> alert('Good Job!ā¢ š¤©'), 1000);
}
});
š° Swipe()
Detecting a swipe (left, right, top or down) When a swipe event fires on an element.
ć½ļø Syntax
Select([CSS selectors]).Swipe([event:<String>], [handler:<Function>])
Events
- left
- right
- top
- bottom
Example
š¹ Change the background When user swipe left š¤ on screen
<div id='app'>
<p data-attribute="title:tooltip">{{message}}</p>
</div>
import {Instance} from "seule";
import {Hoisting} from "seule/selectors";
import {Events} from "seule/events";
import {Effects} from "seule/effects";
new Instance({
el: '#app',
data:{
message: "Swipe left to see what happens!",
tooltip : "See this demo on Mobile"
},
modules:{Events, Effects},
async handlers($app){
const body = Hoisting("body");
body.Swipe("left", e=> e
.Css('background')
.set = '#fed000');
}
});
š° Focus()
The focus event occurs when an element gets focus (when selected by a mouse click or by "tab-navigating" to it).
The Focus() method triggers the focus event, or attaches a function to run when a focus event occurs.
ć½ļø Syntax
Trigger the focus event for selected elements:
Select([CSS selectors]).Focus()
Attach a function to the focus event:
Select([CSS selectors]).Focus([handler:<Function>])
Example
š¹ Attach a function to the focus event. The focus event occurs when the <input> field gets focus:
<div id='app'>
<input placeholder="Focus on me!" type="text">
<p>{{message}}</p>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
import {HtmlMethods} from "seule/htmlMethods";
new Instance({
el: '#app',
data: {
message: "Click in the input field to see what happens!"
},
modules:{Events, HtmlMethods},
async handlers($app){
const
scope = Scope($app),
input = scope.Select("input");
input
.Focus(e =>
e.Val().set = "Great work keep it up!");
}
})
š° Blur()
The blur event occurs when an element loses focus.
The Blur() method triggers the blur event, or attaches a function to run when a blur event occurs.
ć½ļø Syntax
Trigger the blur event for the selected elements:
Select([CSS selectors]).Blur()
Attach a function to the focus event:
Select([CSS selectors]).Blur([handler:<Function>])
Example
š¹ Attach a function to the blur event. The blur event occurs when the <input> field loses focus:
<div id='app'>
<input placeholder="Write something!" type="text">
<p>{{message}}</p>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
import {HtmlMethods} from "seule/htmlMethods";
new Instance({
el: '#app',
data: {
message: "Click outside the field to lose focus (blur)."
},
modules:{Events, HtmlMethods},
async handlers($app){
const
scope = Scope($app),
input = scope.Select("input"),
p = scope.Select("p");
input
.Blur(() =>
p.Text().set = "This input field has lost its focus!");
}
});
ā©ļø Handling keyboard Events
š° HotKey()
With HotKey Method in Seule you can now handling keyboard shortcuts easly.
ć½ļø Syntax
Select([CSS selectors]).Hotkey([keys:<String>], [handler:<Function>], [prevent:<Boolean>]);
SUPPORTED KEYS:
For modifier keys you can use shift, ctrl, alt or meta
You can substitute option for alt and command for meta
Other special keys are backspace, tab, enter, return, capslock, esc, escape, space, pageup, pagedown, end, home, left, up, right, down, ins, del, and plus
Any other key you should be able to reference by name like a, /, $, *, or =.
Examples
š¹ Hotkey event with Single key:
Select('input').HotKey('m',
()=> alert('M button is pressed on the Keyboard!'));
š¹ Combination of keys:
Select('input').HotKey('ctrl s',
()=> alert('You pressed ctrl+s!'));
š¹ Sequence of keys like Konami Style (:
Select('input').HotKey('Left Right Left Right A C',
()=> alert('Now you can play with Orochi Iori'));
š¹ Or you can specify keyboard events that will work anywhere including inside textarea/input fields like:
import {Instance} from "seule";
import {Hoisting} from "seule/selectors";
import {Events} from "seule/events"
new Instance({
el: '#app',
data: {
message: "Click outside the field to lose focus (blur)."
},
modules:{Events},
async handlers(){
const
wn = Hoisting("body");
wn.HotKey('ctrl r',
()=> alert('Global keyboard shortcuts'));
// if you want prevent the default refresh event under WINDOWS system
wn.HotKey('ctrl r',
()=> alert('Global keyboard shortcuts'), true);
}
});
ā©ļø More with Events
There are so many things helpful in Seule like :
š° Fire()
Do you want to simulate event with a single statement? Then you may use Fire Method for that:
ć½ļø Syntax
Select([CSS selectors]).Fire([event:<String>]);
Examples
Simulate a mouse-click when moving the mouse pointer over a button:
<div id='app'>
<button onclick="alert('Clicked !')">Hover Me !</button>
</div>
import {Instance} from "./seule";
import {Scope} from "./seule/selectors";
import {Events} from "./seule/events";
new Instance({
el: '#app',
modules:{Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button");
btn.On('mouseover', e=> e.Fire("click"))
}
});
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago