npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mobiloud/ml-back-button

v1.0.2

Published

MobiLoud Back button

Downloads

7

Readme

Version Static Badge

MobiLoud Back Button

A back button in a native app allows users to navigate to the previously viewed screen or page within the app. It's essential for user experience, providing a quick and intuitive way to backtrack through a series of actions or views. Without a back button, users might feel disoriented or frustrated trying to navigate within the app.

This library provides a web based widget that replicates the native look and feel provided by the iOS and Android SDKs. The purpose is to add navigation options to a web app when running in a native app container, like what MobiLoud provides.

Here's an example:

ml-back-button.png

Features

ML Back Button features:

  • Configuration options:
    • Button text/label
    • Button colors
    • Position and animation
    • Display options: when user scrolls screen, on page load
    • Basic style settings, extensible with CSS
    • Options to replace elements and attach button to a container
    • Regex / url filtering, to avoid displaying the button in certain pages
  • deviceData method available: its a function that can be called to get the current browser OS, useful for triggering external functions'. It returns a string containing "android" | "ios" | "windows"
  • Default options set (if not texts, images or colors provided, it shows placeholder info, useful for catching errors or for testing while implementing the Button)
  • Button can be used as a module or used directly in an html / script tag
  • Code written in Typescript and minified/bundled with Vite

📖 How to use

ml-back-button can be used importing the JS code via CDN or as a module using NPM

🚀 With CDN

<script type="module" src="https://cdn.jsdelivr.net/npm/@mobiloud/ml-back-button/dist/ml-back-button.min.js"></script>
<script>
  function addBackButton() {
    new BackButton().init();
  }
  window.addEventListener('load', addBackButton);
</script>

Configuration options:

const options = {
/** Sets the button text color (if string is used in label); Example '#fff'*/
  textColor: string,
  /** Sets the button fill color (if svg is used in label); Example '#000'*/
  fillColor: string,
  /** Sets the button background color (if svg is used in label); Example '#000'*/
  buttonColorPrimary: string, 
  /** Sets the button label; Example 'Back', '<svg>...</svg>'*/
  label: string,
  /** Sets the button position when floating: 'top-right' | 'top-left' | 'bottom-left' | 'bottom-right' */
  position: 'top-right' | 'top-left' | 'bottom-left' | 'bottom-right',
  /** Sets the button entrance animation: 'fadeIn' | 'scaleUp' | 'slideBottom' | 'slideTop' | 'slideLeft' | 'slideRight' | null */
  animation: 'fadeIn' | 'scaleUp' | 'slideBottom' | 'slideTop' | 'slideLeft' | 'slideRight' | null, 
  /** Sets the button display type: 'onLoad' | 'onScrollDown' | 'onScrollUp' */
  display: 'onLoad' | 'onScrollDown' | 'onScrollUp', 
  /** Sets the button radius: css unit, 50% gives a rounded btn if same height/width; Example '50%' */
  radius: string,
  /** Sets the button width: css unit; Example '20px' */
  width: string,
  /** Sets the button inner padding: css unit; Example '1em' */
  padding: string,
  /** Defines how much time to wait until the element shows up (in ms); Example 1000 */
  delay: number, 
  /** If not null, button is injected into a container, it uses any html selectors; Example '.class', '#id', null  */
  containerSelector: string | null, 
  /** If container selector activated, it places the button before or after other elements; Example 'first' | 'last' | null */
  containerOrder: 'first' | 'last' | null,
  /** Sets text alignment, button has a flex container; Example 'center' | 'start' | 'end' */
  textAlign: 'center' | 'start' | 'end',
  /** If true applies soft shadow; Boolean */
  shadow: boolean,
  /** if a selector is placed here, this element would be replaced with the back button; Example '.className' '#idName' */
  replaceElement:  string | null,
  /** uses regex to avoid injecting button in certain pages; Example /(?:\/|\/home|\/someUrl|\/about|\/categories\/clothing)/ */
  regex: string | null,
  /** Display or not logs, useful when developing; Boolean */
  logs: boolean  
}

const BackButton = new BackButton(options);

Methods

deviceData.os // returns current os "android" | "ios" | "windows" | "desktop"
deviceData.isCanvas // returns true or false
deviceData.isMobile // returns true or false

Recipes

This are useful ways to implement the widget. We always recommend using an Event Listener to trigger the code when the document is loaded window.addEventListener('load', fnName)

Insert Back Button - desktop only

function addBackButton() {
	if(deviceData.isMobile || deviceData.isCanvas ){
		return
	}
    new BackButton(options).init();
  }
  window.addEventListener('load', addBackButton);

Using deviceData method to filter devices

const options = {
  // Set params here
}

// Insert widgets only in our Canvas platform
if(deviceData.isCanvas) {
const backButton = new BackButton(options);
}

// Apply specific configs based on OS
if(deviceData.os === "android" || deviceData.os === "windows") {
  const backButton = new BackButton(options1);
} 
if(deviceData.os === "desktop" || deviceData.os === "ios") {
  const backButton = new BackButton(options2);
}

// Insert widgets only in Mobile userAgent
if(deviceData.isMobile) {
const backButton = new BackButton(options3);
}

Development

  • npm run build produces a production version into /dist folder
  • npm run dev runs dev version and starts a dev server

Testing the Back Button

You will definitely want to test the Back Button once you deploy them to your website, to make sure that everything works and looks as you want.

Running these tests on real mobile devices can get overwhelming, so we recommend that you run your tests on your desktop browser.

To do this, you will need to emulate a mobile device by adjusting your browser’s user agent. We recommend using the following Chrome extension to do this: User Agent Switcher and Manager

Once you have installed the extension, set it up as follows:

Step 1

Select “Chrome” as the browser and “Android” as the platform if you want to test the Android version of the Button, or “Safari” and “iOS” in case you want to test the iOS version:

annotely_image (61).png

Step 2

Select one of the options that will appear, any will work:

annotely_image (62).png

Step 3

Click “Apply” to make sure the user agent is properly set up on your browser:

annotely_image (63).png

Step 4

You can now press “F5” while viewing your website to refresh the browser window with the updated user agent.

Reset

If you want to revert the changes to the user agent, as some websites might start behaving differently after doing so, you can click the “Reset” button:

annotely_image (64).png

License

Copyright (c) MobiLoud