update code formatting, and general cleanup

This commit is contained in:
nightwing 2013-04-13 23:00:37 +04:00
commit 5894667b41
19 changed files with 1166 additions and 1237 deletions

View file

@ -44,9 +44,10 @@ function bindKey(win, mac) {
exports.commands = [{ exports.commands = [{
name: "showSettingsMenu", name: "showSettingsMenu",
bindKey: bindKey("Ctrl-,", "Command-,"), bindKey: bindKey("Ctrl-,", "Command-,"),
exec: function (editor) { exec: function(editor) {
config.loadModule("ace/ext/show_keyboard_shortcuts", function (e) { config.loadModule("ace/ext/settings_menu", function(module) {
e(editor); module.init(editor);
editor.showSettingsMenu();
}); });
}, },
readOnly: true readOnly: true

View file

@ -117,7 +117,7 @@ var ElasticTabstopsLite = function(editor) {
// todo: support multicursor // todo: support multicursor
var tabs = [-1].concat(this.$tabsForRow(row)); var tabs = [-1].concat(this.$tabsForRow(row));
var widths = tabs.map(function (el) { return 0; } ).slice(1); var widths = tabs.map(function(el) { return 0; } ).slice(1);
var line = this.$editor.session.getLine(row); var line = this.$editor.session.getLine(row);
for (var i = 0, len = tabs.length - 1; i < len; i++) { for (var i = 0, len = tabs.length - 1; i < len; i++) {
@ -128,7 +128,7 @@ var ElasticTabstopsLite = function(editor) {
var cell = line.substring(leftEdge, rightEdge); var cell = line.substring(leftEdge, rightEdge);
widths[i] = Math.max(cell.replace(/\s+$/g,'').length, rightmostSelection - leftEdge); widths[i] = Math.max(cell.replace(/\s+$/g,'').length, rightmostSelection - leftEdge);
} }
return widths; return widths;
}; };
@ -137,7 +137,7 @@ var ElasticTabstopsLite = function(editor) {
if (this.$editor.session.getSelection().isEmpty()) { if (this.$editor.session.getSelection().isEmpty()) {
// todo: support multicursor // todo: support multicursor
if (row == cursor.row) if (row == cursor.row)
selections.push(cursor.column); selections.push(cursor.column);
} }
return selections; return selections;
@ -189,7 +189,7 @@ var ElasticTabstopsLite = function(editor) {
for (var s = 0, length = selectionColumns.length; s < length; s++) { for (var s = 0, length = selectionColumns.length; s < length; s++) {
if (selectionColumns[s] <= cellRightEdge) if (selectionColumns[s] <= cellRightEdge)
lengths.push(s); lengths.push(s);
else else
lengths.push(0); lengths.push(0);
} }
rightmost = Math.max.apply(Math, lengths); rightmost = Math.max.apply(Math, lengths);
@ -214,9 +214,9 @@ var ElasticTabstopsLite = function(editor) {
if (rowTabs.length == 0) if (rowTabs.length == 0)
return; return;
var bias = 0, location = -1; var bias = 0, location = -1;
// this always only contains two elements, so we're safe in the loop below // this always only contains two elements, so we're safe in the loop below
var expandedSet = this.$izip(widths, rowTabs); var expandedSet = this.$izip(widths, rowTabs);
@ -261,7 +261,7 @@ var ElasticTabstopsLite = function(editor) {
if (iLength > longest) if (iLength > longest)
longest = iLength; longest = iLength;
} }
var expandedSet = []; var expandedSet = [];
for (var l = 0; l < longest; l++) { for (var l = 0; l < longest; l++) {
@ -275,7 +275,7 @@ var ElasticTabstopsLite = function(editor) {
expandedSet.push(set); expandedSet.push(set);
} }
return expandedSet; return expandedSet;
}; };
@ -284,7 +284,7 @@ var ElasticTabstopsLite = function(editor) {
this.$izip = function(widths, tabs) { this.$izip = function(widths, tabs) {
// grab the shorter size // grab the shorter size
var size = widths.length >= tabs.length ? tabs.length : widths.length; var size = widths.length >= tabs.length ? tabs.length : widths.length;
var expandedSet = []; var expandedSet = [];
for (var i = 0; i < size; i++) { for (var i = 0; i < size; i++) {
var set = [ widths[i], tabs[i] ]; var set = [ widths[i], tabs[i] ];

View file

@ -1,95 +1,86 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
indent: 4, /*global define, require */
maxerr: 50,
white: true, /**
browser: true, * Show Keyboard Shortcuts
vars: true * @fileOverview Show Keyboard Shortcuts <br />
*/ * Generates a menu which displays the keyboard shortcuts.
/*global * @author <a href="mailto:matthewkastor@gmail.com">
define, * Matthew Christopher Kastor-Inare III </a><br />
require * ☭ Hial Atropa!! ☭
*/ */
/** define(function(require, exports, module) {
* Show Keyboard Shortcuts "use strict";
* @fileOverview Show Keyboard Shortcuts <br /> var Editor = require("ace/editor").Editor;
* Generates a menu which displays the keyboard shortcuts. /**
* @author <a href="mailto:matthewkastor@gmail.com"> * Generates a menu which displays the keyboard shortcuts.
* Matthew Christopher Kastor-Inare III </a><br /> * @author <a href="mailto:matthewkastor@gmail.com">
* ☭ Hial Atropa!! ☭ * Matthew Christopher Kastor-Inare III </a><br />
*/ * ☭ Hial Atropa!! ☭
* @param {ace.Editor} editor An instance of the ace editor.
define(function(require, exports, module) { */
"use strict"; function showKeyboardShortcuts (editor) {
var Editor = require("ace/editor").Editor; // make sure the menu isn't open already.
/** if(!document.getElementById('kbshortcutmenu')) {
* Generates a menu which displays the keyboard shortcuts. var overlayPage = require('./menu_tools/overlay_page').overlayPage;
* @author <a href="mailto:matthewkastor@gmail.com"> var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts;
* Matthew Christopher Kastor-Inare III </a><br /> var kb = getEditorKeybordShortcuts(editor);
* ☭ Hial Atropa!! ☭ var el = document.createElement('div');
* @param {ace.Editor} editor An instance of the ace editor. var commands = kb.reduce(function(previous, current) {
*/ return previous + '<div><b>' + current.command + '</b> : ' +
function showKeyboardShortcuts (editor) { current.key + '</div>';
// make sure the menu isn't open already. }, '');
if(!document.getElementById('kbshortcutmenu')) {
var overlayPage = require('./menu_tools/overlay_page').overlayPage; el.id = 'kbshortcutmenu';
var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts; el.innerHTML = '<h1>Keyboard Shortcuts</h1>' + commands + '</div>';
var kb = getEditorKeybordShortcuts(editor); el.style.cssText = 'margin:0; padding:0;';
var el = document.createElement('div'); overlayPage(editor, el, '0', '0', '0', null);
var commands = kb.reduce(function (previous, current) { }
return previous + '<div><b>' + current.command + '</b> : ' + };
current.key + '</div>'; module.exports.init = function(editor) {
}, ''); Editor.prototype.showKeyboardShortcuts = function() {
showKeyboardShortcuts(this);
el.id = 'kbshortcutmenu'; };
el.innerHTML = '<h1>Keyboard Shortcuts</h1>' + commands + '</div>'; editor.commands.addCommands([{
el.style.cssText = 'margin:0; padding:0;'; name: "showKeyboardShortcuts",
overlayPage(editor, el, '0', '0', '0', null); bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
} exec: function(editor, line) {
}; editor.showKeyboardShortcuts();
module.exports.init = function (editor) { }
Editor.prototype.showKeyboardShortcuts = function () { }]);
showKeyboardShortcuts(this); };
};
editor.commands.addCommands([{
name: "showKeyboardShortcuts",
bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
exec: function(editor, line) {
editor.showKeyboardShortcuts();
}
}]);
};
}); });

View file

@ -1,103 +1,94 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
indent: 4, /*global define, require */
maxerr: 50,
white: true, /**
browser: true, * Add Editor Menu Options
vars: true * @fileOverview Add Editor Menu Options <br />
*/ * The menu options property needs to be added to the editor
/*global * so that the settings menu can know about options for
define, * selection elements and track which option is selected.
require * @author <a href="mailto:matthewkastor@gmail.com">
*/ * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭
/** */
* Add Editor Menu Options
* @fileOverview Add Editor Menu Options <br /> define(function(require, exports, module) {
* The menu options property needs to be added to the editor 'use strict';
* so that the settings menu can know about options for
* selection elements and track which option is selected. /**
* @author <a href="mailto:matthewkastor@gmail.com"> * The menu options property needs to be added to the editor
* Matthew Christopher Kastor-Inare III </a><br /> * so that the settings menu can know about options for
* ☭ Hial Atropa!! ☭ * selection elements and track which option is selected.
*/ * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br />
define(function(require, exports, module) { * ☭ Hial Atropa!! ☭
'use strict'; * @param {ace.Editor} editor An instance of the ace editor.
*/
/** module.exports.addEditorMenuOptions = function addEditorMenuOptions (editor) {
* The menu options property needs to be added to the editor var modelist = require('../modelist');
* so that the settings menu can know about options for var themelist = require('../themelist');
* selection elements and track which option is selected. editor.menuOptions = {
* @author <a href="mailto:matthewkastor@gmail.com"> "setNewLineMode" : [{
* Matthew Christopher Kastor-Inare III </a><br /> "textContent" : "unix",
* ☭ Hial Atropa!! ☭ "value" : "unix"
* @param {ace.Editor} editor An instance of the ace editor. }, {
*/ "textContent" : "windows",
module.exports.addEditorMenuOptions = function addEditorMenuOptions (editor) { "value" : "windows"
var modelist = require('../modelist'); }, {
var themelist = require('../themelist'); "textContent" : "auto",
editor.menuOptions = { "value" : "auto"
"setNewLineMode" : [{ }
"textContent" : "unix", ],
"value" : "unix" "setTheme" : [],
}, { "setMode" : []
"textContent" : "windows", };
"value" : "windows"
}, { editor.menuOptions.setTheme = themelist.themes.map(function(theme) {
"textContent" : "auto", return {
"value" : "auto" 'textContent' : theme.desc,
} 'value' : theme.theme
], };
"setTheme" : [], });
"setMode" : []
}; editor.menuOptions.setMode = modelist.modes.map(function(mode) {
return {
editor.menuOptions.setTheme = themelist.themes.map(function (theme) { 'textContent' : mode.name,
return { 'value' : mode.mode
'textContent' : theme.desc, };
'value' : theme.theme });
}; };
});
editor.menuOptions.setMode = modelist.modes.map(function (mode) {
return {
'textContent' : mode.name,
'value' : mode.mode
};
});
};
}); });

View file

@ -1,157 +1,148 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
indent: 4, /*global define, require */
maxerr: 50,
white: true, /**
browser: true, * Element Generator
vars: true * @fileOverview Element Generator <br />
*/ * Contains methods for generating elements.
/*global * @author <a href="mailto:matthewkastor@gmail.com">
define, * Matthew Christopher Kastor-Inare III </a><br />
require * ☭ Hial Atropa!! ☭
*/ */
/** define(function(require, exports, module) {
* Element Generator 'use strict';
* @fileOverview Element Generator <br /> /**
* Contains methods for generating elements. * Creates a DOM option element
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ * @param {object} obj An object containing properties to add to the dom
* element. If one of those properties is named `selected` then it will be
define(function(require, exports, module) { * added as an attribute on the element instead.
'use strict'; */
/** module.exports.createOption = function createOption (obj) {
* Creates a DOM option element var attribute;
* @author <a href="mailto:matthewkastor@gmail.com"> var el = document.createElement('option');
* Matthew Christopher Kastor-Inare III </a><br /> for(attribute in obj) {
* ☭ Hial Atropa!! ☭ if(obj.hasOwnProperty(attribute)) {
* @param {object} obj An object containing properties to add to the dom if(attribute === 'selected') {
* element. If one of those properties is named `selected` then it will be el.setAttribute(attribute, obj[attribute]);
* added as an attribute on the element instead. } else {
*/ el[attribute] = obj[attribute];
module.exports.createOption = function createOption (obj) { }
var attribute; }
var el = document.createElement('option'); }
for(attribute in obj) { return el;
if(obj.hasOwnProperty(attribute)) { };
if(attribute === 'selected') { /**
el.setAttribute(attribute, obj[attribute]); * Creates a DOM checkbox element.
} else { * @author <a href="mailto:matthewkastor@gmail.com">
el[attribute] = obj[attribute]; * Matthew Christopher Kastor-Inare III </a><br />
} * ☭ Hial Atropa!! ☭
} * @param {string} id The id of the element.
} * @param {boolean} checked Whether or not the element is checked.
return el; * @param {string} clss The class of the element.
}; * @returns {DOMElement} Returns a checkbox element reference.
/** */
* Creates a DOM checkbox element. module.exports.createCheckbox = function createCheckbox (id, checked, clss) {
* @author <a href="mailto:matthewkastor@gmail.com"> var el = document.createElement('input');
* Matthew Christopher Kastor-Inare III </a><br /> el.setAttribute('type', 'checkbox');
* ☭ Hial Atropa!! ☭ el.setAttribute('id', id);
* @param {string} id The id of the element. el.setAttribute('name', id);
* @param {boolean} checked Whether or not the element is checked. el.setAttribute('value', checked);
* @param {string} clss The class of the element. el.setAttribute('class', clss);
* @returns {DOMElement} Returns a checkbox element reference. if(checked) {
*/ el.setAttribute('checked', 'checked');
module.exports.createCheckbox = function createCheckbox (id, checked, clss) { }
var el = document.createElement('input'); return el;
el.setAttribute('type', 'checkbox'); };
el.setAttribute('id', id); /**
el.setAttribute('name', id); * Creates a DOM text input element.
el.setAttribute('value', checked); * @author <a href="mailto:matthewkastor@gmail.com">
el.setAttribute('class', clss); * Matthew Christopher Kastor-Inare III </a><br />
if(checked) { * ☭ Hial Atropa!! ☭
el.setAttribute('checked', 'checked'); * @param {string} id The id of the element.
} * @param {string} value The default value of the input element.
return el; * @param {string} clss The class of the element.
}; * @returns {DOMElement} Returns an input element reference.
/** */
* Creates a DOM text input element. module.exports.createInput = function createInput (id, value, clss) {
* @author <a href="mailto:matthewkastor@gmail.com"> var el = document.createElement('input');
* Matthew Christopher Kastor-Inare III </a><br /> el.setAttribute('type', 'text');
* ☭ Hial Atropa!! ☭ el.setAttribute('id', id);
* @param {string} id The id of the element. el.setAttribute('name', id);
* @param {string} value The default value of the input element. el.setAttribute('value', value);
* @param {string} clss The class of the element. el.setAttribute('class', clss);
* @returns {DOMElement} Returns an input element reference. return el;
*/ };
module.exports.createInput = function createInput (id, value, clss) { /**
var el = document.createElement('input'); * Creates a DOM label element.
el.setAttribute('type', 'text'); * @author <a href="mailto:matthewkastor@gmail.com">
el.setAttribute('id', id); * Matthew Christopher Kastor-Inare III </a><br />
el.setAttribute('name', id); * ☭ Hial Atropa!! ☭
el.setAttribute('value', value); * @param {string} text The label text.
el.setAttribute('class', clss); * @param {string} labelFor The id of the element being labeled.
return el; * @returns {DOMElement} Returns a label element reference.
}; */
/** module.exports.createLabel = function createLabel (text, labelFor) {
* Creates a DOM label element. var el = document.createElement('label');
* @author <a href="mailto:matthewkastor@gmail.com"> el.setAttribute('for', labelFor);
* Matthew Christopher Kastor-Inare III </a><br /> el.textContent = text;
* ☭ Hial Atropa!! ☭ return el;
* @param {string} text The label text. };
* @param {string} labelFor The id of the element being labeled. /**
* @returns {DOMElement} Returns a label element reference. * Creates a DOM selection element.
*/ * @author <a href="mailto:matthewkastor@gmail.com">
module.exports.createLabel = function createLabel (text, labelFor) { * Matthew Christopher Kastor-Inare III </a><br />
var el = document.createElement('label'); * ☭ Hial Atropa!! ☭
el.setAttribute('for', labelFor); * @param {string} id The id of the element.
el.textContent = text; * @param {string} values An array of objects suitable for `createOption`
return el; * @param {string} clss The class of the element.
}; * @returns {DOMElement} Returns a selection element reference.
/** * @see ace/ext/element_generator.createOption
* Creates a DOM selection element. */
* @author <a href="mailto:matthewkastor@gmail.com"> module.exports.createSelection = function createSelection (id, values, clss) {
* Matthew Christopher Kastor-Inare III </a><br /> var el = document.createElement('select');
* ☭ Hial Atropa!! ☭ el.setAttribute('id', id);
* @param {string} id The id of the element. el.setAttribute('name', id);
* @param {string} values An array of objects suitable for `createOption` el.setAttribute('class', clss);
* @param {string} clss The class of the element. values.forEach(function(item) {
* @returns {DOMElement} Returns a selection element reference. el.appendChild(module.exports.createOption(item));
* @see ace/ext/element_generator.createOption });
*/ return el;
module.exports.createSelection = function createSelection (id, values, clss) { };
var el = document.createElement('select');
el.setAttribute('id', id);
el.setAttribute('name', id);
el.setAttribute('class', clss);
values.forEach(function (item) {
el.appendChild(module.exports.createOption(item));
});
return el;
};
}); });

View file

@ -1,272 +1,272 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint
indent: 4, indent: 4,
maxerr: 50, maxerr: 50,
white: true, white: true,
browser: true, browser: true,
vars: true vars: true
*/ */
/*global /*global
define define
*/ */
/** /**
* Generates the settings menu * Generates the settings menu
* @fileOverview Generates the settings menu. * @fileOverview Generates the settings menu.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
define(function(require, exports, module) { define(function(require, exports, module) {
'use strict'; 'use strict';
/** /**
* Generates an interactive menu with settings useful to end users. * Generates an interactive menu with settings useful to end users.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
* @param {ace.Editor} editor An instance of the ace editor. * @param {ace.Editor} editor An instance of the ace editor.
*/ */
module.exports.generateSettingsMenu = function generateSettingsMenu (editor) { module.exports.generateSettingsMenu = function generateSettingsMenu (editor) {
var addEditorMenuOptions = require('./add_editor_menu_options').addEditorMenuOptions; var addEditorMenuOptions = require('./add_editor_menu_options').addEditorMenuOptions;
var getSetFunctions = require('./get_set_functions').getSetFunctions; var getSetFunctions = require('./get_set_functions').getSetFunctions;
/** /**
* container for dom elements that will go in the menu. * container for dom elements that will go in the menu.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
var elements = []; var elements = [];
/** /**
* Sorts the menu entries (elements var) so they'll appear in alphabetical order * Sorts the menu entries (elements var) so they'll appear in alphabetical order
* the sort is performed based on the value of the contains property * the sort is performed based on the value of the contains property
* of each element. Since this is an `array.sort` the array is sorted * of each element. Since this is an `array.sort` the array is sorted
* in place. * in place.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
function cleanupElementsList() { function cleanupElementsList() {
elements.sort(function (a, b) { elements.sort(function(a, b) {
var x = a.getAttribute('contains'); var x = a.getAttribute('contains');
var y = b.getAttribute('contains'); var y = b.getAttribute('contains');
return x.localeCompare(y); return x.localeCompare(y);
}); });
} }
/** /**
* Wraps all dom elements contained in the elements var with a single * Wraps all dom elements contained in the elements var with a single
* div. * div.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
function wrapElements() { function wrapElements() {
var topmenu = document.createElement('div'); var topmenu = document.createElement('div');
topmenu.setAttribute('id', 'settingsmenu'); topmenu.setAttribute('id', 'settingsmenu');
elements.forEach(function (element) { elements.forEach(function(element) {
topmenu.appendChild(element); topmenu.appendChild(element);
}); });
return topmenu; return topmenu;
} }
/** /**
* Creates a new menu entry. * Creates a new menu entry.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
* @param {object} obj This is a reference to the object containing the * @param {object} obj This is a reference to the object containing the
* set function. It is used to set up event listeners for when the * set function. It is used to set up event listeners for when the
* menu options change. * menu options change.
* @param {string} clss Maps to the class of the dom element. This is * @param {string} clss Maps to the class of the dom element. This is
* the name of the object containing the set function e.g. `editor`, * the name of the object containing the set function e.g. `editor`,
* `session`, `renderer`. * `session`, `renderer`.
* @param {string} item This is the set function name. It maps to the * @param {string} item This is the set function name. It maps to the
* id of the dom element (check, select, input) and to the "contains" * id of the dom element (check, select, input) and to the "contains"
* attribute of the div holding both the element and its label. * attribute of the div holding both the element and its label.
* @param {mixed} val This is the value of the setting. It is mapped to * @param {mixed} val This is the value of the setting. It is mapped to
* the dom element's value, checked, or selected option accordingly. * the dom element's value, checked, or selected option accordingly.
*/ */
function createNewEntry(obj, clss, item, val) { function createNewEntry(obj, clss, item, val) {
var egen = require('./element_generator'); var egen = require('./element_generator');
var el; var el;
var div = document.createElement('div'); var div = document.createElement('div');
div.setAttribute('contains', item); div.setAttribute('contains', item);
div.setAttribute('class', 'menuEntry'); div.setAttribute('class', 'menuEntry');
div.setAttribute('style', 'clear: both;'); div.setAttribute('style', 'clear: both;');
div.appendChild(egen.createLabel( div.appendChild(egen.createLabel(
item.replace( item.replace(
/^set/, '' /^set/, ''
).replace( ).replace(
/([A-Z])/g, ' $1' /([A-Z])/g, ' $1'
).trim(), ).trim(),
item item
)); ));
if(Array.isArray(val)) { if(Array.isArray(val)) {
el = egen.createSelection(item, val, clss); el = egen.createSelection(item, val, clss);
el.addEventListener('change', function (e) { el.addEventListener('change', function(e) {
try{ try{
editor.menuOptions[e.target.id].forEach(function (x) { editor.menuOptions[e.target.id].forEach(function(x) {
if(x.textContent !== e.target.textContent) { if(x.textContent !== e.target.textContent) {
delete x.selected; delete x.selected;
} }
}); });
// editor.session['setMode']('ace/mode/javascript') // editor.session['setMode']('ace/mode/javascript')
obj[e.target.id](e.target.value); obj[e.target.id](e.target.value);
} catch (err) { } catch (err) {
throw new Error(err); throw new Error(err);
} }
}); });
} else if(typeof val === 'boolean') { } else if(typeof val === 'boolean') {
el = egen.createCheckbox(item, val, clss); el = egen.createCheckbox(item, val, clss);
el.addEventListener('change', function (e) { el.addEventListener('change', function(e) {
try{ try{
// renderer['setHighlightGutterLine'](true); // renderer['setHighlightGutterLine'](true);
obj[e.target.id](!!e.target.checked); obj[e.target.id](!!e.target.checked);
} catch (err) { } catch (err) {
throw new Error(err); throw new Error(err);
} }
}); });
} else { } else {
// this aids in giving the ability to specify settings through // this aids in giving the ability to specify settings through
// post and get requests. // post and get requests.
// /ace_editor.html?setMode=ace/mode/html&setOverwrite=true // /ace_editor.html?setMode=ace/mode/html&setOverwrite=true
el = egen.createInput(item, val, clss); el = egen.createInput(item, val, clss);
el.addEventListener('blur', function (e) { el.addEventListener('blur', function(e) {
try{ try{
if(e.target.value === 'true') { if(e.target.value === 'true') {
obj[e.target.id](true); obj[e.target.id](true);
} else if(e.target.value === 'false') { } else if(e.target.value === 'false') {
obj[e.target.id](false); obj[e.target.id](false);
} else { } else {
obj[e.target.id](e.target.value); obj[e.target.id](e.target.value);
} }
} catch (err) { } catch (err) {
throw new Error(err); throw new Error(err);
} }
}); });
} }
el.style.cssText = 'float:right;'; el.style.cssText = 'float:right;';
div.appendChild(el); div.appendChild(el);
return div; return div;
} }
/** /**
* Generates selection fields for the menu and populates their options * Generates selection fields for the menu and populates their options
* using information from `editor.menuOptions` * using information from `editor.menuOptions`
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
* @param {string} item The set function name. * @param {string} item The set function name.
* @param {object} esr A reference to the object having the set function. * @param {object} esr A reference to the object having the set function.
* @param {string} clss The name of the object containing the set function. * @param {string} clss The name of the object containing the set function.
* @param {string} fn The matching get function's function name. * @param {string} fn The matching get function's function name.
* @returns {DOMElement} Returns a dom element containing a selection * @returns {DOMElement} Returns a dom element containing a selection
* element populated with options. The option whose value matches that * element populated with options. The option whose value matches that
* returned from `esr[fn]()` will be selected. * returned from `esr[fn]()` will be selected.
*/ */
function makeDropdown(item, esr, clss, fn) { function makeDropdown(item, esr, clss, fn) {
var val = editor.menuOptions[item]; var val = editor.menuOptions[item];
val = val.map(function (valuex) { val = val.map(function(valuex) {
if(valuex.value === esr[fn]()) { if(valuex.value === esr[fn]()) {
valuex.selected = 'selected'; valuex.selected = 'selected';
} else if(valuex.value === esr.$modeId) { } else if(valuex.value === esr.$modeId) {
// is mode // is mode
valuex.selected = 'selected'; valuex.selected = 'selected';
} }
return valuex; return valuex;
}); });
return createNewEntry(esr, clss, item, val); return createNewEntry(esr, clss, item, val);
} }
/** /**
* Processes the set functions returned from `getSetFunctions`. First it * Processes the set functions returned from `getSetFunctions`. First it
* checks for menu options defined in `editor.menuOptions`. If no * checks for menu options defined in `editor.menuOptions`. If no
* options are specified then it checks whether there is a get function * options are specified then it checks whether there is a get function
* (replace set with get) for the setting. When either of those * (replace set with get) for the setting. When either of those
* conditions are met it will attempt to create a new entry for the * conditions are met it will attempt to create a new entry for the
* settings menu and push it into the elements array defined above. * settings menu and push it into the elements array defined above.
* It can only do so for get functions which return * It can only do so for get functions which return
* strings, numbers, and booleans. A special case is written in for * strings, numbers, and booleans. A special case is written in for
* `getMode` where it looks at the returned objects `$id` property and * `getMode` where it looks at the returned objects `$id` property and
* forwards that through instead. Other special cases could be written * forwards that through instead. Other special cases could be written
* in but that would get a bit ridiculous. * in but that would get a bit ridiculous.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
* @param {object} setObj An item from the array returned by * @param {object} setObj An item from the array returned by
* `getSetFunctions`. * `getSetFunctions`.
*/ */
function handleSet (setObj) { function handleSet (setObj) {
var item = setObj.functionName; var item = setObj.functionName;
var esr = setObj.parentObj; var esr = setObj.parentObj;
var clss = setObj.parentName; var clss = setObj.parentName;
var val; var val;
var fn = item.replace(/^set/, 'get'); var fn = item.replace(/^set/, 'get');
if(editor.menuOptions[item] !== undefined) { if(editor.menuOptions[item] !== undefined) {
// has options for select element // has options for select element
elements.push(makeDropdown(item, esr, clss, fn)); elements.push(makeDropdown(item, esr, clss, fn));
} else if(typeof esr[fn] === 'function') { } else if(typeof esr[fn] === 'function') {
// has get function // has get function
try { try {
val = esr[fn](); val = esr[fn]();
if(typeof val === 'object') { if(typeof val === 'object') {
// setMode takes a string, getMode returns an object // setMode takes a string, getMode returns an object
// the $id property of that object is the string // the $id property of that object is the string
// which may be given to setMode... // which may be given to setMode...
val = val.$id; val = val.$id;
} }
// the rest of the get functions return strings, // the rest of the get functions return strings,
// booleans, or numbers. // booleans, or numbers.
elements.push( elements.push(
createNewEntry(esr, clss, item, val) createNewEntry(esr, clss, item, val)
); );
} catch (e) { } catch (e) {
// if there are errors it is because the element // if there are errors it is because the element
// does not belong in the settings menu // does not belong in the settings menu
} }
} }
} }
addEditorMenuOptions(editor); addEditorMenuOptions(editor);
// gather the set functions // gather the set functions
getSetFunctions(editor).forEach(function (setObj) { getSetFunctions(editor).forEach(function(setObj) {
// populate the elements array with good stuff. // populate the elements array with good stuff.
handleSet(setObj); handleSet(setObj);
}); });
// sort the menu entries in the elements list so people can find // sort the menu entries in the elements list so people can find
// the settings in alphabetical order. // the settings in alphabetical order.
cleanupElementsList(); cleanupElementsList();
// dump the entries from the elements list and wrap them up in a div // dump the entries from the elements list and wrap them up in a div
return wrapElements(); return wrapElements();
}; };
}); });

