JavaScript
Custom scripts
Each page can be enhanced by using custom JavaScript, you can create the following JavaScript files (each to be placed in the /js
directory):
global.js - global script file that is included on every page,
post.js - post/page specific scripts,
home.js - script to be included on the homepage,
category.js - script to be included on category pages.
You can use the modern JS features, all scripts are compiled using babel and minified before being published.
Utils
The following methods are available in the global JavaScript library (please note that this library is loaded asynchronously, meaning it might be unavailable on page load).
window.Phaistos.addClass
- add class to a Node element, accepts two arguments,node
(the DOM element) andclassName
(the name of the class to be added).window.Phaistos.removeClass
- remove class from a Node element, accepts two arguments,node
(the DOM element) andclassName
(the name of the class to be removed).window.Phaistos.get
- send a GET request, accepts 4 arguments,url
(required),params
(Object - key value pairs appended as query parameters), andonLoad
/onError
callbacks.window.Phaistos.post
- send a POST request, accepts 4 arguments,url
(required),body
(Object - key value pairs sent as the request body), andonLoad
/onError
callbacks.
Loading external scripts
To load external scripts, the global enqueueScript
function should be used. This accepts two arguments:
src
- (String) the source of the external script,attrs
- (Object) a map of attribute names to attribute values to be added to the script tag.