Tag Archives: javascript

JavaScript/CSS/HTML || Notice.js – Simple Notification Message With Success, Warning & Error Icons Using Vanilla JavaScript

The following is a module with functions that demonstrates how to display a simple notification message with success, warning & error icons.

Using vanilla JavaScript, the message fades in and is displayed to the page, and fades out after a delay (in milliseconds). It’s look and feel can also be adjusted via CSS.

Notice.js & CSS Source

Contents

1. Basic Usage
2. Notice HTML
3. Notice.js & CSS Source
4. More Examples

1. Basic Usage

Syntax is very straightforward. The following demonstrates the JavaScript used to show the notification message. The message fades away after a specified amount of time (in milliseconds).

Sample:

Sample


2. Notice HTML

If you wish to show the messages without using JavaScript, the following is an example of the HTML used to display the notices.

Sample:

Sample

Sample:

Sample

Sample:

Sample


3. Notice.js & CSS Source

The following is the Notice.js Namespace & CSS Source. Include this in your project to start using!

The following is Notice.css.


4. More Examples

Below are more examples demonstrating the use of ‘Notice.js‘. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || How To Get All Unique Values In An Array & Remove Duplicates Using Vanilla JavaScript

The following is a module with functions which demonstrates how to get all distinct values in an array & remove duplicates from a simple and object array.

The functions on this page allows for an optional selector function as a parameter, which makes them general enough to work on arrays of any type.


1. Simple Array

The example below demonstrates the use of ‘Utils.arrayUnique‘ to get unique values from a simple array.


2. Object Array

The example below demonstrates the use of ‘Utils.arrayUnique‘ to get unique values from an object array.

In this example, a selector is used, which extracts the value to be used in the evaluation.


3. Mixed Array

The example below demonstrates the use of ‘Utils.arrayUnique‘ to get unique values from a mixed array.

In this example, a selector is used, which extracts the value to be used in the evaluation.


4. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || Circular Array – How To Index Into Array As If It Is Circular Using Vanilla JavaScript

The following is a module with functions which demonstrates how to index into an array as if it is circular using Vanilla JavaScript.

This function adjusts a range as circular and ‘wraps around’ the value to become in bounds.


1. Circular Array

The example below demonstrates the use of ‘Utils.circularWrap‘ to index into an array as if it is circular.


2. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || How To Find All Combinations Of Well-Formed Brackets Using Vanilla JavaScript

The following is a module with functions which demonstrates how to find all combinations of well-formed brackets.

The task is to write a function Brackets(int n) that prints all combinations of well-formed brackets from 1…n. For example, Brackets(3), the output would be:

()
(()) ()()
((())) (()()) (())() ()(()) ()()()

The number of possible combinations is the Catalan number of N pairs C(n).


1. Find All Well-Formed Brackets

The example below demonstrates the use of ‘Utils.brackets‘ to find all the well-formed bracket combinations.


2. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || How To Calculate Nth Catalan Number Using Vanilla JavaScript

In combinatorial mathematics, a Catalan number forms a sequence of natural numbers that occur in various counting problems. It can be used to determine how many different ways to split something up.

The following is a module with functions which demonstrates how to calculate nth Catalan number.


1. Calculate Nth Catalan Number

The example below demonstrates the use of ‘Utils.catalan‘ to calculate nth Catalan number.


2. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript/CSS/HTML || Modal.js – Simple Modal Dialog Prompt Using Vanilla JavaScript

The following is a module which allows for a simple modal popup dialog panel in vanilla JavaScript. This module allows for custom Yes/No prompts.

Options include allowing the modal to be dragged, resized, and closed on outer area click. Modal drag and resize supports touch (mobile) input.

Modal.js & CSS Source

Contents

1. Basic Usage
2. Available Options
3. Alert Dialog
4. Yes/No Dialog
5. Custom Buttons
6. Dialog Instance
7. Modal.js & CSS Source
8. More Examples

1. Basic Usage

Syntax is very straightforward. The following demonstrates adding a simple dialog to the page.


Sample:

Sample

The following example demonstrates how to add click events to the default dialog buttons. The ordering of the buttons on initialization defines its placement on the dialog.


2. Available Options

The options supplied to the ‘Modal.showDialog‘ function is an object that is made up of the following properties.

