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

web-pull-to-refresh

v1.0.1

Published

- [Intro](https://github.com/movii/web-pull-to-refresh/blob/master/README.md#intro) - [Scan the QRCode to preview](https://github.com/movii/web-pull-to-refresh/blob/master/README.md#scan-the-qrcode-to-preview) - [Screenshots](https://github.com/movii/web-

Downloads

14

Readme

web-pull-to-refresh

Intro

Scan the QRCode to preview

Scan the QRCode below to preview the example (which source code is provided in gh-pages branch).

  1. Pull down then let go to see pull-to-refresh effect;
  2. Tap the button in bottom right corner to manually trigger a pull-to action;
  3. After manually trigger, there is Promise returned so you can make use of it by simply chain a .then().
  4. No third-party library required.
  5. Build with Webpack@3.
  6. Support preventing mobile Chrome's default pull to refresh features (reference doc, emample, and related StackOverflow question).

Screenshots

Gif recorded on my Mac

Download

Via Github

Clone or open the ./dist, grab ptr.js and ptr.css, place them wherever you want.

<link rel="stylesheet" href="path/to/ptr.css">
<script src="/path/to/ptr.js"></script>

Via NPM

npm install web-pull-to-refresh --save

Installation

CSS file should always be required

<link rel="stylesheet" href="dist/ptr.css">

Using window

<srcipt src="/path/to/ptr.js"></script>
<script>
  const options = {/*...*/}
  new PTR(options)
</script>

Using AMD with require.js

For example the entry you set is main.js, in the html file should be like this:

<script data-main="main" src="lib/require.js"></script>

then in the main.js, require the ptr:

define(['./dist/ptr'], (PTR) => {
  const options = {/*...*/}
  new PTR(options)
}
// or
define(require => {
  const PTR = require('./dist/ptr')
  const options = {/*...*/}
  new PTR(options)
})

Import with Webpack

import PTR from 'web-pull-to-refresh'

const options = {/*...*/}
new PTR(options)

When use Webpack it could be serval different way to import CSS depends on different situation:

  1. Import the file in an entry CSS file,
  2. Load CSS directly in html using <link> tag,
  3. Or import CSS in JavaScript file then let Webpack take care of the rest.

But the path will stay the same: ./node_modules/web-pull-to-refresh/dist/ptr.css.

Usage

Basic Usage

Firstly there is certain HTML structure and CSS needed.

<!-- html -->
<div class="ptr-wrapper">
  <div class="ptr">
    <span class="status-arrow"></span>
    <span class="status-loader"></span>
    <span class="status-text">pull more</span>
  </div>
  <div class="content">
    <ul></ul>
  </div>
</div>

❗️Note the refresher callback passed in require a Promise returned.


const refresher = (statusText) => {
  return new Promise((resolve) => {
     setTimeout(() => {
       alert('new refresher')
       resolve()
     }, 2000)
  })
}

const options = {
  contain: $('.ptr-wrapper'),
  header: $('.ptr-wrapper .ptr'),
  content: $('.ptr-wrapper .content'),
  distanceToRefresh: 50,
  pullDownText: 'Pull down',
  releaseText: 'Release to refresh',
  refreshText: 'Updating',
  finishText: 'Done Refresh',
  refresher: refresher
}

const ptr = new PTR(options)

Change statusText within refresher callback

statusText refers to the top-bar shown when pull-to action take place.

See the options passed in the PTR constructor, there are four different String value for four different status. The final one finishText will show when entire pull-to-refresh action finish.

But in real world, most situation here is make an AJAX call to load some more data, and then the text could result in 'Update successfully', 'Error loading, try again later', or 'Nothing new'.

So the refresher callback take a statusText parameter in, with which you can easily change statusText shown depends on certain conditions.

❗️Note using statusText will overwrite the option's finishText.

const refresher = (statuText) => {
  if (condition) {
    statuText = 'success'
  }
  else {
    statuText = 'error'
  }
}

Manually trigger with .trigger()

new PTR(options) will return an object with a method called .trigger(), you can use it to manually trigger a pull-to-refresh action, which will also fire the refresher() callback

Then, .trigger() itself returns a Promise, you can chain a .then() directly to fire certain action immediately after action take place.

For example there is a button in html with a class .button-to-trigger, the code would be:

const ptr = PTR(options)

$('.button-to-trigger').on('click'. () => {
  ptr.trigger().then(() => {
    alert('fire after trigger()')
  }) 
})

There's a full trigger() example in gh-pages branch.

Options

| params | type | comment | |--------------------- |------------ |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | contain | DOM | The warpper. | | header | DOM | The wrapper for the status text, spinner | | content | DOM | In most cases, this the wrapper for a <ul>. | | distanceToRefresh | Number | Threshold value. Control how long the distance finger can pull down to trigger release-to-refresh. recommend 50 ~ 90, and a number provided bigger than 120, it willl stay at 120. | | pullDownText | String | The text show in pull-down state.In the example it refers to 'Keep Dragging' | | releaseText | String | The text show in release-to-update state. In the example it refers to 'Now can release' | | refreshText | String | The text show in the refresh action is actually taking place.In the example it refers to 'Updating' | | finishText | String | The text show in the refresh action is done. In the example it refers to 'Done'. There is a trigger() you can use to manually trigger a pull-down-refresh, and the trigger function actually have a paramter call statusText, for detail see the Usage part below. basically it let you change the text shown. | | refresher | function | The function will be fired. Promise Excepted, see example blow. |

Options' default value

const options = {
  contain: $('.ptr-wrapper'),
  header: $('.ptr-wrapper .ptr'),
  content: $('.ptr-wrapper .content'),
  distanceToRefresh: 50,
  pullDownText: 'Pull down',
  releaseText: 'Release to refresh',
  refreshText: 'Updating',
  finishText: 'Done Refresh',
  refresher: refresher
}

Develop

Pull request welcome

Download and run at localhost

npm run serve

Build development

npm run build:dev

Build production

npm run build:prod

License

MIT License Copyright (c) 2018 Lien