Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // START Handlebars
- var Handlebars = {
- precompile: function(){},
- compile : function(){},
- template : function(){}
- };
- define( 'Handlebars', [], function(){
- return Handlebars;
- });
- // END Handlebars
- define('tmpl',[],function () {
- var fs, getXhr,
- progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
- fetchText = function () {
- throw new Error('Environment unsupported.');
- },
- buildMap = [];
- if (typeof window !== "undefined" && window.navigator && window.document) {
- // Browser action
- getXhr = function () {
- //Would love to dump the ActiveX crap in here. Need IE 6 to die first.
- var xhr, i, progId;
- if (typeof XMLHttpRequest !== "undefined") {
- return new XMLHttpRequest();
- } else {
- for (i = 0; i < 3; i++) {
- progId = progIds[i];
- try {
- xhr = new ActiveXObject(progId);
- } catch (e) {}
- if (xhr) {
- progIds = [progId]; // so faster next time
- break;
- }
- }
- }
- if (!xhr) {
- throw new Error("getXhr(): XMLHttpRequest not available");
- }
- return xhr;
- };
- fetchText = function (url, callback) {
- var xhr = getXhr();
- xhr.open('GET', url, true);
- xhr.onreadystatechange = function (evt) {
- //Do not explicitly handle errors, those should be
- //visible via console output in the browser.
- if (xhr.readyState === 4) {
- callback(xhr.responseText);
- }
- };
- xhr.send(null);
- };
- } else if (typeof process !== "undefined" &&
- process.versions &&
- !!process.versions.node) {
- //Using special require.nodeRequire, something added by r.js.
- fs = require.nodeRequire('fs');
- fetchText = function (path, callback) {
- callback(fs.readFileSync(path, 'utf8'));
- };
- }
- return {
- get: function () {
- return Handlebars;
- },
- write: function (pluginName, name, write) {
- if (name in buildMap) {
- var text = buildMap[name];
- //write.asModule(pluginName + "!" + name, text);
- write(text);
- }
- },
- version: '1.0.2beta',
- load: function (name, parentRequire, load, config) {
- var path = parentRequire.toUrl(name + '.handlebars');
- console.log( config );
- fetchText(path, function (text) {
- // for some reason it doesn't include tmpl _first_ when i don't add it here...
- text = "define('tmpl!"+name+"',['tmpl', 'Handlebars'], function( tmpl, Handlebars ){ \n" +
- "return Handlebars.template("+Handlebars.precompile(text)+ ");" +
- "})";
- //Hold on to the transformed text if a build.
- if (config.isBuild) {
- buildMap[name] = text;
- }
- //IE with conditional comments on cannot handle the
- //sourceURL trick, so skip it if enabled.
- /*@if (@_jscript) @else @*/
- if (!config.isBuild) {
- text += "\r\n//@ sourceURL=" + path;
- }
- /*@end@*/
- load.fromText(name, text);
- //Give result to load. Need to wait until the module
- //is fully parse, which will happen after this
- //execution.
- parentRequire([name], function (value) {
- load(value);
- });
- });
- }
- };
- });
Add Comment
Please, Sign In to add comment