mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
beautified all static js files
This commit is contained in:
parent
2fa1d8768b
commit
271ee1776b
36 changed files with 9456 additions and 6035 deletions
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
|
@ -15,65 +15,81 @@
|
|||
*/
|
||||
|
||||
var padutils = {
|
||||
escapeHtml: function(x) {
|
||||
escapeHtml: function(x)
|
||||
{
|
||||
return String(x).replace(/\</g, '<').replace(/\>/g, '>');
|
||||
},
|
||||
uniqueId: function() {
|
||||
function encodeNum(n, width) {
|
||||
uniqueId: function()
|
||||
{
|
||||
function encodeNum(n, width)
|
||||
{
|
||||
// returns string that is exactly 'width' chars, padding with zeros
|
||||
// and taking rightmost digits
|
||||
return (Array(width+1).join('0') + Number(n).toString(35)).slice(-width);
|
||||
return (Array(width + 1).join('0') + Number(n).toString(35)).slice(-width);
|
||||
}
|
||||
return [pad.getClientIp(),
|
||||
encodeNum(+new Date, 7),
|
||||
encodeNum(Math.floor(Math.random()*1e9), 4)].join('.');
|
||||
return [pad.getClientIp(), encodeNum(+new Date, 7), encodeNum(Math.floor(Math.random() * 1e9), 4)].join('.');
|
||||
},
|
||||
uaDisplay: function(ua) {
|
||||
uaDisplay: function(ua)
|
||||
{
|
||||
var m;
|
||||
|
||||
function clean(a) {
|
||||
function clean(a)
|
||||
{
|
||||
var maxlen = 16;
|
||||
a = a.replace(/[^a-zA-Z0-9\.]/g, '');
|
||||
if (a.length > maxlen) {
|
||||
a = a.substr(0,maxlen);
|
||||
if (a.length > maxlen)
|
||||
{
|
||||
a = a.substr(0, maxlen);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
function checkver(name) {
|
||||
function checkver(name)
|
||||
{
|
||||
var m = ua.match(RegExp(name + '\\/([\\d\\.]+)'));
|
||||
if (m && m.length > 1) {
|
||||
return clean(name+m[1]);
|
||||
if (m && m.length > 1)
|
||||
{
|
||||
return clean(name + m[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// firefox
|
||||
if (checkver('Firefox')) { return checkver('Firefox'); }
|
||||
if (checkver('Firefox'))
|
||||
{
|
||||
return checkver('Firefox');
|
||||
}
|
||||
|
||||
// misc browsers, including IE
|
||||
m = ua.match(/compatible; ([^;]+);/);
|
||||
if (m && m.length > 1) {
|
||||
if (m && m.length > 1)
|
||||
{
|
||||
return clean(m[1]);
|
||||
}
|
||||
|
||||
// iphone
|
||||
if (ua.match(/\(iPhone;/)) {
|
||||
if (ua.match(/\(iPhone;/))
|
||||
{
|
||||
return 'iPhone';
|
||||
}
|
||||
|
||||
// chrome
|
||||
if (checkver('Chrome')) { return checkver('Chrome'); }
|
||||
if (checkver('Chrome'))
|
||||
{
|
||||
return checkver('Chrome');
|
||||
}
|
||||
|
||||
// safari
|
||||
m = ua.match(/Safari\/[\d\.]+/);
|
||||
if (m) {
|
||||
if (m)
|
||||
{
|
||||
var v = '?';
|
||||
m = ua.match(/Version\/([\d\.]+)/);
|
||||
if (m && m.length > 1) {
|
||||
if (m && m.length > 1)
|
||||
{
|
||||
v = m[1];
|
||||
}
|
||||
return clean('Safari'+v);
|
||||
return clean('Safari' + v);
|
||||
}
|
||||
|
||||
// everything else
|
||||
|
@ -83,41 +99,49 @@ var padutils = {
|
|||
// "func" is a function over 0..(numItems-1) that is monotonically
|
||||
// "increasing" with index (false, then true). Finds the boundary
|
||||
// between false and true, a number between 0 and numItems inclusive.
|
||||
binarySearch: function (numItems, func) {
|
||||
binarySearch: function(numItems, func)
|
||||
{
|
||||
if (numItems < 1) return 0;
|
||||
if (func(0)) return 0;
|
||||
if (! func(numItems-1)) return numItems;
|
||||
if (!func(numItems - 1)) return numItems;
|
||||
var low = 0; // func(low) is always false
|
||||
var high = numItems-1; // func(high) is always true
|
||||
while ((high - low) > 1) {
|
||||
var x = Math.floor((low+high)/2); // x != low, x != high
|
||||
var high = numItems - 1; // func(high) is always true
|
||||
while ((high - low) > 1)
|
||||
{
|
||||
var x = Math.floor((low + high) / 2); // x != low, x != high
|
||||
if (func(x)) high = x;
|
||||
else low = x;
|
||||
}
|
||||
return high;
|
||||
},
|
||||
// e.g. "Thu Jun 18 2009 13:09"
|
||||
simpleDateTime: function(date) {
|
||||
simpleDateTime: function(date)
|
||||
{
|
||||
var d = new Date(+date); // accept either number or date
|
||||
var dayOfWeek = (['Sun','Mon','Tue','Wed','Thu','Fri','Sat'])[d.getDay()];
|
||||
var month = (['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'])[d.getMonth()];
|
||||
var dayOfWeek = (['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])[d.getDay()];
|
||||
var month = (['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])[d.getMonth()];
|
||||
var dayOfMonth = d.getDate();
|
||||
var year = d.getFullYear();
|
||||
var hourmin = d.getHours()+":"+("0"+d.getMinutes()).slice(-2);
|
||||
return dayOfWeek+' '+month+' '+dayOfMonth+' '+year+' '+hourmin;
|
||||
var hourmin = d.getHours() + ":" + ("0" + d.getMinutes()).slice(-2);
|
||||
return dayOfWeek + ' ' + month + ' ' + dayOfMonth + ' ' + year + ' ' + hourmin;
|
||||
},
|
||||
findURLs: function(text) {
|
||||
findURLs: function(text)
|
||||
{
|
||||
// copied from ACE
|
||||
var _REGEX_WORDCHAR = /[\u0030-\u0039\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u1FFF\u3040-\u9FFF\uF900-\uFDFF\uFE70-\uFEFE\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFDC]/;
|
||||
var _REGEX_URLCHAR = new RegExp('('+/[-:@a-zA-Z0-9_.,~%+\/?=&#;()$]/.source+'|'+_REGEX_WORDCHAR.source+')');
|
||||
var _REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:)/.source+_REGEX_URLCHAR.source+'*(?![:.,;])'+_REGEX_URLCHAR.source, 'g');
|
||||
var _REGEX_URLCHAR = new RegExp('(' + /[-:@a-zA-Z0-9_.,~%+\/?=&#;()$]/.source + '|' + _REGEX_WORDCHAR.source + ')');
|
||||
var _REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:)/.source + _REGEX_URLCHAR.source + '*(?![:.,;])' + _REGEX_URLCHAR.source, 'g');
|
||||
|
||||
// returns null if no URLs, or [[startIndex1, url1], [startIndex2, url2], ...]
|
||||
function _findURLs(text) {
|
||||
|
||||
|
||||
function _findURLs(text)
|
||||
{
|
||||
_REGEX_URL.lastIndex = 0;
|
||||
var urls = null;
|
||||
var execResult;
|
||||
while ((execResult = _REGEX_URL.exec(text))) {
|
||||
while ((execResult = _REGEX_URL.exec(text)))
|
||||
{
|
||||
urls = (urls || []);
|
||||
var startIndex = execResult.index;
|
||||
var url = execResult[0];
|
||||
|
@ -129,23 +153,28 @@ var padutils = {
|
|||
|
||||
return _findURLs(text);
|
||||
},
|
||||
escapeHtmlWithClickableLinks: function(text, target) {
|
||||
escapeHtmlWithClickableLinks: function(text, target)
|
||||
{
|
||||
var idx = 0;
|
||||
var pieces = [];
|
||||
var urls = padutils.findURLs(text);
|
||||
function advanceTo(i) {
|
||||
if (i > idx) {
|
||||
|
||||
function advanceTo(i)
|
||||
{
|
||||
if (i > idx)
|
||||
{
|
||||
pieces.push(padutils.escapeHtml(text.substring(idx, i)));
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
if (urls) {
|
||||
for(var j=0;j<urls.length;j++) {
|
||||
if (urls)
|
||||
{
|
||||
for (var j = 0; j < urls.length; j++)
|
||||
{
|
||||
var startIndex = urls[j][0];
|
||||
var href = urls[j][1];
|
||||
advanceTo(startIndex);
|
||||
pieces.push('<a ', (target?'target="'+target+'" ':''),
|
||||
'href="', href.replace(/\"/g, '"'), '">');
|
||||
pieces.push('<a ', (target ? 'target="' + target + '" ' : ''), 'href="', href.replace(/\"/g, '"'), '">');
|
||||
advanceTo(startIndex + href.length);
|
||||
pieces.push('</a>');
|
||||
}
|
||||
|
@ -153,209 +182,280 @@ var padutils = {
|
|||
advanceTo(text.length);
|
||||
return pieces.join('');
|
||||
},
|
||||
bindEnterAndEscape: function(node, onEnter, onEscape) {
|
||||
bindEnterAndEscape: function(node, onEnter, onEscape)
|
||||
{
|
||||
|
||||
// Use keypress instead of keyup in bindEnterAndEscape
|
||||
// Keyup event is fired on enter in IME (Input Method Editor), But
|
||||
// keypress is not. So, I changed to use keypress instead of keyup.
|
||||
// It is work on Windows (IE8, Chrome 6.0.472), CentOs (Firefox 3.0) and Mac OSX (Firefox 3.6.10, Chrome 6.0.472, Safari 5.0).
|
||||
|
||||
if (onEnter) {
|
||||
node.keypress( function(evt) {
|
||||
if (evt.which == 13) {
|
||||
if (onEnter)
|
||||
{
|
||||
node.keypress(function(evt)
|
||||
{
|
||||
if (evt.which == 13)
|
||||
{
|
||||
onEnter(evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (onEscape) {
|
||||
node.keydown( function(evt) {
|
||||
if (evt.which == 27) {
|
||||
if (onEscape)
|
||||
{
|
||||
node.keydown(function(evt)
|
||||
{
|
||||
if (evt.which == 27)
|
||||
{
|
||||
onEscape(evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
timediff: function(d) {
|
||||
function format(n, word) {
|
||||
timediff: function(d)
|
||||
{
|
||||
function format(n, word)
|
||||
{
|
||||
n = Math.round(n);
|
||||
return ('' + n + ' ' + word + (n != 1 ? 's' : '') + ' ago');
|
||||
}
|
||||
d = Math.max(0, (+(new Date) - (+d) - pad.clientTimeOffset) / 1000);
|
||||
if (d < 60) { return format(d, 'second'); }
|
||||
if (d < 60)
|
||||
{
|
||||
return format(d, 'second');
|
||||
}
|
||||
d /= 60;
|
||||
if (d < 60) { return format(d, 'minute'); }
|
||||
if (d < 60)
|
||||
{
|
||||
return format(d, 'minute');
|
||||
}
|
||||
d /= 60;
|
||||
if (d < 24) { return format(d, 'hour'); }
|
||||
if (d < 24)
|
||||
{
|
||||
return format(d, 'hour');
|
||||
}
|
||||
d /= 24;
|
||||
return format(d, 'day');
|
||||
},
|
||||
makeAnimationScheduler: function(funcToAnimateOneStep, stepTime, stepsAtOnce) {
|
||||
if (stepsAtOnce === undefined) {
|
||||
makeAnimationScheduler: function(funcToAnimateOneStep, stepTime, stepsAtOnce)
|
||||
{
|
||||
if (stepsAtOnce === undefined)
|
||||
{
|
||||
stepsAtOnce = 1;
|
||||
}
|
||||
|
||||
var animationTimer = null;
|
||||
|
||||
function scheduleAnimation() {
|
||||
if (! animationTimer) {
|
||||
animationTimer = window.setTimeout(function() {
|
||||
function scheduleAnimation()
|
||||
{
|
||||
if (!animationTimer)
|
||||
{
|
||||
animationTimer = window.setTimeout(function()
|
||||
{
|
||||
animationTimer = null;
|
||||
var n = stepsAtOnce;
|
||||
var moreToDo = true;
|
||||
while (moreToDo && n > 0) {
|
||||
while (moreToDo && n > 0)
|
||||
{
|
||||
moreToDo = funcToAnimateOneStep();
|
||||
n--;
|
||||
}
|
||||
if (moreToDo) {
|
||||
if (moreToDo)
|
||||
{
|
||||
// more to do
|
||||
scheduleAnimation();
|
||||
}
|
||||
}, stepTime*stepsAtOnce);
|
||||
}, stepTime * stepsAtOnce);
|
||||
}
|
||||
}
|
||||
return { scheduleAnimation: scheduleAnimation };
|
||||
return {
|
||||
scheduleAnimation: scheduleAnimation
|
||||
};
|
||||
},
|
||||
makeShowHideAnimator: function(funcToArriveAtState, initiallyShown, fps, totalMs) {
|
||||
makeShowHideAnimator: function(funcToArriveAtState, initiallyShown, fps, totalMs)
|
||||
{
|
||||
var animationState = (initiallyShown ? 0 : -2); // -2 hidden, -1 to 0 fade in, 0 to 1 fade out
|
||||
var animationFrameDelay = 1000 / fps;
|
||||
var animationStep = animationFrameDelay / totalMs;
|
||||
|
||||
var scheduleAnimation =
|
||||
padutils.makeAnimationScheduler(animateOneStep, animationFrameDelay).scheduleAnimation;
|
||||
var scheduleAnimation = padutils.makeAnimationScheduler(animateOneStep, animationFrameDelay).scheduleAnimation;
|
||||
|
||||
function doShow() {
|
||||
function doShow()
|
||||
{
|
||||
animationState = -1;
|
||||
funcToArriveAtState(animationState);
|
||||
scheduleAnimation();
|
||||
}
|
||||
|
||||
function doQuickShow() { // start showing without losing any fade-in progress
|
||||
if (animationState < -1) {
|
||||
function doQuickShow()
|
||||
{ // start showing without losing any fade-in progress
|
||||
if (animationState < -1)
|
||||
{
|
||||
animationState = -1;
|
||||
}
|
||||
else if (animationState <= 0) {
|
||||
else if (animationState <= 0)
|
||||
{
|
||||
animationState = animationState;
|
||||
}
|
||||
else {
|
||||
animationState = Math.max(-1, Math.min(0, - animationState));
|
||||
else
|
||||
{
|
||||
animationState = Math.max(-1, Math.min(0, -animationState));
|
||||
}
|
||||
funcToArriveAtState(animationState);
|
||||
scheduleAnimation();
|
||||
}
|
||||
|
||||
function doHide() {
|
||||
if (animationState >= -1 && animationState <= 0) {
|
||||
function doHide()
|
||||
{
|
||||
if (animationState >= -1 && animationState <= 0)
|
||||
{
|
||||
animationState = 1e-6;
|
||||
scheduleAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
function animateOneStep() {
|
||||
if (animationState < -1 || animationState == 0) {
|
||||
function animateOneStep()
|
||||
{
|
||||
if (animationState < -1 || animationState == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (animationState < 0) {
|
||||
else if (animationState < 0)
|
||||
{
|
||||
// animate show
|
||||
animationState += animationStep;
|
||||
if (animationState >= 0) {
|
||||
if (animationState >= 0)
|
||||
{
|
||||
animationState = 0;
|
||||
funcToArriveAtState(animationState);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
funcToArriveAtState(animationState);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (animationState > 0) {
|
||||
else if (animationState > 0)
|
||||
{
|
||||
// animate hide
|
||||
animationState += animationStep;
|
||||
if (animationState >= 1) {
|
||||
if (animationState >= 1)
|
||||
{
|
||||
animationState = 1;
|
||||
funcToArriveAtState(animationState);
|
||||
animationState = -2;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
funcToArriveAtState(animationState);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {show: doShow, hide: doHide, quickShow: doQuickShow};
|
||||
return {
|
||||
show: doShow,
|
||||
hide: doHide,
|
||||
quickShow: doQuickShow
|
||||
};
|
||||
},
|
||||
_nextActionId: 1,
|
||||
uncanceledActions: {},
|
||||
getCancellableAction: function(actionType, actionFunc) {
|
||||
getCancellableAction: function(actionType, actionFunc)
|
||||
{
|
||||
var o = padutils.uncanceledActions[actionType];
|
||||
if (! o) {
|
||||
if (!o)
|
||||
{
|
||||
o = {};
|
||||
padutils.uncanceledActions[actionType] = o;
|
||||
}
|
||||
var actionId = (padutils._nextActionId++);
|
||||
o[actionId] = true;
|
||||
return function() {
|
||||
return function()
|
||||
{
|
||||
var p = padutils.uncanceledActions[actionType];
|
||||
if (p && p[actionId]) {
|
||||
if (p && p[actionId])
|
||||
{
|
||||
actionFunc();
|
||||
}
|
||||
};
|
||||
},
|
||||
cancelActions: function(actionType) {
|
||||
cancelActions: function(actionType)
|
||||
{
|
||||
var o = padutils.uncanceledActions[actionType];
|
||||
if (o) {
|
||||
if (o)
|
||||
{
|
||||
// clear it
|
||||
delete padutils.uncanceledActions[actionType];
|
||||
}
|
||||
},
|
||||
makeFieldLabeledWhenEmpty: function(field, labelText) {
|
||||
makeFieldLabeledWhenEmpty: function(field, labelText)
|
||||
{
|
||||
field = $(field);
|
||||
function clear() {
|
||||
|
||||
function clear()
|
||||
{
|
||||
field.addClass('editempty');
|
||||
field.val(labelText);
|
||||
}
|
||||
field.focus(function() {
|
||||
if (field.hasClass('editempty')) {
|
||||
field.focus(function()
|
||||
{
|
||||
if (field.hasClass('editempty'))
|
||||
{
|
||||
field.val('');
|
||||
}
|
||||
field.removeClass('editempty');
|
||||
});
|
||||
field.blur(function() {
|
||||
if (! field.val()) {
|
||||
field.blur(function()
|
||||
{
|
||||
if (!field.val())
|
||||
{
|
||||
clear();
|
||||
}
|
||||
});
|
||||
return {clear:clear};
|
||||
return {
|
||||
clear: clear
|
||||
};
|
||||
},
|
||||
getCheckbox: function(node) {
|
||||
getCheckbox: function(node)
|
||||
{
|
||||
return $(node).is(':checked');
|
||||
},
|
||||
setCheckbox: function(node, value) {
|
||||
if (value) {
|
||||
setCheckbox: function(node, value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
$(node).attr('checked', 'checked');
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
$(node).removeAttr('checked');
|
||||
}
|
||||
},
|
||||
bindCheckboxChange: function(node, func) {
|
||||
bindCheckboxChange: function(node, func)
|
||||
{
|
||||
$(node).bind("click change", func);
|
||||
},
|
||||
encodeUserId: function(userId) {
|
||||
return userId.replace(/[^a-y0-9]/g, function(c) {
|
||||
encodeUserId: function(userId)
|
||||
{
|
||||
return userId.replace(/[^a-y0-9]/g, function(c)
|
||||
{
|
||||
if (c == ".") return "-";
|
||||
return 'z'+c.charCodeAt(0)+'z';
|
||||
return 'z' + c.charCodeAt(0) + 'z';
|
||||
});
|
||||
},
|
||||
decodeUserId: function(encodedUserId) {
|
||||
return encodedUserId.replace(/[a-y0-9]+|-|z.+?z/g, function(cc) {
|
||||
decodeUserId: function(encodedUserId)
|
||||
{
|
||||
return encodedUserId.replace(/[a-y0-9]+|-|z.+?z/g, function(cc)
|
||||
{
|
||||
if (cc == '-') return '.';
|
||||
else if (cc.charAt(0) == 'z') {
|
||||
return String.fromCharCode(Number(cc.slice(1,-1)));
|
||||
else if (cc.charAt(0) == 'z')
|
||||
{
|
||||
return String.fromCharCode(Number(cc.slice(1, -1)));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return cc;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue