mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-22 19:23:38 +08:00
created a way to init the code without autobootstrap
This commit is contained in:
@@ -103,8 +103,17 @@ nglr.Binder.prototype.updateView = function() {
|
||||
_.each(this.updateListeners, function(fn) {fn();});
|
||||
};
|
||||
|
||||
nglr.Binder.prototype.docFindWithSelf = function(exp){
|
||||
var doc = jQuery(this.doc);
|
||||
var selection = doc.find(exp);
|
||||
if (doc.is(exp)){
|
||||
selection = selection.andSelf();
|
||||
}
|
||||
return selection;
|
||||
};
|
||||
|
||||
nglr.Binder.prototype.executeInit = function() {
|
||||
jQuery("[ng-init]", this.doc).each(function() {
|
||||
this.docFindWithSelf("[ng-init]").each(function() {
|
||||
var jThis = jQuery(this);
|
||||
var scope = jThis.scope();
|
||||
try {
|
||||
@@ -116,7 +125,7 @@ nglr.Binder.prototype.executeInit = function() {
|
||||
};
|
||||
|
||||
nglr.Binder.prototype.entity = function (scope) {
|
||||
jQuery("[ng-entity]", this.doc).attr("ng-watch", function() {
|
||||
this.docFindWithSelf("[ng-entity]").attr("ng-watch", function() {
|
||||
try {
|
||||
var jNode = jQuery(this);
|
||||
var decl = scope.entity(jNode.attr("ng-entity"));
|
||||
@@ -131,12 +140,12 @@ nglr.Binder.prototype.compile = function() {
|
||||
var jNode = jQuery(this.doc);
|
||||
var self = this;
|
||||
if (this.config.autoSubmit) {
|
||||
var submits = jQuery(":submit", this.doc).not("[ng-action]");
|
||||
var submits = this.docFindWithSelf(":submit").not("[ng-action]");
|
||||
submits.attr("ng-action", "$save()");
|
||||
submits.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr", '{disabled:"{{$invalidWidgets}}"}');
|
||||
}
|
||||
this.precompile(this.doc)(this.doc, jNode.scope(), "");
|
||||
jQuery("a[ng-action]", this.doc).live('click', function (event) {
|
||||
this.docFindWithSelf("a[ng-action]").live('click', function (event) {
|
||||
var jNode = jQuery(this);
|
||||
try {
|
||||
jNode.scope().eval(jNode.attr('ng-action'));
|
||||
|
||||
@@ -166,7 +166,6 @@ nglr.Loader.prototype.load = function() {
|
||||
this.loadCss('/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css');
|
||||
this.loadCss('/stylesheets/nglr.css');
|
||||
console.log("Server: " + this.config.server);
|
||||
jQuery.noConflict();
|
||||
nglr.msie = jQuery.browser.msie;
|
||||
this.configureJQueryPlugins();
|
||||
this.computeConfiguration();
|
||||
@@ -201,7 +200,7 @@ nglr.Loader.prototype.uid = function() {
|
||||
nglr.Loader.prototype.computeConfiguration = function() {
|
||||
var config = this.config;
|
||||
if (!config.database) {
|
||||
var match = config.server.match(/https?:\/\/([\w]*)/)
|
||||
var match = config.server.match(/https?:\/\/([\w]*)/);
|
||||
config.database = match ? match[1] : "$MEMORY";
|
||||
}
|
||||
};
|
||||
@@ -387,3 +386,19 @@ nglr.UrlWatcher.prototype.setUrl = function(url) {
|
||||
nglr.UrlWatcher.prototype.getUrl = function() {
|
||||
return window.location.href;
|
||||
};
|
||||
|
||||
window['angularFactory'] = function(config) {
|
||||
var defaults = {
|
||||
server: ""
|
||||
};
|
||||
//todo: don't load stylesheet by default
|
||||
//todo: don't start watcher
|
||||
function compile(root){
|
||||
var loader = new nglr.Loader(root, jQuery("head"), _(defaults).extend(config));
|
||||
loader.load();
|
||||
return jQuery(root).scope();
|
||||
};
|
||||
return {
|
||||
compile:compile
|
||||
};
|
||||
};
|
||||
|
||||
49
src/angular-bootstrap.js
vendored
49
src/angular-bootstrap.js
vendored
@@ -39,25 +39,25 @@
|
||||
};
|
||||
|
||||
if (scriptConfig.autoLoadDependencies) {
|
||||
addScript("/javascripts/webtoolkit.base64.js");
|
||||
addScript("/javascripts/swfobject.js");
|
||||
addScript("/javascripts/jQuery/jquery-1.3.2.js");
|
||||
addScript("/javascripts/jQuery/jquery-ui-1.7.1.custom.min.js");
|
||||
addScript("/javascripts/underscore/underscore.js");
|
||||
addScript("/javascripts/nglr/Loader.js");
|
||||
addScript("/javascripts/nglr/API.js");
|
||||
addScript("/javascripts/nglr/Binder.js");
|
||||
addScript("/javascripts/nglr/ControlBar.js");
|
||||
addScript("/javascripts/nglr/DataStore.js");
|
||||
addScript("/javascripts/nglr/Filters.js");
|
||||
addScript("/javascripts/nglr/JSON.js");
|
||||
addScript("/javascripts/nglr/Model.js");
|
||||
addScript("/javascripts/nglr/Parser.js");
|
||||
addScript("/javascripts/nglr/Scope.js");
|
||||
addScript("/javascripts/nglr/Server.js");
|
||||
addScript("/javascripts/nglr/Users.js");
|
||||
addScript("/javascripts/nglr/Validators.js");
|
||||
addScript("/javascripts/nglr/Widgets.js");
|
||||
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");
|
||||
@@ -65,12 +65,6 @@
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
window.angular.init = function(root, config){
|
||||
var cnfgMerged = _.clone(scriptConfig||{});
|
||||
_.extend(cnfgMerged, config);
|
||||
new nglr.Loader(root, jQuery("head"), cnfgMerged).load();
|
||||
};
|
||||
|
||||
var doc = window.document;
|
||||
if (scriptConfig.bindRootId) {
|
||||
doc = null;
|
||||
@@ -86,12 +80,13 @@
|
||||
doc = window.document.getElementById(id);
|
||||
}
|
||||
}
|
||||
var angular = window.angularFactory(scriptConfig);
|
||||
if (scriptConfig.autoBind && doc) {
|
||||
window.angular.init(doc);
|
||||
window.angularScope = angular.compile(doc);
|
||||
}
|
||||
if (typeof previousOnLoad === 'function') {
|
||||
try {
|
||||
previousOnLoad.apply(this, arguments);
|
||||
previousOnLoad.apply(this, arguments);
|
||||
} catch (e) {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
if (!nglr.test) nglr.test = {};
|
||||
|
||||
nglr.test.ScenarioRunner = function(scenarios, body) {
|
||||
this.scenarios = scenarios;
|
||||
this.body = body;
|
||||
@@ -46,10 +48,10 @@ nglr.test.Runner.prototype = {
|
||||
scenario:jQuery('<div class="scenario"></div>')
|
||||
};
|
||||
current.run = current.scenario.append(
|
||||
'<div class="run">' +
|
||||
'<span class="name">.</span>' +
|
||||
'<span class="time">.</span>' +
|
||||
'<span class="state">.</span>' +
|
||||
'<div class="run">' +
|
||||
'<span class="name">.</span>' +
|
||||
'<span class="time">.</span>' +
|
||||
'<span class="state">.</span>' +
|
||||
'</run>').find(".run");
|
||||
current.log = current.scenario.append('<div class="log"></div>').find(".log");
|
||||
current.run.find(".name").text(name);
|
||||
@@ -79,7 +81,7 @@ nglr.test.Runner.prototype = {
|
||||
log.text(buf.join(" "));
|
||||
this.current.log.append(log);
|
||||
this.console.scrollTop(this.console[0].scrollHeight);
|
||||
if (level == "error")
|
||||
if (level == "error")
|
||||
this.current.error = buf.join(" ");
|
||||
}
|
||||
};
|
||||
@@ -114,16 +116,16 @@ nglr.test.Scenario.prototype = {
|
||||
else if (step.Then) fn = angular.test.THEN[step.Then];
|
||||
return fn || function (){
|
||||
throw "ERROR: Need Given/When/Then got: " + nglr.toJson(step);
|
||||
};
|
||||
};
|
||||
},
|
||||
context: function(runner) {
|
||||
var frame = runner.frame;
|
||||
var window = frame[0].contentWindow;
|
||||
var document;
|
||||
if (window.jQuery)
|
||||
if (window.jQuery)
|
||||
document = window.jQuery(window.document);
|
||||
var context = {
|
||||
frame:frame,
|
||||
frame:frame,
|
||||
window:window,
|
||||
log:_.bind(runner.log, runner, "info"),
|
||||
document:document,
|
||||
|
||||
Reference in New Issue
Block a user