diff --git a/lib/ace/keybinding.js b/lib/ace/keybinding.js index fecf2463..db54ac00 100644 --- a/lib/ace/keybinding.js +++ b/lib/ace/keybinding.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var core = require("pilot/core"); +var useragent = require("pilot/useragent"); var event = require("pilot/event"); var default_mac = require("ace/conf/keybindings/default_mac").bindings; var default_win = require("ace/conf/keybindings/default_win").bindings; @@ -50,7 +50,7 @@ var KeyBinding = function(element, editor, config) { var _self = this; event.addKeyListener(element, function(e) { // opera on mac swaps ctrl and meta keys - if (core.isOpera && core.isMac) + if (useragent.isOpera && useragent.isMac) var hashId = 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0); else @@ -145,7 +145,7 @@ var KeyBinding = function(element, editor, config) { } this.setConfig = function(config) { - this.config = config || (core.isMac + this.config = config || (useragent.isMac ? default_mac : default_win); if (typeof this.config.reverse == "undefined") diff --git a/plugins/pilot/event.js b/plugins/pilot/event.js index fdea7164..34621fe6 100644 --- a/plugins/pilot/event.js +++ b/plugins/pilot/event.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var core = require("pilot/core"); +var useragent = require("pilot/useragent"); exports.addListener = function(elem, type, callback) { if (elem.addEventListener) { @@ -215,7 +215,7 @@ exports.addMultiMouseDownListener = function(el, button, count, timeout, callbac }; exports.addListener(el, "mousedown", listener); - core.isIE && exports.addListener(el, "dblclick", listener); + useragent.isIE && exports.addListener(el, "dblclick", listener); }; exports.addKeyListener = function(el, callback) { @@ -227,7 +227,7 @@ exports.addKeyListener = function(el, callback) { }); // repeated keys are fired as keypress and not keydown events - if (core.isMac && (core.isGecko || core.isOpera)) { + if (useragent.isMac && (useragent.isGecko || useragent.isOpera)) { exports.addListener(el, "keypress", function(e) { var keyId = e.keyIdentifier || e.keyCode; if (lastDown !== keyId) { diff --git a/plugins/pilot/keyboard/keyutil.js b/plugins/pilot/keyboard/keyutil.js index 497f316e..4585d20e 100644 --- a/plugins/pilot/keyboard/keyutil.js +++ b/plugins/pilot/keyboard/keyutil.js @@ -34,8 +34,7 @@ For more information about SproutCore, visit http://www.sproutcore.com define(function(require, exports, module) { var dom = require('pilot/dom'); -var util = require('pilot/util'); - +var useragent = require('pilot/useragent'); /** * Helper functions and hashes for key handling. @@ -222,7 +221,7 @@ exports.addKeyDownListener = function(element, boundFunction) { }; element.addEventListener('keydown', function(ev) { - if (util.isMozilla) { + if (useragent.isGecko) { // Check for function keys (like DELETE, TAB, LEFT, RIGHT...) if (exports.KeyHelper.FUNCTION_KEYS[ev.keyCode]) { return true; @@ -241,7 +240,7 @@ exports.addKeyDownListener = function(element, boundFunction) { }, false); element.addEventListener('keypress', function(ev) { - if (util.isMozilla) { + if (useragent.isGecko) { // If this is a function key, we have to use the keyCode. if (exports.KeyHelper.FUNCTION_KEYS[ev.keyCode]) { return handleBoundFunction(ev); diff --git a/plugins/pilot/stacktrace.js b/plugins/pilot/stacktrace.js index 961d88cc..b5094e73 100644 --- a/plugins/pilot/stacktrace.js +++ b/plugins/pilot/stacktrace.js @@ -1,6 +1,6 @@ define(function(require, exports, module) { -var util = require("pilot/util"); +var ua = require("pilot/useragent"); var console = require('pilot/console'); // Changed to suit the specific needs of running within Skywriter @@ -65,11 +65,11 @@ var mode = (function() { // functionality provided by Firebug. Firebug tries to do the right // thing here and break, but it happens every time you load the page. // bug 554105 - if (util.isMozilla) { + if (ua.isGecko) { return 'firefox'; - } else if (util.isOpera) { + } else if (ua.isOpera) { return 'opera'; - } else if (util.isSafari) { + } else { return 'other'; } diff --git a/plugins/pilot/core.js b/plugins/pilot/useragent.js similarity index 63% rename from plugins/pilot/core.js rename to plugins/pilot/useragent.js index 40991657..06c9432e 100644 --- a/plugins/pilot/core.js +++ b/plugins/pilot/useragent.js @@ -38,23 +38,54 @@ define(function(require, exports, module) { var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase(); +var ua = navigator.userAgent; +var av = navigator.appVersion; +/** Is the user using a browser that identifies itself as Windows */ exports.isWin = (os == "win"); + +/** Is the user using a browser that identifies itself as Mac OS */ exports.isMac = (os == "mac"); + +/** Is the user using a browser that identifies itself as Linux */ exports.isLinux = (os == "linux"); + exports.isIE = ! + "\v1"; -exports.isGecko = window.controllers && window.navigator.product === "Gecko"; + +/** Is this Firefox or related? */ +exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko"; + +/** Is this Opera */ exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]"; -exports.provide = function(namespace) { - var parts = namespace.split("."); - var obj = window; - for (var i=0; i= 0; + +/** + * I hate doing this, but we need some way to determine if the user is on a Mac + * The reason is that users have different expectations of their key combinations. + * + * Take copy as an example, Mac people expect to use CMD or APPLE + C + * Windows folks expect to use CTRL + C + */ +exports.OS = { + LINUX: 'LINUX', + MAC: 'MAC', + WINDOWS: 'WINDOWS' +}; + +/** + * Return an exports.OS constant + */ +exports.getOS = function() { + if (exports.isMac) { + return exports.OS['MAC']; + } else if (exports.isLinux) { + return exports.OS['LINUX']; + } else { + return exports.OS['WINDOWS']; } }; diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index e75f9d4f..6c1dc027 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -320,77 +320,6 @@ exports.englishFromCamel = function(camel) { }).trim(); }; -/** - * I hate doing this, but we need some way to determine if the user is on a Mac - * The reason is that users have different expectations of their key combinations. - * - * Take copy as an example, Mac people expect to use CMD or APPLE + C - * Windows folks expect to use CTRL + C - */ -exports.OS = { - LINUX: 'LINUX', - MAC: 'MAC', - WINDOWS: 'WINDOWS' -}; - -var ua = navigator.userAgent; -var av = navigator.appVersion; - -/** Is the user using a browser that identifies itself as Linux */ -exports.isLinux = av.indexOf("Linux") >= 0; - -/** Is the user using a browser that identifies itself as Windows */ -exports.isWindows = av.indexOf("Win") >= 0; - -/** Is the user using a browser that identifies itself as WebKit */ -exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined; - -/** Is the user using a browser that identifies itself as Chrome */ -exports.isChrome = parseFloat(ua.split("Chrome/")[1]) || undefined; - -/** Is the user using a browser that identifies itself as Mac OS */ -exports.isMac = av.indexOf("Macintosh") >= 0; - -/* Is this Firefox or related? */ -exports.isMozilla = av.indexOf('Gecko/') >= 0; - -if (ua.indexOf("AdobeAIR") >= 0) { - exports.isAIR = 1; -} - -/** - * Is the user using a browser that identifies itself as Safari - * See also: - * - http://developer.apple.com/internet/safari/faq.html#anchor2 - * - http://developer.apple.com/internet/safari/uamatrix.html - */ -var index = Math.max(av.indexOf("WebKit"), av.indexOf("Safari"), 0); -if (index && !exports.isChrome) { - // try to grab the explicit Safari version first. If we don't get - // one, look for less than 419.3 as the indication that we're on something - // "Safari 2-ish". - exports.isSafari = parseFloat(av.split("Version/")[1]); - if (!exports.isSafari || parseFloat(av.substr(index + 7)) <= 419.3) { - exports.isSafari = 2; - } -} - -if (ua.indexOf("Gecko") >= 0 && !exports.isWebKit) { - exports.isMozilla = parseFloat(av); -} - -/** - * Return a exports.OS constant - */ -exports.getOS = function() { - if (exports.isMac) { - return exports.OS['MAC']; - } else if (exports.isLinux) { - return exports.OS['LINUX']; - } else { - return exports.OS['WINDOWS']; - } -}; /** Returns true if the DOM element "b" is inside the element "a". */ if (typeof(document) !== 'undefined' && document.compareDocumentPosition) {