dependencyLib.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (function(factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define(["jquery"], factory);
  4. } else if (typeof exports === "object") {
  5. module.exports = factory(require("jquery"));
  6. } else {
  7. factory(jQuery);
  8. }
  9. }
  10. (function($) {
  11. // Use a stripped-down indexOf as it's faster than native
  12. // http://jsperf.com/thor-indexof-vs-for/5
  13. function indexOf(list, elem) {
  14. var i = 0,
  15. len = list.length;
  16. for (; i < len; i++) {
  17. if (list[i] === elem) {
  18. return i;
  19. }
  20. }
  21. return -1;
  22. }
  23. var dependencyLib = {
  24. isFunction: function(obj) {
  25. return jQuery.type(obj) === "function";
  26. },
  27. noop: function() {},
  28. parseJSON: function(data) {
  29. return JSON.parse(data + "");
  30. },
  31. isArray: Array.isArray,
  32. inArray: function(elem, arr, i) {
  33. return arr == null ? -1 : indexOf.call(arr, elem, i);
  34. },
  35. valHooks: undefined,
  36. extend: $.extend,
  37. each: $.each,
  38. map: $.map,
  39. Event: $.Event, //needs to be replaced
  40. _data: $._data, //needs to be replaced
  41. data: $.data //needs to be replaced
  42. }
  43. dependencyLib = $; //todo split out needed functionality
  44. window.dependencyLib = dependencyLib;
  45. return dependencyLib;
  46. }));