library-detector.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. The code in this file is adapted from the original
  3. Library Detector add-on
  4. (https://addons.mozilla.org/en-US/firefox/addon/library-detector/) written by
  5. Paul Bakaus (http://paulbakaus.com/) and made available under the
  6. MIT License (http://www.opensource.org/licenses/mit-license.php).
  7. */
  8. var LD_tests = {
  9. 'jQuery': {
  10. test: function(win) {
  11. var jq = win.jQuery || win.$ || win.$jq || win.$j;
  12. if(jq && jq.fn && jq.fn.jquery) {
  13. return { version: jq.fn.jquery };
  14. } else {
  15. return false;
  16. }
  17. }
  18. },
  19. 'jQuery UI': {
  20. //phonehome: 'http://jqueryui.com/phone_home',
  21. test: function(win) {
  22. var jq = win.jQuery || win.$ || win.$jq || win.$j;
  23. if(jq && jq.fn && jq.fn.jquery && jq.ui) {
  24. var plugins = 'accordion,datepicker,dialog,draggable,droppable,progressbar,resizable,selectable,slider,menu,grid,tabs'.split(','), concat = [];
  25. for (var i=0; i < plugins.length; i++) { if(jq.ui[plugins[i]]) concat.push(plugins[i].substr(0,1).toUpperCase() + plugins[i].substr(1)); };
  26. return { version: jq.ui.version, details: concat.length ? 'Plugins used: '+concat.join(',') : '' };
  27. } else {
  28. return false;
  29. }
  30. }
  31. },
  32. 'MooTools': {
  33. test: function(win) {
  34. if(win.MooTools && win.MooTools.version) {
  35. return { version: win.MooTools.version };
  36. } else {
  37. return false;
  38. }
  39. }
  40. },
  41. 'YUI': {
  42. test: function(win) {
  43. if(win.YAHOO && win.YAHOO.VERSION) {
  44. return { version: win.YAHOO.VERSION };
  45. } else {
  46. return false;
  47. }
  48. }
  49. },
  50. 'Closure': {
  51. test: function(win) {
  52. if(win.goog) {
  53. return { version: '2.0' };
  54. }
  55. return false;
  56. }
  57. },
  58. 'Modernizr': {
  59. test: function(win) {
  60. if(win.Modernizr) {
  61. return { version: win.Modernizr._version };
  62. }
  63. return false;
  64. }
  65. },
  66. };
  67. function testLibraries() {
  68. var win = unsafeWindow;
  69. var libraryList = [];
  70. for(var i in LD_tests) {
  71. var passed = LD_tests[i].test(win);
  72. if (passed) {
  73. let libraryInfo = {
  74. name: i,
  75. version: passed.version
  76. };
  77. libraryList.push(libraryInfo);
  78. }
  79. }
  80. self.postMessage(libraryList);
  81. }
  82. testLibraries();