View file

@ -1,95 +1,86 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
indent: 4, /*global define, require */
maxerr: 50,
white: true, /**
browser: true, * Get Editor Keyboard Shortcuts
vars: true * @fileOverview Get Editor Keyboard Shortcuts <br />
*/ * Gets a map of keyboard shortcuts to command names for the current platform.
/*global * @author <a href="mailto:matthewkastor@gmail.com">
define, * Matthew Christopher Kastor-Inare III </a><br />
require * ☭ Hial Atropa!! ☭
*/ */
/** define(function(require, exports, module) {
* Get Editor Keyboard Shortcuts "use strict";
* @fileOverview Get Editor Keyboard Shortcuts <br /> /**
* Gets a map of keyboard shortcuts to command names for the current platform. * Gets a map of keyboard shortcuts to command names for the current platform.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ * @param {ace.Editor} editor An editor instance.
* @returns {Array} Returns an array of objects representing the keyboard
define(function(require, exports, module) { * shortcuts for the given editor.
"use strict"; * @example
/** * var getKbShortcuts = require('./get_keyboard_shortcuts');
* Gets a map of keyboard shortcuts to command names for the current platform. * console.log(getKbShortcuts(editor));
* @author <a href="mailto:matthewkastor@gmail.com"> * // [
* Matthew Christopher Kastor-Inare III </a><br /> * // {'command' : aCommand, 'key' : 'Control-d'},
* ☭ Hial Atropa!! ☭ * // {'command' : aCommand, 'key' : 'Control-d'}
* @param {ace.Editor} editor An editor instance. * // ]
* @returns {Array} Returns an array of objects representing the keyboard */
* shortcuts for the given editor. module.exports.getEditorKeybordShortcuts = function getEditorKeybordShortcuts (editor) {
* @example var commands = editor.commands.byName;
* var getKbShortcuts = require('./get_keyboard_shortcuts'); var commandName;
* console.log(getKbShortcuts(editor)); var key;
* // [ var platform = editor.commands.platform;
* // {'command' : aCommand, 'key' : 'Control-d'}, var kb = [];
* // {'command' : aCommand, 'key' : 'Control-d'} for (commandName in commands) {
* // ] try {
*/ key = commands[commandName].bindKey[platform];
module.exports.getEditorKeybordShortcuts = function getEditorKeybordShortcuts (editor) { if (key) {
var commands = editor.commands.byName; kb.push({
var commandName; 'command' : commandName,
var key; 'key' : key
var platform = editor.commands.platform; });
var kb = []; }
for (commandName in commands) { } catch (e) {
try { // errors on properties without bindKey we don't want them
key = commands[commandName].bindKey[platform]; // so the errors don't need handling.
if (key) { }
kb.push({ }
'command' : commandName, return kb;
'key' : key };
});
}
} catch (e) {
// errors on properties without bindKey we don't want them
// so the errors don't need handling.
}
}
return kb;
};
}); });

