Comonfunctions
This is a set of helper functions to make writing java script easier
Test against the current flags
comonFunctions.canShow(guide.getFlags(), String ifSet, String ifNotSet);
Returns true or false (this is the code that is used within guideme so ifset/ifnotset handle and/or conditions as they would in the xml)
Get the difference between two dates in different units comonFunctions.dateDifference(String units, Date startdate, Date enddate); The units string can be "d", "h", "m" or "s" to get the difference in days, hours, minutes or seconds. The result is rounded down to the nearest whole number. If startdate and enddate are reversed the result will be negative.
var then = new Date(Date.parse("Jan 1 2015 15:27:30")); var now = new Date(); days = comonFunctions.dateDifference("d", then, now); // Number of days since January 1st days = comonFunctions.dateDifference("d", now, then); // Same as above but result will be negative
Set and unset flags
flagNames is a comma separated list e.g."page3,page5" or "page3"
comonFunctions.SetFlags(String flagNames, guide.getFlags());
comonFunctions.UnsetFlags(String flagNames, guide.getFlags());
Random Numbers
comonFunctions.getRandom(String random)
(x..y) generates a random number between x and y
Converts a time as a string to miliseconds
comonFunctions.getMilisecFromTime(String iTime)
hh:mm:ss to miliseconds
Returns the version of guideme that is running.
If you need a specific verion or more you can check here
comonFunctions.getVersion()
returns a string in the format n.n.n
(The version when this was written would return "0.1.2")
Returns a list of the files in a folder
Returns a list of folders within the media directory
var media;
media = comonFunctions.ListSubFolders("");
// Returns string ["Models", "Tasks"]
var models;
models = comonFunctions.ListSubFolders("Models");
// Returns string ["Kate", "Sophia", "Emily", "Hilda"]
Returns a random file
var randomFile;
randomFile = comonFunctions.GetRandomFile("*.jpg", "Models\\Hilda");
// returns string e.g. Models\Hilda\crissy-moran-misc-037.jpg
Returns whether a file exists
var fileExists;
fileExists = comonFunctions.fileExists("Models\\Hilda\\crissy-moran-unhappy-001.jpg");
// Returns Java Boolean
Returns whether a directory exists
var directoryExists;
directoryExists = comonFunctions.directoryExists("Models\\Hilda");
// Returns Java Boolean