npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery.mobile.lazyloader

v4.0.1

Published

Lazyloading (i.e. loading the content as it's needed during a scroll of a listview or similar control) is a great way to optimize the performance of any app that contains a list of 50 or more items. With the LazyLoader Widget for jQuery Mobile, you can

Downloads

584

Readme

LazyLoader Widget for jQuery Mobile

Lazyloading (i.e. loading the content as it's needed during a scroll of a listview or similar control) is a great way to optimize the performance of any app that contains a list of 50 or more items. With the LazyLoader Widget for jQuery Mobile, you can easily lazyload any listview without having to write a bunch of custom code to accomplish it.

Note: This is only the client-side part of the lazyloading solution. It requires a server-side resource that returns a simple JSON formatted string. Details and examples can be found below.

Build Status Coverage Status npm version

Contents

Requirements

  • jQuery (Tested with v2.2.4)
  • jQuery Mobile (Tested with v1.4.5)
  • Mustache (Tested with v4.2.0)
  • Server-side code to handle the AJAX requests

Install

$ npm install --save jquery.mobile.lazyloader

Run the following grunt command in case the dist directory doesn't exist:

$ grunt dist

Usage

Include the following files:

<link rel="stylesheet" href="node_modules/jquery-mobile/dist/jquery.mobile.min.css"/>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/jquery-mobile/dist/jquery.mobile.min.js"></script>
<script src="node_modules/mustache/mustache.min.js"></script>
<script src="node_modules/jquery.mobile.lazyloader/dist/jquery.mobile.lazyloader.min.js"></script>

Include a template in the <head>:

<script id="user" type="text/html">
	<li>
		<p class="name">Hello I'm {{ name }}</p>
	</li>
</script>

Add a list and optionally an element that indicates progress is going on:

<ul id="myListView"></ul>
<div id="myProgress" style="position: fixed; top: 50%; left: 50%; display: none">Loading...</div>

Initialize the widget with the url to get the data from and the id of the template:

$(function() {
	// Initialize the lazyloader widget
	$("#myListView").lazyloader({
		url: 'http://server.com', 
		templateId: "user", 
		$progress: "#myProgress"
	});
});

Filterable

If you are using the filterable widget in combination with this widget, the default behaviour is changed to filtering server side. The searchQuery option is set to the filter input when its content is changed. This will cause the reset function with the modified searchQuery option to be called. You are responsible for applying the filter server-side.

Server request

The request made out to the server will contain the following data:

  • retrieve: {number} The number of items to be retrieved.
  • retrieved: {number} The current number of retrieved items.
  • reset: {boolean} Whether or not the server data should be reset.
  • searchQuery: {string|null} The search query to filter with.

Server response

The server response is expected to be in a JSON format with the mandatory items key that must contain an array of objects, each representing a list item to be rendered.

{
	"items": [
		{"name": "John"}
	]
}

Options

Functions

loadMore

Loads more items.

$("#myListView").lazyloader("loadMore", timeout);
  • timeout: {number} The timeout before a request is sent. Defaults to the loadMoreTimeout option.

reset

Empties the list, sets the retrieved option back to 0 and sends a request for more items to the server, while also indicating a reset has been performed.

$("#myListView").lazyloader("reset", timeout);
  • timeout: {number} The timeout before a request is sent. Defaults to the loadMoreTimeout option.

Events

The lazyloader triggers several events during certain operations. Here are examples of how to listen for the events:

lazyloaderdoneloading

Raised when a request for more items is completed.

$("#myListView").on("lazyloaderdoneloading", function ( evt, items, data ){ });
  • evt: {JQuery.Event} The jQuery event.

  • items: {Object[]} An array of loaded items.

  • data: {Object} The complete JSON data returned in the response.

lazyloaderskiploading

Raised when loading of items is skipped.

$("#myListView").on("lazyloaderskiploading", function ( evt ){ });
  • evt: {JQuery.Event} The jQuery event.

lazyloaderalldone

Raised when all items have been loaded. No more requests will be sent after this event has been raised.

$("#myListView").on("lazyloaderalldone", function ( evt ){ });
  • evt: {JQuery.Event} The jQuery event.

lazyloaderreset

Raised before a reset request is made.

$("#myListView").on("lazyloaderreset", function ( evt ){ });
  • evt: {JQuery.Event} The jQuery event.

lazyloaderbeforerender

Raised before the loaded items are rendered. This allows you to modify the data before it's rendered in the list.

$("#myListView").on("lazyloaderbeforerender", function ( evt, items, data ){ });
  • evt: {JQuery.Event} The jQuery event.

  • items: {Object[]} An array of loaded items.

  • data: {Object} The complete JSON data returned in the response.

lazyloadererror

Raise when an error occurred with the ajax request or when parsing the result

$("#myListView").on("lazyloadererror", function ( evt, error ){ });
  • evt: {JQuery.Event} The jQuery event.

  • error: {Object} An object containing information about the error that occured.

    • errorCode: {number} The error code.

      Error codes

      • 1: An error occurred with the request.
      • 2: An error occurred parsing the response data.
      • 3: The specified template does not exist.
    • errorData: {*} The data offering more information about the error.

Sample

Navigate to the jquery.mobile.lazyloader directory and run the following command in a console to start the server and open the sample page:

npm start