Add NoopStrategy for Samsung browsers
This commit is contained in:
Родитель
02ee8c98a0
Коммит
67a532cf23
|
@ -7,6 +7,7 @@ var IosStrategy = require('./strategies/ios');
|
||||||
var AndroidChromeStrategy = require('./strategies/android-chrome');
|
var AndroidChromeStrategy = require('./strategies/android-chrome');
|
||||||
var IE9Strategy = require('./strategies/ie9');
|
var IE9Strategy = require('./strategies/ie9');
|
||||||
var BaseStrategy = require('./strategies/base');
|
var BaseStrategy = require('./strategies/base');
|
||||||
|
var NoopStrategy = require('./strategies/noop');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instances of this class can be used to modify the formatter for an input
|
* Instances of this class can be used to modify the formatter for an input
|
||||||
|
@ -29,12 +30,7 @@ function RestrictedInput(options) {
|
||||||
// SamsungBrowser contains 'Chrome' in userAgent, so check it first
|
// SamsungBrowser contains 'Chrome' in userAgent, so check it first
|
||||||
if (device.isSamsungBrowser()) {
|
if (device.isSamsungBrowser()) {
|
||||||
// Disable formatting due to various digits being dropped
|
// Disable formatting due to various digits being dropped
|
||||||
this.strategy = {
|
this.strategy = new NoopStrategy(options);
|
||||||
getUnformattedValue: function () {
|
|
||||||
return options.element.value;
|
|
||||||
},
|
|
||||||
setPattern: function () {}
|
|
||||||
};
|
|
||||||
} else if (device.isIos()) {
|
} else if (device.isIos()) {
|
||||||
this.strategy = new IosStrategy(options);
|
this.strategy = new IosStrategy(options);
|
||||||
} else if (device.isAndroidChrome()) {
|
} else if (device.isAndroidChrome()) {
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
function NoopStrategy(options) {
|
||||||
|
this.inputElement = options.element;
|
||||||
|
}
|
||||||
|
|
||||||
|
NoopStrategy.prototype.getUnformattedValue = function () {
|
||||||
|
return this.inputElement.value;
|
||||||
|
};
|
||||||
|
|
||||||
|
NoopStrategy.prototype.setPattern = function () {};
|
||||||
|
|
||||||
|
NoopStrategy.prototype.pasteEventHandler = function () {};
|
||||||
|
|
||||||
|
module.exports = NoopStrategy;
|
|
@ -5,6 +5,7 @@ var BaseStrategy = require('../../../lib/strategies/base');
|
||||||
var IosStrategy = require('../../../lib/strategies/ios');
|
var IosStrategy = require('../../../lib/strategies/ios');
|
||||||
var IE9Strategy = require('../../../lib/strategies/ie9');
|
var IE9Strategy = require('../../../lib/strategies/ie9');
|
||||||
var AndroidChromeStrategy = require('../../../lib/strategies/android-chrome');
|
var AndroidChromeStrategy = require('../../../lib/strategies/android-chrome');
|
||||||
|
var NoopStrategy = require('../../../lib/strategies/noop');
|
||||||
var device = require('../../../lib/device');
|
var device = require('../../../lib/device');
|
||||||
|
|
||||||
describe('RestrictedInput', function () {
|
describe('RestrictedInput', function () {
|
||||||
|
@ -78,6 +79,19 @@ describe('RestrictedInput', function () {
|
||||||
|
|
||||||
expect(ri.strategy).to.be.an.instanceof(IE9Strategy);
|
expect(ri.strategy).to.be.an.instanceof(IE9Strategy);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses NoopStrategy for Samsung browser', function () {
|
||||||
|
var ri;
|
||||||
|
|
||||||
|
global.sandbox.stub(device, 'isSamsungBrowser').returns(true);
|
||||||
|
|
||||||
|
ri = new RestrictedInput({
|
||||||
|
element: document.createElement('input'),
|
||||||
|
pattern: '{{a}}'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ri.strategy).to.be.an.instanceof(NoopStrategy);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getUnformattedValue()', function () {
|
describe('getUnformattedValue()', function () {
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var NoopStrategy = require('../../../../lib/strategies/noop');
|
||||||
|
var BaseStrategy = require('../../../../lib/strategies/base');
|
||||||
|
|
||||||
|
describe('Noop Strategy', function () {
|
||||||
|
it('has the same public methods as Base Strategy', function () {
|
||||||
|
var noopPublicMethods = Object.getOwnPropertyNames(NoopStrategy.prototype).filter(function (property) {
|
||||||
|
return typeof NoopStrategy.prototype[property] === 'function' && property[0] !== '_';
|
||||||
|
});
|
||||||
|
var basePublicMethods = Object.getOwnPropertyNames(BaseStrategy.prototype).filter(function (property) {
|
||||||
|
return typeof BaseStrategy.prototype[property] === 'function' && property[0] !== '_';
|
||||||
|
});
|
||||||
|
|
||||||
|
basePublicMethods.forEach(function (method) {
|
||||||
|
expect(noopPublicMethods).to.contain(method);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Загрузка…
Ссылка в новой задаче