View file

@ -1,155 +1,155 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint
indent: 4, indent: 4,
maxerr: 50, maxerr: 50,
white: true, white: true,
browser: true, browser: true,
vars: true vars: true
*/ */
/*global /*global
define define
*/ */
/** /**
* Get Set Functions * Get Set Functions
* @fileOverview Get Set Functions <br /> * @fileOverview Get Set Functions <br />
* Gets various functions for setting settings. * Gets various functions for setting settings.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
define(function(require, exports, module) { define(function(require, exports, module) {
'use strict'; 'use strict';
/** /**
* Generates a list of set functions for the settings menu. * Generates a list of set functions for the settings menu.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
* @param {object} editor The editor instance * @param {object} editor The editor instance
* @return {array} Returns an array of objects. Each object contains the * @return {array} Returns an array of objects. Each object contains the
* following properties: functionName, parentObj, and parentName. The * following properties: functionName, parentObj, and parentName. The
* function name will be the name of a method beginning with the string * function name will be the name of a method beginning with the string
* `set` which was found. The parent object will be a reference to the * `set` which was found. The parent object will be a reference to the
* object having the method matching the function name. The parent name * object having the method matching the function name. The parent name
* will be a string representing the identifier of the parent object e.g. * will be a string representing the identifier of the parent object e.g.
* `editor`, `session`, or `renderer`. * `editor`, `session`, or `renderer`.
*/ */
module.exports.getSetFunctions = function getSetFunctions (editor) { module.exports.getSetFunctions = function getSetFunctions (editor) {
/** /**
* Output array. Will hold the objects described above. * Output array. Will hold the objects described above.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
var out = []; var out = [];
/** /**
* This object provides a map between the objects which will be * This object provides a map between the objects which will be
* traversed and the parent name which will appear in the output. * traversed and the parent name which will appear in the output.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
var my = { var my = {
'editor' : editor, 'editor' : editor,
'session' : editor.session, 'session' : editor.session,
'renderer' : editor.renderer 'renderer' : editor.renderer
}; };
/** /**
* This array will hold the set function names which have already been * This array will hold the set function names which have already been
* found so that they are not added to the output multiple times. * found so that they are not added to the output multiple times.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
var opts = []; var opts = [];
/** /**
* This is a list of set functions which will not appear in the settings * This is a list of set functions which will not appear in the settings
* menu. I don't know what to do with setKeyboardHandler. When I tried * menu. I don't know what to do with setKeyboardHandler. When I tried
* to use it, it didn't appear to be working. Someone who knows better * to use it, it didn't appear to be working. Someone who knows better
* could remove it from this list and add it's options to * could remove it from this list and add it's options to
* add_editor_menu_options.js * add_editor_menu_options.js
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
var skip = [ var skip = [
'setOption', 'setOption',
'setUndoManager', 'setUndoManager',
'setDocument', 'setDocument',
'setValue', 'setValue',
'setBreakpoints', 'setBreakpoints',
'setScrollTop', 'setScrollTop',
'setScrollLeft', 'setScrollLeft',
'setSelectionStyle', 'setSelectionStyle',
'setWrapLimitRange', 'setWrapLimitRange',
'setKeyboardHandler' 'setKeyboardHandler'
]; ];
/** /**
* This will search the objects mapped to the `my` variable above. When * This will search the objects mapped to the `my` variable above. When
* it finds a set function in the object that is not listed in the * it finds a set function in the object that is not listed in the
* `skip` list or the `opts` list it will push a new object to the * `skip` list or the `opts` list it will push a new object to the
* output array. * output array.
* @author <a href="mailto:matthewkastor@gmail.com"> * @author <a href="mailto:matthewkastor@gmail.com">
* Matthew Christopher Kastor-Inare III </a><br /> * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭ * ☭ Hial Atropa!! ☭
*/ */
[ [
'renderer', 'renderer',
'session', 'session',
'editor' 'editor'
].forEach(function (esra) { ].forEach(function(esra) {
var fn; var fn;
var esr = my[esra]; var esr = my[esra];
var clss = esra; var clss = esra;
for(fn in esr) { for(fn in esr) {
if(skip.indexOf(fn) === -1) { if(skip.indexOf(fn) === -1) {
if(/^set/.test(fn) && opts.indexOf(fn) === -1) { if(/^set/.test(fn) && opts.indexOf(fn) === -1) {
// found set function // found set function
opts.push(fn); opts.push(fn);
out.push({ out.push({
'functionName' : fn, 'functionName' : fn,
'parentObj' : esr, 'parentObj' : esr,
'parentName' : clss 'parentName' : clss
}); });
} }
} }
} }
}); });
return out; return out;
}; };
}); });

