Skip to content
Snippets Groups Projects
Select Git revision
  • 0a4410b1e836cb0ddd4cf58441823705a2f8f503
  • main default
  • 35-cgu
  • 34-peertube-support
  • 27-add-autoplay-to-iframe
  • 33-bug-on-youtube-embed-urls
  • RC-Rekall-v1.1-fix_lpo
  • tuleap-140-go-back-to-my-capsules-page-when-i-m-on-capsule-preview-page
  • RC-Rekall-v1.2-fix10
  • RC-Rekall-v1.2-fix9
  • RC-Rekall-v1.2-fix8
  • RC-Rekall-v1.2-fix7
  • RC-Rekall-v1.2-fix6
  • RC-Rekall-v1.2-fix5
  • RC-Rekall-v1.2-fix4
  • RC-Rekall-v1.2-fix3
  • RC-Rekall-v1.2-fix2
  • RC-Rekall-v1.2-fix1
  • RC-Rekall-v1.1-fix-3
  • RC-Rekall-v1.1-fix-2
  • RC-Rekall-v1.1-fix-1
  • RC-Rekall-v1.1-delivered
  • preprod20220209-1535
23 results

ProjectController.php

Blame
  • CanvasGroupings.js 1.25 KiB
    /**
     *
     */
    export default class CanvasGroupings {
      /**
       */
      constructor(canvases, viewType = 'single') {
        this.canvases = canvases;
        this.viewType = viewType;
        this._groupings = null; // eslint-disable-line no-underscore-dangle
      }
    
      /**
       */
      getCanvases(index) {
        switch (this.viewType) {
          case 'book':
            return this.groupings()[Math.ceil(index / 2)];
          default:
            return this.groupings()[index];
        }
      }
    
      /**
       * Groups a set of canvases based on the view type. Single, is just an array
       * of canvases, while book view creates pairs.
       */
      groupings() {
        if (this._groupings) { // eslint-disable-line no-underscore-dangle
          return this._groupings; // eslint-disable-line no-underscore-dangle
        }
        if (this.viewType === 'single') {
          return this.canvases.map(canvas => [canvas]);
        }
        const groupings = [];
        this.canvases.forEach((canvas, i) => {
          if (i === 0) {
            groupings.push([canvas]);
            return;
          }
          // Odd page
          if (i % 2 !== 0) {
            groupings.push([canvas]);
          } else {
            // Even page
            groupings[Math.ceil(i / 2)].push(canvas);
          }
        });
        this._groupings = groupings; // eslint-disable-line no-underscore-dangle
        return groupings;
      }
    }