UNPKG

rizzo-next

Version:

The next generation of Lonely Planet's style guide and pattern library.

448 lines (400 loc) 32.6 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../../../"> <title data-ice="title">src/components/things_to_do/things_to_do.js | API Document</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> <link data-ice="userStyle" rel="stylesheet" href="user/css/0-docs.css"> </head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <a href="test.html" data-ice="testLink">Test</a> <a data-ice="repoURL" href="https://github.com/lonelyplanet/rizzo-next.git" class="repo-url-github">Repository</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> </header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-rizzo">rizzo</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/action_sheet</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/action_sheet/index.js~ActionSheetComponent.html">ActionSheetComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-actionSheetComponent">actionSheetComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/article_body</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/article_body/index.js~ArticleBodyComponent.html">ArticleBodyComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/articles</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/articles/index.js~ArticlesComponent.html">ArticlesComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-articlesComponent">articlesComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/footer</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/footer/footer_component.js~Footer.html">Footer</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-footer">footer</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/header</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/header/header_component.js~Header.html">Header</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-header">header</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/hotels</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/hotels/hotels_widget.js~HotelsWidget.html">HotelsWidget</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-hotelsWidget">hotelsWidget</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/image_gallery</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/image_gallery/image_gallery.js~ImageGalleryComponent.html">ImageGalleryComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/login</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/login/login_manager.js~LoginManager.html">LoginManager</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/login/user.js~User.html">User</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/map</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/interactive-map.js~InteractiveMap.html">InteractiveMap</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/map_component.js~MapComponent.html">MapComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-MapActions">MapActions</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-MapAPI">MapAPI</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-interactiveMap">interactiveMap</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-mapComponent">mapComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-MapState">MapState</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/map/mapbox</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/mapbox/index.js~MapProvider.html">MapProvider</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/mapbox/markerset.js~MarkerSet.html">MarkerSet</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-mapProvider">mapProvider</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-markerSet">markerSet</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/map/views</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/about-panel.jsx~AboutPanel.html">AboutPanel</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/alert.jsx~AlertView.html">AlertView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/item.jsx~ItemView.html">ItemView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/main.jsx~MainView.html">MainView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/map.jsx~MapView.html">MapView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/panel.jsx~PanelView.html">PanelView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/pin.jsx~PinView.html">PinView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/sidebar-details.jsx~SidebarDetailsView.html">SidebarDetailsView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/sidebar-dropdown.jsx~SidebarDropdown.html">SidebarDropdown</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/sidebar-fetching.jsx~SidebarFetchingView.html">SidebarFetchingView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/sidebar.jsx~SidebarView.html">SidebarView</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/map/views/tab.jsx~TabView.html">TabView</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/masthead</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/masthead/masthead_component.js~MastheadComponent.html">MastheadComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/navigation</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/navigation/navigation_component.js~NavigationComponent.html">NavigationComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-NavigationActions">NavigationActions</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-navigationComponent">navigationComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-NavigationState">NavigationState</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/notification</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/notification/notification.js~Notification.html">Notification</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-notification">notification</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/overlay</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/overlay/index.js~Overlay.html">Overlay</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-overlay">overlay</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/related_guidebook</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/related_guidebook/index.js~RelatedGuidebookComponent.html">RelatedGuidebookComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-relatedGuidebookComponent">relatedGuidebookComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/search</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/search/search_component.js~SearchComponent.html">SearchComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-SearchActions">SearchActions</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-SearchApi">SearchApi</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-searchComponent">searchComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-SearchServerActions">SearchServerActions</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-SearchState">SearchState</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/search/search_item</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/search/search_item/index.js~SearchItemComponent.html">SearchItemComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-searchItemComponent">searchItemComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/slideshow</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/slideshow/slide_component.js~SlideComponent.html">SlideComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/slideshow/slideshow.js~Slideshow.html">Slideshow</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-slideComponent">slideComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/stacks</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/stacks/stack_component.js~Stack.html">Stack</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-StackActions">StackActions</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-stack">stack</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-StackState">StackState</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/sub_nav</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/sub_nav/index.js~SubNav.html">SubNav</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/tabs</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/tabs/tabs_component.js~Tabs.html">Tabs</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/things_to_do</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/things_to_do/things_to_do.js~ThingsToDo.html">ThingsToDo</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-thingsToDo">thingsToDo</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/tooltip</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/tooltip/tooltip.js~Tooltip.html">Tooltip</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-tooltip">tooltip</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/top_places</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/top_places/top_places_component.js~TopPlaces.html">TopPlaces</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-topPlaces">topPlaces</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/tours</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/tours/index.js~ToursComponent.html">ToursComponent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-toursComponent">toursComponent</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/usabilla</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/usabilla/index.js~Usabilla.html">Usabilla</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-usabilla">usabilla</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">components/video</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/video/brightcove.js~Brightcove.html">Brightcove</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/video/index.js~Video.html">Video</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/components/video/video_player.js~VideoPlayer.html">VideoPlayer</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-brightcove">brightcove</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-video">video</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-videoPlayer">videoPlayer</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">core</div><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/component.js~Component.html">Component</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/component_registry.js~ComponentRegistry.html">ComponentRegistry</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/cookie_util.js~CookieUtil.html">CookieUtil</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/logger.js~Logger.html">Logger</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/mobile_util.js~MobileUtil.html">MobileUtil</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/perf_monitor.js~PerfMonitor.html">PerfMonitor</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/rizzo.js~Rizzo.html">Rizzo</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/core/shop_cookie_util.js~ShopCookieUtil.html">ShopCookieUtil</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Arkham">Arkham</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-mobileUtil">mobileUtil</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-shopCookieUtil">shopCookieUtil</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">core/decorators</div><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-channel">channel</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-publish">publish</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-subscribe">subscribe</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">core/mixins</div><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Events">Events</a></span></span></li> <li data-ice="doc"><div data-ice="dirPath" class="nav-dir-path">core/utils</div><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-highlight">highlight</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-getScrollbarWidth">getScrollbarWidth</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-mark">mark</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-measure">measure</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><h1 data-ice="title">src/components/things_to_do/things_to_do.js</h1> <pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import Component from &quot;../../core/component&quot;; import waitForTransition from &quot;../../core/utils/waitForTransition&quot;; import publish from &quot;../../core/decorators/publish&quot;; import $clamp from &quot;clamp-js/clamp.js&quot;; import rizzo from &quot;../../rizzo&quot;; class ThingsToDo extends Component { get title() { return `Top experiences in ${window.lp.place.name}`; } initialize() { this.currentIndex = (this.getCurrentIndex()) || 0; this.options = { numOfCards: 4 }; this.events = { &quot;click .js-ttd-more&quot;: &quot;loadMore&quot;, &quot;click .js-ttd-less&quot;: &quot;loadPrevious&quot;, &quot;swiperight&quot;: &quot;loadPrevious&quot;, &quot;swipeleft&quot;: &quot;loadMore&quot; }; this.fetchCards().done(this.cardsFetched.bind(this)).fail((jqXHR) =&gt; { rizzo.logger.error({ error: jqXHR.responseText }); return this.nukeIt(); }); } getCurrentIndex() { let obj = window.localStorage &amp;&amp; JSON.parse(window.localStorage.getItem(&quot;ttd.currentIndex&quot;)); if (!obj || obj.slug !== window.lp.place.slug) { return; } return obj.index; } fetchCards() { return $.ajax({ url: `/api/${window.lp.place.slug}/experiences` }); } @publish(&quot;ttd.removed&quot;) nukeIt() { $(&quot;#ttd&quot;).remove(); } // TODO: jc this is... smelly cardsFetched(cards) { if (!cards.length) { return this.nukeIt(); } this.$el.prepend($(`&lt;h2 class=&apos;ttd__heading&apos;&gt;${this.title}&lt;/h2&gt;`)); this.cards = cards; if (cards.length &gt; 4) { this.addNavigationButtons(); } if (this.currentIndex &gt;= this.options.numOfCards) { this.showPrevious(); } if (this.currentIndex + 4 &gt;= this.cards.length) { this.hideShowMore(); } this.template = require(&quot;./thing_to_do_card.hbs&quot;); this.render(this.nextCards()); this.clampImageCardTitle(); } addNavigationButtons() { let $left = $(&quot;&lt;div /&gt;&quot;, { &quot;class&quot;: &quot;has-more--left is-invisible&quot;}); // Lazy? Maybe... awesome? YES $left.html(` &lt;button class=&quot;ttd__less js-ttd-less&quot;&gt; &lt;i class=&quot;ttd__more__icon icon-chevron-left&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt; &lt;/button&gt; `); this.$el.find(&quot;.js-ttd-list&quot;).before($left); let $right = $(&quot;&lt;div /&gt;&quot;, { &quot;class&quot;: &quot;has-more--right&quot;}); $right.html(` &lt;button class=&quot;ttd__more js-ttd-more&quot;&gt; &lt;i class=&quot;ttd__more__icon icon-chevron-right&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt; &lt;/button&gt; `); this.$el.find(&quot;.js-ttd-list&quot;).after($right); } /** * Get the next 4 cards to render * @return {Array} An array of rendered templates */ nextCards() { if (this.currentIndex &gt;= this.cards.length) { this.currentIndex = 0; } else if (this.currentIndex &lt; 0) { this.currentIndex = this.cards.length - ((this.cards.length % this.options.numOfCards) || this.options.numOfCards); } return this.cards.slice(this.currentIndex, this.currentIndex + this.options.numOfCards) .map((card, i) =&gt; { Object.assign(card.card, { card_num: i + this.currentIndex + 1, order: i }); return this.template(card); }); } render(cards) { this.$el.find(&quot;.js-ttd-list&quot;).html(cards.join(&quot;&quot;)); this.loadImages(this.$el.find(&quot;.js-image-card-image&quot;)); } loadImages(images) { let imagePromises = []; images.each((index, element) =&gt; { let $el = $(element), imageUrl = $el.data(&quot;image-url&quot;), backupUrl = $el.data(&quot;backupimage-url&quot;); imagePromises.push(this.lazyLoadImage(imageUrl) .then(undefined, () =&gt; { return this.lazyLoadImage(backupUrl); }) .then((url) =&gt; { $el.css({ &quot;background-image&quot;: &quot;url(&quot; + url + &quot;)&quot; }) .addClass(&quot;is-visible&quot;); })); }); return Promise.all(imagePromises); } makeNextList() { let cards = this.nextCards(); if (window.localStorage) { window.localStorage.setItem(&quot;ttd.currentIndex&quot;, JSON.stringify({ index: this.currentIndex, slug: window.lp.place.slug })); } // Create a new list and place it on top of existing list return $(&quot;&lt;ul /&gt;&quot;, { &quot;class&quot;: &quot;ttd__list js-ttd-list&quot; }) .append(cards); } animate(reverse=false) { let $list = this.$el.find(&quot;.js-ttd-list&quot;), ttdComponentWidth = this.$el.width(); let $nextList = this.makeNextList(); $nextList.css({ &quot;margin-top&quot;: `-${$list.outerHeight(true)}px`, &quot;transform&quot;: `translate3d(${reverse ? &quot;-&quot; : &quot;&quot;}${ttdComponentWidth}px, 0, 0)` }); this.loadImages($nextList.find(&quot;.js-image-card-image&quot;)); this.animating = true; $list.after($nextList) .css(&quot;transform&quot;, `translate3d(${reverse ? &quot;&quot; : &quot;-&quot;}${ttdComponentWidth}px, 0, 0)`); setTimeout(() =&gt; { $nextList .css(&quot;transform&quot;, &quot;translate3d(0, 0, 0)&quot;); }, 30); if (!reverse &amp;&amp; this.currentIndex + 4 &gt;= this.cards.length) { this.hideShowMore(); } else if (reverse &amp;&amp; this.currentIndex - 4 &lt; 0) { this.hideShowPrevious(); } return waitForTransition($nextList, { fallbackTime: 300 }) .then(() =&gt; { $list.remove(); $nextList.css(&quot;margin-top&quot;, 0); this.animating = false; }); } /** * Load more top things to do. Callback from click on load more button. * @param {jQuery.Event} e The DOM event */ @publish(&quot;ttd.loadmore&quot;); loadMore(e) { e.preventDefault(); if (this.animating || this.currentIndex + 4 &gt;= this.cards.length) { return; } // Grab the next 4 images this.showMoreAndPrevious(); this.currentIndex += this.options.numOfCards; // Forward this.animate(); return { &quot;direction&quot;: &quot;forward&quot; }; } @publish(&quot;ttd.loadmore&quot;); loadPrevious(e) { e.preventDefault(); if (this.animating || this.currentIndex - 4 &lt; 0) { return; } // Grab the next 4 images this.showMoreAndPrevious(); this.currentIndex -= this.options.numOfCards; // Reverse this.animate(true); return { &quot;direction&quot;: &quot;reverse&quot; }; } showMore() { this.$el.find(&quot;.has-more--right&quot;).removeClass(&quot;is-invisible&quot;); this.$el.find(&quot;.js-ttd-more&quot;).removeClass(&quot;is-invisible&quot;); } showPrevious() { this.$el.find(&quot;.has-more--left&quot;).removeClass(&quot;is-invisible&quot;); this.$el.find(&quot;.js-ttd-less&quot;).removeClass(&quot;is-invisible&quot;); } showMoreAndPrevious() { this.showMore(); this.showPrevious(); } hideShowMore() { this.$el.find(&quot;.js-ttd-more&quot;).addClass(&quot;is-invisible&quot;); this.$el.find(&quot;.has-more--right&quot;).addClass(&quot;is-invisible&quot;); } hideShowPrevious() { this.$el.find(&quot;.js-ttd-less&quot;).addClass(&quot;is-invisible&quot;); this.$el.find(&quot;.has-more--left&quot;).addClass(&quot;is-invisible&quot;); } /** * Lazy load an image * @param {String} url Image url to lazy load * @return {Promise} A promise that resolves when the image has loaded */ lazyLoadImage(url) { let self = this, image = new Image(); this.imagePromises = this.imagePromises || {}; if (this.imagePromises[url]) { return this.imagePromises[url]; } let promise = new Promise((resolve, reject) =&gt; { image.src = url; image.onload = function() { // Only cache the promise when it&apos;s successfully loading an image self.imagePromises[url] = promise; resolve(url); }; image.onerror = function() { reject(); }; if (!url) { reject(); } }); return promise; } /** * Clamp a card title * @return null */ clampImageCardTitle() { $.each($(&quot;.js-image-card-title&quot;), function() { $clamp($(this).get(0), { clamp: 2 }); }); } } export default ThingsToDo; </code></pre> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.4.3)</span></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>