Supplying different options to ‘Modal.showDialog‘ can change its appearance. The following examples below demonstrate this.


3. Alert Dialog

The following example demonstrates an alert dialog.


Sample:

Sample


4. Yes/No Dialog

The following example demonstrates a yes/no dialog.


Sample:

Sample


5. Custom Buttons

The following example demonstrates multiple custom buttons.


Sample:

Sample


6. Dialog Instance

The following example demonstrates how to use the dialog instance to show and hide when needed.


7. Modal.js & CSS Source

Modal.js & CSS Source


8. More Examples

Below are more examples demonstrating the use of ‘Modal.js‘. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || How To Get The Minimum & Maximum Values In A Simple & Object Array

The following is a module with functions which demonstrates how to get the minimum and maximum values in a simple and object array.

The functions on this page allows for an optional selector function as a parameter, which makes them general enough to work on arrays of any type.


1. Simple Array

The example below demonstrates the use of ‘Utils.arrayMin‘ and ‘Utils.arrayMax‘ to get the minimum and maximum values from a simple array.


2. Object Array

The example below demonstrates the use of ‘Utils.arrayMin‘ and ‘Utils.arrayMax‘ to get the minimum and maximum values from an object array.

In this example, a selector is used, which extracts the value to be used in the evaluation.


3. Mixed Array

The example below demonstrates the use of ‘Utils.arrayMin‘ and ‘Utils.arrayMax‘ to get the minimum and maximum values from a mixed array.

In this example, a selector is used, which extracts the value to be used in the evaluation.


4. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript/CSS/HTML || Placeholder.js – Simple Animated Floating Label For Textbox, Dropdown & Textarea Using Vanilla JavaScript

The following is a module which allows for a simple animated floating placeholder label for textbox, dropdown & textarea using vanilla javascript.

No special HTML markup is required.

Placeholder.js & CSS Source

Contents

1. Basic Usage
2. Placeholder HTML
3. Placeholder.js & CSS Source
4. More Examples

1. Basic Usage

Syntax is very straightforward. The following demonstrates adding and removing floating placeholders to elements.

Placeholder.float‘ and ‘Placeholder.remove‘ accepts either a string selector or one or more Javascript elements.


2. Placeholder HTML

The following is sample HTML used for the floating placeholder label. No special HTML markup is required. Simply supply an element with a ‘placeholder‘ attribute, and you’re all set!

Sample – Blank:

Sample

Sample – Filled:

Sample


3. Placeholder.js & CSS Source

The following is the Placeholder.js Namespace & CSS Source. Include this in your project to start using!

The following is Placeholder.css.


4. More Examples

Below are more examples demonstrating the use of ‘Placeholder.js‘. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript/CSS/HTML || Modal.js – Simple Modal Popup Panel Using Vanilla JavaScript

The following is a module which allows for a simple modal popup panel in vanilla JavaScript. Options include allowing the modal to be dragged, resized, and closed on outer area click.

Modal drag and resize supports touch (mobile) input.

Modal.js & CSS Source

Contents

1. Basic Usage
2. Modal HTML
3. Initialize Modal Options
4. Modal Dialog
5. Modal.js & CSS Source
6. More Examples

1. Basic Usage

Syntax is very straightforward. The following demonstrates showing and hiding a modal popup.

Modal.show‘ and ‘Modal.hide‘ accepts either a string selector or a Javascript element.


2. Modal HTML

The following is the HTML used to display the modal. The attributes supplied to the ‘modal’ element specifies whether it is allowed to be dragged, resized, or closed on outer area click.

Sample:

Sample


3. Initialize Modal Options

In order for the options on the modal to take effect, it needs to be initialized.

The following example demonstrates initializing the modal popup options.

Note: ‘Modal.init‘ only needs to be called once. It will initialize all modals on the page.


4. Modal Dialog

The following demonstrates adding a simple dialog to the page.

For more options, click here!


Sample:

Sample


5. Modal.js & CSS Source

The following is the Modal.js Namespace & CSS Source. Include this in your project to start using!

The following is Modal.css.


6. More Examples

Below are more examples demonstrating the use of ‘Modal.js‘. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || Movement.js – Move, Resize, Drag & Drop Elements With The Mouse, Mobile Touch & Keyboard Using Vanilla JavaScript

