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 padutils = require('./pad_utils').padutils;
|
|
|
|
var padeditor = require('./pad_editor').padeditor;
|
2012-04-01 13:27:38 +02:00
|
|
|
var padsavedrevs = require('./pad_savedrevs');
|
2012-01-16 06:37:47 +01:00
|
|
|
|
2012-02-06 21:36:45 +01:00
|
|
|
function indexOf(array, value) {
|
|
|
|
for (var i = 0, ii = array.length; i < ii; i++) {
|
|
|
|
if (array[i] == value) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-07-07 19:59:34 +02:00
|
|
|
var padeditbar = (function()
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2011-07-07 19:59:34 +02:00
|
|
|
var syncAnimation = (function()
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
var SYNCING = -100;
|
|
|
|
var DONE = 100;
|
|
|
|
var state = DONE;
|
|
|
|
var fps = 25;
|
2011-07-07 19:59:34 +02:00
|
|
|
var step = 1 / fps;
|
2011-03-26 14:10:41 +01:00
|
|
|
var T_START = -0.5;
|
|
|
|
var T_FADE = 1.0;
|
|
|
|
var T_GONE = 1.5;
|
2011-07-07 19:59:34 +02:00
|
|
|
var animator = padutils.makeAnimationScheduler(function()
|
|
|
|
{
|
|
|
|
if (state == SYNCING || state == DONE)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
2011-07-07 19:59:34 +02:00
|
|
|
else if (state >= T_GONE)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
state = DONE;
|
|
|
|
$("#syncstatussyncing").css('display', 'none');
|
|
|
|
$("#syncstatusdone").css('display', 'none');
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-07 19:59:34 +02:00
|
|
|
else if (state < 0)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
state += step;
|
2011-07-07 19:59:34 +02:00
|
|
|
if (state >= 0)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
$("#syncstatussyncing").css('display', 'none');
|
|
|
|
$("#syncstatusdone").css('display', 'block').css('opacity', 1);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-07-07 19:59:34 +02:00
|
|
|
else
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
state += step;
|
2011-07-07 19:59:34 +02:00
|
|
|
if (state >= T_FADE)
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
$("#syncstatusdone").css('opacity', (T_GONE - state) / (T_GONE - T_FADE));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-07-07 19:59:34 +02:00
|
|
|
}, step * 1000);
|
2011-03-26 14:10:41 +01:00
|
|
|
return {
|
2011-07-07 19:59:34 +02:00
|
|
|
syncing: function()
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
state = SYNCING;
|
|
|
|
$("#syncstatussyncing").css('display', 'block');
|
|
|
|
$("#syncstatusdone").css('display', 'none');
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
done: function()
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
state = T_START;
|
|
|
|
animator.scheduleAnimation();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
|
|
|
var self = {
|
2011-07-07 19:59:34 +02:00
|
|
|
init: function()
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
$("#editbar .editbarbutton").attr("unselectable", "on"); // for IE
|
|
|
|
$("#editbar").removeClass("disabledtoolbar").addClass("enabledtoolbar");
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
isEnabled: function()
|
|
|
|
{
|
2011-07-19 18:42:19 +02:00
|
|
|
// return !$("#editbar").hasClass('disabledtoolbar');
|
|
|
|
return true;
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
disable: function()
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
$("#editbar").addClass('disabledtoolbar').removeClass("enabledtoolbar");
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
toolbarClick: function(cmd)
|
2011-07-19 18:42:19 +02:00
|
|
|
{
|
2011-07-07 19:59:34 +02:00
|
|
|
if (self.isEnabled())
|
|
|
|
{
|
2011-07-08 16:19:38 +02:00
|
|
|
if(cmd == "showusers")
|
2011-07-07 19:59:34 +02:00
|
|
|
{
|
2011-07-08 16:19:38 +02:00
|
|
|
self.toogleDropDown("users");
|
2011-03-26 15:50:13 +01:00
|
|
|
}
|
2012-01-26 17:22:44 +01:00
|
|
|
else if (cmd == 'settings')
|
|
|
|
{
|
|
|
|
self.toogleDropDown("settingsmenu");
|
|
|
|
}
|
2011-07-08 16:19:38 +02:00
|
|
|
else if (cmd == 'embed')
|
2011-11-24 16:34:28 +01:00
|
|
|
{
|
|
|
|
self.setEmbedLinks();
|
2012-01-26 17:22:44 +01:00
|
|
|
$('#linkinput').focus().select();
|
2011-11-23 16:46:34 +01:00
|
|
|
self.toogleDropDown("embed");
|
2011-03-26 17:00:04 +01:00
|
|
|
}
|
2011-07-20 18:33:27 +02:00
|
|
|
else if (cmd == 'import_export')
|
|
|
|
{
|
2011-07-27 16:11:30 +02:00
|
|
|
self.toogleDropDown("importexport");
|
2011-07-20 18:33:27 +02:00
|
|
|
}
|
2012-02-29 20:40:14 +01:00
|
|
|
else if (cmd == 'savedRevision')
|
2011-07-07 19:59:34 +02:00
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
padsavedrevs.saveNow();
|
2011-07-07 19:59:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
padeditor.ace.callWithAce(function(ace)
|
|
|
|
{
|
|
|
|
if (cmd == 'bold' || cmd == 'italic' || cmd == 'underline' || cmd == 'strikethrough') ace.ace_toggleAttributeOnSelection(cmd);
|
|
|
|
else if (cmd == 'undo' || cmd == 'redo') ace.ace_doUndoRedo(cmd);
|
|
|
|
else if (cmd == 'insertunorderedlist') ace.ace_doInsertUnorderedList();
|
2012-01-15 18:20:20 +01:00
|
|
|
else if (cmd == 'insertorderedlist') ace.ace_doInsertOrderedList();
|
2011-07-07 19:59:34 +02:00
|
|
|
else if (cmd == 'indent')
|
|
|
|
{
|
|
|
|
if (!ace.ace_doIndentOutdent(false))
|
|
|
|
{
|
|
|
|
ace.ace_doInsertUnorderedList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd == 'outdent')
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
ace.ace_doIndentOutdent(true);
|
2011-07-07 19:59:34 +02:00
|
|
|
}
|
|
|
|
else if (cmd == 'clearauthorship')
|
|
|
|
{
|
|
|
|
if ((!(ace.ace_getRep().selStart && ace.ace_getRep().selEnd)) || ace.ace_isCaret())
|
|
|
|
{
|
|
|
|
if (window.confirm("Clear authorship colors on entire document?"))
|
|
|
|
{
|
|
|
|
ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [
|
|
|
|
['author', '']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ace.ace_setAttributeOnSelection('author', '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, cmd, true);
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-18 06:18:35 +01:00
|
|
|
if(padeditor.ace) padeditor.ace.focus();
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2011-07-08 16:19:38 +02:00
|
|
|
toogleDropDown: function(moduleName)
|
|
|
|
{
|
2012-02-03 20:43:09 +01:00
|
|
|
var modules = ["settingsmenu", "importexport", "embed", "users"];
|
2011-07-08 16:19:38 +02:00
|
|
|
|
|
|
|
//hide all modules
|
|
|
|
if(moduleName == "none")
|
|
|
|
{
|
2012-04-16 15:23:19 +02:00
|
|
|
$(".toolbar ul.menu_right li").removeClass("selected");
|
2011-07-08 16:19:38 +02:00
|
|
|
for(var i=0;i<modules.length;i++)
|
|
|
|
{
|
2011-08-21 20:07:35 +02:00
|
|
|
//skip the userlist
|
|
|
|
if(modules[i] == "users")
|
|
|
|
continue;
|
|
|
|
|
2011-07-08 16:19:38 +02:00
|
|
|
var module = $("#" + modules[i]);
|
|
|
|
|
|
|
|
if(module.css('display') != "none")
|
|
|
|
{
|
|
|
|
module.slideUp("fast");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-06 21:36:45 +01:00
|
|
|
var nth_child = indexOf(modules, moduleName) + 1;
|
2012-04-16 15:23:19 +02:00
|
|
|
if (nth_child > 0 && nth_child <= (modules.length-1)) {
|
|
|
|
$(".toolbar ul.menu_right li:not(:nth-child(" + nth_child + "))").removeClass("selected");
|
|
|
|
$(".toolbar ul.menu_right li:nth-child(" + nth_child + ")").toggleClass("selected");
|
|
|
|
}
|
|
|
|
if(modules[modules.length-1] === moduleName) $(".toolbar ul.menu_right li").removeClass("selected");
|
2011-07-08 16:19:38 +02:00
|
|
|
//hide all modules that are not selected and show the selected one
|
|
|
|
for(var i=0;i<modules.length;i++)
|
|
|
|
{
|
|
|
|
var module = $("#" + modules[i]);
|
|
|
|
|
|
|
|
if(module.css('display') != "none")
|
|
|
|
{
|
|
|
|
module.slideUp("fast");
|
|
|
|
}
|
|
|
|
else if(modules[i]==moduleName)
|
|
|
|
{
|
|
|
|
module.slideDown("fast");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-07-07 19:59:34 +02:00
|
|
|
setSyncStatus: function(status)
|
|
|
|
{
|
|
|
|
if (status == "syncing")
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
syncAnimation.syncing();
|
|
|
|
}
|
2011-07-07 19:59:34 +02:00
|
|
|
else if (status == "done")
|
|
|
|
{
|
2011-03-26 14:10:41 +01:00
|
|
|
syncAnimation.done();
|
|
|
|
}
|
2011-11-24 16:34:28 +01:00
|
|
|
},
|
|
|
|
setEmbedLinks: function()
|
|
|
|
{
|
|
|
|
if ($('#readonlyinput').is(':checked'))
|
|
|
|
{
|
|
|
|
var basePath = document.location.href.substring(0, document.location.href.indexOf("/p/"));
|
|
|
|
var readonlyLink = basePath + "/ro/" + clientVars.readOnlyId;
|
2012-02-28 17:52:30 +01:00
|
|
|
$('#embedinput').val("<iframe name='embed_readonly' src='" + readonlyLink + "?showControls=true&showChat=true&showLineNumbers=true&useMonospaceFont=false' width=600 height=400>");
|
2011-11-24 16:34:28 +01:00
|
|
|
$('#linkinput').val(readonlyLink);
|
2012-02-19 17:04:36 +01:00
|
|
|
$('#embedreadonlyqr').attr("src","https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=|0&chl=" + readonlyLink);
|
2011-11-24 16:34:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var padurl = window.location.href.split("?")[0];
|
2012-02-28 17:52:30 +01:00
|
|
|
$('#embedinput').val("<iframe name='embed_readwrite' src='" + padurl + "?showControls=true&showChat=true&showLineNumbers=true&useMonospaceFont=false' width=600 height=400>");
|
2011-11-24 16:34:28 +01:00
|
|
|
$('#linkinput').val(padurl);
|
2012-02-19 17:04:36 +01:00
|
|
|
$('#embedreadonlyqr').attr("src","https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=|0&chl=" + padurl);
|
2011-11-24 16:34:28 +01:00
|
|
|
}
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return self;
|
2011-03-26 15:50:13 +01:00
|
|
|
}());
|
2012-01-16 02:23:48 +01:00
|
|
|
|
|
|
|
exports.padeditbar = padeditbar;
|