features.js revision b13fa92174ae8a0c808a88984ae029a542b6dd7d
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt SweeneyContains the core of YUI's feature test architecture.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney@module features
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney* Feature detection
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney* @class Features
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * Object hash of all registered feature tests
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @property tests
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @type Object
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * Add a test to the system
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * Y.Features.add("load", "1", {});
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method add
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {String} cat The category, right now only 'load' is supported
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {String} name The number sequence of the test, how it's reported in the URL or config: 1, 2, 3
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {Object} o Object containing test properties
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {String} o.name The name of the test
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {Function} o.test The test function to execute, the only argument to the function is the `Y` instance
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {String} o.trigger The module that triggers this test.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * Execute all tests of a given category and return the serialized results
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * caps=1:1;2:1;3:0
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method all
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {String} cat The category to execute
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {Array} args The arguments to pass to the test function
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {String} A semi-colon separated string of tests and their success/failure: 1:1;2:1;3:0
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // results = {};
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney result.push(k + ':' + (Y.Features.test(cat, k, args) ? 1 : 0));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (result.length) ? result.join(';') : '';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * Run a sepecific test and return a Boolean response.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * Y.Features.test("load", "1");
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method test
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {String} cat The category of the test to run
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {String} name The name of the test to run
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {Array} args The arguments to pass to the test function
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {Boolean} True or false if the test passed/failed.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// Y.Features.add("load", "1", {});
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// Y.Features.test("load", "1");
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// caps=1:1;2:0;3:1;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney/* This file is auto-generated by src/loader/scripts/meta_join.py */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// graphics-canvas-default
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney canvas = DOCUMENT && DOCUMENT.createElement("canvas");
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (canvas && canvas.getContext && canvas.getContext("2d")));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// autocomplete-list-keys
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function (Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // Only add keyboard support to autocomplete-list if this doesn't appear to
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // be an iOS or Android-based mobile device.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // There's currently no feasible way to actually detect whether a device has
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // a hardware keyboard, so this sniff will have to do. It can easily be
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // overridden by manually loading the autocomplete-list-keys module.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // Worth noting: even though iOS supports bluetooth keyboards, Mobile Safari
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // doesn't fire the keyboard events used by AutoCompleteList, so there's
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // no point loading the -keys module even when a bluetooth keyboard may be
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // available.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// dd-gestures
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (Y.config.win && ('ontouchstart' in Y.config.win && !Y.UA.chrome));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// history-hash-ie
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function (Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var docMode = Y.config.doc && Y.config.doc.documentMode;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return Y.UA.ie && (!('onhashchange' in Y.config.win) ||
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// transition-timer
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function (Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney node = (DOCUMENT) ? DOCUMENT.documentElement: null,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ret = !('MozTransition' in node.style || 'WebkitTransition' in node.style);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// graphics-svg-default
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// scrollview-base-ie
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// widget-base-ie
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// dom-style-ie
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function (Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney test: function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney test: function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return DOCUMENT && 'opacity' in DOCUMENT[DOCUMENT_ELEMENT].style;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// selector-css2
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function (Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney ret = DOCUMENT && !('querySelectorAll' in DOCUMENT);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// event-base-ie
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var imp = Y.config.doc && Y.config.doc.implementation;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (imp && (!imp.hasFeature('Events', '2.0')));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// graphics-svg
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// graphics-vml-default
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney canvas = DOCUMENT && DOCUMENT.createElement("canvas");
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (!canvas || !canvas.getContext || !canvas.getContext("2d")));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// graphics-canvas
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney canvas = DOCUMENT && DOCUMENT.createElement("canvas");
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (canvas && canvas.getContext && canvas.getContext("2d")));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney// graphics-vml
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney "test": function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney canvas = DOCUMENT && DOCUMENT.createElement("canvas");
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (!canvas || !canvas.getContext || !canvas.getContext("2d")));