From 80a11082b11eb622307eccda076f2778d4e54a25 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 15:06:40 +0100 Subject: [PATCH 01/11] auto indent fix --- lib/ace/editor.js | 2 +- lib/ace/test/text_edit_test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index a442c38f..2fd404b7 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -426,7 +426,7 @@ var Editor =function(renderer, doc) { this.bgTokenizer.getState(cursor.row, function (lineState) { var shouldOutdent = _self.mode.checkOutdent(lineState, _self.doc.getLine(cursor.row), text); var line = _self.doc.getLine(cursor.row), - lineIndent = _self.mode.getNextLineIndent(lineState, line, _self.doc.getTabString()); + lineIndent = _self.mode.getNextLineIndent(lineState, line.slice(0, cursor.column), _self.doc.getTabString()); var end = _self.doc.insert(cursor, text); /* TODO: This shortcut is somehow broken diff --git a/lib/ace/test/text_edit_test.js b/lib/ace/test/text_edit_test.js index 61658cca..d917b363 100644 --- a/lib/ace/test/text_edit_test.js +++ b/lib/ace/test/text_edit_test.js @@ -133,6 +133,15 @@ var Test = { editor.indent(); assert.equal(["a12345", " b12345", "c12345"].join("\n"), doc.toString()); }, + + "test: no auto indent if cursor is before the {" : function() { + var doc = new Document("{", new JavaScriptMode()); + var editor = new Editor(new MockRenderer(), doc); + + editor.moveCursorTo(0, 0); + editor.onTextInput("\n"); + assert.equal(["", "{"].join("\n"), doc.toString()); + }, "test: outdent block" : function() { var doc = new Document([" a12345", " b12345", " c12345"].join("\n")); From a7963dc9a4a3da1e5caacd6c3f5b08a658521838 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 18:21:43 +0100 Subject: [PATCH 02/11] use more robust type checks --- plugins/pilot/util.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index 7fed5068..d3d3c747 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -140,25 +140,27 @@ exports.rateLimit = function(maxRate, scope, func) { } }; +var objectToString = Object.prototype.toString; + /** * Return true if it is a String */ exports.isString = function(it) { - return (typeof it == "string" || it instanceof String); + return it && objectToString.call(it) === "[object String]"; }; /** * Returns true if it is a Boolean. */ exports.isBoolean = function(it) { - return (typeof it == 'boolean'); + return it && objectToString.call(it) === "[object Boolean]"; }; /** * Returns true if it is a Number. */ exports.isNumber = function(it) { - return (typeof it == 'number' && isFinite(it)); + return it && objectToString.call(it) === "[object Number]" && isFinite(it); }; /** @@ -174,22 +176,9 @@ exports.isObject = function(it) { * Is the passed object a function? * From dojo.isFunction() */ -exports.isFunction = (function() { - var _isFunction = function(it) { - var t = typeof it; // must evaluate separately due to bizarre Opera bug. See #8937 - //Firefox thinks object HTML element is a function, so test for nodeType. - return it && (t == "function" || it instanceof Function) && !it.nodeType; // Boolean - }; - - return exports.isSafari ? - // only slow this down w/ gratuitious casting in Safari (not WebKit) - function(/*anything*/ it) { - if (typeof it == "function" && it == "[object NodeList]") { - return false; - } - return _isFunction(it); // Boolean - } : _isFunction; -})(); +exports.isFunction = function(it) { + return it && objectToString.call(it) === "[object Function]"; +}; /** * A la Prototype endsWith(). Takes a regex excluding the '$' end marker From c0540f7e1ea63a8dcacaa045cc6200bdb40644be Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 18:22:34 +0100 Subject: [PATCH 03/11] move arrayRemove to lang --- plugins/cockpit/cli.js | 4 ++-- plugins/pilot/canon.js | 4 ++-- plugins/pilot/lang.js | 11 +++++++++++ plugins/pilot/util.js | 12 ------------ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/plugins/cockpit/cli.js b/plugins/cockpit/cli.js index bb8428c7..df183782 100644 --- a/plugins/cockpit/cli.js +++ b/plugins/cockpit/cli.js @@ -39,7 +39,7 @@ define(function(require, exports, module) { var console = require('pilot/console'); -var util = require('pilot/util'); +var lang = require('pilot/lang'); var oop = require('pilot/oop'); var EventEmitter = require('pilot/event_emitter').EventEmitter; @@ -1048,7 +1048,7 @@ oop.inherits(CliRequisition, Requisition); } } - util.arrayRemove(names, assignment.name); + lang.arrayRemove(names, assignment.name); args.splice(i, 1); // We don't need to i++ if we splice } diff --git a/plugins/pilot/canon.js b/plugins/pilot/canon.js index e0037cf0..3a4165a0 100644 --- a/plugins/pilot/canon.js +++ b/plugins/pilot/canon.js @@ -44,7 +44,7 @@ var EventEmitter = require('pilot/event_emitter').EventEmitter; var catalog = require('pilot/catalog'); var Status = require('pilot/types').Status; var types = require('pilot/types'); -var util = require('pilot/util'); +var lang = require('pilot/lang'); /* // TODO: this doesn't belong here - or maybe anywhere? @@ -153,7 +153,7 @@ function upgradeType(param) { function removeCommand(command) { var name = (typeof command === 'string' ? command : command.name); delete commands[name]; - util.arrayRemove(commandNames, name); + lang.arrayRemove(commandNames, name); }; function getCommand(name) { diff --git a/plugins/pilot/lang.js b/plugins/pilot/lang.js index 5170a261..b8b946e1 100644 --- a/plugins/pilot/lang.js +++ b/plugins/pilot/lang.js @@ -62,6 +62,17 @@ exports.arrayToMap = function(arr) { }; +/** + * splice out of 'array' anything that === 'value' + */ +exports.arrayRemove = function(array, value) { + for (var i = 0; i <= array.length; i++) { + if (value === array[i]) { + array.splice(i, 1); + } + } +}; + exports.escapeRegExp = function(str) { return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }; diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index d3d3c747..9ce05809 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -618,16 +618,4 @@ exports.rectsEqual = function(r1, r2, delta) { return true; }; -/** - * splice out of 'array' anything that === 'value' - */ -exports.arrayRemove = function(array, value) { - for (var i = 0; i <= array.length; i++) { - if (value === array[i]) { - array.splice(i, 1); - } - } -}; - - }); From 74408f30aca110da3c21556b3c71e53366bdfe68 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 18:23:18 +0100 Subject: [PATCH 04/11] remove css class handling from util.js --- plugins/cockpit/ui/requestView.js | 26 ++++++++--------- plugins/pilot/dom.js | 18 ++++++++++++ plugins/pilot/util.js | 47 ------------------------------- 3 files changed, 30 insertions(+), 61 deletions(-) diff --git a/plugins/cockpit/ui/requestView.js b/plugins/cockpit/ui/requestView.js index 24458a46..8e21d3ca 100644 --- a/plugins/cockpit/ui/requestView.js +++ b/plugins/cockpit/ui/requestView.js @@ -37,16 +37,14 @@ define(function(require, exports, module) { - -var util = require('pilot/util'); - -var requestViewCss = require("text!cockpit/ui/requestView.css"); var dom = require("pilot/dom"); -dom.importCssString(requestViewCss); - +var event = require("pilot/event"); var requestViewHtml = require("text!cockpit/ui/requestView.html"); var Templater = require("pilot/domtemplate").Templater; +var requestViewCss = require("text!cockpit/ui/requestView.css"); +dom.importCssString(requestViewCss); + /** * Pull the HTML into the DOM, but don't add it to the document */ @@ -102,24 +100,24 @@ RequestView.prototype = { hideOutput: function(ev) { this.output.style.display = 'none'; - util.addClass(this.hide, 'cmd_hidden'); - util.removeClass(this.show, 'cmd_hidden'); + dom.addCssClass(this.hide, 'cmd_hidden'); + dom.removeCssClass(this.show, 'cmd_hidden'); - ev.stopPropagation(); + event.stopPropagation(ev); }, showOutput: function(ev) { this.output.style.display = 'block'; - util.removeClass(this.hide, 'cmd_hidden'); - util.addClass(this.show, 'cmd_hidden'); + dom.removeCssClass(this.hide, 'cmd_hidden'); + dom.addCssClass(this.show, 'cmd_hidden'); - ev.stopPropagation(); + event.stopPropagation(ev); }, remove: function(ev) { this.cliView.output.removeChild(this.rowin); this.cliView.output.removeChild(this.rowout); - ev.stopPropagation(); + event.stopPropagation(ev); }, onRequestChange: function(ev) { @@ -140,7 +138,7 @@ RequestView.prototype = { }, this); this.cliView.scrollOutputToBottom(); - util.setClass(this.output, 'cmd_error', this.request.error); + dom.setCssClass(this.output, 'cmd_error', this.request.error); this.throb.style.display = this.request.completed ? 'none' : 'block'; } diff --git a/plugins/pilot/dom.js b/plugins/pilot/dom.js index 99d51636..585ec820 100644 --- a/plugins/pilot/dom.js +++ b/plugins/pilot/dom.js @@ -51,12 +51,30 @@ exports.hasCssClass = function(el, name) { return classes.indexOf(name) !== -1; }; +/** +* Add a CSS class to the list of classes on the given node +*/ exports.addCssClass = function(el, name) { if (!exports.hasCssClass(el, name)) { el.className += " " + name; } }; +/** + * Add or remove a CSS class from the list of classes on the given node + * depending on the value of include + */ +exports.setCssClass = function(node, className, include) { + if (include) { + exports.addCssClass(node, className); + } else { + exports.removeCssClass(node, className); + } +}; + +/** +* Remove a CSS class from the list of classes on the given node +*/ exports.removeCssClass = function(el, name) { var classes = el.className.split(/\s+/g); while (true) { diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index 9ce05809..bb1550e3 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -480,53 +480,6 @@ exports.formatDate = function (date) { */ exports.formatDate.shortMonths = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; -/** - * Add a CSS class to the list of classes on the given node - */ -exports.addClass = function(node, className) { - var parts = className.split(/\s+/); - var cls = " " + node.className + " "; - for (var i = 0, len = parts.length, c; i < len; ++i) { - c = parts[i]; - if (c && cls.indexOf(" " + c + " ") < 0) { - cls += c + " "; - } - } - node.className = cls.trim(); -}; - -/** - * Remove a CSS class from the list of classes on the given node - */ -exports.removeClass = function(node, className) { - var cls; - if (className !== undefined) { - var parts = className.split(/\s+/); - cls = " " + node.className + " "; - for (var i = 0, len = parts.length; i < len; ++i) { - cls = cls.replace(" " + parts[i] + " ", " "); - } - cls = cls.trim(); - } else { - cls = ""; - } - if (node.className != cls) { - node.className = cls; - } -}; - -/** - * Add or remove a CSS class from the list of classes on the given node - * depending on the value of include - */ -exports.setClass = function(node, className, include) { - if (include) { - exports.addClass(node, className); - } else { - exports.removeClass(node, className); - } -}; - /** * Is the passed object either null or undefined (using ===) */ From 5b02b658fedb954841592de127038198c3f2f163 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 18:24:58 +0100 Subject: [PATCH 05/11] remove stopEvent from util -> event --- plugins/pilot/event.js | 3 +++ plugins/pilot/keyboard/keyutil.js | 3 ++- plugins/pilot/util.js | 8 -------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/pilot/event.js b/plugins/pilot/event.js index 2beaff41..fdea7164 100644 --- a/plugins/pilot/event.js +++ b/plugins/pilot/event.js @@ -61,6 +61,9 @@ exports.removeListener = function(elem, type, callback) { } }; +/** +* Prevents propagation and clobbers the default action of the passed event +*/ exports.stopEvent = function(e) { exports.stopPropagation(e); exports.preventDefault(e); diff --git a/plugins/pilot/keyboard/keyutil.js b/plugins/pilot/keyboard/keyutil.js index bbc0ac5a..497f316e 100644 --- a/plugins/pilot/keyboard/keyutil.js +++ b/plugins/pilot/keyboard/keyutil.js @@ -33,6 +33,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'); @@ -215,7 +216,7 @@ exports.addKeyDownListener = function(element, boundFunction) { var handled = boundFunction(ev); // If the boundFunction returned true, then stop the event. if (handled) { - util.stopEvent(ev); + dom.stopEvent(ev); } return handled; }; diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index bb1550e3..0ae29c9e 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -419,14 +419,6 @@ if (typeof(document) !== 'undefined' && document.compareDocumentPosition) { }; } -/** - * Prevents propagation and clobbers the default action of the passed event - */ -exports.stopEvent = function(ev) { - ev.preventDefault(); - ev.stopPropagation(); -}; - /** * Create a random password of the given length (default 16 chars) */ From cb547d86bc46d8279ffb08b601691b74247b9f8b Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 18:25:16 +0100 Subject: [PATCH 06/11] remove repeatString from util --- plugins/pilot/util.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index 0ae29c9e..662e69bd 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -260,21 +260,6 @@ exports.makeArray = function(number, character) { return newArray; }; -/** - * Repeat a string a given number of times. - * @param string String to repeat - * @param repeat Number of times to repeat - */ -exports.repeatString = function(string, repeat) { - var newstring = ''; - - for (var i = 0; i < repeat; i++) { - newstring += string; - } - - return newstring; -}; - /** * Given a row, find the number of leading spaces. * E.g. an array with the string " aposjd" would return 2 From d78bb1b5abadba36227366f5acf1e781570f1893 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 18:25:29 +0100 Subject: [PATCH 07/11] remove type check --- plugins/pilot/util.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index 662e69bd..e75f9d4f 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -217,9 +217,8 @@ exports.indexOfProperty = function(array, propertyName, item) { * A la Prototype last(). */ exports.last = function(array) { - if (Array.isArray(array)) { - return array[array.length - 1]; - } + +return array[array.length - 1]; }; /** From ad19a8f98e64d732036c5f6b33b69f21dc483642 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 18:50:26 +0100 Subject: [PATCH 08/11] consolidate user agent sniffing from util.js and core.js into a new module useragent.js --- lib/ace/keybinding.js | 6 +-- plugins/pilot/event.js | 6 +-- plugins/pilot/keyboard/keyutil.js | 7 ++- plugins/pilot/stacktrace.js | 8 +-- plugins/pilot/{core.js => useragent.js} | 51 ++++++++++++++---- plugins/pilot/util.js | 71 ------------------------- 6 files changed, 54 insertions(+), 95 deletions(-) rename plugins/pilot/{core.js => useragent.js} (63%) 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) { From d45b248bfff7e1f2a5fab04c342b32dfad3ef7a1 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 19:03:54 +0100 Subject: [PATCH 09/11] extract type checks into a separate module --- plugins/pilot/commands/basic.js | 11 +++-- plugins/pilot/typecheck.js | 80 +++++++++++++++++++++++++++++++++ plugins/pilot/util.js | 40 ----------------- 3 files changed, 85 insertions(+), 46 deletions(-) create mode 100644 plugins/pilot/typecheck.js diff --git a/plugins/pilot/commands/basic.js b/plugins/pilot/commands/basic.js index ae16a47e..68b34fa8 100644 --- a/plugins/pilot/commands/basic.js +++ b/plugins/pilot/commands/basic.js @@ -37,8 +37,7 @@ define(function(require, exports, module) { - -var util = require('pilot/util'); +var checks = require("pilot/typecheck"); var canon = require('pilot/canon'); /** @@ -165,11 +164,11 @@ var evalCommandSpec = { var type = ''; var x; - if (util.isFunction(result)) { + if (checks.isFunction(result)) { // converts the function to a well formated string msg = (result + '').replace(/\n/g, '
').replace(/ /g, ' '); type = 'function'; - } else if (util.isObject(result)) { + } else if (checks.isObject(result)) { if (Array.isArray(result)) { type = 'array'; } else { @@ -181,9 +180,9 @@ var evalCommandSpec = { for (x in result) { if (result.hasOwnProperty(x)) { - if (util.isFunction(result[x])) { + if (checks.isFunction(result[x])) { value = '[function]'; - } else if (util.isObject(result[x])) { + } else if (checks.isObject(result[x])) { value = '[object]'; } else { value = result[x]; diff --git a/plugins/pilot/typecheck.js b/plugins/pilot/typecheck.js new file mode 100644 index 00000000..40ea1630 --- /dev/null +++ b/plugins/pilot/typecheck.js @@ -0,0 +1,80 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Skywriter. + * + * The Initial Developer of the Original Code is + * Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2009 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Joe Walker (jwalker@mozilla.com) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { + +var objectToString = Object.prototype.toString; + +/** + * Return true if it is a String + */ +exports.isString = function(it) { + return it && objectToString.call(it) === "[object String]"; +}; + +/** + * Returns true if it is a Boolean. + */ +exports.isBoolean = function(it) { + return it && objectToString.call(it) === "[object Boolean]"; +}; + +/** + * Returns true if it is a Number. + */ +exports.isNumber = function(it) { + return it && objectToString.call(it) === "[object Number]" && isFinite(it); +}; + +/** + * Hack copied from dojo. + */ +exports.isObject = function(it) { + return it !== undefined && + (it === null || typeof it == "object" || + Array.isArray(it) || exports.isFunction(it)); +}; + +/** + * Is the passed object a function? + * From dojo.isFunction() + */ +exports.isFunction = function(it) { + return it && objectToString.call(it) === "[object Function]"; +}; + +}); \ No newline at end of file diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index 6c1dc027..6d9a0c29 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -140,46 +140,6 @@ exports.rateLimit = function(maxRate, scope, func) { } }; -var objectToString = Object.prototype.toString; - -/** - * Return true if it is a String - */ -exports.isString = function(it) { - return it && objectToString.call(it) === "[object String]"; -}; - -/** - * Returns true if it is a Boolean. - */ -exports.isBoolean = function(it) { - return it && objectToString.call(it) === "[object Boolean]"; -}; - -/** - * Returns true if it is a Number. - */ -exports.isNumber = function(it) { - return it && objectToString.call(it) === "[object Number]" && isFinite(it); -}; - -/** - * Hack copied from dojo. - */ -exports.isObject = function(it) { - return it !== undefined && - (it === null || typeof it == "object" || - Array.isArray(it) || exports.isFunction(it)); -}; - -/** - * Is the passed object a function? - * From dojo.isFunction() - */ -exports.isFunction = function(it) { - return it && objectToString.call(it) === "[object Function]"; -}; - /** * A la Prototype endsWith(). Takes a regex excluding the '$' end marker */ From c2c2fa3448716c06a04262648c20095eff07e342 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 19:09:13 +0100 Subject: [PATCH 10/11] add deprecation warning --- plugins/pilot/util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index 6d9a0c29..9a80e472 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -37,6 +37,9 @@ define(function(require, exports, module) { +throw new Error("pilot/util is deprecated. If you need one of the functions from this\ +module please copy the code to the appropriate placein pilot/(lang|dom|event)"); + /** * Create an object representing a de-serialized query section of a URL. * Query keys with multiple values are returned in an array. From e6b3ed5ac9bda56c487ae3fa0361865e98eabff8 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Dec 2010 19:09:27 +0100 Subject: [PATCH 11/11] fix keyutil --- plugins/pilot/keyboard/keyutil.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pilot/keyboard/keyutil.js b/plugins/pilot/keyboard/keyutil.js index 4585d20e..12bc3a99 100644 --- a/plugins/pilot/keyboard/keyutil.js +++ b/plugins/pilot/keyboard/keyutil.js @@ -33,7 +33,7 @@ For more information about SproutCore, visit http://www.sproutcore.com define(function(require, exports, module) { -var dom = require('pilot/dom'); +var event = require('pilot/event'); var useragent = require('pilot/useragent'); /** @@ -215,7 +215,7 @@ exports.addKeyDownListener = function(element, boundFunction) { var handled = boundFunction(ev); // If the boundFunction returned true, then stop the event. if (handled) { - dom.stopEvent(ev); + event.stopEvent(ev); } return handled; };