A very minimalistic javascript library.
adjective: scant
“companies with scant regard for the safety of future generations”
synonyms: little, little or no, minimal, hardly (any), limited, negligible, barely sufficient, meager
antonyms: abundant, ample, sufficient barely amounting to a specified number or quantity.
verb: scant; 3rd person present: scants; past tense: scanted; past participle: scanted; gerund or present participle: scanting
“he does not scant his attention to the later writings”
<script type="text/javascript" src="//path/to/scant.min.js"></script>
<script type="text/javascript">
// window.Scant === window.$
// window.$ is only made available is $ is not already registered
$.ready(function(){
var $elm = $('.selector');
$elm.on('click', '.child', function(evt){
evt.stopPropagation();
evt.preventDefault();
var data = $('form').serialize();
$.ajax({
url: '/end-point',
data: JSON.stringify(data),
dataType: 'application/json',
responseType: 'json',
}, function(err, request){
if(err || ~request.response){
alert('oh no, something went wrong');
} else {
alert('go a good response back');
}
});
});
});
</script>
Main entry point for creating an instance of scant().
Arguments: |
|
---|---|
Returns: | an instance of scant(). |
Helper method to copy properties from one Object over to another
Arguments: |
|
---|---|
Returns: | a copy of target with all of sources‘s properties copied to it |
Helper method to ensure that child‘s prototype inherits from parent‘s
Arguments: |
|
---|---|
Returns: | null |
The prototype for scant() exposed, useful for extending scant().
$.fn.hide = function(){
// "this" refers to the instance of scant
this.forEach(function(elm){
elm.style.display = 'none';
}.bind(this);
};
$('.hidden').hide();
Wrapper around making XMLHttpRequest’s.
// default options to $.ajax
var defaultAjaxOptions = {
// url to fetch
url: null,
// http method to use
method: 'GET',
// additional headers e.g. {'X-Token': 'token'}
headers: {},
// data to send
data: null,
// this gets set as 'Content-Type' header with request
dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
// an optional function(request) to call before sending the request,
// useful to make customizations to the XMLHttpRequest object before sending
beforeSend: null,
// the response type expected back
responseType: '',
};
Arguments: |
|
---|---|
Returns: | null |
Function for event delegation. This method will add handler as an event handler on body, optionally filtering based on the selector provided.
Arguments: |
|
---|---|
Returns: | null |
Function used to add a handler when the page has finished loaded (‘DOMContentLoaded’).
Arguments: |
|
---|---|
Returns: | null |
The scant class inherits from Array and properties of an Array are available (although forEach is shimmed in if it is not supported by the browser).
Arguments: |
|
---|
Method used to find all children matching selector beloning to the elements stored in this instance of scant.
Arguments: |
|
---|---|
Returns: |
This method is the same as $.on() except the handler is bound to every node stored in this instance of scant as opposed to binding to body.
Arguments: |
|
---|---|
Returns: | null |
Method used to serialize the data for elements stored in this instance of scant. Most useful for fetching the data from form elements. This method gets the name/value pairs for all form elements (creating an array when the same name is present multiple times) as well as appending element data attributes.
Arguments: |
|
---|---|
Returns: | Object |