Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

621 script name restrictions + cleanup #624

Merged
merged 4 commits into from
Oct 26, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions docs/content/guide/dev_guide.bootstrap.auto_bootstrap.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ appending `#autobind` to the `<script src=...>` URL, like in this snippet:
<!doctype html>
<html>
<head>
<script type="text/javascript"
src="http://code.angularjs.org/angular.js#autobind"></script>
<script src="http://code.angularjs.org/angular.js#autobind"></script>
</head>
<body>
<div xmlns:ng="http://angularjs.org">
Expand All @@ -67,22 +66,24 @@ appending `#autobind` to the `<script src=...>` URL, like in this snippet:
As with `ng:autobind`, you can specify an element id that should be exclusively targeted for
compilation as the value of the `#autobind`, for example: `#autobind=angularContent`.

## Filename Restrictions for Auto-bootstrap
If angular.js file is being combined with other scripts into a single script file, then all of the
config options above apply to this processed script as well. That means if the contents of
`angular.js` were appended to `all-my-scripts.js`, then the app can be bootstrapped as:

In order for us to find the auto-bootstrap from a script attribute or URL fragment, the value of
the `script` `src` attribute that loads the angular script must match one of these naming
conventions:

- `angular.js`
- `angular-min.js`
- `angular-x.x.x.js`
- `angular-x.x.x.min.js`
- `angular-x.x.x-xxxxxxxx.js` (dev snapshot)
- `angular-x.x.x-xxxxxxxx.min.js` (dev snapshot)
- `angular-bootstrap.js` (used for development of angular)
<pre>
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<head>
<script src="http://myapp.com/all-my-scripts.js" ng:autobind></script>
</head>
<body>
<div>
Hello {{'world'}}!
</div>
</body>
</html>
</pre>

Optionally, any of the filename formats above can be prepended with a relative or absolute URL that
ends with `/`.

## Global Angular Object

