🔱 Introduction
👑 Getting Started
You can create an index.html file and include Seule with:
<script src="https://cdn.jsdelivr.net/gh/ElMehdiLebbar/SeuleJs/seule.0.0.1.dev.js"></script>
<div id='app'>
{{message}}
</div>
const app = new Seule({
el: '#app',
data: {
message : 'hello Seule'
}
})
▶️ Try it Yourself
We have already created our very first Seule app! Click on the "Try it Yourself"
↩️ 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
By Adding Style property in the main Object, there are two ways of inserting a style sheet to Seule Component:
- External
- Internal
External
style property can have like a value the Url of the Style sheet.
Each Seule Application must include a reference to the external style sheet file.
🔹 for exemple:
<div id='app'></div>
const app = new Seule({
el: '#app',
style: './css/mystyle.css',
data:{
message: "Hello It's App number 1"
}
})
Internal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="./css/main.css">
<link rel="stylesheet" href="./css/app.css" about="app-style">
</head>
<body>
<div id='app'>
{{message}}
</div>
</body>
</html>
const app = new Seule({
el: '#app',
style: 'app-style' //Style Sheet ./css/app.css applying for the app in this case,
data:{
message: "Hello World"
}
})
↩️ Bind element attributes
In addition to text interpolation, we can also bind element attributes like this:
〽️ Syntax:
<element attribute="{{[variable: <String>]}}"></element>
🔹 for exemple:
<div id='app'>
<p title="{{message}}"> Hover your mouse over me <br> for a few seconds </p>
</div>
const app = new Seule({
el: '#app',
data: {
message : 'You visited this page on ' + new Date().toLocaleString()
}
})
▶️ Try it Yourself
↩️ Handling User Input
Magic Happens here by invoking Methods inside the handler(), using three parameters: $app, $scoop, $root and let users interact with your app
🔹 for exemple:
<div id='app'>
<p>{{message}}</p>
<button>click-me</button>
</div>
const app = new Seule({
el: '#app',
data: {
message: "Hello my Friend"
},
handler($app, $scoop, $root){
$scoop('button')
.Click(()=> $app.data.message =
$app.data.message.split('').reverse().join(''), true)
}
})
▶️ Try it Yourself
More "Try it Yourself" examples below.
↩️ 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 handler() by invoking the $scoop parameter.
$scoop Selectors method returns all elements in the Seule app that matches a specified CSS selector(s), as a static Seule Object.
〽️ Syntax
$scoop([CSS selectors])
Parameter --> CSS selectors
Type --> String
Tip: For a list of all CSS Selectors, look at w3schools !CSS Selectors Reference
Example
$scoop("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>
const app = new Seule({
el: '#app',
data: {
message: "This is paragraph",
title: "Click me to hide paragraphs"
},
handler($app, $scoop){
$scoop('button')
.Click(()=> $scoop('p').Hide())
}
})
▶️ Try it Yourself
↩️ 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
〽️ Syntax
using the On Method to assign an event to an element.
$scoop([CSS selectors]).On([event:<String>], [handler:<Function>])
Example
<div id='app'>
<img src="https://bit.ly/3mA0FbG" width="150">
<button>Change the picture</button>
<p>{{message}}</p>
</div>
const app = new Seule({
el: '#app',
data: {
message: "Click the button to see what happens!"
},
handler($app, $scoop){
$scoop('button')
.On("click", ()=> $scoop('img')
.Attr('src')
.set('http://bit.ly/3fjVxGC'))
}
})
▶️ Try it Yourself
↩️ Special Events
🔰 Click()
The function is executed when the user clicks on the HTML element.
$scoop("button")
.Click(()=> alert('just a simple click'))
🔰 Hold()
The function is executed when the user make a long presse on the HTML element.
〽️ Syntax
$scoop([CSS selectors]).Hold([handler:<Function>], [time:<Integer>])
the time by default is 1500 => 1.5s
Example
<div id='app'>
<button>Hold Me for 3s</button>
</div>
const app = new Seule({
el: '#app',
handler($app, $scoop){
$scoop('button')
.Hold(()=> alert('Good Job!™ 🤩'), 3000)
}
})
▶️ Try it Yourself
🔰 Swipe()
Detecting a swipe (left, right, top or down) When a swipe event fires on an element.
〽️ Syntax
$scoop([CSS selectors]).Swipe([event:<String>], [handler:<Function>])
Events
- left
- right
- top
- bottom
Example
<div id='app'>
<img src="https://bit.ly/3m7nlzN" width="150" alt="Logo" title="{{tooltip}}">
<p>{{message}}</p>
</div>
const app = new Seule({
el: '#app',
data: {
message: "Swipe left to see what happens!",
tooltip : "See this demo on Mobile"
},
handler($app, $scoop){
$scoop(window)
.Swipe("left", ()=> $scoop('body')
.Css('background')
.set('#666'))
}
})
▶️ Try it Yourself
🔰 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:
$scoop([CSS selectors]).Focus()
Attach a function to the focus event:
$scoop([CSS selectors]).Focus([handler:<Function>])
Example
<div id='app'>
<input placeholder="Focus on me!" type="text">
<p>{{message}}</p>
</div>
const app = new Seule({
el: '#app',
data: {
message: "Click in the input field to see what happens!"
},
handler($app, $scoop){
$scoop('input')
.Focus(e => {
e
.Css("border-bottom-color").set("#8755F2")
.Val("Great work keep it up!").set()
})
}
})
▶️ Try it Yourself
🔰 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:
$scoop([CSS selectors]).Blur()
Attach a function to the focus event:
$scoop([CSS selectors]).Blur([handler:<Function>])
Example
<div id='app'>
<input placeholder="Write something!" type="text">
<p>{{message}}</p>
</div>
const app = new Seule({
el: '#app',
data: {
message: "Click outside the field to lose focus (blur)."
},
handler($app, $scoop){
$scoop('input')
.Blur(()=> $scoop('p')
.Text("This input field has lost its focus!")
.set())
}
})
▶️ Try it Yourself
↩️ Handling keyboard Events
🔰 HotKey()
With HotKey Method in Seule you can now handling keyboard shortcuts easly.
〽️ Syntax
$scoop([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
$scoop('input').HotKey('m',
()=> alert('M button is pressed on the Keyboard!'));
$scoop('input').HotKey('ctrl s',
()=> alert('You pressed ctrl+s!'));
$scoop('input').HotKey('Left Right Left Right A C',
()=> alert('Now you can play with Orochi Iori'));
$scoop(window).HotKey('ctrl+r',
()=> alert('Global keyboard shortcuts'));
// if you want prevent the default refresh event under WINDOWS system
$scoop(window).HotKey('ctrl+r',
()=> alert('Global keyboard shortcuts'), true);
Just One More Example
▶️ Try it Yourself
↩️ 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
$scoop([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>
const app = new Seule({
el: '#app',
handler($app, $scoop){
$scoop('button')
.On('mouseover', e=> e.Fire("click"))
}
});
▶️ Try it Yourself
🔰 Copy()
The Copy() method triggers the specified event(s) and the default behavior of an event (like form submission) for the selected elements.
〽️ Syntax
$scoop([CSS selectors]).Copy([target:<String> | <Object>], [events:<String>]);
Examples
Simulate onmouseout and onmouseover events the mouse pointer (out of/onto) a button:
<div id="app">
<p>{{initMessage}}</p>
<button id="original">Original</button>
<button id="copy">Copy</button>
</div>
const app = new Seule({
el: '#app',
data:{
message : "Woah! That's awesome",
initMessage : "moving the mouse pointer (out of/onto) a button to see what happens!"
},
handler($app, $scoop){
$scoop('#original')
.On("mouseover", e=> {
e.Css("background").set("rgba(0,0,0,1)");
$scoop("p").Text(this.data.message).set()
})
.On("mouseout", e=> {
e.Css("background").set("rgba(0,0,0,0.1)");
$scoop("p").Text(this.data.initMessage).set()
});
$scoop('#copy').Copy("#original", "mouseover : mouseout")
}
});
▶️ Try it Yourself
🔰 Toggle()
The Toggle() method toggles between two custom functions for the selected element(s).
〽️ Syntax
$scoop([CSS selectors]).Toggle([event:<String>], [methods:<Object>]);
Examples
<div id="app">
<p>Click on the square 👇🏻 to see what happens!</p>
<section class="square">{{grimace}}</section>
</div>
const app = new Seule({
el: '#app',
data:{
grimace : "^_^",
},
handler($app, $scoop){
$scoop(".square").Toggle("click",
{
handler(e) {
e
.Css({
"border-radius" : "50%",
background : "red",
duration: 300
}).set()
.Text('*_*').set()
},
callback(e){
e
.Css({
"border-radius" : 0,
background : "#2f2f2f",
duration: 300
}).set()
.Text($app.data.grimace).set()
}
})
}
});
▶️ Try it Yourself
↩️ Traversing Methods
Seule provides a variety of methods that allow us to traverse the App. Traversal methods in Seule help us to select elements in a Seule app randomly as well as in sequential method !
- Select () : Returns all child elements that matches a specified CSS selector(s)
- Each () : Specifies a function to run for each matched element.
- Element () : Returns an element with a specific index number of the selected elements.
- Parent () : Returns the direct parent element of the selected element.
- Child () >>>
- .first() : Returns the first child element of the selected element.
- .last() : Returns the last child element of the selected element.
- .number() : Returns a child element with a specific index number of the selected elements.
- .all() : Returns all direct children of the selected element.
- $() : Returns the root element of the selected element.
Example
<section id="app">
<div class="group">
<p>My name is ElML</p>
<p class="intro">I live in EL Jadida.</p>
<p class="intro">I love EL Jadida.</p>
<p>Dad is my best friend...</p>
</div>
</section>
const app = new Seule({
el: '#app',
handler($app, $scope){
$scope('.group')
.Select('.intro') // returns all descendants <p> with class name equal "intro"
.Element(1) // returns the second element of the selected element.
.Css('background').set('#424cf7')
}
});
▶️ Try it Yourself
🔰 Each()
The Each() method specifies a function to run for each matched element.
〽️ Syntax
$scoop([CSS selectors]).Each([handler:<Function>]);
Example
<div id="app">
<p>Click the button to see what happens!</p>
<ul style="text-align: left">
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
<button title="{{title}}">Click-Me</button>
</div>
const app = new Seule({
el: '#app',
data: {
title: "Add the value of each list item"
},
handler($app, $scope){
$scope('button')
.Click(()=> $scope('li')
.Each(e => {
const item = e.Text().get() + " ";
$scope('.result')
.Text(item).append()
}))
}
});
▶️ Try it Yourself
↩️ Seule Element(s) Manipulation
Seule provides various methods to add, edit or delete element(s) in the Seule App.
🔰 Create()
Create() method creates the HTML element specified by tagName.
〽️ Syntax
$scoop().Create([tagName:<String>]);
Example
<div id="app"></div>
const app = new Seule({
el: '#app',
handler($app, $scope){
const btn = $scope().Create('button')
}
});
<div id="app"></div>
const app = new Seule({
el: '#app',
handler($app, $scope){
const btn = $scope().Create('button');
btn.Text($app.data.text).set();
}
});
🔰 Append()
The Append() method appends a Seule Element as the last child of a Element.
〽️ Syntax
$scoop([CSS selectors]).Append([element:<String> | <Object>]);
Example
<div id="app"></div>
const app = new Seule({
el: '#app',
handler($app, $scope){
const btn = $scope().Create('button');
btn.Text($app.data.text).set();
$scope().Append(btn)
}
});
▶️ Try it Yourself
🔰 Move()
- .before() : method inserts or moves a element as a child, right before an existing child, which you specify.
- .after() : method inserts or moves a element as a child, right after an existing child, which you specify.
〽️ Syntax
$scoop([CSS selectors]).Move().method([element:<String> | <Object>]);
Example
<div id="app">
<button title="Add Water Please!">Click-Me</button>
<ul>
<li>Tea</li>
<li>Coffee</li>
</ul>
</div>
const app = new Seule({
el: '#app',
data:{text: "Water"},
handler($app, $scope){
const
btn = $scope().Create('li'),
Coffee = $scope('li').Element(1);
btn.Text($app.data.text).set();
$scope('button').Click(()=> btn.Move().before(Coffee))
}
});