PageSourceSearch

https://www.label-emmaus.co/static/js/alpine/custom/selection/selection-preferences-store.js?v=204e6a99b7

js label-emmaus.co collected 2026-10-02 05:01:30 UTC 2,345 bytes, 83 lines download raw bytes

1/**
2 * selection-preferences-store.js
3 *
4 * Alpine.js global store for managing selection display preferences.
5 * This store handles:
6 * - showImages preference persistence via cookies
7 * - Synchronization across all selection displays
8 */
9
10document.addEventListener('alpine:init', () => {
11  /**
12   * Global selection preferences store
13   * Manages user preferences for selection display
14   */
15  Alpine.store('selectionPreferences', {
16    // Whether to show ambient images on selection cards
17    showImages: false,
18
19    /**
20     * Initialize the store by loading saved preferences from cookies
21     */
22    init() {
23      this.loadFromCookie();
24    },
25
26    /**
27     * Get a cookie value by name
28     * @param {string} name - The cookie name
29     * @returns {string|null} - The cookie value or null if not found
30     */
31    getCookie(name) {
32      const value = `; ${document.cookie}`;
33      const parts = value.split(`; ${name}=`);
34      if (parts.length === 2) {
35        return parts.pop().split(';').shift();
36      }
37      return null;
38    },
39
40    /**
41     * Set a cookie with a value
42     * @param {string} name - The cookie name
43     * @param {string} value - The cookie value
44     * @param {number} days - Number of days until expiration (default: 365)
45     */
46    setCookie(name, value, days = 365) {
47      const date = new Date();
48      date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
49      const expires = `expires=${date.toUTCString()}`;
50      document.cookie = `${name}=${value};${expires};path=/;SameSite=Lax`;
51    },
52
53    /**
54     * Load preferences from cookie
55     */
56    loadFromCookie() {
57      const saved = this.getCookie('selection_show_images');
58      if (saved !== null) {
59        this.showImages = saved === 'true';
60      }
61    },
62
63    /**
64     * Toggle the showImages preference and save to cookie
65     */
66    toggleShowImages() {
67      this.showImages = !this.showImages;
68      this.setCookie('selection_show_images', this.showImages.toString());
69    },
70
71    /**
72     * Set showImages preference explicitly
73     * @param {boolean} value - The new value for showImages
74     */
75    setShowImages(value) {
76      this.showImages = value;
77      this.setCookie('selection_show_images', value.toString());
78    },
79  });
80
81  // Initialize the store when Alpine is ready
82  Alpine.store('selectionPreferences').init();
83});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.