/* * This content is licensed according to the W3C Software License at * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document */ 'use strict'; /** * @namespace aria */ var aria = aria || {}; aria.RestaurantData = [ { name: "Tito's Tacos", rating: 5, type: 'Mexican, Tacos', street: '123 Blueberry Ln', citystate: 'San Dimas, CA', phone: '(111) 111-1111', image: '', }, { name: 'Sakura Sushi', rating: 4, type: 'Japanese, Fish, Sushi', street: '123 Blueberry Ln', citystate: 'Pomona, CA', phone: '(111) 111-1111', image: '', }, { name: 'Prime Steakhouse', rating: 4, type: 'Steakhouses', street: '123 Blueberry Ln', citystate: 'Claremont, CA', phone: '(111) 111-1111', image: '', }, { name: 'The Pizza Factory', rating: 4, type: 'Pizza', street: '123 Blueberry Ln', citystate: 'Pomona, CA', phone: '(111) 111-1111', image: '', }, { name: "Emperor's Mongolian", rating: 5, type: 'Mongolian, Barbecue, Buffets', street: '123 Blueberry Ln', citystate: 'La Verne, CA', phone: '(111) 111-1111', image: '', }, { name: 'Backyard Grill', rating: 3, type: 'American, Burgers', street: '123 Blueberry Ln', citystate: 'San Dimas, CA', phone: '(111) 111-1111', image: '', }, { name: 'Taste Kitchen', rating: 4, type: 'American', street: '123 Blueberry Ln', citystate: 'Claremont, CA', phone: '(111) 111-1111', image: '', }, { name: 'Bon Appetit', rating: 4, type: 'French', street: '123 Blueberry Ln', citystate: 'La Verne, CA', phone: '(111) 111-1111', image: '', }, { name: "Sally's Sandwiches", rating: 3, type: 'Sandwiches, American', street: '123 Blueberry Ln', citystate: 'San Dimas, CA', phone: '(111) 111-1111', image: '', }, { name: 'The HotPot Spot', rating: 5, type: 'Hot Pot, Japanese', street: '123 Blueberry Ln', citystate: 'Pomona, CA', phone: '(111) 111-1111', image: '', }, ]; aria.FeedDisplay = function (feed, fetchData) { this.feed = feed; this.feedNode = feed.getFeedNode(); this.fetchData = fetchData; this.currentPage = 0; this.perPage = 10; this.feedSize = 0; this.feedItems = []; this.loading = false; this.loadingDelay = 200; // in milliseconds this.lastChecked = Date.now(); this.loadData(); this.setupEvents(); }; aria.FeedDisplay.prototype.setDelay = function (delay) { this.loadingDelay = delay; }; aria.FeedDisplay.prototype.loadData = function () { var feedData = this.fetchData(this.currentPage, this.perPage); if (!this.feedNode || this.loading) { return; } this.feedNode.setAttribute('aria-busy', 'true'); this.loading = true; var loadingItems = []; Array.prototype.forEach.call( feedData, function (itemData) { var newFeedItem = this.renderItemData(itemData); loadingItems.push(newFeedItem); }, this ); this.delayRender( loadingItems, function () { this.feedNode.removeAttribute('aria-busy'); this.loading = false; this.checkLoadMore(); }.bind(this) ); }; aria.FeedDisplay.prototype.delayRender = function (items, onRenderDone) { if (!items || !items.length) { onRenderDone(); return; } var newFeedItem = items.shift(); this.feedNode.appendChild(newFeedItem); this.feedItems.push(newFeedItem); this.feed.addItem(newFeedItem); this.feedItems.forEach(function (feedItem) { feedItem.setAttribute('aria-setsize', this.feedItems.length); }, this); setTimeout( function () { this.delayRender(items, onRenderDone); }.bind(this), this.loadingDelay ); }; aria.FeedDisplay.prototype.renderItemData = function (itemData) { var feedItem = document.createElement('div'); this.feedSize++; feedItem.setAttribute('role', 'article'); feedItem.className = 'restaurant-item'; feedItem.setAttribute('aria-posinset', this.feedSize); feedItem.setAttribute('tabindex', '0'); var itemDetails = document.createElement('div'); itemDetails.className = 'restaurant-details'; var itemContent = ''; var describedbyIDs = []; var restaurantID = 'restaurant-name-' + this.feedSize; feedItem.setAttribute('aria-labelledby', restaurantID); if (itemData.image) { itemContent += '