Giter Club home page Giter Club logo

w's Introduction

W 1.7.0

In responsive development with javascript, we often need to know the correct viewport size, without caring of the environment or the media orientation. Desktop browsers return correct values but mobiles are a big mess.

Moreover, we need to know when the text has been resized or the media orientation has changed, so we can adapt our layout accordingly.

W aims to solve this for you.

Please note that if you want to support mobile devices well I advise you to use this meta markup : <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no">. This line of code should really be present in any website.

Install

You can pick the minified library or install it with :

npm install pyrsmk-w
bower install pyrsmk-w

Syntax

// Get the orientation of the device (return 'portrait' or 'landscape')
W.getOrientation();
// Get the current viewport width
W.getViewportWidth();
// Get the current viewport height
W.getViewportHeight();
// Get viewport dimensions; returns {width: integer, height: integer}
W.getViewportDimensions();
// Add a listener to catch responsive events (key is optional) (you can register several listeners with the same keyword)
W.addListener(function(){}, 'key');
// Remove a listener
W.removeListener('key');
// Clear all listeners
W.clearListeners();

For ease of use, when you register a listener W returns it, so you can reuse that very same callback :

$(window).listen('scroll', W.addListener(function() {
    console.log("Hi! I'm the one who detects scroll and responsive events!");
}));

You can retrieve viewport's width/height in absolute mode (eg. screen resolution) to unify JS and CSS behaviors :

W.getViewportWidth(true);
W.getViewportHeight(true);

If needed, you can trigger your listeners on demand :

// Trigger all listeners
W.trigger();
// Trigger all listeners registered with the 'key' keyword
W.trigger('key');

You can also manually trigger a listener directly by calling it, since the callback is returned by W :

W.addListener(function(){
	// Blah blah
})();

License

W is licensed under the MIT license.

w's People

Contributors

brianally avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

w's Issues

on iPhone

For some reason this code :

W(function() {
    console.log("W");
})

Consoles a W on a scroll action on Safari iPhone. Is it a normal behaviour ?

Remove listener

Hi, is there a way to remove the listener? Thanks for developing this tool.

IE8 bug [IETester]

IE8 throw an error telling that the parent element can't be modified while a child element is not closed. I didn't see this issue with IE9's IE8 mode or with an IE8 installed on wine. Maybe someone could test that on a clean Windows XP?

Call for help!

Hi!

I put online a page that collect data on OS, browser, and several values to have a better resolution detection on W. iOS8 has been just released and the current version of W dosn't handle it correctly, then I think it's time to modify some code. I especially need data about iOS6/7 and Windows Phone.

Thanks a lot!

http://pyrsmk.ddns.net/W

IE5.5 incompatibilities

Internet Explorer 5.5 will probably never be supported: document.documentElement.offsetWidth returns 0 and the em unit too. But keep this opened for the moment.

Bad unit value under IE6/7

Internet Explorer 6 and 7 can't guess the unit value at the core of the em computing of W. This comes from a bad offsetWidth value returned by the browser. It seems the created span is not initiliazed properly.

Therefore, this unit value is fixed to 16 while this bug is not fixed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.