$(document).ready(function(){
//fade in/out based on scrollTop value
+ var scrollStart;
+
$(window).scroll(function () {
- if ($(this).scrollTop() > 1000) {
- $("#back-to-top").fadeIn();
- } else {
+ let currentScroll = $(this).scrollTop();
+
+ // Top of the page or going down = hide the button
+ if (!scrollStart || !currentScroll || currentScroll > scrollStart) {
$("#back-to-top").fadeOut();
+ scrollStart = currentScroll;
+ }
+
+ // Going up enough = show the button
+ if (scrollStart - currentScroll > 100) {
+ $("#back-to-top").fadeIn();
+ scrollStart = currentScroll;
}
});
'target': ".flex-target"
});
- // add Jot botton to the scecond navbar
+ // add Jot button to the second navbar
let $jotButton = $("#jotOpen");
- let $composeButton = $("#composeOpen");
- if (compose) {
- $jotButton.hide();
- if ($composeButton.length) {
- $composeButton.appendTo("#topbar-second > .container > #navbar-button");
- if($("#jot-popup").is(":hidden")) {
- $composeButton.hide();
- }
- }
- } else {
- $composeButton.hide();
- if ($jotButton.length) {
- $jotButton.appendTo("#topbar-second > .container > #navbar-button");
- if($("#jot-popup").is(":hidden")) {
- $jotButton.hide();
- }
+ if ($jotButton.length) {
+ $jotButton.appendTo("#topbar-second > .container > #navbar-button");
+ if ($("#jot-popup").is(":hidden")) {
+ $jotButton.hide();
}
+ $jotButton.on('click', function (e) {
+ e.preventDefault();
+ jotShow();
+ });
}
+ let $body = $('body');
+
// show bulk deletion button at network page if checkbox is checked
- $("body").change("input.item-select", function(){
+ $body.change("input.item-select", function(){
var checked = false;
// We need to get all checked items, so it would close the delete button
}
});
- //$('ul.flex-nav').flexMenu();
-
// initialize the bootstrap tooltips
- $('body').tooltip({
+ $body.tooltip({
selector: '[data-toggle="tooltip"]',
container: 'body',
animation: true,
// Dropdown menus with the class "dropdown-head" will display the active tab
// as button text
- $("body").on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){
+ $body.on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){
toggleDropdownText(this);
});
- /* setup onoff widgets */
- // Add the correct class to the switcher according to the input
- // value (On/Off)
- $(".toggle input").each(function(){
- // Get the value of the input element
- val = $(this).val();
- id = $(this).attr("id");
-
- // The css classes for "on" and "off"
- onstyle = "btn-primary";
- offstyle = "btn-default off";
-
- // Add the correct class in dependence of input value (On/Off)
- toggleclass = (val == 0 ? offstyle : onstyle);
- $("#"+id+"_onoff").addClass(toggleclass);
-
- });
-
// Change the css class while clicking on the switcher elements
$(".toggle label, .toggle .toggle-handle").click(function(event){
event.preventDefault();
// to the input element where the padding value would be at least the width
// of the button. Otherwise long user input would be invisible because it is
// behind the button.
- $("body").on('click', '.form-group-search > input', function() {
+ $body.on('click', '.form-group-search > input', function() {
// Get the width of the button (if the button isn't available
// buttonWidth will be null
var buttonWidth = $(this).next('.form-button-search').outerWidth();
*/
$("aside")
.on("shown.bs.offcanvas", function() {
- $("body").addClass("aside-out");
+ $body.addClass("aside-out");
})
.on("hidden.bs.offcanvas", function() {
- $("body").removeClass("aside-out");
+ $body.removeClass("aside-out");
});
// Event listener for 'Show & hide event map' button in the network stream.
- $("body").on("click", ".event-map-btn", function() {
+ $body.on("click", ".event-map-btn", function() {
showHideEventMap(this);
});
+ // Comment form submit
+ $body.on('submit', '.comment-edit-form', function(e) {
+ let $form = $(this);
+ let id = $form.data('item-id');
+
+ // Compose page form exception: id is always 0 and form must not be submitted asynchronously
+ if (id === 0) {
+ return;
+ }
+
+ e.preventDefault();
+
+ let $commentSubmit = $form.find('.comment-edit-submit').button('loading');
+
+ unpause();
+ commentBusy = true;
+
+ $.post(
+ 'item',
+ $form.serialize(),
+ 'json'
+ )
+ .then(function(data) {
+ if (data.success) {
+ $('#comment-edit-wrapper-' + id).hide();
+ let $textarea = $('#comment-edit-text-' + id);
+ $textarea.val('');
+ if ($textarea.get(0)) {
+ commentClose($textarea.get(0), id);
+ }
+ if (timer) {
+ clearTimeout(timer);
+ }
+ timer = setTimeout(NavUpdate,10);
+ force_update = true;
+ update_item = id;
+ }
+ if (data.reload) {
+ window.location.href = data.reload;
+ }
+ })
+ .always(function() {
+ $commentSubmit.button('reset');
+ });
+ });
+
+ $body.on('submit', '.modal-body #poke-wrapper', function(e) {
+ e.preventDefault();
+
+ let $form = $(this);
+ let $pokeSubmit = $form.find('button[type=submit]').button('loading');
+
+ $.post(
+ $form.attr('action'),
+ $form.serialize(),
+ 'json'
+ )
+ .then(function(data) {
+ if (data.success) {
+ $('#modal').modal('hide');
+ }
+ })
+ .always(function() {
+ $pokeSubmit.button('reset');
+ });
+ })
});
function openClose(theID) {
// Scroll to the DIV with the ID (GUID)
$('html, body').animate({
scrollTop: itemPos
- }, 400, function() {
+ }, 400).promise().done( function() {
// Highlight post/commenent with ID (GUID)
- $el.animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600);
+ $el.animate(colWhite, 1000).animate(colShiny).animate({backgroundColor: 'transparent'}, 600);
});
}
* Sends a /like API call and updates the display of the relevant action button
* before the update reloads the item.
*
- * @param {string} ident The id of the relevant item
- * @param {string} verb The verb of the action
- * @returns {undefined}
+ * @param {int} ident The id of the relevant item
+ * @param {string} verb The verb of the action
+ * @param {boolean} un Whether to perform an activity removal instead of creation
*/
-function doLikeAction(ident, verb) {
- unpause();
-
+function doLikeAction(ident, verb, un) {
if (verb.indexOf('attend') === 0) {
$('.item-' + ident + ' .button-event:not(#' + verb + '-' + ident + ')').removeClass('active');
}
$('#' + verb + '-' + ident).toggleClass('active');
- $('#like-rotator-' + ident.toString()).show();
- $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
- liking = 1;
- force_update = true;
- update_item = ident.toString();
+
+ dolike(ident, verb, un);
}
// Decodes a hexadecimally encoded binary string