mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-11-04 12:12:48 -05:00
- Implemented `planting_alternate_name.js` to load alternate names for crops in the planting form based on user input. - Added `tab_navigation.js` to manage tab navigation and update the URL hash accordingly. Update map rendering in member and place views - Modified `_map.html.haml` to include a custom marker icon for member maps. - Updated `index.html.haml` and `show.html.haml` to pass `places_map_data` to the map sections. Refactor asset management in Rails application - Removed Sprockets from the application configuration and adjusted asset paths. - Updated asset precompilation settings and removed deprecated asset configurations from environment files. - Added new build scripts for CSS and updated package dependencies in `package.json` for Bootstrap, Chart.js, and others. Ensure React and CSS bundles are built before running tests - Updated `react_bundle.rb` to check for the existence of both JavaScript and CSS bundles and build them if missing.
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
$(document).ready(function() {
|
|
$('.like-btn').show();
|
|
|
|
/**
|
|
* Handles the result of an ajax call and updates UI
|
|
*
|
|
* @param {object} data JSON data from ajax response
|
|
* @param {string} type object type (ie: post, activity, etc)
|
|
*/
|
|
var likeableSuccess = function(data, type) {
|
|
var target = '.' + type + '-' + data.id;
|
|
var objectClass = type.charAt(0).toUpperCase() + type.slice(1);
|
|
var likeButton = $(target + ' .' + type + '-like');
|
|
var likeBadge = $(target + ' .like-badge');
|
|
|
|
$(target + ' .like-count').text(data.like_count);
|
|
if (data.liked_by_member) {
|
|
likeBadge.addClass('liked');
|
|
likeButton.data('method', 'delete');
|
|
likeButton.attr('href', data.url);
|
|
likeButton.text('Unlike');
|
|
} else {
|
|
likeBadge.removeClass('liked');
|
|
likeButton.data('method', 'post');
|
|
likeButton.attr('href', '/likes.json?type=' + objectClass + '&id=' + data.id);
|
|
likeButton.text('Like');
|
|
}
|
|
};
|
|
|
|
$('.post-like').on('ajax:success', function(event, data) {
|
|
likeableSuccess(data, 'post');
|
|
});
|
|
|
|
$('.activity-like').on('ajax:success', function(event, data) {
|
|
likeableSuccess(data, 'activity');
|
|
});
|
|
|
|
$('.planting-like').on('ajax:success', function(event, data) {
|
|
likeableSuccess(data, 'planting');
|
|
});
|
|
|
|
$('.harvest-like').on('ajax:success', function(event, data) {
|
|
likeableSuccess(data, 'harvest');
|
|
});
|
|
|
|
$('.photo-like').on('ajax:success', function(event, data) {
|
|
var likeBadge = $('#photo-'+ data.id + ' .like-badge');
|
|
var likeButton = $('#photo-'+ data.id + ' .like-btn');
|
|
|
|
$('#photo-' + data.id + ' .like-count').text(data.like_count);
|
|
if (data.liked_by_member) {
|
|
likeBadge.addClass('liked');
|
|
// Turn the button into an unlike button
|
|
likeButton.data('method', 'delete');
|
|
likeButton.attr('href', data.url);
|
|
} else {
|
|
likeBadge.removeClass('liked');
|
|
// Turn the button into an *like* button
|
|
likeButton.data('method', 'post');
|
|
likeButton.attr('href', '/likes.json?type=Photo&id=' + data.id);
|
|
}
|
|
});
|
|
});
|