psychobunny 11 years ago
commit 5305bc0138

@ -166,119 +166,33 @@ var socket,
});
};
// takes a string like 1000 and returns 1,000
app.addCommas = function (text) {
return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
};
// use unique alert_id to have multiple alerts visible at a time, use the same alert_id to fade out the current instance
// type : error, success, info, warning/notify
// title = bolded title text
// message = alert message content
// timeout default = permanent
// location : alert_window (default) or content
app.alert = function (params) {
var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime());
var alert = $('#' + alert_id);
var title = params.title || '';
function fadeOut() {
alert.fadeOut(500, function () {
$(this).remove();
});
}
function startTimeout(timeout) {
var timeoutId = setTimeout(function () {
fadeOut();
}, timeout);
alert.attr('timeoutId', timeoutId);
}
if (alert.length > 0) {
alert.find('strong').html(title);
alert.find('p').html(params.message);
alert.attr('class', 'alert alert-dismissable alert-' + params.type);
clearTimeout(alert.attr('timeoutId'));
startTimeout(params.timeout);
alert.children().fadeOut('100');
translator.translate(alert.html(), function(translatedHTML) {
alert.children().fadeIn('100');
alert.html(translatedHTML);
});
} else {
alert = $('<div id="' + alert_id + '" class="alert alert-dismissable alert-' + params.type +'"></div>');
alert.append($('<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'))
.append($('<strong>' + title + '</strong>'));
if (params.message) {
alert.append($('<p>' + params.message + '</p>'));
}
if (!params.location) {
params.location = 'alert_window';
}
translator.translate(alert.html(), function(translatedHTML) {
alert.html(translatedHTML);
$('#' + params.location).prepend(alert.fadeIn('100'));
if(typeof params.closefn === 'function') {
alert.find('button').on('click', function() {
params.closefn();
fadeOut();
return false;
});
}
});
if (params.timeout) {
startTimeout(params.timeout);
}
if (typeof params.clickfn === 'function') {
alert.on('click', function (e) {
if(!$(e.target).is('.close')) {
params.clickfn();
}
fadeOut();
});
}
}
require(['alerts'], function(alerts) {
alerts.alert(params);
});
};
app.removeAlert = function(id) {
$('#' + 'alert_button_' + id).remove();
require(['alerts'], function(alerts) {
alerts.remove(id);
});
};
app.alertSuccess = function (message, timeout) {
if (!timeout) {
timeout = 2000;
}
app.alert({
title: '[[global:alert.success]]',
message: message,
type: 'success',
timeout: timeout
timeout: timeout ? timeout : 2000
});
};
app.alertError = function (message, timeout) {
if (!timeout) {
timeout = 2000;
}
app.alert({
title: '[[global:alert.error]]',
message: message,
type: 'danger',
timeout: timeout
timeout: timeout ? timeout : 2000
});
};
@ -362,12 +276,6 @@ var socket,
});
};
app.makeNumbersHumanReadable = function(elements) {
elements.each(function() {
$(this).html(utils.makeNumberHumanReadable($(this).attr('title')));
});
};
app.processPage = function () {
app.populateOnlineUsers();
@ -376,7 +284,7 @@ var socket,
$('span.timeago').timeago();
$('.post-content img').addClass('img-responsive');
app.makeNumbersHumanReadable($('.human-readable-number'));
utils.makeNumbersHumanReadable($('.human-readable-number'));
app.createUserTooltips();
@ -407,12 +315,6 @@ var socket,
}
};
app.addCommasToNumbers = function () {
$('.formatted-number').each(function (index, element) {
$(element).html(app.addCommas($(element).html()));
});
};
app.openChat = function (username, touid) {
if (username === app.username) {
app.alert({

@ -12,8 +12,8 @@ define(['forum/accountheader'], function(header) {
var username = $('.account-username').html();
app.enterRoom('user/' + theirid);
app.addCommasToNumbers();
app.makeNumbersHumanReadable($('.account .human-readable-number'));
utils.addCommasToNumbers($('.account .formatted-number'));
utils.makeNumbersHumanReadable($('.account .human-readable-number'));
$('.user-recent-posts img').addClass('img-responsive');
var followBtn = $('#follow-btn');

@ -49,7 +49,7 @@ define(['forum/accountheader'], function(header) {
$('.user-favourite-posts').append(html);
$('span.timeago').timeago();
app.createUserTooltips();
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
});
}

@ -1,7 +1,7 @@
"use strict";
/* global define, config, templates, app, ajaxify, socket, translator */
define(['composer', 'forum/pagination'], function(composer, pagination) {
define(['composer', 'forum/pagination', 'share'], function(composer, pagination, share) {
var Category = {},
loadingMoreTopics = false;
@ -10,33 +10,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
app.enterRoom('category_' + cid);
$('.twitter-share').on('click', function () {
window.open('https://twitter.com/intent/tweet?url=' + encodeURIComponent(window.location.href) + '&text=' + encodeURIComponent(ajaxify.variables.get('category_name')), '_blank', 'width=550,height=420,scrollbars=no,status=no');
return false;
});
$('.facebook-share').on('click', function () {
window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.location.href), '_blank', 'width=626,height=436,scrollbars=no,status=no');
return false;
});
$('.google-share').on('click', function () {
window.open('https://plus.google.com/share?url=' + encodeURIComponent(window.location.href), '_blank', 'width=500,height=570,scrollbars=no,status=no');
return false;
});
$('.share-dropdown').on('shown.bs.dropdown', function() {
$('#category-link').val(window.location.protocol + '//' + window.location.host + window.location.pathname);
// without the setTimeout can't select the text in the input
setTimeout(function() {
$('#category-link').putCursorAtEnd().select();
}, 50);
});
$('.post-link').on('click', function(e) {
e.preventDefault();
return false;
});
share.addShareHandlers(ajaxify.variables.get('category_name'));
$('#new_post').on('click', function () {
composer.newTopic(cid);
@ -284,7 +258,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
html.find('span.timeago').timeago();
app.createUserTooltips();
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
if (typeof callback === 'function') {
callback(topics);

@ -42,9 +42,9 @@ define(['forum/accountheader'], function(header) {
html = $(translatedHTML);
html.find('img').addClass('img-responsive');
$('.user-favourite-posts').append(html);
$('span.timeago').timeago();
html.find('span.timeago').timeago();
app.createUserTooltips();
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
});
}

@ -9,11 +9,11 @@ define(['forum/accountheader'], function(header) {
followersCount = ajaxify.variables.get('followersCount');
if (parseInt(followersCount, 10) === 0) {
$('#no-followers-notice').removeClass('hide');
}
if (parseInt(followersCount, 10) === 0) {
$('#no-followers-notice').removeClass('hide');
}
app.addCommasToNumbers();
utils.addCommasToNumbers($('.account .formatted-number'));
};
return Followers;

@ -10,7 +10,7 @@ define(['forum/accountheader'], function(header) {
$('#no-following-notice').removeClass('hide');
}
app.addCommasToNumbers();
utils.addCommasToNumbers($('.account .formatted-number'));
};
return Following;

@ -124,9 +124,9 @@ define(function() {
html = $(translatedHTML);
$('#topics-container').append(html);
$('span.timeago').timeago();
html.find('span.timeago').timeago();
app.createUserTooltips();
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
});
}

@ -44,7 +44,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
}
$(function() {
app.addCommasToNumbers();
utils.addCommasToNumbers($('.topic .formatted-number'));
app.enterRoom('topic_' + tid);
@ -761,8 +761,8 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
app.populateOnlineUsers();
app.createUserTooltips();
app.addCommasToNumbers();
app.makeNumbersHumanReadable($('.human-readable-number'));
utils.addCommasToNumbers(html.find('.formatted-number'));
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
html.find('span.timeago').timeago();
html.find('.post-content img').addClass('img-responsive');
updatePostCount();

@ -2,7 +2,7 @@
/* globals define, app, translator, ajaxify, socket, bootbox */
define(['composer'], function(composer) {
define(['composer', 'share'], function(composer, share) {
var PostTools = {},
topicName;
@ -12,7 +12,7 @@ define(['composer'], function(composer) {
addPostHandlers(tid, threadState);
addShareHandlers();
share.addShareHandlers(topicName);
};
function addPostHandlers(tid, threadState) {
@ -21,6 +21,7 @@ define(['composer'], function(composer) {
onReplyClicked($(this), tid, topicName);
}
});
var postContainer = $('#post-container');
postContainer.on('click', '.quote', function() {
@ -228,39 +229,5 @@ define(['composer'], function(composer) {
return false;
}
function addShareHandlers() {
function openShare(url, pid, width, height) {
window.open(url + encodeURIComponent(window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + pid), '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no');
return false;
}
$('#post-container').on('shown.bs.dropdown', '.share-dropdown', function() {
var pid = getPid($(this));
$('#post_' + pid + '_link').val(window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + pid);
// without the setTimeout can't select the text in the input
setTimeout(function() {
$('#post_' + pid + '_link').putCursorAtEnd().select();
}, 50);
});
$('#post-container').on('click', '.post-link', function(e) {
e.preventDefault();
return false;
});
$('#post-container').on('click', '.twitter-share', function () {
return openShare('https://twitter.com/intent/tweet?text=' + topicName + '&url=', getPid($(this)), 550, 420);
});
$('#post-container').on('click', '.facebook-share', function () {
return openShare('https://www.facebook.com/sharer/sharer.php?u=', getPid($(this)), 626, 436);
});
$('#post-container').on('click', '.google-share', function () {
return openShare('https://plus.google.com/share?url=', getPid($(this)), 500, 570);
});
}
return PostTools;
});

@ -16,7 +16,7 @@ define(function() {
var lastSearch = null;
app.addCommasToNumbers();
utils.addCommasToNumbers($('.users .formatted-number'));
$('.nav-pills li').removeClass('active');
$('.nav-pills li a').each(function() {

@ -0,0 +1,94 @@
'use strict';
/* globals define, translator, templates */
define(function() {
var module = {};
// use unique alert_id to have multiple alerts visible at a time, use the same alert_id to fade out the current instance
// type : error, success, info, warning/notify
// title = bolded title text
// message = alert message content
// timeout default = permanent
// location : alert_window (default) or content
module.alert = function (params) {
var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime());
var alert = $('#' + alert_id);
var title = params.title || '';
function fadeOut() {
alert.fadeOut(500, function () {
$(this).remove();
});
}
function startTimeout(timeout) {
var timeoutId = setTimeout(function () {
fadeOut();
}, timeout);
alert.attr('timeoutId', timeoutId);
}
if (alert.length) {
alert.find('strong').html(title);
alert.find('p').html(params.message);
alert.attr('class', 'alert alert-dismissable alert-' + params.type);
clearTimeout(alert.attr('timeoutId'));
startTimeout(params.timeout);
alert.children().fadeOut('100');
translator.translate(alert.html(), function(translatedHTML) {
alert.children().fadeIn('100');
alert.html(translatedHTML);
});
} else {
alert = $('<div id="' + alert_id + '" class="alert alert-dismissable alert-' + params.type +'"></div>');
alert.append($('<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'))
.append($('<strong>' + title + '</strong>'));
if (params.message) {
alert.append($('<p>' + params.message + '</p>'));
}
if (!params.location) {
params.location = 'alert_window';
}
translator.translate(alert.html(), function(translatedHTML) {
alert.html(translatedHTML);
$('#' + params.location).prepend(alert.fadeIn('100'));
if(typeof params.closefn === 'function') {
alert.find('button').on('click', function() {
params.closefn();
fadeOut();
return false;
});
}
});
if (params.timeout) {
startTimeout(params.timeout);
}
if (typeof params.clickfn === 'function') {
alert.on('click', function (e) {
if(!$(e.target).is('.close')) {
params.clickfn();
}
fadeOut();
});
}
}
};
module.remove = function(id) {
$('#alert_button_' + id).remove();
};
return module;
});

@ -0,0 +1,56 @@
'use strict';
/* globals define */
define(function() {
var module = {};
module.addShareHandlers = function(name) {
var baseUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
function openShare(url, hash, width, height) {
window.open(url + encodeURIComponent(baseUrl + hash), '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no');
return false;
}
$('#content').on('shown.bs.dropdown', '.share-dropdown', function() {
var postLink = $(this).find('.post-link');
postLink.val(baseUrl + getPostHash($(this)));
// without the setTimeout can't select the text in the input
setTimeout(function() {
postLink.putCursorAtEnd().select();
}, 50);
});
$('#content').on('click', '.post-link', function(e) {
e.preventDefault();
return false;
});
$('#content').on('click', '.twitter-share', function () {
return openShare('https://twitter.com/intent/tweet?text=' + name + '&url=', getPostHash($(this)), 550, 420);
});
$('#content').on('click', '.facebook-share', function () {
return openShare('https://www.facebook.com/sharer/sharer.php?u=', getPostHash($(this)), 626, 436);
});
$('#content').on('click', '.google-share', function () {
return openShare('https://plus.google.com/share?url=', getPostHash($(this)), 500, 570);
});
};
function getPostHash(clickedElement) {
var pid = clickedElement.parents('.post-row').attr('data-pid');
if (pid) {
return '#' + pid;
}
return '';
}
return module;
});

@ -198,6 +198,12 @@
return (firstChar === '.' || firstChar === '/');
},
makeNumbersHumanReadable: function(elements) {
elements.each(function() {
$(this).html(utils.makeNumberHumanReadable($(this).attr('title')));
});
},
makeNumberHumanReadable: function(num) {
var n = parseInt(num, 10);
if(!n) {
@ -212,6 +218,17 @@
return n;
},
addCommasToNumbers: function (elements) {
elements.each(function (index, element) {
$(element).html(utils.addCommas($(element).html()));
});
},
// takes a string like 1000 and returns 1,000
addCommas: function (text) {
return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
},
toISOString: function(timestamp) {
if(!timestamp) {
return '';

Loading…
Cancel
Save