mv $.parseUserAgentString to the one place that uses it
This was only used in this one file. So instead of loading on every Page in instructure_misc_helpers.js, I moved it to the one place that actually uses it Test plan: * the page views page should still work the same as it always has Change-Id: I916040f35bc08c77564de6c7104f4250a53a987e Reviewed-on: https://gerrit.instructure.com/194380 Tested-by: Jenkins Reviewed-by: Steven Burnett <sburnett@instructure.com> QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Steven Burnett <sburnett@instructure.com>
This commit is contained in:
parent
3b7aa2c1ae
commit
75fcbfecc6
|
@ -16,10 +16,46 @@
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import $ from 'jquery'
|
|
||||||
import Backbone from 'Backbone'
|
import Backbone from 'Backbone'
|
||||||
|
import I18n from 'i18n!modelsPageView'
|
||||||
import TextHelper from '../str/TextHelper'
|
import TextHelper from '../str/TextHelper'
|
||||||
import 'jquery.instructure_misc_helpers' // $.parseUserAgentString
|
|
||||||
|
function parseUserAgentString(userAgent) {
|
||||||
|
userAgent = (userAgent || '').toLowerCase()
|
||||||
|
const data = {
|
||||||
|
version: (userAgent.match(/.+(?:me|ox|it|ra|ie|er|rv|version)[\/: ]([\d.]+)/) || [0, null])[1],
|
||||||
|
chrome: /chrome/.test(userAgent),
|
||||||
|
safari: /webkit/.test(userAgent),
|
||||||
|
opera: /opera/.test(userAgent),
|
||||||
|
msie: (/msie/.test(userAgent) || /trident/.test(userAgent)) && !/opera/.test(userAgent),
|
||||||
|
firefox: /firefox/.test(userAgent),
|
||||||
|
mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent),
|
||||||
|
speedgrader: /speedgrader/.test(userAgent)
|
||||||
|
}
|
||||||
|
let browser = null
|
||||||
|
if (data.chrome) {
|
||||||
|
browser = 'Chrome'
|
||||||
|
} else if (data.safari) {
|
||||||
|
browser = 'Safari'
|
||||||
|
} else if (data.opera) {
|
||||||
|
browser = 'Opera'
|
||||||
|
} else if (data.msie) {
|
||||||
|
browser = 'Internet Explorer'
|
||||||
|
} else if (data.firefox) {
|
||||||
|
browser = 'Firefox'
|
||||||
|
} else if (data.mozilla) {
|
||||||
|
browser = 'Mozilla'
|
||||||
|
} else if (data.speedgrader) {
|
||||||
|
browser = 'SpeedGrader for iPad'
|
||||||
|
}
|
||||||
|
if (!browser) {
|
||||||
|
browser = I18n.t('browsers.unrecognized', 'Unrecognized Browser')
|
||||||
|
} else if (data.version) {
|
||||||
|
data.version = data.version.split(/\./).slice(0, 2).join('.')
|
||||||
|
browser = `${browser} ${data.version}`
|
||||||
|
}
|
||||||
|
return browser
|
||||||
|
}
|
||||||
|
|
||||||
export default class PageView extends Backbone.Model {
|
export default class PageView extends Backbone.Model {
|
||||||
isLinkable() {
|
isLinkable() {
|
||||||
|
@ -29,7 +65,7 @@ export default class PageView extends Backbone.Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
summarizedUserAgent() {
|
summarizedUserAgent() {
|
||||||
return this.get('app_name') || $.parseUserAgentString(this.get('user_agent'))
|
return this.get('app_name') || parseUserAgentString(this.get('user_agent'))
|
||||||
}
|
}
|
||||||
|
|
||||||
readableInteractionTime() {
|
readableInteractionTime() {
|
||||||
|
|
|
@ -110,43 +110,6 @@ import './vendor/jquery.scrollTo'
|
||||||
return $.map(res.split(/\s/), function(word) { return (word[0] || "").toUpperCase() + word.substring(1); }).join(" ");
|
return $.map(res.split(/\s/), function(word) { return (word[0] || "").toUpperCase() + word.substring(1); }).join(" ");
|
||||||
};
|
};
|
||||||
|
|
||||||
$.parseUserAgentString = function(userAgent) {
|
|
||||||
userAgent = (userAgent || "").toLowerCase();
|
|
||||||
var data = {
|
|
||||||
version: (userAgent.match( /.+(?:me|ox|it|ra|ie|er|rv|version)[\/: ]([\d.]+)/ ) || [0,null])[1],
|
|
||||||
chrome: /chrome/.test( userAgent ),
|
|
||||||
safari: /webkit/.test( userAgent ),
|
|
||||||
opera: /opera/.test( userAgent ),
|
|
||||||
msie: (/msie/.test( userAgent ) || (/trident/.test( userAgent ))) && !(/opera/.test( userAgent )),
|
|
||||||
firefox: /firefox/.test( userAgent),
|
|
||||||
mozilla: /mozilla/.test( userAgent ) && !(/(compatible|webkit)/.test( userAgent )),
|
|
||||||
speedgrader: /speedgrader/.test( userAgent )
|
|
||||||
};
|
|
||||||
var browser = null;
|
|
||||||
if(data.chrome) {
|
|
||||||
browser = "Chrome";
|
|
||||||
} else if(data.safari) {
|
|
||||||
browser = "Safari";
|
|
||||||
} else if(data.opera) {
|
|
||||||
browser = "Opera";
|
|
||||||
} else if(data.msie) {
|
|
||||||
browser = "Internet Explorer";
|
|
||||||
} else if(data.firefox) {
|
|
||||||
browser = "Firefox";
|
|
||||||
} else if(data.mozilla) {
|
|
||||||
browser = "Mozilla";
|
|
||||||
} else if(data.speedgrader) {
|
|
||||||
browser = "SpeedGrader for iPad";
|
|
||||||
}
|
|
||||||
if (!browser) {
|
|
||||||
browser = I18n.t('browsers.unrecognized', "Unrecognized Browser");
|
|
||||||
} else if(data.version) {
|
|
||||||
data.version = data.version.split(/\./).slice(0,2).join(".");
|
|
||||||
browser = browser + " " + data.version;
|
|
||||||
}
|
|
||||||
return browser;
|
|
||||||
};
|
|
||||||
|
|
||||||
$.fileSize = function(bytes) {
|
$.fileSize = function(bytes) {
|
||||||
var factor = 1024;
|
var factor = 1024;
|
||||||
if(bytes < factor) {
|
if(bytes < factor) {
|
||||||
|
|
Loading…
Reference in New Issue