Angular tests running, content scoping

This commit is contained in:
Max Lynch
2013-10-02 19:47:21 -05:00
parent 4174fc3d49
commit a7fbaac5db
6 changed files with 95 additions and 30 deletions

View File

@ -32,7 +32,8 @@ module.exports = function(grunt) {
}, },
distAngular: { distAngular: {
src: [ src: [
'js/ext/angular/src/**/*.js' 'js/ext/angular/src/ionicAngular.js',
'js/ext/angular/src/directive/**/*.js'
], ],
dest: 'dist/<%= pkg.name %>-angular.js' dest: 'dist/<%= pkg.name %>-angular.js'
}, },

25
dist/ionic-angular.js vendored
View File

@ -1,3 +1,5 @@
angular.module('ionic.ui', ['ionic.ui.content', 'ionic.ui.tabs', 'ionic.ui.nav', 'ionic.ui.sideMenu']);
;
angular.module('ionic.ui.content', {}) angular.module('ionic.ui.content', {})
// The content directive is a core scrollable content area // The content directive is a core scrollable content area
@ -6,18 +8,18 @@ angular.module('ionic.ui.content', {})
return { return {
restrict: 'E', restrict: 'E',
replace: true, replace: true,
transclude: true, scope: false,
scope: true, compile: function(element, attr, transclude) {
template: '<div class="content" ng-class="{\'has-header\': hasHeader, \'has-tabs\': hasTabs}"></div>',
compile: function(element, attr, transclude, navCtrl) {
return function($scope, $element, $attr) { return function($scope, $element, $attr) {
$scope.hasHeader = attr.hasHeader; $element.addClass('content');
$scope.hasTabs = attr.hasTabs;
var newScope = $scope.$parent.$new(); if(attr.hasHeader) {
$element.addClass('has-header');
$element.append(transclude(newScope)); }
}; if(attr.hasTabs) {
$element.addClass('has-tabs');
}
}
} }
} }
}) })
@ -83,7 +85,6 @@ angular.module('ionic.ui.nav', [])
'<h1 class="title">{{getTopController().title}}</h1>' + '<h1 class="title">{{getTopController().title}}</h1>' +
'</header>', '</header>',
link: function(scope, element, attrs, navCtrl) { link: function(scope, element, attrs, navCtrl) {
scope.isHidden = attrs.hidden;
scope.goBack = function() { scope.goBack = function() {
navCtrl.pop(); navCtrl.pop();
} }
@ -319,5 +320,3 @@ angular.module('ionic.ui.tabs', [])
'</a>' '</a>'
} }
}); });
;
angular.module('ionic.ui', ['ionic.ui.content', 'ionic.ui.tabs', 'ionic.ui.nav', 'ionic.ui.sideMenu']);

View File

@ -14,17 +14,20 @@ module.exports = function(config) {
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
// Include jQuery only for testing convience (lots of DOM checking for unit tests on directives) // Include jQuery only for testing convience (lots of DOM checking for unit tests on directives)
'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
'vendor/angular/1.2.0rc1/*', 'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-mocks.js',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-touch.js',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-animate.js',
'dist/ionic.js', 'dist/ionic.js',
'dist/ionic-angular.js',
'test/**/*.js', 'test/**/*.js',
//'ext/angular/src/**/*.js',
//'ext/angular/test/**/*.js', 'js/ext/angular/test/**/*.js'
//'hacking/**/*.js',
//'test/**/*.js'
], ],

View File

@ -6,18 +6,18 @@ angular.module('ionic.ui.content', {})
return { return {
restrict: 'E', restrict: 'E',
replace: true, replace: true,
transclude: true, scope: false,
scope: true, compile: function(element, attr, transclude) {
template: '<div class="content" ng-class="{\'has-header\': hasHeader, \'has-tabs\': hasTabs}"></div>',
compile: function(element, attr, transclude, navCtrl) {
return function($scope, $element, $attr) { return function($scope, $element, $attr) {
$scope.hasHeader = attr.hasHeader; $element.addClass('content');
$scope.hasTabs = attr.hasTabs;
var newScope = $scope.$parent.$new(); if(attr.hasHeader) {
$element.addClass('has-header');
$element.append(transclude(newScope)); }
}; if(attr.hasTabs) {
$element.addClass('has-tabs');
}
}
} }
} }
}) })

View File

@ -0,0 +1,57 @@
<html ng-app="navTest">
<head>
<meta charset="utf-8">
<title>Nav Bars</title>
<!-- Sets initial viewport load and disables zooming -->
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="/vendor/font-awesome/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="../../../../dist/ionic.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-touch.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-animate.js"></script>
<style>
.reveal-animation {
/*
-webkit-transform: translate3d(0%, 0, 0);
transform: translate3d(0%, 0, 0);
-webkit-transition: -webkit-transform 1s ease-in-out;
transition: transform 1s ease-in-out;
*/
}
.reveal-animation.ng-enter {
-webkit-transition: .2s ease-in-out all;
-webkit-transform:translate3d(100%,0,0) ;
}
.reveal-animation.ng-enter-active {
-webkit-transform:translate3d(0,0,0) ;
}
.reveal-animation.ng-leave {
-webkit-transition: .2s ease-in-out all;
-webkit-transform:translate3d(0%,0,0);
}
.reveal-animation.ng-leave-active {
-webkit-transition: .2s ease-in-out all;
-webkit-transform:translate3d(-100%,0,0);
}
</style>
</head>
<body>
<content has-header="true" ng-controller="AppCtrl" class="reveal-animation">
</content>
<script src="../../../../dist/ionic.js"></script>
<script src="../../../../dist/ionic-angular.js"></script>
<script>
angular.module('navTest', ['ionic.ui'])
.controller('AppCtrl', function($scope, $compile, $element) {
$scope.what = {};
})
</script>
</body>
</html>

View File

@ -12,4 +12,9 @@ describe('Ionic Content directive', function() {
element = compile('<content></content>')(scope); element = compile('<content></content>')(scope);
expect(element.hasClass('content')).toBe(true); expect(element.hasClass('content')).toBe(true);
}); });
it('Has header', function() {
element = compile('<content has-header="true"></content>')(scope);
expect(element.hasClass('has-header')).toEqual(true);
});
}); });