dumpdata.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. function dumpModernizr(){
  2. var str = '';
  3. dumpModernizr.old = dumpModernizr.old || {};
  4. for (var prop in Modernizr) {
  5. // skip previously done ones.
  6. if (dumpModernizr.old[prop]) continue;
  7. else dumpModernizr.old[prop] = true;
  8. if (typeof Modernizr[prop] === 'function') continue;
  9. // skip unit test items
  10. if (/^test/.test(prop)) continue;
  11. if (~TEST.inputs.indexOf(prop)) {
  12. str += '<li><b>'+prop+'{}</b><ul>';
  13. for (var field in Modernizr[prop]) {
  14. str += '<li class="' + (Modernizr[prop][field] ? 'yes' : '') + '">' + field + ': ' + Modernizr[prop][field] + '</li>';
  15. }
  16. str += '</ul></li>';
  17. } else {
  18. str += '<li id="'+prop+'" class="' + (Modernizr[prop] ? 'yes' : '') + '">' + prop + ': ' + Modernizr[prop] + '</li>';
  19. }
  20. }
  21. return str;
  22. }
  23. function grabFeatDetects(){
  24. // thx github.js
  25. $.getScript('https://api.github.com/repos/Modernizr/Modernizr/git/trees/master?recursive=1&callback=processTree');
  26. }
  27. function processTree(data){
  28. var filenames = [];
  29. for (var i = 0; i < data.data.tree.length; i++){
  30. var file = data.data.tree[i];
  31. var match = file.path.match(/^feature-detects\/(.*)/);
  32. if (!match) continue;
  33. var relpath = location.host == "modernizr.github.com" ?
  34. '../modernizr-git/' : '../';
  35. filenames.push(relpath + match[0]);
  36. }
  37. var jqxhrs = filenames.map(function(filename){
  38. return jQuery.getScript(filename);
  39. });
  40. jQuery.when.apply(jQuery, jqxhrs).done(resultsToDOM);
  41. }
  42. function resultsToDOM(){
  43. var modOutput = document.createElement('div'),
  44. ref = document.getElementById('qunit-testresult') || document.getElementById('qunit-tests');
  45. modOutput.className = 'output';
  46. modOutput.innerHTML = dumpModernizr();
  47. ref.parentNode.insertBefore(modOutput, ref);
  48. // Modernizr object as text
  49. document.getElementsByTagName('textarea')[0].innerHTML = JSON.stringify(Modernizr);
  50. }
  51. /* uno */ resultsToDOM();
  52. /* dos */ grabFeatDetects();
  53. /* tres */ setTimeout(resultsToDOM, 5e3);
  54. /* quatro */ setTimeout(resultsToDOM, 15e3);