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

angular-matchmedia

v1.0.0

Published

Angular-matchmedia service is a set of bindings and helper functions for the browser matchMedia api.

Downloads

415

Readme

Angular matchMedia Service

This service is a set of bindings and helper functions for the browser matchMedia api. It allows you to check any media query right in your AngularJS application. It has one core method check and few helper shortcuts (see examples below). Also, you can configure service rules on config stage of your AngularJS app.

Install via npm

$ npm install --save-dev angular-matchmedia

or you can download archive on Releases page.

After that just include dist/angular-matchmedia.js file in your application (between main AngularJS library and your app js file).

Methods

Core method

  • check(mediaQueryString)

Method allows you to check any media query right in your controller or service. You should pass just one parameter: any media query. Methods returns true or false depending on media query result.

app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isThisIphone6 = matchMedia.check('only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)');
});

Helpers

  • isPhone

Method allows you to check if your application is viewed on mobile device (according to the following default media query rule: (max-width: 767px)).

app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isThisIphone6 = matchMedia.check('only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)');
});
  • isTablet

Method allows you to check if your application is viewed on tablet (according to the following default media query rule: (min-width: 768px) and (max-width: 1024px)).

app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isThisIphone6 = matchMedia.check('only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)');
});
  • isDesktop

Method allows you to check if your application is viewed on desktop (according to the following default media query rule: (min-width: 1025px)).

app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isThisIphone6 = matchMedia.check('only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)');
});
  • isPortrait

Method allows you to check if your application is viewed on device with portrait orientation (according to the following default media query rule: (orientation: portrait)).

app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isThisIphone6 = matchMedia.check('only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)');
});
  • isLandscape

Method allows you to check if your application is viewed on device with landscape orientation (according to the following default media query rule: (orientation: landscape)).

app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isThisIphone6 = matchMedia.check('only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)');
});
  • isRetina

Method allows you to check if your application is viewed on retina device (according to the following default media query rule: (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)).

app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isThisIphone6 = matchMedia.check('only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)');
});

DEMO

You can check live demo of this service on Plunker.

Usage example

// add dependency to your application
var app = angular.module('application', ['angular-matchmedia']);

// you can change default `rules` of the service (set your own breakpoints) in your app config
app.config(["matchMediaProvider", function(matchMediaProvider) {
    matchMediaProvider.rules.phone = '(max-width: 767px)';
    matchMediaProvider.rules.tablet = '(min-width: 768px) and (max-width: 988px)';
}]);

// inject service into your controller and you are ready to go
app.controller('MainCtrl', function($scope, matchMedia) {
    $scope.isTablet = matchMedia.isTablet();
    $scope.isRetina = matchMedia.isRetina();
});

Default rules (helper breakpoints)

rules = {
    phone: '(max-width: 767px)',
    tablet: '(min-width: 768px) and (max-width: 1024px)',
    desktop: '(min-width: 1025px)',
    portrait: '(orientation: portrait)',
    landscape: '(orientation: landscape)',
    retina: '(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)'
}

TODO

  • add additional helpers
  • ability to register custom helpers (not sure if it is needed)
  • ability to override existing helper methods

License

MIT © Sergey Lysenko