Contains common utility methods and classes used in our plugins.
Either use the foo-utils.js
or foo-utils.min.js
files in the dist/ directory with the default namespace FooUtils
or if you want to embed this as part of another package you can rename the namespace and file as part of a copy/concat/uglify task by using something like the below.
copy: {
main: {
src: './node_modules/foo-utils/dist/foo-utils.js',
dest: 'compiled/my-api-utils.js',
options: {
process: function (content, srcpath) {
return content.replace(/FooUtils/g, "MyApi.utils");
}
}
}
},
The above simply regex replaces all occurrences of FooUtils
to MyApi.utils
within the JavaScript files and then renames the file to my-api-utils.js
. As this is a simple regex replace the namespace MyApi
must exist prior to the my-api-utils.js
file being included in the page.
This package does expose a custom grunt task called foo-utils
that can be used to perform the above and it requires just two options to be set; namespace
and dest
.
"foo-utils": {
options: {
namespace: "MyApi.utils",
dest: "./dist/my-api-utils.js"
}
},
Ideally the above would be used as a step in a larger build process that would include the my-api-utils.js
file as part of its own concat or uglify tasks resulting in a single file so any include order namespace issues are no longer a problem.
There are considerable changes for this version as I included babel in the build and performed a cleanup of old/unused methods.
- Breaking Change: Removed the
FooUtils.uniqueId
andFooUtils.removeUniqueId
methods as they were no longer being used in any of our plugins. - Breaking Change: Removed the
FooUtils.scrollParent
method as it was no longer being used due to issues in some browsers. - Breaking Change: Removed the
FooUtils.src
method as it was no longer being used in any of our plugins. - Breaking Change: Removed the
FooUtils.versionCompare
method as it was only being used by the lib when it registered itself and that was changed in version 0.2.0. - Breaking Change: Removed the
FooUtils.animation
namespace and moved theFooUtils.animation.requestFrame
andFooUtils.animation.cancelFrame
methods to the baseFooUtils
namespace asFooUtils.requestFrame
andFooUtils.cancelFrame
. - Breaking Change: Removed the
FooUtils.transition.transitionend
andFooUtils.transition.supported
properties as all supported browsers now have support for thetransitionend
event and browser detection is no longer required. - Breaking Change: Updated the signature of the
FooUtils.transition.start(element, triggerFn, propertyName, timeout)
method to provide better functionality now that all supported browsers support thetransitionend
event. - Breaking Change: Removed the
FooUtils.Bounds
object as its functionality can be better implemented using anIntersectionObserver
. - Breaking Change: Removed the
FooUtils.fn.when
method and replaced it withFooUtils.fn.all
andFooUtils.fn.allSettled
to match the signatures of the standardPromise
api. - Breaking Change: Updated the signatures of the
FooUtils.fn.resolveWith
andFooUtils.fn.rejectWith
methods to better match those provided by jQuery. The first parameter is now thethisArg
within any callbacks. - Breaking Change: Changed the
FooUtils.Class.bases
method toFooUtils.Class.getBaseClasses
. - Breaking Change: Removed the
FooUtils.fn.check
andFooUtils.fn.fetch
methods as they were no longer being used in any of our plugins. - Breaking Change: Removed the
FooUtils.Factory
class, use the newFooUtils.ClassRegistry
class instead. - Added new
FooUtils.ClassRegistry
class to replace the previousFooUtils.Factory
class. - Added new
FooUtils.transition.disable(element, modifyFn)
method to help with working with transitions. This method temporarily disables all transitions on an element, executes the callback to modify the element, and then enables all transitions again once modifications are complete. - Added new
FooUtils.transition.modify(element, modifyFn [, immediate [, propertyName]])
method to help with working with transitions. Theimmediate
parameter changes how themodifyFn
is used;true
is applied immediately with no transition,false
is applied immediately but waits for the transition to end. - Added new
FooUtils.fn.all
method to match the functionality provided by thePromise.all
method. - Added new
FooUtils.fn.allSettled
method to match the functionality provided by thePromise.allSettled
method. - Added new
FooUtils.fn.resolve
method to match the functionality provided by thePromise.resolve
method and the previousFooUtils.fn.resolveWith
method. - Added new
FooUtils.fn.reject
method to match the functionality provided by thePromise.reject
method and the previousFooUtils.fn.rejectWith
method.
- Added new
FooUtils.inArray
method to test if a value exists in an array. Essentially a wrapper around the nativeindexOf
method on an array, but it checks if the haystack is an actual array.
- Breaking Change: Removed the
FooUtils.Debugger
class, it's usefulness had come to an end, and it was reporting as a cookie in Chrome because it checked on the existence of localStorage as the script was parsed. - Breaking Change: Removed the default instance of the
FooUtils.FullscreenAPI
class which was exposed asFooUtils.fullscreen
as not all projects need it and initializing it by default was unnecessary overhead.
- Breaking Change: Changed how the lib registers itself to the global. Previously it would only register itself if it didn't exist, or the existing version was older. The version check is no longer performed.
- Added new
FooUtils.find
method to pluck a single value from an array or object. - Added new
FooUtils.each
method to iterate over arrays or objects. - Added new
FooUtils.Event.parse
method that splits an event name into its type and namespace. - Updated the
FooUtils.transition.duration
,FooUtils.animation.duration
andFooUtils.animation.iterations
methods to handle multiple values. - Updated the
FooUtils.EventClass
to expose various internal members publicly. This class now exposes anevents
object as well as aaddListener
andremoveListener
methods. - Updated the
FooUtils.fn.when
method to handle values that are not promises passed in as part of the array. - Updated the
FooUtils.str.format
method to use the newFooUtils.each
method internally. - Updated the
FooUtils.str.from
andFooUtils.str.until
methods by simply removing unnecessary parameter checks. - Updated the
devDependencies
in thepackage.json
. - Updated various comments across the library to give better intellisense.
- Added new
FooUtils.Class.bases
method to return an array of all inherited classes.
- Added new
FooUtils.str.kebab
method for formatting strings to kebab case (this-is-kebab).
- Fixed issue with transitions/animations not firing on newly appended elements.
- Fixed inconsistent results across browsers when using the
FooUtils.url.parts
method. - Added new
FooUtils.animation
namespace containing various properties and methods to help with CSS animations. - Added new
FooUtils.FullscreenAPI
class, exposed as theFooUtils.fullscreen
instance, to provide a cross browser fullscreen API. - Added new
FooUtils.Timer
class to provide a simple event based timer.
- Fixed issue with the
FooUtils.EventClass
'son
andoff
methods when using an object with space separated event names.
- Updated the
FooUtils.EventClass
andFooUtils.Event
classes to handle namespaced events. - Updated the
FooUtils.EventClass
'son
andoff
methods to accept an object containing event type to handler mappings.
- Fixed context issue with
FooUtils.fn.debounce
.
- Updated
FooUtils.scrollParent( element, axis, def )
to explicitly test foroverflow:scroll
oroverflow:auto
rather than just notoverflow:hidden
.
- Updated
FooUtils.scrollParent( element, axis, def )
to exclude<html/>
from the result as its scroll events are raised on thedocument
.
Start of changelog. Older versions have no breaking changes.
- Breaking Change: Removed
FooUtils.Throttle
class, replaced with two methodsFooUtils.fn.debounce( fn, time )
andFooUtils.fn.throttle( fn, time )
. - Added new
FooUtils.EventClass
base class andFooUtils.Event
classes to allow objects to be subscribed to and emit events through the supplied.on( eventName, callback [, thisArg] )
,.off( eventName [, callback] )
and.trigger( eventName, args )
methods. - Added new
FooUtils.selectify( classes )
method. - Added new
FooUtils.src( src, srcset, srcWidth, srcHeight, renderWidth, renderHeight, devicePixelRatio )
method. - Added new
FooUtils.scrollParent( element, axis, def )
method.