Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jquery-detect-environment

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery-detect-environment

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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.

Keywords

FAQs

Package last updated on 11 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc