Giter Site home page Giter Site logo

baobei / chineserp-jquery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xixilive/chineserp-jquery

0.0 2.0 0.0 467 KB

A better region picker plugin for jQuery in China. based on Chineserp, data provided by Chinese region db

Home Page: http://xixilive.github.io/chineserp-jquery/

License: MIT License

chineserp-jquery's Introduction

Chinese region picker plugin for jQuery

The best region picker plugin for jQuery in China. based on Chineserp, data provided by Chinese region db

Getting Started

Download the production version or the development version.

In your web page:

<script src="jquery.js"></script>
<script src="dist/jquery.chineserp.min.js"></script>
<link rel="stylesheet" href="dist/jquery.chineserp.css" media="screen">
<script>
jQuery(function($) {
  //work with a link and 'data-' attributes
  $('a.region-picker').regionPicker()
    .on('picked.rp', function(e, regions){
      $('#picker1 input').val(regions.map(function(r){ return r.n; }).join(", "));
    });

  //work with a button
  $('button.region-picker').regionPicker({
    remote: '/example',
    picked: '310105' //region code of Shanghai
  }).on('picked.rp', function(e, regions){
    $('#picker1 input').val(regions.map(function(r){ return r.n; }).join(", "));
  });
});
</script>

<div id="picker1" class="picker">
  <h1>Region Picker via link</h1>
  <input type="text" readonly="readonly"/>
  <a class="region-picker" href="javascript:;" data-remote="/example" data-picked="**维吾尔自治区, 喀什地区, 巴楚县" data-visible="5">
    Pickup a region
  </a>
  <button class="region-picker" type="button">Pickup a region</button>
</div>

Documentation

$('SELECTOR').regionPicker({OPTIONS}).on('EVENT', HANDLER);

options

{
  remote: 'path_of_json_data',  //URI path of json data files
  picked: 'region_id or region names',  //the initial value to be picked, names are seperated by comma or space, defaule is empty.
  visible: 10,   //the number of items that should be visibled in list element, default is 10.
  animate: 0,  //animation speed in ms, 0 means non-animation, default is 0
}

more details for 'remote' at Chineserp

events

$('SELECTOR').regionPicker().on('initializing.rp', function(e, picker){
  //fire when plugin initializing
})
$('SELECTOR').regionPicker().on('initialized.rp', function(e, picker){
  //fire when plugin initialized
})
$('SELECTOR').regionPicker().on('picked.rp', function(e, regions, picker){
  //fire when a region has picked up,
  //the regions argument contains several region objects that picked up by user
})
$('SELECTOR').regionPicker().on('loading.rp', function(e, picker){
  //fire when plugin is loading data
})
$('SELECTOR').regionPicker().on('loaded.rp', function(e, data, picker){
  //fire when data loaded
})

DOM tree

<div id="region-picker">
  <a href="javascript:;" class="region-picker-closer" title="cancel">&#215;</a>
  <div class="regions">
    <ul class="region-list">
      <li>REGION</li>
      ...more
    </ul>
    ...more
  </div>
</div>

Examples

jQuery(function(){
  $('.region-picker').regionPicker()
  .on('picked.rp', function(e, regions){
    console.log(regions);
  })
  .on('initializing.rp', function(e, picker){
    $(this).text('initializing').attr('disabled', true);
  })
  .on('initialized.rp', function(e, picker){
    $(this).text('Pickup a region').attr('disabled', false);
  })
  .on('loading.rp', function(e, picker){
    $(this).text('loading...').attr('disabled', true);
  })
  .on('loaded.rp', function(e, data, picker){
    $(this).text('Pickup a region').attr('disabled', false);
  });
});

learn more at examples

Release History

  • 2013-09-17 v0.0.1 the first version of RegionPicker plugin.
  • 2013-11-11 v0.0.3 Fix a bug of initialize event handler. It can't initialize again when this plugin was installed on a future-element.

chineserp-jquery's People

Contributors

xixilive avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.