Expand Down
4 changes: 2 additions & 2 deletions docs/src/templates/docs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DocsController.$inject = ['$location', '$browser', '$window', '$cookies'];
function DocsController($location, $browser, $window, $cookies) {
DocsController.$inject = ['$location', '$window', '$cookies'];
function DocsController($location, $window, $cookies) {
window.$root = this.$root;

var scope = this,
Expand Down
15 changes: 8 additions & 7 deletions example/personalLog/scenario/personalLogScenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('personal log', function() {
element('form input[type="submit"]').click();

expect(repeater('ul li').count()).toEqual(1);
expect(repeater('ul li').column('log.msg')).toEqual('my first message');
expect(repeater('ul li').column('log.msg')).toEqual(['my first message']);

//create second msg
input('newMsg').enter('my second message');
Expand All @@ -38,7 +38,7 @@ describe('personal log', function() {

element('ul li a:eq(1)').click();
expect(repeater('ul li').count()).toEqual(1);
expect(repeater('ul li').column('log.msg')).toEqual('my second message');
expect(repeater('ul li').column('log.msg')).toEqual(['my second message']);

element('ul li a:eq(0)').click();
expect(repeater('ul li').count()).toEqual(0);
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('personal log', function() {

browser().reload();

expect(repeater('ul li').column('log.msg')).toEqual('my persistent message');
expect(repeater('ul li').column('log.msg')).toEqual(['my persistent message']);
expect(repeater('ul li').count()).toEqual(1);
});
});
Expand All @@ -85,10 +85,11 @@ angular.scenario.dsl('clearCookies', function() {
$cookies = rootScope.$service('$cookies'),
cookieName;

for (cookieName in $cookies) {
delete $cookies[cookieName];
}
rootScope.$eval();
rootScope.$apply(function() {
for (cookieName in $cookies) {
delete $cookies[cookieName];
}
});

done();
});
Expand Down
76 changes: 35 additions & 41 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (typeof document.getAttribute == $undefined)
* @param {string} string String to be converted to lowercase.
* @returns {string} Lowercased string.
*/
var lowercase = function(string){ return isString(string) ? string.toLowerCase() : string; };
var lowercase = function(string){return isString(string) ? string.toLowerCase() : string;};


/**
Expand All @@ -26,17 +26,17 @@ var lowercase = function(string){ return isString(string) ? string.toLowerCase()
* @param {string} string String to be converted to uppercase.
* @returns {string} Uppercased string.
*/
var uppercase = function(string){ return isString(string) ? string.toUpperCase() : string; };
var uppercase = function(string){return isString(string) ? string.toUpperCase() : string;};


var manualLowercase = function(s) {
return isString(s)
? s.replace(/[A-Z]/g, function(ch) {return fromCharCode(ch.charCodeAt(0) | 32); })
? s.replace(/[A-Z]/g, function(ch) {return fromCharCode(ch.charCodeAt(0) | 32);})
: s;
};
var manualUppercase = function(s) {
return isString(s)
? s.replace(/[a-z]/g, function(ch) {return fromCharCode(ch.charCodeAt(0) & ~32); })
? s.replace(/[a-z]/g, function(ch) {return fromCharCode(ch.charCodeAt(0) & ~32);})
: s;
};

Expand All @@ -49,12 +49,12 @@ if ('i' !== 'I'.toLowerCase()) {
uppercase = manualUppercase;
}

function fromCharCode(code) { return String.fromCharCode(code); }
function fromCharCode(code) {return String.fromCharCode(code);}

/**
* Creates the element for IE8 and below to allow styling of widgets
* (http://ejohn.org/blog/html5-shiv/). This hack works only if angular is
* included synchronously at the top of the document before IE sees any
* (http://ejohn.org/blog/html5-shiv/). This hack works only if angular is
* included synchronously at the top of the document before IE sees any
* unknown elements. See regression/issue-584.html.
*
* @param {string} elementName Name of the widget.
Expand Down Expand Up @@ -116,7 +116,6 @@ var _undefined = undefined,
angularService = extensionMap(angular, 'service'),
angularCallbacks = extensionMap(angular, 'callbacks'),
nodeName_,
rngScript = /^(|.*\/)angular(-.*?)?(\.min)?.js(\?[^#]*)?(#(.*))?$/,
uid = ['0', '0', '0'],
DATE_ISOSTRING_LN = 24;

Expand Down Expand Up @@ -295,7 +294,7 @@ function noop() {}
function identity($) {return $;}


function valueFn(value) {return function() { return value; };}
function valueFn(value) {return function() {return value;};}

function extensionMap(angular, name, transform) {
var extPoint;
Expand All @@ -319,7 +318,7 @@ function extensionMap(angular, name, transform) {
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is undefined.
*/
function isUndefined(value){ return typeof value == $undefined; }
function isUndefined(value){return typeof value == $undefined;}


/**
Expand All @@ -333,7 +332,7 @@ function isUndefined(value){ return typeof value == $undefined; }
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is defined.
*/
function isDefined(value){ return typeof value != $undefined; }
function isDefined(value){return typeof value != $undefined;}


/**
Expand All @@ -348,7 +347,7 @@ function isDefined(value){ return typeof value != $undefined; }
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is an `Object` but not `null`.
*/
function isObject(value){ return value!=null && typeof value == $object;}
function isObject(value){return value!=null && typeof value == $object;}


/**
Expand All @@ -362,7 +361,7 @@ function isObject(value){ return value!=null && typeof value == $object;}
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `String`.
*/
function isString(value){ return typeof value == $string;}
function isString(value){return typeof value == $string;}


/**
Expand All @@ -376,7 +375,7 @@ function isString(value){ return typeof value == $string;}
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Number`.
*/
function isNumber(value){ return typeof value == $number;}
function isNumber(value){return typeof value == $number;}


/**
Expand All @@ -390,7 +389,7 @@ function isNumber(value){ return typeof value == $number;}
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Date`.
*/
function isDate(value){ return value instanceof Date; }
function isDate(value){return value instanceof Date;}


/**
Expand All @@ -404,7 +403,7 @@ function isDate(value){ return value instanceof Date; }
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is an `Array`.
*/
function isArray(value) { return value instanceof Array; }
function isArray(value) {return value instanceof Array;}


/**
Expand All @@ -418,7 +417,7 @@ function isArray(value) { return value instanceof Array; }
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Function`.
*/
function isFunction(value){ return typeof value == 'function';}
function isFunction(value){return typeof value == 'function';}


/**
Expand All @@ -432,8 +431,8 @@ function isWindow(obj) {
return obj && obj.document && obj.location && obj.alert && obj.setInterval;
}

function isBoolean(value) { return typeof value == $boolean; }
function isTextNode(node) { return nodeName_(node) == '#text'; }
function isBoolean(value) {return typeof value == $boolean;}
function isTextNode(node) {return nodeName_(node) == '#text';}

function trim(value) {
return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
Expand Down Expand Up @@ -953,35 +952,30 @@ function angularInit(config, document){
var autobind = config.autobind;

if (autobind) {
var element = isString(autobind) ? document.getElementById(autobind) : document,
scope = compile(element)(createScope()),
$browser = scope.$service('$browser');

if (config.css)
$browser.addCss(config.base_url + config.css);
scope.$apply();
var element = isString(autobind) ? document.getElementById(autobind) : document;
compile(element)().$apply();
}
}

function angularJsConfig(document) {
bindJQuery();
var scripts = document.getElementsByTagName("script"),
var scripts = document.getElementsByTagName('script'),
script = scripts[scripts.length-1],
scriptSrc = script.src,
config = {},
match;
for(var j = 0; j < scripts.length; j++) {
match = (scripts[j].src || "").match(rngScript);
if (match) {
config.base_url = match[1];
extend(config, parseKeyValue(match[6]));
eachAttribute(jqLite(scripts[j]), function(value, name){
if (/^ng:/.exec(name)) {
name = name.substring(3).replace(/-/g, '_');
value = value || true;
config[name] = value;
}
});
hashPos;

hashPos = scriptSrc.indexOf('#');
if (hashPos != -1) extend(config, parseKeyValue(scriptSrc.substr(hashPos+1)));

eachAttribute(jqLite(script), function(value, name){
if (/^ng:/.exec(name)) {
name = name.substring(3).replace(/-/g, '_');
value = value || true;
config[name] = value;
}
}
});

return config;
}

Expand Down
4 changes: 1 addition & 3 deletions src/angular-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@
// empty the cache to prevent mem leaks
globalVars = {};

var config = angularJsConfig(document);

angularInit(config, document);
angularInit({autobind:true}, document);
}

if (window.addEventListener) {
Expand Down
4 changes: 3 additions & 1 deletion src/angular.suffix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

var config = angularJsConfig(document);

jqLiteWrap(document).ready(function() {
angularInit(angularJsConfig(document), document);
angularInit(config, document);
});

})(window, document);
Loading