@internetarchive/ia-book-actions 0.0.29 → 0.0.30-alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/index.html CHANGED
@@ -134,6 +134,25 @@
134
134
  });
135
135
  });
136
136
 
137
+ document.querySelectorAll('.searchParam input[type=checkbox]').forEach((item) => {
138
+ item.addEventListener('click', (e) => {
139
+ var searchParams = new URLSearchParams(window.location.search);
140
+ var separate = '';
141
+ if (e.target.checked) {
142
+ separate = '?';
143
+ searchParams.set('q', 'test');
144
+ } else {
145
+ separate = '';
146
+ searchParams.delete('q');
147
+ }
148
+
149
+ if (history.pushState) {
150
+ var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + separate + searchParams;
151
+ window.history.pushState({path:newurl},'',newurl);
152
+ }
153
+ });
154
+ });
155
+
137
156
  document.querySelectorAll('.errorEnable input[type=checkbox]').forEach((item) => {
138
157
  if (window.location.href.indexOf('?error=true') !== -1) {
139
158
  item.checked = true;
@@ -263,6 +282,9 @@
263
282
  <td class="titleBar">
264
283
  <label><input type="checkbox" name="title" value="title" />Title Bar</label>
265
284
  </td>
285
+ <td class="searchParam">
286
+ <label><input type="checkbox" name="search" value="Search Param" />Search Param</label>
287
+ </td>
266
288
  </tr>
267
289
  </table>
268
290
  </fieldset>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29",
3
+ "version": "0.0.30-alpha2",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -147,7 +147,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
147
147
  get renderSecondaryActions() {
148
148
  if (!this.secondaryActions.length) return nothing;
149
149
 
150
- return this.secondaryActions.map(action => this.renderActionLink(action));
150
+ return this.secondaryActions.map(action => this.renderActionButton(action));
151
151
  }
152
152
 
153
153
  /**
@@ -5,6 +5,7 @@ export class TextGroup extends LitElement {
5
5
  return {
6
6
  texts: { type: String },
7
7
  textClass: { type: String },
8
+ hasAdminBorrowedAccess: { type: Boolean },
8
9
  };
9
10
  }
10
11
 
@@ -12,11 +13,16 @@ export class TextGroup extends LitElement {
12
13
  super();
13
14
  this.texts = '';
14
15
  this.textClass = '';
16
+ this.hasAdminBorrowedAccess = false;
15
17
  }
16
18
 
17
19
  render() {
18
20
  return html`
19
- <span class="variable-texts ${this.textClass}">${this.texts}</span>
21
+ <span class="variable-texts ${this.textClass}">
22
+ ${this.hasAdminBorrowedAccess
23
+ ? html`<slot name="sticky-access-checkbox">${this.texts}</slot>`
24
+ : this.texts}
25
+ </span>
20
26
  `;
21
27
  }
22
28
 
@@ -29,12 +35,13 @@ export class TextGroup extends LitElement {
29
35
  margin-left: 10px;
30
36
  vertical-align: middle;
31
37
  font-size: 1.7rem;
38
+ align-items: center;
32
39
  }
33
40
  .hidden {
34
41
  display: none;
35
42
  }
36
43
  .visible {
37
- display: inline-block;
44
+ display: flex;
38
45
  }
39
46
  `;
40
47
  }
@@ -206,8 +206,6 @@ export default class ActionsConfig {
206
206
  id: 'adminAccess',
207
207
  text: 'Admin Access',
208
208
  title: 'You have administrative privileges to read this book',
209
- url: '?admin=1',
210
- target: '_self',
211
209
  className: 'danger',
212
210
  analyticsEvent: {
213
211
  category: this.analyticsCategories.adminAccess,
@@ -30,6 +30,9 @@ export default async function ActionsHandlerService(options) {
30
30
  let formData = new FormData();
31
31
  formData.append('action', option.action);
32
32
  formData.append('identifier', option.identifier);
33
+ formData.append('sticky-admin', option.stickyAccess);
34
+ console.log(option.stickyAccess);
35
+
33
36
  try {
34
37
  await fetch(baseHost, {
35
38
  method: 'POST',
@@ -82,6 +82,11 @@ export default class ActionsHandler extends LitElement {
82
82
  this.addEventListener('adminAccess', ({ detail }) => {
83
83
  const { category, action } = detail.event;
84
84
  this.sendEvent(category, action);
85
+
86
+ // keep existing params and add new one
87
+ const url = new URL(window.location.href);
88
+ url.searchParams.append('admin', 1);
89
+ window.location.search = url.search;
85
90
  });
86
91
 
87
92
  this.addEventListener('exitAdminAccess', ({ detail }) => {
@@ -93,6 +98,16 @@ export default class ActionsHandler extends LitElement {
93
98
  const { category, action } = detail.event;
94
99
  this.sendEvent(category, action);
95
100
  });
101
+
102
+ document.addEventListener('stickyAdminAccessToggled', ({ detail }) => {
103
+ ActionsHandlerService({
104
+ action: 'toggleAdminStickyAccess',
105
+ stickyAccess: detail.hasStickyAdminAccess,
106
+ identifier: this.identifier,
107
+ success: () => {},
108
+ error: () => {},
109
+ });
110
+ });
96
111
  }
97
112
 
98
113
  handleBrowseIt() {
@@ -51,6 +51,7 @@ export const bookTitles = {
51
51
  on_waitlist: 'You are on the waitlist for this book.',
52
52
  session_expired: 'Your loan has expired.',
53
53
  unavailable: 'This book is not available at this time.',
54
+ admin_borrowed: 'Default to admin access mode',
54
55
  };
55
56
 
56
57
  export class GetLendingActions {
@@ -83,7 +84,7 @@ export class GetLendingActions {
83
84
 
84
85
  adminOrPrintDisabledReadingAction() {
85
86
  return {
86
- primaryTitle: '',
87
+ primaryTitle: bookTitles.admin_borrowed,
87
88
  primaryActions: [],
88
89
  secondaryActions: [this.actionsConfig.adminOrPrintDisabledExitConfig()],
89
90
  borrowType: 'adminBorrowed',
@@ -12,6 +12,7 @@ import './components/info-icon.js';
12
12
  import { GetLendingActions } from './core/services/get-lending-actions.js';
13
13
  import { mobileContainerWidth } from './core/config/constants.js';
14
14
  import { LoanTokenPoller } from './core/services/loan-token-poller.js';
15
+ import { setItem } from './core/services/doc-cookies.js';
15
16
 
16
17
  export const events = {
17
18
  browseExpired: 'IABookReader:BrowsingHasExpired',
@@ -36,6 +37,7 @@ export default class IABookActions extends LitElement {
36
37
  disableActionGroup: { type: Boolean },
37
38
  modal: { Object },
38
39
  tokenDelay: { type: Number },
40
+ hasStickyAdminAccess: { Boolean },
39
41
  };
40
42
  }
41
43
 
@@ -54,6 +56,7 @@ export default class IABookActions extends LitElement {
54
56
  this.disableActionGroup = false;
55
57
  this.modal = undefined;
56
58
  this.tokenDelay = 120000; // 2 minutes
59
+ this.hasStickyAdminAccess = false;
57
60
 
58
61
  // private props
59
62
  this.primaryActions = [];
@@ -76,6 +79,9 @@ export default class IABookActions extends LitElement {
76
79
  this.sharedObserver = new SharedResizeObserver();
77
80
  this.setupResizeObserver();
78
81
  }
82
+
83
+ // manage sticky-admin-acces by cookie
84
+ // this.hasStickyAdminAccess = getItem('sticky-admin-access') === 'true';
79
85
  }
80
86
 
81
87
  updated(changed) {
@@ -96,11 +102,8 @@ export default class IABookActions extends LitElement {
96
102
  }
97
103
 
98
104
  startBrowseTimer() {
99
- const {
100
- browsingExpired,
101
- user_has_browsed,
102
- secondsLeftOnLoan,
103
- } = this.lendingStatus;
105
+ const { browsingExpired, user_has_browsed, secondsLeftOnLoan } =
106
+ this.lendingStatus;
104
107
  if (!user_has_browsed || browsingExpired) {
105
108
  return;
106
109
  }
@@ -366,6 +369,22 @@ export default class IABookActions extends LitElement {
366
369
  });
367
370
  }
368
371
 
372
+ // eslint-disable-next-line class-methods-use-this
373
+ toggleStickyAdminAccess() {
374
+ this.hasStickyAdminAccess = !this.hasStickyAdminAccess;
375
+
376
+ // set in cookies
377
+ setItem('sticky-admin-access', this.hasStickyAdminAccess);
378
+
379
+ document.dispatchEvent(
380
+ new CustomEvent('stickyAdminAccessToggled', {
381
+ detail: {
382
+ hasStickyAdminAccess: this.hasStickyAdminAccess,
383
+ },
384
+ })
385
+ );
386
+ }
387
+
369
388
  get iconClass() {
370
389
  return this.width <= mobileContainerWidth ? 'mobile' : 'desktop';
371
390
  }
@@ -382,10 +401,37 @@ export default class IABookActions extends LitElement {
382
401
  return html`<text-group
383
402
  textClass=${this.textClass}
384
403
  texts=${this.primaryTitle}
404
+ ?hasAdminBorrowedAccess=${this.hasAdminBorrowedAccess}
385
405
  >
406
+ ${this.hasAdminBorrowedAccess
407
+ ? html`<div slot="sticky-access-checkbox">
408
+ ${this.stickyAdminAccess}
409
+ </div>`
410
+ : ''}
386
411
  </text-group>`;
387
412
  }
388
413
 
414
+ get stickyAdminAccess() {
415
+ return html`
416
+ <label class="stick-admin" for="sticky-admin-access">
417
+ <input
418
+ type="checkbox"
419
+ id="sticky-admin-access"
420
+ aria-label="Checkbox"
421
+ ?checked=${this.hasStickyAdminAccess}
422
+ @click=${this.toggleStickyAdminAccess}
423
+ />
424
+ <span>${this.primaryTitle}</span>
425
+ </label>
426
+ `;
427
+ }
428
+
429
+ get hasAdminBorrowedAccess() {
430
+ return this.secondaryActions.some(
431
+ action => action.id === 'exitAdminAccess'
432
+ );
433
+ }
434
+
389
435
  get hasAdminAccess() {
390
436
  return !this.lendingStatus.userHasBorrowed && this.lendingStatus.isAdmin;
391
437
  }
@@ -405,6 +451,10 @@ export default class IABookActions extends LitElement {
405
451
  justify-content: center;
406
452
  flex-wrap: wrap;
407
453
  }
454
+ .stick-admin {
455
+ user-select: none;
456
+ cursor: pointer;
457
+ }
408
458
  `;
409
459
  }
410
460
  }
@@ -1,146 +0,0 @@
1
- <!doctype html>
2
- <html lang="en-GB">
3
-
4
- <head>
5
- <meta charset="utf-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7
- <style>
8
- html {
9
- font-size: 10px;
10
- /* This is to match petabox's base font size */
11
- }
12
- body {
13
- margin: 0;
14
- text-align: center;
15
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
16
- }
17
- #demo {
18
- height: 50px;
19
- }
20
- ia-book-actions {
21
- --white: #fff;
22
- --black: #000;
23
- --primaryBGColor: var(--black);
24
- --secondaryBGColor: #222;
25
- --tertiaryBGColor: #333;
26
- --primaryTextColor: var(--white);
27
- --primaryCTAFill: #194880;
28
- --primaryCTABorder: #c5d1df;
29
- --secondaryCTAFill: #333;
30
- --secondaryCTABorder: #999;
31
- --secondaryCTAFillRGB: 51, 51, 51;
32
- --primaryErrorCTAFill: #e51c26;
33
- --primaryErrorCTABorder: #f8c6c8;
34
- --primaryCTAFillRGB: 25, 72, 128;
35
- --primaryErrorCTAFillRGB: 229, 28, 38;
36
- --primaryDisableCTAFill: #767676;
37
- }
38
-
39
- fieldset {
40
- width: fit-content;
41
- margin-top: 50px;
42
- }
43
- fieldset legend {
44
- text-align: left;
45
- font-size: 12px;
46
- }
47
- td {
48
- color: white;
49
- font-size: 14px;
50
- border-radius: 5%;
51
- display: table-cell;
52
- text-align: initial;
53
- margin: 5px 0;
54
- width: max-content;
55
- display: block;
56
- }
57
- label {
58
- padding: 10px;
59
- display: block;
60
- cursor: pointer;
61
- margin: 2px;
62
- background: #4e545a;
63
- border-radius: 10px;
64
- }
65
- input[type="radio"], input[type="checkbox"] {
66
- margin-top: 0;
67
- vertical-align: middle;
68
- }
69
-
70
- .initial td {
71
- float: left;
72
- margin: 2px;
73
- }
74
-
75
- body.modal-manager-open {
76
- overflow: hidden;
77
- }
78
-
79
- modal-manager[mode='closed'] {
80
- display: none;
81
- }
82
- </style>
83
- </head>
84
-
85
- <body>
86
- <ia-bookreader class="focus-on-child-only" signedin="" fullscreen="">
87
- <div slot="header">
88
- <ia-book-actions></ia-book-actions>
89
- </div>
90
- <div slot="main">
91
- <div id="BookReader"></div>
92
- </div>
93
- </ia-bookreader>
94
-
95
-
96
- <script type="module">
97
- /* eslint-disable */
98
- import '@internetarchive/bookreader';
99
- import '@internetarchive/bookreader/BookReader/jquery-1.10.1.js';
100
- import '@internetarchive/bookreader/BookReader/BookReader.js';
101
- import '../src/ia-book-actions.js';
102
- import {
103
- defaultLendingStatus,
104
- canBrowseAndBorrow,
105
- } from '../src/assets/data/lending-get-status-service.js';
106
- import { ModalConfig } from '@internetarchive/modal-manager';
107
-
108
- const userid = '@neeraj-archive';
109
- const identifier = 'naturalhistoryof00unse_4111';
110
- let bwbPurchaseUrl = 'https://www.betterworldbooks.com/product/detail/cambridge-ancient-hist-v04-0521044863';
111
-
112
- let iaBookActions = document.querySelector('ia-book-actions');
113
-
114
- // for debugging
115
- window.iaBookActions = iaBookActions;
116
-
117
- const modalConfig = new ModalConfig();
118
- modalConfig.headerColor = '#d9534f';
119
-
120
- let lendingBarPostInit = function lendingBarPostInit() {
121
- setTimeout(function() {
122
- console.log('executed', 'br.init()');
123
- }, 100);
124
- }
125
-
126
- // set defaultLendingStatus for unavailable (without borrowables) book
127
- iaBookActions.userid = userid;
128
- iaBookActions.identifier = identifier;
129
- iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
130
- iaBookActions.lendingStatus = canBrowseAndBorrow;
131
- iaBookActions.bwbPurchaseUrl = '';
132
- iaBookActions.modalConfig = modalConfig;
133
- iaBookActions.lendingBarPostInit = lendingBarPostInit;
134
- iaBookActions.tokenDelay = 2000; // 2 seconds
135
- iaBookActions.returnUrl = 'https://openlibrary.org';
136
-
137
- let lendingStatus1 = iaBookActions.lendingStatus;
138
-
139
- const manifest = await fetch('https://ia801302.us.archive.org/BookReader/BookReaderJSIA.php?id=goody&itemPath=/29/items/goody&server=ia801302.us.archive.org&format=jsonp&subPrefix=goody&requestUri=/details/goody/mode/1up%3Fview%3Dtheater%26ui%3Dembed%26wrapper%3Dfalse');
140
-
141
- console.log('manifest ****', manifest).then(res => res.json());
142
- </script>
143
-
144
- </div>
145
- </body>
146
- </html>