Visit https://github.com/DarceyLloyd/aftc-modules
npm i aftc-modules
Why? This is because of the direction JS development is going, if I am building a webpack project I often only want: log, logTo, onReady and argsToObject. And so a new core was born! Using webpack? You should be using aftc-modules unless I haven't migrated a feature over yet.
let color = new AFTC.Color();
color.setRGB(0,255,0); // set starting color
let colors1 = color.fadeTo(255,0,0,10);
// Or do it with fromTo
let colors2 = color.fadeFromTo(0,0,0,255,0,0,10);
A single request animation frame function stack which can be used to control multiple classes / whole applications renderers etc via methods add(fn) remove(fn) stop() start() dispose()
let AnimStack = new AnimationFrameStack();
animStack.add(fn1);
animStack.stop();
adnimStack.remove(fn2);
animStack.start();
You can view all pens at https://codepen.io/AllForTheCode/pens/public/?grid_type=list
Quick and easy script loading and attachement to the DOM.
Attach some visual debug divs to an element which you can logTo, returns an array of elements so you can:
let v = attachDebug(10,document.body);
debugTo(v[0],"hello world 1");
debugTo(v[9],"hello world 10");
npm i aftc.js
or via cdn:
- https://cdn.jsdelivr.net/npm/aftc.js@latest/dist/aftc.min.js
- https://cdn.jsdelivr.net/npm/aftc.js@latest/dist/aftc.core.min.js
Then include the version you wish to use, your options are:
-
aftc.min.js (44KB) - Have it all!
-
aftc.core.min.js (3.71KB) - onReady, log, Log, getElement shortcuts, getRandomInt/float etc.
gulp build
- Open aftc.js directory in VSCode
- Open "gulpfile.js" and edit / comment out or uncomment any of the imports that you want or don't want
// The extras, the modules, the ooo or to some, the bloat
// Nice to have, but not essential
var aftc_modules = [
"./dist/aftc.core.js", // The AFTC Core (required)
"./src/AFTC/AFTC.Audio.js", // Enables new AFTC.Audio() and playSound()
"./src/AFTC/AFTC.Animate.js", // Enables new AFTC.Animate()
"./src/AFTC/AFTC.Canvas.js", // Enables new AFTC.Canvas();
// "./src/AFTC/AFTC.CheckboxHideShow.js", // Up for review - to be updated or removed
"./src/AFTC/AFTC.Color.js", // Enables new AFTC.Color();
"./src/AFTC/AFTC.Visibility.js", // Enables hide(), show(), fade(), fadeIn() & fadeOut()
// "./src/AFTC/AFTC.ResizeManager.js", // Up for review - to be updated or removed
"./src/AFTC/AFTC.XHR.js", // Everyone needs some IO, I know I do...
];
- Open terminal in VSCode by pressing CTRL + '
- Type into terminal
gulp build
NPMJS Has issues with Docs from GITHUB from this point, want to see the docs better please visit the github page https://github.com/DarceyLloyd/AFTC.js.git
addEvent(obj,type,fn,useCapture)
AFTC.Animate()
AFTC.Animate(elementId, onComplete)
AFTC.Audio({options})
AFTC.Color({params})
AFTC.Point(x,y)
AFTC.Rectangle(x, y, w, h)
AFTC.Velocity(vx,vy)
AFTC.XHR({options})
argsToObject(fArgs, obj, strict)
arrayContains(needle,haystack)
arrayEmpty(arr)
arrayGetMin(arr)
arrayRemoveIndex(arr,index)
arrayShuffle(arr)
arrayShuffle2(arr)
arrayToSingleLineString(arr)
boolToString(bool)
boolToYesNo(bool)
centerAbsoluteElement(elementId)
cleanJSONString(s)
cls()
convertToArray(val)
cutStringTo(input, len)
cycle(pos, max)
degToRad(input)
escapeHTML(input)
exitFullScreen()
getAllStringsBetween(str,start,end)
getAnchor(url)
getArrayOfRandomNumbers(arraySize,min,max)
getArrayOfRandomStrings(arraySize,strLength)
getBooleanFrom(input)
getBrowser()
getCookie(name)
getDateTime(local)
getDaysBetween(startDateTime, endDateTime)
getElementByClassName(className)
getElementById(id)
getElementByName(name)
getElementByTagName(tagName)
getElementOffsetTop(elementId)
getElementsByClassName(className)
getElementsByName(name)
getElementsByTagName(tagName)
getFileExtension(input)
getFileExtension2(input)
getFunctionName(fn)
getIEVersion()
getLastPartOfUrl(url)
getMaxFromArray(arr)
getOS(testUserAgent)
getRandomColor()
getRandomFloat(min,max)
getRandomInt(min,max)
getRandomThatsNot(min,max,not)
getSQLDateTime()
getStringBetween(input,start,end)
getUID(length)
getUKDateFromDate(dte)
getUkDateFromDbDateTime(input)
getUkDateTimeFromDbDateTime(input)
getUSDateFromDate(dte)
getWeightedRandom(odds, iterations)
goFullScreen(element)
guid()
hasClass(elementOrId, cls)
hexToRgb(hex)
iOS()
isAlphaNumeric(input)
isAndroid()
isArray(input)
isBoolean(input)
isChecked(elementId)
isChrome()
isDOM(obj)
isEdge()
isElement(o)
isElement2(element)
isEven(n)
isFireFox()
isIE()
isInString(find,source)
isMobile()
isNumberKey(evt)
isNumeric(n)
isOdd(n)
isOpera()
isSafari()
isStringInArray(needle,haystack)
leftTrim(str, by)
limitLengthInWords(str, maxWords)
log(*)
logTo(element,str,append)
onReady(fn)
openDebugWindow(html)
parseArrayToFloat(arr)
parseArrayToInt(arr)
parseJSONToSelect(j, selectElementIdOrElement, label, value)
querySelector(query)
radToDeg(input)
randomString(length)
redirect(url)
removeAllSelectOptions(elementId)
removeClass(elementOrId,className)
removeFileFromPath(path)
rgb2Hex(r,g,b)
rgbToHex(r,g,b)
scrollToElement(elementId, duration, offset)
setCookie(name, value)
setHTML(elementOrId,html);
String.prototype.endsWith(str)
String.prototype.startsWith(str)
stringToBool(str)
toArray(v)
toHex(num)
trimStringBy(input, trimBy)
validateEmail(email)
https://codepen.io/AllForTheCode/pens/public/?grid_type=list
Quick and easy args to object
More information
Name | Type | Description |
---|---|---|
args | object | arguments (from the function structure, typically code will always be 'arguments' |
obj | object | object to parse into |
strict | boolean | console.warn any args that have been supplied that don't exist in args |
Returns: null
- argsToGets an element from the DOM by ID. NOTE
More information
Name | Type | Description |
---|---|---|
id | string | The ID of the DOM element you wish to find |
Returns: html element
- getId - byIdGets an element from the DOM via DOM Query. NOTE
More information
Name | Type | Description |
---|---|---|
query | string | The DOM Query / css element path you wish to find |
Returns: html element
- queryGets an array of element from the DOM that have a specific name. NOTE
More information
Name | Type | Description |
---|---|---|
name | string | The name of the DOM element you wish to find |
Returns: array of html elements
Gets the first element from the DOM that has a specific name. NOTE
More information
Name | Type | Description |
---|---|---|
name | string | The name of the DOM element you wish to find |
Returns: html elements
Gets an array of html elements from the DOM that have a specific class name. NOTE
More information
Name | Type | Description |
---|---|---|
className | string | The class the DOM element(s) use you wish to find |
Returns: array of html elements
Gets the first html element from the DOM that has a specific class name. NOTE
More information
Name | Type | Description |
---|---|---|
className | string | The class name the DOM element uses you wish to find |
Returns: html elements
Gets an array of html elements from the DOM that has a specific tag name. NOTE
More information
Name | Type | Description |
---|---|---|
tagName | string | the tag name you wish to find |
Returns: array of html elements
Gets the first html element from the DOM that has a specific tag name. NOTE
More information
Name | Type | Description |
---|---|---|
tagName | string | the tag name you wish to find |
Returns: html element
Shortcut for console.log with some formatting capabilities, you can also log to html elements see logTo()
log("Hello World");
log("a = " + a);
log("myVar1 = " + myVar1 + " myVar2 = " + myVar2);
log(MyObject);
log(MyClass);
More information
Name | Type | Description |
---|---|---|
* | input | what you want to console.log |
Shortcut for console.log with some formatting capabilities, you can also log to html elements see logTo()
logTo("MyElement","Hello World",false); // clears element and inserts
logTo("MyElement","Hello World"); // appends
let myElement = document.getElementById("MyElementId");
logTo(myElement,"Hello World"); // appends
More information
Element or ElementId | String | Append |
---|---|---|
HTML Element or String | String to be inserted into element | To append string or not to elements contents |
Clears the console if supported
remove a specified index from an array
More information
Name | Type | Description |
---|---|---|
arr | array | the array you wish to remove an index on |
index | number | the array index you wish to remove |
Returns: array
Check to see if a string is in an array
More information
Name | Type | Description |
---|---|---|
needle | string | what you want to search for in each array index |
haystack | string | the array you want to search |
Check to see if your array contains something you want to find
More information
Name | Type | Description |
---|---|---|
needle | string | what you want to search for in each array index |
haystack | string | the array you want to search |
clears/empties an array for garbage collection
More information
Name | Type | Description |
---|---|---|
array | arr | the array to clear / empty |
returns the maximum value in an array
More information
Name | Type | Description |
---|---|---|
array | arr | the array you wish to find the maximum value in |
returns the minimum value in an array
More information
Name | Type | Description |
---|---|---|
arr | array | the array you wish to find the minimum value in |
shuffles an array (method 1)
More information
Name | Type | Description |
---|---|---|
arr | array | the array to shuffle |
shuffles an array (method 2)
More information
Name | Type | Description |
---|---|---|
arr | array | the array to shuffle |
Converts an array to a single line string (usefull for debug)
takes an input and returns it as index[0] of an array
More information
Name | Type | Description |
---|---|---|
val | * | value to make into array an array |
no more typing self.location.href, just use redirect(url)
Go full screen, on an element if specified or whole browser if left out
More information
Name | Type | Description |
---|---|---|
element | element | optional - html element that you want to go full screen on, leave out for whole browser |
Exits full screen mode
More information
converts radians to degrees
More information
Name | Type | Description |
---|---|---|
input | number | the radians you wish converted to degrees |
converts degrees to radians
More information
Name | Type | Description |
---|---|---|
number | input | the value you wish converted to radians |
Converts a number to hex
More information
Name | Type | Description |
---|---|---|
num | number | decimal base 10 |
Returns: hexidecimal value
converts boolean to a string of true or false
converts a boolean to yes or no
Converts a string to a boolean (y,yes,"1",no etc)
converts an input to a boolean
More information
Name | Type | Description |
---|---|---|
* | input | the variable you wish to convert to a boolean |
parses all values in array to float
More information
Name | Type | Description |
---|---|---|
array | arr | array to process |
parses all values in array to float
takes an input and returns it as index[0] of an array
More information
Name | Type | Description |
---|---|---|
* | arg | value to insert into array |
rgb to hex
rgb to hex
hexToRgb
Sets a cookie by name with a value
More information
Name | Type | Description |
---|---|---|
name | string | name of the cookie |
value | string | value of the cookie |
expiryTimeInDays | number | Specify the number of days the cookie will expire in. |
Gets the value of a cookie by name
Add a css class to a html element
More information
Name | Type | Description |
---|---|---|
elementOrId | elementORstring | The elemnt or id of the html element to add a css class to |
className | string | the class name to add |
shortcut to remove a class from a html element
More information
Name | Type | Description |
---|---|---|
elementOrId | elementORstring | The elemnt or id of the html element to add a css class to |
className | string | the class name to remove |
Check to see if an element has a class attached to it
More information
Name | Type | Description |
---|---|---|
elementOrId | string | The elemnt or id of the html element |
cls | string | class to look for |
Gets the number of whole days between a start and end date
More information
Name | Type | Description |
---|---|---|
startDateTime | DateTime | start date |
endDateTime | DateTime | end date |
Formats a date in the UK format
Formats a date in the US format
get a uk date from a mysql db date value
get a uk date from a mysql db date time value
gets the date time now for sql insert
More information
gets the date time at a specified local
More information
Name | Type | Description |
---|---|---|
local | string | options are us or do not supply for en-gb |
open a popup window with the html you wish to display in it
More information
Name | Type | Description |
---|---|---|
html | string | the html you wish to display in the popup window |
Detects if the device you are using is a mobile or not
More information
Detects if the device you are using is android or not
More information
Detects if the device you are using is iOS or not
More information
Detects FireFox
More information
Detects Chrome
More information
Detects Edge
More information
Detects Safari
More information
Detects IE
More information
Detects Opera
More information
Gets version of IE
More information
Detects browser
More information
Attempts to get the os from the user agent or the test user agent
Quick shortcut for outputting html to an element
setHTML("header","Welcome");
More information
Name | Type | Description |
---|---|---|
elementOrId | stringIdOrHtmlElement | the element or the element id you wish to set the html of |
html | string | the html string to insert into your element |
Gets an elements top offset
More information
Name | Type | Description |
---|---|---|
elementId | string | the element ID you wish to get the top offset of |
Center element that is absolute positioned
More information
Name | Type | Description |
---|---|---|
elementId | string | element or id of element to center |
Scroll to element on page
More information
Name | Type | Description |
---|---|---|
elementId | string | ID of element you wish to scroll to |
duration | float | Duration in seconds |
offset | number | How much to offset scroll by |
Shortcut for adding events with old browser compatibility
More information
Name | Type | Description |
---|---|---|
obj | object | The object you wish to attach the event listener to |
type | string | The event type (e.type) mousedown, mouseup, click etc |
fn | function | The function to call when the event is triggered |
useCapture | boolean | Whether the event should be executed in the capturing or in the bubbling phase |
A replacement for using body onload and no need for jQuery's $(document).ready
More information
Name | Type | Description |
---|---|---|
fn | function | inline function or pass it a function for when your page is loaded and ready to be used |
Checks to if checkbox is checked or not
More information
Name | Type | Description |
---|---|---|
elementId | string | element id of the form element to check |
Checks if evt supplied (use on form input events via onkeyup or onkeydown)
More information
Name | Type | Description |
---|---|---|
evt | event | html onkeyup(event) or onkeydown(event) |
Removes all the options in a select
parses a json object of key value pairs to a form select element
More information
Name | Type | Description |
---|---|---|
j | string | the json data |
selectElementIdOrElement | elementOrIdString | the json data |
label | string | of key value pair this is the key |
value | string | of key value pair this is the value |
2D Point
More information
Name | Type | Description |
---|---|---|
x | number | x coordinate |
y | number | y coordinate |
Name | Description |
---|---|
position | |
clone | |
delta | |
distance | |
moveTo | |
moveAtAngle | |
applyVelocity | |
angleRadians | |
angleDeg | |
rotate |
Rectangle class, allos you to set x, y, width and height or a rectangle
More information
Name | Type | Description |
---|---|---|
x | number | x coordinate |
y | number | y coordinate |
w | number | w width |
h | number | h height |
Name | Description |
---|---|
offsetOuter | |
offsetInner | |
setX | |
setY | |
setW | |
setH |
Returns: AFTC.Rectangle
AFTC.Velocity class helper
More information
Name | Type | Description |
---|---|---|
vx | number | velocity vector x |
vy | number | velocity vector y |
Name | Description |
---|---|
flip | flip |
flipX | flipX |
flipY | flipY |
multiply | multiply |
divide | divide |
tries to get the function name of a suppled function
check for string in string
More information
Name | Type | Description |
---|---|---|
string | find | The string to look for |
string | source | The string to look in |
check if input is even
check if input is odd
check if an input is an alpha numerical value ([a-z],[A-Z],[0-9] only)
More information
Name | Type | Description |
---|---|---|
string||number | input | variable / value you wish to check |
checks if your variable is an element or not
checks to see if your vairable is an element or not
checks to see if your variable is a DOM object
checks if a variable is a boolean
check if variable is numeric
check if variable is an array
cycles from 0 to max based on pos, will cycle back to 0 if over max
More information
Name | Type | Description |
---|---|---|
pos | number | position of max |
max | number | max number to cycle to |
returns a random number / int betwen your specified min and max values
More information
Name | Type | Description |
---|---|---|
min | number | the minimum your random number is allowed to go |
max | number | the maximum your random number is allowed to go |
returns a random int betwen your specified min and max values but never the not value
More information
Name | Type | Description |
---|---|---|
min | number | the minimum your random number is allowed to go |
max | number | the maximum your random number is allowed to go |
returns a random floating point number betwen your specified min and max values
get a random string of a specified length
More information
Name | Type | Description |
---|---|---|
length | number | the length of the string you wish to generate |
Generates a random id
More information
Name | Type | Description |
---|---|---|
length | number | length of the unique id to generate |
generate an array of random number between your max and min values
More information
Name | Type | Description |
---|---|---|
arraySize | number | the number of random numbers to generate also the array size that will be returned |
min | number | the minimum your random number is allowed to be |
max | number | the maximum your random number is allowed to be |
generate an array of random string of a specified length
More information
Name | Type | Description |
---|---|---|
arraySize | number | the number of random strings to generate also the array size that will be returned |
strLength | number | the length of the strings to be generated |
generates a guid
Get a weighted random based on odds and iterations
More information
Name | Type | Description |
---|---|---|
odds | array | array of odds |
iterations | number | number of iterations to run on each number test |
Limit a string in length of words
More information
Name | Type | Description |
---|---|---|
str | string | the original string to limit |
maxWords | number | the number of words you wish to limit to |
Returns: {output
Attempts to clean a json string
Attempts to escape a html string
sets the length of a string from left to right
More information
Name | Type | Description |
---|---|---|
input | string | what string do you want to set the length of? |
length | number | the length you want the string to be |
Trims the length of a string by a value
More information
Name | Type | Description |
---|---|---|
input | string | The string you want to trim |
trimBy | number | How many characters do you want to trim off the end |
Trims the left of a string by a specified amount
More information
Name | Type | Description |
---|---|---|
string | str | The string you want to trim |
number | by | How many characters do you want to trim off the end |
Attempts to get the file extension from a file path string
Attempts to get the file extension from a file path string
Gets the last part of a URL
Attempts to remove the file from a file path string
Get anchor from url
ES6 supports the startsWith(), this is for pre ES6 support
ES6 supports endsWith(), this is for pre ES6 support
Gets a string between two other strings
More information
Name | Type | Description |
---|---|---|
string | input | input string to check |
string | start | start string marker |
string | end | end string marker |
Gets all strings between two other strings (multi match)
More information
Name | Type | Description |
---|---|---|
string | str | input string to check |
string | start | start string marker |
string | end | end string marker |
Validats an email address
Color allows you to create, convert, lighten or darken colours and more.
var color1 = new AFTC.Color(); // creates a random color
var color2 = new AFTC.Color({r
var color3 = new AFTC.Color({r
log( color3.getHex() ); // Outputs the hex code of color 3
More information
Name | Type | Description |
---|---|---|
object | params | parameters object |
Name | Description |
---|---|
lighten(percent,spectrum) | lighten the color by precent and optional spectrum {r |
darken(percent,spectrum) | darken the color by precent and optional spectrum {r |
randomizeColor | randomises the colour |
getRGBString | returns the RGB value of the color |
getRGBAString | returns the RGBA value of the color |
getHexString | returns the HEX value of the color |
getHex | returns the HEX value of the color |
hex | returns the HEX value of the color |
getRGB | returns the RGB value of the color |
rgb | returns the RGB value of the color |
getRGBA | returns the RGBA value of the color |
rgba | returns the RGBA value of the color |
setRGB | returns the RGB value of the color |
setHex | returns the HEX value of the color |
returns a random RGB object o.r, o.g, o.g
More information
Quick and easy css animation for nearly every css element style
var anim1 = new AFTC.Animate("box1", onCompleteFunction);
anim1.wait(2); // wait in 2 seconds
anim1.set("backgroundColor","RGBA(255,255,255,0.5)"); // sets background color to white 50% opacity
anim1.anim("fontColor","RGBA(255,0,0,1)",1.5); // animates the font color to red over 1.5 seconds
anim1.set(["html","paddingLeft",left"],["hello","10px","100px"],[1,2,3]); // sets innerHTML, padding-left and left position over 1, 2 and 3 seconds
More information
An audio player with preloading capabilities, looping abilities and loop offset capabilities
More information
Name | Type | Description |
---|---|---|
s | src | String or Array of urls/paths to sound files |
s | cache | To cache or not to cache |
s | volume | 0 to 1 |
s | repeat | -1 forever, 0 play once only, or the number of times to repeat |
s | preload | true or false |
s | offsetLoopBy | the sample offset from the end that you wish to loop by can help remove loop gaps |
s | onUpdate | the function you wish to run when your sound is playing provides and info object |
s | onReady | the function you wish to run when your sound is ready and can play |
s | onComplete | the function you wish to run when your sound has finished playing |
s | hideWarnings | hides notices in console for compatibility issues when not using mp3 etc |
Name | Description |
---|---|
play | Play audio |
stop | Stop audio |
pause | Pause audio |
resume | Resume ausio |
Color allows you to create, convert, lighten or darken colours and more.
var color1 = new AFTC.Color(); // creates a random color
var color2 = new AFTC.Color({r
var color3 = new AFTC.Color({r
log( color3.getHex() ); // Outputs the hex code of color 3
More information
Name | Type | Description |
---|---|---|
object | params | parameters object |
Name | Description |
---|---|
lighten(percent,spectrum) | lighten the color by precent and optional spectrum {r |
darken(percent,spectrum) | darken the color by precent and optional spectrum {r |
randomizeColor | randomises the colour |
getRGBString | returns the RGB value of the color |
getRGBAString | returns the RGBA value of the color |
getHexString | returns the HEX value of the color |
getHex | returns the HEX value of the color |
hex | returns the HEX value of the color |
getRGB | returns the RGB value of the color |
rgb | returns the RGB value of the color |
getRGBA | returns the RGBA value of the color |
rgba | returns the RGBA value of the color |
setRGB | returns the RGB value of the color |
setHex | returns the HEX value of the color |
returns a random RGB object o.r, o.g, o.g
More information
Quick and easy xhr/ajax
Any and all donations to help keep active development and the lights on are more than welcome.