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

adaptivemagic

v1.0.5

Published

The plugin for execuding JS code by different screen's breakpoints. It's adaptive magic of the execuding.

Downloads

8

Readme

What is AdaptiveMagic?

Adaptive Magic is a magic tool giving you to execude your code by different screen's widht sizes in JavaScript code. You can think about like breakpoints for media queries in CSS but only in JavaScript.

Install

It's easy!

npm i --save adaptivemagic

Examples

You can play around on dev-server with completed examples just folow this instructions.

 1. Clone the repository - git clone https://github.com/Wishez/AdaptiveMagic.git.

  1. Open a console, go to the "test" folder in the clopied repository - cd path/to/repo/test, run npm i, and wait.

 3. A last step is to run simple command ー gulp.

The files, you can change and play, is placed in src folder.

That's it!

Usage

Import it:

import AM from 'adaptivemagic';

or use

const AM = require('adaptivemagic');

The Adaptive Magic has magic breakpoints by default:


// The page loading  
window.addEventListener('load', function() {
    const $testBlock = document.getElementById('#testBlock');  
    const changeContent = text => {
        $testBlock.innerHTML = text;
    };
    
    // And code is executing
  
  AM.doBy('lgUp', () => {
  	changeContent(
  		'Cahnge text by Large and Up screen\'s width.'
  	);
  }); // end doBy lgUp
    
  AM.doBy('md', () => {
  	changeContent(
  		  'Cahnge text by Medium screen.'
  	);
  }); // end doBy md
  
	AM.doBy('sm', () => {
  	changeContent(
  		'Cahnge text by Small screen.'
  	);
	}); // end doBy sm
    
  AM.doBy('xs', () => {
  	changeContent(
  		'Cahnge text by Extra-small screen.'
    	);
	}); // end doBy xs
    
    	AM.doBy('xxs', () => {
  	changeContent(
  		'Cahnge text by Extra-extra-small screen.'
  	);
  }); // end doBy xxs    
});

But you can custom yours own breakpoints and execute your code when browser's window is resized just user a plain object instead a default breakpoint name:

```javascript 
const xsToLg = {
	name: 'xsToLg',
min: 779,
max: 1200
};
```

1. The name is needed for not repeating code by same screen's width when the page is resized. It's required.

2. A min value is a min value of a screen's width.

3. A max value is  a screen's width's max value.

  You can leave one of min or max. It means, code will execute - while a screen's width isn't max, or a screen's width isn't min, but one of them is necessery, otherwise, you won't get the magic effect. Keep in mind!

 ```javascript

window.addEventListener('load', function() { 
  const xsToAlmostMd = {
  	  name: 'xsToAlmostMd',
      min: 799,
      max: 850
  };
  
  window.addEventListener('resize', function() {
  
      AM.doBy(
    xsToAlmostMd,
        () => {
          // Func from last example.
          changeContent(
            'It shows content when the screen\'s widht is between 790px and 850px.'
          );
        }
    ); // end doBy
  }); // end resize event
}); // end load event

And last thing is to execute code ever by a set breakpoint when a screen's width will be changed. 
Use function  **AM.changeLimitationMode**.

```javascript
window.addEventListener('load', function() { 
    window.addEventListener('resize', function() {

        AM.doBy('sm', () => {
        changeContent(
  	      'Cahnge text by Small screen.'
        );
  
        console.log('It limits the execution when the screen\'s width same.');
        AM.changeLimitationMode(true);
    	  }); // end doBy sm
        
        AM.doBy('xs', () => {
        changeContent(
  	      'Cahnge text by Extra-small screen.'
        );
        
        console.log('The Code by xs screen\'s width will be calling very often.');
        AM.changeLimitationMode(false);
    	}); // end doBy xs 
    }) // end resize event
    
}); // end load event

About author

He is, absorbing knowledge of web-development, developer.

It's his first documentation. Did you get what he wrote about? 

   And if not, just write him ー [email protected]

License

AdaptiveMagic has MIT license. Don't worry about, just use it!