Advertisement
Guest User

Untitled

a guest
Sep 18th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.35 KB | Source Code | 0 0
  1. export const getBackdrops = () => {
  2.   let xPath = '.backdrop-pending[data-image-src][data-image-key]';
  3.   let id = '';
  4.   const onNoIDB = (el, url) => {
  5.     $(el).removeClass('backdrop-pending').css('background-image', `url('${url}')`);
  6.     if($(xPath).length) setTimeout(getBackdrops, 25);
  7.   }
  8.   const onUndefined = (el, result) => { localImageStore(dbName, storeName.images, id, el, 'ADD', localImageDisplay); }
  9.   const onOutdated = (el, result) => { localImageStore(dbName, storeName.images, id, el, 'PUT', localImageDisplay); }
  10.   const onDefined = (el, blob) => { localImageDisplay(el, blob, false); }
  11.  
  12.   const localImageDisplay = (el, blob, pulled) => {
  13.     $(`.backdrop-pending[data-image-src="${$(el).data('image-src')}"]`)
  14.       .removeClass('backdrop-pending')
  15.       //.data('image-key-idb', id); // Testing purposes
  16.       .css('background-image', `url('${URL.createObjectURL(blob)}')`)
  17.     if($(xPath).length) {
  18.       if(pulled) setTimeout(getBackdrops, 25);
  19.       else getBackdrops();
  20.     }
  21.   }
  22.  
  23.   if($(xPath).length) {
  24.     id = $(`${xPath}:first`).data('image-key');
  25.     localImageCheck(dbName, storeName.images, id, $(`${xPath}:first`), onNoIDB, onUndefined, onOutdated, onDefined);
  26.   }
  27. }
  28.  
  29. export const getPosters = () => {
  30.   let xPath = 'img[data-image-src][data-image-key][src=""]';
  31.   let id = '';
  32.  
  33.   const onNoIDB = (el, url) => {
  34.     $(el).removeClass('d-none').attr('src', url);
  35.     if($(xPath).length) setTimeout(getPosters, 25);
  36.   }
  37.   const onUndefined = (el, result) => { localImageStore(dbName, storeName.images, id, el, 'ADD', localImageDisplay); }
  38.   const onOutdated = (el, result) => { localImageStore(dbName, storeName.images, id, el, 'PUT', localImageDisplay); }
  39.   const onDefined = (el, blob) => { localImageDisplay(el, blob, false); }
  40.  
  41.   const localImageDisplay = (el, blob, pulled) => {
  42.     $(`img[data-image-src="${$(el).data('image-src')}"][src=""]`)
  43.       .removeClass('d-none')
  44.       //.data('image-key-idb', id) // Testing purposes
  45.       .attr('src', URL.createObjectURL(blob));
  46.     if($(xPath).length) {
  47.       if(pulled) setTimeout(getPosters, 25);
  48.       else getPosters();
  49.     }
  50.   }
  51.  
  52.   if($(xPath).length) {
  53.     id = $(`${xPath}:first`).data('image-key');
  54.     localImageCheck(dbName, storeName.images, id, $(`${xPath}:first`), onNoIDB, onUndefined, onOutdated, onDefined);
  55.   }
  56. }
  57.  
  58. getBackdrops();
  59. getPosters();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement