diff --git a/lib/ace/config.js b/lib/ace/config.js index 6116da96..34bf50fd 100644 --- a/lib/ace/config.js +++ b/lib/ace/config.js @@ -34,7 +34,9 @@ define(function(require, exports, module) { var lang = require("./lib/lang"); var oop = require("./lib/oop"); var net = require("./lib/net"); -var EventEmitter = require("./lib/event_emitter").EventEmitter; +var AppConfig = require("./lib/app_config").AppConfig; + +module.exports = exports = new AppConfig(); var global = (function() { return this; @@ -69,8 +71,6 @@ exports.all = function() { }; // module loading -oop.implement(exports, EventEmitter); - exports.moduleUrl = function(name, component) { if (options.$moduleUrls[name]) return options.$moduleUrls[name]; @@ -142,7 +142,6 @@ exports.loadModule = function(moduleName, onLoad) { net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad); }; - // initialization function init(packaged) { options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged); @@ -200,102 +199,4 @@ function deHyphenate(str) { return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); }); } -var optionsProvider = { - setOptions: function(optList) { - Object.keys(optList).forEach(function(key) { - this.setOption(key, optList[key]); - }, this); - }, - getOptions: function(optionNames) { - var result = {}; - if (!optionNames) { - optionNames = Object.keys(this.$options); - } else if (!Array.isArray(optionNames)) { - result = optionNames; - optionNames = Object.keys(result); - } - optionNames.forEach(function(key) { - result[key] = this.getOption(key); - }, this); - return result; - }, - setOption: function(name, value) { - if (this["$" + name] === value) - return; - var opt = this.$options[name]; - if (!opt) { - if (typeof console != "undefined" && console.warn) - console.warn('misspelled option "' + name + '"'); - return undefined; - } - if (opt.forwardTo) - return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value); - - if (!opt.handlesSet) - this["$" + name] = value; - if (opt && opt.set) - opt.set.call(this, value); - }, - getOption: function(name) { - var opt = this.$options[name]; - if (!opt) { - if (typeof console != "undefined" && console.warn) - console.warn('misspelled option "' + name + '"'); - return undefined; - } - if (opt.forwardTo) - return this[opt.forwardTo] && this[opt.forwardTo].getOption(name); - return opt && opt.get ? opt.get.call(this) : this["$" + name]; - } -}; - -var defaultOptions = {}; -/* - * option {name, value, initialValue, setterName, set, get } - */ -exports.defineOptions = function(obj, path, options) { - if (!obj.$options) - defaultOptions[path] = obj.$options = {}; - - Object.keys(options).forEach(function(key) { - var opt = options[key]; - if (typeof opt == "string") - opt = {forwardTo: opt}; - - opt.name || (opt.name = key); - obj.$options[opt.name] = opt; - if ("initialValue" in opt) - obj["$" + opt.name] = opt.initialValue; - }); - - // implement option provider interface - oop.implement(obj, optionsProvider); - - return this; -}; - -exports.resetOptions = function(obj) { - Object.keys(obj.$options).forEach(function(key) { - var opt = obj.$options[key]; - if ("value" in opt) - obj.setOption(key, opt.value); - }); -}; - -exports.setDefaultValue = function(path, name, value) { - var opts = defaultOptions[path] || (defaultOptions[path] = {}); - if (opts[name]) { - if (opts.forwardTo) - exports.setDefaultValue(opts.forwardTo, name, value); - else - opts[name].value = value; - } -}; - -exports.setDefaultValues = function(path, optionHash) { - Object.keys(optionHash).forEach(function(key) { - exports.setDefaultValue(path, key, optionHash[key]); - }); -}; - }); diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 932a9e3d..347c854a 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -969,8 +969,7 @@ var EditSession = function(text, mode) { try { this.$worker = this.$mode.createWorker(this); } catch (e) { - if (typeof console == "object" && console.error) - console.log("Could not load worker", e); + config.warn("Could not load worker", e); this.$worker = null; } }; diff --git a/lib/ace/editor.js b/lib/ace/editor.js index a3fdc978..78c7c18d 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -717,7 +717,10 @@ var Editor = function(renderer, session) { this.$cursorChange(); if (!this.$blockScrolling) { - console.warn("In next version of ace automatic scrolling into view will be disabled"); + config.warn("Automatically scrolling cursor into view after selection change", + "this will be disabled in the next version", + "set editor.$blockScrolling = Infinity to disable this message" + ); this.renderer.scrollCursorIntoView(); } diff --git a/lib/ace/lib/app_config.js b/lib/ace/lib/app_config.js new file mode 100644 index 00000000..84b9e70c --- /dev/null +++ b/lib/ace/lib/app_config.js @@ -0,0 +1,158 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"no use strict"; + +var lang = require("./lang"); +var oop = require("./oop"); +var EventEmitter = require("./event_emitter").EventEmitter; + +var optionsProvider = { + setOptions: function(optList) { + Object.keys(optList).forEach(function(key) { + this.setOption(key, optList[key]); + }, this); + }, + getOptions: function(optionNames) { + var result = {}; + if (!optionNames) { + optionNames = Object.keys(this.$options); + } else if (!Array.isArray(optionNames)) { + result = optionNames; + optionNames = Object.keys(result); + } + optionNames.forEach(function(key) { + result[key] = this.getOption(key); + }, this); + return result; + }, + setOption: function(name, value) { + if (this["$" + name] === value) + return; + var opt = this.$options[name]; + if (!opt) { + return warn('misspelled option "' + name + '"'); + } + if (opt.forwardTo) + return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value); + + if (!opt.handlesSet) + this["$" + name] = value; + if (opt && opt.set) + opt.set.call(this, value); + }, + getOption: function(name) { + var opt = this.$options[name]; + if (!opt) { + return warn('misspelled option "' + name + '"'); + } + if (opt.forwardTo) + return this[opt.forwardTo] && this[opt.forwardTo].getOption(name); + return opt && opt.get ? opt.get.call(this) : this["$" + name]; + } +}; + +function warn(message) { + if (typeof console != "undefined" && console.warn) + console.warn.apply(console, arguments); +} + +function reportError(msg, data) { + var e = new Error(msg); + e.data = data; + if (typeof console == "object" && console.error) + console.error(e); + setTimeout(function() { throw e; }); +}; + +var AppConfig = function() { + this.$defaultOptions = {}; +}; + +(function() { + // module loading + oop.implement(this, EventEmitter); + /* + * option {name, value, initialValue, setterName, set, get } + */ + this.defineOptions = function(obj, path, options) { + if (!obj.$options) + this.$defaultOptions[path] = obj.$options = {}; + + Object.keys(options).forEach(function(key) { + var opt = options[key]; + if (typeof opt == "string") + opt = {forwardTo: opt}; + + opt.name || (opt.name = key); + obj.$options[opt.name] = opt; + if ("initialValue" in opt) + obj["$" + opt.name] = opt.initialValue; + }); + + // implement option provider interface + oop.implement(obj, optionsProvider); + + return this; + }; + + this.resetOptions = function(obj) { + Object.keys(obj.$options).forEach(function(key) { + var opt = obj.$options[key]; + if ("value" in opt) + obj.setOption(key, opt.value); + }); + }; + + this.setDefaultValue = function(path, name, value) { + var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {}); + if (opts[name]) { + if (opts.forwardTo) + this.setDefaultValue(opts.forwardTo, name, value); + else + opts[name].value = value; + } + }; + + this.setDefaultValues = function(path, optionHash) { + Object.keys(optionHash).forEach(function(key) { + this.setDefaultValue(path, key, optionHash[key]); + }); + }; + + this.warn = warn; + this.reportError = reportError; + +}).call(AppConfig.prototype); + +exports.AppConfig = AppConfig; + +}); diff --git a/lib/ace/lib/dom.js b/lib/ace/lib/dom.js index 65f20d7d..ef2f7caa 100644 --- a/lib/ace/lib/dom.js +++ b/lib/ace/lib/dom.js @@ -31,9 +31,6 @@ define(function(require, exports, module) { "use strict"; -if (typeof document == "undefined") - return; - var XHTML_NS = "http://www.w3.org/1999/xhtml"; exports.getDocumentHead = function(doc) { @@ -175,6 +172,10 @@ exports.getInnerHeight = function(element) { ); }; + +if (typeof document == "undefined") + return; + if (window.pageYOffset !== undefined) { exports.getPageScrollTop = function() { return window.pageYOffset; diff --git a/lib/ace/tokenizer.js b/lib/ace/tokenizer.js index a0756157..72490fbb 100644 --- a/lib/ace/tokenizer.js +++ b/lib/ace/tokenizer.js @@ -31,6 +31,7 @@ define(function(require, exports, module) { "use strict"; +var config = require("./config"); // tokenizing lines longer than this makes editor very slow var MAX_TOKEN_COUNT = 2000; /** @@ -353,13 +354,8 @@ var Tokenizer = function(rules) { }; }; - this.reportError = function(msg, data) { - var e = new Error(msg); - e.data = data; - if (typeof console == "object" && console.error) - console.error(e); - setTimeout(function() { throw e; }); - }; + this.reportError = config.reportError; + }).call(Tokenizer.prototype); exports.Tokenizer = Tokenizer;