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

jquery-detect-environment

v1.0.0

Published

A lightweight jQuery plugin that dynamically adds CSS classes to the html tag

Downloads

5

Readme

jQuery Detect Environment Plugin

A lightweight jQuery plugin that dynamically adds CSS classes to the <html> tag based on the device type, operating system, screen size, orientation, browser, internet connection, time of day, color scheme preference, and pixel density. This helps create responsive and adaptive designs easily.

Demo

View Live Demo

Features

The plugin automatically detects and adds classes for:

  • Device Type: device-mobile or device-desktop
  • Operating System: os-windows, os-macos, os-linux, os-android, os-ios
  • Screen Width (Bootstrap-based): width-xs, width-sm, width-md, width-lg, width-xl
  • Screen Orientation: orientation-portrait or orientation-landscape
  • Browser: browser-chrome, browser-firefox, browser-safari, browser-edge
  • Internet Connection Status: status-online or status-offline
  • Time of Day: time-morning, time-afternoon, time-evening, time-night
  • Color Scheme Preference: prefers-dark-mode or prefers-light-mode
  • Pixel Density: pixel-ratio-1x, pixel-ratio-2x, or pixel-ratio-3x

Installation

  1. Include jQuery in your project (if not already included):

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  2. Include the plugin script (choose between the full or minified version):

    • Full version:
      <script src="path/to/jquery.detect-environment.js"></script>
    • Minified version:
      <script src="path/to/jquery.detect-environment.min.js"></script>

Usage

The plugin initializes automatically when the document is ready and dynamically adds classes to the <html> tag. It also listens for window resize, orientation change, and network connection events to update classes in real-time.

$(document).ready(function() {
    $('html').detectEnvironment();
});

The classes added to <html> will update automatically, so you can use them directly in your CSS for responsive and adaptive design.

Example

With this plugin, the <html> tag might look like:

<html class="device-desktop os-windows width-lg orientation-landscape browser-chrome status-online time-afternoon prefers-light-mode pixel-ratio-2x">...</html>

Explanation of Classes

Here are some sample classes and what they represent:

  • device-mobile / device-desktop: Based on device type (mobile or desktop).
  • os-windows, os-macos, os-linux, os-android, os-ios: Operating system detected.
  • width-xs, width-sm, width-md, width-lg, width-xl: Screen width based on Bootstrap breakpoints.
  • orientation-portrait / orientation-landscape: Current screen orientation.
  • browser-chrome, browser-firefox, browser-safari, browser-edge: Browser type.
  • status-online / status-offline: Internet connection status.
  • time-morning, time-afternoon, time-evening, time-night: Time of day for time-based styling.
  • prefers-dark-mode / prefers-light-mode: User’s color scheme preference (from system settings).
  • pixel-ratio-1x, pixel-ratio-2x, pixel-ratio-3x: Screen pixel density, for handling high DPI displays.

Events

The plugin listens for the following events to update classes dynamically:

  • Window Resize: Adjusts width classes and orientation as the window size changes.
  • Orientation Change: Updates orientation classes when the device orientation changes.
  • Online/Offline: Changes connection status classes depending on network status.

License

This project is licensed under the MIT License.


This portion of the README.md file provides examples and explanations of the classes generated by the plugin, describes the events it listens for, and includes a brief note on the license. It’s designed to help users understand how to work with the classes generated by the plugin for responsive design.