tobowers / screw-unit forked from nathansobo/screw-unit

A Javascript BDD Framework with nested describes, a convenient assertion syntax, and an intuitive test browser. - this fork is an attempt to add mocking (Ajax mocking is for prototype)

This URL has Read+Write access

screw-unit / lib / screw.assets.js
100644 37 lines (33 sloc) 1.279 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(function() {
  Screw.Assets = {};
  Screw.Assets.use_cache_buster = false; // TODO: NS/CTI - make this configurable from the UI.
  var required_paths = [];
  var included_stylesheets = {};
  var cache_buster = parseInt(new Date().getTime()/(1*1000));
 
  Screw.Assets.require = function(javascript_path, onload) {
    if(!required_paths[javascript_path]) {
      var full_path = javascript_path + ".js";
      if (Screw.Assets.use_cache_buster) {
        full_path += '?' + cache_buster;
      }
      document.write("<script src='" + full_path + "' type='text/javascript'></script>");
      if(onload) {
        var scripts = document.getElementsByTagName('script');
        scripts[scripts.length-1].onload = onload;
      }
      required_paths[javascript_path] = true;
    }
  };
 
  Screw.Assets.stylesheet = function(stylesheet_path) {
    if(!included_stylesheets[stylesheet_path]) {
      var full_path = stylesheet_path + ".css";
      if(Screw.Assets.use_cache_buster) {
        full_path += '?' + cache_buster;
      }
      document.write("<link rel='stylesheet' type='text/css' href='" + full_path + "' />");
      included_stylesheets[stylesheet_path] = true;
    }
  };
 
  window.require = Screw.Assets.require;
  window.stylesheet = Screw.Assets.stylesheet;
})();