One.js covers the below functionalities in a single file.
- Single page maker
- Todoist like datetime picker
- Multiple selector with image option and multiple values.
By using this library we can easily make our html application into single page application. Here is the list of things used in this functionality.
- onepage - Used to identify the application when to use the function. if the data is empty then use the default tag .
- onecontainer - Used to inform the function where to load the page content. Function set as default .
- opt - Used to opt out from the functionality in a particular tag. Page will reloaded in that case. Default set as false.
- button - Used to exclude the ajax button. Function will not executed if its true. Has default as false.
- menu - Used to make a particular menu active. It will add active class to the menu selector.
- navigation - Used to hide all the other menu inactive. It will work if menu was set.
- URL - The url in the href tag used as URL.
let see the below html Example.
<html>
<title>One.js single page application</title>
<body data-onepage=".menu" data-onecontainer="#container" data-navigation=".menu">
<a class="menu" data-button="true">Ajax Button - Will do the other events.</a>
<a class="menu" href="fb.com" data-opt="true">Optout Button - Will redirect fb.com </a>
<a class="menu change" data-menu=".change">
Change Menu - Will make this menu as active, so this tag will be activated
</a>
<a class="menu" data-container="#special" href="/special">
This will load the page **/special** into #special container
</a>
<a class="otherclass" href="/normal">Will work as normal a tag </a>
<div id="#container">
This is where content will be loaded.
All page content will be loaded here, except tag with inline container.
</div>
<div id="#special">
This is where the special content will be loaded.
</div>
</body>
</html>
This library also have an option to use the single page functionality in reloadable form submissions. To enable we just need to add a class to the form.
<form type="GET" class="oneform" data-location="#container_to_paste">
...
</form>
- This one form functionlity just works only in get type forms
- It will act like normal form get form submission with query parameters
- We can change the container location if we need to by using data-location=""
This multiple selector used to the alternative solution for select2. In this selector we can use image and get the selected value in any format we want.
To enable this frame work we just need a selector and the option data. The framework will do the work for you.
let options = {
'data' : data, //in js object array { required }
'required' : ['id','name'], // Use this index only { optional }
'icon' : 'image', // image index { optional }
'name' : 'name' // name index { required }
}
$(".some-selector").options(options);
$(".some-selector").selected(data,"name index"); { required both }
In this selector we can validate this in two ways.
- data-min : It used to set the minimum set the minimum selected options. This need to be added in the home selector. If the condition failed then it will return false in fetching the result.
<div id="some-selector" data-min="1"> <!-- optional -->
- data-limit : It used to set the maximum select options. This need to be added in the home selector. If the condition failed then it will remove the first selected value from the input.
<div id="some-selector" data-limit="3"> <!-- optional -->
By using this function we can get the selected value and its other property values. We can map the values and customize it based our needs.
let options = {
'required' : [ 'id', 'name' ],
'map' : { id : 'team-id', name : 'team-name' }
}
$(".some-selector").get_c(options);
By using this function we can get the all options value and its other property values. We can map the values and customize it based our needs.
let options = {
'required' : [ 'id', 'name' ],
'map' : { id : 'team-id', name : 'team-name' }
}
$(".some-selector").get_o(options);
Right now there is a bug in the framework and it will be solved soon. But now include this two lines in the page to enable remove option.
$(document).on("click", ".label-info", function() {
$(this).remove();
});
By using this function we can get the date picker like todoist. It will return the JS date object of human input. And it will parse the human input when we enter . [Dot]
To avtivate the picker just need to call the function.
$(".some-selector").onedate();
To use this frame work we need to write the date in computer readable format. Here is the list of acceptable format in the funation.
- 13 jun 2020 8:31am.
- 13 jun 2020 8pm.
- 13 jun 2020.
- jun 2020.
- 13 jun.
- Need to make this work with meta content and title.
- Forward or Backward buttons will not work if page reloaded. Need to solve this bug.
- make selector option close working.