Giter Site home page Giter Site logo

imclab / layout-engine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stowball/layout-engine

0.0 1.0 0.0 138 KB

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

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 IE10 and IE11.

The following layout engines are detected: 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) & 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 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 make 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 */
}
  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 UglifyJS (http://jscompress.com)

layout-engine's People

Contributors

stowball avatar

Watchers

 avatar

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.