Skip to content
Snippets Groups Projects
Commit 06d37c9a authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[TASK] add code docs

parent fd45db23
No related branches found
No related tags found
No related merge requests found
...@@ -31,9 +31,16 @@ use TYPO3\CMS\Core\Database\DatabaseConnection; ...@@ -31,9 +31,16 @@ use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Page\PageRepository; use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* The LikeController handles the Ajax-Actions related to the like feature
*
* @package SGalinski\SgNews\Controller\Ajax
*/
class LikeController extends AbstractAjaxController { class LikeController extends AbstractAjaxController {
/** /**
* This action increases the tx_sgnews_likes field of a given page ($newsPid) by one
*
* @param int $newsPid * @param int $newsPid
* @return string * @return string
*/ */
......
'use strict'; 'use strict';
// We rely on a global jQuery instance here, so don't initialize the module if none is found
if (window.hasOwnProperty('$')) { if (window.hasOwnProperty('$')) {
var $likeContainer = $('#tx-sgnews-likes'), var $likeContainer = $('#tx-sgnews-likes'),
$likeButton = $likeContainer.find('.btn'), $likeButton = $likeContainer.find('.btn'),
...@@ -7,9 +8,12 @@ if (window.hasOwnProperty('$')) { ...@@ -7,9 +8,12 @@ if (window.hasOwnProperty('$')) {
newsId = $likeContainer.data('uid'); newsId = $likeContainer.data('uid');
$likeButton.on('click', addLike); $likeButton.on('click', addLike);
checkButtonStatus(); checkButtonStatus();
/**
* Fires the Ajax-Call to add a new Like
* Won't do anything if the user already committed a like
*/
function addLike() { function addLike() {
if (!window.localStorage.getItem('sg-news-like-' + newsId)) { if (!window.localStorage.getItem('sg-news-like-' + newsId)) {
$likeButton.addClass('tx-sgnews-loading'); $likeButton.addClass('tx-sgnews-loading');
...@@ -26,12 +30,20 @@ if (window.hasOwnProperty('$')) { ...@@ -26,12 +30,20 @@ if (window.hasOwnProperty('$')) {
} }
} }
/**
* Checks if the user already committed a like and updates the button accordingly
*/
function checkButtonStatus() { function checkButtonStatus() {
if (window.localStorage.getItem('sg-news-like-' + newsId)) { if (window.localStorage.getItem('sg-news-like-' + newsId)) {
updateButton(false); updateButton(false);
} }
} }
/**
* Update the like-button status
*
* @param {bool} addedLike If set to true, the like-count will also be increased
*/
function updateButton(addedLike) { function updateButton(addedLike) {
$likeButton.removeClass('btn-info').addClass('btn-success'); $likeButton.removeClass('btn-info').addClass('btn-success');
$likeButton.find('.fa-star-o').removeClass('fa-star-o').addClass('fa-star'); $likeButton.find('.fa-star-o').removeClass('fa-star-o').addClass('fa-star');
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"license": [ "license": [
"GPL-2.0+" "GPL-2.0+"
], ],
"version": "3.7.0", "version": "3.7.1",
"support": { "support": {
}, },
"repositories": [ "repositories": [
......
...@@ -19,7 +19,7 @@ $EM_CONF[$_EXTKEY] = [ ...@@ -19,7 +19,7 @@ $EM_CONF[$_EXTKEY] = [
'modify_tables' => '', 'modify_tables' => '',
'clearCacheOnLoad' => 0, 'clearCacheOnLoad' => 0,
'lockType' => '', 'lockType' => '',
'version' => '3.7.0', 'version' => '3.7.1',
'constraints' => [ 'constraints' => [
'depends' => [ 'depends' => [
'typo3' => '7.6.0-7.6.99', 'typo3' => '7.6.0-7.6.99',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment