Merge branch 'master' of https://github.com/ajaxorg/ace
Conflicts: plugins/cockpit/cli.js plugins/cockpit/lib/ui/plain.js plugins/cockpit/ui/plain.css plugins/cockpit/ui/plain.js plugins/pilot/canon.js plugins/pilot/lib/commands/history.js
This commit is contained in:
commit
0f505962d0
126 changed files with 3375 additions and 3518 deletions
|
|
@ -37,10 +37,9 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
|
||||
var console = require('pilot/console');
|
||||
var Trace = require('pilot/stacktrace').Trace;
|
||||
var oop = require('pilot/oop').oop;
|
||||
var oop = require('pilot/oop');
|
||||
var EventEmitter = require('pilot/event_emitter').EventEmitter;
|
||||
var catalog = require('pilot/catalog');
|
||||
var Status = require('pilot/types').Status;
|
||||
|
|
@ -71,11 +70,8 @@ var commandExtensionSpec = {
|
|||
indexOn: 'name'
|
||||
};
|
||||
|
||||
var env;
|
||||
|
||||
exports.startup = function(data, reason) {
|
||||
// TODO: this is probably all kinds of evil, but we need something working
|
||||
env = data.env;
|
||||
catalog.addExtensionSpec(commandExtensionSpec);
|
||||
};
|
||||
|
||||
|
|
@ -173,8 +169,7 @@ function getCommandNames() {
|
|||
* everything it needs to about the command params
|
||||
* @param command Either a command, or the name of one
|
||||
*/
|
||||
function exec(command, args, typed) {
|
||||
// TODO: Use requisition.toString rather than 'typed'
|
||||
function exec(command, env, args, typed) {
|
||||
if (typeof command === 'string') {
|
||||
command = commands[command];
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ if (typeof(window) === 'undefined') {
|
|||
// For each of the console functions, copy them if they exist, stub if not
|
||||
NAMES.forEach(function(name) {
|
||||
if (window.console && window.console[name]) {
|
||||
exports[name] = window.console[name].bind(window.console);
|
||||
exports[name] = Function.prototype.bind.call(window.console[name], window.console);
|
||||
} else {
|
||||
exports[name] = noop;
|
||||
}
|
||||
|
|
@ -37,27 +37,25 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var core = {};
|
||||
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
|
||||
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
|
||||
|
||||
core.isWin = (os == "win");
|
||||
core.isMac = (os == "mac");
|
||||
core.isLinux = (os == "linux");
|
||||
core.isIE = ! + "\v1";
|
||||
core.isGecko = window.controllers && window.navigator.product === "Gecko";
|
||||
exports.isWin = (os == "win");
|
||||
exports.isMac = (os == "mac");
|
||||
exports.isLinux = (os == "linux");
|
||||
exports.isIE = ! + "\v1";
|
||||
exports.isGecko = window.controllers && window.navigator.product === "Gecko";
|
||||
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
|
||||
|
||||
core.provide = function(namespace) {
|
||||
var parts = namespace.split(".");
|
||||
var obj = window;
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (!obj[part]) {
|
||||
obj[part] = {};
|
||||
}
|
||||
obj = obj[part];
|
||||
exports.provide = function(namespace) {
|
||||
var parts = namespace.split(".");
|
||||
var obj = window;
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (!obj[part]) {
|
||||
obj[part] = {};
|
||||
}
|
||||
};
|
||||
|
||||
exports.core = core;
|
||||
obj = obj[part];
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
136
plugins/pilot/dom.js
Normal file
136
plugins/pilot/dom.js
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/* ***** 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 Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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) {
|
||||
|
||||
exports.setText = function(elem, text) {
|
||||
if (elem.innerText !== undefined) {
|
||||
elem.innerText = text;
|
||||
}
|
||||
if (elem.textContent !== undefined) {
|
||||
elem.textContent = text;
|
||||
}
|
||||
};
|
||||
|
||||
exports.hasCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s+/g);
|
||||
return classes.indexOf(name) !== -1;
|
||||
};
|
||||
|
||||
exports.addCssClass = function(el, name) {
|
||||
if (!exports.hasCssClass(el, name)) {
|
||||
el.className += " " + name;
|
||||
}
|
||||
};
|
||||
|
||||
exports.removeCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s+/g);
|
||||
while (true) {
|
||||
var index = classes.indexOf(name);
|
||||
if (index == -1) {
|
||||
break;
|
||||
}
|
||||
classes.splice(index, 1);
|
||||
}
|
||||
el.className = classes.join(" ");
|
||||
};
|
||||
|
||||
exports.importCssString = function(cssText, doc){
|
||||
doc = doc || document;
|
||||
|
||||
if (doc.createStyleSheet) {
|
||||
var sheet = doc.createStyleSheet();
|
||||
sheet.cssText = cssText;
|
||||
}
|
||||
else {
|
||||
var style = doc.createElement("style");
|
||||
style.appendChild(doc.createTextNode(cssText));
|
||||
doc.getElementsByTagName("head")[0].appendChild(style);
|
||||
}
|
||||
};
|
||||
|
||||
exports.getInnerWidth = function(element) {
|
||||
return (parseInt(exports.computedStyle(element, "paddingLeft"))
|
||||
+ parseInt(exports.computedStyle(element, "paddingRight")) + element.clientWidth);
|
||||
};
|
||||
|
||||
exports.getInnerHeight = function(element) {
|
||||
return (parseInt(exports.computedStyle(element, "paddingTop"))
|
||||
+ parseInt(exports.computedStyle(element, "paddingBottom")) + element.clientHeight);
|
||||
};
|
||||
|
||||
exports.computedStyle = function(element, style) {
|
||||
if (window.getComputedStyle) {
|
||||
return (window.getComputedStyle(element, "") || {})[style] || "";
|
||||
}
|
||||
else {
|
||||
return element.currentStyle[style];
|
||||
}
|
||||
};
|
||||
|
||||
exports.scrollbarWidth = function() {
|
||||
|
||||
var inner = document.createElement('p');
|
||||
inner.style.width = "100%";
|
||||
inner.style.height = "200px";
|
||||
|
||||
var outer = document.createElement("div");
|
||||
var style = outer.style;
|
||||
|
||||
style.position = "absolute";
|
||||
style.left = "-10000px";
|
||||
style.overflow = "hidden";
|
||||
style.width = "200px";
|
||||
style.height = "150px";
|
||||
|
||||
outer.appendChild(inner);
|
||||
document.body.appendChild(outer);
|
||||
var noScrollbar = inner.offsetWidth;
|
||||
|
||||
style.overflow = "scroll";
|
||||
var withScrollbar = inner.offsetWidth;
|
||||
|
||||
if (noScrollbar == withScrollbar) {
|
||||
withScrollbar = outer.clientWidth;
|
||||
}
|
||||
|
||||
document.body.removeChild(outer);
|
||||
|
||||
return noScrollbar-withScrollbar;
|
||||
};
|
||||
|
||||
});
|
||||
239
plugins/pilot/event.js
Normal file
239
plugins/pilot/event.js
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
/* ***** 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 Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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 core = require("pilot/core");
|
||||
|
||||
exports.addListener = function(elem, type, callback) {
|
||||
if (elem.addEventListener) {
|
||||
return elem.addEventListener(type, callback, false);
|
||||
}
|
||||
if (elem.attachEvent) {
|
||||
var wrapper = function() {
|
||||
callback(window.event);
|
||||
};
|
||||
callback._wrapper = wrapper;
|
||||
elem.attachEvent("on" + type, wrapper);
|
||||
}
|
||||
};
|
||||
|
||||
exports.removeListener = function(elem, type, callback) {
|
||||
if (elem.removeEventListener) {
|
||||
return elem.removeEventListener(type, callback, false);
|
||||
}
|
||||
if (elem.detachEvent) {
|
||||
elem.detachEvent("on" + type, callback._wrapper || callback);
|
||||
}
|
||||
};
|
||||
|
||||
exports.stopEvent = function(e) {
|
||||
exports.stopPropagation(e);
|
||||
exports.preventDefault(e);
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.stopPropagation = function(e) {
|
||||
if (e.stopPropagation)
|
||||
e.stopPropagation();
|
||||
else
|
||||
e.cancelBubble = true;
|
||||
};
|
||||
|
||||
exports.preventDefault = function(e) {
|
||||
if (e.preventDefault)
|
||||
e.preventDefault();
|
||||
else
|
||||
e.returnValue = false;
|
||||
};
|
||||
|
||||
exports.getDocumentX = function(e) {
|
||||
if (e.clientX) {
|
||||
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
||||
return e.clientX + scrollLeft;
|
||||
} else {
|
||||
return e.pageX;
|
||||
}
|
||||
};
|
||||
|
||||
exports.getDocumentY = function(e) {
|
||||
if (e.clientY) {
|
||||
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
return e.clientY + scrollTop;
|
||||
} else {
|
||||
return e.pageX;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Number} 0 for left button, 1 for middle button, 2 for right button
|
||||
*/
|
||||
exports.getButton = function(e) {
|
||||
// DOM Event
|
||||
if (e.preventDefault) {
|
||||
return e.button;
|
||||
}
|
||||
// old IE
|
||||
else {
|
||||
return Math.max(e.button - 1, 2);
|
||||
}
|
||||
};
|
||||
|
||||
if (document.documentElement.setCapture) {
|
||||
exports.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||
function onMouseMove(e) {
|
||||
eventHandler(e);
|
||||
return exports.stopPropagation(e);
|
||||
}
|
||||
|
||||
function onReleaseCapture(e) {
|
||||
eventHandler && eventHandler(e);
|
||||
releaseCaptureHandler && releaseCaptureHandler();
|
||||
|
||||
exports.removeListener(el, "mousemove", eventHandler);
|
||||
exports.removeListener(el, "mouseup", onReleaseCapture);
|
||||
exports.removeListener(el, "losecapture", onReleaseCapture);
|
||||
|
||||
el.releaseCapture();
|
||||
}
|
||||
|
||||
exports.addListener(el, "mousemove", eventHandler);
|
||||
exports.addListener(el, "mouseup", onReleaseCapture);
|
||||
exports.addListener(el, "losecapture", onReleaseCapture);
|
||||
el.setCapture();
|
||||
};
|
||||
}
|
||||
else {
|
||||
exports.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||
function onMouseMove(e) {
|
||||
eventHandler(e);
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function onMouseUp(e) {
|
||||
eventHandler && eventHandler(e);
|
||||
releaseCaptureHandler && releaseCaptureHandler();
|
||||
|
||||
el.removeEventListener("mousemove", onMouseMove, true);
|
||||
el.removeEventListener("mouseup", onMouseUp, true);
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
el.addEventListener("mousemove", onMouseMove, true);
|
||||
el.addEventListener("mouseup", onMouseUp, true);
|
||||
};
|
||||
}
|
||||
|
||||
exports.addMouseWheelListener = function(el, callback) {
|
||||
var listener = function(e) {
|
||||
if (e.wheelDelta !== undefined) {
|
||||
if (e.wheelDeltaX !== undefined) {
|
||||
e.wheelX = -e.wheelDeltaX / 8;
|
||||
e.wheelY = -e.wheelDeltaY / 8;
|
||||
} else {
|
||||
e.wheelX = 0;
|
||||
e.wheelY = -e.wheelDelta / 8;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
|
||||
e.wheelX = (e.detail || 0) * 5;
|
||||
e.wheelY = 0;
|
||||
} else {
|
||||
e.wheelX = 0;
|
||||
e.wheelY = (e.detail || 0) * 5;
|
||||
}
|
||||
}
|
||||
callback(e);
|
||||
};
|
||||
exports.addListener(el, "DOMMouseScroll", listener);
|
||||
exports.addListener(el, "mousewheel", listener);
|
||||
};
|
||||
|
||||
exports.addMultiMouseDownListener = function(el, button, count, timeout, callback) {
|
||||
var clicks = 0;
|
||||
var startX, startY;
|
||||
|
||||
var listener = function(e) {
|
||||
clicks += 1;
|
||||
if (clicks == 1) {
|
||||
startX = e.clientX;
|
||||
startY = e.clientY;
|
||||
|
||||
setTimeout(function() {
|
||||
clicks = 0;
|
||||
}, timeout || 600);
|
||||
}
|
||||
|
||||
if (exports.getButton(e) != button
|
||||
|| Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
|
||||
clicks = 0;
|
||||
|
||||
if (clicks == count) {
|
||||
clicks = 0;
|
||||
callback(e);
|
||||
}
|
||||
return exports.preventDefault(e);
|
||||
};
|
||||
|
||||
exports.addListener(el, "mousedown", listener);
|
||||
core.isIE && exports.addListener(el, "dblclick", listener);
|
||||
};
|
||||
|
||||
exports.addKeyListener = function(el, callback) {
|
||||
var lastDown = null;
|
||||
|
||||
exports.addListener(el, "keydown", function(e) {
|
||||
lastDown = e.keyIdentifier || e.keyCode;
|
||||
return callback(e);
|
||||
});
|
||||
|
||||
// repeated keys are fired as keypress and not keydown events
|
||||
if (core.isMac && (core.isGecko || core.isOpera)) {
|
||||
exports.addListener(el, "keypress", function(e) {
|
||||
var keyId = e.keyIdentifier || e.keyCode;
|
||||
if (lastDown !== keyId) {
|
||||
return callback(e);
|
||||
} else {
|
||||
lastDown = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
|
@ -37,8 +37,6 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var lang = require('pilot/lang').lang;
|
||||
|
||||
var EventEmitter = {};
|
||||
|
||||
EventEmitter._dispatchEvent = function(eventName, e) {
|
||||
|
|
@ -63,7 +61,7 @@ EventEmitter.addEventListener = function(eventName, callback) {
|
|||
if (!listeners) {
|
||||
var listeners = this._eventRegistry[eventName] = [];
|
||||
}
|
||||
if (lang.arrayIndexOf(listeners, callback) == -1) {
|
||||
if (listeners.indexOf(callback) == -1) {
|
||||
listeners.push(callback);
|
||||
}
|
||||
};
|
||||
|
|
@ -75,7 +73,7 @@ EventEmitter.removeEventListener = function(eventName, callback) {
|
|||
if (!listeners) {
|
||||
return;
|
||||
}
|
||||
var index = lang.arrayIndexOf(listeners, callback);
|
||||
var index = listeners.indexOf(callback);
|
||||
if (index !== -1) {
|
||||
listeners.splice(index, 1);
|
||||
}
|
||||
164
plugins/pilot/fixoldbrowsers.js
Normal file
164
plugins/pilot/fixoldbrowsers.js
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
/* ***** 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 Mozilla 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):
|
||||
* Kevin Dangoor (kdangoor@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) {
|
||||
|
||||
/**
|
||||
* Array detector.
|
||||
* Firefox 3.5 and Safari 4 have this already. Chrome 4 however ...
|
||||
* Note to Dojo - your isArray is still broken: instanceof doesn't work with
|
||||
* Arrays taken from a different frame/window.
|
||||
*/
|
||||
if (!Array.isArray) {
|
||||
Array.isArray = function(data) {
|
||||
return data && Object.prototype.toString.call(data) === "[object Array]";
|
||||
};
|
||||
}
|
||||
|
||||
// from MDC
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
||||
if (!Array.prototype.indexOf)
|
||||
{
|
||||
Array.prototype.indexOf = function(searchElement /*, fromIndex */)
|
||||
{
|
||||
if (this === void 0 || this === null)
|
||||
throw new TypeError();
|
||||
|
||||
var t = Object(this);
|
||||
var len = t.length >>> 0;
|
||||
if (len === 0)
|
||||
return -1;
|
||||
|
||||
var n = 0;
|
||||
if (arguments.length > 0) {
|
||||
n = Number(arguments[1]);
|
||||
if (n !== n)
|
||||
n = 0;
|
||||
else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
|
||||
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
||||
}
|
||||
|
||||
if (n >= len)
|
||||
return -1;
|
||||
|
||||
var k = n >= 0
|
||||
? n
|
||||
: Math.max(len - Math.abs(n), 0);
|
||||
|
||||
for (; k < len; k++) {
|
||||
if (k in t && t[k] === searchElement)
|
||||
return k;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
// from MDC
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
|
||||
if (!Array.prototype.forEach) {
|
||||
Array.prototype.forEach = function(fun /*, thisp */) {
|
||||
if (this === void 0 || this === null)
|
||||
throw new TypeError();
|
||||
|
||||
var t = Object(this);
|
||||
var len = t.length >>> 0;
|
||||
if (typeof fun !== "function")
|
||||
throw new TypeError();
|
||||
|
||||
var thisp = arguments[1];
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (i in t)
|
||||
fun.call(thisp, t[i], i, t);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of keys on an object.
|
||||
*/
|
||||
if (!Object.keys) {
|
||||
Object.keys = function(obj) {
|
||||
var k, ret = [];
|
||||
for (k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
ret.push(k);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
if (!Function.prototype.bind) {
|
||||
// from MDC
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
|
||||
Function.prototype.bind = function (obj) {
|
||||
var slice = [].slice;
|
||||
var args = slice.call(arguments, 1);
|
||||
var self = this;
|
||||
var nop = function () {};
|
||||
|
||||
// optimize common case
|
||||
if (arguments.length == 1) {
|
||||
var bound = function() {
|
||||
return self.apply(this instanceof nop ? this : obj, arguments);
|
||||
};
|
||||
}
|
||||
else {
|
||||
var bound = function () {
|
||||
return self.apply(
|
||||
this instanceof nop ? this : ( obj || {} ),
|
||||
args.concat( slice.call(arguments) )
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
nop.prototype = self.prototype;
|
||||
bound.prototype = new nop();
|
||||
|
||||
// From Narwhal
|
||||
bound.name = this.name;
|
||||
bound.displayName = this.displayName;
|
||||
bound.length = this.length;
|
||||
bound.unbound = self;
|
||||
|
||||
return bound;
|
||||
};
|
||||
}
|
||||
|
||||
exports.globalsLoaded = true;
|
||||
|
||||
});
|
||||
96
plugins/pilot/lang.js
Normal file
96
plugins/pilot/lang.js
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/* ***** 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 Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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) {
|
||||
|
||||
exports.stringReverse = function(string) {
|
||||
return string.split("").reverse().join("");
|
||||
};
|
||||
|
||||
exports.stringRepeat = function (string, count) {
|
||||
return new Array(count + 1).join(string);
|
||||
};
|
||||
|
||||
exports.copyObject = function(obj) {
|
||||
var copy = {};
|
||||
for (var key in obj) {
|
||||
copy[key] = obj[key];
|
||||
}
|
||||
return copy;
|
||||
};
|
||||
|
||||
exports.arrayToMap = function(arr) {
|
||||
var map = {};
|
||||
for (var i=0; i<arr.length; i++) {
|
||||
map[arr[i]] = 1;
|
||||
}
|
||||
return map;
|
||||
|
||||
};
|
||||
|
||||
exports.escapeRegExp = function(str) {
|
||||
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
|
||||
};
|
||||
|
||||
exports.deferredCall = function(fcn) {
|
||||
|
||||
var timer = null;
|
||||
var callback = function() {
|
||||
timer = null;
|
||||
fcn();
|
||||
};
|
||||
|
||||
return {
|
||||
schedule: function() {
|
||||
if (!timer) {
|
||||
timer = setTimeout(callback, 0);
|
||||
}
|
||||
},
|
||||
|
||||
call: function() {
|
||||
this.cancel();
|
||||
fcn();
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
});
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/* ***** 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 Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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 lang = require("pilot/lang").lang;
|
||||
|
||||
var dom = {};
|
||||
|
||||
dom.setText = function(elem, text) {
|
||||
if (elem.innerText !== undefined) {
|
||||
elem.innerText = text;
|
||||
}
|
||||
if (elem.textContent !== undefined) {
|
||||
elem.textContent = text;
|
||||
}
|
||||
};
|
||||
|
||||
dom.hasCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s+/g);
|
||||
return lang.arrayIndexOf(classes, name) !== -1;
|
||||
};
|
||||
|
||||
dom.addCssClass = function(el, name) {
|
||||
if (!dom.hasCssClass(el, name)) {
|
||||
el.className += " " + name;
|
||||
}
|
||||
};
|
||||
|
||||
dom.removeCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s+/g);
|
||||
while (true) {
|
||||
var index = lang.arrayIndexOf(classes, name);
|
||||
if (index == -1) {
|
||||
break;
|
||||
}
|
||||
classes.splice(index, 1);
|
||||
}
|
||||
el.className = classes.join(" ");
|
||||
};
|
||||
|
||||
dom.importCssString = function(cssText, doc){
|
||||
doc = doc || document;
|
||||
|
||||
if (doc.createStyleSheet) {
|
||||
var sheet = doc.createStyleSheet();
|
||||
sheet.cssText = cssText;
|
||||
}
|
||||
else {
|
||||
var style = doc.createElement("style");
|
||||
style.appendChild(doc.createTextNode(cssText));
|
||||
doc.getElementsByTagName("head")[0].appendChild(style);
|
||||
}
|
||||
};
|
||||
|
||||
dom.getInnerWidth = function(element) {
|
||||
return (parseInt(dom.computedStyle(element, "paddingLeft"))
|
||||
+ parseInt(dom.computedStyle(element, "paddingRight")) + element.clientWidth);
|
||||
};
|
||||
|
||||
dom.getInnerHeight = function(element) {
|
||||
return (parseInt(dom.computedStyle(element, "paddingTop"))
|
||||
+ parseInt(dom.computedStyle(element, "paddingBottom")) + element.clientHeight);
|
||||
};
|
||||
|
||||
dom.computedStyle = function(element, style) {
|
||||
if (window.getComputedStyle) {
|
||||
return (window.getComputedStyle(element, "") || {})[style] || "";
|
||||
}
|
||||
else {
|
||||
return element.currentStyle[style];
|
||||
}
|
||||
};
|
||||
|
||||
dom.scrollbarWidth = function() {
|
||||
|
||||
var inner = document.createElement('p');
|
||||
inner.style.width = "100%";
|
||||
inner.style.height = "200px";
|
||||
|
||||
var outer = document.createElement("div");
|
||||
var style = outer.style;
|
||||
|
||||
style.position = "absolute";
|
||||
style.left = "-10000px";
|
||||
style.overflow = "hidden";
|
||||
style.width = "200px";
|
||||
style.height = "150px";
|
||||
|
||||
outer.appendChild(inner);
|
||||
document.body.appendChild(outer);
|
||||
var noScrollbar = inner.offsetWidth;
|
||||
|
||||
style.overflow = "scroll";
|
||||
var withScrollbar = inner.offsetWidth;
|
||||
|
||||
if (noScrollbar == withScrollbar) {
|
||||
withScrollbar = outer.clientWidth;
|
||||
}
|
||||
|
||||
document.body.removeChild(outer);
|
||||
|
||||
return noScrollbar-withScrollbar;
|
||||
};
|
||||
|
||||
exports.dom = dom;
|
||||
});
|
||||
|
|
@ -1,242 +0,0 @@
|
|||
/* ***** 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 Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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 core = require("pilot/core").core;
|
||||
var event = {};
|
||||
|
||||
event.addListener = function(elem, type, callback) {
|
||||
if (elem.addEventListener) {
|
||||
return elem.addEventListener(type, callback, false);
|
||||
}
|
||||
if (elem.attachEvent) {
|
||||
var wrapper = function() {
|
||||
callback(window.event);
|
||||
};
|
||||
callback._wrapper = wrapper;
|
||||
elem.attachEvent("on" + type, wrapper);
|
||||
}
|
||||
};
|
||||
|
||||
event.removeListener = function(elem, type, callback) {
|
||||
if (elem.removeEventListener) {
|
||||
return elem.removeEventListener(type, callback, false);
|
||||
}
|
||||
if (elem.detachEvent) {
|
||||
elem.detachEvent("on" + type, callback._wrapper || callback);
|
||||
}
|
||||
};
|
||||
|
||||
event.stopEvent = function(e) {
|
||||
event.stopPropagation(e);
|
||||
event.preventDefault(e);
|
||||
return false;
|
||||
};
|
||||
|
||||
event.stopPropagation = function(e) {
|
||||
if (e.stopPropagation)
|
||||
e.stopPropagation();
|
||||
else
|
||||
e.cancelBubble = true;
|
||||
};
|
||||
|
||||
event.preventDefault = function(e) {
|
||||
if (e.preventDefault)
|
||||
e.preventDefault();
|
||||
else
|
||||
e.returnValue = false;
|
||||
};
|
||||
|
||||
event.getDocumentX = function(e) {
|
||||
if (e.clientX) {
|
||||
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
||||
return e.clientX + scrollLeft;
|
||||
} else {
|
||||
return e.pageX;
|
||||
}
|
||||
};
|
||||
|
||||
event.getDocumentY = function(e) {
|
||||
if (e.clientY) {
|
||||
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
return e.clientY + scrollTop;
|
||||
} else {
|
||||
return e.pageX;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Number} 0 for left button, 1 for middle button, 2 for right button
|
||||
*/
|
||||
event.getButton = function(e) {
|
||||
// DOM Event
|
||||
if (e.preventDefault) {
|
||||
return e.button;
|
||||
}
|
||||
// old IE
|
||||
else {
|
||||
return Math.max(e.button - 1, 2);
|
||||
}
|
||||
};
|
||||
|
||||
if (document.documentElement.setCapture) {
|
||||
event.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||
function onMouseMove(e) {
|
||||
eventHandler(e);
|
||||
return event.stopPropagation(e);
|
||||
}
|
||||
|
||||
function onReleaseCapture(e) {
|
||||
eventHandler && eventHandler(e);
|
||||
releaseCaptureHandler && releaseCaptureHandler();
|
||||
|
||||
event.removeListener(el, "mousemove", eventHandler);
|
||||
event.removeListener(el, "mouseup", onReleaseCapture);
|
||||
event.removeListener(el, "losecapture", onReleaseCapture);
|
||||
|
||||
el.releaseCapture();
|
||||
}
|
||||
|
||||
event.addListener(el, "mousemove", eventHandler);
|
||||
event.addListener(el, "mouseup", onReleaseCapture);
|
||||
event.addListener(el, "losecapture", onReleaseCapture);
|
||||
el.setCapture();
|
||||
};
|
||||
}
|
||||
else {
|
||||
event.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||
function onMouseMove(e) {
|
||||
eventHandler(e);
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function onMouseUp(e) {
|
||||
eventHandler && eventHandler(e);
|
||||
releaseCaptureHandler && releaseCaptureHandler();
|
||||
|
||||
document.removeEventListener("mousemove", onMouseMove, true);
|
||||
document.removeEventListener("mouseup", onMouseUp, true);
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
document.addEventListener("mousemove", onMouseMove, true);
|
||||
document.addEventListener("mouseup", onMouseUp, true);
|
||||
};
|
||||
}
|
||||
|
||||
event.addMouseWheelListener = function(el, callback) {
|
||||
var listener = function(e) {
|
||||
if (e.wheelDelta !== undefined) {
|
||||
if (e.wheelDeltaX !== undefined) {
|
||||
e.wheelX = -e.wheelDeltaX / 8;
|
||||
e.wheelY = -e.wheelDeltaY / 8;
|
||||
} else {
|
||||
e.wheelX = 0;
|
||||
e.wheelY = -e.wheelDelta / 8;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
|
||||
e.wheelX = (e.detail || 0) * 5;
|
||||
e.wheelY = 0;
|
||||
} else {
|
||||
e.wheelX = 0;
|
||||
e.wheelY = (e.detail || 0) * 5;
|
||||
}
|
||||
}
|
||||
callback(e);
|
||||
};
|
||||
event.addListener(el, "DOMMouseScroll", listener);
|
||||
event.addListener(el, "mousewheel", listener);
|
||||
};
|
||||
|
||||
event.addMultiMouseDownListener = function(el, button, count, timeout, callback) {
|
||||
var clicks = 0;
|
||||
var startX, startY;
|
||||
|
||||
var listener = function(e) {
|
||||
clicks += 1;
|
||||
if (clicks == 1) {
|
||||
startX = e.clientX;
|
||||
startY = e.clientY;
|
||||
|
||||
setTimeout(function() {
|
||||
clicks = 0;
|
||||
}, timeout || 600);
|
||||
}
|
||||
|
||||
if (event.getButton(e) != button
|
||||
|| Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
|
||||
clicks = 0;
|
||||
|
||||
if (clicks == count) {
|
||||
clicks = 0;
|
||||
callback(e);
|
||||
}
|
||||
return event.preventDefault(e);
|
||||
};
|
||||
|
||||
event.addListener(el, "mousedown", listener);
|
||||
core.isIE && event.addListener(el, "dblclick", listener);
|
||||
};
|
||||
|
||||
event.addKeyListener = function(el, callback) {
|
||||
var lastDown = null;
|
||||
|
||||
event.addListener(el, "keydown", function(e) {
|
||||
lastDown = e.keyIdentifier || e.keyCode;
|
||||
return callback(e);
|
||||
});
|
||||
|
||||
// repeated keys are fired as keypress and not keydown events
|
||||
if (core.isMac && core.isGecko) {
|
||||
event.addListener(el, "keypress", function(e) {
|
||||
var keyId = e.keyIdentifier || e.keyCode;
|
||||
if (lastDown !== keyId) {
|
||||
return callback(e);
|
||||
} else {
|
||||
lastDown = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.event = event;
|
||||
|
||||
});
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
/* ***** 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 Mozilla 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):
|
||||
* Kevin Dangoor (kdangoor@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) {
|
||||
|
||||
exports.startup = function(data, reason) {
|
||||
// Narwhal's shim for ES5 defineProperty
|
||||
// ES5 15.2.3.6
|
||||
if (!Object.defineProperty) {
|
||||
Object.defineProperty = function(object, property, descriptor) {
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
if (typeof descriptor == "object" && object.__defineGetter__) {
|
||||
if (has.call(descriptor, "value")) {
|
||||
if (!object.__lookupGetter__(property) && !object.__lookupSetter__(property)) {
|
||||
// data property defined and no pre-existing accessors
|
||||
object[property] = descriptor.value;
|
||||
}
|
||||
if (has.call(descriptor, "get") || has.call(descriptor, "set")) {
|
||||
// descriptor has a value property but accessor already exists
|
||||
throw new TypeError("Object doesn't support this action");
|
||||
}
|
||||
}
|
||||
// fail silently if "writable", "enumerable", or "configurable"
|
||||
// are requested but not supported
|
||||
/*
|
||||
// alternate approach:
|
||||
if ( // can't implement these features; allow false but not true
|
||||
!(has.call(descriptor, "writable") ? descriptor.writable : true) ||
|
||||
!(has.call(descriptor, "enumerable") ? descriptor.enumerable : true) ||
|
||||
!(has.call(descriptor, "configurable") ? descriptor.configurable : true)
|
||||
)
|
||||
throw new RangeError(
|
||||
"This implementation of Object.defineProperty does not " +
|
||||
"support configurable, enumerable, or writable."
|
||||
);
|
||||
*/
|
||||
else if (typeof descriptor.get == "function") {
|
||||
object.__defineGetter__(property, descriptor.get);
|
||||
}
|
||||
if (typeof descriptor.set == "function") {
|
||||
object.__defineSetter__(property, descriptor.set);
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.2.3.7
|
||||
if (!Object.defineProperties) {
|
||||
Object.defineProperties = function(object, properties) {
|
||||
for (var property in properties) {
|
||||
if (Object.prototype.hasOwnProperty.call(properties, property)) {
|
||||
Object.defineProperty(object, property, properties[property]);
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Array detector.
|
||||
* Firefox 3.5 and Safari 4 have this already. Chrome 4 however ...
|
||||
* Note to Dojo - your isArray is still broken: instanceof doesn't work with
|
||||
* Arrays taken from a different frame/window.
|
||||
*/
|
||||
if (!Array.isArray) {
|
||||
Array.isArray = function(data) {
|
||||
return data && Object.prototype.toString.call(data) === "[object Array]";
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of keys on an object.
|
||||
*/
|
||||
if (!Object.keys) {
|
||||
Object.keys = function(obj) {
|
||||
var k, ret = [];
|
||||
for (k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
ret.push(k);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
if (!Function.prototype.bind) {
|
||||
// From Narwhal
|
||||
Function.prototype.bind = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var self = this;
|
||||
var bound = function () {
|
||||
return self.call.apply(
|
||||
self,
|
||||
args.concat(
|
||||
Array.prototype.slice.call(arguments)
|
||||
)
|
||||
);
|
||||
};
|
||||
bound.name = this.name;
|
||||
bound.displayName = this.displayName;
|
||||
bound.length = this.length;
|
||||
bound.unbound = self;
|
||||
return bound;
|
||||
};
|
||||
}
|
||||
|
||||
exports.globalsLoaded = true;
|
||||
};
|
||||
|
||||
});
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
/* ***** 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 Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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 lang = {};
|
||||
|
||||
lang.stringReverse = function(string) {
|
||||
return string.split("").reverse().join("");
|
||||
};
|
||||
|
||||
lang.stringRepeat = function (string, count) {
|
||||
return new Array(count + 1).join(string);
|
||||
};
|
||||
|
||||
if (Array.prototype.indexOf) {
|
||||
lang.arrayIndexOf = function(array, searchElement) {
|
||||
return array.indexOf(searchElement);
|
||||
};
|
||||
}
|
||||
else {
|
||||
lang.arrayIndexOf = function(array, searchElement) {
|
||||
for (var i=0; i<array.length; i++) {
|
||||
if (array[i] == searchElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
lang.isArray = function(value) {
|
||||
return Object.prototype.toString.call(value) == "[object Array]";
|
||||
};
|
||||
|
||||
lang.copyObject = function(obj) {
|
||||
var copy = {};
|
||||
for (var key in obj) {
|
||||
copy[key] = obj[key];
|
||||
}
|
||||
return copy;
|
||||
};
|
||||
|
||||
lang.arrayToMap = function(arr) {
|
||||
var map = {};
|
||||
for (var i=0; i<arr.length; i++) {
|
||||
map[arr[i]] = 1;
|
||||
}
|
||||
return map;
|
||||
|
||||
};
|
||||
|
||||
lang.escapeRegExp = function(str) {
|
||||
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
|
||||
};
|
||||
|
||||
lang.bind = function(fcn, context) {
|
||||
return function() {
|
||||
return fcn.apply(context, arguments);
|
||||
};
|
||||
};
|
||||
|
||||
lang.deferredCall = function(fcn) {
|
||||
|
||||
var timer = null;
|
||||
var callback = function() {
|
||||
timer = null;
|
||||
fcn();
|
||||
};
|
||||
|
||||
return {
|
||||
schedule: function() {
|
||||
if (!timer) {
|
||||
timer = setTimeout(callback, 0);
|
||||
}
|
||||
},
|
||||
|
||||
call: function() {
|
||||
lang.cancel();
|
||||
fcn();
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.lang = lang;
|
||||
});
|
||||
|
|
@ -37,25 +37,22 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = {};
|
||||
exports.inherits = function(ctor, superCtor) {
|
||||
var tempCtor = function() {};
|
||||
tempCtor.prototype = superCtor.prototype;
|
||||
ctor.super_ = superCtor.prototype;
|
||||
ctor.prototype = new tempCtor();
|
||||
ctor.prototype.constructor = ctor;
|
||||
};
|
||||
|
||||
oop.inherits = function(ctor, superCtor) {
|
||||
var tempCtor = function() {};
|
||||
tempCtor.prototype = superCtor.prototype;
|
||||
ctor.super_ = superCtor.prototype;
|
||||
ctor.prototype = new tempCtor();
|
||||
ctor.prototype.constructor = ctor;
|
||||
};
|
||||
exports.mixin = function(obj, mixin) {
|
||||
for (var key in mixin) {
|
||||
obj[key] = mixin[key];
|
||||
}
|
||||
};
|
||||
|
||||
oop.mixin = function(obj, mixin) {
|
||||
for (var key in mixin) {
|
||||
obj[key] = mixin[key];
|
||||
}
|
||||
};
|
||||
exports.implement = function(proto, mixin) {
|
||||
exports.mixin(proto, mixin);
|
||||
};
|
||||
|
||||
oop.implement = function(proto, mixin) {
|
||||
oop.mixin(proto, mixin);
|
||||
};
|
||||
|
||||
exports.oop = oop;
|
||||
});
|
||||
|
|
@ -44,7 +44,7 @@ define(function(require, exports, module) {
|
|||
*/
|
||||
|
||||
var console = require('pilot/console');
|
||||
var oop = require('pilot/oop').oop;
|
||||
var oop = require('pilot/oop');
|
||||
var types = require('pilot/types');
|
||||
var EventEmitter = require('pilot/event_emitter').EventEmitter;
|
||||
var catalog = require('pilot/catalog');
|
||||
|
|
@ -586,33 +586,6 @@ exports.clone = function(object, deep) {
|
|||
return object;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Helper method for extending one object with another
|
||||
* Copies all properties from source to target. Returns the extended target
|
||||
* object.
|
||||
* Taken from John Resig, http://ejohn.org/blog/javascript-getters-and-setters/.
|
||||
*/
|
||||
exports.mixin = function(a, b) {
|
||||
for (var i in b) {
|
||||
var g = b.__lookupGetter__(i);
|
||||
var s = b.__lookupSetter__(i);
|
||||
|
||||
if (g || s) {
|
||||
if (g) {
|
||||
a.__defineGetter__(i, g);
|
||||
}
|
||||
if (s) {
|
||||
a.__defineSetter__(i, s);
|
||||
}
|
||||
} else {
|
||||
a[i] = b[i];
|
||||
}
|
||||
}
|
||||
|
||||
return a;
|
||||
};
|
||||
|
||||
/**
|
||||
* Basically taken from Sproutcore.
|
||||
* Replaces the count items from idx with objects.
|
||||
Loading…
Add table
Add a link
Reference in a new issue