View file

@ -1,116 +1,107 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
indent: 4, /*global define, require */
maxerr: 50,
white: true, /**
browser: true, * Overlay Page
vars: true * @fileOverview Overlay Page <br />
*/ * Generates an overlay for displaying menus. The overlay is an absolutely
/*global * positioned div.
define, * @author <a href="mailto:matthewkastor@gmail.com">
require * Matthew Christopher Kastor-Inare III </a><br />
*/ * ☭ Hial Atropa!! ☭
*/
/**
* Overlay Page define(function(require, exports, module) {
* @fileOverview Overlay Page <br /> 'use strict';
* Generates an overlay for displaying menus. The overlay is an absolutely
* positioned div. /**
* @author <a href="mailto:matthewkastor@gmail.com"> * Generates an overlay for displaying menus. The overlay is an absolutely
* Matthew Christopher Kastor-Inare III </a><br /> * positioned div.
* ☭ Hial Atropa!! ☭ * @author <a href="mailto:matthewkastor@gmail.com">
*/ * Matthew Christopher Kastor-Inare III </a><br />
* ☭ Hial Atropa!! ☭
define(function(require, exports, module) { * @param {DOMElement} contentElement Any element which may be presented inside
'use strict'; * a div.
* @param {string|number} top absolute position value.
/** * @param {string|number} right absolute position value.
* Generates an overlay for displaying menus. The overlay is an absolutely * @param {string|number} bottom absolute position value.
* positioned div. * @param {string|number} left absolute position value.
* @author <a href="mailto:matthewkastor@gmail.com"> */
* Matthew Christopher Kastor-Inare III </a><br /> module.exports.overlayPage = function overlayPage (editor, contentElement, top, right, bottom, left) {
* ☭ Hial Atropa!! ☭ top = (top) ? 'top: ' + top + ';' : '';
* @param {DOMElement} contentElement Any element which may be presented inside bottom = (bottom) ? 'bottom: ' + bottom + ';' : '';
* a div. right = (right) ? 'right: ' + right + ';' : '';
* @param {string|number} top absolute position value. left = (left) ? 'left: ' + left + ';' : '';
* @param {string|number} right absolute position value.
* @param {string|number} bottom absolute position value. var closer = document.createElement('div');
* @param {string|number} left absolute position value. var contentContainer = document.createElement('div');
*/
module.exports.overlayPage = function overlayPage (editor, contentElement, top, right, bottom, left) { function documentEscListener (e) {
top = (top) ? 'top: ' + top + ';' : ''; if (e.keyCode === 27) {
bottom = (bottom) ? 'bottom: ' + bottom + ';' : ''; closer.click();
right = (right) ? 'right: ' + right + ';' : ''; }
left = (left) ? 'left: ' + left + ';' : ''; }
var closer = document.createElement('div'); closer.style.cssText = 'margin: 0; padding: 0; ' +
var contentContainer = document.createElement('div'); 'position: fixed; top:0; bottom:0; left:0; right:0;' +
'z-index: 9990; ' +
function documentEscListener (e) { 'background-color: rgba(0, 0, 0, 0.2);';
if (e.keyCode === 27) { closer.addEventListener('click', function() {
closer.click(); document.removeEventListener('keydown', documentEscListener);
} closer.parentNode.removeChild(closer);
} editor.focus();
closer = null;
closer.style.cssText = 'margin: 0; padding: 0; ' + });
'position: fixed; top:0; bottom:0; left:0; right:0;' + // click closer if esc key is pressed
'z-index: 9990; ' + document.addEventListener('keydown', documentEscListener);
'background-color: rgba(0, 0, 0, 0.2);';
closer.addEventListener('click', function () { contentContainer.style.cssText = 'margin: 0; padding: 0; ' +
document.removeEventListener('keydown', documentEscListener); 'position: absolute;' +
closer.parentNode.removeChild(closer); top + right + bottom + left +
editor.focus(); 'z-index: 9991; ' +
closer = null; 'box-shadow: rgba(126, 126, 126, 0.25) -20px 10px 25px; ' +
}); 'background-color: rgba(255, 255, 255, 0.6);' +
// click closer if esc key is pressed 'color: black; overflow: auto;';
document.addEventListener('keydown', documentEscListener); contentContainer.addEventListener('click', function(e) {
e.stopPropagation();
contentContainer.style.cssText = 'margin: 0; padding: 0; ' + });
'position: absolute;' +
top + right + bottom + left + contentContainer.appendChild(contentElement);
'z-index: 9991; ' + closer.appendChild(contentContainer);
'box-shadow: rgba(126, 126, 126, 0.25) -20px 10px 25px; ' + document.body.appendChild(closer);
'background-color: rgba(255, 255, 255, 0.6);' + editor.blur();
'color: black; overflow: auto;'; };
contentContainer.addEventListener('click', function (e) {
e.stopPropagation();
});
contentContainer.appendChild(contentElement);
closer.appendChild(contentContainer);
document.body.appendChild(closer);
editor.blur();
};
}); });

