2011-12-04 16:33:56 +01:00
|
|
|
/**
|
|
|
|
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
|
|
|
* This helps other people to understand this code better and helps them to improve it.
|
|
|
|
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
|
|
*/
|
|
|
|
|
2011-03-26 14:10:41 +01:00
|
|
|
/**
|
|
|
|
* Copyright 2009 Google Inc.
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-07 02:27:03 +01:00
|
|
|
var padcookie = require('./pad_cookie').padcookie;
|
|
|
|
var padutils = require('./pad_utils').padutils;
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2011-07-07 19:59:34 +02:00
|
|
|
var padeditor = (function()
|
|
|
|
{
|
2012-01-16 06:37:47 +01:00
|
|
|
var Ace2Editor = undefined;
|
|
|
|
var pad = undefined;
|
|
|
|
var settings = undefined;
|
2011-03-26 14:10:41 +01:00
|
|
|
var self = {
|
2011-07-07 19:59:34 +02:00
|
|
|
ace: null,
|
|
|
|
// this is accessed directly from other files
|
2011-03-26 14:10:41 +01:00
|
|
|
viewZoom: 100,
|
2012-01-27 06:02:58 +01:00
|
|
|
init: function(readyFunc, initialViewOptions, _pad)
|
2011-07-07 19:59:34 +02:00
|
|
|
{
|
2012-03-07 02:27:03 +01:00
|
|
|
Ace2Editor = require('./ace').Ace2Editor;
|
2012-01-27 06:02:58 +01:00
|
|
|
pad = _pad;
|
|
|
|
settings = pad.settings;
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2011-07-07 19:59:34 +02:00
|
|
|
function aceReady()
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
$("#editorloadingbox").hide();
|
2011-07-07 19:59:34 +02:00
|
|
|
if (readyFunc)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
readyFunc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.ace = new Ace2Editor();
|
|
|
|
self.ace.init("editorcontainer", "", aceReady);
|
|
|
|
self.ace.setProperty("wraps", true);
|
2011-07-07 19:59:34 +02:00
|
|
|
if (pad.getIsDebugEnabled())
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
self.ace.setProperty("dmesg", pad.dmesg);
|
|
|
|
}
|
|
|
|
self.initViewOptions();
|
|
|
|
self.setViewOptions(initialViewOptions);
|
|
|
|
|
|
|
|
// view bar
|
|
|
|
$("#viewbarcontents").show();
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
initViewOptions: function()
|
|
|
|
{
|
2013-03-05 23:12:00 +01:00
|
|
|
// Line numbers
|
2011-07-07 19:59:34 +02:00
|
|
|
padutils.bindCheckboxChange($("#options-linenoscheck"), function()
|
|
|
|
{
|
|
|
|
pad.changeViewOption('showLineNumbers', padutils.getCheckbox($("#options-linenoscheck")));
|
2011-03-26 14:10:41 +01:00
|
|
|
});
|
2013-03-05 23:12:00 +01:00
|
|
|
|
|
|
|
// Author colors
|
2011-07-07 19:59:34 +02:00
|
|
|
padutils.bindCheckboxChange($("#options-colorscheck"), function()
|
|
|
|
{
|
2012-02-27 16:24:36 +01:00
|
|
|
padcookie.setPref('showAuthorshipColors', padutils.getCheckbox("#options-colorscheck"));
|
2011-07-07 19:59:34 +02:00
|
|
|
pad.changeViewOption('showAuthorColors', padutils.getCheckbox("#options-colorscheck"));
|
2011-03-26 14:10:41 +01:00
|
|
|
});
|
2013-03-05 23:12:00 +01:00
|
|
|
|
|
|
|
// Right to left
|
|
|
|
padutils.bindCheckboxChange($("#options-rtlcheck"), function()
|
|
|
|
{
|
|
|
|
pad.changeViewOption('rtlIsTrue', padutils.getCheckbox($("#options-rtlcheck")))
|
|
|
|
});
|
|
|
|
html10n.bind('localized', function() {
|
|
|
|
pad.changeViewOption('rtlIsTrue', ('rtl' == html10n.getDirection()));
|
|
|
|
padutils.setCheckbox($("#options-rtlcheck"), ('rtl' == html10n.getDirection()));
|
|
|
|
})
|
|
|
|
|
|
|
|
// font face
|
2011-07-07 19:59:34 +02:00
|
|
|
$("#viewfontmenu").change(function()
|
|
|
|
{
|
|
|
|
pad.changeViewOption('useMonospaceFont', $("#viewfontmenu").val() == 'monospace');
|
2011-03-26 14:10:41 +01:00
|
|
|
});
|
2012-12-19 22:23:13 +01:00
|
|
|
|
2013-03-05 23:12:00 +01:00
|
|
|
// Language
|
2012-12-19 22:23:13 +01:00
|
|
|
html10n.bind('localized', function() {
|
|
|
|
$("#languagemenu").val(html10n.getLanguage());
|
2013-01-25 17:41:33 +01:00
|
|
|
// translate the value of 'unnamed' and 'Enter your name' textboxes in the userlist
|
2013-01-25 20:38:24 +01:00
|
|
|
// this does not interfere with html10n's normal value-setting because html10n just ingores <input>s
|
|
|
|
// also, a value which has been set by the user will be not overwritten since a user-edited <input>
|
|
|
|
// does *not* have the editempty-class
|
2013-01-25 10:32:09 +01:00
|
|
|
$('input[data-l10n-id]').each(function(key, input)
|
|
|
|
{
|
|
|
|
input = $(input);
|
|
|
|
if(input.hasClass("editempty"))
|
2013-01-25 17:41:33 +01:00
|
|
|
input.val(html10n.get(input.attr("data-l10n-id")));
|
2013-01-25 10:32:09 +01:00
|
|
|
});
|
2012-12-19 22:23:13 +01:00
|
|
|
})
|
2012-12-20 11:19:51 +01:00
|
|
|
$("#languagemenu").val(html10n.getLanguage());
|
2012-11-12 16:49:15 +01:00
|
|
|
$("#languagemenu").change(function() {
|
|
|
|
pad.createCookie("language",$("#languagemenu").val(),null,'/');
|
2012-12-19 17:21:22 +01:00
|
|
|
window.html10n.localize([$("#languagemenu").val(), 'en']);
|
2012-11-12 16:49:15 +01:00
|
|
|
});
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
setViewOptions: function(newOptions)
|
|
|
|
{
|
|
|
|
function getOption(key, defaultValue)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
var value = String(newOptions[key]);
|
|
|
|
if (value == "true") return true;
|
|
|
|
if (value == "false") return false;
|
|
|
|
return defaultValue;
|
|
|
|
}
|
2012-01-26 17:22:44 +01:00
|
|
|
|
2011-03-26 14:10:41 +01:00
|
|
|
var v;
|
|
|
|
|
2013-03-05 23:12:00 +01:00
|
|
|
v = getOption('rtlIsTrue', ('rtl' == html10n.getDirection()));
|
|
|
|
// Override from parameters if true
|
|
|
|
if(settings.rtlIsTrue === true) v = true;
|
2012-10-29 22:55:57 +01:00
|
|
|
self.ace.setProperty("rtlIsTrue", v);
|
2013-03-05 23:12:00 +01:00
|
|
|
padutils.setCheckbox($("#options-rtlcheck"), v);
|
2012-10-29 22:55:57 +01:00
|
|
|
|
2011-03-26 14:10:41 +01:00
|
|
|
v = getOption('showLineNumbers', true);
|
|
|
|
self.ace.setProperty("showslinenumbers", v);
|
|
|
|
padutils.setCheckbox($("#options-linenoscheck"), v);
|
|
|
|
|
|
|
|
v = getOption('showAuthorColors', true);
|
|
|
|
self.ace.setProperty("showsauthorcolors", v);
|
|
|
|
padutils.setCheckbox($("#options-colorscheck"), v);
|
2012-04-30 16:40:29 +02:00
|
|
|
// Override from parameters if true
|
|
|
|
if (settings.noColors !== false)
|
|
|
|
self.ace.setProperty("showsauthorcolors", !settings.noColors);
|
2011-03-26 14:10:41 +01:00
|
|
|
|
|
|
|
v = getOption('useMonospaceFont', false);
|
2011-07-07 19:59:34 +02:00
|
|
|
self.ace.setProperty("textface", (v ? "monospace" : "Arial, sans-serif"));
|
2011-03-26 14:10:41 +01:00
|
|
|
$("#viewfontmenu").val(v ? "monospace" : "normal");
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
dispose: function()
|
|
|
|
{
|
|
|
|
if (self.ace)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
self.ace.destroy();
|
2012-01-29 02:25:24 +01:00
|
|
|
self.ace = null;
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
disable: function()
|
|
|
|
{
|
|
|
|
if (self.ace)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
self.ace.setProperty("grayedOut", true);
|
|
|
|
self.ace.setEditable(false);
|
|
|
|
}
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
restoreRevisionText: function(dataFromServer)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.addHistoricalAuthors(dataFromServer.historicalAuthorData);
|
|
|
|
self.ace.importAText(dataFromServer.atext, dataFromServer.apool, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return self;
|
|
|
|
}());
|
2012-01-16 02:23:48 +01:00
|
|
|
|
|
|
|
exports.padeditor = padeditor;
|