Fixed regression from util.js updates + syntax cleanup
We introduced a regression in 6fa9062d28713e81d508854fa232ce65a8a59319 based on syntax error, as a curly brace ({) was lost. This is now fixed.
This commit is contained in:
parent
a56ad2c43d
commit
a4d04d24de
147
js/util.js
147
js/util.js
@ -78,11 +78,10 @@ var SN = { // StatusNet
|
||||
* @return matching localized message string
|
||||
*/
|
||||
msg: function (key) {
|
||||
if (typeof SN.messages[key] == "undefined") {
|
||||
if (SN.messages[key] === undefined) {
|
||||
return '[' + key + ']';
|
||||
} else {
|
||||
return SN.messages[key];
|
||||
}
|
||||
return SN.messages[key];
|
||||
},
|
||||
|
||||
U: { // Utils
|
||||
@ -96,15 +95,15 @@ var SN = { // StatusNet
|
||||
*/
|
||||
FormNoticeEnhancements: function (form) {
|
||||
if (jQuery.data(form[0], 'ElementData') === undefined) {
|
||||
MaxLength = form.find('.count').text();
|
||||
if (typeof(MaxLength) == 'undefined') {
|
||||
var MaxLength = form.find('.count').text();
|
||||
if (MaxLength === undefined) {
|
||||
MaxLength = SN.C.I.MaxLength;
|
||||
}
|
||||
jQuery.data(form[0], 'ElementData', {MaxLength: MaxLength});
|
||||
|
||||
SN.U.Counter(form);
|
||||
|
||||
NDT = form.find('.notice_data-text:first');
|
||||
var NDT = form.find('.notice_data-text:first');
|
||||
|
||||
NDT.on('keyup', function (e) {
|
||||
SN.U.Counter(form);
|
||||
@ -122,8 +121,7 @@ var SN = { // StatusNet
|
||||
// Note there's still no event for mouse-triggered 'delete'.
|
||||
NDT.on('cut', delayedUpdate)
|
||||
.on('paste', delayedUpdate);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
form.find('.count').text(jQuery.data(form[0], 'ElementData').MaxLength);
|
||||
}
|
||||
},
|
||||
@ -213,11 +211,10 @@ var SN = { // StatusNet
|
||||
*/
|
||||
RewriteAjaxAction: function (url) {
|
||||
// Quick hack: rewrite AJAX submits to HTTPS if they'd fail otherwise.
|
||||
if (document.location.protocol == 'https:' && url.substr(0, 5) == 'http:') {
|
||||
if (document.location.protocol === 'https:' && url.substr(0, 5) === 'http:') {
|
||||
return url.replace(/^http:\/\/[^:\/]+/, 'https://' + document.location.host);
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
return url;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -261,7 +258,7 @@ var SN = { // StatusNet
|
||||
if (xhr.responseXML) {
|
||||
errorReported = $('#error', xhr.responseXML).text();
|
||||
}
|
||||
alert(errorReported || errorThrown || textStatus);
|
||||
window.alert(errorReported || errorThrown || textStatus);
|
||||
|
||||
// Restore the form to original state.
|
||||
// Hopefully. :D
|
||||
@ -272,21 +269,19 @@ var SN = { // StatusNet
|
||||
.prop(SN.C.S.Disabled, false);
|
||||
},
|
||||
success: function (data, textStatus) {
|
||||
if (typeof($('form', data)[0]) != 'undefined') {
|
||||
form_new = document._importNode($('form', data)[0], true);
|
||||
if ($('form', data)[0] !== undefined) {
|
||||
var form_new = document._importNode($('form', data)[0], true);
|
||||
form.replaceWith(form_new);
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
}
|
||||
else if (typeof($('p', data)[0]) != 'undefined') {
|
||||
} else if ($('p', data)[0] !== undefined) {
|
||||
form.replaceWith(document._importNode($('p', data)[0], true));
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
}
|
||||
else {
|
||||
alert('Unknown error.');
|
||||
} else {
|
||||
window.alert('Unknown error.');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -376,20 +371,17 @@ var SN = { // StatusNet
|
||||
if (textStatus == 'timeout') {
|
||||
// @fixme i18n
|
||||
showFeedback('error', 'Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists.');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var response = SN.U.GetResponseXML(xhr);
|
||||
if ($('.' + SN.C.S.Error, response).length > 0) {
|
||||
form.append(document._importNode($('.' + SN.C.S.Error, response)[0], true));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
|
||||
form
|
||||
.resetForm()
|
||||
.find('.attach-status').remove();
|
||||
SN.U.FormNoticeEnhancements(form);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// @fixme i18n
|
||||
showFeedback('error', '(Sorry! We had trouble sending your notice (' + xhr.status + ' ' + xhr.statusText + '). Please report the problem to the site administrator if this happens again.');
|
||||
}
|
||||
@ -401,8 +393,7 @@ var SN = { // StatusNet
|
||||
var errorResult = $('#' + SN.C.S.Error, data);
|
||||
if (errorResult.length > 0) {
|
||||
showFeedback('error', errorResult.text());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ($('body')[0].id == 'bookmarklet') {
|
||||
// @fixme self is not referenced anywhere?
|
||||
self.close();
|
||||
@ -411,8 +402,7 @@ var SN = { // StatusNet
|
||||
var commandResult = $('#' + SN.C.S.CommandResult, data);
|
||||
if (commandResult.length > 0) {
|
||||
showFeedback('success', commandResult.text());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// New notice post was successful. If on our timeline, show it!
|
||||
var notice = document._importNode($('li', data)[0], true);
|
||||
var notices = $('#notices_primary .notices:first');
|
||||
@ -425,11 +415,9 @@ var SN = { // StatusNet
|
||||
replyItem.remove();
|
||||
|
||||
var id = $(notice).attr('id');
|
||||
if ($("#"+id).length == 0) {
|
||||
if ($('#' + id).length == 0) {
|
||||
$(notice).insertBefore(placeholder);
|
||||
} else {
|
||||
// Realtime came through before us...
|
||||
}
|
||||
} // else Realtime came through before us...
|
||||
|
||||
// ...and show the placeholder form.
|
||||
placeholder.show();
|
||||
@ -444,8 +432,7 @@ var SN = { // StatusNet
|
||||
$(notice_irt).append('<ul class="notices"></ul>');
|
||||
}
|
||||
$($(notice_irt + ' .notices')[0]).append(notice);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
notices.prepend(notice);
|
||||
}
|
||||
$('#' + notice.id)
|
||||
@ -497,15 +484,14 @@ var SN = { // StatusNet
|
||||
.prop(SN.C.S.Disabled, true);
|
||||
},
|
||||
error: function (xhr, textStatus, errorThrown) {
|
||||
alert(errorThrown || textStatus);
|
||||
window.alert(errorThrown || textStatus);
|
||||
},
|
||||
success: function (data, textStatus) {
|
||||
var results_placeholder = $('#profile_search_results');
|
||||
if (typeof($('ul', data)[0]) != 'undefined') {
|
||||
if ($('ul', data)[0] !== undefined) {
|
||||
var list = document._importNode($('ul', data)[0], true);
|
||||
results_placeholder.replaceWith(list);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var _error = $('<li/>').append(document._importNode($('p', data)[0], true));
|
||||
results_placeholder.html(_error);
|
||||
}
|
||||
@ -531,11 +517,11 @@ var SN = { // StatusNet
|
||||
.prop(SN.C.S.Disabled, true);
|
||||
},
|
||||
error: function (xhr, textStatus, errorThrown) {
|
||||
alert(errorThrown || textStatus);
|
||||
window.alert(errorThrown || textStatus);
|
||||
},
|
||||
success: function (data, textStatus) {
|
||||
var results_placeholder = form.parents('.entity_tags');
|
||||
if (typeof($('.entity_tags', data)[0]) != 'undefined') {
|
||||
if ($('.entity_tags', data)[0] !== undefined) {
|
||||
var tags = document._importNode($('.entity_tags', data)[0], true);
|
||||
$(tags).find('.editable').append($('<button class="peopletags_edit_button"/>'));
|
||||
results_placeholder.replaceWith(tags);
|
||||
@ -574,8 +560,7 @@ var SN = { // StatusNet
|
||||
}
|
||||
if (cookieValue == 'disabled') {
|
||||
SN.C.I.NoticeDataGeo.NDG = form.find('[name=notice_data-geo]').prop('checked', false).prop('checked');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SN.C.I.NoticeDataGeo.NDG = form.find('[name=notice_data-geo]').prop('checked', true).prop('checked');
|
||||
}
|
||||
|
||||
@ -637,6 +622,7 @@ var SN = { // StatusNet
|
||||
NoticeInlineReplyTrigger: function (notice, initialText) {
|
||||
// Find the notice we're replying to...
|
||||
var id = $($('.notice_id', notice)[0]).text();
|
||||
var replyForm, placeholder;
|
||||
var parentNotice = notice;
|
||||
var stripForm = true; // strip a couple things out of reply forms that are inline
|
||||
|
||||
@ -645,7 +631,7 @@ var SN = { // StatusNet
|
||||
if (list.closest('.old-school').length) {
|
||||
// We're replying to an old-school conversation thread;
|
||||
// use the old-style ping into the top form.
|
||||
SN.U.switchInputFormTab("status")
|
||||
SN.U.switchInputFormTab("status");
|
||||
replyForm = $('#input_form_status').find('form');
|
||||
stripForm = false;
|
||||
} else if (list.hasClass('threaded-replies')) {
|
||||
@ -654,7 +640,7 @@ var SN = { // StatusNet
|
||||
parentNotice = list.closest('.notice');
|
||||
|
||||
// See if the form's already open...
|
||||
var replyForm = $('.notice-reply-form', list);
|
||||
replyForm = $('.notice-reply-form', list);
|
||||
} else {
|
||||
// We're replying to a parent notice; pull its threaded list
|
||||
// and we'll add on the end of it. Will add if needed.
|
||||
@ -663,14 +649,14 @@ var SN = { // StatusNet
|
||||
SN.U.NoticeInlineReplyPlaceholder(notice);
|
||||
list = $('ul.threaded-replies', notice);
|
||||
} else {
|
||||
var placeholder = $('li.notice-reply-placeholder', notice);
|
||||
placeholder = $('li.notice-reply-placeholder', notice);
|
||||
if (placeholder.length == 0) {
|
||||
SN.U.NoticeInlineReplyPlaceholder(notice);
|
||||
}
|
||||
}
|
||||
|
||||
// See if the form's already open...
|
||||
var replyForm = $('.notice-reply-form', list);
|
||||
replyForm = $('.notice-reply-form', list);
|
||||
}
|
||||
|
||||
var nextStep = function () {
|
||||
@ -693,8 +679,8 @@ var SN = { // StatusNet
|
||||
if (initialText) {
|
||||
replyto = initialText + ' ';
|
||||
}
|
||||
text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
|
||||
text.data('initialText', $.trim(initialText + ''));
|
||||
text.val(replyto + text.val().replace(new RegExp(replyto, 'i'), ''));
|
||||
text.data('initialText', $.trim(initialText));
|
||||
text.focus();
|
||||
if (text[0].setSelectionRange) {
|
||||
var len = text.val().length;
|
||||
@ -706,7 +692,7 @@ var SN = { // StatusNet
|
||||
nextStep();
|
||||
} else {
|
||||
// Hide the placeholder...
|
||||
var placeholder = list.find('li.notice-reply-placeholder').hide();
|
||||
placeholder = list.find('li.notice-reply-placeholder').hide();
|
||||
|
||||
// Create the reply form entry at the end
|
||||
var replyItem = $('li.notice-reply', list);
|
||||
@ -718,7 +704,8 @@ var SN = { // StatusNet
|
||||
replyItem.append(formEl);
|
||||
list.append(replyItem); // *after* the placeholder
|
||||
|
||||
var form = replyForm = $(formEl);
|
||||
var form = $(formEl);
|
||||
replyForm = form;
|
||||
SN.Init.NoticeFormSetup(form);
|
||||
|
||||
nextStep();
|
||||
@ -904,6 +891,7 @@ var SN = { // StatusNet
|
||||
* @param {jQuery} form
|
||||
*/
|
||||
NoticeDataAttach: function (form) {
|
||||
var i;
|
||||
var NDA = form.find('input[type=file]');
|
||||
NDA.change(function (event) {
|
||||
form.find('.attach-status').remove();
|
||||
@ -924,9 +912,9 @@ var SN = { // StatusNet
|
||||
});
|
||||
form.append(attachStatus);
|
||||
|
||||
if (typeof this.files == "object") {
|
||||
if (typeof this.files === "object") {
|
||||
// Some newer browsers will let us fetch the files for preview.
|
||||
for (var i = 0; i < this.files.length; i++) {
|
||||
for (i = 0; i < this.files.length; i++) {
|
||||
SN.U.PreviewAttach(form, this.files[i]);
|
||||
}
|
||||
}
|
||||
@ -944,9 +932,8 @@ var SN = { // StatusNet
|
||||
var max = $(form).find('input[name=MAX_FILE_SIZE]').attr('value');
|
||||
if (max) {
|
||||
return parseInt(max);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -975,7 +962,7 @@ var SN = { // StatusNet
|
||||
var preview = true;
|
||||
|
||||
var blobAsDataURL;
|
||||
if (typeof window.createObjectURL != "undefined") {
|
||||
if (window.createObjectURL !== undefined) {
|
||||
/**
|
||||
* createObjectURL lets us reference the file directly from an <img>
|
||||
* This produces a compact URL with an opaque reference to the file,
|
||||
@ -988,8 +975,8 @@ var SN = { // StatusNet
|
||||
*/
|
||||
blobAsDataURL = function (blob, callback) {
|
||||
callback(window.createObjectURL(blob));
|
||||
}
|
||||
} else if (typeof window.FileReader != "undefined") {
|
||||
};
|
||||
} else if (window.FileReader !== undefined) {
|
||||
/**
|
||||
* FileAPI's FileReader can build a data URL from a blob's contents,
|
||||
* but it must read the file and build it asynchronously. This means
|
||||
@ -1004,9 +991,9 @@ var SN = { // StatusNet
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
callback(reader.result);
|
||||
}
|
||||
};
|
||||
reader.readAsDataURL(blob);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
preview = false;
|
||||
}
|
||||
@ -1054,8 +1041,8 @@ var SN = { // StatusNet
|
||||
*/
|
||||
NoticeLocationAttach: function (form) {
|
||||
// @fixme this should not be tied to the main notice form, as there may be multiple notice forms...
|
||||
var NLat = form.find('[name=lat]')
|
||||
var NLon = form.find('[name=lon]')
|
||||
var NLat = form.find('[name=lat]');
|
||||
var NLon = form.find('[name=lon]');
|
||||
var NLNS = form.find('[name=location_ns]').val();
|
||||
var NLID = form.find('[name=location_id]').val();
|
||||
var NLN = ''; // @fixme
|
||||
@ -1087,22 +1074,21 @@ var SN = { // StatusNet
|
||||
function getJSONgeocodeURL(geocodeURL, data) {
|
||||
SN.U.NoticeGeoStatus(form, 'Looking up place name...');
|
||||
$.getJSON(geocodeURL, data, function (location) {
|
||||
var lns, lid;
|
||||
var lns, lid, NLN_text;
|
||||
|
||||
if (typeof(location.location_ns) != 'undefined') {
|
||||
if (location.location_ns !== undefined) {
|
||||
form.find('[name=location_ns]').val(location.location_ns);
|
||||
lns = location.location_ns;
|
||||
}
|
||||
|
||||
if (typeof(location.location_id) != 'undefined') {
|
||||
if (location.location_id !== undefined) {
|
||||
form.find('[name=location_id]').val(location.location_id);
|
||||
lid = location.location_id;
|
||||
}
|
||||
|
||||
if (typeof(location.name) == 'undefined') {
|
||||
if (location.name === undefined) {
|
||||
NLN_text = data.lat + ';' + data.lon;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
NLN_text = location.name;
|
||||
}
|
||||
|
||||
@ -1133,19 +1119,17 @@ var SN = { // StatusNet
|
||||
if (check.length > 0) {
|
||||
if ($.cookie(SN.C.S.NoticeDataGeoCookie) == 'disabled') {
|
||||
check.prop('checked', false);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
check.prop('checked', true);
|
||||
}
|
||||
|
||||
var NGW = form.find('.notice_data-geo_wrap');
|
||||
var geocodeURL = NGW.attr('data-api');
|
||||
|
||||
label
|
||||
.attr('title', label.text());
|
||||
label.attr('title', label.text());
|
||||
|
||||
check.change(function () {
|
||||
if (check.prop('checked') === true || $.cookie(SN.C.S.NoticeDataGeoCookie) === null)
|
||||
if (check.prop('checked') === true || $.cookie(SN.C.S.NoticeDataGeoCookie) === null) {
|
||||
label
|
||||
.attr('title', NoticeDataGeo_text.ShareDisable)
|
||||
.addClass('checked');
|
||||
@ -1183,8 +1167,7 @@ var SN = { // StatusNet
|
||||
timeout: 10000
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (NLat.length > 0 && NLon.length > 0) {
|
||||
var data = {
|
||||
lat: NLat,
|
||||
@ -1193,15 +1176,13 @@ var SN = { // StatusNet
|
||||
};
|
||||
|
||||
getJSONgeocodeURL(geocodeURL, data);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
removeNoticeDataGeo();
|
||||
check.remove();
|
||||
label.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var cookieValue = JSON.parse($.cookie(SN.C.S.NoticeDataGeoCookie));
|
||||
|
||||
form.find('[name=lat]').val(cookieValue.NLat);
|
||||
@ -1215,8 +1196,7 @@ var SN = { // StatusNet
|
||||
.attr('title', NoticeDataGeo_text.ShareDisable + ' (' + cookieValue.NLN + ')')
|
||||
.addClass('checked');
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
removeNoticeDataGeo();
|
||||
}
|
||||
}).change();
|
||||
@ -1291,8 +1271,7 @@ var SN = { // StatusNet
|
||||
});
|
||||
NDM.removeClass(SN.C.S.Processing);
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
NDMF.show();
|
||||
$('.entity_send-a-message textarea').focus();
|
||||
}
|
||||
@ -1719,7 +1698,7 @@ var SN = { // StatusNet
|
||||
*/
|
||||
UploadForms: function () {
|
||||
$('input[type=file]').change(function (event) {
|
||||
if (typeof this.files == "object" && this.files.length > 0) {
|
||||
if (typeof this.files === "object" && this.files.length > 0) {
|
||||
var size = 0;
|
||||
for (var i = 0; i < this.files.length; i++) {
|
||||
size += this.files[i].size;
|
||||
|
2
js/util.min.js
vendored
2
js/util.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user