[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/js/ -> dynamic-groups.js (source)

   1  // modules are defined as an array
   2  // [ module function, map of requires ]
   3  //
   4  // map of requires is short require name -> numeric require
   5  //
   6  // anything defined in a previous bundle is accessed via the
   7  // orig method which is the require for previous bundles
   8  parcelRequire = (function (modules, cache, entry, globalName) {
   9    // Save the require from previous bundle to this closure if any
  10    var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
  11    var nodeRequire = typeof require === 'function' && require;
  12  
  13    function newRequire(name, jumped) {
  14      if (!cache[name]) {
  15        if (!modules[name]) {
  16          // if we cannot find the module within our internal map or
  17          // cache jump to the current global require ie. the last bundle
  18          // that was added to the page.
  19          var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
  20          if (!jumped && currentRequire) {
  21            return currentRequire(name, true);
  22          }
  23  
  24          // If there are other bundles on this page the require from the
  25          // previous one is saved to 'previousRequire'. Repeat this as
  26          // many times as there are bundles until the module is found or
  27          // we exhaust the require chain.
  28          if (previousRequire) {
  29            return previousRequire(name, true);
  30          }
  31  
  32          // Try the node require function if it exists.
  33          if (nodeRequire && typeof name === 'string') {
  34            return nodeRequire(name);
  35          }
  36  
  37          var err = new Error('Cannot find module \'' + name + '\'');
  38          err.code = 'MODULE_NOT_FOUND';
  39          throw err;
  40        }
  41  
  42        localRequire.resolve = resolve;
  43        localRequire.cache = {};
  44  
  45        var module = cache[name] = new newRequire.Module(name);
  46  
  47        modules[name][0].call(module.exports, localRequire, module, module.exports, this);
  48      }
  49  
  50      return cache[name].exports;
  51  
  52      function localRequire(x){
  53        return newRequire(localRequire.resolve(x));
  54      }
  55  
  56      function resolve(x){
  57        return modules[name][1][x] || x;
  58      }
  59    }
  60  
  61    function Module(moduleName) {
  62      this.id = moduleName;
  63      this.bundle = newRequire;
  64      this.exports = {};
  65    }
  66  
  67    newRequire.isParcelRequire = true;
  68    newRequire.Module = Module;
  69    newRequire.modules = modules;
  70    newRequire.cache = cache;
  71    newRequire.parent = previousRequire;
  72    newRequire.register = function (id, exports) {
  73      modules[id] = [function (require, module) {
  74        module.exports = exports;
  75      }, {}];
  76    };
  77  
  78    var error;
  79    for (var i = 0; i < entry.length; i++) {
  80      try {
  81        newRequire(entry[i]);
  82      } catch (e) {
  83        // Save first error but execute all entries
  84        if (!error) {
  85          error = e;
  86        }
  87      }
  88    }
  89  
  90    if (entry.length) {
  91      // Expose entry point to Node, AMD or browser globals
  92      // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
  93      var mainExports = newRequire(entry[entry.length - 1]);
  94  
  95      // CommonJS
  96      if (typeof exports === "object" && typeof module !== "undefined") {
  97        module.exports = mainExports;
  98  
  99      // RequireJS
 100      } else if (typeof define === "function" && define.amd) {
 101       define(function () {
 102         return mainExports;
 103       });
 104  
 105      // <script>
 106      } else if (globalName) {
 107        this[globalName] = mainExports;
 108      }
 109    }
 110  
 111    // Override the current require with this new one
 112    parcelRequire = newRequire;
 113  
 114    if (error) {
 115      // throw error from earlier, _after updating parcelRequire_
 116      throw error;
 117    }
 118  
 119    return newRequire;
 120  })({"UOvc":[function(require,module,exports) {
 121  /**
 122   * WordPress dependencies
 123   */
 124  const {
 125    i18n: {
 126      __,
 127      sprintf
 128    }
 129  } = wp;
 130  /**
 131   * BuddyPress dependencies.
 132   */
 133  
 134  const {
 135    dynamicWidgetBlock
 136  } = bp;
 137  /**
 138   * Front-end Dynamic Groups Widget Block class.
 139   *
 140   * @since 9.0.0
 141   */
 142  
 143  class bpGroupsWidgetBlock extends dynamicWidgetBlock {
 144    loop(groups = [], container = '', type = 'active') {
 145      const tmpl = super.useTemplate('bp-dynamic-groups-item');
 146      const selector = document.querySelector('#' + container);
 147      let output = '';
 148  
 149      if (groups && groups.length) {
 150        groups.forEach(group => {
 151          if ('newest' === type && group.created_since) {
 152            /* translators: %s is time elapsed since the group was created */
 153            group.extra = sprintf(__('Created %s', 'buddypress'), group.created_since);
 154          } else if ('popular' === type && group.total_member_count) {
 155            const membersCount = parseInt(group.total_member_count, 10);
 156  
 157            if (0 === membersCount) {
 158              group.extra = __('No members', 'buddypress');
 159            } else if (1 === membersCount) {
 160              group.extra = __('1 member', 'buddypress');
 161            } else {
 162              /* translators: %s is the number of Group members (more than 1). */
 163              group.extra = sprintf(__('%s members', 'buddypress'), group.total_member_count);
 164            }
 165          } else {
 166            /* translators: %s: a human time diff. */
 167            group.extra = sprintf(__('Active %s', 'buddypress'), group.last_activity_diff);
 168          }
 169          /* Translators: %s is the group's name. */
 170  
 171  
 172          group.avatar_alt = sprintf(__('Group Profile photo of %s', 'buddypress'), group.name);
 173          output += tmpl(group);
 174        });
 175      } else {
 176        output = '<div class="widget-error">' + __('There are no groups to display.', 'buddypress') + '</div>';
 177      }
 178  
 179      selector.innerHTML = output;
 180    }
 181  
 182    start() {
 183      this.blocks.forEach((block, i) => {
 184        const {
 185          selector
 186        } = block;
 187        const {
 188          type
 189        } = block.query_args;
 190        const list = document.querySelector('#' + selector).closest('.bp-dynamic-block-container'); // Get default Block's type groups.
 191  
 192        super.getItems(type, i); // Listen to Block's Nav item clics
 193  
 194        list.querySelectorAll('.item-options a').forEach(navItem => {
 195          navItem.addEventListener('click', event => {
 196            event.preventDefault(); // Changes the displayed filter.
 197  
 198            event.target.closest('.item-options').querySelector('.selected').classList.remove('selected');
 199            event.target.classList.add('selected');
 200            const newType = event.target.getAttribute('data-bp-sort');
 201  
 202            if (newType !== this.blocks[i].query_args.type) {
 203              super.getItems(newType, i);
 204            }
 205          });
 206        });
 207      });
 208    }
 209  
 210  }
 211  
 212  const settings = window.bpDynamicGroupsSettings || {};
 213  const blocks = window.bpDynamicGroupsBlocks || [];
 214  const bpDynamicGroups = new bpGroupsWidgetBlock(settings, blocks);
 215  
 216  if ('loading' === document.readyState) {
 217    document.addEventListener('DOMContentLoaded', bpDynamicGroups.start());
 218  } else {
 219    bpDynamicGroups.start();
 220  }
 221  },{}]},{},["UOvc"], null)


Generated: Sat Jun 3 01:01:23 2023 Cross-referenced by PHPXref 0.7.1