The following is a module that handles dragging and resizing elements with a mouse/touch, moving elements with the keyboard via the arrow keys, and drag and dropping elements onto a drop zone.

Movement.js Source

Contents

1. Basic Usage
2. Draggable - Available Options
3. Resizable - Available Options
4. Movable - Available Options
5. Droppable - Available Options
6. Movement.js Namespace
7. More Examples

1. Basic Usage

Syntax is very straightforward. The following demonstrates basic usage to enable element movement.

Movement.draggable‘ makes an element draggable via the mouse/touch input. ‘Movement.resizable‘ makes an element resizable via the mouse/touch input. ‘Movement.movable‘ makes an element movable via the keyboard arrow keys. ‘Movement.droppable‘ makes an element droppable via a dropzone/allows files to be dropped to dropzone.


2. Draggable – Available Options

Movement.draggable‘ makes an element draggable via the mouse/touch input.

The options supplied to the ‘Movement.draggable‘ function is an object that is made up of the following properties.


3. Resizable – Available Options

Movement.resizable‘ makes an element resizable via the mouse/touch input.

The options supplied to the ‘Movement.resizable‘ function is an object that is made up of the following properties.


4. Movable – Available Options

Movement.movable‘ makes an element movable via the keyboard arrow keys.

The options supplied to the ‘Movement.movable‘ function is an object that is made up of the following properties.


5. Droppable – Available Options

Movement.droppable‘ makes an element droppable via a dropzone/allows files to be dropped to dropzone.

The options supplied to the ‘Movement.droppable‘ function is an object that is made up of the following properties.

Movement.droppable‘ utilizes the HTML Drag and Drop API to facilitate movement. Currently, the API only allows Mouse support.

To allow for touch support, the polyfill DragDropTouch.js is recommended to be used, which simulates the Drag and Drop API. This allows ‘Movement.droppable‘ to be supported with touch input.


6. Movement.js Namespace

The following is the Movement.js Namespace. Include this in your project to start using!


7. More Examples

Below are more examples demonstrating the use of ‘Movement.js‘. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || How To Make Change – Display The Total Sales Amount In Dollars & Cents Using Modulus

The following is a module with functions which demonstrates the use of the modulus (%) operator to make change.

So for example, given the value of 2.34, this function would return the result of 2 dollars, 1 quarters, 1 nickels, and 4 pennies.


1. Make Change

The example below demonstrates how to make change.


2. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || Swap Two HTML Element Locations In Dom Tree Using Vanilla JavaScript

The following is a module with functions that demonstrates a simple way how to swap two HTML element locations in the Dom tree using JavaScript.

This method retains any existing event listeners.


1. Swap Element Locations

The example below demonstrates how to swap two HTML element locations.


2. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || Check If An Element Comes Before Or After Another Element In Dom Tree Using Vanilla JavaScript

The following is a module with functions that demonstrates a simple way how to check if an element comes before or after another element in the Dom tree using JavaScript.


1. Check If Before / After

The example below demonstrates how to check if an element is before or after another element.


2. Refined Search

The example below demonstrates how to check if an element is before or after another element by refining the search by a specific container.


3. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

JavaScript || How To Get The Next & Previous Multiple Of A Number Using Vanilla JavaScript

The following is a module with functions that demonstrates how to get the next and previous multiple of a number using Vanilla JavaScript.

If a number is already a multiple, there is a parameter that allows you to specify if it should be rounded or not.


1. Get Next Multiple – Include Existing

The example below demonstrates how to round up a number to the next multiple. In this example, if a number is already a multiple, it will not be rounded up to the next multiple.


2. Get Next Multiple – Skip Existing

The example below demonstrates how to round up a number to the next multiple. In this example, if a number is already a multiple, it will be rounded up to the next multiple.


3. Get Previous Multiple – Include Existing

The example below demonstrates how to round down a number to the previous multiple. In this example, if a number is already a multiple, it will not be rounded down to the previous multiple.


4. Get Previous Multiple – Skip Existing

The example below demonstrates how to round down a number to the previous multiple. In this example, if a number is already a multiple, it will be rounded down to the previous multiple.


5. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.