summaryrefslogtreecommitdiff
path: root/src/static/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/static/js')
-rw-r--r--src/static/js/ace2_inner.js5
-rw-r--r--src/static/js/broadcast.js2
-rw-r--r--src/static/js/browser.js240
-rw-r--r--src/static/js/collab_client.js2
-rw-r--r--src/static/js/farbtastic.js4
-rw-r--r--src/static/js/jquery_browser.js50
-rw-r--r--src/static/js/pad.js5
-rw-r--r--src/static/js/pad_userlist.js2
-rw-r--r--src/static/js/rjquery.js7
9 files changed, 250 insertions, 67 deletions
diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js
index 850d2516..3728efb2 100644
--- a/src/static/js/ace2_inner.js
+++ b/src/static/js/ace2_inner.js
@@ -28,7 +28,6 @@ $ = jQuery = require('./rjquery').$;
_ = require("./underscore");
var isNodeText = Ace2Common.isNodeText,
- browser = $.browser,
getAssoc = Ace2Common.getAssoc,
setAssoc = Ace2Common.setAssoc,
isTextNode = Ace2Common.isTextNode,
@@ -52,6 +51,7 @@ function Ace2Inner(){
var SkipList = require('./skiplist');
var undoModule = require('./undomodule').undoModule;
var AttributeManager = require('./AttributeManager');
+ var browser = require('./browser');
var DEBUG = false; //$$ build script replaces the string "var DEBUG=true;//$$" with "var DEBUG=false;"
// changed to false
@@ -3722,7 +3722,6 @@ function Ace2Inner(){
}
if ((!specialHandled) && isTypeForCmdKey && String.fromCharCode(which).toLowerCase() == "z" && (evt.metaKey || evt.ctrlKey) && !evt.altKey)
{
- // cmd-Z (undo)
fastIncorp(6);
evt.preventDefault();
if (evt.shiftKey)
@@ -3857,7 +3856,7 @@ function Ace2Inner(){
/* Attempt to apply some sanity to cursor handling in Chrome after a copy / paste event
We have to do this the way we do because rep. doesn't hold the value for keyheld events IE if the user
presses and holds the arrow key .. Sorry if this is ugly, blame Chrome's weird handling of viewports after new content is added*/
- if((evt.which == 37 || evt.which == 38 || evt.which == 39 || evt.which == 40) && $.browser.chrome){
+ if((evt.which == 37 || evt.which == 38 || evt.which == 39 || evt.which == 40) && browser.chrome){
var viewport = getViewPortTopBottom();
var myselection = document.getSelection(); // get the current caret selection, can't use rep. here because that only gives us the start position not the current
var caretOffsetTop = myselection.focusNode.parentNode.offsetTop || myselection.focusNode.offsetTop; // get the carets selection offset in px IE 214
diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js
index 9ac8ca3d..191d802e 100644
--- a/src/static/js/broadcast.js
+++ b/src/static/js/broadcast.js
@@ -66,7 +66,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
}
// for IE
- if ($.browser.msie)
+ if (browser.msie)
{
try
{
diff --git a/src/static/js/browser.js b/src/static/js/browser.js
new file mode 100644
index 00000000..f763963e
--- /dev/null
+++ b/src/static/js/browser.js
@@ -0,0 +1,240 @@
+/*!
+ * Bowser - a browser detector
+ * https://github.com/ded/bowser
+ * MIT License | (c) Dustin Diaz 2014
+ */
+
+!function (name, definition) {
+ if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition()
+ else if (typeof define == 'function' && define.amd) define(definition)
+ else this[name] = definition()
+}('bowser', function () {
+ /**
+ * See useragents.js for examples of navigator.userAgent
+ */
+
+ var t = true
+
+ function detect(ua) {
+
+ function getFirstMatch(regex) {
+ var match = ua.match(regex);
+ return (match && match.length > 1 && match[1]) || '';
+ }
+
+ var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
+ , likeAndroid = /like android/i.test(ua)
+ , android = !likeAndroid && /android/i.test(ua)
+ , versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i)
+ , tablet = /tablet/i.test(ua)
+ , mobile = !tablet && /[^-]mobi/i.test(ua)
+ , result
+
+ if (/opera|opr/i.test(ua)) {
+ result = {
+ name: 'Opera'
+ , opera: t
+ , version: versionIdentifier || getFirstMatch(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)
+ }
+ }
+ else if (/windows phone/i.test(ua)) {
+ result = {
+ name: 'Windows Phone'
+ , windowsphone: t
+ , msie: t
+ , version: getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (/msie|trident/i.test(ua)) {
+ result = {
+ name: 'Internet Explorer'
+ , msie: t
+ , version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (/chrome|crios|crmo/i.test(ua)) {
+ result = {
+ name: 'Chrome'
+ , chrome: t
+ , version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (iosdevice) {
+ result = {
+ name : iosdevice == 'iphone' ? 'iPhone' : iosdevice == 'ipad' ? 'iPad' : 'iPod'
+ }
+ // WTF: version is not part of user agent in web apps
+ if (versionIdentifier) {
+ result.version = versionIdentifier
+ }
+ }
+ else if (/sailfish/i.test(ua)) {
+ result = {
+ name: 'Sailfish'
+ , sailfish: t
+ , version: getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (/seamonkey\//i.test(ua)) {
+ result = {
+ name: 'SeaMonkey'
+ , seamonkey: t
+ , version: getFirstMatch(/seamonkey\/(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (/firefox|iceweasel/i.test(ua)) {
+ result = {
+ name: 'Firefox'
+ , firefox: t
+ , version: getFirstMatch(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
+ }
+ if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
+ result.firefoxos = t
+ }
+ }
+ else if (/silk/i.test(ua)) {
+ result = {
+ name: 'Amazon Silk'
+ , silk: t
+ , version : getFirstMatch(/silk\/(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (android) {
+ result = {
+ name: 'Android'
+ , version: versionIdentifier
+ }
+ }
+ else if (/phantom/i.test(ua)) {
+ result = {
+ name: 'PhantomJS'
+ , phantom: t
+ , version: getFirstMatch(/phantomjs\/(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (/blackberry|\bbb\d+/i.test(ua) || /rim\stablet/i.test(ua)) {
+ result = {
+ name: 'BlackBerry'
+ , blackberry: t
+ , version: versionIdentifier || getFirstMatch(/blackberry[\d]+\/(\d+(\.\d+)?)/i)
+ }
+ }
+ else if (/(web|hpw)os/i.test(ua)) {
+ result = {
+ name: 'WebOS'
+ , webos: t
+ , version: versionIdentifier || getFirstMatch(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)
+ };
+ /touchpad\//i.test(ua) && (result.touchpad = t)
+ }
+ else if (/bada/i.test(ua)) {
+ result = {
+ name: 'Bada'
+ , bada: t
+ , version: getFirstMatch(/dolfin\/(\d+(\.\d+)?)/i)
+ };
+ }
+ else if (/tizen/i.test(ua)) {
+ result = {
+ name: 'Tizen'
+ , tizen: t
+ , version: getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i) || versionIdentifier
+ };
+ }
+ else if (/safari/i.test(ua)) {
+ result = {
+ name: 'Safari'
+ , safari: t
+ , version: versionIdentifier
+ }
+ }
+ else result = {}
+
+ // set webkit or gecko flag for browsers based on these engines
+ if (/(apple)?webkit/i.test(ua)) {
+ result.name = result.name || "Webkit"
+ result.webkit = t
+ if (!result.version && versionIdentifier) {
+ result.version = versionIdentifier
+ }
+ } else if (!result.opera && /gecko\//i.test(ua)) {
+ result.name = result.name || "Gecko"
+ result.gecko = t
+ result.version = result.version || getFirstMatch(/gecko\/(\d+(\.\d+)?)/i)
+ }
+
+ // set OS flags for platforms that have multiple browsers
+ if (android || result.silk) {
+ result.android = t
+ } else if (iosdevice) {
+ result[iosdevice] = t
+ result.ios = t
+ }
+
+ // OS version extraction
+ var osVersion = '';
+ if (iosdevice) {
+ osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i);
+ osVersion = osVersion.replace(/[_\s]/g, '.');
+ } else if (android) {
+ osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i);
+ } else if (result.windowsphone) {
+ osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
+ } else if (result.webos) {
+ osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
+ } else if (result.blackberry) {
+ osVersion = getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i);
+ } else if (result.bada) {
+ osVersion = getFirstMatch(/bada\/(\d+(\.\d+)*)/i);
+ } else if (result.tizen) {
+ osVersion = getFirstMatch(/tizen[\/\s](\d+(\.\d+)*)/i);
+ }
+ if (osVersion) {
+ result.osversion = osVersion;
+ }
+
+ // device type extraction
+ var osMajorVersion = osVersion.split('.')[0];
+ if (tablet || iosdevice == 'ipad' || (android && (osMajorVersion == 3 || (osMajorVersion == 4 && !mobile))) || result.silk) {
+ result.tablet = t
+ } else if (mobile || iosdevice == 'iphone' || iosdevice == 'ipod' || android || result.blackberry || result.webos || result.bada) {
+ result.mobile = t
+ }
+
+ // Graded Browser Support
+ // http://developer.yahoo.com/yui/articles/gbs
+ if ((result.msie && result.version >= 10) ||
+ (result.chrome && result.version >= 20) ||
+ (result.firefox && result.version >= 20.0) ||
+ (result.safari && result.version >= 6) ||
+ (result.opera && result.version >= 10.0) ||
+ (result.ios && result.osversion && result.osversion.split(".")[0] >= 6) ||
+ (result.blackberry && result.version >= 10.1)
+ ) {
+ result.a = t;
+ }
+ else if ((result.msie && result.version < 10) ||
+ (result.chrome && result.version < 20) ||
+ (result.firefox && result.version < 20.0) ||
+ (result.safari && result.version < 6) ||
+ (result.opera && result.version < 10.0) ||
+ (result.ios && result.osversion && result.osversion.split(".")[0] < 6)
+ ) {
+ result.c = t
+ } else result.x = t
+
+ return result
+ }
+
+ var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')
+
+
+ /*
+ * Set our detect method to the main bowser object so we can
+ * reuse it to test other user agents.
+ * This is needed to implement future tests.
+ */
+ bowser._detect = detect;
+
+ return bowser
+});
diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js
index 146ec51b..c59c36a6 100644
--- a/src/static/js/collab_client.js
+++ b/src/static/js/collab_client.js
@@ -82,7 +82,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
{}
};
- if ($.browser.mozilla)
+ if (browser.mozilla)
{
// Prevent "escape" from taking effect and canceling a comet connection;
// doesn't work if focus is on an iframe.
diff --git a/src/static/js/farbtastic.js b/src/static/js/farbtastic.js
index 114c4d72..8a61627d 100644
--- a/src/static/js/farbtastic.js
+++ b/src/static/js/farbtastic.js
@@ -170,7 +170,7 @@ $._farbtastic = function (container, options) {
// New color
color2 = fb.pack(fb.HSLToRGB([d2, 1, 0.5]));
if (i > 0) {
- if ($.browser.msie) {
+ if (browser.msie) {
// IE's gradient calculations mess up the colors. Correct along the diagonals.
var corr = (1 + Math.min(Math.abs(Math.tan(angle1)), Math.abs(Math.tan(Math.PI / 2 - angle1)))) / n;
color1 = fb.pack(fb.HSLToRGB([d1 - 0.15 * corr, 1, 0.5]));
@@ -254,7 +254,7 @@ $._farbtastic = function (container, options) {
fb.ctxMask.drawImage(buffer, 0, 0, sz + 1, sz + 1, -sq, -sq, sq * 2, sq * 2);
}
// Method #2: drawing commands (old Canvas).
- else if (!$.browser.msie) {
+ else if (!browser.msie) {
// Render directly at half-resolution
var sz = Math.floor(size / 2);
calculateMask(sz, sz, function (x, y, c, a) {
diff --git a/src/static/js/jquery_browser.js b/src/static/js/jquery_browser.js
deleted file mode 100644
index 0d61e0dd..00000000
--- a/src/static/js/jquery_browser.js
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- Copied from jQuery 1.8, the last jquery version with browser recognition support
-*/
-
-(function(){
- // Use of jQuery.browser is frowned upon.
- // More details: http://api.jquery.com/jQuery.browser
- // jQuery.uaMatch maintained for back-compat
- var uaMatch = function( ua ) {
- ua = ua.toLowerCase();
-
- var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
- /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
- /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
- /(msie) ([\w.]+)/.exec( ua ) ||
- ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
- [];
-
- return {
- browser: match[ 1 ] || "",
- version: match[ 2 ] || "0"
- };
- };
-
- var userAgent = navigator.userAgent;
- var matched = uaMatch(userAgent);
- var browser = {};
-
- if ( matched.browser ) {
- browser[ matched.browser ] = true;
- browser.version = matched.version;
- }
-
- // Chrome is Webkit, but Webkit is also Safari.
- if ( browser.chrome ) {
- browser.webkit = true;
- } else if ( browser.webkit ) {
- browser.safari = true;
- }
-
- //custom extensions, the original jquery didn't have these
- browser.windows = /windows/i.test(userAgent);
- browser.mobile = /mobile/i.test(userAgent) || /android/i.test(userAgent);
-
- if(typeof exports !== 'undefined'){
- exports.browser = browser;
- } else{
- $.browser = browser;
- }
-})(); \ No newline at end of file
diff --git a/src/static/js/pad.js b/src/static/js/pad.js
index 4f5b23c7..78c20657 100644
--- a/src/static/js/pad.js
+++ b/src/static/js/pad.js
@@ -43,7 +43,6 @@ var padsavedrevs = require('./pad_savedrevs');
var paduserlist = require('./pad_userlist').paduserlist;
var padutils = require('./pad_utils').padutils;
var colorutils = require('./colorutils').colorutils;
-
var createCookie = require('./pad_utils').createCookie;
var readCookie = require('./pad_utils').readCookie;
var randomString = require('./pad_utils').randomString;
@@ -453,13 +452,13 @@ var pad = {
pad.initTime = +(new Date());
pad.padOptions = clientVars.initialOptions;
- if ((!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf("1.8.") == 0)))
+ if ((!browser.msie) && (!(browser.mozilla && browser.version.indexOf("1.8.") == 0)))
{
document.domain = document.domain; // for comet
}
// for IE
- if ($.browser.msie)
+ if (browser.msie)
{
try
{
diff --git a/src/static/js/pad_userlist.js b/src/static/js/pad_userlist.js
index 93c8ff70..595de92a 100644
--- a/src/static/js/pad_userlist.js
+++ b/src/static/js/pad_userlist.js
@@ -730,7 +730,7 @@ var paduserlist = (function()
$("#myswatch").css({'background-color': myUserInfo.colorId});
- if ($.browser.msie && parseInt($.browser.version) <= 8) {
+ if (browser.msie && parseInt(browser.version) <= 8) {
$("li[data-key=showusers] > a").css({'box-shadow': 'inset 0 0 30px ' + myUserInfo.colorId,'background-color': myUserInfo.colorId});
}
else
diff --git a/src/static/js/rjquery.js b/src/static/js/rjquery.js
index d9d1ed16..1c0d98e6 100644
--- a/src/static/js/rjquery.js
+++ b/src/static/js/rjquery.js
@@ -1,10 +1,5 @@
// Proviedes a require'able version of jQuery without leaking $ and jQuery;
-
require('./jquery');
var jq = window.$.noConflict(true);
-
-//added the old browser recognition
-jq.browser = require('./jquery_browser').browser;
-
-exports.jQuery = exports.$ = jq; \ No newline at end of file
+exports.jQuery = exports.$ = jq;