Sha256: 10a9245435cac5958d39fce5c6599606975fcc7c60906e8a90a53b2cc8771761

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

var _ns_ = "wisp.engine.browser";
module.namespace = _ns_;
var str = (require("./../runtime")).str;
var rest = (require("./../sequence")).rest;
var readFromString = (require("./../reader")).readFromString;
var compile_ = (require("./../compiler")).compile_;;

var evaluate = function evaluate(code, url) {
  return eval(compile_(read_(code, url)));
};
exports.evaluate = evaluate;

var run = function run(code, url) {
  return (Function(compile_(read_(code, url))))();
};
exports.run = run;

var load = function load(url, callback) {
  var request = window.XMLHttpRequest ?
    new XMLHttpRequest() :
    new ActiveXObject("Microsoft.XMLHTTP");
  request.open("GET", url, true);
  request.overrideMimeType ?
    request.overrideMimeType("application/wisp") :
    void(0);
  request.onreadystatechange = function() {
    return request.readyState === 4 ?
      (request.status === 0) || (request.status === 200) ?
        callback(run(request.responseText, url)) :
        callback("Could not load") :
      void(0);
  };
  return request.send(null);
};
exports.load = load;

var runScripts = function runScripts() {
  var scripts = Array.prototype.filter.call(document.getElementsByTagName("script"), function(script) {
    return script.type === "application/wisp";
  });
  var next = function next() {
    return scripts.length ?
      (function() {
        var script = scripts.shift();
        return script.src ?
          load(script.src, next) :
          next(run(script.innerHTML));
      })() :
      void(0);
  };
  return next();
};
exports.runScripts = runScripts;

(document.readyState === "complete") || (document.readyState === "interactive") ?
  runScripts() :
window.addEventListener ?
  window.addEventListener("DOMContentLoaded", runScripts, false) :
  window.attachEvent("onload", runScripts)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-wisp-source-0.8.0 vendor/node_modules/wisp/engine/browser.js
ruby-wisp-source-0.7.0 vendor/engine/browser.js