View file

@ -34,7 +34,7 @@ var Mode = function(name, desc, extensions) {
}) + "$"; }) + "$";
} else { } else {
var re = "^.*\\.(" + extensions + ")$"; var re = "^.*\\.(" + extensions + ")$";
} }
this.extRe = new RegExp(re, "gi"); this.extRe = new RegExp(re, "gi");
}; };

View file

@ -168,7 +168,7 @@ var SearchBox = function(editor, range, showReplaceForm) {
(sb.activeInput == sb.replaceInput ? sb.searchInput : sb.replaceInput).focus(); (sb.activeInput == sb.replaceInput ? sb.searchInput : sb.replaceInput).focus();
} }
}); });
this.$searchBarKb.addCommands([{ this.$searchBarKb.addCommands([{
name: "toggleRegexpMode", name: "toggleRegexpMode",
bindKey: {win: "Alt-R|Alt-/", mac: "Ctrl-Alt-R|Ctrl-Alt-/"}, bindKey: {win: "Alt-R|Alt-/", mac: "Ctrl-Alt-R|Ctrl-Alt-/"},
@ -191,7 +191,7 @@ var SearchBox = function(editor, range, showReplaceForm) {
sb.$syncOptions(); sb.$syncOptions();
} }
}]); }]);
this.$syncOptions = function() { this.$syncOptions = function() {
dom.setCssClass(this.regExpOption, "checked", this.regExpOption.checked); dom.setCssClass(this.regExpOption, "checked", this.regExpOption.checked);
dom.setCssClass(this.wholeWordOption, "checked", this.wholeWordOption.checked); dom.setCssClass(this.wholeWordOption, "checked", this.wholeWordOption.checked);
@ -224,7 +224,7 @@ var SearchBox = function(editor, range, showReplaceForm) {
this.editor.replaceAll(this.replaceInput.value); this.editor.replaceAll(this.replaceInput.value);
}; };
this.hide = function () { this.hide = function() {
this.element.style.display = "none"; this.element.style.display = "none";
this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb); this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb);
this.editor.focus(); this.editor.focus();

View file

@ -1,94 +1,76 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
indent: 4, /*global define, require */
maxerr: 50,
white: true, /**
browser: true, * Show Settings Menu
vars: true * @fileOverview Show Settings Menu <br />
*/ * Displays an interactive settings menu mostly generated on the fly based on
/*global * the current state of the editor.
define, * @author <a href="mailto:matthewkastor@gmail.com">
require, * Matthew Christopher Kastor-Inare III </a><br />
getComputedStyle * ☭ Hial Atropa!! ☭
*/ */
/** define(function(require, exports, module) {
* Show Settings Menu "use strict";
* @fileOverview Show Settings Menu <br /> /**
* Displays an interactive settings menu mostly generated on the fly based on * This displays the settings menu if it is not already being shown.
* the current state of the editor. * @author <a href="mailto:matthewkastor@gmail.com">
* @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br />
* Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭
* ☭ Hial Atropa!! ☭ * @param {ace.Editor} editor An instance of the ace editor.
*/ */
function showSettingsMenu (editor) {
define(function(require, exports, module) { var overlayPage = require('./menu_tools/overlay_page').overlayPage;
"use strict"; var generateSettingsMenu = require(
/** './menu_tools/generate_settings_menu').generateSettingsMenu;
* This displays the settings menu if it is not already being shown. // make sure the menu isn't open already.
* @author <a href="mailto:matthewkastor@gmail.com"> if(!document.getElementById('settingsmenu')) {
* Matthew Christopher Kastor-Inare III </a><br /> overlayPage(editor, generateSettingsMenu(editor), '0', '0', '0');
* ☭ Hial Atropa!! ☭ }
* @param {ace.Editor} editor An instance of the ace editor. }
*/ /**
function showSettingsMenu (editor) { * Initializes the settings menu extension. It adds the showSettingsMenu
var overlayPage = require('./menu_tools/overlay_page').overlayPage; * method to the given editor object and adds the showSettingsMenu command
var generateSettingsMenu = require( * to the editor with appropriate keyboard shortcuts.
'./menu_tools/generate_settings_menu').generateSettingsMenu; * @param {ace.Editor} editor An instance of the Editor.
// make sure the menu isn't open already. */
if(!document.getElementById('settingsmenu')) { module.exports.init = function(editor) {
overlayPage(editor, generateSettingsMenu(editor), '0', '0', '0'); var Editor = require("ace/editor").Editor;
} Editor.prototype.showSettingsMenu = function() {
} showSettingsMenu(this);
/** };
* Initializes the settings menu extension. It adds the showSettingsMenu };
* method to the given editor object and adds the showSettingsMenu command
* to the editor with appropriate keyboard shortcuts.
* @param {ace.Editor} editor An instance of the Editor.
*/
module.exports.init = function (editor) {
var Editor = require("ace/editor").Editor;
Editor.prototype.showSettingsMenu = function () {
showSettingsMenu(this);
};
editor.commands.addCommands([{
name: "showSettingsMenu",
bindKey: {win: "Ctrl-q", mac: "Command-q"},
exec: function(editor, line) {
editor.showSettingsMenu();
},
readOnly: true
}]);
};
}); });

View file

@ -19,7 +19,7 @@ exports.contextMenuHandler = function(e){
text.value = value; text.value = value;
text.setSelectionRange(w.length + 1, w.length + 1); text.setSelectionRange(w.length + 1, w.length + 1);
text.setSelectionRange(0, 0); text.setSelectionRange(0, 0);
var afterKeydown = false; var afterKeydown = false;
event.addListener(text, "keydown", function onKeydown() { event.addListener(text, "keydown", function onKeydown() {
event.removeListener(text, "keydown", onKeydown); event.removeListener(text, "keydown", onKeydown);
@ -44,7 +44,7 @@ exports.contextMenuHandler = function(e){
return ""; return "";
} }
} }
return newVal; return newVal;
}); });
}; };
@ -58,7 +58,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
if (!val) if (!val)
this.removeListener("nativecontextmenu", exports.contextMenuHandler); this.removeListener("nativecontextmenu", exports.contextMenuHandler);
else else
this.on("nativecontextmenu", exports.contextMenuHandler); this.on("nativecontextmenu", exports.contextMenuHandler);
}, },
value: true value: true
} }

