From 7059579c7499337c7946f3877ce77dd9a04ea22a Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 15 Oct 2010 21:38:41 -0700 Subject: inline all images into css * embedded images as data URIs * rake task to generate multipart js file with embeded images for IE * move images into a separate directory outside of src or css and keep them there for reference * clean up Rakefile and ruby code * .gitignore update * don't penalize IE 8+ with an extra request to the ie-compat.js file --- src/Angular.js | 19 +++++++++++++------ src/Browser.js | 17 ++++++++++++++++- src/angular-bootstrap.js | 12 ++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index 79557c2c..8cacb9e4 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -32,7 +32,8 @@ var _undefined = undefined, PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH}, jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy _ = window['_'], - msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)), + /** holds major version number for IE or NaN for real browsers */ + msie = parseInt((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1], 10), jqLite = jQuery || jqLiteWrap, slice = Array.prototype.slice, push = Array.prototype.push, @@ -408,25 +409,31 @@ function toKeyValue(obj) { function angularInit(config){ if (config.autobind) { // TODO default to the source of angular.js - var scope = compile(window.document, _null, {'$config':config}); + var scope = compile(window.document, _null, {'$config':config}), + $browser = scope.$inject('$browser'); + if (config.css) - scope.$inject('$browser').addCss(config.base_url + config.css); + $browser.addCss(config.base_url + config.css); + else if(msie<8) + $browser.addJs(config.base_url + config.ie_compat, config.ie_compat_id); + scope.$init(); } } function angularJsConfig(document, config) { - var filename = /^(.*)\/angular(-([^\/]*))?.js(\?[^#]*)?(#(.*))?$/, + var filename = /^(.*)angular(-([^\/]*))?.js(\?[^#]*)?(#(.*))?$/, scripts = document.getElementsByTagName("script"), match; config = extend({ base_url: '', - css: '../css/angular.css' + ie_compat: 'angular-ie-compat.js', + ie_compat_id: 'ng-ie-compat' }, config); for(var j = 0; j < scripts.length; j++) { match = (scripts[j].src || "").match(filename); if (match) { - config.base_url = match[1] + '/'; + config.base_url = match[1]; extend(config, parseKeyValue(match[6])); eachAttribute(jqLite(scripts[j]), function(value, name){ if (/^ng:/.exec(name)) { diff --git a/src/Browser.js b/src/Browser.js index aa80ef47..dcdc0a73 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -188,11 +188,26 @@ function Browser(location, document, head, XHR, $log) { }; - self.addCss = function(url) { + /** + * Adds a stylesheet tag to the head. + */ + self.addCss = function(/**string*/url) { var link = jqLite(rawDocument.createElement('link')); link.attr('rel', 'stylesheet'); link.attr('type', 'text/css'); link.attr('href', url); head.append(link); }; + + + /** + * Adds a script tag to the head. + */ + self.addJs = function(/**string*/url, /**string*/dom_id) { + var script = jqLite(rawDocument.createElement('script')); + script.attr('type', 'text/javascript'); + script.attr('src', url); + if (dom_id) script.attr('id', dom_id); + head.append(script); + }; } diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js index 4c95e8b0..416acbde 100644 --- a/src/angular-bootstrap.js +++ b/src/angular-bootstrap.js @@ -37,6 +37,13 @@ document.write(''); } + function addCss(file) { + document.write(''); + } + + addCss("/angular.css"); + addScript("/Angular.js"); addScript("/JSON.js"); addScript("/Compiler.js"); @@ -58,10 +65,15 @@ addScript("/markups.js"); addScript("/widgets.js"); + window.onload = function(){ try { if (previousOnLoad) previousOnLoad(); } catch(e) {} + + //angular-ie-compat.js needs to be pregenerated for development with IE<8 + if (msie<8) addScript('../angular-ie-compat.js'); + angularInit(angularJsConfig(document)); }; -- cgit v1.2.3