Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e22eb82
commit 8f231bd
Showing
7 changed files
with
230 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bower_components | ||
*.log | ||
node_modules | ||
*.swp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,61 @@ | ||
(function (ng) { | ||
|
||
function switchSce(ie7Config, $sceProvider) { | ||
$sceProvider.enabled(!ie7Config.on); | ||
function ie7ConfigProvider() { | ||
this._hash = {}; | ||
this.init(); | ||
} | ||
|
||
function fixAnimation(ie7Config, $$asyncCallback, $animate) { | ||
ie7ConfigProvider.prototype.init = function () { | ||
var rootElement = document.getElementById('ng-app'); | ||
this.set('enabled', !!ng.element(rootElement).length); | ||
}; | ||
|
||
ie7ConfigProvider.prototype.set = function (prop, val) { | ||
this._hash[prop] = val; | ||
}; | ||
|
||
ie7ConfigProvider.prototype.get = function (prop) { | ||
return this._hash[prop]; | ||
}; | ||
|
||
ie7ConfigProvider.prototype.$get = function () { | ||
return this._hash; | ||
}; | ||
|
||
function switchSce(ie7ConfigProvider, $sceProvider) { | ||
var enable = $sceProvider.enabled(); | ||
if (ie7ConfigProvider.get('enabled')) { | ||
enable = false; | ||
} | ||
$sceProvider.enabled(enable); | ||
} | ||
|
||
function $animatePatch(ie7Config, $$asyncCallback, $animate) { | ||
function async(fn) { | ||
return fn && $$asyncCallback(fn); | ||
fn && $$asyncCallback(fn); | ||
} | ||
|
||
if (ie7Config.on) { | ||
$animate.addClass = function (element, className, done) { | ||
ng.element(element).addClass(className); | ||
async(done); | ||
}; | ||
function addClass(element, className, done) { | ||
ng.element(element).addClass(className); | ||
async(done); | ||
} | ||
|
||
function removeClass(element, className, done) { | ||
ng.element(element).removeClass(className); | ||
async(done); | ||
} | ||
|
||
$animate.removeClass = function (element, className, done) { | ||
ng.element(element).removeClass(className); | ||
async(done); | ||
}; | ||
if (ie7Config.enabled) { | ||
$animate.addClass = addClass; | ||
$animate.removeClass = removeClass; | ||
} | ||
} | ||
|
||
ng | ||
.module('ie7-support', []) | ||
.constant('ie7Config', { on: !!document.getElementById('ng-app') }) | ||
.config(['ie7Config', '$sceProvider', switchSce]) | ||
.run(['ie7Config', '$$asyncCallback', '$animate', fixAnimation]); | ||
.provider('ie7Config', ie7ConfigProvider) | ||
.config(['ie7ConfigProvider', '$sceProvider', switchSce]) | ||
.run(['ie7Config', '$$asyncCallback', '$animate', $animatePatch]); | ||
|
||
}(angular)); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
describe('angular-ie7-support', function () { | ||
|
||
var ngElementStub; | ||
|
||
function enableIE7() { | ||
toggleIE7(true); | ||
} | ||
|
||
function disableIE7() { | ||
toggleIE7(false); | ||
} | ||
|
||
function toggleIE7(on) { | ||
var appEl = document.getElementById('ng-app'), | ||
ie7App = on ? [0] : []; | ||
ngElementStub = sinon.stub(angular, 'element'); | ||
ngElementStub.withArgs(appEl).returns(ie7App); | ||
} | ||
|
||
beforeEach(module('ie7-support')); | ||
|
||
afterEach(function () { | ||
angular.element.restore && angular.element.restore(); | ||
}); | ||
|
||
describe('SCE', function () { | ||
|
||
describe('when enabled', function () { | ||
|
||
beforeEach(enableIE7); | ||
|
||
it('should have turned it off by default', inject(['$sce', function ($sce) { | ||
expect($sce.isEnabled()).toBe(false); | ||
}])); | ||
|
||
}); | ||
|
||
describe('when disabled', function () { | ||
|
||
beforeEach(disableIE7); | ||
|
||
it('should leave it to whatever it was before', inject(['$sce', function ($sce) { | ||
expect($sce.isEnabled()).toBe(true); | ||
}])); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe('$animate', function () { | ||
|
||
var addClass, removeClass, call; | ||
|
||
function stub() { | ||
addClass = sinon.spy(); | ||
removeClass = sinon.spy(); | ||
ngElementStub.withArgs('mung').returns({ | ||
addClass: addClass, | ||
removeClass: removeClass | ||
}); | ||
} | ||
|
||
call = inject(['$animate', function ($animate) { | ||
$animate.addClass('mung', 'some class'); | ||
$animate.removeClass('mung', 'some other class'); | ||
}]); | ||
|
||
describe('when enabled', function () { | ||
|
||
beforeEach(enableIE7); | ||
beforeEach(stub); | ||
beforeEach(call); | ||
|
||
it("will construct an element and call it's methods", function () { | ||
expect(addClass).toHaveBeenCalledWithExactly('some class'); | ||
expect(removeClass).toHaveBeenCalledWithExactly('some other class'); | ||
}); | ||
|
||
}); | ||
|
||
describe('when disabled', function () { | ||
|
||
beforeEach(disableIE7); | ||
beforeEach(stub); | ||
beforeEach(call); | ||
|
||
it("will fall back", function () { | ||
expect(addClass.callCount).toBe(0); | ||
expect(removeClass.callCount).toBe(0); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Karma configuration | ||
// Generated on Mon Jun 23 2014 10:57:54 GMT+0100 (BST) | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
|
||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: '..', | ||
|
||
|
||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['jasmine'], | ||
|
||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
'bower_components/angular/angular.js', | ||
'bower_components/angular-mocks/angular-mocks.js', | ||
'bower_components/sinonjs/sinon.js', | ||
'bower_components/jasmine-sinon/lib/jasmine-sinon.js', | ||
'angular-ie7-support.js', | ||
'test/**/*.spec.js' | ||
], | ||
|
||
|
||
// list of files to exclude | ||
exclude: [ | ||
'**/*.swp' | ||
], | ||
|
||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
|
||
}, | ||
|
||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress'], | ||
|
||
|
||
// web server port | ||
port: 9876, | ||
|
||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
|
||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['PhantomJS'], | ||
|
||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: false | ||
}); | ||
}; |