View file

@ -3,12 +3,12 @@
font-size: 12px; font-size: 12px;
} }
.ace_editor .ace_gutter { .ace_editor .ace_gutter {
width: 25px !important; width: 25px !important;
display: block; display: block;
float: left; float: left;
text-align: right; text-align: right;
padding: 0 3px 0 0; padding: 0 3px 0 0;
margin-right: 3px; margin-right: 3px;
} }

View file

@ -3,7 +3,7 @@
* *
* Copyright (c) 2010, Ajax.org B.V. * Copyright (c) 2010, Ajax.org B.V.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -39,8 +39,8 @@ var config = require("../config");
* Transforms a given input code snippet into HTML using the given mode * Transforms a given input code snippet into HTML using the given mode
* *
* @param {string} input Code snippet * @param {string} input Code snippet
* @param {string|mode} mode String specifying the mode to load such as * @param {string|mode} mode String specifying the mode to load such as
* `ace/mode/javascript` or, a mode loaded from `/ace/mode` * `ace/mode/javascript` or, a mode loaded from `/ace/mode`
* (use 'ServerSideHiglighter.getMode'). * (use 'ServerSideHiglighter.getMode').
* @param {string|theme} theme String specifying the theme to load such as * @param {string|theme} theme String specifying the theme to load such as
* `ace/theme/twilight` or, a theme loaded from `/ace/theme`. * `ace/theme/twilight` or, a theme loaded from `/ace/theme`.
@ -57,25 +57,25 @@ var config = require("../config");
exports.render = function(input, mode, theme, lineStart, disableGutter, callback) { exports.render = function(input, mode, theme, lineStart, disableGutter, callback) {
var waiting = 0 var waiting = 0
// if either the theme or the mode were specified as objects // if either the theme or the mode were specified as objects
// then we need to lazily load them. // then we need to lazily load them.
if (typeof theme == "string") { if (typeof theme == "string") {
waiting++; waiting++;
config.loadModule(['theme', theme], function (m) { config.loadModule(['theme', theme], function(m) {
theme = m; theme = m;
--waiting || done(); --waiting || done();
}); });
} }
if (typeof mode == "string") { if (typeof mode == "string") {
waiting++; waiting++;
config.loadModule(['mode', mode], function (m) { config.loadModule(['mode', mode], function(m) {
mode = new m.Mode() mode = new m.Mode()
--waiting || done(); --waiting || done();
}); });
} }
// loads or passes the specified mode module then calls renderer // loads or passes the specified mode module then calls renderer
function done() { function done() {
var result = exports.renderSync(input, mode, theme, lineStart, disableGutter); var result = exports.renderSync(input, mode, theme, lineStart, disableGutter);
@ -94,20 +94,20 @@ exports.render = function(input, mode, theme, lineStart, disableGutter, callback
exports.renderSync = function(input, mode, theme, lineStart, disableGutter) { exports.renderSync = function(input, mode, theme, lineStart, disableGutter) {
lineStart = parseInt(lineStart || 1, 10); lineStart = parseInt(lineStart || 1, 10);
var session = new EditSession(""); var session = new EditSession("");
session.setUseWorker(false); session.setUseWorker(false);
session.setMode(mode); session.setMode(mode);
var textLayer = new TextLayer(document.createElement("div")); var textLayer = new TextLayer(document.createElement("div"));
textLayer.setSession(session); textLayer.setSession(session);
textLayer.config = { textLayer.config = {
characterWidth: 10, characterWidth: 10,
lineHeight: 20 lineHeight: 20
}; };
session.setValue(input); session.setValue(input);
var stringBuilder = []; var stringBuilder = [];
var length = session.getLength(); var length = session.getLength();
@ -118,16 +118,16 @@ exports.renderSync = function(input, mode, theme, lineStart, disableGutter) {
textLayer.$renderLine(stringBuilder, ix, true, false); textLayer.$renderLine(stringBuilder, ix, true, false);
stringBuilder.push("</div>"); stringBuilder.push("</div>");
} }
// let's prepare the whole html // let's prepare the whole html
var html = "<div class=':cssClass'>\ var html = "<div class=':cssClass'>\
<div class='ace_editor ace_scroller ace_text-layer'>\ <div class='ace_editor ace_scroller ace_text-layer'>\
:code\ :code\
</div>\ </div>\
</div>".replace(/:cssClass/, theme.cssClass).replace(/:code/, stringBuilder.join("")); </div>".replace(/:cssClass/, theme.cssClass).replace(/:code/, stringBuilder.join(""));
textLayer.destroy(); textLayer.destroy();
return { return {
css: baseStyles + theme.cssText, css: baseStyles + theme.cssText,
html: html html: html

View file

@ -13,7 +13,7 @@ var JavaScriptMode = require("../mode/javascript").Mode;
// Execution ORDER: test.setUpSuite, setUp, testFn, tearDown, test.tearDownSuite // Execution ORDER: test.setUpSuite, setUp, testFn, tearDown, test.tearDownSuite
module.exports = { module.exports = {
timeout: 10000, timeout: 10000,
"test simple snippet": function(next) { "test simple snippet": function(next) {
var theme = require("../theme/tomorrow"); var theme = require("../theme/tomorrow");
var snippet = "\ var snippet = "\
@ -24,13 +24,13 @@ function hello (a, b, c) {\n\
console.log(a * b + c + 'sup?');\n\ console.log(a * b + c + 'sup?');\n\
}"; }";
var mode = new JavaScriptMode(); var mode = new JavaScriptMode();
var result = highlighter.render(snippet, mode, theme); var result = highlighter.render(snippet, mode, theme);
assert.equal(result.html, "<div class='ace-tomorrow'> <div class='ace_editor ace_scroller ace_text-layer'> <div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>1</span><span class='ace_comment ace_doc'>/**\xa0this\xa0is\xa0a\xa0function</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>2</span><span class='ace_comment ace_doc'>*</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>3</span><span class='ace_comment ace_doc'>*/</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>4</span><span class='ace_storage ace_type'>function</span>\xa0<span class='ace_entity ace_name ace_function'>hello</span>\xa0<span class='ace_paren ace_lparen'>(</span><span class='ace_variable ace_parameter'>a</span><span class='ace_punctuation ace_operator'>,\xa0</span><span class='ace_variable ace_parameter'>b</span><span class='ace_punctuation ace_operator'>,\xa0</span><span class='ace_variable ace_parameter'>c</span><span class='ace_paren ace_rparen'>)</span>\xa0<span class='ace_paren ace_lparen'>{</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>5</span>\xa0\xa0\xa0\xa0<span class='ace_storage ace_type'>console</span><span class='ace_punctuation ace_operator'>.</span><span class='ace_support ace_function ace_firebug'>log</span><span class='ace_paren ace_lparen'>(</span><span class='ace_identifier'>a</span>\xa0<span class='ace_keyword ace_operator'>*</span>\xa0<span class='ace_identifier'>b</span>\xa0<span class='ace_keyword ace_operator'>+</span>\xa0<span class='ace_identifier'>c</span>\xa0<span class='ace_keyword ace_operator'>+</span>\xa0<span class='ace_string'>'sup?'</span><span class='ace_paren ace_rparen'>)</span><span class='ace_punctuation ace_operator'>;</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>6</span><span class='ace_paren ace_rparen'>}</span></div> </div> </div>"); assert.equal(result.html, "<div class='ace-tomorrow'> <div class='ace_editor ace_scroller ace_text-layer'> <div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>1</span><span class='ace_comment ace_doc'>/**\xa0this\xa0is\xa0a\xa0function</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>2</span><span class='ace_comment ace_doc'>*</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>3</span><span class='ace_comment ace_doc'>*/</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>4</span><span class='ace_storage ace_type'>function</span>\xa0<span class='ace_entity ace_name ace_function'>hello</span>\xa0<span class='ace_paren ace_lparen'>(</span><span class='ace_variable ace_parameter'>a</span><span class='ace_punctuation ace_operator'>,\xa0</span><span class='ace_variable ace_parameter'>b</span><span class='ace_punctuation ace_operator'>,\xa0</span><span class='ace_variable ace_parameter'>c</span><span class='ace_paren ace_rparen'>)</span>\xa0<span class='ace_paren ace_lparen'>{</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>5</span>\xa0\xa0\xa0\xa0<span class='ace_storage ace_type'>console</span><span class='ace_punctuation ace_operator'>.</span><span class='ace_support ace_function ace_firebug'>log</span><span class='ace_paren ace_lparen'>(</span><span class='ace_identifier'>a</span>\xa0<span class='ace_keyword ace_operator'>*</span>\xa0<span class='ace_identifier'>b</span>\xa0<span class='ace_keyword ace_operator'>+</span>\xa0<span class='ace_identifier'>c</span>\xa0<span class='ace_keyword ace_operator'>+</span>\xa0<span class='ace_string'>'sup?'</span><span class='ace_paren ace_rparen'>)</span><span class='ace_punctuation ace_operator'>;</span></div><div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'>6</span><span class='ace_paren ace_rparen'>}</span></div> </div> </div>");
assert.ok(!!result.css); assert.ok(!!result.css);
next(); next();
}, },
"test css from theme is used": function(next) { "test css from theme is used": function(next) {
var theme = require("../theme/tomorrow"); var theme = require("../theme/tomorrow");
var snippet = "\ var snippet = "\
@ -41,16 +41,16 @@ function hello (a, b, c) {\n\
console.log(a * b + c + 'sup?');\n\ console.log(a * b + c + 'sup?');\n\
}"; }";
var mode = new JavaScriptMode(); var mode = new JavaScriptMode();
var isError = false, result; var isError = false, result;
result = highlighter.render(snippet, mode, theme); result = highlighter.render(snippet, mode, theme);
assert.ok(result.css.indexOf(theme.cssText) !== -1); assert.ok(result.css.indexOf(theme.cssText) !== -1);
next(); next();
}, },
"test theme classname should be in output html": function (next) { "test theme classname should be in output html": function(next) {
var theme = require("../theme/tomorrow"); var theme = require("../theme/tomorrow");
var snippet = "\ var snippet = "\
/** this is a function\n\ /** this is a function\n\
@ -60,11 +60,11 @@ function hello (a, b, c) {\n\
console.log(a * b + c + 'sup?');\n\ console.log(a * b + c + 'sup?');\n\
}"; }";
var mode = new JavaScriptMode(); var mode = new JavaScriptMode();
var isError = false, result; var isError = false, result;
result = highlighter.render(snippet, mode, theme); result = highlighter.render(snippet, mode, theme);
assert.equal(!!result.html.match(/<div class='ace-tomorrow'>/), true); assert.equal(!!result.html.match(/<div class='ace-tomorrow'>/), true);
next(); next();
} }
}; };

View file

@ -3,7 +3,7 @@
* *
* Copyright (c) 2010, Ajax.org B.V. * Copyright (c) 2010, Ajax.org B.V.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -232,7 +232,7 @@ exports.transformTextarea = function(element, loader) {
// Create the setting's panel. // Create the setting's panel.
setupSettingPanel(settingDiv, settingOpener, editor, options); setupSettingPanel(settingDiv, settingOpener, editor, options);
var state = ""; var state = "";
event.addListener(settingOpener, "mousemove", function(e) { event.addListener(settingOpener, "mousemove", function(e) {
var rect = this.getBoundingClientRect(); var rect = this.getBoundingClientRect();
@ -245,7 +245,7 @@ exports.transformTextarea = function(element, loader) {
this.style.cursor = "nw-resize"; this.style.cursor = "nw-resize";
} }
}); });
event.addListener(settingOpener, "mousedown", function(e) { event.addListener(settingOpener, "mousedown", function(e) {
if (state == "toggle") { if (state == "toggle") {
editor.setDisplaySettings(); editor.setDisplaySettings();
@ -294,7 +294,7 @@ function setupApi(editor, editorDiv, settingDiv, ace, options, loader) {
editor.focus(); editor.focus();
}; };
}; };
editor.setOption = function(key, value) { editor.setOption = function(key, value) {
if (options[key] == value) return; if (options[key] == value) return;
@ -335,7 +335,7 @@ function setupApi(editor, editorDiv, settingDiv, ace, options, loader) {
case "vim": case "vim":
editor.setKeyboardHandler("ace/keyboard/vim"); editor.setKeyboardHandler("ace/keyboard/vim");
break; break;
case "emacs": case "emacs":
editor.setKeyboardHandler("ace/keyboard/emacs"); editor.setKeyboardHandler("ace/keyboard/emacs");
break; break;
default: default:

View file

@ -1,88 +1,79 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license: * Distributed under the BSD license:
* *
* Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
* All rights reserved. * All rights reserved.
* *
* Contributed to Ajax.org under the BSD license. * Contributed to Ajax.org under the BSD license.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/*jslint /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
indent: 4, /*global define, require */
maxerr: 50,
white: true, /**
browser: true, * Generates a list of themes available when ace was built.
vars: true * @fileOverview Generates a list of themes available when ace was built.
*/ * @author <a href="mailto:matthewkastor@gmail.com">
/*global * Matthew Christopher Kastor-Inare III </a><br />
define, * ☭ Hial Atropa!! ☭
require */
*/
define(function(require, exports, module) {
/** "use strict";
* Generates a list of themes available when ace was built.
* @fileOverview Generates a list of themes available when ace was built. /**
* @author <a href="mailto:matthewkastor@gmail.com"> * An array containing information about available themes.
* Matthew Christopher Kastor-Inare III </a><br /> */
* ☭ Hial Atropa!! ☭ module.exports.themes = require('ace/ext/themelist_utils/themes').themes;
*/
/**
define(function(require, exports, module) { * Creates a theme description.
"use strict"; * @param {string} name The file name of the theme.
* @returns {ThemeDescription} Returns a theme description object which has
/** * three properties: the name gives the filename, the desc gives a menu
* An array containing information about available themes. * friendly name, and the theme gives the string to set the theme with
*/ * `setTheme`
module.exports.themes = require('ace/ext/themelist_utils/themes').themes; */
module.exports.ThemeDescription = function(name) {
/** this.name = name;
* Creates a theme description. this.desc = name.split('_'
* @param {string} name The file name of the theme. ).map(
* @returns {ThemeDescription} Returns a theme description object which has function(namePart) {
* three properties: the name gives the filename, the desc gives a menu return namePart[0].toUpperCase() + namePart.slice(1);
* friendly name, and the theme gives the string to set the theme with }
* `setTheme` ).join(' ');
*/ this.theme = "ace/theme/" + name;
module.exports.ThemeDescription = function(name) { };
this.name = name;
this.desc = name.split('_' module.exports.themesByName = {};
).map(
function (namePart) { module.exports.themes = module.exports.themes.map(function(name) {
return namePart[0].toUpperCase() + namePart.slice(1); module.exports.themesByName[name] = new module.exports.ThemeDescription(name);
} return module.exports.themesByName[name];
).join(' '); });
this.theme = "ace/theme/" + name;
}; });
module.exports.themesByName = {};
module.exports.themes = module.exports.themes.map(function (name) {
module.exports.themesByName[name] = new module.exports.ThemeDescription(name);
return module.exports.themesByName[name];
});
});

View file

@ -55,23 +55,23 @@ exports.$detectIndentation = function(lines, fallback) {
var diff = spaces - prevSpaces; var diff = spaces - prevSpaces;
if (diff > 0 && !(prevSpaces%diff) && !(spaces%diff)) if (diff > 0 && !(prevSpaces%diff) && !(spaces%diff))
changes[diff] = (changes[diff] || 0) + 1; changes[diff] = (changes[diff] || 0) + 1;
stats[spaces] = (stats[spaces] || 0) + 1; stats[spaces] = (stats[spaces] || 0) + 1;
} }
prevSpaces = spaces; prevSpaces = spaces;
// ignore lines ending with backslash // ignore lines ending with backslash
while (line[line.length - 1] == "\\") while (line[line.length - 1] == "\\")
line = lines[i++]; line = lines[i++];
}; };
function getScore(indent) { function getScore(indent) {
var score = 0; var score = 0;
for (var i = indent; i < stats.length; i += indent) for (var i = indent; i < stats.length; i += indent)
score += stats[i] || 0; score += stats[i] || 0;
return score; return score;
} }
var changesTotal = changes.reduce(function(a,b){return a+b}, 0); var changesTotal = changes.reduce(function(a,b){return a+b}, 0);
var first = {score: 0, length: 0}; var first = {score: 0, length: 0};
@ -86,17 +86,17 @@ exports.$detectIndentation = function(lines, fallback) {
if (changes[i]) { if (changes[i]) {
score += changes[i] / changesTotal; score += changes[i] / changesTotal;
} }
if (score > first.score) if (score > first.score)
first = {score: score, length: i}; first = {score: score, length: i};
} }
if (first.score && first.score > 1.4) if (first.score && first.score > 1.4)
var tabLength = first.length; var tabLength = first.length;
if (tabIndents > spaceIndents + 1) if (tabIndents > spaceIndents + 1)
return {ch: "\t", length: tabLength}; return {ch: "\t", length: tabLength};
if (spaceIndents + 1 > tabIndents) if (spaceIndents + 1 > tabIndents)
return {ch: " ", length: tabLength}; return {ch: " ", length: tabLength};
}; };
@ -104,10 +104,10 @@ exports.$detectIndentation = function(lines, fallback) {
exports.detectIndentation = function(session) { exports.detectIndentation = function(session) {
var lines = session.getLines(0, 1000); var lines = session.getLines(0, 1000);
var indent = exports.$detectIndentation(lines) || {}; var indent = exports.$detectIndentation(lines) || {};
if (indent.ch) if (indent.ch)
session.setUseSoftTabs(indent.ch == " "); session.setUseSoftTabs(indent.ch == " ");
if (indent.length) if (indent.length)
session.setTabSize(indent.length); session.setTabSize(indent.length);
return indent; return indent;
@ -131,9 +131,9 @@ exports.convertIndentation = function(session, ch, len) {
var oldLen = session.getTabSize(); var oldLen = session.getTabSize();
if (!len) len = oldLen; if (!len) len = oldLen;
if (!ch) ch = oldCh; if (!ch) ch = oldCh;
var tab = ch == "\t" ? ch: lang.stringRepeat(ch, len); var tab = ch == "\t" ? ch: lang.stringRepeat(ch, len);
var doc = session.doc; var doc = session.doc;
var lines = doc.getAllLines(); var lines = doc.getAllLines();
@ -148,10 +148,10 @@ exports.convertIndentation = function(session, ch, len) {
var reminder = w%oldLen; var reminder = w%oldLen;
var toInsert = cache[tabCount] || (cache[tabCount] = lang.stringRepeat(tab, tabCount)); var toInsert = cache[tabCount] || (cache[tabCount] = lang.stringRepeat(tab, tabCount));
toInsert += spaceCache[reminder] || (spaceCache[reminder] = lang.stringRepeat(" ", reminder)); toInsert += spaceCache[reminder] || (spaceCache[reminder] = lang.stringRepeat(" ", reminder));
if (toInsert != match) { if (toInsert != match) {
doc.removeInLine(i, 0, match.length); doc.removeInLine(i, 0, match.length);
doc.insertInLine({row: i, column: 0}, toInsert); doc.insertInLine({row: i, column: 0}, toInsert);
} }
} }
} }