[Pkg-javascript-commits] [sockjs-client] 111/350: Abstract out browser checks
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:49 UTC 2016
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.
commit ce62f1da4764d022edb8bc53002067dca131097e
Author: Bryce Kahle <bkahle at gmail.com>
Date: Fri Oct 10 13:26:40 2014 -0400
Abstract out browser checks
---
lib/transport/lib/iframe.js | 6 ++----
lib/transport/receiver/jsonp.js | 3 ++-
lib/transport/xhr-streaming.js | 3 ++-
lib/utils/browser.js | 13 +++++++++++++
4 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/lib/transport/lib/iframe.js b/lib/transport/lib/iframe.js
index 6ac4442..f74ed77 100644
--- a/lib/transport/lib/iframe.js
+++ b/lib/transport/lib/iframe.js
@@ -17,6 +17,7 @@ var util = require('util')
, iframeUtils = require('../../utils/iframe')
, eventUtils = require('../../utils/event')
, random = require('../../utils/random')
+ , browser = require('../../utils/browser')
;
function IframeTransport(transport, transUrl, baseUrl) {
@@ -104,11 +105,8 @@ IframeTransport.prototype.send = function (message) {
IframeTransport.enabled = function() {
// postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
// huge delay, or not at all.
- var konqueror = global.navigator &&
- global.navigator.userAgent &&
- global.navigator.userAgent.indexOf('Konqueror') !== -1;
return ((typeof global.postMessage === 'function' ||
- typeof global.postMessage === 'object') && (!konqueror));
+ typeof global.postMessage === 'object') && (!browser.isKonqueror()));
};
module.exports = IframeTransport;
diff --git a/lib/transport/receiver/jsonp.js b/lib/transport/receiver/jsonp.js
index b5d5385..bd46d3c 100644
--- a/lib/transport/receiver/jsonp.js
+++ b/lib/transport/receiver/jsonp.js
@@ -2,6 +2,7 @@
var utils = require('../../utils/iframe')
, random = require('../../utils/random')
+ , browser = require('../../utils/browser')
, util = require('util')
, SimpleEvent = require('../../simpleevent')
, EventTarget = require('../../polyfills/eventtarget')
@@ -134,7 +135,7 @@ JsonpReceiver.prototype._createScript = function (url) {
// According to mozilla docs, in recent browsers script.async defaults
// to 'true', so we may use it to detect a good browser:
// https://developer.mozilla.org/en/HTML/Element/script
- if (!/opera/i.test(global.navigator.userAgent)) {
+ if (!browser.isOpera()) {
// Naively assume we're in IE
try {
script.htmlFor = script.id;
diff --git a/lib/transport/xhr-streaming.js b/lib/transport/xhr-streaming.js
index ae75544..0a2344e 100644
--- a/lib/transport/xhr-streaming.js
+++ b/lib/transport/xhr-streaming.js
@@ -6,6 +6,7 @@ var util = require('util')
, XHRCorsObject = require('./sender/xhr-cors')
, XHRLocalObject = require('./sender/xhr-local')
, utils = require('../utils/origin')
+ , browser = require('../utils/browser')
, loc = require('../polyfills/location')
;
@@ -20,7 +21,7 @@ XhrStreamingTransport.enabled = function(url, info) {
return false;
}
// Opera doesn't support xhr-streaming
- if (global.navigator && /opera/i.test(global.navigator.userAgent)) {
+ if (browser.isOpera()) {
return false;
}
diff --git a/lib/utils/browser.js b/lib/utils/browser.js
new file mode 100644
index 0000000..82820b3
--- /dev/null
+++ b/lib/utils/browser.js
@@ -0,0 +1,13 @@
+'use strict';
+
+module.exports = {
+ isOpera: function () {
+ return global.navigator &&
+ /opera/i.test(global.navigator.userAgent);
+ }
+
+, isKonqueror: function () {
+ return global.navigator &&
+ /konqueror/i.test(global.navigator.userAgent);
+ }
+};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list