merge develop

This commit is contained in:
John McLear 2013-03-20 01:11:27 +00:00
commit 4ea7ccd104
60 changed files with 6957 additions and 232 deletions

View file

@ -5125,7 +5125,7 @@ function Ace2Inner(){
function initLineNumbers()
{
lineNumbersShown = 1;
sideDiv.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" align="right">' + '<tr><td id="sidedivinner"><div>1</div></td></tr></table>';
sideDiv.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" align="right"><tr><td id="sidedivinner"><div>1</div></td></tr></table>';
sideDivInner = outerWin.document.getElementById("sidedivinner");
}

View file

@ -17,6 +17,7 @@
var padutils = require('./pad_utils').padutils;
var padcookie = require('./pad_cookie').padcookie;
var Tinycon = require('tinycon/tinycon');
var hooks = require('./pluginfw/hooks');
var chat = (function()
{
@ -77,7 +78,7 @@ var chat = (function()
$("#chatinput").val("");
},
addMessage: function(msg, increment, isHistoryAdd)
{
{
//correct the time
msg.time += this._pad.clientTimeOffset;
@ -99,73 +100,68 @@ var chat = (function()
var text = padutils.escapeHtmlWithClickableLinks(msg.text, "_blank");
/* Performs an action if your name is mentioned */
var myName = $('#myusernameedit').val();
myName = myName.toLowerCase();
var chatText = text.toLowerCase();
var wasMentioned = false;
if (chatText.indexOf(myName) !== -1 && myName != "undefined"){
wasMentioned = true;
var authorName = msg.userName == null ? _('pad.userlist.unnamed') : padutils.escapeHtml(msg.userName);
// the hook args
var ctx = {
"authorName" : authorName,
"author" : msg.userId,
"text" : text,
"sticky" : false,
"timestamp" : msg.time,
"timeStr" : timeStr
}
/* End of new action */
var authorName = msg.userName == null ? _('pad.userlist.unnamed') : padutils.escapeHtml(msg.userName);
var html = "<p data-authorId='" + msg.userId + "' class='" + authorClass + "'><b>" + authorName + ":</b><span class='time " + authorClass + "'>" + timeStr + "</span> " + text + "</p>";
if(isHistoryAdd)
$(html).insertAfter('#chatloadmessagesbutton');
else
$("#chattext").append(html);
//should we increment the counter??
if(increment && !isHistoryAdd)
{
var count = Number($("#chatcounter").text());
count++;
// is the users focus already in the chatbox?
var alreadyFocused = $("#chatinput").is(":focus");
// does the user already have the chatbox open?
var chatOpen = $("#chatbox").is(":visible");
// is the users focus already in the chatbox?
var alreadyFocused = $("#chatinput").is(":focus");
$("#chatcounter").text(count);
// chat throb stuff -- Just make it throw for twice as long
if(wasMentioned && !alreadyFocused && !isHistoryAdd && !chatOpen)
{ // If the user was mentioned show for twice as long and flash the browser window
$.gritter.add({
// (string | mandatory) the heading of the notification
title: authorName,
// (string | mandatory) the text inside the notification
text: text,
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true,
// (int | optional) the time you want it to be alive for before fading out
time: '2000'
});
// does the user already have the chatbox open?
var chatOpen = $("#chatbox").is(":visible");
chatMentions++;
Tinycon.setBubble(chatMentions);
}
// does this message contain this user's name? (is the curretn user mentioned?)
var myName = $('#myusernameedit').val();
var wasMentioned = (text.toLowerCase().indexOf(myName.toLowerCase()) !== -1 && myName != "undefined");
if(wasMentioned && !alreadyFocused && !isHistoryAdd && !chatOpen)
{ // If the user was mentioned show for twice as long and flash the browser window
chatMentions++;
Tinycon.setBubble(chatMentions);
ctx.sticky = true;
}
// Call chat message hook
hooks.aCallAll("chatNewMessage", ctx, function() {
var html = "<p data-authorId='" + msg.userId + "' class='" + authorClass + "'><b>" + authorName + ":</b><span class='time " + authorClass + "'>" + ctx.timeStr + "</span> " + ctx.text + "</p>";
if(isHistoryAdd)
$(html).insertAfter('#chatloadmessagesbutton');
else
$("#chattext").append(html);
//should we increment the counter??
if(increment && !isHistoryAdd)
{
if(!chatOpen){
// Update the counter of unread messages
var count = Number($("#chatcounter").text());
count++;
$("#chatcounter").text(count);
if(!chatOpen) {
$.gritter.add({
// (string | mandatory) the heading of the notification
title: authorName,
title: ctx.authorName,
// (string | mandatory) the text inside the notification
text: text,
text: ctx.text,
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: false,
sticky: ctx.sticky,
// (int | optional) the time you want it to be alive for before fading out
time: '4000'
});
Tinycon.setBubble(count);
}
}
}
// Clear the chat mentions when the user clicks on the chat input box
});
// Clear the chat mentions when the user clicks on the chat input box
$('#chatinput').click(function(){
chatMentions = 0;
Tinycon.setBubble(0);

View file

@ -23,27 +23,27 @@
window.html10n = (function(window, document, undefined) {
// fix console
var console = window.console;
var console = window.console
function interceptConsole(method){
if (!console) return function() {};
if (!console) return function() {}
var original = console[method];
var original = console[method]
// do sneaky stuff
if (original.bind){
// Do this for normal browsers
return original.bind(console);
return original.bind(console)
}else{
return function() {
// Do this for IE
var message = Array.prototype.slice.apply(arguments).join(' ');
original(message);
var message = Array.prototype.slice.apply(arguments).join(' ')
original(message)
}
}
}
var consoleLog = interceptConsole('log')
, consoleWarn = interceptConsole('warn')
, consoleError = interceptConsole('warn');
, consoleError = interceptConsole('warn')
// fix Array.prototype.instanceOf in, guess what, IE! <3
@ -84,14 +84,14 @@ window.html10n = (function(window, document, undefined) {
* MicroEvent - to make any js object an event emitter (server or browser)
*/
var MicroEvent = function(){}
var MicroEvent = function(){}
MicroEvent.prototype = {
bind : function(event, fct){
bind : function(event, fct){
this._events = this._events || {};
this._events[event] = this._events[event] || [];
this._events[event].push(fct);
},
unbind : function(event, fct){
unbind : function(event, fct){
this._events = this._events || {};
if( event in this._events === false ) return;
this._events[event].splice(this._events[event].indexOf(fct), 1);
@ -100,7 +100,7 @@ window.html10n = (function(window, document, undefined) {
this._events = this._events || {};
if( event in this._events === false ) return;
for(var i = 0; i < this._events[event].length; i++){
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1))
}
}
};
@ -122,50 +122,50 @@ window.html10n = (function(window, document, undefined) {
* and caching all necessary resources
*/
function Loader(resources) {
this.resources = resources;
this.cache = {}; // file => contents
this.langs = {}; // lang => strings
this.resources = resources
this.cache = {} // file => contents
this.langs = {} // lang => strings
}
Loader.prototype.load = function(lang, cb) {
if(this.langs[lang]) return cb();
if(this.langs[lang]) return cb()
if (this.resources.length > 0) {
var reqs = 0;
for (var i=0, n=this.resources.length; i < n; i++) {
this.fetch(this.resources[i], lang, function(e) {
reqs++;
if(e) return setTimeout(function(){ throw e }, 0);
if(e) console.warn(e)
if (reqs < n) return;// Call back once all reqs are completed
cb && cb();
cb && cb()
})
}
}
}
Loader.prototype.fetch = function(href, lang, cb) {
var that = this;
var that = this
if (this.cache[href]) {
this.parse(lang, href, this.cache[href], cb)
return;
}
var xhr = new XMLHttpRequest();
xhr.open('GET', href, /*async: */true);
var xhr = new XMLHttpRequest()
xhr.open('GET', href, /*async: */true)
if (xhr.overrideMimeType) {
xhr.overrideMimeType('application/json; charset=utf-8');
}
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status === 0) {
var data = JSON.parse(xhr.responseText);
that.cache[href] = data;
var data = JSON.parse(xhr.responseText)
that.cache[href] = data
// Pass on the contents for parsing
that.parse(lang, href, data, cb);
that.parse(lang, href, data, cb)
} else {
cb(new Error('Failed to load '+href));
cb(new Error('Failed to load '+href))
}
}
};
@ -174,39 +174,39 @@ window.html10n = (function(window, document, undefined) {
Loader.prototype.parse = function(lang, currHref, data, cb) {
if ('object' != typeof data) {
cb(new Error('A file couldn\'t be parsed as json.'));
return;
cb(new Error('A file couldn\'t be parsed as json.'))
return
}
if (!data[lang]) lang = lang.substr(0, lang.indexOf('-') == -1? lang.length : lang.indexOf('-'));
if (!data[lang]) lang = lang.substr(0, lang.indexOf('-') == -1? lang.length : lang.indexOf('-'))
if (!data[lang]) {
cb(new Error('Couldn\'t find translations for '+lang));
return;
cb(new Error('Couldn\'t find translations for '+lang))
return
}
if ('string' == typeof data[lang]) {
// Import rule
// absolute path
var importUrl = data[lang];
var importUrl = data[lang]
// relative path
if(data[lang].indexOf("http") != 0 && data[lang].indexOf("/") != 0) {
importUrl = currHref+"/../"+data[lang];
importUrl = currHref+"/../"+data[lang]
}
this.fetch(importUrl, lang, cb);
return;
this.fetch(importUrl, lang, cb)
return
}
if ('object' != typeof data[lang]) {
cb(new Error('Translations should be specified as JSON objects!'));
return;
cb(new Error('Translations should be specified as JSON objects!'))
return
}
this.langs[lang] = data[lang];
this.langs[lang] = data[lang]
// TODO: Also store accompanying langs
cb();
cb()
}
@ -216,11 +216,11 @@ window.html10n = (function(window, document, undefined) {
var html10n =
{ language : null
}
MicroEvent.mixin(html10n);
MicroEvent.mixin(html10n)
html10n.macros = {};
html10n.macros = {}
html10n.rtl = ["ar","dv","fa","ha","he","ks","ku","ps","ur","yi"];
html10n.rtl = ["ar","dv","fa","ha","he","ks","ku","ps","ur","yi"]
/**
* Get rules for plural forms (shared with JetPack), see:
@ -664,14 +664,14 @@ window.html10n = (function(window, document, undefined) {
* @param langs An array of lang codes defining fallbacks
*/
html10n.localize = function(langs) {
var that = this;
var that = this
// if only one string => create an array
if ('string' == typeof langs) langs = [langs];
if ('string' == typeof langs) langs = [langs]
this.build(langs, function(er, translations) {
html10n.translations = translations;
html10n.translateElement(translations);
that.trigger('localized');
html10n.translations = translations
html10n.translateElement(translations)
that.trigger('localized')
})
}
@ -682,78 +682,78 @@ window.html10n = (function(window, document, undefined) {
* @param element A DOM element, if omitted, the document element will be used
*/
html10n.translateElement = function(translations, element) {
element = element || document.documentElement;
element = element || document.documentElement
var children = element? getTranslatableChildren(element) : document.childNodes;
for (var i=0, n=children.length; i < n; i++) {
this.translateNode(translations, children[i]);
this.translateNode(translations, children[i])
}
// translate element itself if necessary
this.translateNode(translations, element);
this.translateNode(translations, element)
}
function asyncForEach(list, iterator, cb) {
var i = 0
, n = list.length;
, n = list.length
iterator(list[i], i, function each(err) {
if(err) consoleLog(err);
i++;
if(err) consoleLog(err)
i++
if (i < n) return iterator(list[i],i, each);
cb();
cb()
})
}
function getTranslatableChildren(element) {
if(!document.querySelectorAll) {
if (!element) return [];
if (!element) return []
var nodes = element.getElementsByTagName('*')
, l10nElements = [];
, l10nElements = []
for (var i=0, n=nodes.length; i < n; i++) {
if (nodes[i].getAttribute('data-l10n-id'))
l10nElements.push(nodes[i]);
}
return l10nElements;
return l10nElements
}
return element.querySelectorAll('*[data-l10n-id]');
return element.querySelectorAll('*[data-l10n-id]')
}
html10n.get = function(id, args) {
var translations = html10n.translations;
if(!translations) return consoleWarn('No translations available (yet)');
if(!translations[id]) return consoleWarn('Could not find string '+id);
var translations = html10n.translations
if(!translations) return consoleWarn('No translations available (yet)')
if(!translations[id]) return consoleWarn('Could not find string '+id)
// apply args
var str = substArguments(translations[id], args);
var str = substArguments(translations[id], args)
// apply macros
return substMacros(id, str, args);
return substMacros(id, str, args)
// replace {{arguments}} with their values or the
// associated translation string (based on its key)
function substArguments(str, args) {
var reArgs = /\{\{\s*([a-zA-Z\.]+)\s*\}\}/
, match;
, match
while (match = reArgs.exec(str)) {
if (!match || match.length < 2)
return str; // argument key not found
return str // argument key not found
var arg = match[1]
, sub = '';
, sub = ''
if (arg in args) {
sub = args[arg];
sub = args[arg]
} else if (arg in translations) {
sub = translations[arg];
sub = translations[arg]
} else {
consoleWarn('Could not find argument {{' + arg + '}}');
return str;
consoleWarn('Could not find argument {{' + arg + '}}')
return str
}
str = str.substring(0, match.index) + sub + str.substr(match.index + match[0].length);
str = str.substring(0, match.index) + sub + str.substr(match.index + match[0].length)
}
return str;
return str
}
// replace {[macros]} with their values
@ -766,21 +766,21 @@ window.html10n = (function(window, document, undefined) {
// a macro has been found
// Note: at the moment, only one parameter is supported
var macroName = reMatch[1]
, paramName = reMatch[2];
, paramName = reMatch[2]
if (!(macroName in gMacros)) return str;
if (!(macroName in gMacros)) return str
var param;
var param
if (args && paramName in args) {
param = args[paramName];
param = args[paramName]
} else if (paramName in translations) {
param = translations[paramName];
param = translations[paramName]
}
// there's no macro parser yet: it has to be defined in gMacros
var macro = html10n.macros[macroName];
str = macro(translations, key, str, param);
return str;
var macro = html10n.macros[macroName]
str = macro(translations, key, str, param)
return str
}
}
@ -788,26 +788,26 @@ window.html10n = (function(window, document, undefined) {
* Applies translations to a DOM node (recursive)
*/
html10n.translateNode = function(translations, node) {
var str = {};
var str = {}
// get id
str.id = node.getAttribute('data-l10n-id');
if (!str.id) return;
str.id = node.getAttribute('data-l10n-id')
if (!str.id) return
if(!translations[str.id]) return consoleWarn('Couldn\'t find translation key '+str.id);
if(!translations[str.id]) return consoleWarn('Couldn\'t find translation key '+str.id)
// get args
if(window.JSON) {
str.args = JSON.parse(node.getAttribute('data-l10n-args'));
str.args = JSON.parse(node.getAttribute('data-l10n-args'))
}else{
try{
str.args = eval(node.getAttribute('data-l10n-args'));
str.args = eval(node.getAttribute('data-l10n-args'))
}catch(e) {
consoleWarn('Couldn\'t parse args for '+str.id);
consoleWarn('Couldn\'t parse args for '+str.id)
}
}
str.str = html10n.get(str.id, str.args);
str.str = html10n.get(str.id, str.args)
// get attribute name to apply str to
var prop
@ -817,31 +817,31 @@ window.html10n = (function(window, document, undefined) {
, "innerHTML": 1
, "alt": 1
, "textContent": 1
};
}
if (index > 0 && str.id.substr(index + 1) in attrList) { // an attribute has been specified
prop = str.id.substr(index + 1);
prop = str.id.substr(index + 1)
} else { // no attribute: assuming text content by default
prop = document.body.textContent ? 'textContent' : 'innerText';
prop = document.body.textContent ? 'textContent' : 'innerText'
}
// Apply translation
if (node.children.length === 0 || prop != 'textContent') {
node[prop] = str.str;
node[prop] = str.str
} else {
var children = node.childNodes,
found = false;
found = false
for (var i=0, n=children.length; i < n; i++) {
if (children[i].nodeType === 3 && /\S/.test(children[i].textContent)) {
if (!found) {
children[i].nodeValue = str.str;
found = true;
children[i].nodeValue = str.str
found = true
} else {
children[i].nodeValue = '';
children[i].nodeValue = ''
}
}
}
if (!found) {
consoleWarn('Unexpected error: could not translate element content for key '+str.id, node);
consoleWarn('Unexpected error: could not translate element content for key '+str.id, node)
}
}
}
@ -852,32 +852,32 @@ window.html10n = (function(window, document, undefined) {
*/
html10n.build = function(langs, cb) {
var that = this
, build = {};
, build = {}
asyncForEach(langs, function (lang, i, next) {
if(!lang) return next();
that.loader.load(lang, next);
that.loader.load(lang, next)
}, function() {
var lang;
langs.reverse();
var lang
langs.reverse()
// loop through priority array...
for (var i=0, n=langs.length; i < n; i++) {
lang = langs[i];
lang = langs[i]
if(!lang || !(lang in that.loader.langs)) continue;
// ... and apply all strings of the current lang in the list
// to our build object
for (var string in that.loader.langs[lang]) {
build[string] = that.loader.langs[lang][string];
build[string] = that.loader.langs[lang][string]
}
// the last applied lang will be exposed as the
// lang the page was translated to
that.language = lang;
that.language = lang
}
cb(null, build);
cb(null, build)
})
}
@ -893,8 +893,8 @@ window.html10n = (function(window, document, undefined) {
* Returns the direction of the language returned be html10n#getLanguage
*/
html10n.getDirection = function() {
var langCode = this.language.indexOf('-') == -1? this.language : this.language.substr(0, this.language.indexOf('-'));
return html10n.rtl.indexOf(langCode) == -1? 'ltr' : 'rtl';
var langCode = this.language.indexOf('-') == -1? this.language : this.language.substr(0, this.language.indexOf('-'))
return html10n.rtl.indexOf(langCode) == -1? 'ltr' : 'rtl'
}
/**
@ -903,28 +903,28 @@ window.html10n = (function(window, document, undefined) {
html10n.index = function () {
// Find all <link>s
var links = document.getElementsByTagName('link')
, resources = [];
, resources = []
for (var i=0, n=links.length; i < n; i++) {
if (links[i].type != 'application/l10n+json')
continue;
resources.push(links[i].href);
resources.push(links[i].href)
}
this.loader = new Loader(resources);
this.trigger('indexed');
this.loader = new Loader(resources)
this.trigger('indexed')
}
if (document.addEventListener) // modern browsers and IE9+
document.addEventListener('DOMContentLoaded', function() {
html10n.index();
}, false);
html10n.index()
}, false)
else if (window.attachEvent)
window.attachEvent('onload', function() {
html10n.index();
}, false);
html10n.index()
}, false)
// gettext-like shortcut
if (window._ === undefined)
window._ = html10n.get;
return html10n;
})(window, document);
return html10n
})(window, document)

View file

@ -469,14 +469,6 @@ var pad = {
userAgent: pad.getDisplayUserAgent()
};
if (clientVars.specialKey)
{
pad.myUserInfo.specialKey = clientVars.specialKey;
if (clientVars.specialKeyTranslation)
{
$("#specialkeyarea").html("mode: " + String(clientVars.specialKeyTranslation).toUpperCase());
}
}
padimpexp.init(this);
padsavedrevs.init(this);
@ -662,8 +654,8 @@ var pad = {
{
alertBar.displayMessage(function(abar)
{
abar.find("#servermsgdate").html(" (" + padutils.simpleDateTime(new Date) + ")");
abar.find("#servermsgtext").html(m.text);
abar.find("#servermsgdate").text(" (" + padutils.simpleDateTime(new Date) + ")");
abar.find("#servermsgtext").text(m.text);
});
}
if (m.js)

View file

@ -76,7 +76,6 @@ var padconnectionstatus = (function()
},
isFullyConnected: function()
{
padmodals.hideOverlay();
return status.what == 'connected';
},
getStatus: function()

View file

@ -40,22 +40,10 @@ var padmodals = (function()
});
},
showOverlay: function(duration) {
$("#overlay").show().css(
{
'opacity': 0
}).animate(
{
'opacity': 1
}, duration);
$("#overlay").show();
},
hideOverlay: function(duration) {
$("#overlay").animate(
{
'opacity': 0
}, duration, function()
{
$("#modaloverlay").hide();
});
$("#overlay").hide();
}
};
return self;

View file

@ -116,7 +116,7 @@ var paduserlist = (function()
nameHtml = '<input data-l10n-id="pad.userlist.unnamed" type="text" class="editempty newinput" value="'+_('pad.userlist.unnamed')+'" ' + (isNameEditable(data) ? '' : 'disabled="disabled" ') + '/>';
}
return ['<td style="height:', height, 'px" class="usertdswatch"><div class="swatch" style="background:' + data.color + '">&nbsp;</div></td>', '<td style="height:', height, 'px" class="usertdname">', nameHtml, '</td>', '<td style="height:', height, 'px" class="activity">', padutils.escapeHtml(data.activity), '</td>'].join('');
return ['<td style="height:', height, 'px" class="usertdswatch"><div class="swatch" style="background:' + padutils.escapeHtml(data.color) + '">&nbsp;</div></td>', '<td style="height:', height, 'px" class="usertdname">', nameHtml, '</td>', '<td style="height:', height, 'px" class="activity">', padutils.escapeHtml(data.activity), '</td>'].join('');
}
function getRowHtml(id, innerHtml, authorId)