Guest User

Untitled

a guest
Jan 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. // START Handlebars
  2. var Handlebars = {
  3. precompile: function(){},
  4. compile : function(){},
  5. template : function(){}
  6. };
  7.  
  8. define( 'Handlebars', [], function(){
  9. return Handlebars;
  10. });
  11. // END Handlebars
  12.  
  13. define('tmpl',[],function () {
  14. var fs, getXhr,
  15. progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
  16. fetchText = function () {
  17. throw new Error('Environment unsupported.');
  18. },
  19. buildMap = [];
  20.  
  21. if (typeof window !== "undefined" && window.navigator && window.document) {
  22. // Browser action
  23. getXhr = function () {
  24. //Would love to dump the ActiveX crap in here. Need IE 6 to die first.
  25. var xhr, i, progId;
  26. if (typeof XMLHttpRequest !== "undefined") {
  27. return new XMLHttpRequest();
  28. } else {
  29. for (i = 0; i < 3; i++) {
  30. progId = progIds[i];
  31. try {
  32. xhr = new ActiveXObject(progId);
  33. } catch (e) {}
  34.  
  35. if (xhr) {
  36. progIds = [progId]; // so faster next time
  37. break;
  38. }
  39. }
  40. }
  41.  
  42. if (!xhr) {
  43. throw new Error("getXhr(): XMLHttpRequest not available");
  44. }
  45.  
  46. return xhr;
  47. };
  48.  
  49. fetchText = function (url, callback) {
  50. var xhr = getXhr();
  51. xhr.open('GET', url, true);
  52. xhr.onreadystatechange = function (evt) {
  53. //Do not explicitly handle errors, those should be
  54. //visible via console output in the browser.
  55. if (xhr.readyState === 4) {
  56. callback(xhr.responseText);
  57. }
  58. };
  59. xhr.send(null);
  60. };
  61.  
  62. } else if (typeof process !== "undefined" &&
  63. process.versions &&
  64. !!process.versions.node) {
  65. //Using special require.nodeRequire, something added by r.js.
  66. fs = require.nodeRequire('fs');
  67. fetchText = function (path, callback) {
  68. callback(fs.readFileSync(path, 'utf8'));
  69. };
  70. }
  71.  
  72. return {
  73.  
  74. get: function () {
  75. return Handlebars;
  76. },
  77.  
  78. write: function (pluginName, name, write) {
  79. if (name in buildMap) {
  80. var text = buildMap[name];
  81. //write.asModule(pluginName + "!" + name, text);
  82. write(text);
  83. }
  84. },
  85.  
  86. version: '1.0.2beta',
  87.  
  88. load: function (name, parentRequire, load, config) {
  89. var path = parentRequire.toUrl(name + '.handlebars');
  90. console.log( config );
  91. fetchText(path, function (text) {
  92. // for some reason it doesn't include tmpl _first_ when i don't add it here...
  93. text = "define('tmpl!"+name+"',['tmpl', 'Handlebars'], function( tmpl, Handlebars ){ \n" +
  94. "return Handlebars.template("+Handlebars.precompile(text)+ ");" +
  95. "})";
  96.  
  97. //Hold on to the transformed text if a build.
  98. if (config.isBuild) {
  99. buildMap[name] = text;
  100. }
  101.  
  102. //IE with conditional comments on cannot handle the
  103. //sourceURL trick, so skip it if enabled.
  104. /*@if (@_jscript) @else @*/
  105. if (!config.isBuild) {
  106. text += "\r\n//@ sourceURL=" + path;
  107. }
  108. /*@end@*/
  109.  
  110. load.fromText(name, text);
  111.  
  112. //Give result to load. Need to wait until the module
  113. //is fully parse, which will happen after this
  114. //execution.
  115. parentRequire([name], function (value) {
  116. load(value);
  117. });
  118. });
  119. }
  120. };
  121. });
Add Comment
Please, Sign In to add comment