Skip to content

Commit

Permalink
finished porting tests to AMD
Browse files Browse the repository at this point in the history
  • Loading branch information
SlexAxton committed Nov 7, 2012
1 parent ba0b0d5 commit d4c2950
Show file tree
Hide file tree
Showing 68 changed files with 809 additions and 708 deletions.
16 changes: 7 additions & 9 deletions feature-detects/custom-protocol-handler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/*
Custom protocol handler support
http://developers.whatwg.org/timers.html#custom-handlers
Added by @benschwarz
*/

Modernizr.addTest('customprotocolhandler', function () {
return !!navigator.registerProtocolHandler;
define(['Modernizr'], function( Modernizr ) {
/*
Custom protocol handler support
http://developers.whatwg.org/timers.html#custom-handlers
Added by @benschwarz
*/
Modernizr.addTest('customprotocolhandler', !!navigator.registerProtocolHandler);
});
11 changes: 6 additions & 5 deletions feature-detects/dart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Dart
// By Theodoor van Donge
define(['Modernizr', 'prefixed'], function( Modernizr, prefixed ) {
// Dart
// By Theodoor van Donge
// https://chromiumcodereview.appspot.com/9232049/

// https://chromiumcodereview.appspot.com/9232049/

Modernizr.addTest('dart', !!Modernizr.prefixed('startDart', navigator));
Modernizr.addTest('dart', !!prefixed('startDart', navigator));
});
10 changes: 6 additions & 4 deletions feature-detects/dataview-api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// DataView
// https://developer.mozilla.org/en/JavaScript_typed_arrays/DataView
// By Addy Osmani
Modernizr.addTest('dataview', (typeof DataView !== 'undefined' && 'getFloat64' in DataView.prototype));
define(['Modernizr'], function( Modernizr ) {
// DataView
// https://developer.mozilla.org/en/JavaScript_typed_arrays/DataView
// By Addy Osmani
Modernizr.addTest('dataview', (typeof DataView !== 'undefined' && 'getFloat64' in DataView.prototype));
});
11 changes: 6 additions & 5 deletions feature-detects/draganddrop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define(['Modernizr', 'createElement'], function( Modernizr, createElement ) {
// http://dev.w3.org/html5/spec/dnd.html

// http://dev.w3.org/html5/spec/dnd.html

Modernizr.addTest('draganddrop', function () {
var div = document.createElement('div');
return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
Modernizr.addTest('draganddrop', function() {
var div = createElement('div');
return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
});
});
22 changes: 12 additions & 10 deletions feature-detects/emoji.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Requires a Modernizr build with `canvastext` included
// http://www.modernizr.com/download/#-canvas-canvastext
Modernizr.addTest('emoji', function() {
if (!Modernizr.canvastext) return false;
var node = document.createElement('canvas'),
ctx = node.getContext('2d');
ctx.textBaseline = 'top';
ctx.font = '32px Arial';
ctx.fillText('\ud83d\ude03', 0, 0); // "smiling face with open mouth" emoji
return ctx.getImageData(16, 16, 1, 1).data[0] !== 0;
define(['Modernizr', 'createElement', 'test/canvastext'], function( Modernizr, createElement ) {
// Requires a Modernizr build with `canvastext` included
// http://www.modernizr.com/download/#-canvas-canvastext
Modernizr.addTest('emoji', function() {
if (!Modernizr.canvastext) return false;
var node = createElement('canvas'),
ctx = node.getContext('2d');
ctx.textBaseline = 'top';
ctx.font = '32px Arial';
ctx.fillText('\ud83d\ude03', 0, 0); // "smiling face with open mouth" emoji
return ctx.getImageData(16, 16, 1, 1).data[0] !== 0;
});
});
51 changes: 25 additions & 26 deletions feature-detects/exif-orientation.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
// EXIF Orientation test
define(['Modernizr'], function( Modernizr ) {
// EXIF Orientation test

// iOS looks at the EXIF Orientation flag in jpgs and rotates the image
// accordingly. Looks like most desktop browsers just ignore this data.
// iOS looks at the EXIF Orientation flag in jpgs and rotates the image
// accordingly. Looks like most desktop browsers just ignore this data.

// description:
// recursive-design.com/blog/2012/07/28/exif-orientation-handling-is-a-ghetto/
// www.impulseadventure.com/photo/exif-orientation.html
// description:
// recursive-design.com/blog/2012/07/28/exif-orientation-handling-is-a-ghetto/
// www.impulseadventure.com/photo/exif-orientation.html

// Bug trackers:
// bugzil.la/298619 (unimplemented)
// crbug.com/56845 (looks incomplete)
// webk.it/19688 (available upstream but its up all ports to turn on individually)
//
// Bug trackers:
// bugzil.la/298619 (unimplemented)
// crbug.com/56845 (looks incomplete)
// webk.it/19688 (available upstream but its up all ports to turn on individually)
//

// detect by Paul Sayre
// detect by Paul Sayre

Modernizr.addAsyncTest(function() {
var img = new Image();

(function(){
img.onerror = function() {
Modernizr.addTest('exif-orientation', false);
};

var img = new Image();
img.onload = function() {
Modernizr.addTest('exif-orientation', img.width !== 2);
};

img.onerror = function() {
Modernizr.addTest('exif-orientation', function () { return false; });
};

img.onload = function() {
Modernizr.addTest('exif-orientation', function () { return img.width !== 2; });
};

// There may be a way to shrink this more, it's a 1x2 white jpg with the orientation flag set to 6
img.src = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAASUkqAAgAAAABABIBAwABAAAABgASAAAAAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAABAAIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+/iiiigD/2Q==";

})();
// There may be a way to shrink this more, it's a 1x2 white jpg with the orientation flag set to 6
img.src = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAASUkqAAgAAAABABIBAwABAAAABgASAAAAAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAABAAIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+/iiiigD/2Q==";
});
});
39 changes: 19 additions & 20 deletions feature-detects/forms/inputnumber-l10n.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
// input[type="number"] localized input/output
// // Detects whether input type="number" is capable of receiving and
// // displaying localized numbers, e.g. with comma separator
// // https://bugs.webkit.org/show_bug.cgi?id=42484
// // Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js?rev=80096#L9
// // By Peter Janes
define(['Modernizr', 'createElement', 'docElement'], function( Modernizr, createElement, docElement ) {
// input[type="number"] localized input/output
// // Detects whether input type="number" is capable of receiving and
// // displaying localized numbers, e.g. with comma separator
// // https://bugs.webkit.org/show_bug.cgi?id=42484
// // Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js?rev=80096#L9
// // By Peter Janes

Modernizr.addTest('localizedNumber', function() {
var doc = document,
el = document.createElement('div'),
fake,
root,
input,
diff;
root = doc.body || (function() {
var de = doc.documentElement;
fake = true;
return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild);
Modernizr.addTest('localizedNumber', function() {
var el = createElement('div');
var fake;

var root = document.body || (function() {
fake = true;
return docElement.insertBefore(createElement('body'), docElement.firstElementChild || docElement.firstChild);
}());
el.innerHTML = '<input type="number" value="1.0" step="0.1"/>';
input = el.childNodes[0];
var input = el.childNodes[0];
root.appendChild(el);
input.focus();
try {
doc.execCommand('InsertText', false, '1,1');
document.execCommand('InsertText', false, '1,1');
} catch(e) { // prevent warnings in IE
}
diff = input.type === 'number' && input.valueAsNumber === 1.1 && input.checkValidity();
var diff = input.type === 'number' && input.valueAsNumber === 1.1 && input.checkValidity();
root.removeChild(el);
fake && root.parentNode.removeChild(root);
return diff;
});

});
12 changes: 3 additions & 9 deletions feature-detects/forms/placeholder.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// testing for placeholder attribute in inputs and textareas
// re-using Modernizr.input if available

Modernizr.addTest('placeholder', function(){

return !!( 'placeholder' in ( Modernizr.input || document.createElement('input') ) &&
'placeholder' in ( Modernizr.textarea || document.createElement('textarea') )
);

define(['Modernizr', 'createElement'], function( Modernizr, createElement ) {
// testing for placeholder attribute in inputs and textareas
Modernizr.addTest('placeholder', !!('placeholder' in createElement('input') && 'placeholder' in createElement('textarea')));
});
26 changes: 14 additions & 12 deletions feature-detects/forms/speechinput.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// speech input for inputs
// by @alrra
define(['Modernizr', 'createElement'], function( Modernizr, createElement ) {
// speech input for inputs
// by @alrra


// `webkitSpeech` in elem
// doesn`t work correctly in all versions of Chromium based browsers.
// It can return false even if they have support for speech i.imgur.com/2Y40n.png
// Testing with 'onwebkitspeechchange' seems to fix this problem
// `webkitSpeech` in elem
// doesn`t work correctly in all versions of Chromium based browsers.
// It can return false even if they have support for speech i.imgur.com/2Y40n.png
// Testing with 'onwebkitspeechchange' seems to fix this problem

// this detect only checks the webkit version because
// the speech attribute is likely to be deprecated in favor of a JavaScript API.
// http://lists.w3.org/Archives/Public/public-webapps/2011OctDec/att-1696/speechapi.html
// this detect only checks the webkit version because
// the speech attribute is likely to be deprecated in favor of a JavaScript API.
// http://lists.w3.org/Archives/Public/public-webapps/2011OctDec/att-1696/speechapi.html

// FIXME: add support for detecting the new spec'd behavior
// FIXME: add support for detecting the new spec'd behavior

Modernizr.addTest('speechinput', function(){
var elem = document.createElement('input');
Modernizr.addTest('speechinput', function() {
var elem = createElement('input');
return 'speech' in elem || 'onwebkitspeechchange' in elem;
});
});
106 changes: 48 additions & 58 deletions feature-detects/forms/validation.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,73 @@
// This implementation only tests support for interactive form validation.
// To check validation for a specific type or a specific other constraint,
// the test can be combined:
// - Modernizr.inputtypes.numer && Modernizr.formvalidation (browser supports rangeOverflow, typeMismatch etc. for type=number)
// - Modernizr.input.required && Modernizr.formvalidation (browser supports valueMissing)
//
(function(document, Modernizr){


Modernizr.formvalidationapi = false;
Modernizr.formvalidationmessage = false;

Modernizr.addTest('formvalidation', function(){
var form = document.createElement('form');
if ( !('checkValidity' in form) ) {
define(['Modernizr', 'createElement', 'docElement'], function( Modernizr, createElement, docElement ) {
// This implementation only tests support for interactive form validation.
// To check validation for a specific type or a specific other constraint,
// the test can be combined:
// - Modernizr.inputtypes.numer && Modernizr.formvalidation (browser supports rangeOverflow, typeMismatch etc. for type=number)
// - Modernizr.input.required && Modernizr.formvalidation (browser supports valueMissing)
//

Modernizr.addTest('formvalidation', function() {
var form = createElement('form');
if ( !('checkValidity' in form) ) {
return false;
}
var body = document.body,

html = document.documentElement,

bodyFaked = false,
}
var body = document.body;
var html = docElement;
var bodyFaked = false;
var invaildFired = false;
var input;

invaildFired = false,
Modernizr.formvalidationapi = true;

input;

Modernizr.formvalidationapi = true;

// Prevent form from being submitted
form.onsubmit = function(e) {
// Prevent form from being submitted
form.onsubmit = function(e) {
//Opera does not validate form, if submit is prevented
if ( !window.opera ) {
e.preventDefault();
e.preventDefault();
}
e.stopPropagation();
};
};

// Calling form.submit() doesn't trigger interactive validation,
// use a submit button instead
//older opera browsers need a name attribute
form.innerHTML = '<input name="modTest" required><button></button>';
// Calling form.submit() doesn't trigger interactive validation,
// use a submit button instead
//older opera browsers need a name attribute
form.innerHTML = '<input name="modTest" required><button></button>';

// FF4 doesn't trigger "invalid" event if form is not in the DOM tree
// Chrome throws error if invalid input is not visible when submitting
form.style.position = 'absolute';
form.style.top = '-99999em';
// FF4 doesn't trigger "invalid" event if form is not in the DOM tree
// Chrome throws error if invalid input is not visible when submitting
form.style.position = 'absolute';
form.style.top = '-99999em';

// We might in <head> in which case we need to create body manually
if ( !body ) {
// We might in <head> in which case we need to create body manually
if ( !body ) {
bodyFaked = true;
body = document.createElement('body');
body = createElement('body');
//avoid crashing IE8, if background image is used
body.style.background = "";
html.appendChild(body);
}
}

body.appendChild(form);
body.appendChild(form);

input = form.getElementsByTagName('input')[0];
input = form.getElementsByTagName('input')[0];

// Record whether "invalid" event is fired
input.oninvalid = function(e) {
// Record whether "invalid" event is fired
input.oninvalid = function(e) {
invaildFired = true;
e.preventDefault();
e.stopPropagation();
};
};

//Opera does not fully support the validationMessage property
Modernizr.formvalidationmessage = !!input.validationMessage;
//Opera does not fully support the validationMessage property
Modernizr.formvalidationmessage = !!input.validationMessage;

// Submit form by clicking submit button
form.getElementsByTagName('button')[0].click();
// Submit form by clicking submit button
form.getElementsByTagName('button')[0].click();

// Don't forget to clean up
body.removeChild(form);
bodyFaked && html.removeChild(body);
// Don't forget to clean up
body.removeChild(form);
bodyFaked && html.removeChild(body);

return invaildFired;
return invaildFired;
});
});


})(document, window.Modernizr);
20 changes: 11 additions & 9 deletions feature-detects/fullscreen-api.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Modernizr.addTest('fullscreen',function(){
for(var i = 0; i < Modernizr._domPrefixes.length; i++) {
if( document[Modernizr._domPrefixes[i].toLowerCase() + 'CancelFullScreen'])
return true;
}
return !!document['cancelFullScreen'] || false;
});
define(['Modernizr', 'domPrefixes'], function( Modernizr, domPrefixes ) {
Modernizr.addTest('fullscreen',function() {
for (var i = 0; i < domPrefixes.length; i++) {
if( document[domPrefixes[i].toLowerCase() + 'CancelFullScreen'])
return true;
}
return !!document['cancelFullScreen'] || false;
});

// http://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html#//apple_ref/doc/uid/TP40009523-CH3-SW20
// https://developer.mozilla.org/en/API/Fullscreen
// http://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html#//apple_ref/doc/uid/TP40009523-CH3-SW20
// https://developer.mozilla.org/en/API/Fullscreen
});

0 comments on commit d4c2950

Please sign in to comment.