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

city-picker-pc

v1.1.0

Published

A simple jQuery plugin for picking provinces, cities and districts of China.

Downloads

12

Readme

City Picker

A simple jQuery plugin for picking provinces, cities and districts of China.

##Release History

###v1.1.0 Add function to get the code:

// type: null or undefined(get the full code path, separated with /), province, city, district
$('.city-picker').data('citypicker').getCode(type);

Main

dist/
├── city-picker.js          ( 7 KB)
├── city-picker.min.js      ( 4 KB)
├── city-picker.data.js     (98 KB)
└── city-picker.data.min.js (68 KB)

Getting started

Quick start

Four quick start options are available:

  • Download the latest release.
  • Clone the repository: git clone https://github.com/tshi0912/city-picker.git.
  • Install with NPM: npm install city-picker.
  • Install with Bower: bower install city-picker.

Installation

Include files:

<script src="/path/to/jquery.js"></script><!-- jQuery is required -->
<script src="/path/to/city-picker.data.js"></script>
<script src="/path/to/city-picker.js"></script>

Create HTML elements:

<div style="position:relative;"><!-- container -->
  <input readonly type="text">
</div>

Usage

Initialize with data-toggle="city-picker" attribute

Basic

<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker">
</div>

Custom placeholders

<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker" placeholder="customized placeholder...">
</div>

Responsive width

<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker" data-responsive="true" style="width:50%;">
</div>

Custom province/city/district

<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker" value="江苏省/常州市/溧阳市">
</div>

Initialize with $.fn.city-picker method

Basic

$('#target').citypicker();

Custom districts

$('#target').citypicker({
  province: '江苏省',
  city: '常州市',
  district: '溧阳市'
});

Options

  • Change the default options with $().citypicker(options).
  • Change the global default options with $.fn.citypicker.setDefaults(options).

simple

  • Type: Boolean
  • Default: false

Make the address level more simple, e.g. 内蒙古 instead of 内蒙古自治区.

level

  • Type: String
  • Default: district

Only province, province + city, or province + city + district.

responsive

  • Type: Boolean
  • Default: false

make the drop down and mask span responsive on width.

placeholder

  • Type: Boolean
  • Default: 请输入省/市/区

Show placeholder (with an <option> element).

province

  • Type: String
  • Default: null

Defines the initial value of province. If it is a existing province in city-picker.data.js, it will be selected. If not, it will be used as a placeholder.

city

  • Type: String
  • Default: null

Defines the initial value of city. If it is a existing city under the selected province, it will be selected. If not, it will be used as a placeholder.

district

  • Type: String
  • Default: null

Defines the initial value of district. If it is a existing district under the selected city, it will be selected. If not, it will be used as a placeholder.

Methods

reset()

Reset the selects to the initial states (Undo changed).

Examples:

$().citypicker('reset');

destroy()

Destroy the city-picker instance, but keep the selected districts.

If you want to remove the selected districts, you can call reset method first and then call this method.

No conflict

If you have to use other plugin with the same namespace, just call the $.fn.city-picker.noConflict method to revert to it.

<script src="other-plugin.js"></script>
<script src="city-picker.js"></script>
<script>
  $.fn.citypicker.noConflict();
  // Code that uses other plugin's "$().citypicker" can follow here.
</script>

Browser support

  • Chrome (latest 2)
  • Firefox (latest 2)
  • Internet Explorer 8+
  • Opera (latest 2)
  • Safari (latest 2)

As a jQuery plugin, you also need to see the jQuery Browser Support.

License

MIT © Tao Shi