weekly release 2.4dev
[moodle.git] / lib / yuilib / 3.7.1 / build / features / features.js
blobc0f8df5d48d6d5c87f36ee73d7dc16d46bd232c1
1 /*
2 YUI 3.7.1 (build 5627)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('features', function (Y, NAME) {
9 var feature_tests = {};
11 /**
12 Contains the core of YUI's feature test architecture.
13 @module features
16 /**
17 * Feature detection
18 * @class Features
19 * @static
22 Y.mix(Y.namespace('Features'), {
23     
24     /**
25     * Object hash of all registered feature tests
26     * @property tests
27     * @type Object
28     */
29     tests: feature_tests,
30     
31     /**
32     * Add a test to the system
33     * 
34     *   ```
35     *   Y.Features.add("load", "1", {});
36     *   ```
37     * 
38     * @method add
39     * @param {String} cat The category, right now only 'load' is supported
40     * @param {String} name The number sequence of the test, how it's reported in the URL or config: 1, 2, 3
41     * @param {Object} o Object containing test properties
42     * @param {String} o.name The name of the test
43     * @param {Function} o.test The test function to execute, the only argument to the function is the `Y` instance
44     * @param {String} o.trigger The module that triggers this test.
45     */
46     add: function(cat, name, o) {
47         feature_tests[cat] = feature_tests[cat] || {};
48         feature_tests[cat][name] = o;
49     },
50     /**
51     * Execute all tests of a given category and return the serialized results
52     *
53     *   ```
54     *   caps=1:1;2:1;3:0
55     *   ```
56     * @method all
57     * @param {String} cat The category to execute
58     * @param {Array} args The arguments to pass to the test function
59     * @return {String} A semi-colon separated string of tests and their success/failure: 1:1;2:1;3:0
60     */
61     all: function(cat, args) {
62         var cat_o = feature_tests[cat],
63             // results = {};
64             result = [];
65         if (cat_o) {
66             Y.Object.each(cat_o, function(v, k) {
67                 result.push(k + ':' + (Y.Features.test(cat, k, args) ? 1 : 0));
68             });
69         }
71         return (result.length) ? result.join(';') : '';
72     },
73     /**
74     * Run a sepecific test and return a Boolean response.
75     *
76     *   ```
77     *   Y.Features.test("load", "1");
78     *   ```
79     *
80     * @method test
81     * @param {String} cat The category of the test to run
82     * @param {String} name The name of the test to run
83     * @param {Array} args The arguments to pass to the test function
84     * @return {Boolean} True or false if the test passed/failed.
85     */
86     test: function(cat, name, args) {
87         args = args || [];
88         var result, ua, test,
89             cat_o = feature_tests[cat],
90             feature = cat_o && cat_o[name];
92         if (!feature) {
93         } else {
95             result = feature.result;
97             if (Y.Lang.isUndefined(result)) {
99                 ua = feature.ua;
100                 if (ua) {
101                     result = (Y.UA[ua]);
102                 }
104                 test = feature.test;
105                 if (test && ((!ua) || result)) {
106                     result = test.apply(Y, args);
107                 }
109                 feature.result = result;
110             }
111         }
113         return result;
114     }
117 // Y.Features.add("load", "1", {});
118 // Y.Features.test("load", "1");
119 // caps=1:1;2:0;3:1;
121 /* This file is auto-generated by src/loader/scripts/meta_join.js */
122 var add = Y.Features.add;
123 // app-transitions-native
124 add('load', '0', {
125     "name": "app-transitions-native",
126     "test": function (Y) {
127     var doc  = Y.config.doc,
128         node = doc ? doc.documentElement : null;
130     if (node && node.style) {
131         return ('MozTransition' in node.style || 'WebkitTransition' in node.style);
132     }
134     return false;
136     "trigger": "app-transitions"
138 // autocomplete-list-keys
139 add('load', '1', {
140     "name": "autocomplete-list-keys",
141     "test": function (Y) {
142     // Only add keyboard support to autocomplete-list if this doesn't appear to
143     // be an iOS or Android-based mobile device.
144     //
145     // There's currently no feasible way to actually detect whether a device has
146     // a hardware keyboard, so this sniff will have to do. It can easily be
147     // overridden by manually loading the autocomplete-list-keys module.
148     //
149     // Worth noting: even though iOS supports bluetooth keyboards, Mobile Safari
150     // doesn't fire the keyboard events used by AutoCompleteList, so there's
151     // no point loading the -keys module even when a bluetooth keyboard may be
152     // available.
153     return !(Y.UA.ios || Y.UA.android);
155     "trigger": "autocomplete-list"
157 // dd-gestures
158 add('load', '2', {
159     "name": "dd-gestures",
160     "test": function(Y) {
161     return ((Y.config.win && ("ontouchstart" in Y.config.win)) && !(Y.UA.chrome && Y.UA.chrome < 6));
163     "trigger": "dd-drag"
165 // dom-style-ie
166 add('load', '3', {
167     "name": "dom-style-ie",
168     "test": function (Y) {
170     var testFeature = Y.Features.test,
171         addFeature = Y.Features.add,
172         WINDOW = Y.config.win,
173         DOCUMENT = Y.config.doc,
174         DOCUMENT_ELEMENT = 'documentElement',
175         ret = false;
177     addFeature('style', 'computedStyle', {
178         test: function() {
179             return WINDOW && 'getComputedStyle' in WINDOW;
180         }
181     });
183     addFeature('style', 'opacity', {
184         test: function() {
185             return DOCUMENT && 'opacity' in DOCUMENT[DOCUMENT_ELEMENT].style;
186         }
187     });
189     ret =  (!testFeature('style', 'opacity') &&
190             !testFeature('style', 'computedStyle'));
192     return ret;
194     "trigger": "dom-style"
196 // editor-para-ie
197 add('load', '4', {
198     "name": "editor-para-ie",
199     "trigger": "editor-para",
200     "ua": "ie",
201     "when": "instead"
203 // event-base-ie
204 add('load', '5', {
205     "name": "event-base-ie",
206     "test": function(Y) {
207     var imp = Y.config.doc && Y.config.doc.implementation;
208     return (imp && (!imp.hasFeature('Events', '2.0')));
210     "trigger": "node-base"
212 // graphics-canvas
213 add('load', '6', {
214     "name": "graphics-canvas",
215     "test": function(Y) {
216     var DOCUMENT = Y.config.doc,
217         useCanvas = Y.config.defaultGraphicEngine && Y.config.defaultGraphicEngine == "canvas",
218                 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),
219         svg = (DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"));
220     return (!svg || useCanvas) && (canvas && canvas.getContext && canvas.getContext("2d"));
222     "trigger": "graphics"
224 // graphics-canvas-default
225 add('load', '7', {
226     "name": "graphics-canvas-default",
227     "test": function(Y) {
228     var DOCUMENT = Y.config.doc,
229         useCanvas = Y.config.defaultGraphicEngine && Y.config.defaultGraphicEngine == "canvas",
230                 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),
231         svg = (DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"));
232     return (!svg || useCanvas) && (canvas && canvas.getContext && canvas.getContext("2d"));
234     "trigger": "graphics"
236 // graphics-svg
237 add('load', '8', {
238     "name": "graphics-svg",
239     "test": function(Y) {
240     var DOCUMENT = Y.config.doc,
241         useSVG = !Y.config.defaultGraphicEngine || Y.config.defaultGraphicEngine != "canvas",
242                 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),
243         svg = (DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"));
244     
245     return svg && (useSVG || !canvas);
247     "trigger": "graphics"
249 // graphics-svg-default
250 add('load', '9', {
251     "name": "graphics-svg-default",
252     "test": function(Y) {
253     var DOCUMENT = Y.config.doc,
254         useSVG = !Y.config.defaultGraphicEngine || Y.config.defaultGraphicEngine != "canvas",
255                 canvas = DOCUMENT && DOCUMENT.createElement("canvas"),
256         svg = (DOCUMENT && DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"));
257     
258     return svg && (useSVG || !canvas);
260     "trigger": "graphics"
262 // graphics-vml
263 add('load', '10', {
264     "name": "graphics-vml",
265     "test": function(Y) {
266     var DOCUMENT = Y.config.doc,
267                 canvas = DOCUMENT && DOCUMENT.createElement("canvas");
268     return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (!canvas || !canvas.getContext || !canvas.getContext("2d")));
270     "trigger": "graphics"
272 // graphics-vml-default
273 add('load', '11', {
274     "name": "graphics-vml-default",
275     "test": function(Y) {
276     var DOCUMENT = Y.config.doc,
277                 canvas = DOCUMENT && DOCUMENT.createElement("canvas");
278     return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (!canvas || !canvas.getContext || !canvas.getContext("2d")));
280     "trigger": "graphics"
282 // history-hash-ie
283 add('load', '12', {
284     "name": "history-hash-ie",
285     "test": function (Y) {
286     var docMode = Y.config.doc && Y.config.doc.documentMode;
288     return Y.UA.ie && (!('onhashchange' in Y.config.win) ||
289             !docMode || docMode < 8);
291     "trigger": "history-hash"
293 // io-nodejs
294 add('load', '13', {
295     "name": "io-nodejs",
296     "trigger": "io-base",
297     "ua": "nodejs"
299 // scrollview-base-ie
300 add('load', '14', {
301     "name": "scrollview-base-ie",
302     "trigger": "scrollview-base",
303     "ua": "ie"
305 // selector-css2
306 add('load', '15', {
307     "name": "selector-css2",
308     "test": function (Y) {
309     var DOCUMENT = Y.config.doc,
310         ret = DOCUMENT && !('querySelectorAll' in DOCUMENT);
312     return ret;
314     "trigger": "selector"
316 // transition-timer
317 add('load', '16', {
318     "name": "transition-timer",
319     "test": function (Y) {
320     var DOCUMENT = Y.config.doc,
321         node = (DOCUMENT) ? DOCUMENT.documentElement: null,
322         ret = true;
324     if (node && node.style) {
325         ret = !('MozTransition' in node.style || 'WebkitTransition' in node.style);
326     } 
328     return ret;
330     "trigger": "transition"
332 // widget-base-ie
333 add('load', '17', {
334     "name": "widget-base-ie",
335     "trigger": "widget-base",
336     "ua": "ie"
339 }, '3.7.1', {"requires": ["yui-base"]});