1 /**
  2  * 日期选择器
  3  *
  4  * @fileOverView 基础组件
  5  * @author  <a href="mailto:zhang.gd@foxmail.com">Zhang Guangda</a>
  6  * @date    2012-10-25
  7  */
  8 define(["core", "plugin/My97DatePicker/WdatePicker"], function() {
  9 
 10 	/**
 11 	 * 日期选择器
 12 	 * @lends $we.widget.my97datepicker
 13 	 */
 14 	$we.widget.reg("my97datepicker", {
 15 		/**
 16 		 * interfaces
 17 		 * @memberOf $we.widget.my97datepicker#
 18 		 */
 19 		interfaces: {
 20 			/**
 21 			 * 设置选项
 22 			 * @param {Object} op 选项
 23 			 * @memberOf $we.widget.my97datepicker#
 24 			 */
 25 			setOption: function(op) {
 26 				op = op || {};
 27 				for (var i in op) {
 28 					if (op[i])
 29 						this.option[i] = op[i];
 30 				}
 31 			},
 32 			/**
 33 			 * 启用datepicker
 34 			 * @param  {String} id ID
 35 			 * @memberOf $we.widget.my97datepicker#
 36 			 */
 37 			on: function(id) {
 38 				var me = this;
 39 
 40 				$(document).ready(function() {
 41 					$("#"+id).on("focus", function() {
 42 						show.call(me, id);
 43 					});
 44 					$("#"+id).on("click", function() {
 45 						show.call(me, id);
 46 					});
 47 				});
 48 			},
 49 			/**
 50 			 * 显示datepicker
 51 			 * @param  {Events} e 事件
 52 			 * @memberOf $we.widget.my97datepicker#
 53 			 */
 54 			show: function(e) {
 55 				var el;
 56 				if (e) el = e.target ? e.target : e;
 57 				else el = $we.dom.getTarget();
 58 				
 59 				if (window.WdatePicker) {
 60 					if (el) this.option.el = el;
 61 					WdatePicker(this.option);
 62 				}
 63 			}
 64 		},
 65 		/**
 66 		 * @constructs
 67 		 * @param  {Object} option 配置
 68 		 */
 69 		init: function(option) {
 70 			var d = new Date();
 71 			var dateStr = [d.getFullYear(), (d.getMonth()+1), d.getDate()].join("-");
 72 
 73 			this.option = option || {
 74 				skin: "whyGreen",
 75 				dateFmt: "yyyy-MM-dd",
 76 				maxDate: dateStr,
 77 				lang: "zh-cn"
 78 			};
 79 		}
 80 	});
 81 
 82 	$we.comp.datepicker = $we.widget.add("my97datepicker");
 83 
 84 	return $we.comp.datepicker;
 85 
 86 });