Skip to content

Commit

Permalink
refactor($ionicLoading,$ionicPopup): factor out common code, add tests
Browse files Browse the repository at this point in the history
Also fixes $ionicLoading flickering on ios7 in beta.1.
  • Loading branch information
ajoslin committed Apr 8, 2014
1 parent 8af018b commit 98e7e3d
Show file tree
Hide file tree
Showing 24 changed files with 959 additions and 692 deletions.
2 changes: 1 addition & 1 deletion config/build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
],

angularIonicFiles: [
'js/ext/angular/src/ionicAngular.js',
'js/ext/angular/src/*.js',
'js/ext/angular/src/service/**/*.js',
'js/ext/angular/src/directive/**/*.js',
'js/ext/angular/src/controller/**/*.js'
Expand Down
3 changes: 2 additions & 1 deletion config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = function(config) {
'config/lib/js/angular/angular-animate.js',
'config/lib/js/angular/angular-sanitize.js',
'config/lib/js/angular/angular-mocks.js',
'config/lib/js/angular-ui/angular-ui-router.js'
'config/lib/js/angular-ui/angular-ui-router.js',
'config/lib/testutil.js'
]
.concat(buildConfig.ionicFiles)
.concat(buildConfig.angularIonicFiles)
Expand Down
42 changes: 42 additions & 0 deletions config/lib/testutil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Included by karma
* Usage: var result = TestUtil.unwrapPromise(promise);
*/
var TestUtil = {
unwrapPromise: function(value) {
var result;
inject(function($rootScope, $q) {
$q.when(value).then(function(data) {
result = data;
});
$rootScope.$apply();
});
return result;
},
createMockTimeout: function(shouldApply) {
var timeoutQueue = [];
function timeout(fn, delay) {
timeoutQueue.push({fn: fn, delay: delay});
}
timeout.queue = timeoutQueue;
timeout.expect = function(expectedDelay) {
if (timeoutQueue.length > 0) {
return {
process: function() {
var tick = timeoutQueue.shift();
if (angular.isDefined(expectedDelay)) {
expect(tick.delay).toEqual(expectedDelay);
}
tick.fn();
shouldApply && inject(function($rootScope) {
$rootScope.$apply();
});
}
};
} else {
expect('TimoutQueue empty. Expecting delay of ').toEqual(delay);
}
};
return timeout;
}
};
45 changes: 45 additions & 0 deletions js/ext/angular/src/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* deprecated.js
* https://github.com/wearefractal/deprecated/
* Copyright (c) 2014 Fractal <[email protected]>
* License MIT
*/
//Interval object
var deprecated = {
method: function(msg, log, fn) {
var called = false;
return function deprecatedMethod(){
if (!called) {
called = true;
log(msg);
}
return fn.apply(this, arguments);
};
},

field: function(msg, log, parent, field, val) {
var called = false;
var getter = function(){
if (!called) {
called = true;
log(msg);
}
return val;
};
var setter = function(v) {
if (!called) {
called = true;
log(msg);
}
val = v;
return v;
};
Object.defineProperty(parent, field, {
get: getter,
set: setter,
enumerable: true
});
return;
}
};

25 changes: 0 additions & 25 deletions js/ext/angular/src/directive/ionicLoading.js

This file was deleted.

64 changes: 0 additions & 64 deletions js/ext/angular/src/directive/ionicPopup.js

This file was deleted.

1 change: 0 additions & 1 deletion js/ext/angular/src/ionicAngular.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ angular.module('ionic.ui', [
'ionic.ui.header',
'ionic.ui.list',
'ionic.ui.navBar',
'ionic.ui.popup',
'ionic.ui.radio',
'ionic.ui.scroll',
'ionic.ui.sideMenu',
Expand Down
37 changes: 37 additions & 0 deletions js/ext/angular/src/service/ionicBackdrop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
angular.module('ionic')

/**
* @private
*/
.factory('$ionicBackdrop', [
'$animate',
'$document',
function($animate, $document) {

var el;
var backdropHolds = 0;

return {
retain: retain,
release: release,
_getElement: getElement
};

function getElement() {
if (!el) {
el = angular.element('<div class="backdrop ng-hide">');
$document[0].body.appendChild(el[0]);
}
return el;
}
function retain() {
if ( (++backdropHolds) === 1 ) {
$animate.removeClass(getElement(), 'ng-hide');
}
}
function release() {
if ( (--backdropHolds) === 0 ) {
$animate.addClass(getElement(), 'ng-hide');
}
}
}]);
Loading

0 comments on commit 98e7e3d

Please sign in to comment.