aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular-bootstrap.js
blob: 50c78f81c080bc656876ad69c0d7f7cfe8b30e2b (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * The MIT License
 * 
 * Copyright (c) 2010 Adam Abrons and Misko Hevery http://getangular.com
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
(function(previousOnLoad){
  var filename = /(.*)\/angular-(.*).js(#(.*))?/;
  var scripts = document.getElementsByTagName("script");
  var scriptConfig = {
      autoSubmit:true,
      autoBind:true,
      autoLoadDependencies:false
  };
  for(var j = 0; j < scripts.length; j++) {
    var src = scripts[j].src;
    if (src && src.match(filename)) {
      var parts = src.match(filename);
      if (parts[2] == 'bootstrap') {
        scriptConfig.autoLoadDependencies = true;
      }
      scriptConfig.server = parts[1] || '';
      if (!scriptConfig.server) {
        scriptConfig.server = window.location.toString().split(window.location.pathname)[0];
      }
      if (parts[4]) {
        var directive = parts[4].split('&');
        for ( var i = 0; i < directive.length; i++) {
          var keyValue = directive[i].split('=');
          var key = keyValue[0];
          var value = keyValue.length == 1 ? true : keyValue[1];
          if (value == 'false') value = false;
          if (value == 'true') value = true;
          scriptConfig[key] = value;
        }
      }
    }
  }

  var addScript = function(path, server){
    server = server || scriptConfig.server;
    document.write('<script type="text/javascript" src="' + server + path +'"></script>');
  };

  if (scriptConfig.autoLoadDependencies) {
    addScript("/../lib/webtoolkit/webtoolkit.base64.js");
    addScript("/../lib/swfobject/swfobject.js");
    addScript("/../lib/jquery/jquery-1.3.2.js");
    addScript("/../lib/jquery/jquery-ui-1.7.1.custom.min.js");
    addScript("/../lib/underscore/underscore.js");
    addScript("/Loader.js");
    addScript("/API.js");
    addScript("/Binder.js");
    addScript("/ControlBar.js");
    addScript("/DataStore.js");
    addScript("/Filters.js");
    addScript("/JSON.js");
    addScript("/Model.js");
    addScript("/Parser.js");
    addScript("/Scope.js");
    addScript("/Server.js");
    addScript("/Users.js");
    addScript("/Validators.js");
    addScript("/Widgets.js");
  } else {
    addScript("/ajax/libs/swfobject/2.2/swfobject.js", "http://ajax.googleapis.com");
    addScript("/ajax/libs/jquery/1.3.2/jquery.min.js", "http://ajax.googleapis.com");
    addScript("/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js", "http://ajax.googleapis.com");
  }

  window.onload = function() {
    var doc = window.document;
    if (scriptConfig.bindRootId) {
      doc = null;
      var ids = scriptConfig.bindRootId.split('|');
      for ( var i = 0; i < ids.length && !doc; i++) {
        var idCond = ids[i].split('?');
        var id = idCond[0];
        if (idCond.length > 1) {
          if (!window.document.getElementById(idCond[1])) {
            continue;
          }
        }
        doc = window.document.getElementById(id);
      }
    }
    if (scriptConfig.autoBind && doc) {
      window.angularScope = angular.compile(doc, scriptConfig);
    }
    if (typeof previousOnLoad === 'function') {
      try {
        previousOnLoad.apply(this, arguments);
      } catch (e) {}
    }
  };
})(window.onload);