JAVASCRIPT 30
Mediaconfig.js Guest on 30th July 2020 12:51:26 PM
  1. define('core/mediaConfig',[
  2.     'underscore',
  3.     'backbone',
  4. ], function (
  5.     _,
  6.     Backbone
  7. ) {
  8.     'use strict';
  9.  
  10.     var MEDIA_PERSISTED_WIDTHS = [320, 480, 600, 800];
  11.  
  12.     // Calculates closest thumbnail width based on available
  13.     // width (document.body.offsetWidth) and caches this value
  14.     // for future use by PostView.
  15.     function findClosestThumbnailSize() {
  16.         var width = window.document.body.offsetWidth;
  17.  
  18.         // get closest image width we have to @width argument
  19.         var thumbnailsWidths = MEDIA_PERSISTED_WIDTHS;
  20.         var len = thumbnailsWidths.length;
  21.  
  22.         return _.find(thumbnailsWidths, function (__, i) {
  23.             return (i + 1 === len) ||
  24.                 (Math.abs(thumbnailsWidths[i + 1] - width) > Math.abs(thumbnailsWidths[i] - width));
  25.         });
  26.     }
  27.  
  28.     var config = new Backbone.Model({
  29.         collapsed: false,
  30.  
  31.         defaultIframeHeight: 300,
  32.         mediaPersistedWidths: MEDIA_PERSISTED_WIDTHS,
  33.  
  34.         loadedThumbnailWidth: findClosestThumbnailSize(),
  35.     });
  36.  
  37.     // for testing
  38.     config.findClosestThumbnailSize = findClosestThumbnailSize;
  39.  
  40.     return config;
  41. });

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.