Giter Site home page Giter Site logo

stowball / layout-engine Goto Github PK

View Code? Open in Web Editor NEW
95.0 14.0 18.0 23 KB

Adds the rendering engine name as a class on the html tag and returns a JavaScript object containing the vendor, version and browser name (where appropriate)

Home Page: http://mattstow.com/experiment/layout-engine/demo.html

License: MIT License

JavaScript 100.00%
javascript

layout-engine's Introduction

Layout Engine

Browser detection done right

Adds the rendering engine and browser names as a class on the html tag and returns a JavaScript object containing the vendor, version and browser name (where appropriate)

Layout Engine uses feature detection so there can never be a false positive* and vendors cannot be spoofed. It's the simplest and most reliable way to target Edge, IE11 and IE10.

The following layout engines are detected: edge, ie, khtml, mozilla, opera & webkit

The following versions are detected: ie- 11, 10, 9, 8, 7 & opera- mini

The following WebKit browsers are detected: android, chrome (includes Opera Blink and Android 5+ WebView), safari, safari-ios & wiiu

Up to 3 classes are applied to <html> with the syntax: .vendor-vendor_name, .vendor-vendor_name-version (optional) and .browser-browser_name (optional).

A JavaScript object with up to 3 properties is exposed: layoutEngine.vendor, layoutEngine.version (optional) and layoutEngine.browser (optional).

Layout Engine will also identify the default Android v2-4 Browser (and its WebView variants), by adding a class of browser-android to <html>. Unfortunately, it has to use UA sniffing to do so. Anyway… why might you need to detect the Android Browser? Applying a border or background to <select>s makes them render as text inputs. Also, AOSP Browser's radio buttons and checkboxes are very badly positioned compared to other browsers.


Demo and Further Info:


Usage:

  1. Reference layout.engine.min.js in the <head> of your document

  2. In your CSS, use a vendor class to style elements appropriately, e.g.:

.vendor-ie-10 {
	line-height: 20px; /* 1px more than IE 8 */
}

.browser-safari-ios .text-input {
	font-size: 16px; /* Prevent zooming in on iOS form inputs */
}
  1. If appropriate, in your JavaScript, use layoutEngine.vendor, layoutEngine.version and layoutEngine.browser to run conditional functions where relevant, e.g.:
if (layoutEngine.vendor === 'ie' && layoutEngine.version === 10) {
	// Conditional script
}

Caveats:

IE 8, 9 and 10's Browser and Document Modes incorrectly detect IE 7 as IE 8. Real IE 7 works as intended, however.

IE 6 cannot be detected with Layout Engine. I recommend using IE Conditional Comments to target IE 6 and 7 instead.


Minified version created with Online JavaScript/CSS/HTML Compressor

layout-engine's People

Contributors

stowball 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

Watchers

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

layout-engine's Issues

Bower support

Hello!

It would be nice to have Bower support!

Thank you!

Does not identify Opera correctly

It looks like it cannot identify Opera correctly after its switch to the Blink engine. I am using Opera 17.0.1241.53 and the test page says that I'm on Chrome.

Perfect

Inserts the html tag, ok.

Now, if I want this class to be put on a li?

For example

li class="vendor-ie-10"

Help, please

Detection is wrong for IE11/Mobile

On IE11/Mobile (Windows Phone 8.1, Nokia Lumia 930), Layout Engine 0.8.2 reports class="vendor-webkit browser-android".

Sample User-Agent: Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

Add MIT license?

I'd like to include Layout Engine in a Drupal Theme that's on drupal.org but it only allows for GPL as per this page: https://drupal.org/licensing/faq

Referring to the MIT license, it states:
It is not possible to distribute a module that integrates a non-GPL compatible library with Drupal, because it would be a derivative work of both Drupal and that other library and would therefore violate either the GPL or the license of the other library.

So I'm wondering if it's possible to change the license to GPL MIT .

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.