Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

File: src\js\RAMP\Utils\functionMangler.js

  1. /* global define, console */
  2.  
  3. /**
  4. * Utility module containing useful static classes.
  5. *
  6. * @module Utils
  7. */
  8.  
  9. /**
  10. * ??? Description
  11. *
  12. *
  13. * @class FunctionMangler
  14. * @static
  15. * @uses dojo/on
  16. * @uses dojo/_base/lang
  17. * @uses dojo/topic
  18. * @uses Util
  19. */
  20.  
  21. define([
  22. /* Dojo */
  23. "dojo/topic", "dojo/_base/lang", "dojo/on",
  24.  
  25. /* Utils */
  26. "utils/util"
  27. ],
  28.  
  29. function (
  30. /* Dojo */
  31. topic, dojoLang, dojoOn,
  32.  
  33. /* Utils */
  34. UtilMisc) {
  35. "use strict";
  36.  
  37. /**
  38. * [_initDojoPrototype description] Adds following extensions:
  39. * - `topic.subscrive(name, listener, scope)` - An extension of dojoLang.subscribe that allows the callback function to be
  40. * hitched with the given scope.
  41. * - `dojoOn(target, type, listener, scope)` -
  42. *
  43. *
  44. * @method _initDojoPrototype
  45. * @private
  46. */
  47. function _initDojoPrototype() {
  48. var originalOn = dojoOn;
  49. dojoOn = function (target, type, listener, scope) {
  50. if (UtilMisc.isUndefined(scope)) {
  51. return originalOn(target, type, listener);
  52. } else {
  53. return originalOn(target, type, dojoLang.hitch(scope, listener));
  54. }
  55. };
  56.  
  57. var originalSubscribe = topic.subscribe;
  58. topic.subscribe = function (eventName, listener) {
  59. if (UtilMisc.isUndefined(eventName)) {
  60. console.error("Trying to subscribe to an undefined event");
  61. console.trace();
  62. } else {
  63. return originalSubscribe(eventName, listener);
  64. }
  65. };
  66. }
  67.  
  68. return {
  69. /**
  70. * [load description]
  71. *
  72. * @method load
  73. * @param {[type]} id [description]
  74. * @param {[type]} require [description]
  75. * @param {[type]} load [description]
  76. * @return {[type]} [description]
  77. */
  78. load: function (id, require, load) {
  79. _initDojoPrototype();
  80.  
  81. load();
  82. }
  83. };
  84. });