-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,22 +9,41 @@ VuFind.register('cart', function Cart() { | |
var _COOKIE_PATH = '/'; | ||
var _COOKIE_SAMESITE = 'Lax'; | ||
|
||
/** | ||
* | ||
* @param domain | ||
Check warning on line 14 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
Check warning on line 14 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
|
||
*/ | ||
function setDomain(domain) { | ||
_COOKIE_DOMAIN = domain; | ||
} | ||
|
||
/** | ||
* | ||
* @param path | ||
Check warning on line 22 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
Check warning on line 22 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
|
||
*/ | ||
function setCookiePath(path) { | ||
_COOKIE_PATH = path; | ||
} | ||
|
||
/** | ||
* | ||
* @param sameSite | ||
Check warning on line 30 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
Check warning on line 30 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
|
||
*/ | ||
function setCookieSameSite(sameSite) { | ||
_COOKIE_SAMESITE = sameSite; | ||
} | ||
|
||
/** | ||
Check warning on line 36 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
|
||
* | ||
*/ | ||
function _getCookieParams() { | ||
return { path: _COOKIE_PATH, domain: _COOKIE_DOMAIN, SameSite: _COOKIE_SAMESITE }; | ||
} | ||
|
||
/** | ||
Check warning on line 43 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
|
||
* | ||
* @param op | ||
Check warning on line 45 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
Check warning on line 45 in themes/bootstrap3/js/cart.js GitHub Actions / Tests with PHP 8.2
|
||
*/ | ||
function _uniqueArray(op) { | ||
var ret = []; | ||
for (var i = 0; i < op.length; i++) { | ||
|
@@ -35,20 +54,29 @@ VuFind.register('cart', function Cart() { | |
return ret; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
function _getItems() { | ||
var items = window.Cookies.get(_COOKIE); | ||
if (items) { | ||
return items.split(_COOKIE_DELIM); | ||
} | ||
return []; | ||
} | ||
/** | ||
* | ||
*/ | ||
function _getSources() { | ||
var items = window.Cookies.get(_COOKIE_SOURCES); | ||
if (items) { | ||
return items.split(_COOKIE_DELIM); | ||
} | ||
return []; | ||
} | ||
/** | ||
* | ||
*/ | ||
function getFullItems() { | ||
var items = _getItems(); | ||
var sources = _getSources(); | ||
|
@@ -62,11 +90,19 @@ VuFind.register('cart', function Cart() { | |
return full; | ||
} | ||
|
||
/** | ||
* | ||
* @param id | ||
* @param _source | ||
*/ | ||
function hasItem(id, _source) { | ||
var source = _source || VuFind.defaultSearchBackend; | ||
return _getItems().indexOf(String.fromCharCode(65 + _getSources().indexOf(source)) + id) > -1; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
function _refreshToggles() { | ||
var $toggleBtns = $('.btn-bookbag-toggle'); | ||
if ($toggleBtns.length > 0) { | ||
|
@@ -82,6 +118,9 @@ VuFind.register('cart', function Cart() { | |
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
function updateCount() { | ||
var items = VuFind.cart.getFullItems(); | ||
$('#cartItems strong').html(items.length); | ||
|
@@ -93,6 +132,11 @@ VuFind.register('cart', function Cart() { | |
_refreshToggles(); | ||
} | ||
|
||
/** | ||
* | ||
* @param id | ||
* @param _source | ||
*/ | ||
function addItem(id, _source) { | ||
var source = _source || VuFind.defaultSearchBackend; | ||
var cartItems = _getItems(); | ||
|
@@ -113,6 +157,11 @@ VuFind.register('cart', function Cart() { | |
updateCount(); | ||
return true; | ||
} | ||
/** | ||
* | ||
* @param id | ||
* @param source | ||
*/ | ||
function removeItem(id, source) { | ||
var cartItems = _getItems(); | ||
var cartSources = _getSources(); | ||
|
@@ -157,6 +206,10 @@ VuFind.register('cart', function Cart() { | |
} | ||
|
||
var _cartNotificationTimeout = false; | ||
/** | ||
* | ||
* @param _form | ||
*/ | ||
function _registerUpdate(_form) { | ||
var $form = typeof _form === 'undefined' | ||
? $('form[name="bulkActionForm"]') | ||
|
@@ -210,6 +263,10 @@ VuFind.register('cart', function Cart() { | |
}); | ||
} | ||
|
||
/** | ||
* | ||
* @param _container | ||
*/ | ||
function registerToggles(_container) { | ||
var container = typeof _container !== 'undefined' ? $(_container) : $(document); | ||
var $toggleBtns = container.find('.btn-bookbag-toggle'); | ||
|
@@ -244,10 +301,17 @@ VuFind.register('cart', function Cart() { | |
} | ||
} | ||
|
||
/** | ||
* | ||
* @param params | ||
*/ | ||
function updateContainer(params) { | ||
registerToggles(params.container); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
function init() { | ||
// Record buttons | ||
registerToggles(); | ||
|
@@ -283,6 +347,11 @@ VuFind.register('cart', function Cart() { | |
|
||
// Building an array and checking indexes prevents a race situation | ||
// We want to prioritize empty over printing | ||
/** | ||
* | ||
* @param event | ||
* @param data | ||
*/ | ||
function cartFormHandler(event, data) { | ||
let numberOfItems = 0; | ||
let isPrint = false; | ||
|