Merge branch 'master' of https://github.com/designcreateplay/NodeBB
commit
5305bc0138
@ -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">×</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;
|
||||
});
|
Loading…
Reference in New Issue